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

Unified Diff: chrome/test/webdriver/webdriver_key_converter.cc

Issue 6694007: Small test and ChromeDriver fixes to enable additional tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 9 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 | « chrome/test/webdriver/session.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/webdriver_key_converter.cc
diff --git a/chrome/test/webdriver/webdriver_key_converter.cc b/chrome/test/webdriver/webdriver_key_converter.cc
index f8f3db66b151514c54c2eb1ee4bfe934a8d291c8..b509f4a9626dcc49780721c1ed23369b116360fd 100644
--- a/chrome/test/webdriver/webdriver_key_converter.cc
+++ b/chrome/test/webdriver/webdriver_key_converter.cc
@@ -109,6 +109,39 @@ bool KeyCodeFromSpecialWebDriverKey(char16 key, ui::KeyboardCode* key_code) {
return is_special_key;
}
+// Gets the key code associated with |key|, if it is a special shorthand key,
+// Shorthand keys are common text equivalents for keys, such as the newline
+// character, which is shorthand for the return key. Returns whether |key| is
+// a shorthand key. If true, |key_code| will be set and |should_skip| will be
+// set to whether the key should be skipped.
+bool KeyCodeFromShorthandKey(char16 key_utf16,
+ ui::KeyboardCode* key_code,
+ bool* client_should_skip) {
+ string16 key_str_utf16;
+ key_str_utf16.push_back(key_utf16);
+ std::string key_str_utf8 = UTF16ToUTF8(key_str_utf16);
+ if (key_str_utf8.length() != 1)
+ return false;
+ bool should_skip = false;
+ char key = key_str_utf8[0];
+ if (key == '\n') {
Joe 2011/03/15 21:22:17 While \n is a newline for unix isn't \r\n a newlin
kkania 2011/03/18 21:45:12 Yes, I support \r\n and \n. I do this by skipping
+ *key_code = ui::VKEY_RETURN;
+ } else if (key == '\t') {
+ *key_code = ui::VKEY_TAB;
+ } else if (key == '\b') {
+ *key_code = ui::VKEY_BACK;
+ } else if (key == ' ') {
+ *key_code = ui::VKEY_SPACE;
+ } else if (key == '\r') {
+ *key_code = ui::VKEY_UNKNOWN;
+ should_skip = true;
+ } else {
+ return false;
+ }
+ *client_should_skip = should_skip;
+ return true;
+}
+
} // namespace
namespace webdriver {
@@ -189,28 +222,39 @@ void ConvertKeysToWebKeyEvents(const string16& client_keys,
std::string unmodified_text, modified_text;
int all_modifiers = sticky_modifiers;
- bool is_special_key = KeyCodeFromSpecialWebDriverKey(key, &key_code);
- if (is_special_key && key_code == ui::VKEY_UNKNOWN) {
- LOG(ERROR) << "Unknown WebDriver key: " << static_cast<int>(key);
- continue;
- }
- if (!is_special_key) {
+ // Get the key code, text, and modifiers for the given key.
+ bool should_skip = false;
+ if (KeyCodeFromSpecialWebDriverKey(key, &key_code) ||
+ KeyCodeFromShorthandKey(key, &key_code, &should_skip)) {
+ if (should_skip)
+ continue;
+ if (key_code == ui::VKEY_UNKNOWN) {
+ LOG(ERROR) << "Unknown WebDriver key: " << static_cast<int>(key);
Joe 2011/03/15 21:22:17 If an unknown key is requested shouldn't it break
kkania 2011/03/18 21:45:12 Done.
+ continue;
+ }
+ if (key_code == ui::VKEY_RETURN) {
+ modified_text = unmodified_text = "\r";
+ } else {
+ unmodified_text = ConvertKeyCodeToText(key_code, 0);
+ modified_text = ConvertKeyCodeToText(key_code, all_modifiers);
+ }
+ } else {
int necessary_modifiers = 0;
ConvertCharToKeyCode(key, &key_code, &necessary_modifiers);
all_modifiers |= necessary_modifiers;
- }
- if (key_code != ui::VKEY_UNKNOWN) {
- unmodified_text = ConvertKeyCodeToText(key_code, 0);
- modified_text = ConvertKeyCodeToText(key_code, all_modifiers);
- }
- if (!is_special_key && (unmodified_text.empty() || modified_text.empty())) {
- // Do a best effort and use the raw key we were given.
- LOG(WARNING) << "No translation for key code. Code point: "
- << static_cast<int>(key);
- if (unmodified_text.empty())
- unmodified_text = UTF16ToUTF8(keys.substr(i, 1));
- if (modified_text.empty())
- modified_text = UTF16ToUTF8(keys.substr(i, 1));
+ 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()) {
+ // Do a best effort and use the raw key we were given.
+ LOG(WARNING) << "No translation for key code. Code point: "
+ << static_cast<int>(key);
+ if (unmodified_text.empty())
+ unmodified_text = UTF16ToUTF8(keys.substr(i, 1));
+ if (modified_text.empty())
+ modified_text = UTF16ToUTF8(keys.substr(i, 1));
+ }
}
// Create the key events.
« no previous file with comments | « chrome/test/webdriver/session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698