diff --git a/dom/tests/mochitest/gamepad/mock_gamepad.js b/dom/tests/mochitest/gamepad/mock_gamepad.js index a8832a31a8ac..a246604242e5 100644 --- a/dom/tests/mochitest/gamepad/mock_gamepad.js +++ b/dom/tests/mochitest/gamepad/mock_gamepad.js @@ -3,11 +3,10 @@ var GamepadService; -GamepadService = SpecialPowers.Cc["@mozilla.org/gamepad-test;1"].getService(SpecialPowers.Ci.nsIGamepadServiceTest); - - -var addGamepad = function(name, mapping, buttons, axes) { - return new Promise((resolve, reject) => { - resolve(GamepadService.addGamepad(name, mapping, buttons, axes)); - }); -} +function runGamepadTest (callback) { + SpecialPowers.pushPrefEnv({"set" : [["dom.gamepad.test.enabled", true]]}, + () => { + GamepadService = navigator.requestGamepadServiceTest(); + callback(); + }); +} \ No newline at end of file diff --git a/dom/tests/mochitest/gamepad/test_check_timestamp.html b/dom/tests/mochitest/gamepad/test_check_timestamp.html index d54e1d29c4b9..fa167d57b8e5 100644 --- a/dom/tests/mochitest/gamepad/test_check_timestamp.html +++ b/dom/tests/mochitest/gamepad/test_check_timestamp.html @@ -10,25 +10,31 @@ diff --git a/dom/tests/mochitest/gamepad/test_gamepad_connect_events.html b/dom/tests/mochitest/gamepad/test_gamepad_connect_events.html index 08988a2ba59c..3d5df9cf71bb 100644 --- a/dom/tests/mochitest/gamepad/test_gamepad_connect_events.html +++ b/dom/tests/mochitest/gamepad/test_gamepad_connect_events.html @@ -24,13 +24,13 @@ function pressButton() { // Add a gamepad function startTests() { - addGamepad("test gamepad", // id - SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING, - 4, // buttons - 2).then(function(i) { - gamepad_index = i; - gamepad_connected() - }); + GamepadService.addGamepad("test gamepad", // id + GamepadService.standardMapping, + 4, // buttons + 2).then(function(i) { + gamepad_index = i; + gamepad_connected() + }); } var f1, f2; @@ -71,6 +71,6 @@ function test2() { } - + diff --git a/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html index 5f8b4e5fe4de..abf7217899a5 100644 --- a/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html +++ b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html @@ -24,19 +24,33 @@ var frames_loaded = 0; function startTest() { frames_loaded++; if (frames_loaded == 2) { - addGamepad("test gamepad", // id - SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING, - 4, // buttons - 2).then(function(i) { - index = i; - gamepad_loaded(); - }); + GamepadService.addGamepad("test gamepad", // id + GamepadService.standardMapping, + 4, // buttons + 2).then(function(i) { + index = i; + gamepad_loaded(); + }); } } var f1, f2; function gamepad_loaded() { f1 = document.getElementById('f1'); f2 = document.getElementById('f2'); + let w1 = f1.contentWindow; + let w2 = f2.contentWindow; + w1.addEventListener("gamepadbuttonup", () => { + ok(!f1.contentWindow.gamepad.buttons[0].pressed, + "frame 1 no button pressed"); + }); + w2.addEventListener("gamepadbuttonup", () => { + ok(!f2.contentWindow.gamepad.buttons[0].pressed, + "frame 2 no button pressed"); + setFrameVisible(f2, false); + SpecialPowers.executeSoon(function() { + GamepadService.newButtonEvent(index, 0, true); + }); + }) // Now press the button, but don't release it. GamepadService.newButtonEvent(index, 0, true); } @@ -59,15 +73,6 @@ function check_button_pressed() { // Now release the button, then hide the second frame. GamepadService.newButtonEvent(index, 0, false); - SpecialPowers.executeSoon(function() { - // Now press the button, but don't release it. - ok(!f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 no button pressed"); - ok(!f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 no button pressed"); - setFrameVisible(f2, false); - SpecialPowers.executeSoon(function() { - GamepadService.newButtonEvent(index, 0, true); - }); - }); } function check_second_frame_no_button_press () { @@ -91,7 +96,7 @@ function check_second_frame_no_button_press () { } - - + + diff --git a/dom/tests/mochitest/gamepad/test_gamepad_hidden_frame.html b/dom/tests/mochitest/gamepad/test_gamepad_hidden_frame.html index 3b9ae2d52e95..d287a128d03e 100644 --- a/dom/tests/mochitest/gamepad/test_gamepad_hidden_frame.html +++ b/dom/tests/mochitest/gamepad/test_gamepad_hidden_frame.html @@ -12,6 +12,11 @@ - - + + diff --git a/dom/tests/mochitest/gamepad/test_navigator_gamepads.html b/dom/tests/mochitest/gamepad/test_navigator_gamepads.html index a509401795e2..48f78397a7e7 100644 --- a/dom/tests/mochitest/gamepad/test_navigator_gamepads.html +++ b/dom/tests/mochitest/gamepad/test_navigator_gamepads.html @@ -24,9 +24,6 @@ function run_next_test(event) { SpecialPowers.executeSoon(function() { tests[testNum++](event); }); } -// gamepads should be empty first -is(navigator.getGamepads().length, 0, "should be zero gamepads exposed"); - function buttonhandler(e) { run_next_test(e); } @@ -36,15 +33,22 @@ function disconnecthandler(e) { } window.addEventListener("gamepadbuttondown", buttonhandler); window.addEventListener("gamepaddisconnected", disconnecthandler); -// Add a gamepad -addGamepad("test gamepad 1", // id - SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING, - 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); - }); + +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; @@ -59,13 +63,13 @@ function check_first_gamepad(e) { 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. - addGamepad("test gamepad 2", // id - SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING, - 4, // buttons - 2).then(function(index) { - internal_index2 = index; - GamepadService.newButtonEvent(internal_index2, 0, true); - }); + 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"); }