prefetch-traverse-reload.sub.html (3084B)
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/dispatcher/dispatcher.js"></script> 6 <script src="/common/utils.js"></script> 7 <script src="/websockets/constants.sub.js"></script> 8 <script src="../resources/utils.js"></script> 9 <script src="resources/utils.sub.js"></script> 10 <script> 11 setup(() => assertSpeculationRulesIsSupported()); 12 13 promise_test(async t => { 14 let agent = await spawnWindow(t, { protocol: 'https', pipe: 'header(Cache-Control, no-store)' }); 15 let previousUrl = await agent.execute_script(() => location.href); 16 await agent.execute_script(async () => { 17 window.preventBfcache = new WebSocket('wss://{{ports[wss][0]}}/echo'); 18 }); 19 20 let nextUrl = agent.getExecutorURL({ protocol: 'https', page: 2 }); 21 await agent.navigate(nextUrl); 22 23 await agent.forceSinglePrefetch(previousUrl); 24 await agent.execute_script(() => { 25 window.executor.suspend(() => history.go(-1)); 26 }); 27 28 assert_equals(previousUrl, await agent.execute_script(() => location.href)); 29 assert_prefetched(await agent.getRequestHeaders(), "traversal should use prefetch"); 30 }, "prefetches can be used for traversal navigations"); 31 32 promise_test(async t => { 33 let agent = await spawnWindow(t, { protocol: 'https', pipe: 'header(Cache-Control, no-store)' }); 34 let previousUrl = await agent.execute_script(() => location.href); 35 await agent.execute_script(async () => { 36 window.preventBfcache = new WebSocket('wss://{{ports[wss][0]}}/echo'); 37 }); 38 39 let nextUrl = agent.getExecutorURL({ protocol: 'https', page: 2 }); 40 await agent.navigate(nextUrl); 41 42 await agent.forceSinglePrefetch(previousUrl); 43 // In https://html.spec.whatwg.org/multipage/nav-history-apis.html#delta-traverse, 44 // `sourceDocument` is `History`'s relevant global object's associated 45 // Document. In this case, it's `iframe.contentDocument`, and thus the 46 // prefetch from `win`'s Document (iframe's parent Document) isn't used. 47 await agent.execute_script(() => { 48 window.executor.suspend(() => { 49 const iframe = document.createElement('iframe'); 50 document.body.appendChild(iframe); 51 iframe.contentWindow.history.go(-1); 52 }); 53 }); 54 55 assert_equals(previousUrl, await agent.execute_script(() => location.href)); 56 assert_not_prefetched(await agent.getRequestHeaders(), 57 "prefetch from different Document should not be used"); 58 }, "History's Document is used for traversal navigations"); 59 60 promise_test(async t => { 61 let agent = await spawnWindow(t, { protocol: 'https', pipe: 'header(Cache-Control, no-store)' }); 62 let previousUrl = await agent.execute_script(() => location.href); 63 await agent.forceSinglePrefetch(previousUrl); 64 await agent.execute_script(() => { 65 window.executor.suspend(() => location.reload()); 66 }); 67 68 assert_equals(previousUrl, await agent.execute_script(() => location.href)); 69 assert_prefetched(await agent.getRequestHeaders(), "reload should use prefetch"); 70 }, "prefetches can be used for reload navigations"); 71 </script>