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

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: Created 5 years, 4 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
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (entry->code) { 123 if (entry->code) {
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) {
kpschoedel 2015/08/07 20:42:12 Added cases for Unicode characters.
134 // Test invalid and unknown arguments to KeyStringToDomKey() 134 static const struct {
135 EXPECT_EQ(ui::DomKey::NONE, ui::KeycodeConverter::KeyStringToDomKey(nullptr)); 135 ui::DomKey key;
136 EXPECT_EQ(ui::DomKey::NONE, ui::KeycodeConverter::KeyStringToDomKey("-")); 136 bool is_unicode;
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 {'-', true, false, true, "-" },
148 {'A', true, false, true, "A"},
149 {0xE1, true, false, true, "\xC3\xA1"},
150 {0x1F648, true, false, true, "\xF0\x9F\x99\x88"},
151 // Unicode-equivalent named values.
152 {ui::DomKey::BACKSPACE, true, false, true, "Backspace"},
153 {ui::DomKey::TAB, true, false, true, "Tab"},
154 {ui::DomKey::ENTER, true, false, true, "Enter"},
155 {ui::DomKey::ESCAPE, true, false, true, "Escape"},
156 {ui::DomKey::DEL, true, false, true, "Delete"},
157 {ui::DomKey::BACKSPACE, true, false, false, "\b"},
158 {ui::DomKey::TAB, true, false, false, "\t"},
159 {ui::DomKey::ENTER, true, false, false, "\r"},
160 {ui::DomKey::ESCAPE, true, false, false, "\x1B"},
161 {ui::DomKey::DEL, true, false, false, "\x7F"},
162 {'\b', true, false, true, "Backspace"},
163 {'\t', true, false, true, "Tab"},
164 {'\r', true, false, true, "Enter"},
165 {0x1B, true, false, true, "Escape"},
166 {0x7F, true, false, true, "Delete"},
167 // 'Dead' key.
168 {ui::DomKey::Dead(0xFFFF), false, true, true, "Dead"},
169 // Sample non-Unicode key names.
170 {ui::DomKey::SHIFT, false, false, true, "Shift"},
171 {ui::DomKey::F16, false, false, true, "F16"},
172 {ui::DomKey::ZOOM_IN, false, false, true, "ZoomIn"},
173 {ui::DomKey::UNIDENTIFIED, false, false, true, "Unidentified"},
174 };
175 for (const auto& test : test_cases) {
176 // Check KeyStringToDomKey().
177 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(test.string);
178 EXPECT_EQ(test.is_unicode, key.IsUnicode());
179 EXPECT_EQ(test.is_dead, key.IsDead());
180 EXPECT_EQ(test.key, key);
181 // Check |DomKeyToKeyString()|.
182 if (test.test_to_string) {
183 std::string s(ui::KeycodeConverter::DomKeyToKeyString(test.key));
184 EXPECT_STREQ(test.string, s.c_str());
185 }
186 }
187 // Round-trip test all UI Events KeyboardEvent.key strings.
138 const char* s = nullptr; 188 const char* s = nullptr;
139 for (size_t i = 0; 189 for (size_t i = 0;
140 (s = ui::KeycodeConverter::DomKeyStringForTest(i)) != nullptr; 190 (s = ui::KeycodeConverter::DomKeyStringForTest(i)) != nullptr; ++i) {
141 ++i) {
142 SCOPED_TRACE(i); 191 SCOPED_TRACE(i);
143 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s); 192 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s);
144 if (s) { 193 if (s) {
145 EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key)); 194 EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key).c_str());
146 } else { 195 } else {
147 EXPECT_EQ(ui::DomKey::NONE, key); 196 EXPECT_EQ(ui::DomKey::NONE, key);
148 } 197 }
149 } 198 }
150 } 199 }
151 200
152 } // namespace 201 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698