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

Side by Side Diff: ui/events/keycodes/platform_key_map_win_unittest.cc

Issue 2128573002: [DomKey] Support Japanese (JIS) layout special keys (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DomKey map for Japanese special keys Created 4 years, 5 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) 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 15
16 namespace ui { 16 namespace ui {
17 17
18 namespace { 18 namespace {
19 19
20 enum Layout { 20 enum Layout {
21 LAYOUT_US, 21 LAYOUT_US,
22 LAYOUT_FR, 22 LAYOUT_FR,
23 LAYOUT_KR, 23 LAYOUT_KR,
24 LAYOUT_JP,
24 }; 25 };
25 26
26 // |LoadKeyboardLayout()| ensures the locale to be loaded into the system 27 // |LoadKeyboardLayout()| ensures the locale to be loaded into the system
27 // (Similar to temporarily adding a locale in Control Panel), otherwise 28 // (Similar to temporarily adding a locale in Control Panel), otherwise
28 // |ToUnicodeEx()| will fall-back to the default locale. 29 // |ToUnicodeEx()| will fall-back to the default locale.
29 // See MSDN LoadKeyboardLayout(): 30 // See MSDN LoadKeyboardLayout():
30 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).as px 31 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).as px
31 // And language constants and strings: 32 // And language constants and strings:
32 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).as px 33 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).as px
33 HKL GetInputLocale(Layout layout) { 34 HKL GetInputLocale(Layout layout) {
34 switch (layout) { 35 switch (layout) {
35 case LAYOUT_US: 36 case LAYOUT_US:
36 return ::LoadKeyboardLayout(L"00000409", KLF_ACTIVATE); 37 return ::LoadKeyboardLayout(L"00000409", KLF_ACTIVATE);
37 case LAYOUT_FR: 38 case LAYOUT_FR:
38 return ::LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE); 39 return ::LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE);
39 case LAYOUT_KR: 40 case LAYOUT_KR:
40 // |LoadKeyboardLayout(L"00000412", KLF_ACTIVATE)| returns the correct 41 // |LoadKeyboardLayout(L"00000412", KLF_ACTIVATE)| returns the correct
41 // Korean locale, but it will fail on DrMemory tests. 42 // Korean locale, but it will fail on DrMemory tests.
42 // See https://crbug.com/612736#c6 43 // See https://crbug.com/612736#c6
43 // However we could bypass it since we are only testing non-printable keys 44 // However we could bypass it since we are only testing non-printable keys
44 // on Korean locale. 45 // on Korean locale.
45 // (This issue only happens on Korean and Japanese). 46 // (This issue only happens on Korean and Japanese).
46 return reinterpret_cast<HKL>(0x04120412); 47 return reinterpret_cast<HKL>(0x04120412);
48 case LAYOUT_JP:
49 return reinterpret_cast<HKL>(0x04110411);
Wez 2016/07/07 18:25:51 LoadKeyboardLayout doesn't work here?
chongz 2016/07/07 22:18:09 Yes |LoadKeyboardLayout()| won't pass DrMemory tes
Wez 2016/07/08 23:34:07 OK, what I was missing is that we just pull the "p
47 default: 50 default:
48 return 0; 51 return 0;
49 } 52 }
50 } 53 }
51 54
52 struct TestKey { 55 struct TestKey {
53 KeyboardCode key_code; 56 KeyboardCode key_code;
54 const char* normal; 57 const char* normal;
55 const char* shift; 58 const char* shift;
56 const char* capslock; 59 const char* capslock;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 EXPECT_STREQ(test_case.altgr_capslock, 110 EXPECT_STREQ(test_case.altgr_capslock,
108 KeycodeConverter::DomKeyToKeyString( 111 KeycodeConverter::DomKeyToKeyString(
109 keymap.DomKeyFromKeyboardCodeImpl( 112 keymap.DomKeyFromKeyboardCodeImpl(
110 key_code, EF_ALTGR_DOWN | EF_CAPS_LOCK_ON)) 113 key_code, EF_ALTGR_DOWN | EF_CAPS_LOCK_ON))
111 .c_str()) 114 .c_str())
112 << label; 115 << label;
113 } 116 }
114 117
115 DomKey DomKeyFromKeyboardCodeImpl(const PlatformKeyMap& keymap, 118 DomKey DomKeyFromKeyboardCodeImpl(const PlatformKeyMap& keymap,
116 KeyboardCode key_code, 119 KeyboardCode key_code,
117 int flags) { 120 int flags) {
Wez 2016/07/07 18:25:51 What's the point of this "helper"? It just seems t
chongz 2016/07/07 22:18:09 Because |PlatformKeyMap::DomKeyFromKeyboardCodeImp
Wez 2016/07/08 23:34:07 Acknowledged.
118 return keymap.DomKeyFromKeyboardCodeImpl(key_code, flags); 121 return keymap.DomKeyFromKeyboardCodeImpl(key_code, flags);
119 } 122 }
120 123
121 private: 124 private:
122 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest); 125 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest);
123 }; 126 };
124 127
125 TEST_F(PlatformKeyMapTest, USLayout) { 128 TEST_F(PlatformKeyMapTest, USLayout) {
126 HKL layout = GetInputLocale(LAYOUT_US); 129 HKL layout = GetInputLocale(LAYOUT_US);
127 PlatformKeyMap keymap(layout); 130 PlatformKeyMap keymap(layout);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 KeyboardCode key_code; 315 KeyboardCode key_code;
313 DomKey key; 316 DomKey key;
314 } kKoreanTestCases[] = { 317 } kKoreanTestCases[] = {
315 {VKEY_HANGUL, DomKey::HANGUL_MODE}, {VKEY_HANJA, DomKey::HANJA_MODE}, 318 {VKEY_HANGUL, DomKey::HANGUL_MODE}, {VKEY_HANJA, DomKey::HANJA_MODE},
316 }; 319 };
317 320
318 // US English should not return values for these keys. 321 // US English should not return values for these keys.
319 HKL us_layout = GetInputLocale(LAYOUT_US); 322 HKL us_layout = GetInputLocale(LAYOUT_US);
320 PlatformKeyMap us_keymap(us_layout); 323 PlatformKeyMap us_keymap(us_layout);
321 for (const auto& test_case : kKoreanTestCases) { 324 for (const auto& test_case : kKoreanTestCases) {
322 EXPECT_EQ(DomKey::NONE, DomKeyFromKeyboardCodeImpl( 325 EXPECT_EQ(DomKey::UNIDENTIFIED, DomKeyFromKeyboardCodeImpl(
323 us_keymap, test_case.key_code, EF_NONE)) 326 us_keymap, test_case.key_code, EF_NONE))
324 << test_case.key_code; 327 << test_case.key_code;
325 } 328 }
326 329
327 // Korean layout should return specific DomKey. 330 // Korean layout should return specific DomKey.
328 HKL ko_layout = GetInputLocale(LAYOUT_KR); 331 HKL ko_layout = GetInputLocale(LAYOUT_KR);
329 PlatformKeyMap ko_keymap(ko_layout); 332 PlatformKeyMap ko_keymap(ko_layout);
330 for (const auto& test_case : kKoreanTestCases) { 333 for (const auto& test_case : kKoreanTestCases) {
331 EXPECT_EQ(test_case.key, DomKeyFromKeyboardCodeImpl( 334 EXPECT_EQ(test_case.key, DomKeyFromKeyboardCodeImpl(
332 ko_keymap, test_case.key_code, EF_NONE)) 335 ko_keymap, test_case.key_code, EF_NONE))
333 << test_case.key_code; 336 << test_case.key_code;
334 } 337 }
335 } 338 }
336 339
340 TEST_F(PlatformKeyMapTest, JapaneseSpecificKeys) {
341 const struct TestCase {
342 KeyboardCode key_code;
343 DomKey jp_key;
344 DomKey us_key;
345 } kJapaneseTestCases[] = {
346 {VKEY_KANA, DomKey::KANA_MODE, DomKey::UNIDENTIFIED},
347 {VKEY_KANJI, DomKey::KANJI_MODE, DomKey::UNIDENTIFIED},
348 {VKEY_OEM_ATTN, DomKey::ALPHANUMERIC, DomKey::UNIDENTIFIED},
349 {VKEY_OEM_FINISH, DomKey::KATAKANA, DomKey::UNIDENTIFIED},
350 {VKEY_OEM_COPY, DomKey::HIRAGANA, DomKey::UNIDENTIFIED},
351 {VKEY_DBE_SBCSCHAR, DomKey::HANKAKU, DomKey::UNIDENTIFIED},
352 {VKEY_DBE_DBCSCHAR, DomKey::ZENKAKU, DomKey::UNIDENTIFIED},
353 {VKEY_OEM_BACKTAB, DomKey::ROMAJI, DomKey::UNIDENTIFIED},
354 {VKEY_ATTN, DomKey::KANA_MODE, DomKey::ATTN},
355 };
356
357 // US English should not return values for these keys.
358 HKL us_layout = GetInputLocale(LAYOUT_US);
359 PlatformKeyMap us_keymap(us_layout);
Wez 2016/07/07 18:25:51 nit: Here and elsewhere, I think it's OK to pass t
chongz 2016/07/07 22:18:09 Done. Except one place for DomCode=>Key testing.
360 for (const auto& test_case : kJapaneseTestCases) {
Wez 2016/07/07 18:25:51 Suggest folding these two loops into one, for clar
chongz 2016/07/07 22:18:09 Done.
361 EXPECT_EQ(test_case.us_key, DomKeyFromKeyboardCodeImpl(
362 us_keymap, test_case.key_code, EF_NONE))
363 << test_case.key_code;
364 }
365
366 // Japanese layout should return specific DomKey.
367 HKL jp_layout = GetInputLocale(LAYOUT_JP);
368 PlatformKeyMap ko_keymap(jp_layout);
Wez 2016/07/07 18:25:51 jp_keymap?
chongz 2016/07/07 22:18:09 Done.
369 for (const auto& test_case : kJapaneseTestCases) {
370 EXPECT_EQ(test_case.jp_key, DomKeyFromKeyboardCodeImpl(
371 ko_keymap, test_case.key_code, EF_NONE))
372 << test_case.key_code;
373 }
374 }
375
337 } // namespace ui 376 } // namespace ui
OLDNEW
« ui/events/keycodes/platform_key_map_win.cc ('K') | « ui/events/keycodes/platform_key_map_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698