same-document-traversal-same-document-traversal-hashchange.html (6630B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Same-document traversals during same-document traversals (using fragment navigations)</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <!-- 8 Compare this to cross-document-traversal-cross-document-traversal.html. Since 9 there are no network loads or document unloads to cancel tasks, both 10 traversals should observably go through. Target step calculation for the 11 second traversal should take place after the first traversal is finished. So 12 we end up with both traversals observable in sequence. 13 --> 14 15 <body> 16 <script type="module"> 17 import { createIframe, delay, waitForHashchange } from "./resources/helpers.mjs"; 18 19 promise_test(async t => { 20 const iframe = await createIframe(t); 21 const baseURL = iframe.contentWindow.location.href; 22 23 // Setup 24 iframe.contentWindow.location.hash = "#1"; 25 await waitForHashchange(iframe.contentWindow); 26 iframe.contentWindow.location.hash = "#2"; 27 await waitForHashchange(iframe.contentWindow); 28 iframe.contentWindow.location.hash = "#3"; 29 await waitForHashchange(iframe.contentWindow); 30 iframe.contentWindow.history.back(); 31 await waitForHashchange(iframe.contentWindow); 32 assert_equals(iframe.contentWindow.location.hash, "#2", "we made our way to #2 for setup"); 33 34 iframe.contentWindow.history.back(); 35 assert_equals(iframe.contentWindow.location.hash, "#2", "must not go back synchronously"); 36 37 iframe.contentWindow.history.forward(); 38 assert_equals(iframe.contentWindow.location.hash, "#2", "must not go forward synchronously"); 39 40 const event1 = await waitForHashchange(iframe.contentWindow); 41 assert_equals(event1.oldURL, baseURL + "#2", "oldURL 1"); 42 assert_equals(event1.newURL, baseURL + "#1", "newURL 1"); 43 // Cannot test iframe.contentWindow.location.hash since the second history 44 // traversal task is racing with the fire an event task, so we don't know 45 // which will happen first. 46 47 const event2 = await waitForHashchange(iframe.contentWindow); 48 assert_equals(event2.oldURL, baseURL + "#1", "oldURL 2"); 49 assert_equals(event2.newURL, baseURL + "#2", "newURL 2"); 50 assert_equals(iframe.contentWindow.location.hash, "#2"); 51 }, "same-document traversals in opposite directions: queued up"); 52 53 promise_test(async t => { 54 const iframe = await createIframe(t); 55 const baseURL = iframe.contentWindow.location.href; 56 57 // Setup 58 iframe.contentWindow.location.hash = "#1"; 59 await waitForHashchange(iframe.contentWindow); 60 iframe.contentWindow.location.hash = "#2"; 61 await waitForHashchange(iframe.contentWindow); 62 63 iframe.contentWindow.history.back(); 64 assert_equals(iframe.contentWindow.location.hash, "#2", "must not go back synchronously"); 65 66 iframe.contentWindow.history.forward(); 67 assert_equals(iframe.contentWindow.location.hash, "#2", "must not go forward synchronously"); 68 69 const event1 = await waitForHashchange(iframe.contentWindow); 70 assert_equals(event1.oldURL, baseURL + "#2", "oldURL 1"); 71 assert_equals(event1.newURL, baseURL + "#1", "newURL 1"); 72 // Cannot test iframe.contentWindow.location.hash since the second history 73 // traversal task is racing with the fire an event task, so we don't know 74 // which will happen first. 75 76 const event2 = await waitForHashchange(iframe.contentWindow); 77 assert_equals(event2.oldURL, baseURL + "#1", "oldURL 2"); 78 assert_equals(event2.newURL, baseURL + "#2", "newURL 2"); 79 assert_equals(iframe.contentWindow.location.hash, "#2"); 80 }, "same-document traversals in opposite directions, second traversal invalid at queuing time: queued up"); 81 82 promise_test(async t => { 83 const iframe = await createIframe(t); 84 const baseURL = iframe.contentWindow.location.href; 85 86 // Setup 87 iframe.contentWindow.location.hash = "#1"; 88 await waitForHashchange(iframe.contentWindow); 89 iframe.contentWindow.location.hash = "#2"; 90 await waitForHashchange(iframe.contentWindow); 91 iframe.contentWindow.location.hash = "#3"; 92 await waitForHashchange(iframe.contentWindow); 93 94 iframe.contentWindow.history.back(); 95 assert_equals(iframe.contentWindow.location.hash, "#3", "must not go back synchronously (1)"); 96 97 iframe.contentWindow.history.back(); 98 assert_equals(iframe.contentWindow.location.hash, "#3", "must not go back synchronously (2)"); 99 100 const event1 = await waitForHashchange(iframe.contentWindow); 101 assert_equals(event1.oldURL, baseURL + "#3", "oldURL 1"); 102 assert_equals(event1.newURL, baseURL + "#2", "newURL 1"); 103 // Cannot test iframe.contentWindow.location.hash since the second history 104 // traversal task is racing with the fire an event task, so we don't know 105 // which will happen first. 106 107 const event2 = await waitForHashchange(iframe.contentWindow); 108 assert_equals(event2.oldURL, baseURL + "#2", "oldURL 2"); 109 assert_equals(event2.newURL, baseURL + "#1", "newURL 2"); 110 assert_equals(iframe.contentWindow.location.hash, "#1"); 111 }, "same-document traversals in the same (back) direction: queue up"); 112 113 promise_test(async t => { 114 const iframe = await createIframe(t); 115 const baseURL = iframe.contentWindow.location.href; 116 117 // Setup 118 iframe.contentWindow.location.hash = "#1"; 119 await waitForHashchange(iframe.contentWindow); 120 iframe.contentWindow.location.hash = "#2"; 121 await waitForHashchange(iframe.contentWindow); 122 iframe.contentWindow.location.hash = "#3"; 123 await waitForHashchange(iframe.contentWindow); 124 iframe.contentWindow.history.back(); 125 await waitForHashchange(iframe.contentWindow); 126 iframe.contentWindow.history.back(); 127 await waitForHashchange(iframe.contentWindow); 128 assert_equals(iframe.contentWindow.location.hash, "#1", "we made our way to #1 for setup"); 129 130 iframe.contentWindow.history.forward(); 131 assert_equals(iframe.contentWindow.location.hash, "#1", "must not go forward synchronously (1)"); 132 133 iframe.contentWindow.history.forward(); 134 assert_equals(iframe.contentWindow.location.hash, "#1", "must not go forward synchronously (2)"); 135 136 const event1 = await waitForHashchange(iframe.contentWindow); 137 assert_equals(event1.oldURL, baseURL + "#1", "oldURL 1"); 138 assert_equals(event1.newURL, baseURL + "#2", "newURL 1"); 139 // Cannot test iframe.contentWindow.location.hash since the second history 140 // traversal task is racing with the fire an event task, so we don't know 141 // which will happen first. 142 143 const event2 = await waitForHashchange(iframe.contentWindow); 144 assert_equals(event2.oldURL, baseURL + "#2", "oldURL 2"); 145 assert_equals(event2.newURL, baseURL + "#3", "newURL 2"); 146 assert_equals(iframe.contentWindow.location.hash, "#3"); 147 }, "same-document traversals in the same (forward) direction: queue up"); 148 </script>