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

Side by Side Diff: ui/events/keycodes/dom/keycode_converter_unittest.cc

Issue 1284433002: Revise ui::DomKey to unify character and non-character codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsDead Created 5 years, 3 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/dom/keycode_converter.cc ('k') | ui/events/keycodes/dom_us_layout_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dom/keycode_converter.h" 5 #include "ui/events/keycodes/dom/keycode_converter.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 EXPECT_STREQ(entry->code, 124 EXPECT_STREQ(entry->code,
125 ui::KeycodeConverter::DomCodeToCodeString(code)); 125 ui::KeycodeConverter::DomCodeToCodeString(code));
126 } else { 126 } else {
127 EXPECT_EQ(static_cast<int>(ui::DomCode::NONE), 127 EXPECT_EQ(static_cast<int>(ui::DomCode::NONE),
128 static_cast<int>(code)); 128 static_cast<int>(code));
129 } 129 }
130 } 130 }
131 } 131 }
132 132
133 TEST(KeycodeConverter, DomKey) { 133 TEST(KeycodeConverter, DomKey) {
134 // Test invalid and unknown arguments to KeyStringToDomKey() 134 const struct {
135 EXPECT_EQ(ui::DomKey::NONE, ui::KeycodeConverter::KeyStringToDomKey(nullptr)); 135 ui::DomKey::Base key;
136 EXPECT_EQ(ui::DomKey::NONE, ui::KeycodeConverter::KeyStringToDomKey("-")); 136 bool is_character;
137 // Round-trip test DOM Level 3 .key strings. 137 bool is_dead;
138 bool test_to_string;
139 const char* const string;
140 } test_cases[] = {
141 // Invalid arguments to KeyStringToDomKey().
142 {ui::DomKey::NONE, false, false, false, nullptr},
143 {ui::DomKey::NONE, false, false, true, ""},
144 {ui::DomKey::NONE, false, false, false, "?!?"},
145 {ui::DomKey::NONE, false, false, false, "\x61\xCC\x81"},
146 // Some single Unicode characters.
147 {ui::DomKey::Constant<'-'>::Character, true, false, true, "-"},
148 {ui::DomKey::Constant<'A'>::Character, true, false, true, "A"},
149 {ui::DomKey::Constant<0xE1>::Character, true, false, true, "\xC3\xA1"},
150 {ui::DomKey::Constant<0x1F648>::Character, true, false, true,
151 "\xF0\x9F\x99\x88"},
152 // Unicode-equivalent named values.
153 {ui::DomKey::BACKSPACE, true, false, true, "Backspace"},
154 {ui::DomKey::TAB, true, false, true, "Tab"},
155 {ui::DomKey::ENTER, true, false, true, "Enter"},
156 {ui::DomKey::ESCAPE, true, false, true, "Escape"},
157 {ui::DomKey::DEL, true, false, true, "Delete"},
158 {ui::DomKey::BACKSPACE, true, false, false, "\b"},
159 {ui::DomKey::TAB, true, false, false, "\t"},
160 {ui::DomKey::ENTER, true, false, false, "\r"},
161 {ui::DomKey::ESCAPE, true, false, false, "\x1B"},
162 {ui::DomKey::DEL, true, false, false, "\x7F"},
163 {ui::DomKey::Constant<'\b'>::Character, true, false, true, "Backspace"},
164 {ui::DomKey::Constant<'\t'>::Character, true, false, true, "Tab"},
165 {ui::DomKey::Constant<'\r'>::Character, true, false, true, "Enter"},
166 {ui::DomKey::Constant<0x1B>::Character, true, false, true, "Escape"},
167 {ui::DomKey::Constant<0x7F>::Character, true, false, true, "Delete"},
168 // 'Dead' key.
169 {ui::DomKey::Constant<0xFFFF>::Dead, false, true, true, "Dead"},
170 // Sample non-Unicode key names.
171 {ui::DomKey::SHIFT, false, false, true, "Shift"},
172 {ui::DomKey::F16, false, false, true, "F16"},
173 {ui::DomKey::ZOOM_IN, false, false, true, "ZoomIn"},
174 {ui::DomKey::UNIDENTIFIED, false, false, true, "Unidentified"},
175 };
176 for (const auto& test : test_cases) {
177 // Check KeyStringToDomKey().
178 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(test.string);
179 EXPECT_EQ(test.is_character, key.IsCharacter());
180 EXPECT_EQ(test.is_dead, key.IsDeadKey());
181 EXPECT_EQ(test.key, key);
182 // Check |DomKeyToKeyString()|.
183 if (test.test_to_string) {
184 std::string s(ui::KeycodeConverter::DomKeyToKeyString(test.key));
185 EXPECT_STREQ(test.string, s.c_str());
186 }
187 }
188 // Round-trip test all UI Events KeyboardEvent.key strings.
138 const char* s = nullptr; 189 const char* s = nullptr;
139 for (size_t i = 0; 190 for (size_t i = 0;
140 (s = ui::KeycodeConverter::DomKeyStringForTest(i)) != nullptr; 191 (s = ui::KeycodeConverter::DomKeyStringForTest(i)) != nullptr; ++i) {
141 ++i) {
142 SCOPED_TRACE(i); 192 SCOPED_TRACE(i);
143 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s); 193 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s);
144 if (s) { 194 if (s) {
145 EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key)); 195 EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key).c_str());
146 } else { 196 } else {
147 EXPECT_EQ(ui::DomKey::NONE, key); 197 EXPECT_EQ(ui::DomKey::NONE, key);
148 } 198 }
149 } 199 }
150 } 200 }
151 201
152 } // namespace 202 } // namespace
OLDNEW
« no previous file with comments | « ui/events/keycodes/dom/keycode_converter.cc ('k') | ui/events/keycodes/dom_us_layout_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698