|
| 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> |
0 commit comments