location-href-double-intercept.html (2316B)
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 location.href = "/common/blank.html#1"; 36 location.href = "/common/blank.html#2"; 37 38 Promise.resolve().then(() => recorder.record("promise microtask")); 39 40 await recorder.readyToAssert; 41 42 recorder.assert([ 43 /* event name, location.hash value, navigation.transition properties */ 44 ["navigate", "", null], 45 ["currententrychange", "#1", { from: fromStart, navigationType: "push" }], 46 ["handler run", "#1", { from: fromStart, navigationType: "push" }], 47 ["AbortSignal abort", "#1", { from: fromStart, navigationType: "push" }], 48 ["navigateerror", "#1", { from: fromStart, navigationType: "push" }], 49 50 ["navigate", "#1", null], 51 ["currententrychange", "#2", { from: fromHash1, navigationType: "push" }], 52 ["handler run", "#2", { from: fromHash1, navigationType: "push" }], 53 ["transition.finished rejected", "#2", { from: fromHash1, navigationType: "push" }], 54 ["promise microtask", "#2", { from: fromHash1, navigationType: "push" }], 55 ["navigatesuccess", "#2", { from: fromHash1, navigationType: "push" }], 56 ["transition.finished fulfilled", "#2", null] 57 ]); 58 59 recorder.assertErrorsAreAbortErrors(); 60 }, "event and promise ordering when location.href is set repeatedly and handled by intercept()"); 61 </script>