|
| 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