tor-browser

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

nav-cancelation-1.html (2232B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Parent main frame cancels a same-origin child whose navigation is pending</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <!--
      8  This test asserts that a parent canceling a same-origin child's cross-origin
      9  navigation does not result in load events firing synchronously in the parent
     10 -->
     11 
     12 <body>
     13 
     14 <iframe src=resources/slow.py></iframe>
     15 
     16 <script>
     17 promise_test(async t => {
     18  let window_load_fired = false;
     19  let iframe_load_fired = false;
     20  const iframe = document.querySelector('iframe');
     21 
     22  const window_load_promise = new Promise(resolve => {
     23    window.onload = () => {
     24      window_load_fired = true;
     25      resolve();
     26    }
     27  });
     28 
     29  const iframe_onload_promise = new Promise(resolve => {
     30    iframe.onload = () => {
     31      iframe_load_fired = true;
     32      resolve();
     33    }
     34  });
     35 
     36  // While the child navigation is in-flight, cancel it and record when the
     37  // parent `load` event fires.
     38  window.frames[0].location.href = "resources/slow.py?different";
     39 
     40  // Synchronously after cancelation, no load events should have been fired.
     41  assert_false(window_load_fired,
     42    "Parent's load event does not synchronously fire after cancelation");
     43  assert_false(iframe_load_fired,
     44    "<iframe> load event does not synchronously fire after cancelation");
     45 
     46  // Load events did not fire in a microtask after cancelation.
     47  await Promise.resolve();
     48  assert_false(window_load_fired,
     49      "Parent's load event does not fire in the microtask after cancelation");
     50  assert_false(iframe_load_fired,
     51      "<iframe> load event does not fire in the microtask after cancelation");
     52 
     53  // Canceling the navigation should unblock the parent's load event, but the
     54  // new iframe navigation should still be pending, and the iframe load event
     55  // shouldn't fire until *that one* is complete.
     56  await window_load_promise;
     57  assert_true(window_load_fired,
     58      "Parent's load event fires asynchronously after child navigation cancelation");
     59  assert_false(iframe_load_fired,
     60      "<iframe> load event does not fire until subsequent navigation is complete");
     61 }, "parent cancels a pending navigation in a same-origin child");
     62 </script>