summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html')
-rw-r--r--dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html102
1 files changed, 102 insertions, 0 deletions
diff --git a/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html
new file mode 100644
index 000000000..abf721789
--- /dev/null
+++ b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html
@@ -0,0 +1,102 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test hidden frames</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <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">
+SimpleTest.waitForExplicitFinish();
+ // Add a gamepad
+var index;
+
+function setFrameVisible(f, visible) {
+ var Ci = SpecialPowers.Ci;
+ var docshell = SpecialPowers.wrap(f.contentWindow).QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell);
+ docshell.isActive = visible;
+}
+
+var frames_loaded = 0;
+function startTest() {
+ frames_loaded++;
+ if (frames_loaded == 2) {
+ GamepadService.addGamepad("test gamepad", // id
+ GamepadService.standardMapping,
+ 4, // buttons
+ 2).then(function(i) {
+ index = i;
+ gamepad_loaded();
+ });
+ }
+}
+var f1, f2;
+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");
+ });
+ w2.addEventListener("gamepadbuttonup", () => {
+ ok(!f2.contentWindow.gamepad.buttons[0].pressed,
+ "frame 2 no button pressed");
+ setFrameVisible(f2, false);
+ SpecialPowers.executeSoon(function() {
+ GamepadService.newButtonEvent(index, 0, true);
+ });
+ })
+ // Now press the button, but don't release it.
+ GamepadService.newButtonEvent(index, 0, 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,
+ check_second_frame_no_button_press,
+];
+
+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(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
+
+ // Now release the button, then hide the second frame.
+ GamepadService.newButtonEvent(index, 0, false);
+}
+
+function check_second_frame_no_button_press () {
+ /*
+ * At this point the first frame should see the button as pressed,
+ * but the second frame should not, since it's hidden.
+ */
+ ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
+ ok(!f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 should not see button pressed");
+
+ // Now unhide the second frame.
+ setFrameVisible(f2, true);
+ SpecialPowers.executeSoon(function() {
+ // Now that the frame is visible again, it should see the button
+ // that was pressed.
+ ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
+ // cleanup
+ 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>