summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/screen-orientation/orientation-reading.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/screen-orientation/orientation-reading.html
parentInitial commit. (diff)
downloadfirefox-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/orientation-reading.html')
-rw-r--r--testing/web-platform/tests/screen-orientation/orientation-reading.html119
1 files changed, 119 insertions, 0 deletions
diff --git a/testing/web-platform/tests/screen-orientation/orientation-reading.html b/testing/web-platform/tests/screen-orientation/orientation-reading.html
new file mode 100644
index 0000000000..90bbb8071d
--- /dev/null
+++ b/testing/web-platform/tests/screen-orientation/orientation-reading.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<meta viewport="width=device-width, initial-scale=1" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script type="module">
+"use strict";
+import {
+ makeCleanup,
+ getOppositeOrientation,
+} from "./resources/orientation-utils.js";
+
+test(() => {
+ assert_true("type" in screen.orientation, ".type must be present");
+ assert_true("angle" in screen.orientation, ".angle must be present");
+}, "screen.orientation attributes are present");
+
+async function testExpectedOrientationAngles(expectedAngles) {
+ for (const [orientation, expectedAngle] of Object.entries(expectedAngles)) {
+ try {
+ if (screen.orientation.type !== orientation) {
+ await screen.orientation.lock(orientation);
+ }
+ assert_equals(
+ screen.orientation.angle,
+ expectedAngle,
+ `Orientation angle for '${orientation}' must be ${expectedAngle} degrees`
+ );
+ } catch (err) {
+ // implementation might not support locking to this orientation
+ }
+ }
+}
+
+promise_test(async (t) => {
+ t.add_cleanup(makeCleanup());
+ await test_driver.bless("request full screen");
+ await document.documentElement.requestFullscreen();
+
+ const expectedAnglesPortrait = {
+ "portrait-primary": 0,
+ "landscape-primary": 90,
+ "portrait-secondary": 180,
+ "landscape-secondary": 270,
+ };
+
+ await testExpectedOrientationAngles(expectedAnglesPortrait);
+}, "Test the orientations and associated angles when the natural orientation is 'portrait'");
+
+promise_test(async (t) => {
+ t.add_cleanup(makeCleanup());
+ await test_driver.bless("request full screen");
+ await document.documentElement.requestFullscreen();
+
+ const expectedAnglesLandscape = {
+ "landscape-primary": 0,
+ "portrait-primary": 90,
+ "landscape-secondary": 180,
+ "portrait-secondary": 270,
+ };
+
+ await testExpectedOrientationAngles(expectedAnglesLandscape);
+}, "Test the orientations and associated angles when the natural orientation is 'landscape'");
+
+test(() => {
+ const { angle, type } = screen.orientation;
+
+ assert_throws_js(
+ TypeError,
+ () => {
+ screen.orientation.type = "foo";
+ },
+ "throws when setting ScreenOrientation.type to a string in strict mode"
+ );
+ assert_throws_js(
+ TypeError,
+ () => {
+ screen.orientation.angle = 42;
+ },
+ "throws when setting ScreenOrientation.angle to a number in strict mode"
+ );
+
+ assert_equals(screen.orientation.type, type);
+ assert_equals(screen.orientation.angle, angle);
+}, "Test that ScreenOrientation properties are not writable");
+
+test(() => {
+ assert_equals(screen.orientation, screen.orientation);
+}, "Test that ScreenOrientation is always the same object");
+
+promise_test(async (t) => {
+ t.add_cleanup(makeCleanup());
+ await test_driver.bless("request full screen");
+ await document.documentElement.requestFullscreen();
+ const initialType = screen.orientation.type;
+ const initialAngle = screen.orientation.angle;
+ const orientationWatcher = new EventWatcher(t, screen.orientation, "change");
+ const newOrientationType = getOppositeOrientation();
+
+ // change event is fired before resolving promise by lock.
+ const event = await Promise.race([
+ orientationWatcher.wait_for("change"),
+ screen.orientation.lock(newOrientationType),
+ ]);
+ assert_true(event instanceof Event, "expected event");
+ assert_not_equals(
+ screen.orientation.type,
+ initialType,
+ ".type must change"
+ );
+ assert_not_equals(
+ screen.orientation.angle,
+ initialAngle,
+ ".angle must change"
+ );
+}, "Test that ScreenOrientation's attribute values change after 'change' event fires");
+</script>