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