diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html | |
parent | Initial commit. (diff) | |
download | firefox-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 '')
-rw-r--r-- | dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html new file mode 100644 index 0000000000..bdea4e8a5a --- /dev/null +++ b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html @@ -0,0 +1,87 @@ +<!-- Any copyright is dedicated to the Public Domain. + - http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <title>Test hidden frames</title> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<script type="text/javascript" src="mock_gamepad.js"></script> +<script class="testbody" type="text/javascript"> +let ok = window.parent.ok; +let is = window.parent.is; +let SimpleTest = window.parent.SimpleTest; +let SpecialPowers = window.parent.SpecialPowers; + + // Add a gamepad +var index; + +var frames_loaded = 0; +async function startTest() { + frames_loaded++; + if (frames_loaded != 2) return; + index = await GamepadService.addGamepad("test gamepad", // id + GamepadService.standardMapping, + GamepadService.noHand, + 4, // buttons + 2, + 0, + 0, + 0); + await gamepad_loaded(); +} +var f1, f2; +async function gamepad_loaded() { + f1 = document.getElementById('f1'); + f2 = document.getElementById('f2'); + let w1 = f1.contentWindow; + let w2 = f2.contentWindow; + w1.addEventListener("gamepadbuttonup", () => { + ok(!f1.contentWindow.gamepad.buttons[0].pressed, + "frame 1 no button pressed"); + ok(!f1.contentWindow.gamepad.buttons[0].touched, + "frame 1 no button touched"); + }); + w2.addEventListener("gamepadbuttonup", () => { + ok(!f2.contentWindow.gamepad.buttons[0].pressed, + "frame 2 no button pressed"); + ok(!f2.contentWindow.gamepad.buttons[0].touched, + "frame 2 no button touched"); + }) + // Now press the button, but don't release it. + await GamepadService.newButtonEvent(index, 0, true, true); +} + +window.addEventListener("gamepadbuttondown", function() { + // Wait to ensure that all frames received the button press as well. + SpecialPowers.executeSoon(tests[testNum++]); +}); + +var testNum = 0; +var tests = [ + check_button_pressed, +]; + +async function check_button_pressed() { + // At this point the both frames should see the button as pressed. + ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed"); + ok(f1.contentWindow.gamepad.buttons[0].touched, "frame 1 sees button touched"); + ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed"); + ok(f2.contentWindow.gamepad.buttons[0].touched, "frame 2 sees button touched"); + + // Now release the button, then hide the second frame. + await GamepadService.newButtonEvent(index, 0, false, false); + + SpecialPowers.executeSoon(async function() { + // cleanup + await GamepadService.removeGamepad(index); + SimpleTest.finish(); + }); +} + +</script> +<iframe id="f1" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe> +<iframe id="f2" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe> +</body> +</html> |