tor-browser

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

test_iframe_sandbox_navigation2.html (9668B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=341604
      5 Implement HTML5 sandbox attribute for IFRAMEs
      6 -->
      7 <head>
      8  <meta charset="utf-8">
      9  <title>Test for Bug 341604 - navigation</title>
     10  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     11  <script src="/tests/SimpleTest/EventUtils.js"></script>
     12  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     13 </head>
     14 <script type="application/javascript">
     15 /** Test for Bug 341604 - Implement HTML5 sandbox attribute for IFRAMEs */
     16 /** Navigation tests Part 2*/
     17 
     18 SimpleTest.expectAssertions(0);
     19 SimpleTest.requestLongerTimeout(2); // slow on Android
     20 SimpleTest.waitForExplicitFinish();
     21 SimpleTest.requestFlakyTimeout("untriaged");
     22 // a postMessage handler that is used by sandboxed iframes without
     23 // 'allow-same-origin'/other windows to communicate pass/fail back to this main page.
     24 // it expects to be called with an object like {ok: true/false, desc:
     25 // <description of the test> which it then forwards to ok()
     26 var bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("test_iframe_sandbox_navigation");
     27 bc.addEventListener("message", receiveMessage);
     28 window.addEventListener("message", receiveMessage);
     29 
     30 var testPassesReceived = 0;
     31 
     32 function receiveMessage(event) {
     33  switch (event.data.type) {
     34    case "attempted":
     35      testAttempted();
     36      break;
     37    case "ok":
     38      ok_wrapper(event.data.ok, event.data.desc, event.data.addToAttempted);
     39      break;
     40    default:
     41      // allow for old style message
     42      if (event.data.ok != undefined) {
     43        ok_wrapper(event.data.ok, event.data.desc, event.data.addToAttempted);
     44      }
     45  }
     46 }
     47 
     48 // Open windows for tests to attempt to navigate later.
     49 var windowsToClose = new Array();
     50 windowsToClose.push(window.open("about:blank", "window_to_navigate"));
     51 windowsToClose.push(window.open("about:blank", "window_to_navigate2"));
     52 var iframesWithWindowsToClose = new Array();
     53 
     54 var attemptedTests = 0;
     55 var passedTests = 0;
     56 var totalTestsToPass = 12;
     57 var totalTestsToAttempt = 15;
     58 
     59 function ok_wrapper(result, desc, addToAttempted = true) {
     60  ok(result, desc);
     61 
     62  if (result) {
     63    passedTests++;
     64  }
     65 
     66  if (addToAttempted) {
     67    testAttempted();
     68  }
     69 }
     70 
     71 // Added so that tests that don't register unless they fail,
     72 // can at least notify that they've attempted to run.
     73 function testAttempted() {
     74  attemptedTests++;
     75  if (attemptedTests == totalTestsToAttempt) {
     76    // Make sure all tests have had a chance to complete.
     77    setTimeout(function() {finish();}, 1000);
     78  }
     79 }
     80 
     81 var finishCalled = false;
     82 
     83 function finish() {
     84  if (!finishCalled) {
     85    finishCalled = true;
     86    is(passedTests, totalTestsToPass, "There are " + totalTestsToPass + " navigation tests that should pass");
     87 
     88    for (var i = 0; i < windowsToClose.length; i++) {
     89      windowsToClose[i].close();
     90    }
     91 
     92    bc.close();
     93 
     94    SimpleTest.finish();
     95  }
     96 }
     97 
     98 function checkTestsFinished() {
     99  // If our own finish() has not been called, probably failed due to a timeout, so close remaining windows.
    100  if (!finishCalled) {
    101    for (var i = 0; i < windowsToClose.length; i++) {
    102      windowsToClose[i].close();
    103    }
    104  }
    105 }
    106 
    107 function doTest() {
    108  // fails if bad
    109  // 14) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not
    110  // be able to navigate another window (opened by another browsing context) using its name.
    111  // file_iframe_sandbox_d_if14.html in if_14 attempts to navigate "window_to_navigate",
    112  // which has been opened in preparation.
    113 
    114  // fails if bad
    115  // 15) iframe with sandbox='allow-scripts' should not be able to navigate top using its
    116  // real name (instead of _top) as allow-top-navigation is not specified.
    117  // file_iframe_sandbox_e_if7.html contains file_iframe_sandbox_e_if8.html, which
    118  // attempts to navigate top by name.
    119  windowsToClose.push(window.open("file_iframe_sandbox_e_if7.html"));
    120 
    121  // fails if bad
    122  // 16) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not
    123  // be able to use its parent's name (instead of _parent) to navigate it, when it is not top.
    124  // (Note: this would apply to other ancestors that are not top as well.)
    125  // file_iframe_sandbox_d_if15.html in if_15 contains file_iframe_sandbox_d_if16.html, which
    126  // tries to navigate if_15 by its name (if_parent).
    127 
    128  // passes if good, fails if bad
    129  // 17) A sandboxed iframe is allowed to navigate itself using window.open().
    130  // (Done by file_iframe_sandbox_d_if17.html which has 'allow-scripts' and navigates to
    131  // file_iframe_sandbox_navigation_pass.html).
    132 
    133  // passes if good, fails if bad
    134  // 18) A sandboxed iframe is allowed to navigate its children with window.open(), even if
    135  // they are sandboxed.  (Done by file_iframe_sandbox_d_if18.html which has 'allow-scripts',
    136  // it navigates a child iframe to file_iframe_sandbox_navigation_pass.html).
    137 
    138  // passes if good, fails if bad
    139  // 19) A sandboxed iframe is not allowed to navigate its ancestor with window.open().
    140  // (Done by file_iframe_sandbox_d_if20.html contained within file_iframe_sandbox_d_if19.html,
    141  // it attempts to navigate file_iframe_sandbox_d_if19.html to file_iframe_sandbox_navigation_fail.html).
    142 
    143  // passes if good, fails if bad
    144  // 20) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not
    145  // be able to navigate another window (opened by another browsing context) using window.open(..., "<name>").
    146  // file_iframe_sandbox_d_if14.html in if_14 attempts to navigate "window_to_navigate2",
    147  // which has been opened in preparation, using window.open(..., "window_to_navigate2").
    148 
    149  // passes if good, fails if bad
    150  // 21) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not
    151  // be able to use its parent's name (not _parent) to navigate it using window.open(), when it is not top.
    152  // (Note: this would apply to other ancestors that are not top as well.)
    153  // file_iframe_sandbox_d_if21.html in if_21 contains file_iframe_sandbox_d_if22.html, which
    154  // tries to navigate if_21 by its name (if_parent2).
    155 
    156  // passes if good, fails if bad
    157  // 22) iframe with sandbox='allow-top-navigation allow-scripts' can navigate top with window.open().
    158  // file_iframe_sandbox_e_if9.html contains file_iframe_sandbox_e_if11.html which navigates top.
    159  window.open("file_iframe_sandbox_e_if9.html");
    160 
    161  // passes if good, fails if bad
    162  // 23) iframe with sandbox='allow-top-navigation allow-scripts' nested inside an iframe with
    163  // 'allow-top-navigation allow-scripts' can navigate top, with window.open().
    164  // file_iframe_sandbox_e_if10.html contains file_iframe_sandbox_e_if9.html which contains
    165  // file_iframe_sandbox_e_if11.html which navigates top.
    166  window.open("file_iframe_sandbox_e_if10.html");
    167 
    168  // passes if good, fails if bad
    169  // 24) iframe with sandbox='allow-scripts' can NOT navigate top with window.open().
    170  // file_iframe_sandbox_e_if12.html contains file_iframe_sandbox_e_if14.html which navigates top.
    171  window.open("file_iframe_sandbox_e_if12.html");
    172 
    173  // passes if good, fails if bad
    174  // 25) iframe with sandbox='allow-scripts' nested inside an iframe with
    175  // 'allow-top-navigation allow-scripts' can NOT navigate top, with window.open(..., "_top").
    176  // file_iframe_sandbox_e_if13.html contains file_iframe_sandbox_e_if12.html which contains
    177  // file_iframe_sandbox_e_if14.html which navigates top.
    178  window.open("file_iframe_sandbox_e_if13.html");
    179 
    180  // passes if good, fails if bad
    181  // 26) iframe with sandbox='allow-scripts' should not be able to navigate top using its real name
    182  // (not with _top e.g. window.open(..., "topname")) as allow-top-navigation is not specified.
    183  // file_iframe_sandbox_e_if15.html contains file_iframe_sandbox_e_if16.html, which
    184  // attempts to navigate top by name using window.open().
    185  window.open("file_iframe_sandbox_e_if15.html");
    186 
    187  // passes if good
    188  // 27) iframe with sandbox='allow-scripts allow-popups' should be able to
    189  // navigate a window, that it has opened, using it's name.
    190  // file_iframe_sandbox_d_if23.html in if_23 opens a window and then attempts
    191  // to navigate it using it's name in the target of an anchor.
    192  iframesWithWindowsToClose.push("if_23");
    193 
    194  // passes if good, fails if bad
    195  // 28) iframe with sandbox='allow-scripts allow-popups' should be able to
    196  // navigate a window, that it has opened, using window.open(..., "<name>").
    197  // file_iframe_sandbox_d_if23.html in if_23 opens a window and then attempts
    198  // to navigate it using it's name in the target of window.open().
    199 }
    200 
    201 addLoadEvent(doTest);
    202 </script>
    203 <body onunload="checkTestsFinished()">
    204 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs
    205 <p id="display"></p>
    206 <div id="content">
    207 <iframe sandbox="allow-same-origin allow-scripts allow-top-navigation" id="if_14" src="file_iframe_sandbox_d_if14.html" height="10" width="10"></iframe>
    208 <iframe id="if_15" name="if_parent" src="file_iframe_sandbox_d_if15.html" height="10" width="10"></iframe>
    209 <iframe sandbox="allow-scripts" id="if_17" src="file_iframe_sandbox_d_if17.html" height="10" width="10"></iframe>
    210 <iframe sandbox="allow-scripts" id="if_18" src="file_iframe_sandbox_d_if18.html" height="10" width="10"></iframe>
    211 <iframe sandbox="allow-scripts" id="if_19" src="file_iframe_sandbox_d_if19.html" height="10" width="10"></iframe>
    212 <iframe id="if_21" name="if_parent2" src="file_iframe_sandbox_d_if21.html" height="10" width="10"></iframe>
    213 <iframe sandbox="allow-scripts allow-popups" id="if_23" src="file_iframe_sandbox_d_if23.html" height="10" width="10"></iframe>
    214 </div>
    215 </body>
    216 </html>