diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/screen-orientation/resources | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/screen-orientation/resources')
4 files changed, 94 insertions, 0 deletions
diff --git a/testing/web-platform/tests/screen-orientation/resources/empty.html b/testing/web-platform/tests/screen-orientation/resources/empty.html new file mode 100644 index 0000000000..0e76edd65b --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/resources/empty.html @@ -0,0 +1 @@ +<!DOCTYPE html> diff --git a/testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html b/testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html new file mode 100644 index 0000000000..68a67f8818 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html @@ -0,0 +1,9 @@ +<script> + try { + window.screen.orientation.addEventListener("change", () => { + parent.window.postMessage(screen.orientation.type, "*"); + }); + } catch (err) { + parent.window.postMessage(err.message, "*"); + } +</script> diff --git a/testing/web-platform/tests/screen-orientation/resources/orientation-utils.js b/testing/web-platform/tests/screen-orientation/resources/orientation-utils.js new file mode 100644 index 0000000000..95383750f1 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/resources/orientation-utils.js @@ -0,0 +1,52 @@ +/** + * + * @param {object} options + * @param {string} options.src - The iframe src + * @param {Window} options.context - The browsing context in which the iframe will be created + * @param {string} options.sandbox - The sandbox attribute for the iframe + * @returns + */ +export async function attachIframe(options = {}) { + const { src, context, sandbox, allowFullscreen } = { + ...{ + src: "about:blank", + context: self, + allowFullscreen: true, + sandbox: null, + }, + ...options, + }; + const iframe = context.document.createElement("iframe"); + if (sandbox !== null) iframe.sandbox = sandbox; + iframe.allowFullscreen = allowFullscreen; + await new Promise((resolve) => { + iframe.onload = resolve; + iframe.src = src; + context.document.body.appendChild(iframe); + }); + return iframe; +} + +export function getOppositeOrientation() { + return screen.orientation.type.startsWith("portrait") + ? "landscape" + : "portrait"; +} + +export function makeCleanup( + initialOrientation = screen.orientation?.type.split(/-/)[0] +) { + return async () => { + if (initialOrientation) { + try { + await screen.orientation.lock(initialOrientation); + } catch {} + } + screen.orientation.unlock(); + requestAnimationFrame(async () => { + try { + await document.exitFullscreen(); + } catch {} + }); + }; +} diff --git a/testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html b/testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html new file mode 100644 index 0000000000..436c67f5b5 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script> +test_driver.set_test_context(parent); + +// At first, run simple unlock test without lock. +screen.orientation?.unlock(); + +test_driver.bless("request full screen", async () => { + const data = {}; + try { + await document.documentElement.requestFullscreen(); + await screen.orientation.lock("portrait") + data.result = "locked"; + data.orientation = screen.orientation.type; + } catch (error) { + data.result = "errored"; + data.name = error.name; + } + + screen.orientation.unlock(); + try { + await document.exitFullscreen(); + } catch (error) { + data.result = "errored"; + data.name = error.name; + } + + parent.window.postMessage(data, "*"); +}); +</script> |