Bug 1343955 - part 1: Add automated tests for synthesizeKey() of EventUtils.js r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 02 Oct 2018 14:31:56 +0000
changeset 495137 1a1ef374eba66c3af2c252711e607d095e2c2c23
parent 495136 f54d088190672270c1487359a13a9ec9a9940e79
child 495138 fea8e039767a88ebfb73b1f0d43d1f87ee7394e1
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)
reviewerssmaug
bugs1343955
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 1343955 - part 1: Add automated tests for synthesizeKey() of EventUtils.js r=smaug For preventing regressions of the following patches, test_sanityEventUtils.html should have more tests of syntheiszeKey(). Differential Revision: https://phabricator.services.mozilla.com/D5513
testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html
--- a/testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html
@@ -116,23 +116,56 @@ function starttest() {
       /* test synthesizeKey* */
       check = false;
       $("testKeyEvent").addEventListener("keypress", doCheck, {once:true});
       $("testKeyEvent").focus();
       sendString("a");
       is($("testKeyEvent").value, "a", "synthesizeKey should work");
       is(check, true, "synthesizeKey should dispatch keyPress");
       $("testKeyEvent").value = "";
-    
-      check = false;
-      $("testKeyEvent").addEventListener("keypress", doCheck, {once:true});
-      synthesizeKeyExpectEvent("a", {}, $("testKeyEvent"), "keypress");
-      is($("testKeyEvent").value, "a", "synthesizeKey should work");
-      is(check, true, "synthesizeKey should dispatch keyPress");
-      $("testKeyEvent").value = "";
+
+      // If |.code| value is not specified explicitly, it should be computed
+      // from the |.key| value or |.keyCode| value.  If a printable key is
+      // specified, the |.code| value should be guessed with US-English
+      // keyboard layout.
+      for (let test of [{ arg: "KEY_Enter", code: "Enter", keyCode: KeyboardEvent.DOM_VK_RETURN },
+                        { arg: "VK_RETURN", code: "Enter", keyCode: KeyboardEvent.DOM_VK_RETURN },
+                        { arg: "KEY_Backspace", code: "Backspace", keyCode: KeyboardEvent.DOM_VK_BACK_SPACE },
+                        { arg: "KEY_Delete", code: "Delete", keyCode: KeyboardEvent.DOM_VK_DELETE },
+                        { arg: "KEY_Home", code: "Home", keyCode: KeyboardEvent.DOM_VK_HOME },
+                        { arg: "KEY_End", code: "End", keyCode: KeyboardEvent.DOM_VK_END },
+                        { arg: "KEY_ArrowDown", code: "ArrowDown", keyCode: KeyboardEvent.DOM_VK_DOWN },
+                        { arg: "KEY_ArrowUp", code: "ArrowUp", keyCode: KeyboardEvent.DOM_VK_UP },
+                        { arg: "KEY_ArrowLeft", code: "ArrowLeft", keyCode: KeyboardEvent.DOM_VK_LEFT },
+                        { arg: "KEY_ArrowRight", code: "ArrowRight", keyCode: KeyboardEvent.DOM_VK_RIGHT },
+                        { arg: "KEY_Shift", code: "ShiftLeft", keyCode: KeyboardEvent.DOM_VK_SHIFT },
+                        { arg: "KEY_Control", code: "ControlLeft", keyCode: KeyboardEvent.DOM_VK_CONTROL },
+                        { arg: "a", code: "KeyA", keyCode: KeyboardEvent.DOM_VK_A },
+                        { arg: "B", code: "KeyB", keyCode: KeyboardEvent.DOM_VK_B },
+                        { arg: " ", code: "Space", keyCode: KeyboardEvent.DOM_VK_SPACE },
+                        { arg: "0", code: "Digit0", keyCode: KeyboardEvent.DOM_VK_0 },
+                        { arg: "(", code: "Digit9", keyCode: KeyboardEvent.DOM_VK_9 },
+                        { arg: "!", code: "Digit1", keyCode: KeyboardEvent.DOM_VK_1 },
+                        { arg: "[", code: "BracketLeft", keyCode: KeyboardEvent.DOM_VK_OPEN_BRACKET },
+                        { arg: ";", code: "Semicolon", keyCode: KeyboardEvent.DOM_VK_SEMICOLON },
+                        { arg: "\"", code: "Quote", keyCode: KeyboardEvent.DOM_VK_QUOTE },
+                        { arg: "~", code: "Backquote", keyCode: KeyboardEvent.DOM_VK_BACK_QUOTE },
+                        { arg: "<", code: "Comma", keyCode: KeyboardEvent.DOM_VK_COMMA },
+                        { arg: ".", code: "Period", keyCode: KeyboardEvent.DOM_VK_PERIOD }]) {
+        let keydown, keyup;
+        $("testKeyEvent").focus();
+        $("testKeyEvent").addEventListener("keydown", (e) => { keydown = e; }, {once: true});
+        $("testKeyEvent").addEventListener("keyup", (e) => { keyup = e; }, {once: true});
+        synthesizeKey(test.arg);
+        is(keydown.code, test.code, `Synthesizing "${test.arg}" should set code value of "keydown" to "${test.code}"`);
+        is(keydown.keyCode, test.keyCode, `Synthesizing "${test.arg}" should set keyCode value of "keydown" to "${test.keyCode}"`);
+        is(keyup.code, test.code, `Synthesizing "${test.arg}" key should set code value of "keyup" to "${test.code}"`);
+        is(keyup.keyCode, test.keyCode, `Synthesizing "${test.arg}" key should set keyCode value of "keyup" to "${test.keyCode}"`);
+        $("testKeyEvent").value = "";
+      }
     
       /* test synthesizeComposition */
       var description = "";
       var keydownEvent = null;
       var keyupEvent = null;
       function onKeyDown(aEvent) {
         ok(!keydownEvent, description + "keydown should be fired only once" + (keydownEvent ? keydownEvent.key : "") + ", " + (keyupEvent ? keyupEvent.key : ""));
         keydownEvent = aEvent;