OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/test/chromedriver/chrome/status.h" | 14 #include "chrome/test/chromedriver/chrome/status.h" |
15 #include "chrome/test/chromedriver/chrome/ui_events.h" | 15 #include "chrome/test/chromedriver/chrome/ui_events.h" |
16 #include "chrome/test/chromedriver/key_converter.h" | 16 #include "chrome/test/chromedriver/key_converter.h" |
17 #include "chrome/test/chromedriver/test_util.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/events/test/keyboard_layout.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 void CheckEvents(const base::string16& keys, | 22 void CheckEvents(const base::string16& keys, |
23 KeyEvent expected_events[], | 23 KeyEvent expected_events[], |
24 bool release_modifiers, | 24 bool release_modifiers, |
25 size_t expected_size, | 25 size_t expected_size, |
26 int expected_modifiers) { | 26 int expected_modifiers) { |
27 int modifiers = 0; | 27 int modifiers = 0; |
28 std::list<KeyEvent> events; | 28 std::list<KeyEvent> events; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 CreateKeyDownEvent(ui::VKEY_UNKNOWN, 0), | 158 CreateKeyDownEvent(ui::VKEY_UNKNOWN, 0), |
159 CreateCharEvent(base::WideToUTF8(L"\u00E9"), | 159 CreateCharEvent(base::WideToUTF8(L"\u00E9"), |
160 base::WideToUTF8(L"\u00E9"), 0), | 160 base::WideToUTF8(L"\u00E9"), 0), |
161 CreateKeyUpEvent(ui::VKEY_UNKNOWN, 0)}; | 161 CreateKeyUpEvent(ui::VKEY_UNKNOWN, 0)}; |
162 CheckEventsReleaseModifiers(base::WideToUTF16(L"\u00E9"), | 162 CheckEventsReleaseModifiers(base::WideToUTF16(L"\u00E9"), |
163 event_array, arraysize(event_array)); | 163 event_array, arraysize(event_array)); |
164 } | 164 } |
165 | 165 |
166 #if defined(OS_WIN) | 166 #if defined(OS_WIN) |
167 TEST(KeyConverter, NeedsCtrlAndAlt) { | 167 TEST(KeyConverter, NeedsCtrlAndAlt) { |
168 RestoreKeyboardLayoutOnDestruct restore; | |
169 int ctrl_and_alt = kControlKeyModifierMask | kAltKeyModifierMask; | 168 int ctrl_and_alt = kControlKeyModifierMask | kAltKeyModifierMask; |
170 KeyEvent event_array[] = { | 169 KeyEvent event_array[] = { |
171 CreateKeyDownEvent(ui::VKEY_CONTROL, 0), | 170 CreateKeyDownEvent(ui::VKEY_CONTROL, 0), |
172 CreateKeyDownEvent(ui::VKEY_MENU, 0), | 171 CreateKeyDownEvent(ui::VKEY_MENU, 0), |
173 CreateKeyDownEvent(ui::VKEY_Q, ctrl_and_alt), | 172 CreateKeyDownEvent(ui::VKEY_Q, ctrl_and_alt), |
174 CreateCharEvent("q", "@", ctrl_and_alt), | 173 CreateCharEvent("q", "@", ctrl_and_alt), |
175 CreateKeyUpEvent(ui::VKEY_Q, ctrl_and_alt), | 174 CreateKeyUpEvent(ui::VKEY_Q, ctrl_and_alt), |
176 CreateKeyUpEvent(ui::VKEY_MENU, 0), | 175 CreateKeyUpEvent(ui::VKEY_MENU, 0), |
177 CreateKeyUpEvent(ui::VKEY_CONTROL, 0)}; | 176 CreateKeyUpEvent(ui::VKEY_CONTROL, 0)}; |
178 ASSERT_TRUE(SwitchKeyboardLayout("00000407")); | 177 ui::ScopedKeyboardLayout keyboard_layout(ui::KEYBOARD_LAYOUT_GERMAN); |
179 CheckEventsReleaseModifiers("@", event_array, arraysize(event_array)); | 178 CheckEventsReleaseModifiers("@", event_array, arraysize(event_array)); |
180 } | 179 } |
181 #endif | 180 #endif |
182 | 181 |
183 TEST(KeyConverter, UppercaseCharDoesShift) { | 182 TEST(KeyConverter, UppercaseCharDoesShift) { |
184 KeyEvent event_array[] = { | 183 KeyEvent event_array[] = { |
185 CreateKeyDownEvent(ui::VKEY_SHIFT, 0), | 184 CreateKeyDownEvent(ui::VKEY_SHIFT, 0), |
186 CreateKeyDownEvent(ui::VKEY_A, kShiftKeyModifierMask), | 185 CreateKeyDownEvent(ui::VKEY_A, kShiftKeyModifierMask), |
187 CreateCharEvent("a", "A", kShiftKeyModifierMask), | 186 CreateCharEvent("a", "A", kShiftKeyModifierMask), |
188 CreateKeyUpEvent(ui::VKEY_A, kShiftKeyModifierMask), | 187 CreateKeyUpEvent(ui::VKEY_A, kShiftKeyModifierMask), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 273 } |
275 | 274 |
276 #if defined(OS_LINUX) | 275 #if defined(OS_LINUX) |
277 // Fails on bots: crbug.com/174962 | 276 // Fails on bots: crbug.com/174962 |
278 #define MAYBE_AllEnglishKeyboardSymbols DISABLED_AllEnglishKeyboardSymbols | 277 #define MAYBE_AllEnglishKeyboardSymbols DISABLED_AllEnglishKeyboardSymbols |
279 #else | 278 #else |
280 #define MAYBE_AllEnglishKeyboardSymbols AllEnglishKeyboardSymbols | 279 #define MAYBE_AllEnglishKeyboardSymbols AllEnglishKeyboardSymbols |
281 #endif | 280 #endif |
282 | 281 |
283 TEST(KeyConverter, MAYBE_AllEnglishKeyboardSymbols) { | 282 TEST(KeyConverter, MAYBE_AllEnglishKeyboardSymbols) { |
| 283 ui::ScopedKeyboardLayout keyboard_layout(ui::KEYBOARD_LAYOUT_ENGLISH_US); |
284 base::string16 keys; | 284 base::string16 keys; |
285 const ui::KeyboardCode kSymbolKeyCodes[] = { | 285 const ui::KeyboardCode kSymbolKeyCodes[] = { |
286 ui::VKEY_OEM_3, | 286 ui::VKEY_OEM_3, |
287 ui::VKEY_OEM_MINUS, | 287 ui::VKEY_OEM_MINUS, |
288 ui::VKEY_OEM_PLUS, | 288 ui::VKEY_OEM_PLUS, |
289 ui::VKEY_OEM_4, | 289 ui::VKEY_OEM_4, |
290 ui::VKEY_OEM_6, | 290 ui::VKEY_OEM_6, |
291 ui::VKEY_OEM_5, | 291 ui::VKEY_OEM_5, |
292 ui::VKEY_OEM_1, | 292 ui::VKEY_OEM_1, |
293 ui::VKEY_OEM_7, | 293 ui::VKEY_OEM_7, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 kShiftKeyModifierMask | kControlKeyModifierMask), | 407 kShiftKeyModifierMask | kControlKeyModifierMask), |
408 CreateKeyUpEvent(ui::VKEY_SHIFT, 0), | 408 CreateKeyUpEvent(ui::VKEY_SHIFT, 0), |
409 CreateKeyUpEvent(ui::VKEY_CONTROL, 0)}; | 409 CreateKeyUpEvent(ui::VKEY_CONTROL, 0)}; |
410 base::string16 keys; | 410 base::string16 keys; |
411 keys.push_back(static_cast<base::char16>(0xE008U)); | 411 keys.push_back(static_cast<base::char16>(0xE008U)); |
412 keys.push_back(static_cast<base::char16>(0xE009U)); | 412 keys.push_back(static_cast<base::char16>(0xE009U)); |
413 | 413 |
414 CheckEvents(keys, event_array, true /* release_modifiers */, | 414 CheckEvents(keys, event_array, true /* release_modifiers */, |
415 arraysize(event_array), 0); | 415 arraysize(event_array), 0); |
416 } | 416 } |
OLD | NEW |