blob: 8dcd2a5c7577b2f306afc9fd083ffc47614e081f [file] [log] [blame]
<head>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
function log(msg)
{
document.getElementById("logger").innerHTML += msg + "<br>";
}
function finishTest()
{
if (testRunner)
testRunner.notifyDone();
}
function handleGamepadConnect(evt)
{
log("Connecting gamepad:");
log(navigator.getGamepads());
logGamepad(evt.gamepad);
testGenerator.next();
}
function handleGamepadDisconnect(evt)
{
log("Disconnecting gamepad:");
log(navigator.getGamepads());
testGenerator.next();
}
function logGamepad(gp)
{
log("Name: " + gp.id);
log("Index: " + gp.index);
log("Mapping: " + gp.mapping);
log("Axes: " + gp.axes);
var buttonString = "";
for (button in gp.buttons) {
buttonString += gp.buttons[button].pressed + "-" + gp.buttons[button].value + " ";
}
log("Buttons: " + buttonString);
}
function* testSteps() {
addEventListener("gamepadconnected", handleGamepadConnect);
addEventListener("gamepaddisconnected", handleGamepadDisconnect);
log("Initial gamepads length: " + navigator.getGamepads().length);
log("Connecting 20 different gamepads");
for (var i = 0; i < 20; ++i) {
testRunner.setMockGamepadDetails(i, i, "", i, i);
testRunner.connectMockGamepad(i);
yield;
}
log("Verifying there are 20 connected gamepads in the set of all gamepads");
var gamepads = navigator.getGamepads();
log(gamepads);
for (i in gamepads) {
logGamepad(gamepads[i]);
}
log("Disconnecting gamepads in reverse order, making sure gamepads array remains as expected");
for (var i = 19; i >= 0; --i) {
testRunner.disconnectMockGamepad(i);
yield;
}
log("Checking non-zero'ed details for a gamepad");
testRunner.setMockGamepadDetails(10, "Awesome Joystick 5000", "standard", 4, 16);
testRunner.setMockGamepadAxisValue(10, 0, 0.7);
testRunner.setMockGamepadAxisValue(10, 1, -0.9);
testRunner.setMockGamepadAxisValue(10, 2, 1.0);
testRunner.setMockGamepadAxisValue(10, 3, -1.0);
for (var i = 0; i < 16; ++i)
testRunner.setMockGamepadButtonValue(10, i, 1.0);
testRunner.connectMockGamepad(10);
yield;
finishTest();
}
function runTest()
{
testGenerator = testSteps();
testGenerator.next();
}
</script>
</head>
<body onload="runTest();">
<div id="logger"></div>
</body>