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