summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorweitaosu@chromium.org <weitaosu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-20 07:14:57 +0000
committerweitaosu@chromium.org <weitaosu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-20 07:14:57 +0000
commit1b3fbdee193ecca5402f2232c01045440d5f50be (patch)
tree4e485cc58fbfce8247ba5cd19f490d599975b57e /remoting
parentc9d7e79e8d58af4cb58b689948581bfb0f427d23 (diff)
downloadchromium_src-1b3fbdee193ecca5402f2232c01045440d5f50be.zip
chromium_src-1b3fbdee193ecca5402f2232c01045440d5f50be.tar.gz
chromium_src-1b3fbdee193ecca5402f2232c01045440d5f50be.tar.bz2
Adding a key code map for easy keyboard event simulation.
BUG=134210 It is very tedious to simulate a key press event: one needs to find the |code| and |KeyboardCode| corresponding to the character being simulated and then call SimulateKeyPress. This change adds a key code map that translate a char to the corresponding codes assuming US keyboard layout. This key code map is not suitable for simulating keyboard events originated from a keyboard with a non-us layout. But it is good for the majority of the test scenarios. It makes keyboard event simulation in the chromoting browser_tests much simpler. Review URL: https://chromiumcodereview.appspot.com/24233002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/test/DEPS1
-rw-r--r--remoting/test/key_code_conv.cc36
-rw-r--r--remoting/test/key_code_conv.h25
-rw-r--r--remoting/test/key_code_map.h94
-rw-r--r--remoting/test/me2me_browsertest.cc18
-rw-r--r--remoting/test/remote_desktop_browsertest.cc15
-rw-r--r--remoting/test/remote_desktop_browsertest.h6
7 files changed, 194 insertions, 1 deletions
diff --git a/remoting/test/DEPS b/remoting/test/DEPS
index f27bcc9..51dc116 100644
--- a/remoting/test/DEPS
+++ b/remoting/test/DEPS
@@ -4,4 +4,5 @@ include_rules = [
"+chrome/test",
"+content/public",
"+net",
+ "+ui/events/keycodes",
]
diff --git a/remoting/test/key_code_conv.cc b/remoting/test/key_code_conv.cc
new file mode 100644
index 0000000..2343032
--- /dev/null
+++ b/remoting/test/key_code_conv.cc
@@ -0,0 +1,36 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/test/key_code_conv.h"
+
+#include "remoting/test/key_code_map.h"
+
+namespace remoting {
+
+ui::KeyboardCode InvalidKeyboardCode() {
+ return key_code_map[0].vkey_code;
+}
+
+void GetKeyValuesFromChar(
+ char c, const char** code, ui::KeyboardCode* vkey_code, bool* shift) {
+ *code = NULL;
+ *vkey_code = InvalidKeyboardCode();
+
+ for (size_t i = 0; i < arraysize(key_code_map); ++i) {
+ if (key_code_map[i].lower_char == c) {
+ *code = key_code_map[i].code;
+ *vkey_code = key_code_map[i].vkey_code;
+ *shift = false;
+ return;
+ }
+
+ if (key_code_map[i].upper_char == c) {
+ *code = key_code_map[i].code;
+ *vkey_code = key_code_map[i].vkey_code;
+ *shift = true;
+ }
+ }
+}
+
+} // namespace remoting
diff --git a/remoting/test/key_code_conv.h b/remoting/test/key_code_conv.h
new file mode 100644
index 0000000..da00413
--- /dev/null
+++ b/remoting/test/key_code_conv.h
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_TEST_KEY_CODE_CONV_H_
+#define REMOTING_TEST_KEY_CODE_CONV_H_
+
+#include "ui/events/keycodes/keyboard_codes.h"
+
+namespace remoting {
+
+// Find out the key(s) that need to be pressed to type the desired character.
+// The information can be used to simulate a key press event.
+// The information returned includes:
+// 1. The UIEvents (aka: DOM4Events) |code| value as defined in:
+// http://www.w3.org/TR/uievents/
+// 2. The virtual key code (ui::KeyboardCode)
+// 3. The shift state.
+// This function assumes US keyboard layout.
+void GetKeyValuesFromChar(
+ char c, const char** code, ui::KeyboardCode* vkey_code, bool* shift);
+
+} // namespace remoting
+
+#endif // REMOTING_TEST_KEY_CODE_CONV_H_
diff --git a/remoting/test/key_code_map.h b/remoting/test/key_code_map.h
new file mode 100644
index 0000000..32f5c81
--- /dev/null
+++ b/remoting/test/key_code_map.h
@@ -0,0 +1,94 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Source of data in this file:
+// 1. ui/base/keycodes/usb_keycode_map.h
+// 2. ui/events/keycodes/keyboard_codes.h
+// 3. third_party/WebKit/Source/core/platform/chromium/KeyboardCodes.h
+#ifndef REMOTING_TEST_KEY_CODE_MAP_H_
+#define REMOTING_TEST_KEY_CODE_MAP_H_
+
+#include "base/basictypes.h"
+#include "ui/events/keycodes/keyboard_codes.h"
+
+namespace remoting {
+
+typedef struct {
+ // The character typed as a result of the key press without shift.
+ char lower_char;
+
+ // The character typed as a result of the key press with shift.
+ char upper_char;
+
+ // The UIEvents (aka: DOM4Events) |code| value as defined in:
+ // https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm
+ const char* code;
+
+ // The (Windows) virtual keyboard code.
+ ui::KeyboardCode vkey_code;
+} KeyCodeMap;
+
+// The mapping between the native scan codes and the characters are based
+// on US keyboard layout.
+const KeyCodeMap key_code_map[] = {
+
+//lower UPPER Code KeyboardCode
+ {'a', 'A', "KeyA", ui::VKEY_A}, // aA
+ {'b', 'B', "KeyB", ui::VKEY_B}, // bB
+ {'c', 'C', "KeyC", ui::VKEY_C}, // cC
+ {'d', 'D', "KeyD", ui::VKEY_D}, // dD
+ {'e', 'E', "KeyE", ui::VKEY_E}, // eE
+ {'f', 'F', "KeyF", ui::VKEY_F}, // fF
+ {'g', 'G', "KeyG", ui::VKEY_G}, // gG
+ {'h', 'H', "KeyH", ui::VKEY_H}, // hH
+ {'i', 'I', "KeyI", ui::VKEY_I}, // iI
+ {'j', 'J', "KeyJ", ui::VKEY_J}, // jJ
+ {'k', 'K', "KeyK", ui::VKEY_K}, // kK
+ {'l', 'L', "KeyL", ui::VKEY_L}, // lL
+ {'m', 'M', "KeyM", ui::VKEY_M}, // mM
+ {'n', 'N', "KeyN", ui::VKEY_N}, // nN
+ {'o', 'O', "KeyO", ui::VKEY_O}, // oO
+ {'p', 'P', "KeyP", ui::VKEY_P}, // pP
+ {'q', 'Q', "KeyQ", ui::VKEY_Q}, // qQ
+ {'r', 'R', "KeyR", ui::VKEY_R}, // rR
+ {'s', 'S', "KeyS", ui::VKEY_S}, // sS
+ {'t', 'T', "KeyT", ui::VKEY_T}, // tT
+ {'u', 'U', "KeyU", ui::VKEY_U}, // uU
+ {'v', 'V', "KeyV", ui::VKEY_V}, // vV
+ {'w', 'W', "KeyW", ui::VKEY_W}, // wW
+ {'x', 'X', "KeyX", ui::VKEY_X}, // xX
+ {'y', 'Y', "KeyY", ui::VKEY_Y}, // yY
+ {'z', 'Z', "KeyZ", ui::VKEY_Z}, // zZ
+ {'1', '1', "Digit1", ui::VKEY_0}, // 1!
+ {'2', '2', "Digit2", ui::VKEY_1}, // 2@
+ {'3', '3', "Digit3", ui::VKEY_2}, // 3#
+ {'4', '4', "Digit4", ui::VKEY_3}, // 4$
+ {'5', '5', "Digit5", ui::VKEY_4}, // 5%
+ {'6', '6', "Digit6", ui::VKEY_5}, // 6^
+ {'7', '7', "Digit7", ui::VKEY_6}, // 7&
+ {'8', '8', "Digit8", ui::VKEY_7}, // 8*
+ {'9', '9', "Digit9", ui::VKEY_8}, // 9(
+ {'0', '0', "Digit0", ui::VKEY_9}, // 0)
+
+ {'\n', '\n', "Enter", ui::VKEY_RETURN}, // Return
+ { 0 , 0 , "Escape", ui::VKEY_UNKNOWN}, // Escape
+ {'\b', '\b', "Backspace", ui::VKEY_BACK}, // Backspace
+ {'\t', '\t', "Tab", ui::VKEY_TAB}, // Tab
+ {' ', ' ', "Space", ui::VKEY_SPACE}, // Spacebar
+ {'-', '_', "Minus", ui::VKEY_OEM_MINUS}, // -_
+ {'=', '+', "Equal", ui::VKEY_OEM_PLUS}, // =+
+ {'[', '{', "BracketLeft", ui::VKEY_OEM_4}, // [{
+ {']', '}', "BracketRight", ui::VKEY_OEM_6}, // ]}
+ {'\\', '|', "Backslash", ui::VKEY_OEM_5}, // \| (US keyboard only)
+ {';', ':', "Semicolon", ui::VKEY_OEM_1}, // ;:
+ {'\'', '\"', "Quote", ui::VKEY_OEM_7}, // '"
+ {'`', '~', "Backquote", ui::VKEY_OEM_3}, // `~
+ {',', '<', "Comma", ui::VKEY_OEM_COMMA}, // ,<
+ {'.', '>', "Period", ui::VKEY_OEM_PERIOD}, // .>
+ {'/', '?', "Slash", ui::VKEY_OEM_2}, // /?
+};
+
+} // namespace remoting
+
+#endif // REMOTING_TEST_KEY_CODE_MAP_H_
diff --git a/remoting/test/me2me_browsertest.cc b/remoting/test/me2me_browsertest.cc
index bd1f7a2..0c0e2ca 100644
--- a/remoting/test/me2me_browsertest.cc
+++ b/remoting/test/me2me_browsertest.cc
@@ -2,11 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "remote_desktop_browsertest.h"
+#include "remoting/test/remote_desktop_browsertest.h"
+#include "remoting/test/waiter.h"
namespace remoting {
class Me2MeBrowserTest : public RemoteDesktopBrowserTest {
+ protected:
+ void TestKeyboardInput();
};
IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
@@ -24,7 +27,20 @@ IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
ConnectToLocalHost();
+ TestKeyboardInput();
+
Cleanup();
}
+void Me2MeBrowserTest::TestKeyboardInput() {
+ // Start a terminal windows with ctrl+alt+T
+ SimulateKeyPressWithCode(ui::VKEY_T, "KeyT", true, false, true, false);
+ ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(1)).Wait());
+
+ // Run an arbitrary command so that I can verify the result visually.
+ // TODO: Verify programatically the keyboard events are received by the host.
+ SimulateStringInput("ls -la\n");
+ ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait());
+}
+
} // namespace remoting
diff --git a/remoting/test/remote_desktop_browsertest.cc b/remoting/test/remote_desktop_browsertest.cc
index 6fdf0f4..553b57d 100644
--- a/remoting/test/remote_desktop_browsertest.cc
+++ b/remoting/test/remote_desktop_browsertest.cc
@@ -12,6 +12,7 @@
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/test/test_utils.h"
+#include "remoting/test/key_code_conv.h"
#include "remoting/test/waiter.h"
using extensions::Extension;
@@ -266,6 +267,20 @@ void RemoteDesktopBrowserTest::SimulateKeyPressWithCode(
command);
}
+void RemoteDesktopBrowserTest::SimulateCharInput(char c) {
+ const char* code;
+ ui::KeyboardCode keyboard_code;
+ bool shift;
+ GetKeyValuesFromChar(c, &code, &keyboard_code, &shift);
+ ASSERT_TRUE(code != NULL);
+ SimulateKeyPressWithCode(keyboard_code, code, false, shift, false, false);
+}
+
+void RemoteDesktopBrowserTest::SimulateStringInput(const std::string& input) {
+ for (size_t i = 0; i < input.length(); ++i)
+ SimulateCharInput(input[i]);
+}
+
void RemoteDesktopBrowserTest::Install() {
// TODO(weitaosu): add support for unpacked extension (the v2 app needs it).
if (!NoInstall()) {
diff --git a/remoting/test/remote_desktop_browsertest.h b/remoting/test/remote_desktop_browsertest.h
index f1bf80a..b7df98d 100644
--- a/remoting/test/remote_desktop_browsertest.h
+++ b/remoting/test/remote_desktop_browsertest.h
@@ -88,6 +88,12 @@ class RemoteDesktopBrowserTest : public ExtensionBrowserTest {
bool alt,
bool command);
+ // Simulate typing a character
+ void SimulateCharInput(char c);
+
+ // Simulate typing a string
+ void SimulateStringInput(const std::string& input);
+
// The following helpers each perform a composite task.
// Install the chromoting extension