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

Side by Side Diff: chrome/test/chromedriver/keycode_text_conversion_unittest.cc

Issue 2353333002: Reland of Force U.S. English keyboard layout for TextfieldTest.KeysWithModifiersTest (Closed)
Patch Set: Use ScopedCFTypeRef instead of PlatformKeyboardLayout Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/test/chromedriver/chrome/ui_events.h" 10 #include "chrome/test/chromedriver/chrome/ui_events.h"
11 #include "chrome/test/chromedriver/keycode_text_conversion.h" 11 #include "chrome/test/chromedriver/keycode_text_conversion.h"
12 #include "chrome/test/chromedriver/test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/events/keycodes/keyboard_codes.h" 13 #include "ui/events/keycodes/keyboard_codes.h"
14 #include "ui/events/test/keyboard_layout.h"
15 15
16 namespace { 16 namespace {
17 17
18 void CheckCharToKeyCode16(base::char16 character, ui::KeyboardCode key_code, 18 void CheckCharToKeyCode16(base::char16 character, ui::KeyboardCode key_code,
19 int modifiers) { 19 int modifiers) {
20 ui::KeyboardCode actual_key_code = ui::VKEY_UNKNOWN; 20 ui::KeyboardCode actual_key_code = ui::VKEY_UNKNOWN;
21 int actual_modifiers = 0; 21 int actual_modifiers = 0;
22 std::string error_msg; 22 std::string error_msg;
23 EXPECT_TRUE(ConvertCharToKeyCode( 23 EXPECT_TRUE(ConvertCharToKeyCode(
24 character, &actual_key_code, &actual_modifiers, &error_msg)); 24 character, &actual_key_code, &actual_modifiers, &error_msg));
25 EXPECT_EQ(key_code, actual_key_code) << "Char: " << character; 25 EXPECT_EQ(key_code, actual_key_code) << "Char: " << character;
26 EXPECT_EQ(modifiers, actual_modifiers) << "Char: " << character; 26 EXPECT_EQ(modifiers, actual_modifiers) << "Char: " << character;
27 } 27 }
28 28
29 void CheckCharToKeyCode(char character, ui::KeyboardCode key_code, 29 void CheckCharToKeyCode(char character, ui::KeyboardCode key_code,
30 int modifiers) { 30 int modifiers) {
31 CheckCharToKeyCode16(base::UTF8ToUTF16(std::string(1, character))[0], 31 CheckCharToKeyCode16(base::UTF8ToUTF16(std::string(1, character))[0],
32 key_code, modifiers); 32 key_code, modifiers);
33 } 33 }
34 34
35 #if defined(OS_WIN)
36 void CheckCharToKeyCode(wchar_t character, ui::KeyboardCode key_code, 35 void CheckCharToKeyCode(wchar_t character, ui::KeyboardCode key_code,
37 int modifiers) { 36 int modifiers) {
38 CheckCharToKeyCode16(base::WideToUTF16(std::wstring(1, character))[0], 37 CheckCharToKeyCode16(base::WideToUTF16(std::wstring(1, character))[0],
39 key_code, modifiers); 38 key_code, modifiers);
40 } 39 }
41 #endif
42 40
43 void CheckCantConvertChar(wchar_t character) { 41 void CheckCantConvertChar(wchar_t character) {
44 std::wstring character_string; 42 std::wstring character_string;
45 character_string.push_back(character); 43 character_string.push_back(character);
46 base::char16 character_utf16 = base::WideToUTF16(character_string)[0]; 44 base::char16 character_utf16 = base::WideToUTF16(character_string)[0];
47 ui::KeyboardCode actual_key_code = ui::VKEY_UNKNOWN; 45 ui::KeyboardCode actual_key_code = ui::VKEY_UNKNOWN;
48 int actual_modifiers = 0; 46 int actual_modifiers = 0;
49 std::string error_msg; 47 std::string error_msg;
50 EXPECT_FALSE(ConvertCharToKeyCode( 48 EXPECT_FALSE(ConvertCharToKeyCode(
51 character_utf16, &actual_key_code, &actual_modifiers, &error_msg)); 49 character_utf16, &actual_key_code, &actual_modifiers, &error_msg));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 118
121 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) 119 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
122 // Not implemented on Linux. 120 // Not implemented on Linux.
123 // Fails if German layout is not installed on Mac. 121 // Fails if German layout is not installed on Mac.
124 #define MAYBE_NonShiftModifiers DISABLED_NonShiftModifiers 122 #define MAYBE_NonShiftModifiers DISABLED_NonShiftModifiers
125 #else 123 #else
126 #define MAYBE_NonShiftModifiers NonShiftModifiers 124 #define MAYBE_NonShiftModifiers NonShiftModifiers
127 #endif 125 #endif
128 126
129 TEST(KeycodeTextConversionTest, MAYBE_NonShiftModifiers) { 127 TEST(KeycodeTextConversionTest, MAYBE_NonShiftModifiers) {
130 RestoreKeyboardLayoutOnDestruct restore; 128 ui::ScopedKeyboardLayout keyboard_layout(ui::KEYBOARD_LAYOUT_GERMAN);
131 #if defined(OS_WIN) 129 #if defined(OS_WIN)
132 ASSERT_TRUE(SwitchKeyboardLayout("00000407")); // german
133 int ctrl_and_alt = kControlKeyModifierMask | kAltKeyModifierMask; 130 int ctrl_and_alt = kControlKeyModifierMask | kAltKeyModifierMask;
134 CheckCharToKeyCode('@', ui::VKEY_Q, ctrl_and_alt); 131 CheckCharToKeyCode('@', ui::VKEY_Q, ctrl_and_alt);
135 EXPECT_EQ("@", ConvertKeyCodeToTextNoError(ui::VKEY_Q, ctrl_and_alt)); 132 EXPECT_EQ("@", ConvertKeyCodeToTextNoError(ui::VKEY_Q, ctrl_and_alt));
136 #elif defined(OS_MACOSX) 133 #elif defined(OS_MACOSX)
137 ASSERT_TRUE(SwitchKeyboardLayout("com.apple.keylayout.German"));
138 EXPECT_EQ("@", ConvertKeyCodeToTextNoError( 134 EXPECT_EQ("@", ConvertKeyCodeToTextNoError(
139 ui::VKEY_L, kAltKeyModifierMask)); 135 ui::VKEY_L, kAltKeyModifierMask));
140 #endif 136 #endif
141 } 137 }
142 138
143 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) 139 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
144 // Not implemented on Linux. 140 // Not implemented on Linux.
145 // Fails if German layout is not installed on Mac. 141 // Fails if tested layouts are not installed on Mac.
146 #define MAYBE_NonEnglish DISABLED_NonEnglish 142 #define MAYBE_NonEnglish DISABLED_NonEnglish
147 #else 143 #else
148 #define MAYBE_NonEnglish NonEnglish 144 #define MAYBE_NonEnglish NonEnglish
149 #endif 145 #endif
150 146
151 TEST(KeycodeTextConversionTest, MAYBE_NonEnglish) { 147 TEST(KeycodeTextConversionTest, MAYBE_NonEnglish) {
152 RestoreKeyboardLayoutOnDestruct restore; 148 // For Greek and Russian keyboard layouts, which are very different from
153 #if defined(OS_WIN) 149 // QWERTY, Windows just uses virtual key codes that match the QWERTY layout,
154 ASSERT_TRUE(SwitchKeyboardLayout("00000408")); // greek 150 // and translates them to other characters. If we wanted to test something
155 CheckCharToKeyCode(';', ui::VKEY_Q, 0); 151 // like German, whose layout is very similar to QWERTY, we'd need to be
156 EXPECT_EQ(";", ConvertKeyCodeToTextNoError(ui::VKEY_Q, 0)); 152 // careful, as in this case Windows maps the keyboard scan codes to the
157 // Regression test for chromedriver bug #405. 153 // appropriate (different) VKEYs instead of mapping the VKEYs to different
158 ASSERT_TRUE(SwitchKeyboardLayout("00000419")); // russian 154 // characters.
159 CheckCharToKeyCode(L'\u0438', ui::VKEY_B, 0); 155 {
160 EXPECT_EQ(base::UTF16ToUTF8(L"\u0438"), 156 ui::ScopedKeyboardLayout greek_layout(ui::KEYBOARD_LAYOUT_GREEK);
161 ConvertKeyCodeToTextNoError(ui::VKEY_B, 0)); 157 CheckCharToKeyCode(';', ui::VKEY_Q, 0);
162 #elif defined(OS_MACOSX) 158 EXPECT_EQ(";", ConvertKeyCodeToTextNoError(ui::VKEY_Q, 0));
163 ASSERT_TRUE(SwitchKeyboardLayout("com.apple.keylayout.German")); 159 }
164 CheckCharToKeyCode('z', ui::VKEY_Y, 0); 160 {
165 EXPECT_EQ("z", ConvertKeyCodeToTextNoError(ui::VKEY_Y, 0)); 161 // Regression test for chromedriver bug #405.
166 #endif 162 ui::ScopedKeyboardLayout russian_layout(ui::KEYBOARD_LAYOUT_RUSSIAN);
163 CheckCharToKeyCode(L'\u0438', ui::VKEY_B, 0);
164 EXPECT_EQ(base::WideToUTF8(L"\u0438"),
165 ConvertKeyCodeToTextNoError(ui::VKEY_B, 0));
166 }
167 } 167 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/key_converter_unittest.cc ('k') | chrome/test/chromedriver/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698