intercept-popstate.html (881B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script> 5 promise_test(async t => { 6 // Wait for after the load event so that the navigation doesn't get converted 7 // into a replace navigation. 8 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 9 history.replaceState({ state: "foo"}, "", "#replace"); 10 11 let onpopstate_fired = false; 12 let last_state; 13 window.onpopstate = e => { 14 onpopstate_fired = true; 15 last_state = e.state; 16 } 17 navigation.onnavigate = t.step_func(e => e.intercept()); 18 19 await navigation.navigate("#").finished; 20 assert_true(navigation.canGoBack); 21 22 await navigation.back().finished; 23 assert_true(onpopstate_fired); 24 assert_not_equals(last_state, null); 25 }, "event.intercept() should provide popstate with a valid state object"); 26 </script>