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

Unified Diff: apps/moterm/key_util_unittest.cc

Issue 1130093003: Moterm part 4: Add input event -> input character conversion function. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « apps/moterm/key_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/moterm/key_util_unittest.cc
diff --git a/apps/moterm/key_util_unittest.cc b/apps/moterm/key_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..560ee71164d7668a8020debe74b41ea6c0860224
--- /dev/null
+++ b/apps/moterm/key_util_unittest.cc
@@ -0,0 +1,70 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/moterm/key_util.h"
+
+#include <string>
+
+#include "mojo/services/input_events/public/interfaces/input_events.mojom.h"
+#include "mojo/services/input_events/public/interfaces/input_key_codes.mojom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Makes a key event. Note that this cheats in a number of respects.
+// TODO(vtl): Add a |flags| argument when |GetInputSequenceForKeyPressedEvent()|
+// actually uses it.
+mojo::EventPtr MakeKeyEvent(bool is_char,
+ char character,
+ mojo::KeyboardCode windows_key_code) {
+ uint16_t character16 = static_cast<unsigned char>(character);
+
+ mojo::EventPtr ev = mojo::Event::New();
+ ev->action = mojo::EVENT_TYPE_KEY_PRESSED;
+ ev->flags = mojo::EVENT_FLAGS_NONE; // Cheat.
+ ev->time_stamp = 1234567890LL;
+ ev->key_data = mojo::KeyData::New();
+ ev->key_data->key_code = 0; // Cheat.
+ ev->key_data->is_char = is_char;
+ ev->key_data->character = character16;
+ ev->key_data->windows_key_code = windows_key_code;
+ ev->key_data->native_key_code = 0;
+ ev->key_data->text = character16; // Cheat.
+ ev->key_data->unmodified_text = character16; // Cheat.
+ return ev;
+}
+
+TEST(KeyUtilTest, RegularChars) {
+ // Only handles character events.
+ EXPECT_EQ(std::string(), GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(false, 0, mojo::KEYBOARD_CODE_A)));
+
+ EXPECT_EQ("A", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, 'A', mojo::KEYBOARD_CODE_A)));
+ EXPECT_EQ("a", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, 'a', mojo::KEYBOARD_CODE_A)));
+ EXPECT_EQ("0", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, '0', mojo::KEYBOARD_CODE_NUM_0)));
+ EXPECT_EQ("!", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, '!', mojo::KEYBOARD_CODE_NUM_0)));
+ EXPECT_EQ("\t", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, '\t', mojo::KEYBOARD_CODE_TAB)));
+ EXPECT_EQ("\r", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, '\r', mojo::KEYBOARD_CODE_RETURN)));
+}
+
+TEST(KeyUtilTest, SpecialChars) {
+ // Backspace should send DEL.
+ EXPECT_EQ("\x7f", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, 0, mojo::KEYBOARD_CODE_BACK)));
+ EXPECT_EQ("\x1b", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, 0, mojo::KEYBOARD_CODE_ESCAPE)));
+ // Some multi-character results:
+ EXPECT_EQ("\x1b[5~", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, 0, mojo::KEYBOARD_CODE_PRIOR)));
+ EXPECT_EQ("\x1b[C", GetInputSequenceForKeyPressedEvent(
+ *MakeKeyEvent(true, 0, mojo::KEYBOARD_CODE_RIGHT)));
+}
+
+} // namespace
« no previous file with comments | « apps/moterm/key_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698