Skip to content

Commit c2be01e

Browse files
domenicmoz-wptsync-bot
authored andcommitted
Bug 1794378 [wpt PR 36368] - history.state during a bfcache traversal, a=testonly
Automatic update from web-platform-tests history.state during a bfcache traversal Per whatwg/html#6652, it must not get serialized and deserialized. -- wpt-commits: 7d60342ce41a95f4db1e57dd324917a9bc8bf730 wpt-pr: 36368
1 parent f02b87c commit c2be01e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// META: title=Navigating back to a bfcached page does not reset history.state
2+
// META: script=/common/dispatcher/dispatcher.js
3+
// META: script=/common/utils.js
4+
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
5+
6+
// See https://github.com/whatwg/html/issues/6652.
7+
8+
'use strict';
9+
10+
promise_test(async t => {
11+
const rcHelper = new RemoteContextHelper();
12+
13+
// Open a window with noopener so that BFCache will work.
14+
const rc = await rcHelper.addWindow(null, { features: "noopener" });
15+
16+
// Add a pageshow listener to stash the event, and set history.state using replaceState().
17+
await rc.executeScript(() => {
18+
window.addEventListener('pageshow', (event) => {
19+
window.pageshowEvent = event;
20+
});
21+
22+
history.replaceState({ foo: 'bar' }, '', '');
23+
window.stashedHistoryState = history.state;
24+
});
25+
26+
const rc2 = await rc.navigateToNew();
27+
await rc2.historyBack();
28+
29+
assert_implements_optional(
30+
await rc.executeScript(() => window.pageshowEvent.persisted),
31+
'precondition: document was bfcached'
32+
);
33+
34+
assert_equals(
35+
await rc.executeScript(() => history.state.foo),
36+
'bar',
37+
'history.state was restored correctly'
38+
);
39+
40+
assert_true(
41+
await rc.executeScript(() => window.stashedHistoryState === history.state),
42+
'history.state did not get serialized and deserialized');
43+
});

0 commit comments

Comments
 (0)