windowclient-navigate-to-cross-origin-url-on-iframe.https.html (2895B)
1 <!-- 2 This file cannot be upstreamed to WPT until: 3 * Cross-origin iframe loading is specified. The test expects that cross-origin 4 iframe loading is deferred. 5 --> 6 <!DOCTYPE html> 7 <title>WindowClient.navigate() to cross-origin url in a prerendered iframe</title> 8 <meta name="timeout" content="long"> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="/common/get-host-info.sub.js"></script> 12 <script src="/common/utils.js"></script> 13 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> 14 <script src="../resources/utils.js"></script> 15 <script src="resources/utils.js"></script> 16 17 <body> 18 <script> 19 setup(() => assertSpeculationRulesIsSupported()); 20 21 const PAGE_URL = 'resources/windowclient-navigate-on-iframe.html'; 22 const WORKER_URL = 'resources/windowclient-navigate-worker.js'; 23 const SCOPE = 'resources/'; 24 const CROSS_ORIGIN_DESTINATION = 25 get_host_info()['HTTPS_REMOTE_ORIGIN'] + 26 base_path() + 'resources/empty.html'; 27 28 promise_test(async t => { 29 const uid = token(); 30 31 const registration = await service_worker_unregister_and_register( 32 t, `${WORKER_URL}?uid=${uid}`, SCOPE); 33 t.add_cleanup(() => registration.unregister()); 34 await wait_for_state(t, registration.installing, 'activated'); 35 36 const bc = new PrerenderChannel('test-channel', uid); 37 t.add_cleanup(_ => bc.close()); 38 39 const gotMessage = new Promise(resolve => { 40 bc.addEventListener('message', e => { 41 resolve(e.data); 42 }, { 43 once: true 44 }); 45 }); 46 47 // PAGE_URL starts a prerender of a page that makes an iframe, then asks the 48 // service worker to navigate the iframe to `navigationUrl` via 49 // `WindowClient.navigate(url)`. The cross-origin url triggers 50 // PrerenderEventCollector to wait to navigate to `navigationUrl` on an iframe 51 // until the prerendered iframe is activated. 52 window.open( 53 `${PAGE_URL}?navigationUrl=${CROSS_ORIGIN_DESTINATION}&uid=${uid}`, 54 '_blank', 55 'noopener'); 56 57 const navigationResult = await gotMessage; 58 const expected = [ 59 { 60 event: 'started waiting navigation on iframe', 61 prerendering: true 62 }, 63 { 64 event: 'prerendering change', 65 prerendering: false 66 }, 67 { 68 event: 'finished waiting navigation on iframe', 69 prerendering: false 70 }, 71 ]; 72 assert_equals(navigationResult.length, expected.length); 73 for (let i = 0; i < navigationResult.length; i++) { 74 assert_equals(navigationResult[i].event, expected[i].event, `event[${i}]`); 75 assert_equals(navigationResult[i].prerendering, expected[i].prerendering, 76 `prerendering[${i}]`); 77 } 78 79 // Send a close signal to PrerenderEventCollector on the prerendered page. 80 new PrerenderChannel('close', uid).postMessage(''); 81 }, 'WindowClient.navigate() to a cross-origin URL on a prerendered iframe ' + 82 'should be deferred'); 83 </script>