diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/speculation-rules/prerender/resources/notification-on-activation.html | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/resources/notification-on-activation.html')
-rw-r--r-- | testing/web-platform/tests/speculation-rules/prerender/resources/notification-on-activation.html | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/resources/notification-on-activation.html b/testing/web-platform/tests/speculation-rules/prerender/resources/notification-on-activation.html new file mode 100644 index 0000000000..0a85746b04 --- /dev/null +++ b/testing/web-platform/tests/speculation-rules/prerender/resources/notification-on-activation.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<script src="utils.js"></script> +<script> + +const params = new URLSearchParams(location.search); + +// The main test page (restriction-notification.https.html) loads the initiator +// page, then the initiator page will prerender itself with the `prerendering` +// parameter. +const isPrerendering = params.has('prerendering'); + +if (!isPrerendering) { + loadInitiatorPage(); +} else { + // Used to communicate with the initiator page. + const prerenderChannel = new PrerenderChannel('prerender-channel'); + // Used to communicate with the main test page. + const testChannel = new PrerenderChannel('test-channel'); + + window.addEventListener('load', () => { + // Inform the initiator page that this page is ready to be activated. + prerenderChannel.postMessage('readyToActivate'); + prerenderChannel.close(); + }); + + document.addEventListener('prerenderingchange', () => { + // Accessing the Notification API is allowed after the prerendering state + // changed. + const permission = Notification.permission; + const notification = new Notification('New Notification'); + + notification.onerror = function(_) { + testChannel.postMessage('notification error'); + testChannel.close(); + } + notification.onshow = function() { + testChannel.postMessage('notification showed'); + notification.close(); + testChannel.close(); + }; + }); +} + +</script> |