Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6015)

Unified Diff: chrome/test/chromedriver/key_converter.cc

Issue 14023006: [chromedriver] Fix bugs in SendKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and "" -> std::string() Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/chromedriver/test_expectations » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/key_converter.cc
diff --git a/chrome/test/chromedriver/key_converter.cc b/chrome/test/chromedriver/key_converter.cc
index 49b95f36e627bb0d965b88115b61ecf310bd3b15..c81a242dc12ca905df63f2287c1d4c9e0a939bd9 100644
--- a/chrome/test/chromedriver/key_converter.cc
+++ b/chrome/test/chromedriver/key_converter.cc
@@ -97,6 +97,15 @@ const char16 kWebDriverControlKey = 0xE009U;
const char16 kWebDriverAltKey = 0xE00AU;
const char16 kWebDriverCommandKey = 0xE03DU;
+// Returns whether the given key code has a corresponding printable char.
+// Notice: The given key code should be a special WebDriver key code.
+bool IsSpecialKeyPrintable(ui::KeyboardCode key_code) {
+ return key_code == ui::VKEY_TAB || key_code == ui::VKEY_SPACE ||
+ key_code == ui::VKEY_OEM_1 || key_code == ui::VKEY_OEM_PLUS ||
+ key_code == ui::VKEY_OEM_COMMA ||
+ (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_DIVIDE);
+}
+
// Returns whether the given key is a WebDriver key modifier.
bool IsModifierKey(char16 key) {
switch (key) {
@@ -242,7 +251,8 @@ Status ConvertKeysToKeyEvents(const string16& client_keys,
// Get the key code, text, and modifiers for the given key.
bool should_skip = false;
- if (KeyCodeFromSpecialWebDriverKey(key, &key_code) ||
+ bool is_special_key = KeyCodeFromSpecialWebDriverKey(key, &key_code);
+ if (is_special_key ||
KeyCodeFromShorthandKey(key, &key_code, &should_skip)) {
if (should_skip)
continue;
@@ -255,6 +265,9 @@ Status ConvertKeysToKeyEvents(const string16& client_keys,
if (key_code == ui::VKEY_RETURN) {
// For some reason Chrome expects a carriage return for the return key.
modified_text = unmodified_text = "\r";
+ } else if (is_special_key && !IsSpecialKeyPrintable(key_code)) {
+ // To prevent char event for special keys like DELETE.
+ modified_text = unmodified_text = std::string();
} else {
// WebDriver assumes a numpad key should translate to the number,
// which requires NumLock to be on with some platforms. This isn't
@@ -274,14 +287,15 @@ Status ConvertKeysToKeyEvents(const string16& client_keys,
if (key_code != ui::VKEY_UNKNOWN) {
unmodified_text = ConvertKeyCodeToText(key_code, 0);
modified_text = ConvertKeyCodeToText(key_code, all_modifiers);
- }
-
- if (unmodified_text.empty() || modified_text.empty()) {
+ if (unmodified_text.empty() || modified_text.empty()) {
+ // To prevent char event for special cases like CTRL + x (cut).
+ unmodified_text.clear();
+ modified_text.clear();
+ }
+ } else {
// Do a best effort and use the raw key we were given.
- if (unmodified_text.empty())
- unmodified_text = UTF16ToUTF8(keys.substr(i, 1));
- if (modified_text.empty())
- modified_text = UTF16ToUTF8(keys.substr(i, 1));
+ unmodified_text = UTF16ToUTF8(keys.substr(i, 1));
+ modified_text = UTF16ToUTF8(keys.substr(i, 1));
}
}
« no previous file with comments | « no previous file | chrome/test/chromedriver/test_expectations » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698