back-same-document-intercept.html (1763B)
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 await navigation.navigate("#1").finished; 15 16 const from = navigation.currentEntry; 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() { recorder.record("handler run"); } }); 27 }); 28 29 const result = navigation.back(); 30 recorder.setUpResultListeners(result); 31 32 Promise.resolve().then(() => recorder.record("promise microtask")); 33 34 await recorder.readyToAssert; 35 36 recorder.assert([ 37 /* event name, location.hash value, navigation.transition properties */ 38 ["promise microtask", "#1", null], 39 ["navigate", "#1", null], 40 ["currententrychange", "", { from, navigationType: "traverse" }], 41 ["handler run", "", { from, navigationType: "traverse" }], 42 ["committed fulfilled", "", { from, navigationType: "traverse" }], 43 ["navigatesuccess", "", { from, navigationType: "traverse" }], 44 ["finished fulfilled", "", null], 45 ["transition.finished fulfilled", "", null] 46 ]); 47 }, "event and promise ordering for same-document navigation.back() intercepted by intercept()"); 48 </script>