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 if (window.gamepadController) | 5 if (window.gamepadController) |
6 { | 6 { |
7 // start all disconnected | 7 // start all disconnected |
8 gamepadController.disconnect(0); | 8 gamepadController.disconnect(0); |
9 gamepadController.disconnect(1); | 9 gamepadController.disconnect(1); |
10 gamepadController.disconnect(2); | 10 gamepadController.disconnect(2); |
11 gamepadController.disconnect(3); | 11 gamepadController.disconnect(3); |
12 shouldBe("navigator.getGamepads().length", "4"); | 12 |
13 shouldBeNull("navigator.getGamepads().item(0)"); | 13 shouldBeType("navigator.getGamepads()", "Array"); |
14 shouldBeNull("navigator.getGamepads().item(1)"); | 14 shouldBe("navigator.getGamepads().length", "0"); |
15 shouldBeNull("navigator.getGamepads().item(2)"); | 15 shouldBeFalse("navigator.getGamepads().hasOwnProperty(0)"); |
16 shouldBeNull("navigator.getGamepads().item(3)"); | 16 shouldBeFalse("navigator.getGamepads().hasOwnProperty(1)"); |
17 shouldBeUndefined("navigator.getGamepads()[0]"); | |
18 shouldBeUndefined("navigator.getGamepads()[1]"); | |
19 shouldBeUndefined("navigator.getGamepads()[2]"); | |
20 shouldBeUndefined("navigator.getGamepads()[3]"); | |
21 | 17 |
22 // connect and disconnect | 18 // connect and disconnect |
23 gamepadController.connect(0); | 19 gamepadController.connect(0); |
24 shouldBeNonNull("navigator.getGamepads()[0]"); | 20 shouldBe("navigator.getGamepads().length", "1"); |
| 21 shouldBeTrue("navigator.getGamepads().hasOwnProperty(0)"); |
| 22 shouldBeType("navigator.getGamepads()[0]", "Gamepad"); |
| 23 shouldBe("navigator.getGamepads()[0].index", "0"); |
| 24 shouldBeFalse("navigator.getGamepads().hasOwnProperty(1)"); |
| 25 gamepadController.connect(1); |
| 26 shouldBe("navigator.getGamepads().length", "2"); |
| 27 shouldBeTrue("navigator.getGamepads().hasOwnProperty(0)"); |
| 28 shouldBeType("navigator.getGamepads()[0]", "Gamepad"); |
| 29 shouldBe("navigator.getGamepads()[0].index", "0"); |
| 30 shouldBeTrue("navigator.getGamepads().hasOwnProperty(1)"); |
| 31 shouldBeType("navigator.getGamepads()[1]", "Gamepad"); |
| 32 shouldBe("navigator.getGamepads()[1].index", "1"); |
25 gamepadController.disconnect(0); | 33 gamepadController.disconnect(0); |
26 shouldBeNull("navigator.getGamepads().item(0)"); | 34 shouldBe("navigator.getGamepads().length", "2"); |
27 shouldBeUndefined("navigator.getGamepads()[0]"); | 35 shouldBeTrue("navigator.getGamepads().hasOwnProperty(0)"); // FIXME |
| 36 shouldBeNull("navigator.getGamepads()[0]"); // FIXME |
| 37 shouldBeTrue("navigator.getGamepads().hasOwnProperty(1)"); |
| 38 shouldBeType("navigator.getGamepads()[1]", "Gamepad"); |
| 39 shouldBe("navigator.getGamepads()[1].index", "1"); |
| 40 gamepadController.disconnect(1); |
| 41 shouldBe("navigator.getGamepads().length", "0"); |
| 42 shouldBeFalse("navigator.getGamepads().hasOwnProperty(0)"); |
| 43 shouldBeFalse("navigator.getGamepads().hasOwnProperty(1)"); |
28 | 44 |
29 // connect again, and check standard access | 45 // connect again, and check standard access |
30 gamepadController.connect(0); | 46 gamepadController.connect(0); |
31 gamepadController.setId(0, "MockStick 3000"); | 47 gamepadController.setId(0, "MockStick 3000"); |
32 gamepadController.setButtonCount(0, 2); | 48 gamepadController.setButtonCount(0, 2); |
33 gamepadController.setAxisCount(0, 2); | 49 gamepadController.setAxisCount(0, 2); |
34 gamepadController.setButtonData(0, 0, 1); | 50 gamepadController.setButtonData(0, 0, 1); |
35 gamepadController.setButtonData(0, 1, 0); | 51 gamepadController.setButtonData(0, 1, 0); |
36 gamepadController.setAxisData(0, 0, .5); | 52 gamepadController.setAxisData(0, 0, .5); |
37 gamepadController.setAxisData(0, 1, -1.0); | 53 gamepadController.setAxisData(0, 1, -1.0); |
38 shouldBe("navigator.getGamepads()[0].id", "'MockStick 3000'"); | 54 shouldBe("navigator.getGamepads()[0].id", "'MockStick 3000'"); |
39 shouldBe("navigator.getGamepads()[0].buttons.length", "2"); | 55 shouldBe("navigator.getGamepads()[0].buttons.length", "2"); |
40 shouldBe("navigator.getGamepads()[0].axes.length", "2"); | 56 shouldBe("navigator.getGamepads()[0].axes.length", "2"); |
41 shouldBe("navigator.getGamepads()[0].buttons[0].value", "1.0"); | 57 shouldBe("navigator.getGamepads()[0].buttons[0].value", "1.0"); |
42 shouldBe("navigator.getGamepads()[0].buttons[0].pressed", "true"); | 58 shouldBe("navigator.getGamepads()[0].buttons[0].pressed", "true"); |
43 shouldBe("navigator.getGamepads()[0].buttons[1].value", "0.0"); | 59 shouldBe("navigator.getGamepads()[0].buttons[1].value", "0.0"); |
44 shouldBe("navigator.getGamepads()[0].buttons[1].pressed", "false"); | 60 shouldBe("navigator.getGamepads()[0].buttons[1].pressed", "false"); |
45 shouldBe("navigator.getGamepads()[0].axes.length", "2"); | 61 shouldBe("navigator.getGamepads()[0].axes.length", "2"); |
46 shouldBe("navigator.getGamepads()[0].axes[0]", "0.5"); | 62 shouldBe("navigator.getGamepads()[0].axes[0]", "0.5"); |
47 shouldBe("navigator.getGamepads()[0].axes[1]", "-1.0"); | 63 shouldBe("navigator.getGamepads()[0].axes[1]", "-1.0"); |
48 } | 64 } |
49 else | 65 else |
50 { | 66 { |
51 console.log("FAIL: no gamepadController available.") | 67 console.log("FAIL: no gamepadController available.") |
52 } | 68 } |
53 </script> | 69 </script> |
54 <p>Typical polling access to gamepads contents.</p> | 70 <p>Typical polling access to gamepads contents.</p> |
55 </body> | 71 </body> |
OLD | NEW |