navigation-traverseTo-in-iframe-same-document-preventDefault.html (2435B)
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 <iframe id="i" src="/common/blank.html"></iframe> 6 <script> 7 promise_test(async t => { 8 let start_length = navigation.entries().length; 9 let start_index = navigation.currentEntry.index; 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 // Navigate the iframe, then the top window, so that when the iframe goes back 16 // to its initial entry, the top window navigates as well. 17 await i.contentWindow.navigation.navigate("#").finished; 18 await navigation.navigate("#").finished; 19 assert_equals(navigation.entries().length, start_length + 1); 20 assert_equals(i.contentWindow.navigation.entries().length, 2); 21 assert_equals(navigation.currentEntry.index, start_index + 1); 22 assert_equals(i.contentWindow.navigation.currentEntry.index, 1); 23 24 // Ensure the top window, which is allowed to cancel the traversal, does so. 25 navigation.onnavigate = e => e.preventDefault(); 26 27 let top_navigateerror_fired = false; 28 navigation.onnavigateerror = t.step_func(e => { 29 assert_equals(e.constructor, ErrorEvent); 30 assert_equals(e.filename, location.href); 31 top_navigateerror_fired = true; 32 }); 33 34 i.contentWindow.navigation.onnavigate = t.unreached_func("navigate event should not fire in the iframe, because the traversal was cancelled in the top window"); 35 i.contentWindow.navigation.onnavigateerror = t.unreached_func("navigateerror event should not fire in the iframe, because the navigate event was not fired"); 36 37 // When the top window blocks the traversal, it should be blocked in the 38 // iframe as well, and the traversal promises in the iframe should be rejected. 39 const iWindow = i.contentWindow; 40 const iDOMException = iWindow.DOMException; 41 await assertBothRejectDOM(t, i.contentWindow.navigation.traverseTo(i.contentWindow.navigation.entries()[0].key), "AbortError", iWindow, iDOMException); 42 assert_true(top_navigateerror_fired); 43 assert_equals(navigation.currentEntry.index, start_index + 1); 44 assert_equals(i.contentWindow.navigation.currentEntry.index, 1); 45 }, "navigation.traverseTo() in an iframe with same-document preventDefault in its parent"); 46 </script>