initiators-window-open.sub.https.html (2495B)
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 await win.execute_script((url) => { 29 window.executor.suspend(() => { 30 window.open(url, "_blank"); 31 }); 32 }, [nextUrl]); 33 34 // Below, the scripts given to `win.execute_script()` are executed on the 35 // `nextUrl` page in the new window, because `window.executor.suspend()` 36 // above made `win`'s original page stop processing `execute_script()`, 37 // while the new page of `nextUrl` in the new window starts processing 38 // `execute_script()` for the same ID. Same for below. 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 }, `window.open()`); 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 await win.execute_script((url) => { 57 window.executor.suspend(() => { 58 window.open(url, "_blank", "noopener"); 59 }); 60 }, [nextUrl]); 61 62 assert_equals( 63 await win.execute_script(() => location.href), 64 nextUrl.toString(), 65 "expected navigation to reach destination URL"); 66 67 assert_prefetched(await win.getRequestHeaders()); 68 }, `window.open(noopener)`); 69 </script>