tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug773962.xhtml (3141B)


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