navigate-destination-dynamic-index.html (1495B)
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 <script> 6 promise_test(async t => { 7 let start_index = navigation.currentEntry.index; 8 9 // Wait for after the load event so that the navigation doesn't get converted 10 // into a replace navigation. 11 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 12 await navigation.navigate("#1").finished; 13 14 let back_destination; 15 navigation.addEventListener("navigate", t.step_func(e => { 16 back_destination = e.destination; 17 assert_equals(back_destination.index, start_index); 18 }), { once: true }); 19 await navigation.back().finished; 20 21 // Disposing the destination entry of back_destination should update 22 // back_destination.index, even though back_destination's navigation has 23 // completed. 24 await navigation.navigate("#clobber_back", { history: "replace" }).finished; 25 assert_equals(back_destination.index, -1); 26 27 navigation.addEventListener("navigate", t.step_func(e => { 28 assert_equals(e.destination.index, start_index + 1); 29 30 // Dispose the destination entry and destination.index should update. 31 navigation.navigate("#clobber_forward"); 32 assert_equals(e.destination.index, -1); 33 }), { once: true }); 34 await assertBothRejectDOM(t, navigation.forward(), "AbortError"); 35 }, "navigate event destination.index should be dynamic"); 36 </script>