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

Unified Diff: ui/events/keycodes/dom4/keycode_converter_unittest.cc

Issue 641753003: DOM Level 3 .code and .key value enumerations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add code for unicode keys Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ui/events/keycodes/dom4/keycode_converter_unittest.cc
diff --git a/ui/events/keycodes/dom4/keycode_converter_unittest.cc b/ui/events/keycodes/dom4/keycode_converter_unittest.cc
index 0b96583617b7c09d7867583991813043ccb5a081..ed5d04f540bd4a59408637864af1e029e08f679e 100644
--- a/ui/events/keycodes/dom4/keycode_converter_unittest.cc
+++ b/ui/events/keycodes/dom4/keycode_converter_unittest.cc
@@ -8,6 +8,8 @@
#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/keycodes/dom3/dom_code.h"
+#include "ui/events/keycodes/dom3/dom_key.h"
using ui::KeycodeConverter;
@@ -16,7 +18,7 @@ namespace {
#if defined(OS_WIN)
const size_t kExpectedMappedKeyCount = 138;
#elif defined(OS_LINUX)
-const size_t kExpectedMappedKeyCount = 145;
+const size_t kExpectedMappedKeyCount = 155;
#elif defined(OS_MACOSX)
const size_t kExpectedMappedKeyCount = 118;
#else
@@ -109,4 +111,47 @@ TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) {
ui::KeycodeConverter::UsbKeycodeToNativeKeycode(kUsbNonUsHash));
}
+TEST(KeycodeConverter, DomCode) {
+ // Test invalid and unknown arguments to CodeStringToDomCode()
+ EXPECT_EQ(ui::DomCode::NONE,
+ ui::KeycodeConverter::CodeStringToDomCode(nullptr));
+ EXPECT_EQ(ui::DomCode::NONE, ui::KeycodeConverter::CodeStringToDomCode("-"));
+ EXPECT_EQ(ui::DomCode::NONE, ui::KeycodeConverter::CodeStringToDomCode(""));
+ // Round-trip test DOM Level 3 .code strings.
+ const ui::KeycodeMapEntry* keycode_map =
+ ui::KeycodeConverter::GetKeycodeMapForTest();
+ size_t numEntries = ui::KeycodeConverter::NumKeycodeMapEntriesForTest();
+ for (size_t i = 0; i < numEntries; ++i) {
+ SCOPED_TRACE(i);
+ const ui::KeycodeMapEntry* entry = &keycode_map[i];
+ ui::DomCode code = ui::KeycodeConverter::CodeStringToDomCode(entry->code);
+ if (entry->code) {
+ EXPECT_STREQ(entry->code,
+ ui::KeycodeConverter::DomCodeToCodeString(code));
+ } else {
+ EXPECT_EQ(static_cast<int>(ui::DomCode::NONE),
+ static_cast<int>(code));
+ }
+ }
+}
+
+TEST(KeycodeConverter, DomKey) {
+ // Test invalid and unknown arguments to KeyStringToDomKey()
+ EXPECT_EQ(ui::DomKey::NONE, ui::KeycodeConverter::KeyStringToDomKey(nullptr));
+ EXPECT_EQ(ui::DomKey::NONE, ui::KeycodeConverter::KeyStringToDomKey("-"));
+ // Round-trip test DOM Level 3 .key strings.
+ const char* s = nullptr;
+ for (size_t i = 0;
+ (s = ui::KeycodeConverter::DomKeyStringForTest(i)) != nullptr;
+ ++i) {
+ SCOPED_TRACE(i);
+ ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s);
+ if (s) {
+ EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key));
+ } else {
+ EXPECT_EQ(ui::DomKey::NONE, key);
+ }
+ }
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698