servo/tests/wpt/web-platform-tests/screen-orientation/orientation-reading.html

58 lines
2 KiB
HTML

<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_true('type' in screen.orientation);
assert_true('angle' in screen.orientation);
}, "Test screen.orientation properties");
test(() => {
const type = screen.orientation.type;
const angle = screen.orientation.angle;
if (screen.width > screen.height) {
assert_true(type == "landscape-primary" || type == "landscape-secondary");
} else if (screen.width < screen.height) {
assert_true(type == "portrait-primary" || type == "portrait-secondary");
}
assert_true(angle == 0 || angle == 90 || angle == 180 || angle == 270);
}, "Test screen.orientation default values.");
test(() => {
const type = screen.orientation.type;
const angle = screen.orientation.angle;
screen.orientation.type = 'foo';
screen.orientation.angle = 42;
assert_equals(screen.orientation.type, type);
assert_equals(screen.orientation.angle, angle);
}, "Test that screen.orientation properties are not writable");
test(() => {
assert_equals(screen.orientation, screen.orientation);
}, "Test that screen.orientation is always the same object");
promise_test(async t => {
const orientation = screen.orientation;
const orientationType = screen.orientation.type;
const orientationAngle = screen.orientation.angle;
const orientationWatcher = new EventWatcher(t, orientation, "change");
if (orientationType.includes("portrait")) {
await orientation.lock("landscape-primary");
} else {
await orientation.lock("portrait-primary");
}
await orientationWatcher.wait_for("change");
assert_equals(screen.orientation, orientation);
assert_equals(screen.orientation.type, orientation.type);
assert_equals(screen.orientation.angle, orientation.angle);
assert_not_equals(screen.orientation.type, orientationType);
assert_not_equals(screen.orientation.angle, orientationAngle);
screen.orientation.unlock();
}, "Test that screen.orientation values change if the orientation changes");
</script>