prefetch-time-to-fetch.https.html (1967B)
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/get-host-info.sub.js"></script> 7 <script src="/preload/resources/preload_helper.js"></script> 8 <body> 9 <script> 10 11 const {REMOTE_ORIGIN} = get_host_info(); 12 13 function test_prefetch_change(before, after, expected, label) { 14 promise_test(async t => { 15 const link = document.createElement('link'); 16 link.rel = 'prefetch'; 17 t.add_cleanup(() => link.remove()); 18 const loadErrorOrTimeout = () => new Promise(resolve => { 19 const timeoutMillis = 1000; 20 link.addEventListener('load', () => resolve('load')); 21 link.addEventListener('error', () => resolve('error')); 22 t.step_timeout(() => resolve('timeout'), timeoutMillis); 23 }); 24 for (const attr in before) 25 link.setAttribute(attr, before[attr]); 26 document.head.appendChild(link); 27 const result1 = await loadErrorOrTimeout(); 28 for (const attr in after) { 29 if (attr in before && after[attr] === null) 30 link.removeAttribute(attr); 31 else 32 link.setAttribute(attr, after[attr]); 33 } 34 const result2 = await loadErrorOrTimeout(); 35 assert_array_equals([result1, result2], expected); 36 }, label); 37 } 38 39 test_prefetch_change( 40 {href: '/common/square.png?1'}, 41 {href: '/common/square.png?2'}, 42 ['load', 'load'], 43 'Changing a prefetch href should trigger a fetch'); 44 45 test_prefetch_change( 46 {href: `${REMOTE_ORIGIN}/common/square.png?pipe=header(Access-Control-Allow-Origin,*)`}, 47 {href: `${REMOTE_ORIGIN}/common/square.png?pipe=header(Access-Control-Allow-Origin,*)`, crossorigin: 'anonymous'}, 48 ['load', 'timeout'], 49 'Changing a prefetch crossorigin attribute does not trigger a fetch'); 50 51 </script> 52 </body>