same-document-traversal-same-document-traversal-pushstate.html (6376B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Same-document traversals during same-document traversals (using pushState())</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, waitForPopstate } from "./resources/helpers.mjs"; 18 19 promise_test(async t => { 20 const iframe = await createIframe(t); 21 22 // Setup 23 iframe.contentWindow.history.pushState(1, "", "/1"); 24 assert_equals(iframe.contentWindow.location.pathname, "/1", "setup /1"); 25 iframe.contentWindow.history.pushState(2, "", "/2"); 26 assert_equals(iframe.contentWindow.location.pathname, "/2", "setup /2"); 27 iframe.contentWindow.history.pushState(3, "", "/3"); 28 assert_equals(iframe.contentWindow.location.pathname, "/3", "setup /3"); 29 iframe.contentWindow.history.back(); 30 await waitForPopstate(iframe.contentWindow); 31 assert_equals(iframe.contentWindow.location.pathname, "/2", "we made our way to /2 for setup"); 32 33 iframe.contentWindow.history.back(); 34 assert_equals(iframe.contentWindow.location.pathname, "/2", "must not go back synchronously"); 35 36 iframe.contentWindow.history.forward(); 37 assert_equals(iframe.contentWindow.location.pathname, "/2", "must not go forward synchronously"); 38 39 const event1 = await waitForPopstate(iframe.contentWindow); 40 assert_equals(event1.state, 1, "state 1"); 41 // Cannot test iframe.contentWindow.location.pathname since the second history 42 // traversal task is racing with the fire an event task, so we don't know 43 // which will happen first. 44 45 const event2 = await waitForPopstate(iframe.contentWindow); 46 assert_equals(event2.state, 2, "state 2"); 47 assert_equals(iframe.contentWindow.location.pathname, "/2"); 48 }, "same-document traversals in opposite directions: queued up"); 49 50 promise_test(async t => { 51 const iframe = await createIframe(t); 52 53 // Setup 54 iframe.contentWindow.history.pushState(1, "", "/1"); 55 assert_equals(iframe.contentWindow.location.pathname, "/1", "setup /1"); 56 iframe.contentWindow.history.pushState(2, "", "/2"); 57 assert_equals(iframe.contentWindow.location.pathname, "/2", "we made our way to /2 for setup"); 58 59 iframe.contentWindow.history.back(); 60 assert_equals(iframe.contentWindow.location.pathname, "/2", "must not go back synchronously"); 61 62 iframe.contentWindow.history.forward(); 63 assert_equals(iframe.contentWindow.location.pathname, "/2", "must not go forward synchronously"); 64 65 const event1 = await waitForPopstate(iframe.contentWindow); 66 assert_equals(event1.state, 1, "state 1"); 67 // Cannot test iframe.contentWindow.location.pathname since the second history 68 // traversal task is racing with the fire an event task, so we don't know 69 // which will happen first. 70 71 const event2 = await waitForPopstate(iframe.contentWindow); 72 assert_equals(event2.state, 2, "state 2"); 73 assert_equals(iframe.contentWindow.location.pathname, "/2"); 74 }, "same-document traversals in opposite directions, second traversal invalid at queuing time: queued up"); 75 76 promise_test(async t => { 77 const iframe = await createIframe(t); 78 79 // Setup 80 iframe.contentWindow.history.pushState(1, "", "/1"); 81 assert_equals(iframe.contentWindow.location.pathname, "/1", "setup /1"); 82 iframe.contentWindow.history.pushState(2, "", "/2"); 83 assert_equals(iframe.contentWindow.location.pathname, "/2", "setup /2"); 84 iframe.contentWindow.history.pushState(3, "", "/3"); 85 assert_equals(iframe.contentWindow.location.pathname, "/3", "we made our way to /3 for setup"); 86 87 iframe.contentWindow.history.back(); 88 assert_equals(iframe.contentWindow.location.pathname, "/3", "must not go back synchronously (1)"); 89 90 iframe.contentWindow.history.back(); 91 assert_equals(iframe.contentWindow.location.pathname, "/3", "must not go back synchronously (2)"); 92 93 const event1 = await waitForPopstate(iframe.contentWindow); 94 assert_equals(event1.state, 2, "state 1"); 95 // Cannot test iframe.contentWindow.location.pathname since the second history 96 // traversal task is racing with the fire an event task, so we don't know 97 // which will happen first. 98 99 const event2 = await waitForPopstate(iframe.contentWindow); 100 assert_equals(event2.state, 1, "state 2"); 101 assert_equals(iframe.contentWindow.location.pathname, "/1"); 102 }, "same-document traversals in the same (back) direction: queue up"); 103 104 promise_test(async t => { 105 const iframe = await createIframe(t); 106 107 // Setup 108 iframe.contentWindow.history.pushState(1, "", "/1"); 109 assert_equals(iframe.contentWindow.location.pathname, "/1", "setup /1"); 110 iframe.contentWindow.history.pushState(2, "", "/2"); 111 assert_equals(iframe.contentWindow.location.pathname, "/2", "setup /2"); 112 iframe.contentWindow.history.pushState(3, "", "/3"); 113 assert_equals(iframe.contentWindow.location.pathname, "/3", "setup /3"); 114 iframe.contentWindow.history.back(); 115 await waitForPopstate(iframe.contentWindow); 116 assert_equals(iframe.contentWindow.location.pathname, "/2", "setup /2 again"); 117 iframe.contentWindow.history.back(); 118 await waitForPopstate(iframe.contentWindow); 119 assert_equals(iframe.contentWindow.location.pathname, "/1", "we made our way to /1 for setup"); 120 121 iframe.contentWindow.history.forward(); 122 assert_equals(iframe.contentWindow.location.pathname, "/1", "must not go forward synchronously (1)"); 123 124 iframe.contentWindow.history.forward(); 125 assert_equals(iframe.contentWindow.location.pathname, "/1", "must not go forward synchronously (2)"); 126 127 const event1 = await waitForPopstate(iframe.contentWindow); 128 assert_equals(event1.state, 2, "state 1"); 129 // Cannot test iframe.contentWindow.location.pathname since the second history 130 // traversal task is racing with the fire an event task, so we don't know 131 // which will happen first. 132 133 const event2 = await waitForPopstate(iframe.contentWindow); 134 assert_equals(event2.state, 3, "state 2"); 135 assert_equals(iframe.contentWindow.location.pathname, "/3"); 136 }, "same-document traversals in the same (forward) direction: queue up"); 137 </script>