diff options
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/resources/message-boxes.html')
-rw-r--r-- | testing/web-platform/tests/speculation-rules/prerender/resources/message-boxes.html | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/resources/message-boxes.html b/testing/web-platform/tests/speculation-rules/prerender/resources/message-boxes.html new file mode 100644 index 0000000000..8e0a6e874f --- /dev/null +++ b/testing/web-platform/tests/speculation-rules/prerender/resources/message-boxes.html @@ -0,0 +1,50 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/speculation-rules/prerender/resources/utils.js"></script> +<script> +function runAlertTest() { + window.alert('Hello! Preprendering!'); + return 'no block'; +} + +function runConfirmTest() { + const result = window.confirm('Are you preprendering page?'); + return 'the return value is ' + (result === true ? 'yes' : 'no'); +} + +function runPromptTest() { + const result = window.prompt('Are you preprendering page?', + 'the default value'); + return 'the return value is ' + (result === null ? 'null' : result); +} + +const params = new URLSearchParams(location.search); + +const uid = params.get('uid'); + +// The main test page (restriction-message-boxes.html) loads the +// initiator page, then the initiator page will prerender itself with the +// `prerendering` parameter. +const isPrerendering = params.has('prerendering'); + +if (isPrerendering) { + // Test web APIs on the pages. + const bc = new PrerenderChannel('prerender-channel', uid); + assert_true(document.prerendering); + if (params.has('alert')) { + bc.postMessage(runAlertTest()); + } else if (params.has('confirm')) { + bc.postMessage(runConfirmTest()); + } else if (params.has('prompt')) { + bc.postMessage(runPromptTest()); + } + bc.close(); + window.close(); +} else { + // Initiator pages should prerender the prerendering page. + const url = new URL(document.URL); + url.searchParams.append('prerendering', ''); + startPrerendering(url); +} +</script> |