Bug 1336002 - Part 4: Add gamepad button touched tests; r=Lenzak,qdot
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 10 Apr 2017 11:48:30 +0800
changeset 560264 4d1d356ad1b3d37716d2657de15a031acf883159
parent 560263 961f1f9a522e2942a040ce63e735ef774dbbe905
child 560265 39460355837190ae3ae5ad458cb9039a893643fe
push id53365
push userjichen@mozilla.com
push dateTue, 11 Apr 2017 08:35:12 +0000
reviewersLenzak, qdot
bugs1336002
milestone55.0a1
Bug 1336002 - Part 4: Add gamepad button touched tests; r=Lenzak,qdot MozReview-Commit-ID: 5OoR2vf0zZn
dom/tests/mochitest/gamepad/test_check_timestamp_iframe.html
dom/tests/mochitest/gamepad/test_gamepad_connect_events_iframe.html
dom/tests/mochitest/gamepad/test_gamepad_extensions_iframe.html
dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html
dom/tests/mochitest/gamepad/test_gamepad_hidden_frame_iframe.html
dom/tests/mochitest/gamepad/test_gamepad_iframe.html
dom/tests/mochitest/gamepad/test_navigator_gamepads_iframe.html
--- a/dom/tests/mochitest/gamepad/test_check_timestamp_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_check_timestamp_iframe.html
@@ -29,18 +29,18 @@ function checkTimestamp(){
                             GamepadService.standardMapping,
                             GamepadService.noHand,
                             4,
                             2,
                             0).then(function(i) {
                               index = i;
                               // Press a button to make the gamepad visible
                               // to the page.
-                              GamepadService.newButtonEvent(index, 0, true);
-                              GamepadService.newButtonEvent(index, 0, true);
+                              GamepadService.newButtonEvent(index, 0, true, true);
+                              GamepadService.newButtonEvent(index, 0, true, true);
                               ok(true, "test");
                             });
 }
 
 function cleanup(){
   SpecialPowers.executeSoon(function() {
     GamepadService.removeGamepad(index);
     SimpleTest.finish();
@@ -51,17 +51,17 @@ function buttonpresshandler(e) {
   if (testOver) {
     return;
   }
   if (timea == 0){
     timea = e.gamepad.timestamp;
   } else {
     ok(timea <= e.gamepad.timestamp, "Timestamp less than last timestamp");
   }
-  GamepadService.newButtonEvent(index, 0, false);
+  GamepadService.newButtonEvent(index, 0, false, false);
   if (!firstPress) {
     testOver = true;
     SpecialPowers.executeSoon(cleanup);
   } else {
     firstPress = false;
   }
 }
 
--- a/dom/tests/mochitest/gamepad/test_gamepad_connect_events_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_gamepad_connect_events_iframe.html
@@ -16,18 +16,18 @@
 let ok = window.parent.ok;
 let is = window.parent.is;
 let SimpleTest = window.parent.SimpleTest;
 let SpecialPowers = window.parent.SpecialPowers;
 
 var gamepad_index;
 
 function pressButton() {
-  GamepadService.newButtonEvent(gamepad_index, 0, true);
-  GamepadService.newButtonEvent(gamepad_index, 0, false);
+  GamepadService.newButtonEvent(gamepad_index, 0, true, true);
+  GamepadService.newButtonEvent(gamepad_index, 0, false, false);
 }
 
  // Add a gamepad
 function startTests() {
   window.addEventListener("gamepadbuttondown", function() {
     // Wait to ensure that all frames received the button press as well.
     SpecialPowers.executeSoon(tests[testNum++]);
   });
--- a/dom/tests/mochitest/gamepad/test_gamepad_extensions_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_gamepad_extensions_iframe.html
@@ -30,18 +30,18 @@ var poseLinAcc = new Float32Array([-1.21
 
 window.addEventListener("gamepadconnected", connecthandler);
 window.addEventListener("gamepadbuttondown", function() {
   // Wait to ensure that all frames received the button press as well.
   SpecialPowers.executeSoon(tests[testNum++]);
 });
 
 function pressButton() {
-  GamepadService.newButtonEvent(gamepad_index, 0, true);
-  GamepadService.newButtonEvent(gamepad_index, 0, false);
+  GamepadService.newButtonEvent(gamepad_index, 0, true, true);
+  GamepadService.newButtonEvent(gamepad_index, 0, false, false);
 }
 
 function startTest() {
   SpecialPowers.pushPrefEnv({ "set": [["dom.gamepad.extensions.enabled", true]] });
   // Add a gamepad
   GamepadService.addGamepad("test gamepad", // id
                      GamepadService.standardMapping,
                      GamepadService.leftHand,
--- a/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync_iframe.html
@@ -42,63 +42,72 @@ 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");
+                       ok(!f1.contentWindow.gamepad.buttons[0].touched,
+                          "frame 1 no button touched");
                       });
   w2.addEventListener("gamepadbuttonup", () => {
                       ok(!f2.contentWindow.gamepad.buttons[0].pressed,
                          "frame 2 no button pressed");
+                      ok(!f2.contentWindow.gamepad.buttons[0].touched,
+                         "frame 2 no button touched");
                       setFrameVisible(f2, false);
                       SpecialPowers.executeSoon(function() {
-                        GamepadService.newButtonEvent(index, 0, true);
+                        GamepadService.newButtonEvent(index, 0, true, true);
                         });
                       })
   // Now press the button, but don't release it.
-  GamepadService.newButtonEvent(index, 0, true);
+  GamepadService.newButtonEvent(index, 0, true, true);
 }
 
 window.addEventListener("gamepadbuttondown", function() {
   // Wait to ensure that all frames received the button press as well.
  SpecialPowers.executeSoon(tests[testNum++]);
 });
 
 var testNum = 0;
 var tests = [
   check_button_pressed,
   check_second_frame_no_button_press,
 ];
 
 function check_button_pressed() {
   // At this point the both frames should see the button as pressed.
   ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
+  ok(f1.contentWindow.gamepad.buttons[0].touched, "frame 1 sees button touched");
   ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
+  ok(f2.contentWindow.gamepad.buttons[0].touched, "frame 2 sees button touched");
 
   // Now release the button, then hide the second frame.
-  GamepadService.newButtonEvent(index, 0, false);
+  GamepadService.newButtonEvent(index, 0, false, false);
 }
 
 function check_second_frame_no_button_press () {
   /*
    * At this point the first frame should see the button as pressed,
    * but the second frame should not, since it's hidden.
    */
   ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
+  ok(f1.contentWindow.gamepad.buttons[0].touched, "frame 1 sees button touched");
   ok(!f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 should not see button pressed");
+  ok(!f2.contentWindow.gamepad.buttons[0].touched, "frame 2 should not see button touched");
 
   // Now unhide the second frame.
   setFrameVisible(f2, true);
   SpecialPowers.executeSoon(function() {
     // Now that the frame is visible again, it should see the button
     // that was pressed.
     ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
+    ok(f2.contentWindow.gamepad.buttons[0].touched, "frame 2 sees button touched");
     // cleanup
     GamepadService.removeGamepad(index);
     SimpleTest.finish();
   });
 }
 
 </script>
 <iframe id="f1" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe>
--- a/dom/tests/mochitest/gamepad/test_gamepad_hidden_frame_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_gamepad_hidden_frame_iframe.html
@@ -15,18 +15,18 @@ let SimpleTest = window.parent.SimpleTes
 let SpecialPowers = window.parent.SpecialPowers;
 
 window.addEventListener("gamepadbuttondown", function() {
   // Wait to ensure that all frames received the button press as well.
  SpecialPowers.executeSoon(tests[testNum++]);
 });
 
 function pressButton() {
-  GamepadService.newButtonEvent(index, 0, true);
-  GamepadService.newButtonEvent(index, 0, false);
+  GamepadService.newButtonEvent(index, 0, true, true);
+  GamepadService.newButtonEvent(index, 0, false, false);
 }
 
 function setFrameVisible(f, visible) {
   var Ci = SpecialPowers.Ci;
   var docshell = SpecialPowers.wrap(f.contentWindow).QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell);
   docshell.isActive = visible;
 }
 
--- a/dom/tests/mochitest/gamepad/test_gamepad_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_gamepad_iframe.html
@@ -37,39 +37,41 @@ function startTest() {
   GamepadService.addGamepad("test gamepad", // id
                      GamepadService.standardMapping,
                      GamepadService.noHand,
                      4,
                      2,
                      0).then(function(i) {
                        index = i;
                        // Simulate button events on the gamepad we added
-                       GamepadService.newButtonEvent(index, 0, true);
+                       GamepadService.newButtonEvent(index, 0, true, true);
                      });
 }
 
 function connecthandler(e) {
   ok(e.gamepad.timestamp <= performance.now(),
      "gamepad.timestamp should less than or equal to performance.now()");
   is(e.gamepad.index, 0, "correct gamepad index");
   is(e.gamepad.id, "test gamepad", "correct gamepad name");
   is(e.gamepad.mapping, "standard", "standard mapping");
   is(e.gamepad.buttons.length, 4, "correct number of buttons");
   is(e.gamepad.axes.length, 2, "correct number of axes");
 }
 
 function buttontest1() {
   var gamepads = navigator.getGamepads();
   is(gamepads[0].buttons[0].pressed, true, "gamepad button should register as pressed");
-  GamepadService.newButtonValueEvent(index, 1, true, 0.5);
+  is(gamepads[0].buttons[0].touched, true, "gamepad button should register as touched");
+  GamepadService.newButtonValueEvent(index, 1, true, true, 0.5);
 }
 
 function buttontest2() {
   var gamepads = navigator.getGamepads();
   is(gamepads[0].buttons[1].pressed, true, "gamepad button should register as pressed");
+  is(gamepads[0].buttons[1].touched, true, "gamepad button should register as touched");
   is(gamepads[0].buttons[1].value, 0.5, "gamepad button value should be 0.5");
   GamepadService.removeGamepad(index);
   SimpleTest.finish();
 }
 
 </script>
 </body>
 </html>
--- a/dom/tests/mochitest/gamepad/test_navigator_gamepads_iframe.html
+++ b/dom/tests/mochitest/gamepad/test_navigator_gamepads_iframe.html
@@ -46,17 +46,17 @@ function startTest() {
   GamepadService.addGamepad("test gamepad 1", // id
                      GamepadService.standardMapping,
                      GamepadService.noHand,
                      4, // buttons
                      2,
                      0).then(function(index) {
                        internal_index1 = index;
                        // Press a button to make the gamepad visible to the page.
-                       GamepadService.newButtonEvent(internal_index1, 0, true);
+                       GamepadService.newButtonEvent(internal_index1, 0, true, true);
                      });
 }
 
 var content_index1 = 0;
 var internal_index2;
 var content_index2 = 1;
 
 function check_first_gamepad(e) {
@@ -70,17 +70,17 @@ function check_first_gamepad(e) {
   // Add a second gamepad, should automatically show up.
   GamepadService.addGamepad("test gamepad 2", // id
                      GamepadService.standardMapping,
                      GamepadService.noHand,
                      4, // buttons
                      2,
                      0).then(function(index) {
                        internal_index2 = index;
-                       GamepadService.newButtonEvent(internal_index2, 0, true);
+                       GamepadService.newButtonEvent(internal_index2, 0, true, 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")