prefetch-uses-cache.sub.https.html (2885B)
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/utils.js"></script> 8 <script src="resources/utils.sub.js"></script> 9 10 <meta name="variant" content="?same-site"> 11 <meta name="variant" content="?cross-site"> 12 13 <script> 14 setup(() => assertSpeculationRulesIsSupported()); 15 16 promise_test(async t => { 17 const is_same_site = location.search === '?same-site'; 18 const initiator = await spawnWindow(t); 19 const url1 = initiator.getExecutorURL({ 20 hostname: is_same_site ? undefined : '{{hosts[alt][www]}}', 21 page: 1, 22 pipe: 'header(Cache-Control,private\\,max-age=604800)' 23 }); 24 const url2 = initiator.getExecutorURL({ 25 hostname: is_same_site ? undefined : '{{hosts[][]}}', 26 page: 2, 27 pipe: 'header(Cache-Control,private\\,max-age=604800)' 28 }); 29 30 await initiator.forceSinglePrefetch(url1); 31 initiator.navigate(url2); 32 assert_equals(await initiator.getDeliveryType(), ''); 33 assert_not_prefetched(await initiator.getRequestHeaders(), 34 'Content should not have been prefetched.'); 35 36 initiator.navigate(url1); 37 if (is_same_site) { 38 assert_equals(await initiator.getDeliveryType(), 'cache', 39 'Navigation should have retrieved the response from the HTTP Cache.'); 40 // Note: Even though we didn't use a prefetch, the cached response for 41 // |url1| was obtained using a prefetch request, and the recorded headers 42 // at the time of the first request would have Sec-Purpose: 'prefetch'. 43 assert_prefetched(await initiator.getRequestHeaders(), 44 'The cached response should have been from the initial prefetch request.'); 45 } else { 46 assert_equals(await initiator.getDeliveryType(), '', 47 'Navigation response should not have been from the HTTP Cache.'); 48 } 49 50 51 await initiator.forceSinglePrefetch(url2); 52 initiator.navigate(url2); 53 assert_equals(await initiator.getDeliveryType(), 'navigational-prefetch', 54 'Navigation should have used the prefetch'); 55 if (is_same_site) { 56 // Note: Even though we did use a prefetch, the recorded request headers in 57 // the response will not be prefetch headers. This is because the prefetch 58 // request retrieved its response from the HTTP cache, and the response in 59 // the cache was initially obtained from the first navigation to |url2|, 60 // which was not a prefetch. 61 assert_not_prefetched(await initiator.getRequestHeaders(), 62 'The prefetch request should have used a response from the HTTP cache.'); 63 } else { 64 assert_prefetched(await initiator.getRequestHeaders(), 65 'The prefetch request should have used a fresh response'); 66 } 67 68 }, 'Test that prefetches use/store responses to/from the HTTP cache.'); 69 </script>