From f88b86b8fc7c1f294d87b0e9df48648afb23ab14 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 10 Oct 2022 19:38:17 +0900 Subject: [PATCH 1/2] history.state during a bfcache traversal Per https://github.com/whatwg/html/issues/6652, it must not get serialized and deserialized. --- .../history-state-after-bfcache.window.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 html/browsers/history/the-history-interface/history-state-after-bfcache.window.js diff --git a/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js b/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js new file mode 100644 index 00000000000000..12e40974d49fb4 --- /dev/null +++ b/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js @@ -0,0 +1,39 @@ +// META: title=Navigating back to a bfcached page does not reset history.state +// META: script=/common/dispatcher/dispatcher.js +// META: script=/common/utils.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js + +// See https://github.com/whatwg/html/issues/6652. + +'use strict'; + +promise_test(async t => { + const rcHelper = new RemoteContextHelper(); + + // Open a window with noopener so that BFCache will work. + const rc = await rcHelper.addWindow(null, { features: "noopener" }); + + // Add a pageshow listener to stash the event, and set history.state using replaceState(). + await rc.executeScript(() => { + window.addEventListener('pageshow', (event) => { + window.pageshowEvent = event; + }); + + history.replaceState({ foo: 'bar' }, '', ''); + window.stashedHistoryState = history.state; + }); + + const rc2 = await rc.navigateToNew(); + await rc2.historyBack(); + + assert_implements_optional( + await rc.executeScript(() => window.pageshowEvent.persisted), + 'precondition: document was bfcached' + ); + + assert_equals(await rc.executeScript(() => history.state.foo), 'bar', 'history.state was restored correctly'); + + assert_true( + await rc.executeScript(() => window.stashedHistoryState === history.state), + 'history.state did not get serialized and deserialized'); +}); From 28e2974b8ebb3382df4b6d0e813b6f8af1caee24 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 11 Oct 2022 11:37:07 +0900 Subject: [PATCH 2/2] wrap --- .../history-state-after-bfcache.window.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js b/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js index 12e40974d49fb4..5f04890a72805c 100644 --- a/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js +++ b/html/browsers/history/the-history-interface/history-state-after-bfcache.window.js @@ -31,7 +31,11 @@ promise_test(async t => { 'precondition: document was bfcached' ); - assert_equals(await rc.executeScript(() => history.state.foo), 'bar', 'history.state was restored correctly'); + assert_equals( + await rc.executeScript(() => history.state.foo), + 'bar', + 'history.state was restored correctly' + ); assert_true( await rc.executeScript(() => window.stashedHistoryState === history.state),