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

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

Issue 1585193002: Build key map DomCodeToKey() for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest Created 4 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/events/keycodes/platform_key_map_win.h"
6
7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/events/keycodes/dom/dom_code.h"
11 #include "ui/events/keycodes/dom/dom_key.h"
12 #include "ui/events/keycodes/dom/keycode_converter.h"
13
14 namespace ui {
15
16 namespace {
17
18 const wchar_t* LAYOUT_US = L"00000409";
19 const wchar_t* LAYOUT_FR = L"0000040c";
20
21 struct TestKey {
22 // Have to use KeyboardCode instead of DomCode because we don't know the
23 // physical keyboard layout for try bots.
24 KeyboardCode vk;
25 const char* normal;
26 const char* shift;
27 const char* capslock;
28 const char* altgr;
29 const char* shift_capslock;
30 const char* shift_altgr;
31 const char* altgr_capslock;
32 };
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
67
68 class PlatformKeyMapTest : public testing::Test {
69 public:
70 PlatformKeyMapTest() {}
71 ~PlatformKeyMapTest() override {}
72 private:
73 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMapTest);
74 };
75
76 TEST_F(PlatformKeyMapTest, USLayout) {
77 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0);
78 PlatformKeyMap keymap(layout);
79
80 const TestKey USKeys[] = {
81 // n s c a sc sa ac
82 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"},
83 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"},
84 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"},
85 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"},
86 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"},
87 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"},
88 {VKEY_6, "6", "^", "6", "6", "^", "^", "6"},
89 {VKEY_7, "7", "&", "7", "7", "&", "&", "7"},
90 {VKEY_8, "8", "*", "8", "8", "*", "*", "8"},
91 {VKEY_9, "9", "(", "9", "9", "(", "(", "9"},
92 {VKEY_A, "a", "A", "A", "a", "a", "A", "A"},
93 {VKEY_B, "b", "B", "B", "b", "b", "B", "B"},
94 {VKEY_C, "c", "C", "C", "c", "c", "C", "C"},
95 {VKEY_D, "d", "D", "D", "d", "d", "D", "D"},
96 {VKEY_E, "e", "E", "E", "e", "e", "E", "E"},
97 {VKEY_F, "f", "F", "F", "f", "f", "F", "F"},
98 {VKEY_G, "g", "G", "G", "g", "g", "G", "G"},
99 {VKEY_H, "h", "H", "H", "h", "h", "H", "H"},
100 {VKEY_I, "i", "I", "I", "i", "i", "I", "I"},
101 {VKEY_J, "j", "J", "J", "j", "j", "J", "J"},
102 {VKEY_K, "k", "K", "K", "k", "k", "K", "K"},
103 {VKEY_L, "l", "L", "L", "l", "l", "L", "L"},
104 {VKEY_M, "m", "M", "M", "m", "m", "M", "M"},
105 {VKEY_N, "n", "N", "N", "n", "n", "N", "N"},
106 {VKEY_O, "o", "O", "O", "o", "o", "O", "O"},
107 {VKEY_P, "p", "P", "P", "p", "p", "P", "P"},
108 {VKEY_Q, "q", "Q", "Q", "q", "q", "Q", "Q"},
109 {VKEY_R, "r", "R", "R", "r", "r", "R", "R"},
110 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"},
111 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"},
112 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"},
113 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"},
114 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"},
115 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"},
116 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
117 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
118 };
119
120 for (const auto& k : USKeys) {
121 CheckDomCodeToKeyString("USLayout", keymap, k, layout);
122 }
123 }
124
125 TEST_F(PlatformKeyMapTest, FRLayout) {
126 HKL layout = ::LoadKeyboardLayout(LAYOUT_FR, 0);
127 PlatformKeyMap keymap(layout);
128
129 const TestKey FRKeys[] = {
130 // n s c a sc sa ac
131 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"},
132 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"},
133 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"},
134 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"},
135 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"},
136 {VKEY_5, "(", "5", "5", "[", "(", "5", "["},
137 {VKEY_6, "-", "6", "6", "|", "-", "6", "|"},
138 {VKEY_7, "è", "7", "7", "Dead", "è", "7", "Dead"},
139 {VKEY_8, "_", "8", "8", "\\", "_", "8", "\\"},
140 {VKEY_9, "ç", "9", "9", "^", "ç", "9", "^"},
141 {VKEY_A, "a", "A", "A", "a", "a", "A", "A"},
142 {VKEY_B, "b", "B", "B", "b", "b", "B", "B"},
143 {VKEY_C, "c", "C", "C", "c", "c", "C", "C"},
144 {VKEY_D, "d", "D", "D", "d", "d", "D", "D"},
145 {VKEY_E, "e", "E", "E", "€", "e", "E", "€"},
146 {VKEY_F, "f", "F", "F", "f", "f", "F", "F"},
147 {VKEY_G, "g", "G", "G", "g", "g", "G", "G"},
148 {VKEY_H, "h", "H", "H", "h", "h", "H", "H"},
149 {VKEY_I, "i", "I", "I", "i", "i", "I", "I"},
150 {VKEY_J, "j", "J", "J", "j", "j", "J", "J"},
151 {VKEY_K, "k", "K", "K", "k", "k", "K", "K"},
152 {VKEY_L, "l", "L", "L", "l", "l", "L", "L"},
153 {VKEY_M, "m", "M", "M", "m", "m", "M", "M"},
154 {VKEY_N, "n", "N", "N", "n", "n", "N", "N"},
155 {VKEY_O, "o", "O", "O", "o", "o", "O", "O"},
156 {VKEY_P, "p", "P", "P", "p", "p", "P", "P"},
157 {VKEY_Q, "q", "Q", "Q", "q", "q", "Q", "Q"},
158 {VKEY_R, "r", "R", "R", "r", "r", "R", "R"},
159 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"},
160 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"},
161 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"},
162 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"},
163 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"},
164 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"},
165 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
166 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
167 };
168
169 for (const auto& k : FRKeys) {
170 CheckDomCodeToKeyString("FRLayout", keymap, k, layout);
171 }
172 }
173
174 } // 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