Commit ec55b967 authored by chrisgao@chromium.org's avatar chrisgao@chromium.org

[chromedriver] Fix bugs in SendKeys.

Review URL: https://codereview.chromium.org/14023006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194691 0039d316-1c4b-4281-b951-d872f2087c98
parent bcae835d
...@@ -97,6 +97,15 @@ const char16 kWebDriverControlKey = 0xE009U; ...@@ -97,6 +97,15 @@ const char16 kWebDriverControlKey = 0xE009U;
const char16 kWebDriverAltKey = 0xE00AU; const char16 kWebDriverAltKey = 0xE00AU;
const char16 kWebDriverCommandKey = 0xE03DU; 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. // Returns whether the given key is a WebDriver key modifier.
bool IsModifierKey(char16 key) { bool IsModifierKey(char16 key) {
switch (key) { switch (key) {
...@@ -242,7 +251,8 @@ Status ConvertKeysToKeyEvents(const string16& client_keys, ...@@ -242,7 +251,8 @@ Status ConvertKeysToKeyEvents(const string16& client_keys,
// Get the key code, text, and modifiers for the given key. // Get the key code, text, and modifiers for the given key.
bool should_skip = false; 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)) { KeyCodeFromShorthandKey(key, &key_code, &should_skip)) {
if (should_skip) if (should_skip)
continue; continue;
...@@ -255,6 +265,9 @@ Status ConvertKeysToKeyEvents(const string16& client_keys, ...@@ -255,6 +265,9 @@ Status ConvertKeysToKeyEvents(const string16& client_keys,
if (key_code == ui::VKEY_RETURN) { if (key_code == ui::VKEY_RETURN) {
// For some reason Chrome expects a carriage return for the return key. // For some reason Chrome expects a carriage return for the return key.
modified_text = unmodified_text = "\r"; 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 { } else {
// WebDriver assumes a numpad key should translate to the number, // WebDriver assumes a numpad key should translate to the number,
// which requires NumLock to be on with some platforms. This isn't // which requires NumLock to be on with some platforms. This isn't
...@@ -274,14 +287,15 @@ Status ConvertKeysToKeyEvents(const string16& client_keys, ...@@ -274,14 +287,15 @@ Status ConvertKeysToKeyEvents(const string16& client_keys,
if (key_code != ui::VKEY_UNKNOWN) { if (key_code != ui::VKEY_UNKNOWN) {
unmodified_text = ConvertKeyCodeToText(key_code, 0); unmodified_text = ConvertKeyCodeToText(key_code, 0);
modified_text = ConvertKeyCodeToText(key_code, all_modifiers); modified_text = ConvertKeyCodeToText(key_code, all_modifiers);
} if (unmodified_text.empty() || modified_text.empty()) {
// To prevent char event for special cases like CTRL + x (cut).
if (unmodified_text.empty() || modified_text.empty()) { unmodified_text.clear();
modified_text.clear();
}
} else {
// Do a best effort and use the raw key we were given. // Do a best effort and use the raw key we were given.
if (unmodified_text.empty()) unmodified_text = UTF16ToUTF8(keys.substr(i, 1));
unmodified_text = UTF16ToUTF8(keys.substr(i, 1)); modified_text = UTF16ToUTF8(keys.substr(i, 1));
if (modified_text.empty())
modified_text = UTF16ToUTF8(keys.substr(i, 1));
} }
} }
......
...@@ -80,12 +80,7 @@ _REVISION_NEGATIVE_FILTER['HEAD'] = [ ...@@ -80,12 +80,7 @@ _REVISION_NEGATIVE_FILTER['HEAD'] = [
'TextHandlingTest.testShouldReturnEmptyStringWhenTagIsSelfClosing', 'TextHandlingTest.testShouldReturnEmptyStringWhenTagIsSelfClosing',
'TextPagesTest.testShouldBeAbleToLoadASimplePageOfText', 'TextPagesTest.testShouldBeAbleToLoadASimplePageOfText',
'TextPagesTest.testShouldThrowExceptionWhenAddingCookieToAPageThatIsNotHtml', 'TextPagesTest.testShouldThrowExceptionWhenAddingCookieToAPageThatIsNotHtml',
'TypingTest.testChordControlCutAndPaste',
'TypingTest.testChordControlHomeShiftEndDelete',
'TypingTest.testChordReveseShiftHomeSelectionDeletes',
'TypingTest.testDeleteAndBackspaceKeys',
'TypingTest.testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet', 'TypingTest.testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet',
'TypingTest.testShiftSelectionDeletes',
'TypingTest.testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue', 'TypingTest.testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue',
'TypingTest.testShouldNotTypeIntoElementsThatPreventKeyDownEvents', 'TypingTest.testShouldNotTypeIntoElementsThatPreventKeyDownEvents',
'TypingTest.testTypingIntoAnIFrameWithContentEditableOrDesignModeSet', 'TypingTest.testTypingIntoAnIFrameWithContentEditableOrDesignModeSet',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment