tor-browser

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

test_sharedChromeCompartment.html (1956B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1517694
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1517694</title>
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
     11  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
     12  <script type="application/javascript">
     13 "use strict";
     14 
     15 /** Test for Bug 1517694 */
     16 const { XPCOMUtils } = ChromeUtils.importESModule(
     17  "resource://gre/modules/XPCOMUtils.sys.mjs"
     18 );
     19 
     20 SimpleTest.waitForExplicitFinish();
     21 
     22 function go() {
     23    var frame = $('subframe');
     24    frame.onload = null;
     25 
     26    var isSameCompartment = Cu.getJSTestingFunctions().isSameCompartment;
     27 
     28    ok(isSameCompartment(window, frame.contentWindow),
     29       "System window is in same compartment");
     30 
     31    var sameCompSb = Cu.Sandbox(window);
     32    ok(isSameCompartment(window, sameCompSb),
     33       "System sandbox is in same compartment");
     34 
     35    var ownCompSb = Cu.Sandbox(window, {freshCompartment: true});
     36    ok(!isSameCompartment(window, ownCompSb),
     37       "Sandbox created with freshCompartment is in separate compartment");
     38 
     39    // Sandbox created in fresh-compartment sandbox must be in shared
     40    // compartment.
     41    var sb = Cu.evalInSandbox(`
     42      let principal =
     43        Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
     44      Cu.Sandbox(principal)
     45    `, ownCompSb);
     46    ok(isSameCompartment(window, sb),
     47       "System sandbox created in different compartment is in system compartment");
     48 
     49    ok(isSameCompartment(window, XPCOMUtils),
     50       "Object defined in system module is in same compartment");
     51 
     52    SimpleTest.finish();
     53 }
     54 
     55  </script>
     56 </head>
     57 <body>
     58 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1517694">Mozilla Bug 1517694</a>
     59 
     60 <iframe id="subframe" src="file_empty.html" onload="go()"></iframe>
     61 
     62 </body>
     63 </html>