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

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

Issue 1585193002: Build key map DomCodeToKey() for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dtapuska's review, added more tests, handles non-printable key combination 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/keyboard_lookup_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_key.h"
11 #include "ui/events/keycodes/dom/keycode_converter.h"
12 #include "ui/events/keycodes/keyboard_codes_win.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 KeyboardCode vk;
23 const char* basic;
24 const char* shift;
25 const char* capslock;
26 const char* altgr;
27 const char* shift_capslock;
28 const char* shift_altgr;
29 const char* altgr_capslock;
30 };
31
32 void CheckVirtualKeyToDomKeyString(const char* label,
33 const WindowsKeyboardLookup &lookup,
34 const TestKey &t) {
35 EXPECT_STREQ(t.basic, KeycodeConverter::DomKeyToKeyString(
36 lookup.VirtualKeyToDomKey(t.vk, EF_NONE)).c_str()
37 ) << label;
38 EXPECT_STREQ(t.shift, KeycodeConverter::DomKeyToKeyString(
39 lookup.VirtualKeyToDomKey(t.vk, EF_SHIFT_DOWN)).c_str()
40 ) << label;
41 EXPECT_STREQ(t.capslock, KeycodeConverter::DomKeyToKeyString(
42 lookup.VirtualKeyToDomKey(t.vk, EF_CAPS_LOCK_ON)).c_str()
43 ) << label;
44 EXPECT_STREQ(t.altgr, KeycodeConverter::DomKeyToKeyString(
45 lookup.VirtualKeyToDomKey(t.vk, EF_ALTGR_DOWN)).c_str()
46 ) << label;
47 EXPECT_STREQ(t.shift_capslock, KeycodeConverter::DomKeyToKeyString(
48 lookup.VirtualKeyToDomKey(t.vk, EF_SHIFT_DOWN | EF_CAPS_LOCK_ON)).c_str()
49 ) << label;
50 EXPECT_STREQ(t.shift_altgr, KeycodeConverter::DomKeyToKeyString(
51 lookup.VirtualKeyToDomKey(t.vk, EF_SHIFT_DOWN | EF_ALTGR_DOWN)).c_str()
52 ) << label;
53 EXPECT_STREQ(t.altgr_capslock, KeycodeConverter::DomKeyToKeyString(
54 lookup.VirtualKeyToDomKey(t.vk, EF_ALTGR_DOWN | EF_CAPS_LOCK_ON)).c_str()
55 ) << label;
56 }
57
58 } // anonymous namespace
59
60 class WindowsKeyboardLookupTest : public testing::Test {
61 public:
62 WindowsKeyboardLookupTest() {}
63 ~WindowsKeyboardLookupTest() override {}
64
65 void SetUp() override {}
66
67 private:
68 DISALLOW_COPY_AND_ASSIGN(WindowsKeyboardLookupTest);
69 };
70
71 TEST_F(WindowsKeyboardLookupTest, USLayout) {
72 HKL layout = ::LoadKeyboardLayout(LAYOUT_US, 0);
73 WindowsKeyboardLookup lookup = WindowsKeyboardLookup(layout);
74
75 const TestKey USKeys[] = {
76 // b s c a sc sa ac
77 {VKEY_0, "0", ")", "0", "0", ")", ")", "0"},
78 {VKEY_1, "1", "!", "1", "1", "!", "!", "1"},
79 {VKEY_2, "2", "@", "2", "2", "@", "@", "2"},
80 {VKEY_3, "3", "#", "3", "3", "#", "#", "3"},
81 {VKEY_4, "4", "$", "4", "4", "$", "$", "4"},
82 {VKEY_5, "5", "%", "5", "5", "%", "%", "5"},
83 {VKEY_6, "6", "^", "6", "6", "^", "^", "6"},
84 {VKEY_7, "7", "&", "7", "7", "&", "&", "7"},
85 {VKEY_8, "8", "*", "8", "8", "*", "*", "8"},
86 {VKEY_9, "9", "(", "9", "9", "(", "(", "9"},
87 {VKEY_A, "a", "A", "A", "a", "a", "A", "A"},
88 {VKEY_B, "b", "B", "B", "b", "b", "B", "B"},
89 {VKEY_C, "c", "C", "C", "c", "c", "C", "C"},
90 {VKEY_D, "d", "D", "D", "d", "d", "D", "D"},
91 {VKEY_E, "e", "E", "E", "e", "e", "E", "E"},
92 {VKEY_F, "f", "F", "F", "f", "f", "F", "F"},
93 {VKEY_G, "g", "G", "G", "g", "g", "G", "G"},
94 {VKEY_H, "h", "H", "H", "h", "h", "H", "H"},
95 {VKEY_I, "i", "I", "I", "i", "i", "I", "I"},
96 {VKEY_J, "j", "J", "J", "j", "j", "J", "J"},
97 {VKEY_K, "k", "K", "K", "k", "k", "K", "K"},
98 {VKEY_L, "l", "L", "L", "l", "l", "L", "L"},
99 {VKEY_M, "m", "M", "M", "m", "m", "M", "M"},
100 {VKEY_N, "n", "N", "N", "n", "n", "N", "N"},
101 {VKEY_O, "o", "O", "O", "o", "o", "O", "O"},
102 {VKEY_P, "p", "P", "P", "p", "p", "P", "P"},
103 {VKEY_Q, "q", "Q", "Q", "q", "q", "Q", "Q"},
104 {VKEY_R, "r", "R", "R", "r", "r", "R", "R"},
105 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"},
106 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"},
107 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"},
108 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"},
109 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"},
110 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"},
111 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
112 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
113 };
114
115 for (const auto &k : USKeys) {
116 CheckVirtualKeyToDomKeyString("USLayout", lookup, k);
117 }
118 }
119
120 TEST_F(WindowsKeyboardLookupTest, FRLayout) {
121 HKL layout = ::LoadKeyboardLayout(LAYOUT_FR, 0);
122 WindowsKeyboardLookup lookup = WindowsKeyboardLookup(layout);
123
124 const TestKey FRKeys[] = {
125 // b s c a sc sa ac
126 {VKEY_0, "à", "0", "0", "@", "à", "0", "@"},
127 {VKEY_1, "&", "1", "1", "&", "&", "1", "1"},
128 {VKEY_2, "é", "2", "2", "Dead", "é", "2", "Dead"},
129 {VKEY_3, "\"", "3", "3", "#", "\"", "3", "#"},
130 {VKEY_4, "\'", "4", "4", "{", "\'", "4", "{"},
131 {VKEY_5, "(", "5", "5", "[", "(", "5", "["},
132 {VKEY_6, "-", "6", "6", "|", "-", "6", "|"},
133 {VKEY_7, "è", "7", "7", "Dead", "è", "7", "Dead"},
134 {VKEY_8, "_", "8", "8", "\\", "_", "8", "\\"},
135 {VKEY_9, "ç", "9", "9", "^", "ç", "9", "^"},
136 {VKEY_A, "a", "A", "A", "a", "a", "A", "A"},
137 {VKEY_B, "b", "B", "B", "b", "b", "B", "B"},
138 {VKEY_C, "c", "C", "C", "c", "c", "C", "C"},
139 {VKEY_D, "d", "D", "D", "d", "d", "D", "D"},
140 {VKEY_E, "e", "E", "E", "€", "e", "E", "€"},
141 {VKEY_F, "f", "F", "F", "f", "f", "F", "F"},
142 {VKEY_G, "g", "G", "G", "g", "g", "G", "G"},
143 {VKEY_H, "h", "H", "H", "h", "h", "H", "H"},
144 {VKEY_I, "i", "I", "I", "i", "i", "I", "I"},
145 {VKEY_J, "j", "J", "J", "j", "j", "J", "J"},
146 {VKEY_K, "k", "K", "K", "k", "k", "K", "K"},
147 {VKEY_L, "l", "L", "L", "l", "l", "L", "L"},
148 {VKEY_M, "m", "M", "M", "m", "m", "M", "M"},
149 {VKEY_N, "n", "N", "N", "n", "n", "N", "N"},
150 {VKEY_O, "o", "O", "O", "o", "o", "O", "O"},
151 {VKEY_P, "p", "P", "P", "p", "p", "P", "P"},
152 {VKEY_Q, "q", "Q", "Q", "q", "q", "Q", "Q"},
153 {VKEY_R, "r", "R", "R", "r", "r", "R", "R"},
154 {VKEY_S, "s", "S", "S", "s", "s", "S", "S"},
155 {VKEY_T, "t", "T", "T", "t", "t", "T", "T"},
156 {VKEY_U, "u", "U", "U", "u", "u", "U", "U"},
157 {VKEY_V, "v", "V", "V", "v", "v", "V", "V"},
158 {VKEY_W, "w", "W", "W", "w", "w", "W", "W"},
159 {VKEY_X, "x", "X", "X", "x", "x", "X", "X"},
160 {VKEY_Y, "y", "Y", "Y", "y", "y", "Y", "Y"},
161 {VKEY_Z, "z", "Z", "Z", "z", "z", "Z", "Z"},
162 };
163
164 for (const auto &k : FRKeys) {
165 CheckVirtualKeyToDomKeyString("FRLayout", lookup, k);
166 }
167 }
168
169 } // namespace ui
OLDNEW
« ui/events/keycodes/keyboard_lookup_win.cc ('K') | « ui/events/keycodes/keyboard_lookup_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698