navigate-intercept-precommitHandler-reject.tentative.html (2011B)
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 17 const recorder = new Recorder({ 18 skipCurrentChange: !hasVariant("currententrychange"), 19 finalExpectedEvent: "transition.finished rejected" 20 }); 21 22 recorder.setUpNavigationAPIListeners(); 23 24 navigation.addEventListener("navigate", e => { 25 e.intercept({ async precommitHandler() { 26 recorder.record("precommitHandler start"); 27 return Promise.reject("reject reason"); 28 }, 29 async handler() { recorder.record("handler should not run"); } 30 }); 31 }); 32 33 const result = navigation.navigate("#1"); 34 recorder.setUpResultListeners(result); 35 36 Promise.resolve().then(() => recorder.record("promise microtask")); 37 38 await recorder.readyToAssert; 39 40 recorder.assert([ 41 /* event name, location.hash value, navigation.transition properties */ 42 ["navigate", "", null], 43 ["precommitHandler start", "", { from, navigationType: "push" }], 44 ["promise microtask", "", { from, navigationType: "push" }], 45 ["AbortSignal abort", "", { from, navigationType: "push" }], 46 ["navigateerror", "", { from, navigationType: "push" }], 47 ["committed rejected", "", null], 48 ["finished rejected", "", null], 49 ["transition.committed rejected", "", null], 50 ["transition.finished rejected", "", null], 51 ]); 52 }, "event and promise ordering for same-document navigation.navigate() intercepted by intercept() with a precommitHandler"); 53 </script>