tor-browser

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

navigate-same-document-intercept-reject.html (2065B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <meta name="variant" content="?no-currententrychange">
      5 <meta name="variant" content="?currententrychange">
      6 
      7 <script type="module">
      8 import { Recorder, hasVariant } from "./resources/helpers.mjs";
      9 
     10 promise_test(async t => {
     11  // Wait for after the load event so that the navigation doesn't get converted
     12  // into a replace navigation.
     13  await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
     14 
     15  const from = navigation.currentEntry;
     16  const expectedError = new Error("boo");
     17 
     18  const recorder = new Recorder({
     19    skipCurrentChange: !hasVariant("currententrychange"),
     20    finalExpectedEvent: "transition.finished rejected"
     21  });
     22 
     23  recorder.setUpNavigationAPIListeners();
     24 
     25  navigation.addEventListener("navigate", e => {
     26    e.intercept({ handler() {
     27      recorder.record("handler run");
     28      return Promise.reject(expectedError);
     29    }});
     30  });
     31 
     32  const result = navigation.navigate("#1");
     33  recorder.setUpResultListeners(result);
     34 
     35  Promise.resolve().then(() => recorder.record("promise microtask"));
     36 
     37  await recorder.readyToAssert;
     38 
     39  recorder.assert([
     40    /* event name, location.hash value, navigation.transition properties */
     41    ["navigate", "", null],
     42    ["currententrychange", "#1", { from, navigationType: "push" }],
     43    ["handler run", "#1", { from, navigationType: "push" }],
     44    ["committed fulfilled", "#1", { from, navigationType: "push" }],
     45    ["transition.committed fulfilled", "#1", { from, navigationType: "push" }],
     46    ["promise microtask", "#1", { from, navigationType: "push" }],
     47    ["AbortSignal abort", "#1", { from, navigationType: "push" }],
     48    ["navigateerror", "#1", { from, navigationType: "push" }],
     49    ["finished rejected", "#1", null],
     50    ["transition.finished rejected", "#1", null],
     51  ]);
     52 
     53  recorder.assertErrorsAre(expectedError);
     54 }, "event and promise ordering for same-document navigation.navigate() intercepted by passing a rejected promise to intercept()");
     55 </script>