cross-document-traversal-cross-document-nav.html (3040B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Cross-document navigations during cross-document traversals</title> 4 <meta name="timeout" content="long"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <!-- 9 According to the spec, if ongoing navigation is "traversal", the navigation 10 fails and nothing happens. 11 --> 12 13 <body> 14 <script type="module"> 15 import { createIframe, waitForLoad, delay, waitForPotentialNetworkLoads } from "./resources/helpers.mjs"; 16 17 promise_test(async t => { 18 const iframe = await createIframe(t); 19 const slowURL = (new URL("resources/slow.py", location.href)).href; 20 21 // Setup 22 // Extra delay()s are necessary because if we navigate "inside" the load 23 // handler (i.e. in a promise reaction for the load handler) then it will 24 // be a replace navigation. 25 iframe.contentWindow.location.href = slowURL; 26 await waitForLoad(iframe); 27 await delay(t, 0); 28 iframe.contentWindow.location.href = "/common/blank.html?2"; 29 await waitForLoad(iframe); 30 await delay(t, 0); 31 32 iframe.contentWindow.history.back(); 33 34 assert_equals(iframe.contentWindow.location.search, "?2", "must not go back synchronously"); 35 36 iframe.contentWindow.location.href = "/common/blank.html?3"; 37 assert_equals(iframe.contentWindow.location.search, "?2", "must not navigate synchronously"); 38 39 // We end up at slow.py and never at /common/blank.html?3 40 await waitForLoad(iframe); 41 assert_equals(iframe.contentWindow.location.href, slowURL, "first load after the nav"); 42 43 await waitForPotentialNetworkLoads(t); 44 assert_equals(iframe.contentWindow.location.href, slowURL, "must stay on slow.py"); 45 }, "slow cross-document traversal and then fast cross-document navigation: traversal wins and nav is ignored"); 46 47 promise_test(async t => { 48 const iframe = await createIframe(t); 49 const slowURL = (new URL("resources/slow.py", location.href)).href; 50 51 // Setup 52 // Extra delay()s are necessary because if we navigate "inside" the load 53 // handler (i.e. in a promise reaction for the load handler) then it will 54 // be a replace navigation. 55 iframe.contentWindow.location.search = "?1"; 56 await waitForLoad(iframe); 57 await delay(t, 0); 58 iframe.contentWindow.location.search = "?2"; 59 await waitForLoad(iframe); 60 await delay(t, 0); 61 62 iframe.contentWindow.history.back(); 63 64 assert_equals(iframe.contentWindow.location.search, "?2", "must not go back synchronously"); 65 66 iframe.contentWindow.location.href = slowURL; 67 assert_equals(iframe.contentWindow.location.search, "?2", "must not navigate synchronously"); 68 69 // We end up at ?1 and never at slowURL 70 await waitForLoad(iframe); 71 assert_equals(iframe.contentWindow.location.search, "?1", "first load after the nav"); 72 73 // The long timeout is because slow.py would take 2 seconds, if it did load. 74 await delay(t, 3000); 75 assert_equals(iframe.contentWindow.location.search, "?1", "must stay on ?1"); 76 }, "fast cross-document traversal and then slow cross-document navigation: traversal wins and nav is ignored"); 77 </script>