diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/screen-orientation/onchange-event-subframe.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/screen-orientation/onchange-event-subframe.html')
-rw-r--r-- | testing/web-platform/tests/screen-orientation/onchange-event-subframe.html | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/testing/web-platform/tests/screen-orientation/onchange-event-subframe.html b/testing/web-platform/tests/screen-orientation/onchange-event-subframe.html new file mode 100644 index 0000000000..1b4b8cd428 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/onchange-event-subframe.html @@ -0,0 +1,83 @@ +<!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"> + import { + attachIframe, + makeCleanup, + getOppositeOrientation, + } from "./resources/orientation-utils.js"; + + promise_test(async (t) => { + t.add_cleanup(makeCleanup()); + await test_driver.bless("request fullscreen"); + await document.documentElement.requestFullscreen(); + let orientations = ["portrait", "landscape"]; + if (screen.orientation.type.includes("portrait")) { + orientations = orientations.reverse(); + } + const messageWatcher = new EventWatcher(t, window, "message"); + const changeWatcher = new EventWatcher(t, screen.orientation, "change"); + const iframe = await attachIframe({ + src: "resources/iframe-listen-orientation-change.html", + sandbox: "allow-scripts allow-same-origin", + }); + for (const orientation of orientations) { + const messagePromise = messageWatcher.wait_for("message"); + const eventPromise = changeWatcher.wait_for("change"); + await screen.orientation.lock(orientation); + const winner = await Promise.race([eventPromise, messagePromise]); + assert_true(winner instanceof Event, "change event must be fired first"); + const message = await messagePromise; + assert_true( + message.data.startsWith(orientation), + "subframe receives orientation change event" + ); + } + iframe.remove(); + }, "Test subframes receive orientation change events"); + + promise_test(async (t) => { + t.add_cleanup(makeCleanup()); + const iframe = await attachIframe(); + const opposite = getOppositeOrientation(); + + const topEventPromise = new EventWatcher( + t, + screen.orientation, + "change" + ).wait_for("change"); + const iframeEventPromise = new EventWatcher( + t, + iframe.contentWindow.screen.orientation, + "change" + ).wait_for("change"); + + // Lock from the iframe + await test_driver.bless("request fullscreen"); + await document.documentElement.requestFullscreen(); + const lockPromise = iframe.contentWindow.screen.orientation.lock(opposite); + + const winningEvent = await Promise.race([ + topEventPromise, + iframeEventPromise, + ]); + assert_true( + winningEvent instanceof window.Event, + "top-level change event must be fired first" + ); + + const iframeEvent = await iframeEventPromise; + assert_true( + iframeEvent instanceof iframe.contentWindow.Event, + "iframe event eventually fires" + ); + + await lockPromise; + iframe.remove(); + }, "Check directly that events are fired in right order (from top to bottom)"); +</script> |