initiators-iframe-location-href.sub.https.html (2422B)
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 // 20 // Nonetheless, a prefetch in a top-level window is not suitable to use in an iframe. 21 // In particular, browsers partition storage and cache by top-level site. 22 // If a browser does start allowing these in narrower cases where the partition 23 // would nonetheless be the same, this test might need tweaking. 24 promise_test(async t => { 25 const win = await spawnWindow(t, { protocol: 'https' }); 26 27 const hostname = 28 location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; 29 const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); 30 31 await win.forceSinglePrefetch(nextUrl); 32 33 // In https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate, 34 // `sourceDocument` is the incumbent Document and thus `win`'s Document. 35 // `navigable`'s active document is `iframe`'s Document. 36 await win.execute_script((url) => { 37 window.executor.suspend(() => { 38 const iframe = document.createElement('iframe'); 39 document.body.appendChild(iframe); 40 iframe.contentWindow.location.href = url; 41 }); 42 }, [nextUrl]); 43 44 // Below, the scripts given to `win.execute_script()` are executed on the 45 // `nextUrl` page in the iframe, because `window.executor.suspend()` above 46 // made `win`'s original page stop processing `execute_script()`, 47 // while the new page of `nextUrl` in the iframe starts processing 48 // `execute_script()` for the same ID. 49 assert_equals( 50 await win.execute_script(() => location.href), 51 nextUrl.toString(), 52 "expected navigation to reach destination URL"); 53 54 assert_not_prefetched(await win.getRequestHeaders()); 55 }, `location.href across iframe`); 56 </script>