Chromium Code Reviews| Index: ui/events/keycodes/platform_key_map_win_unittest.cc |
| diff --git a/ui/events/keycodes/platform_key_map_win_unittest.cc b/ui/events/keycodes/platform_key_map_win_unittest.cc |
| index 1a3fb352f79868bc4ea3cc970792f6425e68cec4..2d87cf26787fbe401b9b9dbb3d96e6be341d6dd6 100644 |
| --- a/ui/events/keycodes/platform_key_map_win_unittest.cc |
| +++ b/ui/events/keycodes/platform_key_map_win_unittest.cc |
| @@ -17,8 +17,37 @@ namespace ui { |
| namespace { |
| -const wchar_t* LAYOUT_US = L"00000409"; |
| -const wchar_t* LAYOUT_FR = L"0000040c"; |
| +enum Layout { |
| + LAYOUT_US, |
| + LAYOUT_FR, |
| + LAYOUT_KR, |
| +}; |
| + |
| +// |LoadKeyboardLayout()| ensures the locale to be loaded into the system |
| +// (Similar to temporarily adding a locale in Control Panel), otherwise |
| +// |ToUnicodeEx()| will fall-back to the default locale. |
| +// See MSDN LoadKeyboardLayout(): |
| +// https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).aspx |
| +// And language constants and strings: |
| +// https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).aspx |
| +HKL GetInputLocale(Layout layout) { |
| + switch (layout) { |
| + case LAYOUT_US: |
| + return ::LoadKeyboardLayout(L"00000409", KLF_ACTIVATE); |
| + case LAYOUT_FR: |
| + return ::LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE); |
| + case LAYOUT_KR: |
| + // |GetInputLocale(L"00000412", KLF_ACTIVATE)| returns the coct |
|
chongz
2016/06/24 17:05:32
Also tried:
1. L"0412:E0010412"
2. L"E0010412"
Wez
2016/06/24 17:54:57
What is the 'coct Korean locale'?
Do you mean 'Lo
chongz
2016/06/24 18:07:27
Sorry for the typo... Yes it should be 'LoadKeyboa
chongz
2016/06/24 18:45:55
Sure I'll wait for his comments.
|
| + // Korean locale, but it will fail on DrMemory tests. |
| + // See https://crbug.com/612736#c6 |
| + // However we could bypass it since we are only testing non-printable keys |
| + // on Korean locale. |
| + // (This issue only happens on Korean and Japanese). |
| + return reinterpret_cast<HKL>(0x04120412); |
| + default: |
| + return 0; |
| + } |
| +} |
| struct TestKey { |
| // Have to use KeyboardCode instead of DomCode because we don't know the |
| @@ -100,7 +129,7 @@ class PlatformKeyMapTest : public testing::Test { |
| }; |
| TEST_F(PlatformKeyMapTest, USLayout) { |
| - HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); |
| + HKL layout = GetInputLocale(LAYOUT_US); |
| PlatformKeyMap keymap(layout); |
| const TestKey kUSLayoutTestCases[] = { |
| @@ -149,7 +178,7 @@ TEST_F(PlatformKeyMapTest, USLayout) { |
| } |
| TEST_F(PlatformKeyMapTest, FRLayout) { |
| - HKL layout = ::LoadKeyboardLayout(LAYOUT_FR, 0); |
| + HKL layout = GetInputLocale(LAYOUT_FR); |
| PlatformKeyMap keymap(layout); |
| const TestKey kFRLayoutTestCases[] = { |
| @@ -198,7 +227,7 @@ TEST_F(PlatformKeyMapTest, FRLayout) { |
| } |
| TEST_F(PlatformKeyMapTest, NumPad) { |
| - HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); |
| + HKL layout = GetInputLocale(LAYOUT_US); |
| PlatformKeyMap keymap(layout); |
| const struct TestCase { |
| @@ -250,7 +279,7 @@ TEST_F(PlatformKeyMapTest, NumPad) { |
| } |
| TEST_F(PlatformKeyMapTest, NonPrintableKey) { |
| - HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); |
| + HKL layout = GetInputLocale(LAYOUT_US); |
| PlatformKeyMap keymap(layout); |
| for (const auto& test_case : kNonPrintableCodeMap) { |
| @@ -287,4 +316,31 @@ TEST_F(PlatformKeyMapTest, NonPrintableKey) { |
| } |
| } |
| +TEST_F(PlatformKeyMapTest, KoreanSpecificKeys) { |
| + const struct TestCase { |
| + KeyboardCode key_code; |
| + DomKey key; |
| + } kKoreanTestCases[] = { |
| + {VKEY_HANGUL, DomKey::HANGUL_MODE}, {VKEY_HANJA, DomKey::HANJA_MODE}, |
| + }; |
| + |
| + // US English should not return values for these keys. |
| + HKL us_layout = GetInputLocale(LAYOUT_US); |
| + PlatformKeyMap us_keymap(us_layout); |
| + for (const auto& test_case : kKoreanTestCases) { |
| + EXPECT_EQ(DomKey::NONE, DomKeyFromNativeImpl(us_keymap, DomCode::NONE, |
| + test_case.key_code, EF_NONE)) |
| + << test_case.key_code; |
| + } |
| + |
| + // Korean layout should return specific DomKey. |
| + HKL ko_layout = GetInputLocale(LAYOUT_KR); |
| + PlatformKeyMap ko_keymap(ko_layout); |
| + for (const auto& test_case : kKoreanTestCases) { |
| + EXPECT_EQ(test_case.key, DomKeyFromNativeImpl(ko_keymap, DomCode::NONE, |
| + test_case.key_code, EF_NONE)) |
| + << test_case.key_code; |
| + } |
| +} |
| + |
| } // namespace ui |