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

Side by Side Diff: ui/base/events/key_identifier_conversion_unittest.cc

Issue 16972006: Insert text directly from the virtual keyboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix include Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/events/key_identifier_conversion.cc ('k') | ui/keyboard/keyboard_ui_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/base/events/key_identifier_conversion.h"
6
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/events/event.h"
11 #include "ui/base/keycodes/keyboard_codes.h"
12
13 namespace ui {
14
15 TEST(KeyEventFromKeyIdentifierTest, MatchOnIdentifier) {
16 EXPECT_EQ(ui::VKEY_APPS, KeyEventFromKeyIdentifier("Apps").key_code());
17 EXPECT_EQ(ui::VKEY_UNKNOWN,
18 KeyEventFromKeyIdentifier("Nonsense").key_code());
19 }
20
21 TEST(KeyEventFromKeyIdentifierTest, MatchOnCharacter) {
22 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("a").key_code());
23 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("A").key_code());
24 EXPECT_EQ(ui::VKEY_OEM_PERIOD, KeyEventFromKeyIdentifier(">").key_code());
25
26 std::string non_printing_char(" ");
27 non_printing_char[0] = static_cast<char>(1);
28 EXPECT_EQ(ui::VKEY_UNKNOWN,
29 KeyEventFromKeyIdentifier(non_printing_char).key_code());
30 }
31
32 TEST(KeyEventFromKeyIdentifierTest, MatchOnUnicodeCodepoint) {
33 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0041").key_code());
34 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0061").key_code());
35 EXPECT_EQ(ui::VKEY_DELETE, KeyEventFromKeyIdentifier("U+007F").key_code());
36
37 // this one exists in the map, but has no valid ui::VKEY
38 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+030A").key_code());
39
40 // this one is not in the map
41 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+0001").key_code());
42 }
43
44 TEST(KeyEventFromKeyIdentifierTest, DoesNotMatchEmptyString) {
45 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("").key_code());
46 }
47
48 TEST(KeyEventFromKeyIdentifierTest, ShiftModifiersAreSet) {
49 EXPECT_EQ(0, KeyEventFromKeyIdentifier("1").flags());
50
51 const char* keys_with_shift[] = {
52 "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+",
53 "{", "}", "|", ":", "<", ">", "?", "\""
54 };
55 int kNumKeysWithShift = arraysize(keys_with_shift);
56
57 for (int i = 0; i < kNumKeysWithShift; ++i) {
58 EXPECT_EQ(ui::EF_SHIFT_DOWN,
59 KeyEventFromKeyIdentifier(keys_with_shift[i]).flags());
60 }
61 }
62
63 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/events/key_identifier_conversion.cc ('k') | ui/keyboard/keyboard_ui_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698