initiators-a-element.sub.https.html (2948B)
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="../resources/utils.js"></script> 8 <script src="resources/utils.sub.js"></script> 9 10 <meta name="variant" content="?cross-site"> 11 <meta name="variant" content="?same-site"> 12 13 <script> 14 setup(() => assertSpeculationRulesIsSupported()); 15 16 // In https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate, 17 // `sourceDocument` (instead of `navigable`'s active document) should be 18 // used as the referring document for prefetch. 19 promise_test(async t => { 20 const win = await spawnWindow(t, { protocol: 'https' }); 21 22 const hostname = 23 location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; 24 const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); 25 26 await win.forceSinglePrefetch(nextUrl); 27 28 // sourceDocument == `win`'s Document == active document of window being 29 // navigated. 30 await win.execute_script((url) => { 31 window.executor.suspend(() => { 32 const a = document.createElement('a'); 33 a.setAttribute('href', url); 34 document.body.appendChild(a); 35 a.click(); 36 }); 37 }, [nextUrl]); 38 39 assert_equals( 40 await win.execute_script(() => location.href), 41 nextUrl.toString(), 42 "expected navigation to reach destination URL"); 43 44 assert_prefetched(await win.getRequestHeaders()); 45 }, `<a>`); 46 47 promise_test(async t => { 48 const win = await spawnWindow(t, { protocol: 'https' }); 49 50 const hostname = 51 location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; 52 const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); 53 54 await win.forceSinglePrefetch(nextUrl); 55 56 // sourceDocument == `win`'s Document != active document of window being 57 // navigated, since the window being navigated is a new window. 58 await win.execute_script((url) => { 59 window.executor.suspend(() => { 60 const a = document.createElement('a'); 61 a.setAttribute('href', url); 62 a.setAttribute('target', '_blank'); 63 document.body.appendChild(a); 64 a.click(); 65 }); 66 }, [nextUrl]); 67 68 // Below, the scripts given to `win.execute_script()` are executed on the 69 // `nextUrl` page in the new window, because `window.executor.suspend()` 70 // above made `win`'s original page stop processing `execute_script()`, 71 // while the new page of `nextUrl` in the new window starts processing 72 // `execute_script()` for the same ID. 73 assert_equals( 74 await win.execute_script(() => location.href), 75 nextUrl.toString(), 76 "expected navigation to reach destination URL"); 77 78 assert_prefetched(await win.getRequestHeaders()); 79 }, `<a target="blank">`); 80 </script>