OLD | NEW |
---|---|
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 const wchar_t* LAYOUT_US = L"00000409"; | 20 enum Layout { |
21 const wchar_t* LAYOUT_FR = L"0000040c"; | 21 LAYOUT_US, |
22 LAYOUT_FR, | |
23 LAYOUT_KR, | |
24 }; | |
25 | |
26 // |LoadKeyboardLayout()| ensures the locale to be loaded into the system | |
27 // (Similar to temporarily adding a locale in Control Panel), otherwise | |
28 // |ToUnicodeEx()| will fall-back to the default locale. | |
29 // See MSDN LoadKeyboardLayout(): | |
30 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).as px | |
31 // And language constants and strings: | |
32 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).as px | |
33 HKL GetInputLocale(Layout layout) { | |
34 switch (layout) { | |
35 case LAYOUT_US: | |
36 return ::LoadKeyboardLayout(L"00000409", KLF_ACTIVATE); | |
37 case LAYOUT_FR: | |
38 return ::LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE); | |
39 case LAYOUT_KR: | |
40 // |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.
| |
41 // Korean locale, but it will fail on DrMemory tests. | |
42 // See https://crbug.com/612736#c6 | |
43 // However we could bypass it since we are only testing non-printable keys | |
44 // on Korean locale. | |
45 // (This issue only happens on Korean and Japanese). | |
46 return reinterpret_cast<HKL>(0x04120412); | |
47 default: | |
48 return 0; | |
49 } | |
50 } | |
22 | 51 |
23 struct TestKey { | 52 struct TestKey { |
24 // Have to use KeyboardCode instead of DomCode because we don't know the | 53 // Have to use KeyboardCode instead of DomCode because we don't know the |
25 // physical keyboard layout for try bots. | 54 // physical keyboard layout for try bots. |
26 KeyboardCode key_code; | 55 KeyboardCode key_code; |
27 const char* normal; | 56 const char* normal; |
28 const char* shift; | 57 const char* shift; |
29 const char* capslock; | 58 const char* capslock; |
30 const char* altgr; | 59 const char* altgr; |
31 const char* shift_capslock; | 60 const char* shift_capslock; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 KeyboardCode key_code, | 122 KeyboardCode key_code, |
94 int flags) { | 123 int flags) { |
95 return keymap.DomKeyFromNativeImpl(dom_code, key_code, flags); | 124 return keymap.DomKeyFromNativeImpl(dom_code, key_code, flags); |
96 } | 125 } |
97 | 126 |
98 private: | 127 private: |
99 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest); | 128 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest); |
100 }; | 129 }; |
101 | 130 |
102 TEST_F(PlatformKeyMapTest, USLayout) { | 131 TEST_F(PlatformKeyMapTest, USLayout) { |
103 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); | 132 HKL layout = GetInputLocale(LAYOUT_US); |
104 PlatformKeyMap keymap(layout); | 133 PlatformKeyMap keymap(layout); |
105 | 134 |
106 const TestKey kUSLayoutTestCases[] = { | 135 const TestKey kUSLayoutTestCases[] = { |
107 // n s c a sc sa ac | 136 // n s c a sc sa ac |
108 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"}, | 137 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"}, |
109 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"}, | 138 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"}, |
110 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"}, | 139 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"}, |
111 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"}, | 140 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"}, |
112 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"}, | 141 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"}, |
113 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"}, | 142 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"}, |
(...skipping 28 matching lines...) Expand all Loading... | |
142 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, | 171 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, |
143 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, | 172 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, |
144 }; | 173 }; |
145 | 174 |
146 for (const auto& test_case : kUSLayoutTestCases) { | 175 for (const auto& test_case : kUSLayoutTestCases) { |
147 CheckDomCodeToKeyString("USLayout", keymap, test_case, layout); | 176 CheckDomCodeToKeyString("USLayout", keymap, test_case, layout); |
148 } | 177 } |
149 } | 178 } |
150 | 179 |
151 TEST_F(PlatformKeyMapTest, FRLayout) { | 180 TEST_F(PlatformKeyMapTest, FRLayout) { |
152 HKL layout = ::LoadKeyboardLayout(LAYOUT_FR, 0); | 181 HKL layout = GetInputLocale(LAYOUT_FR); |
153 PlatformKeyMap keymap(layout); | 182 PlatformKeyMap keymap(layout); |
154 | 183 |
155 const TestKey kFRLayoutTestCases[] = { | 184 const TestKey kFRLayoutTestCases[] = { |
156 // n s c a sc sa ac | 185 // n s c a sc sa ac |
157 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"}, | 186 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"}, |
158 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"}, | 187 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"}, |
159 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"}, | 188 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"}, |
160 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"}, | 189 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"}, |
161 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"}, | 190 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"}, |
162 {VKEY_5, "(", "5", "5", "[", "(", "5", "["}, | 191 {VKEY_5, "(", "5", "5", "[", "(", "5", "["}, |
(...skipping 28 matching lines...) Expand all Loading... | |
191 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, | 220 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, |
192 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, | 221 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, |
193 }; | 222 }; |
194 | 223 |
195 for (const auto& test_case : kFRLayoutTestCases) { | 224 for (const auto& test_case : kFRLayoutTestCases) { |
196 CheckDomCodeToKeyString("FRLayout", keymap, test_case, layout); | 225 CheckDomCodeToKeyString("FRLayout", keymap, test_case, layout); |
197 } | 226 } |
198 } | 227 } |
199 | 228 |
200 TEST_F(PlatformKeyMapTest, NumPad) { | 229 TEST_F(PlatformKeyMapTest, NumPad) { |
201 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); | 230 HKL layout = GetInputLocale(LAYOUT_US); |
202 PlatformKeyMap keymap(layout); | 231 PlatformKeyMap keymap(layout); |
203 | 232 |
204 const struct TestCase { | 233 const struct TestCase { |
205 KeyboardCode key_code; | 234 KeyboardCode key_code; |
206 DomKey key; | 235 DomKey key; |
207 } kNumPadTestCases[] = { | 236 } kNumPadTestCases[] = { |
208 {VKEY_NUMPAD0, DomKey::FromCharacter('0')}, | 237 {VKEY_NUMPAD0, DomKey::FromCharacter('0')}, |
209 {VKEY_NUMPAD1, DomKey::FromCharacter('1')}, | 238 {VKEY_NUMPAD1, DomKey::FromCharacter('1')}, |
210 {VKEY_NUMPAD2, DomKey::FromCharacter('2')}, | 239 {VKEY_NUMPAD2, DomKey::FromCharacter('2')}, |
211 {VKEY_NUMPAD3, DomKey::FromCharacter('3')}, | 240 {VKEY_NUMPAD3, DomKey::FromCharacter('3')}, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 DomKeyFromNativeImpl(keymap, dom_code, key_code, EF_CONTROL_DOWN)) | 272 DomKeyFromNativeImpl(keymap, dom_code, key_code, EF_CONTROL_DOWN)) |
244 << key_code; | 273 << key_code; |
245 EXPECT_EQ(test_case.key, | 274 EXPECT_EQ(test_case.key, |
246 DomKeyFromNativeImpl(keymap, dom_code, key_code, | 275 DomKeyFromNativeImpl(keymap, dom_code, key_code, |
247 EF_ALTGR_DOWN | EF_CONTROL_DOWN)) | 276 EF_ALTGR_DOWN | EF_CONTROL_DOWN)) |
248 << key_code; | 277 << key_code; |
249 } | 278 } |
250 } | 279 } |
251 | 280 |
252 TEST_F(PlatformKeyMapTest, NonPrintableKey) { | 281 TEST_F(PlatformKeyMapTest, NonPrintableKey) { |
253 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); | 282 HKL layout = GetInputLocale(LAYOUT_US); |
254 PlatformKeyMap keymap(layout); | 283 PlatformKeyMap keymap(layout); |
255 | 284 |
256 for (const auto& test_case : kNonPrintableCodeMap) { | 285 for (const auto& test_case : kNonPrintableCodeMap) { |
257 // Not available on |LAYOUT_US|. | 286 // Not available on |LAYOUT_US|. |
258 if (test_case.dom_code == DomCode::PAUSE || | 287 if (test_case.dom_code == DomCode::PAUSE || |
259 test_case.dom_code == DomCode::LANG2 || | 288 test_case.dom_code == DomCode::LANG2 || |
260 test_case.dom_code == DomCode::NON_CONVERT) | 289 test_case.dom_code == DomCode::NON_CONVERT) |
261 continue; | 290 continue; |
262 | 291 |
263 int scan_code = | 292 int scan_code = |
(...skipping 16 matching lines...) Expand all Loading... | |
280 test_case.dom_key, | 309 test_case.dom_key, |
281 DomKeyFromNativeImpl(keymap, DomCode::NONE, key_code, EF_CONTROL_DOWN)) | 310 DomKeyFromNativeImpl(keymap, DomCode::NONE, key_code, EF_CONTROL_DOWN)) |
282 << key_code << ", " << scan_code; | 311 << key_code << ", " << scan_code; |
283 EXPECT_EQ(test_case.dom_key, | 312 EXPECT_EQ(test_case.dom_key, |
284 DomKeyFromNativeImpl(keymap, DomCode::NONE, key_code, | 313 DomKeyFromNativeImpl(keymap, DomCode::NONE, key_code, |
285 EF_ALTGR_DOWN | EF_CONTROL_DOWN)) | 314 EF_ALTGR_DOWN | EF_CONTROL_DOWN)) |
286 << key_code << ", " << scan_code; | 315 << key_code << ", " << scan_code; |
287 } | 316 } |
288 } | 317 } |
289 | 318 |
319 TEST_F(PlatformKeyMapTest, KoreanSpecificKeys) { | |
320 const struct TestCase { | |
321 KeyboardCode key_code; | |
322 DomKey key; | |
323 } kKoreanTestCases[] = { | |
324 {VKEY_HANGUL, DomKey::HANGUL_MODE}, {VKEY_HANJA, DomKey::HANJA_MODE}, | |
325 }; | |
326 | |
327 // US English should not return values for these keys. | |
328 HKL us_layout = GetInputLocale(LAYOUT_US); | |
329 PlatformKeyMap us_keymap(us_layout); | |
330 for (const auto& test_case : kKoreanTestCases) { | |
331 EXPECT_EQ(DomKey::NONE, DomKeyFromNativeImpl(us_keymap, DomCode::NONE, | |
332 test_case.key_code, EF_NONE)) | |
333 << test_case.key_code; | |
334 } | |
335 | |
336 // Korean layout should return specific DomKey. | |
337 HKL ko_layout = GetInputLocale(LAYOUT_KR); | |
338 PlatformKeyMap ko_keymap(ko_layout); | |
339 for (const auto& test_case : kKoreanTestCases) { | |
340 EXPECT_EQ(test_case.key, DomKeyFromNativeImpl(ko_keymap, DomCode::NONE, | |
341 test_case.key_code, EF_NONE)) | |
342 << test_case.key_code; | |
343 } | |
344 } | |
345 | |
290 } // namespace ui | 346 } // namespace ui |
OLD | NEW |