message-boxes.html (1549B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/speculation-rules/prerender/resources/utils.js"></script> 5 <script> 6 function runAlertTest() { 7 window.alert('Hello! Preprendering!'); 8 return 'no block'; 9 } 10 11 function runConfirmTest() { 12 const result = window.confirm('Are you preprendering page?'); 13 return 'the return value is ' + (result === true ? 'yes' : 'no'); 14 } 15 16 function runPromptTest() { 17 const result = window.prompt('Are you preprendering page?', 18 'the default value'); 19 return 'the return value is ' + (result === null ? 'null' : result); 20 } 21 22 const params = new URLSearchParams(location.search); 23 24 const uid = params.get('uid'); 25 26 // The main test page (restriction-message-boxes.html) loads the 27 // initiator page, then the initiator page will prerender itself with the 28 // `prerendering` parameter. 29 const isPrerendering = params.has('prerendering'); 30 31 if (isPrerendering) { 32 // Test web APIs on the pages. 33 const bc = new PrerenderChannel('prerender-channel', uid); 34 assert_true(document.prerendering); 35 if (params.has('alert')) { 36 bc.postMessage(runAlertTest()); 37 } else if (params.has('confirm')) { 38 bc.postMessage(runConfirmTest()); 39 } else if (params.has('prompt')) { 40 bc.postMessage(runPromptTest()); 41 } 42 bc.close(); 43 window.close(); 44 } else { 45 // Initiator pages should prerender the prerendering page. 46 const url = new URL(document.URL); 47 url.searchParams.append('prerendering', ''); 48 startPrerendering(url); 49 } 50 </script>