tor-browser

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

navigate-intercept-precommitHandler.html (2521B)


      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 
     17  const recorder = new Recorder({
     18    skipCurrentChange: !hasVariant("currententrychange"),
     19    finalExpectedEvent: "transition.finished fulfilled"
     20  });
     21 
     22  recorder.setUpNavigationAPIListeners();
     23 
     24  navigation.addEventListener("navigate", e => {
     25    e.intercept({ async precommitHandler() {
     26                    recorder.record("precommitHandler start");
     27                    await new Promise(r => t.step_timeout(r, 0));
     28                    recorder.record("precommitHandler async step");
     29                  },
     30                  async handler() {
     31                    recorder.record("handler start");
     32                    await new Promise(r => t.step_timeout(r, 0));
     33                    recorder.record("handler async step");
     34                  }
     35                });
     36  });
     37 
     38  const result = navigation.navigate("#1");
     39  recorder.setUpResultListeners(result);
     40 
     41  Promise.resolve().then(() => recorder.record("promise microtask"));
     42 
     43  await recorder.readyToAssert;
     44 
     45  recorder.assert([
     46    /* event name, location.hash value, navigation.transition properties */
     47    ["navigate", "", null],
     48    ["precommitHandler start", "", { from, navigationType: "push" }],
     49    ["promise microtask", "", { from, navigationType: "push" }],
     50    ["precommitHandler async step", "", { from, navigationType: "push" }],
     51    ["currententrychange", "#1", { from, navigationType: "push" }],
     52    ["handler start", "#1", { from, navigationType: "push" }],
     53    ["committed fulfilled", "#1", { from, navigationType: "push" }],
     54    ["transition.committed fulfilled", "#1", { from, navigationType: "push" }],
     55    ["handler async step", "#1", { from, navigationType: "push" }],
     56    ["navigatesuccess", "#1", { from, navigationType: "push" }],
     57    ["finished fulfilled", "#1", null],
     58    ["transition.finished fulfilled", "#1", null],
     59  ]);
     60 }, "event and promise ordering for same-document navigation.navigate() intercepted by intercept() with a precommitHandler");
     61 </script>