navigate-double-intercept.html (2927B)
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 }); 21 22 recorder.setUpNavigationAPIListeners(); 23 24 navigation.addEventListener("navigate", e => { 25 e.intercept({ handler() { 26 recorder.record("handler run"); 27 return new Promise(r => t.step_timeout(r, 1)); 28 }}); 29 30 if (location.hash === "#1") { 31 fromHash1 = navigation.currentEntry; 32 } 33 }); 34 35 const result1 = navigation.navigate("/common/blank.html#1"); 36 recorder.setUpResultListeners(result1, " 1"); 37 38 const result2 = navigation.navigate("/common/blank.html#2"); 39 recorder.setUpResultListeners(result2, " 2"); 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 ["currententrychange", "#1", { from: fromStart, navigationType: "push" }], 49 ["handler run", "#1", { from: fromStart, navigationType: "push" }], 50 ["AbortSignal abort", "#1", { from: fromStart, navigationType: "push" }], 51 ["navigateerror", "#1", { from: fromStart, navigationType: "push" }], 52 53 ["navigate", "#1", null], 54 ["currententrychange", "#2", { from: fromHash1, navigationType: "push" }], 55 ["handler run", "#2", { from: fromHash1, navigationType: "push" }], 56 ["committed fulfilled 1", "#2", { from: fromHash1, navigationType: "push" }], 57 ["transition.committed fulfilled 1", "#2", { from: fromHash1, navigationType: "push" }], 58 ["finished rejected 1", "#2", { from: fromHash1, navigationType: "push" }], 59 ["transition.finished rejected", "#2", { from: fromHash1, navigationType: "push" }], 60 ["committed fulfilled 2", "#2", { from: fromHash1, navigationType: "push" }], 61 ["transition.committed fulfilled 2", "#2", { from: fromHash1, navigationType: "push" }], 62 ["promise microtask", "#2", { from: fromHash1, navigationType: "push" }], 63 ["navigatesuccess", "#2", { from: fromHash1, navigationType: "push" }], 64 ["finished fulfilled 2", "#2", null], 65 ["transition.finished fulfilled", "#2", null] 66 ]); 67 68 recorder.assertErrorsAreAbortErrors(); 69 }, "event and promise ordering when navigate() is called repeatedly and handled by intercept()"); 70 </script>