pushstate.https.html (2860B)
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 // Tests what happens when doing history navigation to an entry that's created 10 // via pushState, with and without BFCache: 11 // 1. Navigate to `urlA`. 12 // 2. `pushState(urlPushState)`. 13 // 3. Navigate to `urlB`. 14 // 4. Do a back navigation. 15 // With BFCache, the page loaded at Step 1 is restored from BFCache, 16 // and is not reloaded from `urlPushState` nor `urlA`. 17 // Without BFCache, a page is loaded from `urlPushState`, not from `urlA`. 18 // In both cases, `location` and `history.state` are set to those set by 19 // `pushState()` in Step 2. 20 // See https://github.com/whatwg/html/issues/6207 for more discussion on the 21 // specified, implemented and desired behaviors. While this test contradicts 22 // the current spec but matches the desired behavior, and the spec will be 23 // fixed as part of https://github.com/whatwg/html/pull/6315. 24 for (const bfcacheDisabled of [false, true]) { 25 const pushStateExecutorPath = 26 '/html/browsers/browsing-the-web/back-forward-cache/resources/executor-pushstate.html'; 27 28 runBfcacheTest({ 29 funcBeforeNavigation: async (bfcacheDisabled, pushStateExecutorPath) => { 30 const urlPushState = new URL(location.href); 31 urlPushState.pathname = pushStateExecutorPath; 32 if (bfcacheDisabled) { 33 await disableBFCache(); 34 } 35 36 // `pushState(..., urlPushState)` on `urlA`, 37 history.pushState('blue', '', urlPushState.href); 38 }, 39 argsBeforeNavigation: [bfcacheDisabled, pushStateExecutorPath], 40 shouldBeCached: !bfcacheDisabled, 41 funcAfterAssertion: async (pageA) => { 42 // We've navigated to `urlB` and back again 43 // (already done within `runBfcacheTest()`). 44 // After the back navigation, `location` etc. should point to 45 // `urlPushState` and the state that's pushed. 46 const urlPushState = location.origin + pushStateExecutorPath + 47 '?uuid=' + pageA.context_id; 48 assert_equals(await pageA.execute_script(() => location.href), 49 urlPushState, 'url'); 50 assert_equals(await pageA.execute_script(() => history.state), 51 'blue', 'history.state'); 52 53 if (bfcacheDisabled) { 54 // When the page is not restored from BFCache, the HTML page is loaded 55 // from `urlPushState` (not from `urlA`). 56 assert_true(await pageA.execute_script(() => isLoadedFromPushState), 57 'document should be loaded from urlPushState'); 58 } 59 } 60 }, 'back navigation to pushState()d page (' + 61 (bfcacheDisabled ? 'not ' : '') + 'in BFCache)'); 62 } 63 </script>