diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/gamepad/test_gamepad.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-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.html')
-rw-r--r-- | dom/tests/mochitest/gamepad/test_gamepad.html | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/tests/mochitest/gamepad/test_gamepad.html b/dom/tests/mochitest/gamepad/test_gamepad.html new file mode 100644 index 000000000..e66f7ff2a --- /dev/null +++ b/dom/tests/mochitest/gamepad/test_gamepad.html @@ -0,0 +1,71 @@ +<!-- Any copyright is dedicated to the Public Domain. + - http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <title>Test gamepad</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(); +// Due to gamepad being a polling API instead of event driven, test ordering +// ends up being a little weird in order to deal with e10s. Calls to +// GamepadService are async across processes, so we'll need to make sure +// we account for timing before checking values. +window.addEventListener("gamepadconnected", connecthandler); +var index; +var testNum = 0; + +window.addEventListener("gamepadbuttondown", () => { + SpecialPowers.executeSoon(buttontest1); +}); + +window.addEventListener("gamepadbuttonup", () => { + SpecialPowers.executeSoon(buttontest2); +}); + +runGamepadTest(startTest); + +function startTest() { + // Add a gamepad + GamepadService.addGamepad("test gamepad", // id + GamepadService.standardMapping, + 4, + 2).then(function(i) { + index = i; + // Simulate button events on the gamepad we added + GamepadService.newButtonEvent(index, 0, true); + }); +} + +function connecthandler(e) { + ok(e.gamepad.timestamp <= performance.now(), + "gamepad.timestamp should less than or equal to performance.now()"); + is(e.gamepad.index, 0, "correct gamepad index"); + is(e.gamepad.id, "test gamepad", "correct gamepad name"); + is(e.gamepad.mapping, "standard", "standard mapping"); + is(e.gamepad.buttons.length, 4, "correct number of buttons"); + is(e.gamepad.axes.length, 2, "correct number of axes"); +} + +function buttontest1() { + var gamepads = navigator.getGamepads(); + is(gamepads[0].buttons[0].pressed, true, "gamepad button should register as pressed"); + GamepadService.newButtonValueEvent(index, 1, true, 0.5); +} + +function buttontest2() { + var gamepads = navigator.getGamepads(); + is(gamepads[0].buttons[1].pressed, true, "gamepad button should register as pressed"); + is(gamepads[0].buttons[1].value, 0.5, "gamepad button value should be 0.5"); + GamepadService.removeGamepad(index); + SimpleTest.finish(); +} + +</script> +</body> +</html> + |