tor-browser

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

test_bug534149.html (2369B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=534149
      5 -->
      6 <head>
      7  <title>Test for Bug 534149</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=534149">Mozilla Bug 534149</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15  
     16 </div>
     17 <pre id="test">
     18 <script type="application/javascript">
     19 
     20 /** Test for Bug 534149 */
     21 function getIDs(iframe) {
     22  var win = iframe.contentWindow;
     23  // Force inner creation
     24  win.document;
     25 
     26  let wgc = SpecialPowers.wrap(win).windowGlobalChild;
     27  return [wgc.outerWindowId, wgc.innerWindowId];
     28 }
     29 
     30 var i1 = document.createElement("iframe");
     31 var i2 = document.createElement("iframe");
     32 
     33 document.body.appendChild(i1);
     34 var [i1outer, i1inner] = getIDs(i1);
     35 
     36 document.body.appendChild(i2);
     37 var [i2outer, i2inner] = getIDs(i2);
     38 
     39 is(i1inner, i1outer + 1, "For frame 1, inner should come right after outer");
     40 is(i2inner, i2outer + 1, "For frame 2, inner should come right after outer");
     41 is(i2outer, i1inner + 1, "Frame 2 comes right after frame 1");
     42 
     43 var innerWindowDestroyID = null;
     44 var outerWindowDestroyID = null;
     45 
     46 var outerObserver = {
     47  observe(id) {
     48    outerWindowDestroyID =
     49      SpecialPowers.wrap(id).QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
     50    SpecialPowers.removeObserver(outerObserver, "outer-window-destroyed");
     51    maybeContinueTest();
     52  }
     53 };
     54 var innerObserver = {
     55  observe(id) {
     56    innerWindowDestroyID =
     57      SpecialPowers.wrap(id).QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
     58    SpecialPowers.removeObserver(innerObserver, "inner-window-destroyed");
     59    maybeContinueTest();
     60  }
     61 };
     62 
     63 function removeFrame(iframe) {
     64  SpecialPowers.addObserver(outerObserver, "outer-window-destroyed");
     65  SpecialPowers.addObserver(innerObserver, "inner-window-destroyed");
     66 
     67  iframe.remove();
     68 }
     69 
     70 function maybeContinueTest() {
     71  if (innerWindowDestroyID != null &&
     72      outerWindowDestroyID != null) {
     73    is(innerWindowDestroyID, i1inner, "inner window of frame 1 should be destroyed");
     74    is(outerWindowDestroyID, i1outer, "outer window of frame 1 should be destroyed");
     75    SimpleTest.finish();
     76  }
     77 }
     78 
     79 removeFrame(i1);
     80 SimpleTest.waitForExplicitFinish();
     81 
     82 </script>
     83 </pre>
     84 </body>
     85 </html>