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/prerender-state.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.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/prerender-state.html')
-rw-r--r-- | testing/web-platform/tests/speculation-rules/prerender/resources/prerender-state.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/resources/prerender-state.html b/testing/web-platform/tests/speculation-rules/prerender/resources/prerender-state.html new file mode 100644 index 0000000000..914db2a9ed --- /dev/null +++ b/testing/web-platform/tests/speculation-rules/prerender/resources/prerender-state.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<script src="/common/utils.js"></script> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="utils.js"></script> +<script> + +// TODO(https://crbug.com/1174978): Make sure this page is being prerendered. + +const params = new URLSearchParams(location.search); + +// Take a key used for storing a test result in the server. +const key = params.get('key'); + +// The main test page (state-and-event.html in the parent directory) will load +// this page only with the "key" parameter. This page will then prerender +// itself with the "run-test" parameter. When "run-test" is in the URL we'll +// actually start the test process and record the results to send back to the +// main test page. We do this because the main test page cannot navigate itself +// but it also cannot open a popup to a prerendered browsing context so the +// prerender triggering and activation must both happen in this popup. +const run_test = params.has('run-test'); +if (!run_test) { + // Generate a new stash key so we can communicate with the prerendered page + // about when to activate it. + const activate_key = token(); + const url = new URL(document.URL); + url.searchParams.append('run-test', ''); + url.searchParams.append('activate-key', activate_key); + startPrerendering(url.toString()); + + // Wait until the prerendered page signals us it's time to activate, then + // navigate to it. + nextValueFromServer(activate_key).then(() => { + window.location = url.toString(); + }); +} else { + const activate_key = params.get('activate-key'); + const result = { + // Check the types of the members on document. + prerenderingTypeOf: typeof(document.prerendering), + onprerenderingChangeTypeOf: typeof(document.onprerenderingchange), + + // Check the value of document.prerendering now and after activation. + prerenderingValueBeforeActivate: document.prerendering, + prerenderingValueAfterActivate: null, + + // Track when the prerenderingchange event is fired. + onprerenderingchangeCalledBeforeActivate: false, + onprerenderingchangeCalledAfterActivate: false, + + // Tracks the properties on the prerenderingchange event. + eventBubbles: null, + eventCancelable: null + }; + + let did_load = false; + + addEventListener('load', () => { + did_load = true; + + // Tell the harness we've finished loading so we can proceed to activation. + writeValueToServer(activate_key, 'did_load'); + }); + + document.addEventListener('prerenderingchange', (e) => { + result.eventBubbles = e.bubbles; + result.eventCancelable = e.cancelable; + + if (did_load) { + result.onprerenderingchangeCalledAfterActivate = true; + result.prerenderingValueAfterActivate = document.prerendering; + writeValueToServer(key, JSON.stringify(result)).then(() => { + window.close(); + }); + } else { + result.onprerenderingchangeCalledBeforeActivate = true; + } + }); +} + +</script> |