3 <script src="../resources/js-test.js"></script>
5 description("Validates the exposed Gamepad API.")
7 shouldBeDefined("navigator.webkitGetGamepads");
8 shouldBeDefined("navigator.getGamepads");
9 shouldBeDefined("GamepadEvent");
11 webkitGamepads = navigator.webkitGetGamepads();
12 shouldBe("webkitGamepads.length", "4");
13 shouldBeUndefined("webkitGamepads[0]");
14 shouldBe("webkitGamepads.item.__proto__", "Function.prototype")
15 shouldBeNull("webkitGamepads.item(0)");
17 gamepads = navigator.getGamepads();
18 shouldBe("gamepads.length", "4");
19 shouldBeUndefined("gamepads[0]");
20 shouldBe("gamepads.item.__proto__", "Function.prototype")
21 shouldBeNull("gamepads.item(0)");
23 if (window.gamepadController)
25 gamepadController.connect(0);
26 gamepadController.setId(0, "MockStick 3000");
27 gamepadController.setButtonCount(0, 1);
28 gamepadController.setAxisCount(0, 1);
30 function checkProperties(isPrefixed) {
31 shouldBe("gamepad.id.__proto__", "String.prototype");
32 shouldBe("gamepad.connected.__proto__", "Boolean.prototype");
33 shouldBe("gamepad.index.__proto__", "Number.prototype");
34 shouldBe("gamepad.timestamp.__proto__", "Number.prototype");
35 shouldBe("gamepad.axes.__proto__", "Array.prototype");
36 shouldBe("gamepad.axes[0].__proto__", "Number.prototype");
38 shouldBe("gamepad.buttons.__proto__", "Array.prototype");
40 shouldBe("gamepad.buttons[0].__proto__", "Number.prototype");
42 shouldBe("gamepad.buttons[0].pressed.__proto__", "Boolean.prototype");
43 shouldBe("gamepad.buttons[0].value.__proto__", "Number.prototype");
47 shouldBe("gamepad.mapping.__proto__", "String.prototype");
50 gamepad = navigator.webkitGetGamepads()[0];
51 shouldBeNonNull("gamepad");
52 shouldBeTrue("gamepad.connected");
53 shouldBe("gamepad.__proto__", "WebKitGamepad.prototype");
54 checkProperties(true);
56 gamepad = navigator.getGamepads()[0];
57 shouldBeNonNull("gamepad");
58 shouldBeTrue("gamepad.connected");
59 shouldBe("gamepad.__proto__", "Gamepad.prototype");
60 checkProperties(false);
64 testFailed("no gamepadController available.");