test_bug773962.xul 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
  3. <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
  4. <!--
  5. https://bugzilla.mozilla.org/show_bug.cgi?id=773962
  6. -->
  7. <window title="Mozilla Bug 773962"
  8. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  10. <!-- test results are displayed in the html:body -->
  11. <body xmlns="http://www.w3.org/1999/xhtml">
  12. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=773962"
  13. target="_blank">Mozilla Bug 773962</a>
  14. </body>
  15. <!-- test code goes here -->
  16. <script type="application/javascript">
  17. <![CDATA[
  18. /** Test for remapping Xray waivers during brain transplant. **/
  19. SimpleTest.waitForExplicitFinish();
  20. const Cu = Components.utils;
  21. var gFramesLoaded = 0;
  22. function frameLoaded() {
  23. ++gFramesLoaded;
  24. if (gFramesLoaded == 2)
  25. startTest();
  26. if (gFramesLoaded == 3)
  27. finishTest();
  28. }
  29. function startTest() {
  30. // grab the windows and the node.
  31. win1 = document.getElementById('frame1').contentWindow;
  32. win2 = document.getElementById('frame2').contentWindow;
  33. node1 = win1.document.getElementById('text');
  34. loc1 = win1.location;
  35. // Grab some Xray waivers.
  36. win1Waiver = win1.wrappedJSObject;
  37. node1Waiver = node1.wrappedJSObject;
  38. loc1Waiver = win1Waiver.location;
  39. // Adopt node1 into win2. This causes node1 to be transplanted.
  40. win2.document.adoptNode(node1);
  41. // Navigate win1. This causes win1 to be transplanted.
  42. win1.location = 'http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html';
  43. // The above happens async. Our onload handler will call finishTest() when we're ready.
  44. }
  45. function finishTest() {
  46. // Now, recompute some wrappers.
  47. Cu.recomputeWrappers();
  48. // First, pat ourselves on the back for not asserting/crashing. That's most of
  49. // what we're really testing here.
  50. ok(true, "Didnt crash!");
  51. // Now, make sure everything is set up how we expect.
  52. ok(win1Waiver === win1.wrappedJSObject, "waivers still work");
  53. ok(XPCNativeWrapper(win1Waiver) === win1, "waivers still work");
  54. ok(node1Waiver === node1.wrappedJSObject, "waivers still work");
  55. ok(XPCNativeWrapper(node1Waiver) === node1, "waivers still work");
  56. // The semantics of location are tricky, because win1 now has a new location object.
  57. // In fact, loc1 should be a dead object proxy. Let's make sure we get this right.
  58. ok(loc1 !== win1.location, "navigation means different window.location");
  59. ok(loc1Waiver !== win1.location.wrappedJSObject, "navigation means different window.location");
  60. // Whew.
  61. SimpleTest.finish();
  62. }
  63. ]]>
  64. </script>
  65. <iframe id="frame1" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
  66. <iframe id="frame2" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
  67. </window>