2011-08-03 22:12:08 +04:00
|
|
|
<!-- 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();
|
|
|
|
window.addEventListener("gamepadconnected", connecthandler);
|
|
|
|
// Add a gamepad
|
2016-03-04 04:11:47 +03:00
|
|
|
var index = GamepadService.addGamepad("test gamepad", // id
|
|
|
|
SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING,
|
|
|
|
4, // buttons
|
|
|
|
2);// axes
|
|
|
|
GamepadService.newButtonEvent(index, 0, true);
|
2011-08-03 22:12:08 +04:00
|
|
|
function connecthandler(e) {
|
2015-07-30 08:41:00 +03:00
|
|
|
ok(e.gamepad.timestamp <= performance.now(),
|
|
|
|
"gamepad.timestamp should less than or equal to performance.now()");
|
2015-04-24 01:05:29 +03:00
|
|
|
is(e.gamepad.index, 0, "correct gamepad index");
|
2013-04-09 16:43:25 +04:00
|
|
|
is(e.gamepad.id, "test gamepad", "correct gamepad name");
|
|
|
|
is(e.gamepad.mapping, "standard", "standard mapping");
|
2011-08-03 22:12:08 +04:00
|
|
|
is(e.gamepad.buttons.length, 4, "correct number of buttons");
|
|
|
|
is(e.gamepad.axes.length, 2, "correct number of axes");
|
2016-03-04 04:11:47 +03:00
|
|
|
// Press a button
|
|
|
|
GamepadService.newButtonEvent(index, 0, true);
|
|
|
|
gamepads = navigator.getGamepads();
|
|
|
|
is(gamepads[0].buttons[0].pressed, true, "gamepad button should register as pressed")
|
|
|
|
GamepadService.newButtonValueEvent(index, 1, true, 0.5);
|
|
|
|
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")
|
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
GamepadService.removeGamepad(index);
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
}
|
2016-03-04 04:11:47 +03:00
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|