activation-replace.html (2481B)
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 // Wait for after the load event so that the navigation doesn't get converted 8 // into a replace navigation. 9 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 10 11 let before_key = i.contentWindow.navigation.currentEntry.key; 12 let before_id = i.contentWindow.navigation.currentEntry.id; 13 let before_url = i.contentWindow.navigation.currentEntry.url; 14 i.contentWindow.navigation.navigate("/common/blank.html?a", { history: "replace" }); 15 await new Promise(resolve => i.onload = () => t.step_timeout(resolve, 0)); 16 let current_entry_after_nav = i.contentWindow.navigation.currentEntry; 17 let from_entry_after_nav = i.contentWindow.navigation.activation.from; 18 19 // activation.entry is the current entry. activation.from is a new 20 // NavigationHistoryEntry object (because there is a new window), with the 21 // same key/id/url as before the navigation, and an index of -1 because it is 22 // not present in the entries array. 23 assert_equals(i.contentWindow.navigation.entries().length, 1); 24 assert_equals(i.contentWindow.navigation.activation.entry, current_entry_after_nav); 25 assert_equals(i.contentWindow.navigation.activation.entry.index, 0); 26 assert_equals(from_entry_after_nav.key, before_key); 27 assert_equals(from_entry_after_nav.id, before_id); 28 assert_equals(from_entry_after_nav.url, before_url); 29 assert_equals(from_entry_after_nav.index, -1); 30 assert_equals(i.contentWindow.navigation.activation.navigationType, "replace"); 31 32 await i.contentWindow.navigation.navigate("/common/blank.html?a#fragment", { history: "replace" }).finished; 33 34 // activation.entry is no longer navigation.currentEntry and is disposed. 35 // activation.from has not changed. 36 assert_equals(i.contentWindow.navigation.entries().length, 1); 37 assert_equals(i.contentWindow.navigation.activation.entry, current_entry_after_nav); 38 assert_not_equals(i.contentWindow.navigation.activation.entry, 39 i.contentWindow.navigation.currentEntry); 40 assert_equals(i.contentWindow.navigation.activation.entry.index, -1); 41 assert_equals(i.contentWindow.navigation.activation.from, from_entry_after_nav); 42 assert_equals(i.contentWindow.navigation.activation.navigationType, "replace"); 43 }, "navigation.activation after replace"); 44 </script>