Skip to content

Commit eb1d370

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

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
// See https://github.com/whatwg/html/issues/6207 for discussion on the
10+
// specified, implemented and desired behaviors.
11+
for (const bfcacheDisabled of [false, true]) {
12+
runBfcacheTest({
13+
funcBeforeNavigation: async (bfcacheDisabled) => {
14+
const urlPushState = location.href + '&pipe=sub';
15+
if (bfcacheDisabled) {
16+
await disableBFCache();
17+
}
18+
19+
// `pushState(..., urlPushState)` on `urlA`,
20+
history.pushState('blue', '', urlPushState);
21+
},
22+
argsBeforeNavigation: [bfcacheDisabled],
23+
shouldBeCached: !bfcacheDisabled,
24+
funcAfterAssertion: async (pageA) => {
25+
const urlA = location.origin + executorPath + pageA.context_id;
26+
const urlPushState = urlA + '&pipe=sub';
27+
28+
// and then navigate to `urlB` and then back navigate
29+
// (already done within `runBfcacheTest()`).
30+
// After the back navigation, `location` etc. should point to
31+
// `urlPushState` and the state that's pushed.
32+
assert_equals(await pageA.execute_script(() => location.href),
33+
urlPushState, 'url');
34+
assert_equals(await pageA.execute_script(() => history.state),
35+
'blue', 'history.state');
36+
37+
if (bfcacheDisabled) {
38+
// When the page is not restored from BFCache, the HTML page is loaded
39+
// from `urlPushState` (not from `urlA`).
40+
// To detect whether the page is loaded from `urlA` or `urlPushState`,
41+
// we check whether `pipe=sub` is enabled on the executor.
42+
const loadedFromUrlPushState =
43+
await pageA.execute_script(() => hasPipeSub);
44+
assert_true(loadedFromUrlPushState,
45+
'document should be loaded from urlPushState with pipe=sub');
46+
}
47+
}
48+
}, 'back navigation to pushState()d page (' +
49+
(bfcacheDisabled ? 'not ' : '') + 'in BFCache)');
50+
}
51+
</script>

html/browsers/browsing-the-web/back-forward-cache/resources/executor.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,24 @@
4949
{once: true});
5050
executor.suspend(callback);
5151
}
52+
53+
// Try to disable BFCache by acquiring and never releasing a Web Lock.
54+
// This requires HTTPS.
55+
// Note: This is a workaround depending on non-specified WebLock+BFCache
56+
// behavior. We might want to introduce a test-only BFCache-disabling API
57+
// instead in the future.
58+
window.disableBFCache = () => {
59+
return new Promise(resolve => {
60+
// Use page's UUID as a unique lock name.
61+
navigator.locks.request(uuid, () => {
62+
resolve();
63+
return new Promise(() => {});
64+
});
65+
});
66+
};
67+
68+
// Indicates whether this page is served with `pipe=sub`.
69+
// This is used by `pushstate.https.html` to detect the executor is loaded from
70+
// a URL with or without `pipe=sub`.
71+
window.hasPipeSub = '{{GET[uuid]}}' === uuid;
5272
</script>

0 commit comments

Comments
 (0)