Bug 1493546 - Only uppercase printable keys when shift modifier is set. r=ato
☠☠ backed out by fa1e16a89825 ☠ ☠
authorHenrik Skupin <mail@hskupin.info>
Wed, 26 Sep 2018 08:27:39 +0000
changeset 496743 1a24a41b377e518c30cf2e3ba687af4debce2a01
parent 496742 9f1c5ece3510d1e38630bd73994466ec0eb271bd
child 496744 8d6329af610eb827b07f3cc5782fa1c77af2a271
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1493546
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 1493546 - Only uppercase printable keys when shift modifier is set. r=ato Differential Revision: https://phabricator.services.mozilla.com/D6776
testing/marionette/event.js
testing/web-platform/tests/webdriver/tests/perform_actions/key.py
testing/web-platform/tests/webdriver/tests/perform_actions/key_modifiers.py
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -451,16 +451,19 @@ function createKeyboardEventDictionary_(
   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";
 
+  // only force printable if "raw character" and event key match, like "a"
+  let printable = !("key" in keyEvent && key != keyEvent.key);
+
   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;
     }
@@ -471,29 +474,28 @@ function createKeyboardEventDictionary_(
   } else if (key != "") {
     keyName = key;
     if (!keyCodeIsDefined) {
       keyCode = computeKeyCodeFromChar_(key.charAt(0), win);
     }
     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)) {
+    if (printable) {
       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) {
+  if (printable && keyEvent.shiftKey) {
     resultKey = resultKey.toUpperCase();
   }
 
   result.dictionary = {
     key: resultKey,
     code: "code" in keyEvent ? keyEvent.code : "",
     location: locationIsDefined ? keyEvent.location : 0,
     repeat: "repeat" in keyEvent ? keyEvent.repeat === true : false,
--- a/testing/web-platform/tests/webdriver/tests/perform_actions/key.py
+++ b/testing/web-platform/tests/webdriver/tests/perform_actions/key.py
@@ -11,15 +11,23 @@ def test_null_response_value(session, ke
     assert value is None
 
 
 def test_no_browsing_context(session, closed_window, key_chain):
     with pytest.raises(NoSuchWindowException):
         key_chain.key_up("a").perform()
 
 
+def test_element_not_focused(session, test_actions_page, key_chain):
+    key_reporter = session.find.css("#keys", all=False)
+
+    key_chain.key_down("a").key_up("a").perform()
+
+    assert get_keys(key_reporter) == ""
+
+
 def test_backspace_erases_keys(session, key_reporter, key_chain):
     key_chain \
         .send_keys("efcd") \
         .send_keys([Keys.BACKSPACE, Keys.BACKSPACE]) \
         .perform()
 
     assert get_keys(key_reporter) == "ef"
--- a/testing/web-platform/tests/webdriver/tests/perform_actions/key_modifiers.py
+++ b/testing/web-platform/tests/webdriver/tests/perform_actions/key_modifiers.py
@@ -1,14 +1,27 @@
 import pytest
 
 from tests.perform_actions.support.keys import Keys
 
 
 @pytest.mark.parametrize("modifier", [Keys.SHIFT, Keys.R_SHIFT])
+def test_shift_modifier_and_non_printable_keys(session, key_reporter, key_chain, modifier):
+    key_chain \
+        .send_keys("foo") \
+        .key_down(modifier) \
+        .key_down(Keys.BACKSPACE) \
+        .key_up(modifier) \
+        .key_up(Keys.BACKSPACE) \
+        .perform()
+
+    assert key_reporter.property("value") == "fo"
+
+
+@pytest.mark.parametrize("modifier", [Keys.SHIFT, Keys.R_SHIFT])
 def test_shift_modifier_generates_capital_letters(session, key_reporter, key_chain, modifier):
     key_chain \
         .send_keys("b") \
         .key_down(modifier) \
         .key_down("c") \
         .key_up(modifier) \
         .key_up("c") \
         .key_down("d") \