cross-origin-iframe.html (2014B)
1 <!DOCTYPE html> 2 <script src="/common/utils.js"></script> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/get-host-info.sub.js"></script> 6 <script src="/speculation-rules/prerender/resources/utils.js"></script> 7 <script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script> 8 <body> 9 <script> 10 11 async function main() { 12 const crossOriginUrl = 13 new URL('cross-origin-iframe-src.html', 14 get_host_info()['HTTPS_REMOTE_ORIGIN'] + 15 window.location.pathname); 16 17 // Start loading a cross-origin iframe. The iframe messages us with the 18 // value of its document.prerendering, which should be false since load 19 // is delayed until after activation. 20 const crossOriginIframe = document.createElement('iframe'); 21 22 const gotMessage = new Promise((resolve, reject) => { 23 window.addEventListener('message', (e) => { 24 if (e.data == 'document.prerendering: false') 25 resolve(); 26 else 27 reject('bad message: ' + e.data); 28 }); 29 }); 30 31 crossOriginIframe.src = crossOriginUrl.href; 32 document.body.appendChild(crossOriginIframe); 33 34 // To give the test a chance to fail by giving enough time if it loads the 35 // cross-origin iframe instead of deferring, wait for a same-origin iframe to 36 // load before proceeding with the test. 37 await createFrame('empty.html'); 38 39 // Start the event collector to trigger activation. 40 const prerenderEventCollector = new PrerenderEventCollector(); 41 prerenderEventCollector.start(gotMessage, 42 'iframe loaded'); 43 44 } 45 46 // The main test page (cross-origin-iframe.https.html) loads the initiator 47 // page, then the initiator page will prerender itself with the 48 // `prerendering` parameter. 49 const params = new URLSearchParams(location.search); 50 if (!params.has('prerendering')) { 51 const rule_extras = {'target_hint': getTargetHint()}; 52 loadInitiatorPage(rule_extras); 53 } else { 54 main(); 55 } 56 </script> 57 </body>