3 <script src=
"../resources/js-test.js"></script>
5 if (window
.gamepadController
)
7 // start all disconnected
8 gamepadController
.disconnect(0);
9 gamepadController
.disconnect(1);
10 gamepadController
.disconnect(2);
11 gamepadController
.disconnect(3);
12 shouldBe("navigator.getGamepads().length", "4");
13 shouldBeNull("navigator.getGamepads().item(0)");
14 shouldBeNull("navigator.getGamepads().item(1)");
15 shouldBeNull("navigator.getGamepads().item(2)");
16 shouldBeNull("navigator.getGamepads().item(3)");
17 shouldBeUndefined("navigator.getGamepads()[0]");
18 shouldBeUndefined("navigator.getGamepads()[1]");
19 shouldBeUndefined("navigator.getGamepads()[2]");
20 shouldBeUndefined("navigator.getGamepads()[3]");
22 // connect and disconnect
23 gamepadController
.connect(0);
24 shouldBeNonNull("navigator.getGamepads()[0]");
25 gamepadController
.disconnect(0);
26 shouldBeNull("navigator.getGamepads().item(0)");
27 shouldBeUndefined("navigator.getGamepads()[0]");
29 // connect again, and check standard access
30 gamepadController
.connect(0);
31 gamepadController
.setId(0, "MockStick 3000");
32 gamepadController
.setButtonCount(0, 2);
33 gamepadController
.setAxisCount(0, 2);
34 gamepadController
.setButtonData(0, 0, 1);
35 gamepadController
.setButtonData(0, 1, 0);
36 gamepadController
.setAxisData(0, 0, .5);
37 gamepadController
.setAxisData(0, 1, -1.0);
38 shouldBe("navigator.getGamepads()[0].id", "'MockStick 3000'");
39 shouldBe("navigator.getGamepads()[0].buttons.length", "2");
40 shouldBe("navigator.getGamepads()[0].axes.length", "2");
41 shouldBe("navigator.getGamepads()[0].buttons[0].value", "1.0");
42 shouldBe("navigator.getGamepads()[0].buttons[0].pressed", "true");
43 shouldBe("navigator.getGamepads()[0].buttons[1].value", "0.0");
44 shouldBe("navigator.getGamepads()[0].buttons[1].pressed", "false");
45 shouldBe("navigator.getGamepads()[0].axes.length", "2");
46 shouldBe("navigator.getGamepads()[0].axes[0]", "0.5");
47 shouldBe("navigator.getGamepads()[0].axes[1]", "-1.0");
51 console
.log("FAIL: no gamepadController available.")
54 <p>Typical polling access to gamepads contents.
</p>