dispose-skip-current-on-truncate.html (2191B)
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 let start_length = navigation.entries().length; 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(r => window.onload = () => t.step_timeout(r, 0)); 12 await navigation.navigate("#1").finished; 13 assert_equals(navigation.entries().length, start_length + 1); 14 15 let iframe = document.createElement("iframe"); 16 iframe.src = "/common/blank.html"; 17 document.body.appendChild(iframe); 18 await new Promise(r => iframe.onload = () => t.step_timeout(r, 0)); 19 assert_equals(iframe.contentWindow.navigation.entries().length, 1); 20 21 // Go back to before the iframe was added. The iframe will still be in the 22 // document, but we will be at a joint session history entry that was created 23 // before the iframe was added to the document. 24 await navigation.back().finished; 25 assert_equals(navigation.entries().length, start_length + 1); 26 assert_equals(iframe.contentWindow.navigation.entries().length, 1); 27 assert_equals(navigation.currentEntry.index, start_index); 28 assert_equals(iframe.contentWindow.navigation.currentEntry.index, 0); 29 30 // A push navigation in the top window will truncate-then-push the joint 31 // session history. This should dispose the forward entry in the top window, 32 // but should not interfere with the currentEntry in the iframe. 33 let dispose_promise = new Promise(r => navigation.entries()[start_index + 1].ondispose = r); 34 iframe.contentWindow.navigation.currentEntry.ondispose = t.unreached_func("iframe entry must not be disposed"); 35 await navigation.navigate("#b").finished; 36 37 await dispose_promise; 38 assert_equals(navigation.entries().length, start_length + 1); 39 assert_equals(iframe.contentWindow.navigation.entries().length, 1); 40 assert_equals(navigation.currentEntry.index, start_index + 1); 41 assert_equals(iframe.contentWindow.navigation.currentEntry.index, 0); 42 }, "Removing a currentEntry from the joint session history shouldn't dispose it"); 43 </script>