tor-browser

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

test_other_auxiliary_navigation_by_location.html (2525B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=785310
      5 html5 sandboxed iframe should not be able to perform top navigation with scripts allowed
      6 -->
      7 <head>
      8 <meta charset="utf-8">
      9 <title>Test for Bug 785310 - iframe sandbox other auxiliary navigation by location tests</title>
     10 <script src="/tests/SimpleTest/SimpleTest.js"></script>
     11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 
     13 <script>
     14  SimpleTest.waitForExplicitFinish();
     15 
     16  function runScriptNavigationTest(testCase) {
     17    window.onmessage = function(event) {
     18      if (event.data != "otherWindow") {
     19        ok(false, "event.data: got '" + event.data + "', expected 'otherWindow'");
     20      }
     21      ok(false, testCase.desc + " - auxiliary navigation was NOT blocked");
     22      runNextTest();
     23    };
     24    try {
     25      window.testIframe.eval(testCase.script);
     26    } catch (e) {
     27      ok(true, testCase.desc + " - " + e.message);
     28      runNextTest();
     29    }
     30  }
     31 
     32  var testCaseIndex = -1;
     33  var testCases = [
     34    {
     35      desc: "Test 1: location.replace on auxiliary NOT opened by us should be blocked",
     36      script: "parent.openedWindow.location.replace('file_other_auxiliary_navigation_by_location.html')",
     37    },
     38    {
     39      desc: "Test 2: location.assign on auxiliary NOT opened by us should be blocked",
     40      script: "parent.openedWindow.location.assign('file_other_auxiliary_navigation_by_location.html')",
     41    },
     42    {
     43      desc: "Test 3: location.href on auxiliary NOT opened by us should be blocked",
     44      script: "parent.openedWindow.location.href = 'file_other_auxiliary_navigation_by_location.html'",
     45    },
     46    {
     47      desc: "Test 4: location.hash on auxiliary NOT opened by us should be blocked",
     48      script: "parent.openedWindow.location.hash = 'wibble'",
     49    },
     50  ];
     51 
     52  function runNextTest() {
     53    ++testCaseIndex;
     54    if (testCaseIndex == testCases.length) {
     55      window.openedWindow.close();
     56      SimpleTest.finish();
     57      return;
     58    }
     59 
     60    runScriptNavigationTest(testCases[testCaseIndex]);
     61  }
     62 
     63  window.onmessage = runNextTest;
     64 
     65  window.onload = function() {
     66    window.openedWindow = window.open("file_other_auxiliary_navigation_by_location.html", "otherWindow");
     67  };
     68 </script>
     69 
     70 </head>
     71 <body>
     72 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
     73 <p id="display"></p>
     74 <div id="content">
     75 Tests for Bug 785310
     76 </div>
     77 
     78 <iframe name="testIframe" sandbox="allow-scripts allow-same-origin allow-top-navigation allow-popups"></iframe>
     79 </body>
     80 </html>