cross-document-traversal-same-document-nav.html (2332B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Same-document navigations during cross-document traversals</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <!-- 8 The spec explicitly covers this case, with a Jake diagram: 9 https://whatpr.org/html/6315/browsing-the-web.html#example-sync-navigation-steps-queue-jumping-basic 10 --> 11 12 <body> 13 <script type="module"> 14 import { createIframe, waitForLoad, delay } from "./resources/helpers.mjs"; 15 16 promise_test(async t => { 17 const iframe = await createIframe(t); 18 19 // Setup 20 // Extra delay()s are necessary because if we navigate "inside" the load 21 // handler (i.e. in a promise reaction for the load handler) then it will 22 // be a replace navigation. 23 iframe.contentWindow.location.search = "?1"; 24 await waitForLoad(iframe); 25 await delay(t, 0); 26 iframe.contentWindow.location.search = "?2"; 27 await waitForLoad(iframe); 28 await delay(t, 0); 29 30 iframe.contentWindow.history.back(); 31 32 assert_equals(iframe.contentWindow.location.search, "?2", "must not go back synchronously"); 33 34 iframe.contentWindow.location.hash = "#3"; 35 assert_equals(iframe.contentWindow.location.search, "?2"); 36 assert_equals(iframe.contentWindow.location.hash, "#3"); 37 38 // Eventually ends up on ?1 39 await t.step_wait(() => iframe.contentWindow.location.search === "?1" && iframe.contentWindow.location.hash === ""); 40 }, "same-document traversals + fragment navigations"); 41 42 promise_test(async t => { 43 const iframe = await createIframe(t); 44 45 // Setup 46 // Extra delay()s are necessary because if we navigate "inside" the load 47 // handler (i.e. in a promise reaction for the load handler) then it will 48 // be a replace navigation. 49 iframe.contentWindow.location.search = "?1"; 50 await waitForLoad(iframe); 51 await delay(t, 0); 52 iframe.contentWindow.location.search = "?2"; 53 await waitForLoad(iframe); 54 await delay(t, 0); 55 56 iframe.contentWindow.history.back(); 57 58 assert_equals(iframe.contentWindow.location.search, "?2", "must not go back synchronously"); 59 60 iframe.contentWindow.history.pushState(null, "", "?3"); 61 assert_equals(iframe.contentWindow.location.search, "?3"); 62 63 // Eventually ends up on ?1 64 await t.step_wait(() => iframe.contentWindow.location.search === "?1"); 65 }, "same-document traversals + pushState()"); 66 </script>