tor-browser

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

test_iframe_sandbox_popups_inheritance.html (6146B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=766282
      5 Implement HTML5 sandbox allow-popuos directive for IFRAMEs - inheritance tests
      6 -->
      7 <head>
      8  <meta charset="utf-8">
      9  <title>Tests for Bug 766282</title>
     10  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 
     14 <script type="application/javascript">
     15 
     16 SimpleTest.expectAssertions(0, 5);
     17 SimpleTest.waitForExplicitFinish();
     18 SimpleTest.requestFlakyTimeout("untriaged");
     19 
     20 // A postMessage handler that is used by sandboxed iframes without
     21 // 'allow-same-origin' to communicate pass/fail back to this main page.
     22 window.addEventListener("message", receiveMessage);
     23 
     24 function receiveMessage(event) {
     25  switch (event.data.type) {
     26    case "attempted":
     27      testAttempted();
     28      break;
     29    case "ok":
     30      ok_wrapper(event.data.ok, event.data.desc, event.data.addToAttempted);
     31      break;
     32    default:
     33      // allow for old style message
     34      if (event.data.ok != undefined) {
     35        ok_wrapper(event.data.ok, event.data.desc, event.data.addToAttempted);
     36      }
     37  }
     38 }
     39 
     40 var iframesWithWindowsToClose = new Array();
     41 
     42 var attemptedTests = 0;
     43 var passedTests = 0;
     44 var totalTestsToPass = 15;
     45 var totalTestsToAttempt = 21;
     46 
     47 function ok_wrapper(result, desc, addToAttempted = true) {
     48  ok(result, desc);
     49 
     50  if (result) {
     51    passedTests++;
     52  }
     53 
     54  if (addToAttempted) {
     55    testAttempted();
     56  }
     57 }
     58 
     59 // Added so that tests that don't register unless they fail,
     60 // can at least notify that they've attempted to run.
     61 function testAttempted() {
     62  attemptedTests++;
     63  if (attemptedTests == totalTestsToAttempt) {
     64    // Make sure all tests have had a chance to complete.
     65    setTimeout(function() {finish();}, 1000);
     66  }
     67 }
     68 
     69 var finishCalled = false;
     70 
     71 function finish() {
     72  if (!finishCalled) {
     73    finishCalled = true;
     74    is(passedTests, totalTestsToPass, "There are " + totalTestsToPass + " inheritance tests that should pass");
     75 
     76    closeWindows();
     77 
     78    SimpleTest.finish();
     79  }
     80 }
     81 
     82 function checkTestsFinished() {
     83  // If our own finish() has not been called, probably failed due to a timeout, so close remaining windows.
     84  if (!finishCalled) {
     85    closeWindows();
     86  }
     87 }
     88 
     89 function closeWindows() {
     90  for (var i = 0; i < iframesWithWindowsToClose.length; i++) {
     91    document.getElementById(iframesWithWindowsToClose[i]).contentWindow.postMessage({type: "closeWindows"}, "*");
     92  }
     93 }
     94 
     95 function doTest() {
     96  // passes if good and fails if bad
     97  // 1,2,3) A window opened from inside an iframe that has sandbox = "allow-scripts allow-popups
     98  // allow-same-origin" should not have its origin sandbox flag set and be able to access document.cookie.
     99  // (Done by file_iframe_sandbox_k_if5.html opened from file_iframe_sandbox_k_if4.html)
    100  // This is repeated for 3 different ways of opening the window,
    101  // see file_iframe_sandbox_k_if4.html for details.
    102 
    103  // passes if good
    104  // 4,5,6) A window opened from inside an iframe that has sandbox = "allow-scripts allow-popups
    105  // allow-top-navigation" should not have its top-level navigation sandbox flag set and be able to
    106  // navigate top. (Done by file_iframe_sandbox_k_if5.html (and if6) opened from
    107  // file_iframe_sandbox_k_if4.html).  This is repeated for 3 different ways of opening the window,
    108  // see file_iframe_sandbox_k_if4.html for details.
    109 
    110  // passes if good
    111  // 7,8,9) A window opened from inside an iframe that has sandbox = "allow-scripts allow-popups
    112  // all-forms" should not have its forms sandbox flag set and be able to submit forms.
    113  // (Done by file_iframe_sandbox_k_if7.html opened from file_iframe_sandbox_k_if4.html)
    114  // This is repeated for 3 different ways of opening the window,
    115  // see file_iframe_sandbox_k_if4.html for details.
    116 
    117  // passes if good
    118  // 10,11,12) Make sure that the sandbox flags copied to a new browsing context are taken from the
    119  // current active document not the browsing context (iframe / docShell).
    120  // This is done by removing allow-same-origin and calling doSubOpens from file_iframe_sandbox_k_if8.html,
    121  // which opens file_iframe_sandbox_k_if9.html in 3 different ways.
    122  // It then navigates to file_iframe_sandbox_k_if1.html to run tests 13 - 21 below.
    123  var if_8_1 = document.getElementById('if_8_1');
    124  if_8_1.sandbox = 'allow-scripts allow-popups';
    125  if_8_1.contentWindow.doSubOpens();
    126 
    127  // passes if good and fails if bad
    128  // 13,14,15) A window opened from inside an iframe that has sandbox = "allow-scripts allow-popups"
    129  // should have its origin sandbox flag set and not be able to access document.cookie.
    130  // This is done by file_iframe_sandbox_k_if8.html navigating to file_iframe_sandbox_k_if1.html
    131  // after allow-same-origin has been removed from iframe if_8_1.  file_iframe_sandbox_k_if1.html
    132  // opens file_iframe_sandbox_k_if2.html in 3 different ways to perform the tests.
    133  iframesWithWindowsToClose.push("if_8_1");
    134 
    135  // fails if bad
    136  // 16,17,18) A window opened from inside an iframe that has sandbox = "allow-scripts allow-popups"
    137  // should have its forms sandbox flag set and not be able to submit forms.
    138  // This is done by file_iframe_sandbox_k_if2.html, see test 10 for details of how this is opened.
    139 
    140  // fails if bad
    141  // 19,20,21) A window opened from inside an iframe that has sandbox = "allow-scripts allow-popups"
    142  // should have its top-level navigation sandbox flag set and not be able to navigate top.
    143  // This is done by file_iframe_sandbox_k_if2.html, see test 10 for details of how this is opened.
    144 }
    145 
    146 addLoadEvent(doTest);
    147 </script>
    148 
    149 <body onunload="checkTestsFinished()">
    150 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=766282">Mozilla Bug 766282</a> - Implement HTML5 sandbox allow-popups directive for IFRAMEs
    151 <p id="display"></p>
    152 <div id="content">
    153 <iframe sandbox="allow-scripts allow-popups allow-same-origin allow-forms allow-top-navigation" id="if_4" src="file_iframe_sandbox_k_if4.html" height="10" width="10"></iframe>
    154 <iframe sandbox="allow-scripts allow-popups allow-same-origin" id="if_8_1" src="file_iframe_sandbox_k_if8.html" height="10" width="10"></iframe>
    155 </div>
    156 </body>
    157 </html>