Bug 1405370 - [marionette] Synthesized key event for "Shift" has to capitalize typable characters. r=ato
authorHenrik Skupin <mail@hskupin.info>
Thu, 20 Sep 2018 12:24:27 +0200
changeset 493502 2998b10eb5a79d16557f5bf5b176482afe68522c
parent 493501 eec10aa9703c57236f64461c6b37ba9bbe06b4b8
child 493503 7c1a9d25aaf013ee3ec9b6856445dabe5ac484a1
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1405370
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1405370 - [marionette] Synthesized key event for "Shift" has to capitalize typable characters. r=ato The current code only capitalizes the "keyName" and not the "modifier.key" property. As such the capitalization gets lost, because in "event.createKeyboardEventDictionary_()" the "modifier.key" property gets precedence over "keyName". To not have to capitalize both at this level, it's better to move this code directly into "event.createKeyboardEventDictionary_()". This also makes the method "event.sendSingleKey()" useless, so it can be removed.
testing/marionette/event.js
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -450,16 +450,17 @@ function getKeyboardEvent_(win) {
 function createKeyboardEventDictionary_(key, keyEvent, win) {
   let result = {dictionary: null, flags: 0};
   let keyCodeIsDefined = "keyCode" in keyEvent &&
       keyEvent.keyCode != undefined;
   let keyCode =
     (keyCodeIsDefined && keyEvent.keyCode >= 0 && keyEvent.keyCode <= 255) ?
       keyEvent.keyCode : 0;
   let keyName = "Unidentified";
+
   if (key.indexOf("KEY_") == 0) {
     keyName = key.substr("KEY_".length);
     result.flags |= Ci.nsITextInputProcessor.KEY_NON_PRINTABLE_KEY;
   } else if (key.indexOf("VK_") == 0) {
     keyCode = getKeyboardEvent_(win)["DOM_" + key];
     if (!keyCode) {
       throw "Unknown key: " + key;
     }
@@ -475,27 +476,35 @@ function createKeyboardEventDictionary_(
     if (!keyCode) {
       result.flags |= Ci.nsITextInputProcessor.KEY_KEEP_KEYCODE_ZERO;
     }
     // only force printable if "raw character" and event key match, like "a"
     if (!("key" in keyEvent && key != keyEvent.key)) {
       result.flags |= Ci.nsITextInputProcessor.KEY_FORCE_PRINTABLE_KEY;
     }
   }
+
   let locationIsDefined = "location" in keyEvent;
   if (locationIsDefined && keyEvent.location === 0) {
     result.flags |= Ci.nsITextInputProcessor.KEY_KEEP_KEY_LOCATION_STANDARD;
   }
+
+  let resultKey = "key" in keyEvent ? keyEvent.key : keyName;
+  if (!MODIFIER_KEYCODES_LOOKUP[key] && keyEvent.shiftKey) {
+    resultKey = resultKey.toUpperCase();
+  }
+
   result.dictionary = {
-    key: "key" in keyEvent ? keyEvent.key : keyName,
+    key: resultKey,
     code: "code" in keyEvent ? keyEvent.code : "",
     location: locationIsDefined ? keyEvent.location : 0,
     repeat: "repeat" in keyEvent ? keyEvent.repeat === true : false,
     keyCode,
   };
+
   return result;
 }
 
 function emulateToActivateModifiers_(TIP, keyEvent, win) {
   if (!keyEvent) {
     return null;
   }
   let KeyboardEvent = getKeyboardEvent_(win);
@@ -820,17 +829,17 @@ event.synthesizeMouseExpectEvent = funct
   event.synthesizeMouse(target, offsetX, offsetY, ev, win);
   checkExpectedEvent_(
       expectedTarget,
       expectedEvent,
       eventHandler,
       testName);
 };
 
-const KEYCODES_LOOKUP = {
+const MODIFIER_KEYCODES_LOOKUP = {
   "VK_SHIFT": "shiftKey",
   "VK_CONTROL": "ctrlKey",
   "VK_ALT": "altKey",
   "VK_META": "metaKey",
 };
 
 const VIRTUAL_KEYCODE_LOOKUP = {
   "\uE001": "VK_CANCEL",
@@ -1006,27 +1015,26 @@ event.sendKeyUp = function(keyToSend, mo
  * @param {Object.<string, boolean>} modifiers
  *     Object with properties used in KeyboardEvent (shiftkey, repeat, ...)
  *     as well as, the event |type| such as keydown. All properties
  *     are optional.
  * @param {Window} win
  *     Window object.
  */
 event.sendSingleKey = function(keyToSend, modifiers, win) {
-  let keyName = getKeyCode(keyToSend);
-  if (keyName in KEYCODES_LOOKUP) {
-    // We assume that if |keyToSend| is a raw code point (like "\uE009")
-    // then |modifiers| does not already have correct value for corresponding
-    // |modName| attribute (like ctrlKey), so that value needs to be flipped.
-    let modName = KEYCODES_LOOKUP[keyName];
+  let keyCode = getKeyCode(keyToSend);
+  if (keyCode in MODIFIER_KEYCODES_LOOKUP) {
+    // For |sendKeysToElement| and legacy actions we assume that if
+    // |keyToSend| is a raw code point (like "\uE009") then |modifiers| does
+    // not already have correct value for corresponding |modName| attribute
+    // (like ctrlKey), so that value needs to be flipped.
+    let modName = MODIFIER_KEYCODES_LOOKUP[keyCode];
     modifiers[modName] = !modifiers[modName];
-  } else if (modifiers.shiftKey && keyName != "Shift") {
-    keyName = keyName.toUpperCase();
   }
-  event.synthesizeKey(keyName, modifiers, win);
+  event.synthesizeKey(keyCode, modifiers, win);
 };
 
 /**
  * @param {string} keyString
  * @param {Element} element
  * @param {Window} win
  */
 event.sendKeysToElement = function(keyString, el, win) {