tor-browser

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

test_shared_compartment1.html (2427B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1530608
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1530608</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 1530608 */
     14  SimpleTest.waitForExplicitFinish();
     15 
     16  var Cu = SpecialPowers.Cu;
     17  var isSameCompartment = Cu.getJSTestingFunctions().isSameCompartment;
     18 
     19  var testsDone = 0;
     20  function finishIfDone() {
     21    testsDone++;
     22    if (testsDone === 4) {
     23      SimpleTest.finish();
     24    }
     25  }
     26 
     27  // Test 1: same-origin iframe.
     28  function testFrame1() {
     29    var frameWin = document.getElementById("frame1").contentWindow;
     30    ok(isSameCompartment(window, frameWin),
     31       "Same-origin iframe must be same-compartment");
     32    finishIfDone();
     33  }
     34 
     35  // Test 2: cross-origin iframe.
     36  function testFrame2() {
     37    var frameWin = document.getElementById("frame2").contentWindow;
     38    ok(!isSameCompartment(window, frameWin),
     39       "Cross-origin iframe must be cross-compartment");
     40    finishIfDone();
     41  }
     42 
     43  // Test 3: same-site, cross-origin iframe.
     44  function testFrame3() {
     45    var frame = document.getElementById("frame3");
     46    ok(!isSameCompartment(window, frame.contentWindow),
     47       "Same-site cross-origin iframe must be cross-compartment");
     48 
     49    // Now load a same-origin page in this iframe.
     50    frame.onload = function() {
     51      ok(isSameCompartment(window, frame.contentWindow),
     52         "Frame must be same-compartment now");
     53      finishIfDone();
     54    };
     55    frame.src = "file_empty.html";
     56  }
     57 
     58  // Test 4: dynamically created iframe.
     59  addLoadEvent(function() {
     60    var frame = document.createElement("iframe");
     61    document.body.appendChild(frame);
     62    ok(isSameCompartment(window, frame.contentWindow),
     63       "Newly created iframe must be same-compartment");
     64    finishIfDone();
     65  });
     66 
     67  </script>
     68 </head>
     69 <body>
     70 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1530608">Mozilla Bug 1530608</a>
     71 
     72 <iframe id="frame1" onload="testFrame1()" src="file_empty.html"></iframe>
     73 <iframe id="frame2" onload="testFrame2()" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>
     74 <iframe id="frame3" onload="testFrame3()" src="http://test1.mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>
     75 
     76 </body>
     77 </html>