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