tor-browser

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

src-repeated-in-ancestor.html (4553B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Navigation should not occur when `src` matches the location of a anscestor browsing context</title>
      4 <script>
      5 // Avoid recursion in non-conforming browsers
      6 if (parent !== window && parent.title == window.title) {
      7  window.stop();
      8 }
      9 </script>
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 <body>
     13 <script>
     14 /**
     15 * This test uses the `beforeunload` event to detect navigation. Because that
     16 * event is fired synchronously in response to "process the iframe attributes",
     17 * a second "control" iframe may be used to verify cases where navigation
     18 * should *not* occur. `Promise.race` ensures that tests complete as soon as
     19 * possible.
     20 *
     21 * Although the specification dictates that the `beforeunload` event must be
     22 * emitted synchronously during navigation, a number of user agents do not
     23 * adhere to this requirement. WPT includes a dedicated test for synchronous
     24 * emission of the event [1]. This test is authored to support non-standard
     25 * behavior in order to avoid spuriously passing in those UAs.
     26 *
     27 * [1] https://github.com/web-platform-tests/wpt/pull/12343
     28 */
     29 'use strict';
     30 
     31 function when(target, eventName) {
     32  return new Promise(function(resolve, reject) {
     33    target.addEventListener(eventName, function() {
     34      resolve();
     35    }, { once: true });
     36    target.addEventListener('error', function() {
     37      reject(new Error('Error while waiting for ' + eventName));
     38    }, { once: true });
     39  });
     40 }
     41 
     42 function init(doc, t) {
     43  var iframes = [doc.createElement('iframe'), doc.createElement('iframe')];
     44 
     45  iframes.forEach(function(iframe) {
     46    iframe.src = '/common/blank.html';
     47    doc.body.appendChild(iframe);
     48 
     49    t.add_cleanup(function() {
     50      iframe.parentNode.removeChild(iframe);
     51    });
     52  });
     53 
     54  return Promise.all([when(iframes[0], 'load'), when(iframes[1], 'load')])
     55    .then(function() { return iframes; });
     56 }
     57 
     58 // This test verifies that navigation does occur; it is intended to validate
     59 // the utility functions.
     60 promise_test(function(t) {
     61  return init(document, t)
     62    .then(function(iframes) {
     63      var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
     64      var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
     65 
     66      iframes[0].src = '/common/blank.html?2';
     67      iframes[1].src = '/common/blank.html?3';
     68 
     69      return Promise.all([subjectNavigation, controlNavigation]);
     70    });
     71 }, 'different path name');
     72 
     73 promise_test(function(t) {
     74  return init(document, t)
     75    .then(function(iframes) {
     76      var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
     77      var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
     78 
     79      iframes[0].src = location.href;
     80      iframes[1].src = '/common/blank.html?4';
     81 
     82      return Promise.race([
     83        subjectNavigation.then(function() {
     84          assert_unreached('Should not navigate');
     85        }),
     86        controlNavigation
     87      ]);
     88    });
     89 }, 'same path name, no document fragment');
     90 
     91 promise_test(function(t) {
     92  return init(document, t)
     93    .then(function(iframes) {
     94      var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
     95      var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
     96 
     97      iframes[0].src = location.href + '#something-else';
     98      iframes[1].src = '/common/blank.html?5';
     99 
    100      return Promise.race([
    101        subjectNavigation.then(function() {
    102          assert_unreached('Should not navigate');
    103        }),
    104        controlNavigation
    105      ]);
    106    });
    107 }, 'same path name, different document fragment');
    108 
    109 promise_test(function(t) {
    110  var intermediate = document.createElement('iframe');
    111 
    112  document.body.appendChild(intermediate);
    113 
    114  t.add_cleanup(function() {
    115    intermediate.parentNode.removeChild(intermediate);
    116  });
    117  intermediate.contentDocument.open();
    118  intermediate.contentDocument.write('<body></body>');
    119  intermediate.contentDocument.close();
    120 
    121  return init(intermediate.contentDocument, t)
    122    .then(function(iframes) {
    123      var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
    124      var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
    125 
    126      iframes[0].src = location.href;
    127      iframes[1].src = '/common/blank.html?6';
    128 
    129      return Promise.race([
    130        subjectNavigation.then(function() {
    131          assert_unreached('Should not navigate');
    132        }),
    133        controlNavigation
    134      ]);
    135    });
    136 }, 'same path name, no document fragement (intermediary browsing context)');
    137 </script>
    138 </body>