tor-browser

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

navigate-in-transition-finished.html (2900B)


      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 promise_test(async t => {
     10  // Wait for after the load event so that the navigation doesn't get converted
     11  // into a replace navigation.
     12  await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
     13 
     14  const fromStart = navigation.currentEntry;
     15  let fromHash1;
     16 
     17  const recorder = new Recorder({
     18    skipCurrentChange: !hasVariant("currententrychange"),
     19    finalExpectedEvent: "transition.finished fulfilled",
     20    finalExpectedEventCount: 2
     21  });
     22 
     23  recorder.setUpNavigationAPIListeners();
     24 
     25  navigation.addEventListener("navigatesuccess", t.step_func(() => {
     26    if (location.hash === "#1") {
     27      navigation.transition.finished.then(() => {
     28        const result2 = navigation.navigate("/common/blank.html#2");
     29        recorder.setUpResultListeners(result2, " 2");
     30      });
     31    }
     32  }));
     33 
     34  navigation.addEventListener("navigate", e => {
     35    e.intercept({ handler() { recorder.record("handler run"); } });
     36 
     37    if (location.hash === "#1") {
     38      fromHash1 = navigation.currentEntry;
     39    }
     40  });
     41 
     42  const result1 = navigation.navigate("/common/blank.html#1");
     43  recorder.setUpResultListeners(result1, " 1");
     44 
     45  Promise.resolve().then(() => recorder.record("promise microtask"));
     46 
     47  await recorder.readyToAssert;
     48 
     49  recorder.assert([
     50    /* event name, location.hash value, navigation.transition properties */
     51    ["navigate", "", null],
     52    ["currententrychange", "#1", { from: fromStart, navigationType: "push" }],
     53    ["handler run", "#1", { from: fromStart, navigationType: "push" }],
     54    ["committed fulfilled 1", "#1", { from: fromStart, navigationType: "push" }],
     55    ["transition.committed fulfilled 1", "#1", { from: fromStart, navigationType: "push" }],
     56    ["promise microtask", "#1", { from: fromStart, navigationType: "push" }],
     57    ["navigatesuccess", "#1", { from: fromStart, navigationType: "push" }],
     58    ["finished fulfilled 1", "#1", null],
     59    ["transition.finished fulfilled", "#1", null],
     60 
     61    ["navigate", "#1", null],
     62    ["currententrychange", "#2", { from: fromHash1, navigationType: "push" }],
     63    ["handler run", "#2", { from: fromHash1, navigationType: "push" }],
     64    ["committed fulfilled 2", "#2", { from: fromHash1, navigationType: "push" }],
     65    ["transition.committed fulfilled 2", "#2", { from: fromHash1, navigationType: "push" }],
     66    ["navigatesuccess", "#2", { from: fromHash1, navigationType: "push" }],
     67    ["finished fulfilled 2", "#2", null],
     68    ["transition.finished fulfilled", "#2", null]
     69  ]);
     70 }, "event and promise ordering when navigate() is called inside the transition.finished promise handler");
     71 </script>