MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / ui / events / keycodes / keyboard_code_conversion_unittest.cc
blobeb764513842aafb1bcf3b1d8714dba63f091fd93
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/keycodes/keyboard_code_conversion.h"
7 #include "base/basictypes.h"
8 #include "base/strings/stringprintf.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/event_constants.h"
11 #include "ui/events/keycodes/dom/dom_code.h"
12 #include "ui/events/keycodes/dom/dom_key.h"
13 #include "ui/events/keycodes/dom/keycode_converter.h"
14 #include "ui/events/keycodes/dom_us_layout_data.h"
15 #include "ui/events/keycodes/keyboard_codes.h"
17 namespace {
19 struct Meaning {
20 bool defined;
21 ui::DomKey::Base dom_key;
22 ui::KeyboardCode key_code;
25 const Meaning kUndefined = {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN};
27 void CheckDomCodeToMeaning(const char* label,
28 bool f(ui::DomCode dom_code,
29 int flags,
30 ui::DomKey* out_dom_key,
31 ui::KeyboardCode* out_key_code),
32 ui::DomCode dom_code,
33 int event_flags,
34 const Meaning& result) {
35 ui::DomKey result_dom_key = ui::DomKey::NONE;
36 ui::KeyboardCode result_key_code = ui::VKEY_UNKNOWN;
37 bool success = f(dom_code, event_flags, &result_dom_key, &result_key_code);
38 SCOPED_TRACE(
39 base::StringPrintf("%s %s %06X:%04X", label,
40 ui::KeycodeConverter::DomCodeToCodeString(dom_code),
41 static_cast<int>(dom_code), event_flags));
42 EXPECT_EQ(result.defined, success);
43 if (success) {
44 EXPECT_EQ(result.dom_key, result_dom_key)
45 << "Expected '"
46 << ui::KeycodeConverter::DomKeyToKeyString(result.dom_key)
47 << "' Actual '"
48 << ui::KeycodeConverter::DomKeyToKeyString(result_dom_key) << "'";
49 EXPECT_EQ(result.key_code, result_key_code);
50 } else {
51 // Should not have touched output parameters.
52 EXPECT_EQ(ui::DomKey::NONE, result_dom_key);
53 EXPECT_EQ(ui::VKEY_UNKNOWN, result_key_code);
57 TEST(KeyboardCodeConversion, ControlCharacters) {
58 // The codes in this table are handled by |DomCodeToControlCharacter()|.
59 static const struct {
60 ui::DomCode dom_code;
61 Meaning control;
62 Meaning control_shift;
63 } kControlCharacters[] = {
64 {ui::DomCode::KEY_A,
65 {true, ui::DomKey::Constant<0x01>::Character, ui::VKEY_A},
66 {true, ui::DomKey::Constant<0x01>::Character, ui::VKEY_A}},
67 {ui::DomCode::KEY_B,
68 {true, ui::DomKey::Constant<0x02>::Character, ui::VKEY_B},
69 {true, ui::DomKey::Constant<0x02>::Character, ui::VKEY_B}},
70 {ui::DomCode::KEY_C,
71 {true, ui::DomKey::Constant<0x03>::Character, ui::VKEY_C},
72 {true, ui::DomKey::Constant<0x03>::Character, ui::VKEY_C}},
73 {ui::DomCode::KEY_D,
74 {true, ui::DomKey::Constant<0x04>::Character, ui::VKEY_D},
75 {true, ui::DomKey::Constant<0x04>::Character, ui::VKEY_D}},
76 {ui::DomCode::KEY_E,
77 {true, ui::DomKey::Constant<0x05>::Character, ui::VKEY_E},
78 {true, ui::DomKey::Constant<0x05>::Character, ui::VKEY_E}},
79 {ui::DomCode::KEY_F,
80 {true, ui::DomKey::Constant<0x06>::Character, ui::VKEY_F},
81 {true, ui::DomKey::Constant<0x06>::Character, ui::VKEY_F}},
82 {ui::DomCode::KEY_G,
83 {true, ui::DomKey::Constant<0x07>::Character, ui::VKEY_G},
84 {true, ui::DomKey::Constant<0x07>::Character, ui::VKEY_G}},
85 {ui::DomCode::KEY_H,
86 {true, ui::DomKey::BACKSPACE, ui::VKEY_BACK},
87 {true, ui::DomKey::BACKSPACE, ui::VKEY_BACK}},
88 {ui::DomCode::KEY_I,
89 {true, ui::DomKey::TAB, ui::VKEY_TAB},
90 {true, ui::DomKey::TAB, ui::VKEY_TAB}},
91 {ui::DomCode::KEY_J,
92 {true, ui::DomKey::Constant<0x0A>::Character, ui::VKEY_J},
93 {true, ui::DomKey::Constant<0x0A>::Character, ui::VKEY_J}},
94 {ui::DomCode::KEY_K,
95 {true, ui::DomKey::Constant<0x0B>::Character, ui::VKEY_K},
96 {true, ui::DomKey::Constant<0x0B>::Character, ui::VKEY_K}},
97 {ui::DomCode::KEY_L,
98 {true, ui::DomKey::Constant<0x0C>::Character, ui::VKEY_L},
99 {true, ui::DomKey::Constant<0x0C>::Character, ui::VKEY_L}},
100 {ui::DomCode::KEY_M,
101 {true, ui::DomKey::ENTER, ui::VKEY_RETURN},
102 {true, ui::DomKey::ENTER, ui::VKEY_RETURN}},
103 {ui::DomCode::KEY_N,
104 {true, ui::DomKey::Constant<0x0E>::Character, ui::VKEY_N},
105 {true, ui::DomKey::Constant<0x0E>::Character, ui::VKEY_N}},
106 {ui::DomCode::KEY_O,
107 {true, ui::DomKey::Constant<0x0F>::Character, ui::VKEY_O},
108 {true, ui::DomKey::Constant<0x0F>::Character, ui::VKEY_O}},
109 {ui::DomCode::KEY_P,
110 {true, ui::DomKey::Constant<0x10>::Character, ui::VKEY_P},
111 {true, ui::DomKey::Constant<0x10>::Character, ui::VKEY_P}},
112 {ui::DomCode::KEY_Q,
113 {true, ui::DomKey::Constant<0x11>::Character, ui::VKEY_Q},
114 {true, ui::DomKey::Constant<0x11>::Character, ui::VKEY_Q}},
115 {ui::DomCode::KEY_R,
116 {true, ui::DomKey::Constant<0x12>::Character, ui::VKEY_R},
117 {true, ui::DomKey::Constant<0x12>::Character, ui::VKEY_R}},
118 {ui::DomCode::KEY_S,
119 {true, ui::DomKey::Constant<0x13>::Character, ui::VKEY_S},
120 {true, ui::DomKey::Constant<0x13>::Character, ui::VKEY_S}},
121 {ui::DomCode::KEY_T,
122 {true, ui::DomKey::Constant<0x14>::Character, ui::VKEY_T},
123 {true, ui::DomKey::Constant<0x14>::Character, ui::VKEY_T}},
124 {ui::DomCode::KEY_U,
125 {true, ui::DomKey::Constant<0x15>::Character, ui::VKEY_U},
126 {true, ui::DomKey::Constant<0x15>::Character, ui::VKEY_U}},
127 {ui::DomCode::KEY_V,
128 {true, ui::DomKey::Constant<0x16>::Character, ui::VKEY_V},
129 {true, ui::DomKey::Constant<0x16>::Character, ui::VKEY_V}},
130 {ui::DomCode::KEY_W,
131 {true, ui::DomKey::Constant<0x17>::Character, ui::VKEY_W},
132 {true, ui::DomKey::Constant<0x17>::Character, ui::VKEY_W}},
133 {ui::DomCode::KEY_X,
134 {true, ui::DomKey::Constant<0x18>::Character, ui::VKEY_X},
135 {true, ui::DomKey::Constant<0x18>::Character, ui::VKEY_X}},
136 {ui::DomCode::KEY_Y,
137 {true, ui::DomKey::Constant<0x19>::Character, ui::VKEY_Y},
138 {true, ui::DomKey::Constant<0x19>::Character, ui::VKEY_Y}},
139 {ui::DomCode::KEY_Z,
140 {true, ui::DomKey::Constant<0x1A>::Character, ui::VKEY_Z},
141 {true, ui::DomKey::Constant<0x1A>::Character, ui::VKEY_Z}},
143 for (const auto& it : kControlCharacters) {
144 // Verify |DomCodeToControlCharacter()|.
145 CheckDomCodeToMeaning("c_cc_n", ui::DomCodeToControlCharacter, it.dom_code,
146 ui::EF_NONE, kUndefined);
147 CheckDomCodeToMeaning("c_cc_c", ui::DomCodeToControlCharacter, it.dom_code,
148 ui::EF_CONTROL_DOWN, it.control);
149 CheckDomCodeToMeaning("c_cc_cs", ui::DomCodeToControlCharacter, it.dom_code,
150 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN,
151 it.control_shift);
152 // Verify |DomCodeToUsLayoutDomKey()|.
153 CheckDomCodeToMeaning("c_us_c", ui::DomCodeToUsLayoutDomKey, it.dom_code,
154 ui::EF_CONTROL_DOWN, it.control);
155 CheckDomCodeToMeaning("c_us_cs", ui::DomCodeToUsLayoutDomKey, it.dom_code,
156 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN,
157 it.control_shift);
160 // The codes in this table are sensitive to the Shift state, so they are
161 // handled differently by |DomCodeToControlCharacter()|, which returns false
162 // for unknown combinations, vs |DomCodeToUsLayoutDomKey()|, which returns
163 // true with DomKey::UNIDENTIFIED.
164 static const struct {
165 ui::DomCode dom_code;
166 Meaning cc_control;
167 Meaning cc_control_shift;
168 Meaning us_control;
169 Meaning us_control_shift;
170 } kShiftControlCharacters[] = {
171 {ui::DomCode::DIGIT2,
172 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
173 {true, ui::DomKey::Constant<0>::Character, ui::VKEY_2},
174 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_2},
175 {true, ui::DomKey::Constant<0>::Character, ui::VKEY_2}},
176 {ui::DomCode::DIGIT6,
177 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
178 {true, ui::DomKey::Constant<0x1E>::Character, ui::VKEY_6},
179 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_6},
180 {true, ui::DomKey::Constant<0x1E>::Character, ui::VKEY_6}},
181 {ui::DomCode::MINUS,
182 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
183 {true, ui::DomKey::Constant<0x1F>::Character, ui::VKEY_OEM_MINUS},
184 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_OEM_MINUS},
185 {true, ui::DomKey::Constant<0x1F>::Character, ui::VKEY_OEM_MINUS}},
186 {ui::DomCode::ENTER,
187 {true, ui::DomKey::Constant<0x0A>::Character, ui::VKEY_RETURN},
188 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
189 {true, ui::DomKey::Constant<0x0A>::Character, ui::VKEY_RETURN},
190 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_RETURN}},
191 {ui::DomCode::BRACKET_LEFT,
192 {true, ui::DomKey::ESCAPE, ui::VKEY_OEM_4},
193 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
194 {true, ui::DomKey::ESCAPE, ui::VKEY_OEM_4},
195 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_OEM_4}},
196 {ui::DomCode::BACKSLASH,
197 {true, ui::DomKey::Constant<0x1C>::Character, ui::VKEY_OEM_5},
198 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
199 {true, ui::DomKey::Constant<0x1C>::Character, ui::VKEY_OEM_5},
200 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_OEM_5}},
201 {ui::DomCode::BRACKET_RIGHT,
202 {true, ui::DomKey::Constant<0x1D>::Character, ui::VKEY_OEM_6},
203 {false, ui::DomKey::NONE, ui::VKEY_UNKNOWN},
204 {true, ui::DomKey::Constant<0x1D>::Character, ui::VKEY_OEM_6},
205 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_OEM_6}},
207 for (const auto& it : kShiftControlCharacters) {
208 // Verify |DomCodeToControlCharacter()|.
209 CheckDomCodeToMeaning("s_cc_n", ui::DomCodeToControlCharacter, it.dom_code,
210 ui::EF_NONE, kUndefined);
211 CheckDomCodeToMeaning("s_cc_c", ui::DomCodeToControlCharacter, it.dom_code,
212 ui::EF_CONTROL_DOWN, it.cc_control);
213 CheckDomCodeToMeaning("s_cc_cs", ui::DomCodeToControlCharacter, it.dom_code,
214 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN,
215 it.cc_control_shift);
216 // Verify |DomCodeToUsLayoutDomKey()|.
217 CheckDomCodeToMeaning("s_us_c", ui::DomCodeToUsLayoutDomKey, it.dom_code,
218 ui::EF_CONTROL_DOWN, it.us_control);
219 CheckDomCodeToMeaning("s_us_cs", ui::DomCodeToUsLayoutDomKey, it.dom_code,
220 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN,
221 it.us_control_shift);
224 // These codes are not handled by |DomCodeToControlCharacter()| directly.
225 static const struct {
226 ui::DomCode dom_code;
227 Meaning normal;
228 Meaning control;
229 } kNonControlCharacters[] = {
230 // Modifiers are handled by |DomCodeToUsLayoutDomKey()| without regard
231 // to whether Control is down.
232 {ui::DomCode::CONTROL_LEFT,
233 {true, ui::DomKey::CONTROL, ui::VKEY_CONTROL},
234 {true, ui::DomKey::CONTROL, ui::VKEY_CONTROL}},
235 {ui::DomCode::CONTROL_RIGHT,
236 {true, ui::DomKey::CONTROL, ui::VKEY_CONTROL},
237 {true, ui::DomKey::CONTROL, ui::VKEY_CONTROL}},
238 {ui::DomCode::SHIFT_LEFT,
239 {true, ui::DomKey::SHIFT, ui::VKEY_SHIFT},
240 {true, ui::DomKey::SHIFT, ui::VKEY_SHIFT}},
241 {ui::DomCode::SHIFT_RIGHT,
242 {true, ui::DomKey::SHIFT, ui::VKEY_SHIFT},
243 {true, ui::DomKey::SHIFT, ui::VKEY_SHIFT}},
244 {ui::DomCode::ALT_LEFT,
245 {true, ui::DomKey::ALT, ui::VKEY_MENU},
246 {true, ui::DomKey::ALT, ui::VKEY_MENU}},
247 {ui::DomCode::ALT_RIGHT,
248 {true, ui::DomKey::ALT, ui::VKEY_MENU},
249 {true, ui::DomKey::ALT, ui::VKEY_MENU}},
250 {ui::DomCode::OS_LEFT,
251 {true, ui::DomKey::OS, ui::VKEY_LWIN},
252 {true, ui::DomKey::OS, ui::VKEY_LWIN}},
253 {ui::DomCode::OS_RIGHT,
254 {true, ui::DomKey::OS, ui::VKEY_LWIN},
255 {true, ui::DomKey::OS, ui::VKEY_LWIN}},
256 // Non-modifiers (a representative sample here) succeed with
257 // DomKey::UNIDENTIFIED when Control is down.
258 {ui::DomCode::DIGIT1,
259 {true, ui::DomKey::Constant<'1'>::Character, ui::VKEY_1},
260 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_1}},
261 {ui::DomCode::EQUAL,
262 {true, ui::DomKey::Constant<'='>::Character, ui::VKEY_OEM_PLUS},
263 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_OEM_PLUS}},
264 {ui::DomCode::TAB,
265 {true, ui::DomKey::TAB, ui::VKEY_TAB},
266 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_TAB}},
267 {ui::DomCode::F1,
268 {true, ui::DomKey::F1, ui::VKEY_F1},
269 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_F1}},
270 {ui::DomCode::VOLUME_UP,
271 {true, ui::DomKey::VOLUME_UP, ui::VKEY_VOLUME_UP},
272 {true, ui::DomKey::UNIDENTIFIED, ui::VKEY_VOLUME_UP}},
274 for (const auto& it : kNonControlCharacters) {
275 // Verify |DomCodeToControlCharacter()|.
276 CheckDomCodeToMeaning("n_cc_n", ui::DomCodeToControlCharacter, it.dom_code,
277 ui::EF_NONE, kUndefined);
278 CheckDomCodeToMeaning("n_cc_c", ui::DomCodeToControlCharacter, it.dom_code,
279 ui::EF_CONTROL_DOWN, kUndefined);
280 CheckDomCodeToMeaning("n_cc_cs", ui::DomCodeToControlCharacter, it.dom_code,
281 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, kUndefined);
282 // Verify |DomCodeToUsLayoutDomKey()|.
283 CheckDomCodeToMeaning("n_us_n", ui::DomCodeToUsLayoutDomKey, it.dom_code,
284 ui::EF_NONE, it.normal);
285 CheckDomCodeToMeaning("n_us_c", ui::DomCodeToUsLayoutDomKey, it.dom_code,
286 ui::EF_CONTROL_DOWN, it.control);
287 CheckDomCodeToMeaning("n_us_cs", ui::DomCodeToUsLayoutDomKey, it.dom_code,
288 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, it.control);
292 TEST(KeyboardCodeConversion, UsLayout) {
293 static const struct {
294 ui::DomCode dom_code;
295 Meaning normal;
296 Meaning shift;
297 } kPrintableUsLayout[] = {
298 {ui::DomCode::KEY_A,
299 {true, ui::DomKey::Constant<'a'>::Character, ui::VKEY_A},
300 {true, ui::DomKey::Constant<'A'>::Character, ui::VKEY_A}},
301 {ui::DomCode::KEY_B,
302 {true, ui::DomKey::Constant<'b'>::Character, ui::VKEY_B},
303 {true, ui::DomKey::Constant<'B'>::Character, ui::VKEY_B}},
304 {ui::DomCode::KEY_C,
305 {true, ui::DomKey::Constant<'c'>::Character, ui::VKEY_C},
306 {true, ui::DomKey::Constant<'C'>::Character, ui::VKEY_C}},
307 {ui::DomCode::KEY_D,
308 {true, ui::DomKey::Constant<'d'>::Character, ui::VKEY_D},
309 {true, ui::DomKey::Constant<'D'>::Character, ui::VKEY_D}},
310 {ui::DomCode::KEY_E,
311 {true, ui::DomKey::Constant<'e'>::Character, ui::VKEY_E},
312 {true, ui::DomKey::Constant<'E'>::Character, ui::VKEY_E}},
313 {ui::DomCode::KEY_F,
314 {true, ui::DomKey::Constant<'f'>::Character, ui::VKEY_F},
315 {true, ui::DomKey::Constant<'F'>::Character, ui::VKEY_F}},
316 {ui::DomCode::KEY_G,
317 {true, ui::DomKey::Constant<'g'>::Character, ui::VKEY_G},
318 {true, ui::DomKey::Constant<'G'>::Character, ui::VKEY_G}},
319 {ui::DomCode::KEY_H,
320 {true, ui::DomKey::Constant<'h'>::Character, ui::VKEY_H},
321 {true, ui::DomKey::Constant<'H'>::Character, ui::VKEY_H}},
322 {ui::DomCode::KEY_I,
323 {true, ui::DomKey::Constant<'i'>::Character, ui::VKEY_I},
324 {true, ui::DomKey::Constant<'I'>::Character, ui::VKEY_I}},
325 {ui::DomCode::KEY_J,
326 {true, ui::DomKey::Constant<'j'>::Character, ui::VKEY_J},
327 {true, ui::DomKey::Constant<'J'>::Character, ui::VKEY_J}},
328 {ui::DomCode::KEY_K,
329 {true, ui::DomKey::Constant<'k'>::Character, ui::VKEY_K},
330 {true, ui::DomKey::Constant<'K'>::Character, ui::VKEY_K}},
331 {ui::DomCode::KEY_L,
332 {true, ui::DomKey::Constant<'l'>::Character, ui::VKEY_L},
333 {true, ui::DomKey::Constant<'L'>::Character, ui::VKEY_L}},
334 {ui::DomCode::KEY_M,
335 {true, ui::DomKey::Constant<'m'>::Character, ui::VKEY_M},
336 {true, ui::DomKey::Constant<'M'>::Character, ui::VKEY_M}},
337 {ui::DomCode::KEY_N,
338 {true, ui::DomKey::Constant<'n'>::Character, ui::VKEY_N},
339 {true, ui::DomKey::Constant<'N'>::Character, ui::VKEY_N}},
340 {ui::DomCode::KEY_O,
341 {true, ui::DomKey::Constant<'o'>::Character, ui::VKEY_O},
342 {true, ui::DomKey::Constant<'O'>::Character, ui::VKEY_O}},
343 {ui::DomCode::KEY_P,
344 {true, ui::DomKey::Constant<'p'>::Character, ui::VKEY_P},
345 {true, ui::DomKey::Constant<'P'>::Character, ui::VKEY_P}},
346 {ui::DomCode::KEY_Q,
347 {true, ui::DomKey::Constant<'q'>::Character, ui::VKEY_Q},
348 {true, ui::DomKey::Constant<'Q'>::Character, ui::VKEY_Q}},
349 {ui::DomCode::KEY_R,
350 {true, ui::DomKey::Constant<'r'>::Character, ui::VKEY_R},
351 {true, ui::DomKey::Constant<'R'>::Character, ui::VKEY_R}},
352 {ui::DomCode::KEY_S,
353 {true, ui::DomKey::Constant<'s'>::Character, ui::VKEY_S},
354 {true, ui::DomKey::Constant<'S'>::Character, ui::VKEY_S}},
355 {ui::DomCode::KEY_T,
356 {true, ui::DomKey::Constant<'t'>::Character, ui::VKEY_T},
357 {true, ui::DomKey::Constant<'T'>::Character, ui::VKEY_T}},
358 {ui::DomCode::KEY_U,
359 {true, ui::DomKey::Constant<'u'>::Character, ui::VKEY_U},
360 {true, ui::DomKey::Constant<'U'>::Character, ui::VKEY_U}},
361 {ui::DomCode::KEY_V,
362 {true, ui::DomKey::Constant<'v'>::Character, ui::VKEY_V},
363 {true, ui::DomKey::Constant<'V'>::Character, ui::VKEY_V}},
364 {ui::DomCode::KEY_W,
365 {true, ui::DomKey::Constant<'w'>::Character, ui::VKEY_W},
366 {true, ui::DomKey::Constant<'W'>::Character, ui::VKEY_W}},
367 {ui::DomCode::KEY_X,
368 {true, ui::DomKey::Constant<'x'>::Character, ui::VKEY_X},
369 {true, ui::DomKey::Constant<'X'>::Character, ui::VKEY_X}},
370 {ui::DomCode::KEY_Y,
371 {true, ui::DomKey::Constant<'y'>::Character, ui::VKEY_Y},
372 {true, ui::DomKey::Constant<'Y'>::Character, ui::VKEY_Y}},
373 {ui::DomCode::KEY_Z,
374 {true, ui::DomKey::Constant<'z'>::Character, ui::VKEY_Z},
375 {true, ui::DomKey::Constant<'Z'>::Character, ui::VKEY_Z}},
376 {ui::DomCode::DIGIT1,
377 {true, ui::DomKey::Constant<'1'>::Character, ui::VKEY_1},
378 {true, ui::DomKey::Constant<'!'>::Character, ui::VKEY_1}},
379 {ui::DomCode::DIGIT2,
380 {true, ui::DomKey::Constant<'2'>::Character, ui::VKEY_2},
381 {true, ui::DomKey::Constant<'@'>::Character, ui::VKEY_2}},
382 {ui::DomCode::DIGIT3,
383 {true, ui::DomKey::Constant<'3'>::Character, ui::VKEY_3},
384 {true, ui::DomKey::Constant<'#'>::Character, ui::VKEY_3}},
385 {ui::DomCode::DIGIT4,
386 {true, ui::DomKey::Constant<'4'>::Character, ui::VKEY_4},
387 {true, ui::DomKey::Constant<'$'>::Character, ui::VKEY_4}},
388 {ui::DomCode::DIGIT5,
389 {true, ui::DomKey::Constant<'5'>::Character, ui::VKEY_5},
390 {true, ui::DomKey::Constant<'%'>::Character, ui::VKEY_5}},
391 {ui::DomCode::DIGIT6,
392 {true, ui::DomKey::Constant<'6'>::Character, ui::VKEY_6},
393 {true, ui::DomKey::Constant<'^'>::Character, ui::VKEY_6}},
394 {ui::DomCode::DIGIT7,
395 {true, ui::DomKey::Constant<'7'>::Character, ui::VKEY_7},
396 {true, ui::DomKey::Constant<'&'>::Character, ui::VKEY_7}},
397 {ui::DomCode::DIGIT8,
398 {true, ui::DomKey::Constant<'8'>::Character, ui::VKEY_8},
399 {true, ui::DomKey::Constant<'*'>::Character, ui::VKEY_8}},
400 {ui::DomCode::DIGIT9,
401 {true, ui::DomKey::Constant<'9'>::Character, ui::VKEY_9},
402 {true, ui::DomKey::Constant<'('>::Character, ui::VKEY_9}},
403 {ui::DomCode::DIGIT0,
404 {true, ui::DomKey::Constant<'0'>::Character, ui::VKEY_0},
405 {true, ui::DomKey::Constant<')'>::Character, ui::VKEY_0}},
406 {ui::DomCode::SPACE,
407 {true, ui::DomKey::Constant<' '>::Character, ui::VKEY_SPACE},
408 {true, ui::DomKey::Constant<' '>::Character, ui::VKEY_SPACE}},
409 {ui::DomCode::MINUS,
410 {true, ui::DomKey::Constant<'-'>::Character, ui::VKEY_OEM_MINUS},
411 {true, ui::DomKey::Constant<'_'>::Character, ui::VKEY_OEM_MINUS}},
412 {ui::DomCode::EQUAL,
413 {true, ui::DomKey::Constant<'='>::Character, ui::VKEY_OEM_PLUS},
414 {true, ui::DomKey::Constant<'+'>::Character, ui::VKEY_OEM_PLUS}},
415 {ui::DomCode::BRACKET_LEFT,
416 {true, ui::DomKey::Constant<'['>::Character, ui::VKEY_OEM_4},
417 {true, ui::DomKey::Constant<'{'>::Character, ui::VKEY_OEM_4}},
418 {ui::DomCode::BRACKET_RIGHT,
419 {true, ui::DomKey::Constant<']'>::Character, ui::VKEY_OEM_6},
420 {true, ui::DomKey::Constant<'}'>::Character, ui::VKEY_OEM_6}},
421 {ui::DomCode::BACKSLASH,
422 {true, ui::DomKey::Constant<'\\'>::Character, ui::VKEY_OEM_5},
423 {true, ui::DomKey::Constant<'|'>::Character, ui::VKEY_OEM_5}},
424 {ui::DomCode::SEMICOLON,
425 {true, ui::DomKey::Constant<';'>::Character, ui::VKEY_OEM_1},
426 {true, ui::DomKey::Constant<':'>::Character, ui::VKEY_OEM_1}},
427 {ui::DomCode::QUOTE,
428 {true, ui::DomKey::Constant<'\''>::Character, ui::VKEY_OEM_7},
429 {true, ui::DomKey::Constant<'"'>::Character, ui::VKEY_OEM_7}},
430 {ui::DomCode::BACKQUOTE,
431 {true, ui::DomKey::Constant<'`'>::Character, ui::VKEY_OEM_3},
432 {true, ui::DomKey::Constant<'~'>::Character, ui::VKEY_OEM_3}},
433 {ui::DomCode::COMMA,
434 {true, ui::DomKey::Constant<','>::Character, ui::VKEY_OEM_COMMA},
435 {true, ui::DomKey::Constant<'<'>::Character, ui::VKEY_OEM_COMMA}},
436 {ui::DomCode::PERIOD,
437 {true, ui::DomKey::Constant<'.'>::Character, ui::VKEY_OEM_PERIOD},
438 {true, ui::DomKey::Constant<'>'>::Character, ui::VKEY_OEM_PERIOD}},
439 {ui::DomCode::SLASH,
440 {true, ui::DomKey::Constant<'/'>::Character, ui::VKEY_OEM_2},
441 {true, ui::DomKey::Constant<'?'>::Character, ui::VKEY_OEM_2}},
442 {ui::DomCode::INTL_BACKSLASH,
443 {true, ui::DomKey::Constant<'<'>::Character, ui::VKEY_OEM_102},
444 {true, ui::DomKey::Constant<'>'>::Character, ui::VKEY_OEM_102}},
445 {ui::DomCode::INTL_YEN,
446 {true, ui::DomKey::Constant<0x00A5>::Character, ui::VKEY_OEM_5},
447 {true, ui::DomKey::Constant<'|'>::Character, ui::VKEY_OEM_5}},
448 {ui::DomCode::NUMPAD_DIVIDE,
449 {true, ui::DomKey::Constant<'/'>::Character, ui::VKEY_DIVIDE},
450 {true, ui::DomKey::Constant<'/'>::Character, ui::VKEY_DIVIDE}},
451 {ui::DomCode::NUMPAD_MULTIPLY,
452 {true, ui::DomKey::Constant<'*'>::Character, ui::VKEY_MULTIPLY},
453 {true, ui::DomKey::Constant<'*'>::Character, ui::VKEY_MULTIPLY}},
454 {ui::DomCode::NUMPAD_SUBTRACT,
455 {true, ui::DomKey::Constant<'-'>::Character, ui::VKEY_SUBTRACT},
456 {true, ui::DomKey::Constant<'-'>::Character, ui::VKEY_SUBTRACT}},
457 {ui::DomCode::NUMPAD_ADD,
458 {true, ui::DomKey::Constant<'+'>::Character, ui::VKEY_ADD},
459 {true, ui::DomKey::Constant<'+'>::Character, ui::VKEY_ADD}},
460 {ui::DomCode::NUMPAD1,
461 {true, ui::DomKey::Constant<'1'>::Character, ui::VKEY_1},
462 {true, ui::DomKey::Constant<'1'>::Character, ui::VKEY_1}},
463 {ui::DomCode::NUMPAD2,
464 {true, ui::DomKey::Constant<'2'>::Character, ui::VKEY_2},
465 {true, ui::DomKey::Constant<'2'>::Character, ui::VKEY_2}},
466 {ui::DomCode::NUMPAD3,
467 {true, ui::DomKey::Constant<'3'>::Character, ui::VKEY_3},
468 {true, ui::DomKey::Constant<'3'>::Character, ui::VKEY_3}},
469 {ui::DomCode::NUMPAD4,
470 {true, ui::DomKey::Constant<'4'>::Character, ui::VKEY_4},
471 {true, ui::DomKey::Constant<'4'>::Character, ui::VKEY_4}},
472 {ui::DomCode::NUMPAD5,
473 {true, ui::DomKey::Constant<'5'>::Character, ui::VKEY_5},
474 {true, ui::DomKey::Constant<'5'>::Character, ui::VKEY_5}},
475 {ui::DomCode::NUMPAD6,
476 {true, ui::DomKey::Constant<'6'>::Character, ui::VKEY_6},
477 {true, ui::DomKey::Constant<'6'>::Character, ui::VKEY_6}},
478 {ui::DomCode::NUMPAD7,
479 {true, ui::DomKey::Constant<'7'>::Character, ui::VKEY_7},
480 {true, ui::DomKey::Constant<'7'>::Character, ui::VKEY_7}},
481 {ui::DomCode::NUMPAD8,
482 {true, ui::DomKey::Constant<'8'>::Character, ui::VKEY_8},
483 {true, ui::DomKey::Constant<'8'>::Character, ui::VKEY_8}},
484 {ui::DomCode::NUMPAD9,
485 {true, ui::DomKey::Constant<'9'>::Character, ui::VKEY_9},
486 {true, ui::DomKey::Constant<'9'>::Character, ui::VKEY_9}},
487 {ui::DomCode::NUMPAD0,
488 {true, ui::DomKey::Constant<'0'>::Character, ui::VKEY_0},
489 {true, ui::DomKey::Constant<'0'>::Character, ui::VKEY_0}},
490 {ui::DomCode::NUMPAD_DECIMAL,
491 {true, ui::DomKey::Constant<'.'>::Character, ui::VKEY_DECIMAL},
492 {true, ui::DomKey::Constant<'.'>::Character, ui::VKEY_DECIMAL}},
493 {ui::DomCode::NUMPAD_EQUAL,
494 {true, ui::DomKey::Constant<'='>::Character, ui::VKEY_UNKNOWN},
495 {true, ui::DomKey::Constant<'='>::Character, ui::VKEY_UNKNOWN}},
496 {ui::DomCode::NUMPAD_COMMA,
497 {true, ui::DomKey::Constant<','>::Character, ui::VKEY_OEM_COMMA},
498 {true, ui::DomKey::Constant<','>::Character, ui::VKEY_OEM_COMMA}},
499 {ui::DomCode::NUMPAD_PAREN_LEFT,
500 {true, ui::DomKey::Constant<'('>::Character, ui::VKEY_UNKNOWN},
501 {true, ui::DomKey::Constant<'('>::Character, ui::VKEY_UNKNOWN}},
502 {ui::DomCode::NUMPAD_PAREN_RIGHT,
503 {true, ui::DomKey::Constant<')'>::Character, ui::VKEY_UNKNOWN},
504 {true, ui::DomKey::Constant<')'>::Character, ui::VKEY_UNKNOWN}},
505 {ui::DomCode::NUMPAD_SIGN_CHANGE,
506 {true, ui::DomKey::Constant<0xB1>::Character, ui::VKEY_UNKNOWN},
507 {true, ui::DomKey::Constant<0xB1>::Character, ui::VKEY_UNKNOWN}},
510 for (const auto& it : kPrintableUsLayout) {
511 CheckDomCodeToMeaning("p_us_n", ui::DomCodeToUsLayoutDomKey, it.dom_code,
512 ui::EF_NONE, it.normal);
513 CheckDomCodeToMeaning("p_us_s", ui::DomCodeToUsLayoutDomKey, it.dom_code,
514 ui::EF_SHIFT_DOWN, it.shift);
515 CheckDomCodeToMeaning("p_us_a", ui::DomCodeToUsLayoutDomKey, it.dom_code,
516 ui::EF_ALTGR_DOWN, it.normal);
517 CheckDomCodeToMeaning("p_us_a", ui::DomCodeToUsLayoutDomKey, it.dom_code,
518 ui::EF_ALTGR_DOWN|ui::EF_SHIFT_DOWN, it.shift);
522 TEST(KeyboardCodeConversion, Tables) {
523 // Verify that kDomCodeToKeyboardCodeMap is ordered by DomCode value.
524 uint32_t previous = 0;
525 for (const auto& it : ui::kDomCodeToKeyboardCodeMap) {
526 uint32_t current = static_cast<uint32_t>(it.dom_code);
527 EXPECT_LT(previous, current);
528 previous = current;
532 } // namespace