summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/screen-orientation/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/screen-orientation/resources
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/screen-orientation/resources')
-rw-r--r--testing/web-platform/tests/screen-orientation/resources/empty.html1
-rw-r--r--testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html9
-rw-r--r--testing/web-platform/tests/screen-orientation/resources/nav_iframe.html18
-rw-r--r--testing/web-platform/tests/screen-orientation/resources/orientation-utils.js52
-rw-r--r--testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html32
5 files changed, 112 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/nav_iframe.html b/testing/web-platform/tests/screen-orientation/resources/nav_iframe.html
new file mode 100644
index 0000000000..bb26cf7c10
--- /dev/null
+++ b/testing/web-platform/tests/screen-orientation/resources/nav_iframe.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>A Document</title>
+</head>
+<body>
+ <h1 id="section1">Section 1</h1>
+ <p>This is the content of section 1.</p>
+
+ <h2 id="section2">Section 2</h2>
+ <p>This is the content of section 2.</p>
+
+ <p>
+ <a href="#section1">Go to Section 1</a> |
+ <a id="clickme" href="#section2">Go to Section 2</a>
+ </p>
+</body>
+</html>
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>