navigate-history-back-noop.html (1570B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <iframe id="i" src="/common/blank.html"></iframe> 5 <script> 6 promise_test(async t => { 7 let start_length = navigation.entries().length; 8 let start_index = navigation.currentEntry.index; 9 let start_history_length = history.length; 10 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 await i.contentWindow.navigation.navigate("#").finished; 16 assert_equals(i.contentWindow.navigation.entries().length, 2); 17 assert_equals(i.contentWindow.navigation.currentEntry.index, 1); 18 assert_equals(navigation.entries().length, start_length); 19 assert_equals(navigation.currentEntry.index, start_index); 20 assert_equals(history.length, start_history_length + 1); 21 22 i.remove(); 23 assert_equals(navigation.entries().length, start_length); 24 assert_equals(navigation.currentEntry.index, start_index); 25 26 // back() here should do nothing. The iframe that would have navigated has 27 // been removed. No navigate event should be fired. 28 navigation.onnavigate = t.unreached_func("navigate must not fire"); 29 navigation.oncurrententrychange = t.unreached_func("currententrychange must not fire"); 30 history.back(); 31 32 // Give time for the navigation to proceed. 33 await new Promise(resolve => t.step_timeout(resolve, 20)); 34 }, "history.back() does not fire a navigate event when there's nothing to navigate"); 35 </script>