Skip to content

Commit 4fc1186

Browse files
[WPT] BFCache: pushState() works in the same way as non-BFCache case
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
1 parent 679cfd4 commit 4fc1186

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
7+
<script src="resources/helper.sub.js"></script>
8+
<script>
9+
// `pushState()` should work in the same way regardless of whether the page is
10+
// restored from BFCache or not.
11+
for (const shouldBeBFCached of [true, false]) {
12+
promise_test(async t => {
13+
const pageA = new RemoteContext(token());
14+
const pageB = new RemoteContext(token());
15+
16+
let urlA = location.origin + executorPath + pageA.context_id;
17+
if (!shouldBeBFCached) {
18+
// Try to disable BFCache.
19+
urlA += '&pipe=header(Cache-Control,no-store)';
20+
}
21+
const urlPushState = urlA + '&pushState=yes';
22+
const urlB = originCrossSite + executorPath + pageB.context_id;
23+
24+
window.open(urlA, '_blank', 'noopener');
25+
26+
// `pushState(..., urlPushState)` on `urlA`.
27+
await pageA.execute_script(waitForPageShow);
28+
await pageA.execute_script(
29+
(url) => history.pushState('blue', '', url),
30+
[urlPushState]);
31+
32+
// Navigate to `urlB`.
33+
await pageA.execute_script(
34+
(url) => prepareNavigation(() => {
35+
location.href = url;
36+
}),
37+
[urlB]);
38+
39+
// Back navigate and check whether the page is restored from BFCache.
40+
await pageB.execute_script(waitForPageShow);
41+
await pageB.execute_script(
42+
() => {
43+
prepareNavigation(() => { history.back(); });
44+
}
45+
);
46+
if (shouldBeBFCached) {
47+
await assert_bfcached(pageA);
48+
} else {
49+
await assert_not_bfcached(pageA);
50+
}
51+
52+
// `location` etc. should point to what are `pushState()`d.
53+
assert_equals(await pageA.execute_script(() => location.href),
54+
urlPushState, 'url 1');
55+
assert_equals(await pageA.execute_script(() => history.state),
56+
'blue', 'history.state 1');
57+
58+
// `history.back()` and then wait for `onpopstate`.
59+
await pageA.execute_script(() => new Promise(resolve => {
60+
window.onpopstate = () => resolve();
61+
history.back();
62+
}));
63+
64+
// `location` etc. should point to the original URL before `pushState()`.
65+
assert_equals(await pageA.execute_script(() => location.href),
66+
urlA, 'url 2');
67+
assert_equals(await pageA.execute_script(() => history.state),
68+
null, 'history.state 2');
69+
}, 'back navigation to pushState()d page (' +
70+
(shouldBeBFCached ? '' : 'not ') + 'in BFCache)');
71+
}
72+
</script>

0 commit comments

Comments
 (0)