location-href-intercept-reentrant.html (2002B)
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 let firstNavigate = true; 17 18 const recorder = new Recorder({ 19 skipCurrentChange: !hasVariant("currententrychange"), 20 finalExpectedEvent: "transition.finished fulfilled" 21 }); 22 23 recorder.setUpNavigationAPIListeners(); 24 25 navigation.addEventListener("navigate", e => { 26 e.intercept({ handler() { 27 recorder.record("handler run"); 28 return new Promise(resolve => t.step_timeout(resolve, 2)); 29 }}); 30 31 if (firstNavigate) { 32 firstNavigate = false; 33 34 location.href = "/common/blank.html#2"; 35 } 36 }); 37 38 location.href = "/common/blank.html#1"; 39 40 Promise.resolve().then(() => recorder.record("promise microtask")); 41 42 await recorder.readyToAssert; 43 44 recorder.assert([ 45 /* event name, location.hash value, navigation.transition properties */ 46 ["navigate", "", null], 47 ["AbortSignal abort", "", null], 48 ["navigateerror", "", null], 49 50 ["navigate", "", null], 51 ["currententrychange", "#2", { from, navigationType: "push" }], 52 ["handler run", "#2", { from, navigationType: "push" }], 53 ["promise microtask", "#2", { from, navigationType: "push" }], 54 ["navigatesuccess", "#2", { from, navigationType: "push" }], 55 ["transition.finished fulfilled", "#2", null] 56 ]); 57 58 recorder.assertErrorsAreAbortErrors(); 59 }, "event and promise ordering for the location.href setter intercepted by intercept() where we set location.href again inside the navigate handler"); 60 </script>