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

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

Issue 2349253002: Revert of Force U.S. English keyboard layout for TextfieldTest.KeysWithModifiersTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/events/keycodes/keyboard_codes.h" 14 #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)
35 void CheckCharToKeyCode(wchar_t character, ui::KeyboardCode key_code, 36 void CheckCharToKeyCode(wchar_t character, ui::KeyboardCode key_code,
36 int modifiers) { 37 int modifiers) {
37 CheckCharToKeyCode16(base::WideToUTF16(std::wstring(1, character))[0], 38 CheckCharToKeyCode16(base::WideToUTF16(std::wstring(1, character))[0],
38 key_code, modifiers); 39 key_code, modifiers);
39 } 40 }
41 #endif
40 42
41 void CheckCantConvertChar(wchar_t character) { 43 void CheckCantConvertChar(wchar_t character) {
42 std::wstring character_string; 44 std::wstring character_string;
43 character_string.push_back(character); 45 character_string.push_back(character);
44 base::char16 character_utf16 = base::WideToUTF16(character_string)[0]; 46 base::char16 character_utf16 = base::WideToUTF16(character_string)[0];
45 ui::KeyboardCode actual_key_code = ui::VKEY_UNKNOWN; 47 ui::KeyboardCode actual_key_code = ui::VKEY_UNKNOWN;
46 int actual_modifiers = 0; 48 int actual_modifiers = 0;
47 std::string error_msg; 49 std::string error_msg;
48 EXPECT_FALSE(ConvertCharToKeyCode( 50 EXPECT_FALSE(ConvertCharToKeyCode(
49 character_utf16, &actual_key_code, &actual_modifiers, &error_msg)); 51 character_utf16, &actual_key_code, &actual_modifiers, &error_msg));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 120
119 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) 121 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
120 // Not implemented on Linux. 122 // Not implemented on Linux.
121 // Fails if German layout is not installed on Mac. 123 // Fails if German layout is not installed on Mac.
122 #define MAYBE_NonShiftModifiers DISABLED_NonShiftModifiers 124 #define MAYBE_NonShiftModifiers DISABLED_NonShiftModifiers
123 #else 125 #else
124 #define MAYBE_NonShiftModifiers NonShiftModifiers 126 #define MAYBE_NonShiftModifiers NonShiftModifiers
125 #endif 127 #endif
126 128
127 TEST(KeycodeTextConversionTest, MAYBE_NonShiftModifiers) { 129 TEST(KeycodeTextConversionTest, MAYBE_NonShiftModifiers) {
128 ui::ScopedKeyboardLayout keyboard_layout(ui::KEYBOARD_LAYOUT_GERMAN); 130 RestoreKeyboardLayoutOnDestruct restore;
129 #if defined(OS_WIN) 131 #if defined(OS_WIN)
132 ASSERT_TRUE(SwitchKeyboardLayout("00000407")); // german
130 int ctrl_and_alt = kControlKeyModifierMask | kAltKeyModifierMask; 133 int ctrl_and_alt = kControlKeyModifierMask | kAltKeyModifierMask;
131 CheckCharToKeyCode('@', ui::VKEY_Q, ctrl_and_alt); 134 CheckCharToKeyCode('@', ui::VKEY_Q, ctrl_and_alt);
132 EXPECT_EQ("@", ConvertKeyCodeToTextNoError(ui::VKEY_Q, ctrl_and_alt)); 135 EXPECT_EQ("@", ConvertKeyCodeToTextNoError(ui::VKEY_Q, ctrl_and_alt));
133 #elif defined(OS_MACOSX) 136 #elif defined(OS_MACOSX)
137 ASSERT_TRUE(SwitchKeyboardLayout("com.apple.keylayout.German"));
134 EXPECT_EQ("@", ConvertKeyCodeToTextNoError( 138 EXPECT_EQ("@", ConvertKeyCodeToTextNoError(
135 ui::VKEY_L, kAltKeyModifierMask)); 139 ui::VKEY_L, kAltKeyModifierMask));
136 #endif 140 #endif
137 } 141 }
138 142
139 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) 143 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
140 // Not implemented on Linux. 144 // Not implemented on Linux.
141 // Fails if tested layouts are not installed on Mac. 145 // Fails if German layout is not installed on Mac.
142 #define MAYBE_NonEnglish DISABLED_NonEnglish 146 #define MAYBE_NonEnglish DISABLED_NonEnglish
143 #else 147 #else
144 #define MAYBE_NonEnglish NonEnglish 148 #define MAYBE_NonEnglish NonEnglish
145 #endif 149 #endif
146 150
147 TEST(KeycodeTextConversionTest, MAYBE_NonEnglish) { 151 TEST(KeycodeTextConversionTest, MAYBE_NonEnglish) {
148 // For Greek and Russian keyboard layouts, which are very different from 152 RestoreKeyboardLayoutOnDestruct restore;
149 // QWERTY, Windows just uses virtual key codes that match the QWERTY layout, 153 #if defined(OS_WIN)
150 // and translates them to other characters. If we wanted to test something 154 ASSERT_TRUE(SwitchKeyboardLayout("00000408")); // greek
151 // like German, whose layout is very similar to QWERTY, we'd need to be 155 CheckCharToKeyCode(';', ui::VKEY_Q, 0);
152 // careful, as in this case Windows maps the keyboard scan codes to the 156 EXPECT_EQ(";", ConvertKeyCodeToTextNoError(ui::VKEY_Q, 0));
153 // appropriate (different) VKEYs instead of mapping the VKEYs to different 157 // Regression test for chromedriver bug #405.
154 // characters. 158 ASSERT_TRUE(SwitchKeyboardLayout("00000419")); // russian
155 { 159 CheckCharToKeyCode(L'\u0438', ui::VKEY_B, 0);
156 ui::ScopedKeyboardLayout greek_layout(ui::KEYBOARD_LAYOUT_GREEK); 160 EXPECT_EQ(base::UTF16ToUTF8(L"\u0438"),
157 CheckCharToKeyCode(';', ui::VKEY_Q, 0); 161 ConvertKeyCodeToTextNoError(ui::VKEY_B, 0));
158 EXPECT_EQ(";", ConvertKeyCodeToTextNoError(ui::VKEY_Q, 0)); 162 #elif defined(OS_MACOSX)
159 } 163 ASSERT_TRUE(SwitchKeyboardLayout("com.apple.keylayout.German"));
160 { 164 CheckCharToKeyCode('z', ui::VKEY_Y, 0);
161 // Regression test for chromedriver bug #405. 165 EXPECT_EQ("z", ConvertKeyCodeToTextNoError(ui::VKEY_Y, 0));
162 ui::ScopedKeyboardLayout russian_layout(ui::KEYBOARD_LAYOUT_RUSSIAN); 166 #endif
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