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/html/user-activation/resources/utils.js | |
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/html/user-activation/resources/utils.js')
-rw-r--r-- | testing/web-platform/tests/html/user-activation/resources/utils.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/user-activation/resources/utils.js b/testing/web-platform/tests/html/user-activation/resources/utils.js new file mode 100644 index 0000000000..5d3302583f --- /dev/null +++ b/testing/web-platform/tests/html/user-activation/resources/utils.js @@ -0,0 +1,48 @@ +function delayByFrames(f, num_frames) { + function recurse(depth) { + if (depth == 0) + f(); + else + requestAnimationFrame(() => recurse(depth-1)); + } + recurse(num_frames); +} + +// Returns a Promise which is resolved with the event object when the event is +// fired. +function getEvent(eventType) { + return new Promise(resolve => { + document.body.addEventListener(eventType, e => resolve(e), {once: true}); + }); +} + + +// Returns a Promise which is resolved with a "true" iff transient activation +// was available and successfully consumed. +// +// This function relies on Fullscreen API to check/consume user activation +// state. +async function consumeTransientActivation() { + try { + await document.body.requestFullscreen(); + await document.exitFullscreen(); + return true; + } catch(e) { + return false; + } +} + +function receiveMessage(type) { + return new Promise((resolve) => { + window.addEventListener("message", function listener(event) { + if (typeof event.data !== "string") { + return; + } + const data = JSON.parse(event.data); + if (data.type === type) { + window.removeEventListener("message", listener); + resolve(data); + } + }); + }); +} |