tor-browser

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

test_nukeContentWindow.html (2212B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1322273
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1322273</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322273">Mozilla Bug 1322273</a>
     14 
     15 <iframe id="subframe"></iframe>
     16 
     17 <script type="application/javascript">
     18 "use strict";
     19 
     20 function waitForWindowDestroyed(winID, callback) {
     21  let observer = {
     22    observe: function(subject, topic, data) {
     23      let id = subject.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
     24      if (id != winID) {
     25        return;
     26      }
     27      SpecialPowers.removeObserver(observer, "outer-window-nuked");
     28      SpecialPowers.executeSoon(callback);
     29    }
     30  };
     31  SpecialPowers.addObserver(observer, "outer-window-nuked");
     32 }
     33 
     34 add_task(async function() {
     35  let frame = $('subframe');
     36  frame.srcdoc = "foo";
     37  await new Promise(resolve => frame.addEventListener("load", resolve, {once: true}));
     38 
     39  let win = frame.contentWindow;
     40  let winID = SpecialPowers.wrap(win).docShell.outerWindowID;
     41 
     42  win.eval("obj = {}");
     43  win.obj.foo = {bar: "baz"};
     44 
     45  let obj = win.obj;
     46 
     47  let system = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal()
     48  let sandbox = SpecialPowers.Cu.Sandbox(system);
     49 
     50  sandbox.obj = obj;
     51 
     52  let isWrapperDead = SpecialPowers.Cu.evalInSandbox(`(${
     53      function isWrapperDead() {
     54        return Cu.isDeadWrapper(obj);
     55      }
     56    })`,
     57    sandbox);
     58 
     59  is(isWrapperDead(), false, "Sandbox wrapper for content window should not be dead");
     60  is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive");
     61 
     62  // Remove the frame, which should nuke the content window.
     63  info("Remove the content frame");
     64  frame.remove();
     65 
     66  // Give the nuke wrappers task a chance to run.
     67  await new Promise(resolve => waitForWindowDestroyed(winID, resolve));
     68 
     69  is(isWrapperDead(), true, "Sandbox wrapper for content window should be dead");
     70  is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive");
     71 });
     72 </script>
     73 
     74 </body>
     75 </html>