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

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

Issue 1776673007: [Windows] Produce correct DomKey for NumPad when combined with Shift/NumLock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wez's review 2 Created 4 years, 9 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/keycodes/platform_key_map_win.cc ('k') | no next file » | 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 "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/events/event_constants.h" 9 #include "ui/events/event_constants.h"
10 #include "ui/events/keycodes/dom/dom_code.h" 10 #include "ui/events/keycodes/dom/dom_code.h"
11 #include "ui/events/keycodes/dom/dom_key.h" 11 #include "ui/events/keycodes/dom/dom_key.h"
12 #include "ui/events/keycodes/dom/keycode_converter.h" 12 #include "ui/events/keycodes/dom/keycode_converter.h"
13 13
14 namespace ui { 14 namespace ui {
15 15
16 namespace { 16 namespace {
17 17
18 const wchar_t* LAYOUT_US = L"00000409"; 18 const wchar_t* LAYOUT_US = L"00000409";
19 const wchar_t* LAYOUT_FR = L"0000040c"; 19 const wchar_t* LAYOUT_FR = L"0000040c";
20 20
21 struct TestKey { 21 struct TestKey {
22 // Have to use KeyboardCode instead of DomCode because we don't know the 22 // Have to use KeyboardCode instead of DomCode because we don't know the
23 // physical keyboard layout for try bots. 23 // physical keyboard layout for try bots.
24 KeyboardCode vk; 24 KeyboardCode key_code;
25 const char* normal; 25 const char* normal;
26 const char* shift; 26 const char* shift;
27 const char* capslock; 27 const char* capslock;
28 const char* altgr; 28 const char* altgr;
29 const char* shift_capslock; 29 const char* shift_capslock;
30 const char* shift_altgr; 30 const char* shift_altgr;
31 const char* altgr_capslock; 31 const char* altgr_capslock;
32 }; 32 };
33 33
34 void CheckDomCodeToKeyString(const char* label,
35 const PlatformKeyMap& keymap,
36 const TestKey& t,
37 HKL layout) {
38 int scan_code = ::MapVirtualKeyEx(t.vk, MAPVK_VK_TO_VSC, layout);
39 DomCode dom_code = KeycodeConverter::NativeKeycodeToDomCode(scan_code);
40 EXPECT_STREQ(t.normal, KeycodeConverter::DomKeyToKeyString(
41 keymap.DomCodeAndFlagsToDomKey(dom_code, EF_NONE)).c_str()
42 ) << label;
43 EXPECT_STREQ(t.shift, KeycodeConverter::DomKeyToKeyString(
44 keymap.DomCodeAndFlagsToDomKey(dom_code, EF_SHIFT_DOWN)).c_str()
45 ) << label;
46 EXPECT_STREQ(t.capslock, KeycodeConverter::DomKeyToKeyString(
47 keymap.DomCodeAndFlagsToDomKey(dom_code, EF_CAPS_LOCK_ON)).c_str()
48 ) << label;
49 EXPECT_STREQ(t.altgr, KeycodeConverter::DomKeyToKeyString(
50 keymap.DomCodeAndFlagsToDomKey(dom_code, EF_ALTGR_DOWN)).c_str()
51 ) << label;
52 EXPECT_STREQ(t.shift_capslock, KeycodeConverter::DomKeyToKeyString(
53 keymap.DomCodeAndFlagsToDomKey(dom_code,
54 EF_SHIFT_DOWN | EF_CAPS_LOCK_ON)).c_str()
55 ) << label;
56 EXPECT_STREQ(t.shift_altgr, KeycodeConverter::DomKeyToKeyString(
57 keymap.DomCodeAndFlagsToDomKey(dom_code,
58 EF_SHIFT_DOWN | EF_ALTGR_DOWN)).c_str()
59 ) << label;
60 EXPECT_STREQ(t.altgr_capslock, KeycodeConverter::DomKeyToKeyString(
61 keymap.DomCodeAndFlagsToDomKey(dom_code,
62 EF_ALTGR_DOWN | EF_CAPS_LOCK_ON)).c_str()
63 ) << label;
64 }
65
66 } // anonymous namespace 34 } // anonymous namespace
67 35
68 class PlatformKeyMapTest : public testing::Test { 36 class PlatformKeyMapTest : public testing::Test {
69 public: 37 public:
70 PlatformKeyMapTest() {} 38 PlatformKeyMapTest() {}
71 ~PlatformKeyMapTest() override {} 39 ~PlatformKeyMapTest() override {}
40
41 void CheckDomCodeToKeyString(const char* label,
42 const PlatformKeyMap& keymap,
43 const TestKey& test_case,
44 HKL layout) {
45 KeyboardCode key_code = test_case.key_code;
46 int scan_code = ::MapVirtualKeyEx(key_code, MAPVK_VK_TO_VSC, layout);
47 DomCode dom_code = KeycodeConverter::NativeKeycodeToDomCode(scan_code);
48 EXPECT_STREQ(test_case.normal,
49 KeycodeConverter::DomKeyToKeyString(
50 keymap.DomKeyFromNativeImpl(dom_code, key_code, EF_NONE))
51 .c_str())
52 << label;
53 EXPECT_STREQ(test_case.shift, KeycodeConverter::DomKeyToKeyString(
54 keymap.DomKeyFromNativeImpl(
55 dom_code, key_code, EF_SHIFT_DOWN))
56 .c_str())
57 << label;
58 EXPECT_STREQ(
59 test_case.capslock,
60 KeycodeConverter::DomKeyToKeyString(
61 keymap.DomKeyFromNativeImpl(dom_code, key_code, EF_CAPS_LOCK_ON))
62 .c_str())
63 << label;
64 EXPECT_STREQ(test_case.altgr, KeycodeConverter::DomKeyToKeyString(
65 keymap.DomKeyFromNativeImpl(
66 dom_code, key_code, EF_ALTGR_DOWN))
67 .c_str())
68 << label;
69 EXPECT_STREQ(test_case.shift_capslock,
70 KeycodeConverter::DomKeyToKeyString(
71 keymap.DomKeyFromNativeImpl(
72 dom_code, key_code, EF_SHIFT_DOWN | EF_CAPS_LOCK_ON))
73 .c_str())
74 << label;
75 EXPECT_STREQ(test_case.shift_altgr,
76 KeycodeConverter::DomKeyToKeyString(
77 keymap.DomKeyFromNativeImpl(dom_code, key_code,
78 EF_SHIFT_DOWN | EF_ALTGR_DOWN))
79 .c_str())
80 << label;
81 EXPECT_STREQ(test_case.altgr_capslock,
82 KeycodeConverter::DomKeyToKeyString(
83 keymap.DomKeyFromNativeImpl(
84 dom_code, key_code, EF_ALTGR_DOWN | EF_CAPS_LOCK_ON))
85 .c_str())
86 << label;
87 }
88
89 DomKey DomKeyFromNativeImpl(const PlatformKeyMap& keymap,
90 DomCode dom_code,
91 KeyboardCode key_code,
92 int flags) {
93 return keymap.DomKeyFromNativeImpl(dom_code, key_code, flags);
94 }
95
72 private: 96 private:
73 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest); 97 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest);
74 }; 98 };
75 99
76 TEST_F(PlatformKeyMapTest, USLayout) { 100 TEST_F(PlatformKeyMapTest, USLayout) {
77 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0); 101 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0);
78 PlatformKeyMap keymap(layout); 102 PlatformKeyMap keymap(layout);
79 103
80 const TestKey USKeys[] = { 104 const TestKey kUSLayoutTestCases[] = {
81 // n s c a sc sa ac 105 // n s c a sc sa ac
82 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"}, 106 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"},
83 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"}, 107 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"},
84 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"}, 108 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"},
85 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"}, 109 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"},
86 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"}, 110 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"},
87 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"}, 111 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"},
88 {VKEY_6, "6", "^", "6", "6", "^", "^", "6"}, 112 {VKEY_6, "6", "^", "6", "6", "^", "^", "6"},
89 {VKEY_7, "7", "&", "7", "7", "&", "&", "7"}, 113 {VKEY_7, "7", "&", "7", "7", "&", "&", "7"},
90 {VKEY_8, "8", "*", "8", "8", "*", "*", "8"}, 114 {VKEY_8, "8", "*", "8", "8", "*", "*", "8"},
(...skipping 19 matching lines...) Expand all
110 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"}, 134 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"},
111 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"}, 135 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"},
112 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"}, 136 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"},
113 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"}, 137 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"},
114 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"}, 138 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"},
115 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"}, 139 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"},
116 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, 140 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
117 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, 141 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
118 }; 142 };
119 143
120 for (const auto& k : USKeys) { 144 for (const auto& test_case : kUSLayoutTestCases) {
121 CheckDomCodeToKeyString("USLayout", keymap, k, layout); 145 CheckDomCodeToKeyString("USLayout", keymap, test_case, layout);
122 } 146 }
123 } 147 }
124 148
125 TEST_F(PlatformKeyMapTest, FRLayout) { 149 TEST_F(PlatformKeyMapTest, FRLayout) {
126 HKL layout = ::LoadKeyboardLayout(LAYOUT_FR, 0); 150 HKL layout = ::LoadKeyboardLayout(LAYOUT_FR, 0);
127 PlatformKeyMap keymap(layout); 151 PlatformKeyMap keymap(layout);
128 152
129 const TestKey FRKeys[] = { 153 const TestKey kFRLayoutTestCases[] = {
130 // n s c a sc sa ac 154 // n s c a sc sa ac
131 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"}, 155 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"},
132 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"}, 156 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"},
133 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"}, 157 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"},
134 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"}, 158 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"},
135 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"}, 159 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"},
136 {VKEY_5, "(", "5", "5", "[", "(", "5", "["}, 160 {VKEY_5, "(", "5", "5", "[", "(", "5", "["},
137 {VKEY_6, "-", "6", "6", "|", "-", "6", "|"}, 161 {VKEY_6, "-", "6", "6", "|", "-", "6", "|"},
138 {VKEY_7, "è", "7", "7", "Dead", "è", "7", "Dead"}, 162 {VKEY_7, "è", "7", "7", "Dead", "è", "7", "Dead"},
139 {VKEY_8, "_", "8", "8", "\\", "_", "8", "\\"}, 163 {VKEY_8, "_", "8", "8", "\\", "_", "8", "\\"},
(...skipping 19 matching lines...) Expand all
159 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"}, 183 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"},
160 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"}, 184 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"},
161 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"}, 185 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"},
162 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"}, 186 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"},
163 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"}, 187 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"},
164 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"}, 188 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"},
165 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"}, 189 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
166 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"}, 190 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
167 }; 191 };
168 192
169 for (const auto& k : FRKeys) { 193 for (const auto& test_case : kFRLayoutTestCases) {
170 CheckDomCodeToKeyString("FRLayout", keymap, k, layout); 194 CheckDomCodeToKeyString("FRLayout", keymap, test_case, layout);
171 } 195 }
172 } 196 }
173 197
198 TEST_F(PlatformKeyMapTest, NumPad) {
199 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0);
200 PlatformKeyMap keymap(layout);
201
202 const struct TestCase {
203 KeyboardCode key_code;
204 DomKey key;
205 } kNumPadTestCases[] = {
206 {VKEY_NUMPAD0, DomKey::FromCharacter('0')},
207 {VKEY_NUMPAD1, DomKey::FromCharacter('1')},
208 {VKEY_NUMPAD2, DomKey::FromCharacter('2')},
209 {VKEY_NUMPAD3, DomKey::FromCharacter('3')},
210 {VKEY_NUMPAD4, DomKey::FromCharacter('4')},
211 {VKEY_NUMPAD5, DomKey::FromCharacter('5')},
212 {VKEY_NUMPAD6, DomKey::FromCharacter('6')},
213 {VKEY_NUMPAD7, DomKey::FromCharacter('7')},
214 {VKEY_NUMPAD8, DomKey::FromCharacter('8')},
215 {VKEY_NUMPAD9, DomKey::FromCharacter('9')},
216 {VKEY_CLEAR, DomKey::CLEAR},
217 {VKEY_PRIOR, DomKey::PAGE_UP},
218 {VKEY_NEXT, DomKey::PAGE_DOWN},
219 {VKEY_END, DomKey::END},
220 {VKEY_HOME, DomKey::HOME},
221 {VKEY_LEFT, DomKey::ARROW_LEFT},
222 {VKEY_UP, DomKey::ARROW_UP},
223 {VKEY_RIGHT, DomKey::ARROW_RIGHT},
224 {VKEY_DOWN, DomKey::ARROW_DOWN},
225 {VKEY_INSERT, DomKey::INSERT},
226 {VKEY_DELETE, DomKey::DEL},
227 };
228
229 for (const auto& test_case : kNumPadTestCases) {
230 KeyboardCode key_code = test_case.key_code;
231 int scan_code = ::MapVirtualKeyEx(key_code, MAPVK_VK_TO_VSC, layout);
232 DomCode dom_code = KeycodeConverter::NativeKeycodeToDomCode(scan_code);
233
234 EXPECT_EQ(test_case.key,
235 DomKeyFromNativeImpl(keymap, dom_code, key_code, EF_NONE))
236 << key_code;
237 EXPECT_EQ(test_case.key,
238 DomKeyFromNativeImpl(keymap, dom_code, key_code, EF_ALTGR_DOWN))
239 << key_code;
240 EXPECT_EQ(test_case.key,
241 DomKeyFromNativeImpl(keymap, dom_code, key_code, EF_CONTROL_DOWN))
242 << key_code;
243 EXPECT_EQ(test_case.key,
244 DomKeyFromNativeImpl(keymap, dom_code, key_code,
245 EF_ALTGR_DOWN | EF_CONTROL_DOWN))
246 << key_code;
247 }
248 }
249
174 } // namespace ui 250 } // namespace ui
OLDNEW
« no previous file with comments | « 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