OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <body> | 2 <body> |
3 <script src="../resources/js-test.js"></script> | 3 <script src="../resources/js-test.js"></script> |
4 <script> | 4 <script> |
5 description("Basic test for 'gamepadconnected' and 'gamepaddisconnected' eve
nts."); | 5 description("Basic test for 'gamepadconnected' and 'gamepaddisconnected' eve
nts."); |
6 | 6 |
7 jsTestIsAsync = true; | 7 jsTestIsAsync = true; |
8 | 8 |
9 if (window.gamepadController) | 9 if (window.gamepadController) |
10 { | 10 { |
11 function onConnected(event) { | 11 function onConnected(event) { |
12 debug("Gamepad connected"); | 12 debug("Gamepad connected"); |
13 shouldBe("event.__proto__", "GamepadEvent.prototype"); | 13 shouldBe("event.__proto__", "GamepadEvent.prototype"); |
14 shouldBe("event.__proto__.__proto__", "Event.prototype"); | 14 shouldBe("event.__proto__.__proto__", "Event.prototype"); |
15 shouldBeEqualToString("event.gamepad.id", "MockStick 3000"); | 15 shouldBeEqualToString("event.gamepad.id", "MockStick 3000"); |
16 shouldBe("event.gamepad.buttons.length", "3"); | 16 shouldBe("event.gamepad.buttons.length", "2"); |
17 shouldBe("event.gamepad.axes.length", "3"); | 17 shouldBe("event.gamepad.axes.length", "2"); |
18 shouldBe("event.gamepad.buttons[0].value", "1.0"); | 18 shouldBe("event.gamepad.buttons[0].value", "1.0"); |
19 shouldBeTrue("event.gamepad.buttons[0].pressed"); | 19 shouldBeTrue("event.gamepad.buttons[0].pressed"); |
20 shouldBe("event.gamepad.buttons[1].value", "0.0"); | 20 shouldBe("event.gamepad.buttons[1].value", "0.0"); |
21 shouldBeFalse("event.gamepad.buttons[1].pressed"); | 21 shouldBeFalse("event.gamepad.buttons[1].pressed"); |
22 shouldBe("event.gamepad.axes.length", "3"); | 22 shouldBe("event.gamepad.axes.length", "2"); |
23 shouldBe("event.gamepad.buttons[2].value", "0.333333"); | |
24 shouldBeTrue("event.gamepad.buttons[2].pressed"); | |
25 shouldBe("event.gamepad.axes[0]", "0.5"); | 23 shouldBe("event.gamepad.axes[0]", "0.5"); |
26 shouldBe("event.gamepad.axes[1]", "-1.0"); | 24 shouldBe("event.gamepad.axes[1]", "-1.0"); |
27 shouldBe("event.gamepad.axes[2]", "0.333333"); | |
28 gamepadController.disconnect(0); | 25 gamepadController.disconnect(0); |
29 } | 26 } |
30 | 27 |
31 function onDisconnected(event) { | 28 function onDisconnected(event) { |
32 debug("Gamepad disconnected"); | 29 debug("Gamepad disconnected"); |
33 shouldBe("event.__proto__", "GamepadEvent.prototype"); | 30 shouldBe("event.__proto__", "GamepadEvent.prototype"); |
34 shouldBe("event.__proto__.__proto__", "Event.prototype"); | 31 shouldBe("event.__proto__.__proto__", "Event.prototype"); |
35 shouldBeEqualToString("event.gamepad.id", "MockStick 3000"); | 32 shouldBeEqualToString("event.gamepad.id", "MockStick 3000"); |
36 shouldBe("event.gamepad.buttons.length", "3"); | 33 shouldBe("event.gamepad.buttons.length", "2"); |
37 shouldBe("event.gamepad.axes.length", "3"); | 34 shouldBe("event.gamepad.axes.length", "2"); |
38 finishJSTest(); | 35 finishJSTest(); |
39 } | 36 } |
40 | 37 |
41 window.addEventListener('gamepadconnected', onConnected); | 38 window.addEventListener('gamepadconnected', onConnected); |
42 window.addEventListener('gamepaddisconnected', onDisconnected); | 39 window.addEventListener('gamepaddisconnected', onDisconnected); |
43 | 40 |
44 gamepadController.connect(0); | 41 gamepadController.connect(0); |
45 gamepadController.setId(0, "MockStick 3000"); | 42 gamepadController.setId(0, "MockStick 3000"); |
46 gamepadController.setButtonCount(0, 3); | 43 gamepadController.setButtonCount(0, 2); |
47 gamepadController.setAxisCount(0, 3); | 44 gamepadController.setAxisCount(0, 2); |
48 gamepadController.setButtonData(0, 0, 1); | 45 gamepadController.setButtonData(0, 0, 1); |
49 gamepadController.setButtonData(0, 1, 0); | 46 gamepadController.setButtonData(0, 1, 0); |
50 gamepadController.setButtonData(0, 2, 0.333333); | |
51 gamepadController.setAxisData(0, 0, .5); | 47 gamepadController.setAxisData(0, 0, .5); |
52 gamepadController.setAxisData(0, 1, -1.0); | 48 gamepadController.setAxisData(0, 1, -1.0); |
53 gamepadController.setAxisData(0, 2, 0.333333); | |
54 gamepadController.dispatchConnected(0); | 49 gamepadController.dispatchConnected(0); |
55 } | 50 } |
56 else | 51 else |
57 { | 52 { |
58 testFailed("no gamepadController available."); | 53 testFailed("no gamepadController available."); |
59 } | 54 } |
60 </script> | 55 </script> |
61 </body> | 56 </body> |
OLD | NEW |