From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/screen-orientation/resources/empty.html | 1 + .../iframe-listen-orientation-change.html | 9 ++++ .../resources/orientation-utils.js | 52 ++++++++++++++++++++++ .../resources/sandboxed-iframe-locking.html | 32 +++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 testing/web-platform/tests/screen-orientation/resources/empty.html create mode 100644 testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html create mode 100644 testing/web-platform/tests/screen-orientation/resources/orientation-utils.js create mode 100644 testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html (limited to 'testing/web-platform/tests/screen-orientation/resources') 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 @@ + 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 @@ + 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 @@ + + + + -- cgit v1.2.3