diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/gamepad/test_navigator_gamepads.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/gamepad/test_navigator_gamepads.html')
-rw-r--r-- | dom/tests/mochitest/gamepad/test_navigator_gamepads.html | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/dom/tests/mochitest/gamepad/test_navigator_gamepads.html b/dom/tests/mochitest/gamepad/test_navigator_gamepads.html new file mode 100644 index 000000000..48f78397a --- /dev/null +++ b/dom/tests/mochitest/gamepad/test_navigator_gamepads.html @@ -0,0 +1,111 @@ +<!-- Any copyright is dedicated to the Public Domain. + - http://creativecommons.org/publicdomain/zero/1.0/ --> +<!DOCTYPE HTML> +<html> +<head> + <title>Test gamepad</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<script type="text/javascript" src="mock_gamepad.js"></script> +<script class="testbody" type="text/javascript"> +SimpleTest.waitForExplicitFinish(); + +var testNum = 0; +var tests = [ + check_first_gamepad, + check_second_gamepad, + check_gamepad_hole, + check_no_gamepads, +]; + +function run_next_test(event) { + SpecialPowers.executeSoon(function() { tests[testNum++](event); }); +} + +function buttonhandler(e) { + run_next_test(e); +} + +function disconnecthandler(e) { + run_next_test(e); +} +window.addEventListener("gamepadbuttondown", buttonhandler); +window.addEventListener("gamepaddisconnected", disconnecthandler); + +runGamepadTest(startTest) + +function startTest() { + // gamepads should be empty first + is(navigator.getGamepads().length, 0, "should be zero gamepads exposed"); + // Add a gamepad + GamepadService.addGamepad("test gamepad 1", // id + GamepadService.standardMapping, + 4, // buttons + 2).then(function(index) { + internal_index1 = index; + // Press a button to make the gamepad visible to the page. + GamepadService.newButtonEvent(internal_index1, 0, true); + }); +} + +var content_index1 = 0; +var internal_index2; +var content_index2 = 1; + +function check_first_gamepad(e) { + ok(true, "Checking first gamepad"); + // First gamepad gets added. + is(e.gamepad.id, "test gamepad 1", "correct gamepad name"); + var gamepads = navigator.getGamepads(); + is(gamepads.length, 1, "should have one gamepad exposed"); + is(gamepads[e.gamepad.index], e.gamepad, "right gamepad exposed at index"); + is(gamepads[content_index1], e.gamepad, "gamepad counter working correctly"); + // Add a second gamepad, should automatically show up. + GamepadService.addGamepad("test gamepad 2", // id + GamepadService.standardMapping, + 4, // buttons + 2).then(function(index) { + internal_index2 = index; + GamepadService.newButtonEvent(internal_index2, 0, true); + }); + ok(true, "Done checking first gamepad"); +} + +function check_second_gamepad(e) { + ok(true, "Checking second gamepad"); + // Second gamepad gets added. + is(e.gamepad.index, 1, "gamepad index should be 1") + is(e.gamepad.id, "test gamepad 2", "correct gamepad name"); + var gamepads = navigator.getGamepads(); + is(gamepads.length, 2, "should have two gamepads exposed"); + is(gamepads[e.gamepad.index], e.gamepad, "right gamepad exposed at index"); + is(gamepads[content_index2], e.gamepad, "gamepad counter working correctly"); + // Now remove the first one. + GamepadService.removeGamepad(internal_index1); + ok(true, "Done checking second gamepad"); +} + +function check_gamepad_hole(e) { + ok(true, "Checking gamepad hole"); + // First gamepad gets removed. + var gamepads = navigator.getGamepads(); + is(gamepads.length, 2, "gamepads should have two entries"); + is(gamepads[content_index1], null, "should be a hole in the gamepad list"); + isnot(gamepads[content_index2], null, "second gamepad should exist"); + // Now remove the second one. + GamepadService.removeGamepad(internal_index2); + ok(true, "Done checking gamepad hole"); +} + +function check_no_gamepads(e) { + ok(true, "Checking no gamepads"); + // Second gamepad gets removed. + var gamepads = navigator.getGamepads(); + is(gamepads.length, 0, "gamepads should be empty"); + SimpleTest.finish(); +} +</script> +</body> +</html> |