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