precommitHandler-traversal-window-stop-before-commit.html (2070B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="../navigation-methods/return-value/resources/helpers.js"></script> 5 <body> 6 <script> 7 promise_test(async t => { 8 // Wait for after the load event because window.stop() hangs the test harness 9 // if called before the load event. 10 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 11 12 let start_length = navigation.entries().length; 13 let start_index = navigation.currentEntry.index; 14 15 await navigation.navigate("#1").finished; 16 await navigation.navigate("#2").finished; 17 assert_equals(navigation.entries().length, start_length + 2); 18 assert_equals(navigation.currentEntry.index, start_index + 2); 19 20 let stopped_first_traverse = false; 21 navigation.onnavigate = t.step_func(e => { 22 if (!stopped_first_traverse) { 23 stopped_first_traverse = true; 24 t.step_timeout(() => window.stop(), 0); 25 } 26 e.intercept({ precommitHandler: () => new Promise(r => t.step_timeout(r, 10)) }); 27 }); 28 29 let navigatesuccess_called = false; 30 let navigateerror_called = false; 31 navigation.onnavigatesuccess = t.step_func(() => { 32 navigatesuccess_called = true; 33 assert_equals(location.hash, "#1"); 34 }); 35 navigation.onnavigateerror = t.step_func(() => { 36 navigateerror_called = true; 37 assert_equals(location.hash, "#2"); 38 }); 39 40 await assertBothRejectDOM(t, navigation.back(), "AbortError"); 41 42 assert_equals(navigation.currentEntry.index, start_index + 2); 43 assert_equals(location.hash, "#2"); 44 assert_true(navigateerror_called); 45 assert_false(navigatesuccess_called); 46 47 // Ensure navigation.entries() remains in sync with the session history in 48 // spite of the window.stop(), and navigation.back() does not skip over #1. 49 await navigation.back().finished; 50 51 assert_equals(navigation.currentEntry.index, start_index + 1); 52 assert_equals(location.hash, "#1"); 53 assert_true(navigatesuccess_called); 54 }, " precommitHandler traverse with window.stop() before commit"); 55 </script> 56 </body>