Skip to content

Commit

Permalink
[WPT] BFCache: pushState() works in the same way as non-BFCache case
Browse files Browse the repository at this point in the history
Bug: 1107415, whatwg/html#6207
Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
  • Loading branch information
hiroshige-g authored and chromium-wpt-export-bot committed Jan 16, 2022
1 parent 1dd414c commit eb1d370
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="resources/helper.sub.js"></script>
<script>
// See https://github.com/whatwg/html/issues/6207 for discussion on the
// specified, implemented and desired behaviors.
for (const bfcacheDisabled of [false, true]) {
runBfcacheTest({
funcBeforeNavigation: async (bfcacheDisabled) => {
const urlPushState = location.href + '&pipe=sub';
if (bfcacheDisabled) {
await disableBFCache();
}

// `pushState(..., urlPushState)` on `urlA`,
history.pushState('blue', '', urlPushState);
},
argsBeforeNavigation: [bfcacheDisabled],
shouldBeCached: !bfcacheDisabled,
funcAfterAssertion: async (pageA) => {
const urlA = location.origin + executorPath + pageA.context_id;
const urlPushState = urlA + '&pipe=sub';

// and then navigate to `urlB` and then back navigate
// (already done within `runBfcacheTest()`).
// After the back navigation, `location` etc. should point to
// `urlPushState` and the state that's pushed.
assert_equals(await pageA.execute_script(() => location.href),
urlPushState, 'url');
assert_equals(await pageA.execute_script(() => history.state),
'blue', 'history.state');

if (bfcacheDisabled) {
// When the page is not restored from BFCache, the HTML page is loaded
// from `urlPushState` (not from `urlA`).
// To detect whether the page is loaded from `urlA` or `urlPushState`,
// we check whether `pipe=sub` is enabled on the executor.
const loadedFromUrlPushState =
await pageA.execute_script(() => hasPipeSub);
assert_true(loadedFromUrlPushState,
'document should be loaded from urlPushState with pipe=sub');
}
}
}, 'back navigation to pushState()d page (' +
(bfcacheDisabled ? 'not ' : '') + 'in BFCache)');
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,24 @@
{once: true});
executor.suspend(callback);
}

// Try to disable BFCache by acquiring and never releasing a Web Lock.
// This requires HTTPS.
// Note: This is a workaround depending on non-specified WebLock+BFCache
// behavior. We might want to introduce a test-only BFCache-disabling API
// instead in the future.
window.disableBFCache = () => {
return new Promise(resolve => {
// Use page's UUID as a unique lock name.
navigator.locks.request(uuid, () => {
resolve();
return new Promise(() => {});
});
});
};

// Indicates whether this page is served with `pipe=sub`.
// This is used by `pushstate.https.html` to detect the executor is loaded from
// a URL with or without `pipe=sub`.
window.hasPipeSub = '{{GET[uuid]}}' === uuid;
</script>

0 comments on commit eb1d370

Please sign in to comment.