Bug 1530220 - part2 : modify test in order to test different kinds of keycode. r=cpearce a=lizzard
authorAlastor Wu <alwu@mozilla.com>
Tue, 05 Mar 2019 02:09:50 +0000
changeset 516286 4b05bf628c6106f4d690a5da78e826f7ab3e80fc
parent 516285 dc39216dfad387efd439083045062e323869a428
child 516287 71e48c6607e6c53eed1de2256c5760fa6c1b18aa
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lizzard
bugs1530220
milestone66.0
Bug 1530220 - part2 : modify test in order to test different kinds of keycode. r=cpearce a=lizzard Except printable keys, we would treat `carriage return` and `space` as supported user gesture inputs for activating document. Other keys won't activate document. Differential Revision: https://phabricator.services.mozilla.com/D21255
toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js
--- a/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js
+++ b/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js
@@ -6,17 +6,22 @@ var UserGestures = {
   MOUSE_CLICK: "mouse-click",
   MOUSE_MOVE: "mouse-move",
   KEYBOARD_PRESS: "keyboard-press",
 };
 
 var UserGestureTests = [
   {type: UserGestures.MOUSE_CLICK, isActivationGesture: true},
   {type: UserGestures.MOUSE_MOVE, isActivationGesture: false},
-  {type: UserGestures.KEYBOARD_PRESS, isActivationGesture: true},
+  // test different keycode here. printable key, non-printable key and other
+  // special keys.
+  {type: UserGestures.KEYBOARD_PRESS, isActivationGesture: true, keyCode: "a"},
+  {type: UserGestures.KEYBOARD_PRESS, isActivationGesture: false, keyCode: "VK_ESCAPE"},
+  {type: UserGestures.KEYBOARD_PRESS, isActivationGesture: true, keyCode: "VK_RETURN"},
+  {type: UserGestures.KEYBOARD_PRESS, isActivationGesture: true, keyCode: "VK_SPACE"},
 ];
 
 function setup_test_preference() {
   return SpecialPowers.pushPrefEnv({"set": [
     ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
     ["media.autoplay.enabled.user-gestures-needed", true],
     ["media.autoplay.block-webaudio", true],
     ["media.navigator.permission.fake", true],
@@ -28,17 +33,17 @@ function simulateUserGesture(gesture, ta
   switch (gesture.type) {
     case UserGestures.MOUSE_CLICK:
       return BrowserTestUtils.synthesizeMouseAtCenter("body", {button: 0},
                                                       targetBrowser);
     case UserGestures.MOUSE_MOVE:
       return BrowserTestUtils.synthesizeMouseAtCenter("body", {type: "mousemove"},
                                                       targetBrowser);
     case UserGestures.KEYBOARD_PRESS:
-      return BrowserTestUtils.sendChar("a", targetBrowser);
+      return BrowserTestUtils.synthesizeKey(gesture.keyCode, {}, targetBrowser);
     default:
       ok(false, "undefined user gesture");
       return false;
   }
 }
 
 async function test_play_without_user_gesture() {
   info("- open new tab -");