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: ui/events/keycodes/platform_key_map_win_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
« no previous file with comments | « ui/events/BUILD.gn ('k') | ui/events/test/keyboard_layout.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "ui/events/keycodes/platform_key_map_win.h" 5 #include "ui/events/keycodes/platform_key_map_win.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/event_constants.h" 10 #include "ui/events/event_constants.h"
11 #include "ui/events/keycodes/dom/dom_code.h" 11 #include "ui/events/keycodes/dom/dom_code.h"
12 #include "ui/events/keycodes/dom/dom_key.h" 12 #include "ui/events/keycodes/dom/dom_key.h"
13 #include "ui/events/keycodes/dom/keycode_converter.h" 13 #include "ui/events/keycodes/dom/keycode_converter.h"
14 #include "ui/events/keycodes/dom_us_layout_data.h" 14 #include "ui/events/keycodes/dom_us_layout_data.h"
15 #include "ui/events/test/keyboard_layout.h"
16 15
17 namespace ui { 16 namespace ui {
18 17
19 namespace { 18 namespace {
20 19
20 enum Layout {
21 LAYOUT_US,
22 LAYOUT_FR,
23 LAYOUT_KR,
24 LAYOUT_JP,
25 };
26
27 // |LoadKeyboardLayout()| ensures the locale to be loaded into the system
28 // (Similar to temporarily adding a locale in Control Panel), otherwise
29 // |ToUnicodeEx()| will fall-back to the default locale.
30 // See MSDN LoadKeyboardLayout():
31 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).as px
32 // And language constants and strings:
33 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).as px
34 HKL GetInputLocale(Layout layout) {
35 switch (layout) {
36 case LAYOUT_US:
37 return ::LoadKeyboardLayout(L"00000409", KLF_ACTIVATE);
38 case LAYOUT_FR:
39 return ::LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE);
40 case LAYOUT_KR:
41 // |LoadKeyboardLayout(L"00000412", KLF_ACTIVATE)| returns the correct
42 // Korean locale, but it will fail on DrMemory tests.
43 // See https://crbug.com/612736#c6
44 // However we could bypass it since we are only testing non-printable keys
45 // on Korean locale.
46 // (This issue only happens on Korean and Japanese).
47 return reinterpret_cast<HKL>(0x04120412);
48 case LAYOUT_JP:
49 return reinterpret_cast<HKL>(0x04110411);
50 default:
51 return 0;
52 }
53 }
54
21 struct TestKey { 55 struct TestKey {
22 KeyboardCode key_code; 56 KeyboardCode key_code;
23 const char* normal; 57 const char* normal;
24 const char* shift; 58 const char* shift;
25 const char* capslock; 59 const char* capslock;
26 const char* altgr; 60 const char* altgr;
27 const char* shift_capslock; 61 const char* shift_capslock;
28 const char* shift_altgr; 62 const char* shift_altgr;
29 const char* altgr_capslock; 63 const char* altgr_capslock;
30 }; 64 };
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 KeyboardCode key_code, 119 KeyboardCode key_code,
86 int flags) { 120 int flags) {
87 return keymap.DomKeyFromKeyboardCodeImpl(key_code, flags); 121 return keymap.DomKeyFromKeyboardCodeImpl(key_code, flags);
88 } 122 }
89 123
90 private: 124 private:
91 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest); 125 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest);
92 }; 126 };
93 127
94 TEST_F(PlatformKeyMapTest, USLayout) { 128 TEST_F(PlatformKeyMapTest, USLayout) {
95 PlatformKeyMap keymap(GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_ENGLISH_US)); 129 PlatformKeyMap keymap(GetInputLocale(LAYOUT_US));
96 130
97 const TestKey kUSLayoutTestCases[] = { 131 const TestKey kUSLayoutTestCases[] = {
98 // n s c a sc sa ac 132 // n s c a sc sa ac
99 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"}, 133 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"},
100 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"}, 134 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"},
101 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"}, 135 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"},
102 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"}, 136 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"},
103 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"}, 137 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"},
104 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"}, 138 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"},
105 {VKEY_6, "6", "^", "6", "6", "^", "^", "6"}, 139 {VKEY_6, "6", "^", "6", "6", "^", "^", "6"},
(...skipping 27 matching lines...) Expand all
133 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, 167 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
134 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, 168 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
135 }; 169 };
136 170
137 for (const auto& test_case : kUSLayoutTestCases) { 171 for (const auto& test_case : kUSLayoutTestCases) {
138 CheckKeyboardCodeToKeyString("USLayout", keymap, test_case); 172 CheckKeyboardCodeToKeyString("USLayout", keymap, test_case);
139 } 173 }
140 } 174 }
141 175
142 TEST_F(PlatformKeyMapTest, FRLayout) { 176 TEST_F(PlatformKeyMapTest, FRLayout) {
143 PlatformKeyMap keymap(GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_FRENCH)); 177 PlatformKeyMap keymap(GetInputLocale(LAYOUT_FR));
144 178
145 const TestKey kFRLayoutTestCases[] = { 179 const TestKey kFRLayoutTestCases[] = {
146 // n s c a sc sa ac 180 // n s c a sc sa ac
147 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"}, 181 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"},
148 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"}, 182 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"},
149 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"}, 183 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"},
150 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"}, 184 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"},
151 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"}, 185 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"},
152 {VKEY_5, "(", "5", "5", "[", "(", "5", "["}, 186 {VKEY_5, "(", "5", "5", "[", "(", "5", "["},
153 {VKEY_6, "-", "6", "6", "|", "-", "6", "|"}, 187 {VKEY_6, "-", "6", "6", "|", "-", "6", "|"},
(...skipping 27 matching lines...) Expand all
181 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, 215 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
182 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, 216 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
183 }; 217 };
184 218
185 for (const auto& test_case : kFRLayoutTestCases) { 219 for (const auto& test_case : kFRLayoutTestCases) {
186 CheckKeyboardCodeToKeyString("FRLayout", keymap, test_case); 220 CheckKeyboardCodeToKeyString("FRLayout", keymap, test_case);
187 } 221 }
188 } 222 }
189 223
190 TEST_F(PlatformKeyMapTest, NumPad) { 224 TEST_F(PlatformKeyMapTest, NumPad) {
191 PlatformKeyMap keymap(GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_ENGLISH_US)); 225 PlatformKeyMap keymap(GetInputLocale(LAYOUT_US));
192 226
193 const struct TestCase { 227 const struct TestCase {
194 KeyboardCode key_code; 228 KeyboardCode key_code;
195 DomKey key; 229 DomKey key;
196 } kNumPadTestCases[] = { 230 } kNumPadTestCases[] = {
197 {VKEY_NUMPAD0, DomKey::FromCharacter('0')}, 231 {VKEY_NUMPAD0, DomKey::FromCharacter('0')},
198 {VKEY_NUMPAD1, DomKey::FromCharacter('1')}, 232 {VKEY_NUMPAD1, DomKey::FromCharacter('1')},
199 {VKEY_NUMPAD2, DomKey::FromCharacter('2')}, 233 {VKEY_NUMPAD2, DomKey::FromCharacter('2')},
200 {VKEY_NUMPAD3, DomKey::FromCharacter('3')}, 234 {VKEY_NUMPAD3, DomKey::FromCharacter('3')},
201 {VKEY_NUMPAD4, DomKey::FromCharacter('4')}, 235 {VKEY_NUMPAD4, DomKey::FromCharacter('4')},
(...skipping 28 matching lines...) Expand all
230 DomKeyFromKeyboardCodeImpl(keymap, key_code, EF_CONTROL_DOWN)) 264 DomKeyFromKeyboardCodeImpl(keymap, key_code, EF_CONTROL_DOWN))
231 << key_code; 265 << key_code;
232 EXPECT_EQ(test_case.key, 266 EXPECT_EQ(test_case.key,
233 DomKeyFromKeyboardCodeImpl(keymap, key_code, 267 DomKeyFromKeyboardCodeImpl(keymap, key_code,
234 EF_ALTGR_DOWN | EF_CONTROL_DOWN)) 268 EF_ALTGR_DOWN | EF_CONTROL_DOWN))
235 << key_code; 269 << key_code;
236 } 270 }
237 } 271 }
238 272
239 TEST_F(PlatformKeyMapTest, NonPrintableKey) { 273 TEST_F(PlatformKeyMapTest, NonPrintableKey) {
240 HKL layout = GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_ENGLISH_US); 274 HKL layout = GetInputLocale(LAYOUT_US);
241 PlatformKeyMap keymap(layout); 275 PlatformKeyMap keymap(layout);
242 276
243 for (const auto& test_case : kNonPrintableCodeMap) { 277 for (const auto& test_case : kNonPrintableCodeMap) {
244 // Not available on |LAYOUT_US|. 278 // Not available on |LAYOUT_US|.
245 if (test_case.dom_code == DomCode::PAUSE || 279 if (test_case.dom_code == DomCode::PAUSE ||
246 test_case.dom_code == DomCode::LANG2 || 280 test_case.dom_code == DomCode::LANG2 ||
247 test_case.dom_code == DomCode::NON_CONVERT) 281 test_case.dom_code == DomCode::NON_CONVERT)
248 continue; 282 continue;
249 283
250 int scan_code = 284 int scan_code =
(...skipping 25 matching lines...) Expand all
276 TEST_F(PlatformKeyMapTest, KoreanSpecificKeys) { 310 TEST_F(PlatformKeyMapTest, KoreanSpecificKeys) {
277 const struct TestCase { 311 const struct TestCase {
278 KeyboardCode key_code; 312 KeyboardCode key_code;
279 DomKey kr_key; 313 DomKey kr_key;
280 DomKey us_key; 314 DomKey us_key;
281 } kKoreanTestCases[] = { 315 } kKoreanTestCases[] = {
282 {VKEY_HANGUL, DomKey::HANGUL_MODE, DomKey::UNIDENTIFIED}, 316 {VKEY_HANGUL, DomKey::HANGUL_MODE, DomKey::UNIDENTIFIED},
283 {VKEY_HANJA, DomKey::HANJA_MODE, DomKey::UNIDENTIFIED}, 317 {VKEY_HANJA, DomKey::HANJA_MODE, DomKey::UNIDENTIFIED},
284 }; 318 };
285 319
286 PlatformKeyMap us_keymap( 320 PlatformKeyMap us_keymap(GetInputLocale(LAYOUT_US));
287 GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_ENGLISH_US)); 321 PlatformKeyMap kr_keymap(GetInputLocale(LAYOUT_KR));
288 PlatformKeyMap kr_keymap(GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_KOREAN));
289 for (const auto& test_case : kKoreanTestCases) { 322 for (const auto& test_case : kKoreanTestCases) {
290 EXPECT_EQ(test_case.us_key, DomKeyFromKeyboardCodeImpl( 323 EXPECT_EQ(test_case.us_key, DomKeyFromKeyboardCodeImpl(
291 us_keymap, test_case.key_code, EF_NONE)) 324 us_keymap, test_case.key_code, EF_NONE))
292 << test_case.key_code; 325 << test_case.key_code;
293 EXPECT_EQ(test_case.kr_key, DomKeyFromKeyboardCodeImpl( 326 EXPECT_EQ(test_case.kr_key, DomKeyFromKeyboardCodeImpl(
294 kr_keymap, test_case.key_code, EF_NONE)) 327 kr_keymap, test_case.key_code, EF_NONE))
295 << test_case.key_code; 328 << test_case.key_code;
296 } 329 }
297 } 330 }
298 331
299 TEST_F(PlatformKeyMapTest, JapaneseSpecificKeys) { 332 TEST_F(PlatformKeyMapTest, JapaneseSpecificKeys) {
300 const struct TestCase { 333 const struct TestCase {
301 KeyboardCode key_code; 334 KeyboardCode key_code;
302 DomKey jp_key; 335 DomKey jp_key;
303 DomKey us_key; 336 DomKey us_key;
304 } kJapaneseTestCases[] = { 337 } kJapaneseTestCases[] = {
305 {VKEY_KANA, DomKey::KANA_MODE, DomKey::UNIDENTIFIED}, 338 {VKEY_KANA, DomKey::KANA_MODE, DomKey::UNIDENTIFIED},
306 {VKEY_KANJI, DomKey::KANJI_MODE, DomKey::UNIDENTIFIED}, 339 {VKEY_KANJI, DomKey::KANJI_MODE, DomKey::UNIDENTIFIED},
307 {VKEY_OEM_ATTN, DomKey::ALPHANUMERIC, DomKey::UNIDENTIFIED}, 340 {VKEY_OEM_ATTN, DomKey::ALPHANUMERIC, DomKey::UNIDENTIFIED},
308 {VKEY_OEM_FINISH, DomKey::KATAKANA, DomKey::UNIDENTIFIED}, 341 {VKEY_OEM_FINISH, DomKey::KATAKANA, DomKey::UNIDENTIFIED},
309 {VKEY_OEM_COPY, DomKey::HIRAGANA, DomKey::UNIDENTIFIED}, 342 {VKEY_OEM_COPY, DomKey::HIRAGANA, DomKey::UNIDENTIFIED},
310 {VKEY_DBE_SBCSCHAR, DomKey::HANKAKU, DomKey::UNIDENTIFIED}, 343 {VKEY_DBE_SBCSCHAR, DomKey::HANKAKU, DomKey::UNIDENTIFIED},
311 {VKEY_DBE_DBCSCHAR, DomKey::ZENKAKU, DomKey::UNIDENTIFIED}, 344 {VKEY_DBE_DBCSCHAR, DomKey::ZENKAKU, DomKey::UNIDENTIFIED},
312 {VKEY_OEM_BACKTAB, DomKey::ROMAJI, DomKey::UNIDENTIFIED}, 345 {VKEY_OEM_BACKTAB, DomKey::ROMAJI, DomKey::UNIDENTIFIED},
313 {VKEY_ATTN, DomKey::KANA_MODE, DomKey::ATTN}, 346 {VKEY_ATTN, DomKey::KANA_MODE, DomKey::ATTN},
314 }; 347 };
315 348
316 PlatformKeyMap us_keymap( 349 PlatformKeyMap us_keymap(GetInputLocale(LAYOUT_US));
317 GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_ENGLISH_US)); 350 PlatformKeyMap jp_keymap(GetInputLocale(LAYOUT_JP));
318 PlatformKeyMap jp_keymap(GetPlatformKeyboardLayout(KEYBOARD_LAYOUT_JAPANESE));
319 for (const auto& test_case : kJapaneseTestCases) { 351 for (const auto& test_case : kJapaneseTestCases) {
320 EXPECT_EQ(test_case.us_key, DomKeyFromKeyboardCodeImpl( 352 EXPECT_EQ(test_case.us_key, DomKeyFromKeyboardCodeImpl(
321 us_keymap, test_case.key_code, EF_NONE)) 353 us_keymap, test_case.key_code, EF_NONE))
322 << test_case.key_code; 354 << test_case.key_code;
323 EXPECT_EQ(test_case.jp_key, DomKeyFromKeyboardCodeImpl( 355 EXPECT_EQ(test_case.jp_key, DomKeyFromKeyboardCodeImpl(
324 jp_keymap, test_case.key_code, EF_NONE)) 356 jp_keymap, test_case.key_code, EF_NONE))
325 << test_case.key_code; 357 << test_case.key_code;
326 } 358 }
327 } 359 }
328 360
329 } // namespace ui 361 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/BUILD.gn ('k') | ui/events/test/keyboard_layout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698