same-document-nav-cross-document-traversal.html (2675B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Traversal after a same-document navigations</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <!-- 8 These tests are kind of silly since it's hard to imagine any other result: 9 same-document navigations are always synchronous so of course back() won't 10 cancel them. 11 12 Nevertheless they're nice as a basis from which to write corresponding app 13 history tests, where the consequences aren't as obvious. 14 --> 15 16 <body> 17 <script type="module"> 18 import { createIframe, waitForLoad, delay } from "./resources/helpers.mjs"; 19 20 promise_test(async t => { 21 const iframe = await createIframe(t); 22 23 // Setup 24 // Extra delay()s are necessary because if we navigate "inside" the load 25 // handler (i.e. in a promise reaction for the load handler) then it will 26 // be a replace navigation. 27 iframe.contentWindow.location.search = "?1"; 28 await waitForLoad(iframe); 29 await delay(t, 0); 30 iframe.contentWindow.location.search = "?2"; 31 await waitForLoad(iframe); 32 await delay(t, 0); 33 34 iframe.contentWindow.location.hash = "#3"; 35 iframe.contentWindow.history.go(-2); 36 37 assert_equals(iframe.contentWindow.location.search, "?2", "must not go back synchronously (search)"); 38 assert_equals(iframe.contentWindow.location.hash, "#3", "must not go back synchronously (hash)"); 39 40 await waitForLoad(iframe); 41 assert_equals(iframe.contentWindow.location.search, "?1", "must go back eventually (search)"); 42 assert_equals(iframe.contentWindow.location.hash, "", "must go back eventually (hash)"); 43 }, "fragment navigation then go(-2)"); 44 45 promise_test(async t => { 46 const iframe = await createIframe(t); 47 48 // Setup 49 // Extra delay()s are necessary because if we navigate "inside" the load 50 // handler (i.e. in a promise reaction for the load handler) then it will 51 // be a replace navigation. 52 iframe.contentWindow.location.search = "?1"; 53 await waitForLoad(iframe); 54 await delay(t, 0); 55 iframe.contentWindow.location.search = "?2"; 56 await waitForLoad(iframe); 57 await delay(t, 0); 58 59 iframe.contentWindow.history.pushState(null, "", "/3"); 60 iframe.contentWindow.history.go(-2); 61 62 assert_equals(iframe.contentWindow.location.search, "", "must not go back synchronously (search)"); 63 assert_equals(iframe.contentWindow.location.pathname, "/3", "must not go back synchronously (pathname)"); 64 65 await waitForLoad(iframe); 66 assert_equals(iframe.contentWindow.location.search, "?1", "must go back eventually (search)"); 67 assert_equals(iframe.contentWindow.location.pathname, "/common/blank.html", "must go back eventually (pathname)"); 68 69 }, "pushState then go(-2)"); 70 </script>