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/fullscreen/trusted-click.js | |
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/fullscreen/trusted-click.js')
-rw-r--r-- | testing/web-platform/tests/fullscreen/trusted-click.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fullscreen/trusted-click.js b/testing/web-platform/tests/fullscreen/trusted-click.js new file mode 100644 index 0000000000..51fbce7ee4 --- /dev/null +++ b/testing/web-platform/tests/fullscreen/trusted-click.js @@ -0,0 +1,65 @@ +/** + * Invokes callback from a trusted click event, avoiding interception by fullscreen element. + * + * @param {Element} container - Element where button will be created and clicked. + */ +function trusted_click(container = document.body) { + var document = container.ownerDocument; + var button = document.createElement("button"); + button.textContent = "click to continue test"; + button.style.display = "block"; + button.style.fontSize = "20px"; + button.style.padding = "10px"; + button.addEventListener("click", () => { + button.remove(); + }); + container.appendChild(button); + if (window.top !== window) test_driver.set_test_context(window.top); + // Race them for manually testing... + return Promise.race([ + test_driver.click(button), + new Promise((resolve) => { + button.addEventListener("click", resolve); + }), + ]); +} + +// Invokes element.requestFullscreen() from a trusted click. +async function trusted_request(element = document.body, whereToCreateButton = null) { + await trusted_click(whereToCreateButton ?? element.parentNode ?? element); + return element.requestFullscreen(); +} + +/** + * Used to await a fullscreen change event, once. + * + * @param {EventTarget} target + * @returns + */ +function fullScreenChange(target = document) { + return new Promise((resolve) => + target.addEventListener("fullscreenchange", resolve, { once: true }) + ); +} + +/** + * Sets up a message event listener, and returns a promise that resolves + * when the message from the iframe is received. + * + * @param {HTMLIFrameElement} iframe + * @returns {Promise<object>} + */ +function promiseMessage(iframe) { + return new Promise((resolve) => { + window.addEventListener( + "message", + (e) => { + if (e.data?.report.api === "fullscreen") { + resolve(e.data); + } + }, + { once: true } + ); + iframe.contentWindow.postMessage({ action: "report" }, "*"); + }); +} |