prerender-until-script.https.html (1909B)
1 <!DOCTYPE html> 2 <title>Prerender and activate prerender-until-script action page correctly</title> 3 <meta name="timeout" content="long"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/common/utils.js"></script> 7 <script src="/speculation-rules/prerender/resources/utils.js"></script> 8 <script src="../resources/utils.js"></script> 9 <body> 10 <script> 11 setup(() => assertSpeculationRulesIsSupported()); 12 13 promise_test(async t => { 14 /* 15 Workflows: 16 1. The initiator page (pus-initiator-page-template.html) 17 triggers the prerender and simultaneously fetches a signal_url. This 18 fetch is designed to hang on the server. 19 20 2. The prerendered page (pus-page-template.html) is allowed to fetch an 21 async script (which also hits the signal_url, but with 22 isprerendering=True). 23 24 3. When the server receives the request from the prerendered page, it 25 puts a token in its stash, which in turn unblocks the initiator's 26 hanging fetch. 27 28 4. The .then() block of the initiator's fetch then runs, navigating to 29 the prerendered page and causing activation. 30 31 5. The (previously blocked) inline script on the prerendered page then 32 executes, verifying that document.prerendering is false and sending the 33 result back to the main test page. 34 */ 35 36 const uid = token(); 37 const bc = new PrerenderChannel('test-channel', uid); 38 39 const gotMessage = new Promise(resolve => { 40 bc.addEventListener('message', e => { 41 resolve(e.data); 42 }, { 43 once: true 44 }); 45 }); 46 const url = `resources/pus-handler.py?type=main&uid=${uid}`; 47 window.open(url, '_blank', 'noopener'); 48 49 const result = await gotMessage; 50 assert_equals(result, 'prerendering state when executing JS: false'); 51 52 bc.close(); 53 }, `when prerender-until-script action prerenders a page, the script on that page should always be executed after activation.`); 54 </script>