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

Side by Side Diff: chrome/browser/extensions/key_identifier_conversion_views_unittest.cc

Issue 13957005: Move KeyIdentifier->KeyEvent conversion to src/ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gyp fix Created 7 years, 8 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
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 "chrome/browser/extensions/key_identifier_conversion_views.h"
6
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "base/message_loop.h"
10 #include "content/public/test/test_browser_thread.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/events/event.h"
13 #include "ui/base/keycodes/keyboard_codes.h"
14
15 using content::BrowserThread;
16
17 namespace {
18
19 class KeyEventFromKeyIdentifierTest : public testing::Test {
20 protected:
21 KeyEventFromKeyIdentifierTest()
22 : ui_thread_(BrowserThread::UI, &message_loop_) {}
23
24 MessageLoopForUI message_loop_;
25 content::TestBrowserThread ui_thread_;
26 };
27
28 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnIdentifier) {
29 EXPECT_EQ(ui::VKEY_APPS, KeyEventFromKeyIdentifier("Apps").key_code());
30 EXPECT_EQ(ui::VKEY_UNKNOWN,
31 KeyEventFromKeyIdentifier("Nonsense").key_code());
32 }
33
34 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnCharacter) {
35 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("a").key_code());
36 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("A").key_code());
37 EXPECT_EQ(ui::VKEY_OEM_PERIOD, KeyEventFromKeyIdentifier(">").key_code());
38
39 std::string non_printing_char(" ");
40 non_printing_char[0] = static_cast<char>(1);
41 EXPECT_EQ(ui::VKEY_UNKNOWN,
42 KeyEventFromKeyIdentifier(non_printing_char).key_code());
43 }
44
45 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnUnicodeCodepoint) {
46 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0041").key_code());
47 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0061").key_code());
48 EXPECT_EQ(ui::VKEY_DELETE, KeyEventFromKeyIdentifier("U+007F").key_code());
49
50 // this one exists in the map, but has no valid ui::VKEY
51 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+030A").key_code());
52
53 // this one is not in the map
54 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+0001").key_code());
55 }
56
57 TEST_F(KeyEventFromKeyIdentifierTest, DoesNotMatchEmptyString) {
58 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("").key_code());
59 }
60
61 TEST_F(KeyEventFromKeyIdentifierTest, ShiftModifiersAreSet) {
62 EXPECT_EQ(0, KeyEventFromKeyIdentifier("1").flags());
63
64 const char* keys_with_shift[] = {
65 "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+",
66 "{", "}", "|", ":", "<", ">", "?", "\""
67 };
68 int kNumKeysWithShift = arraysize(keys_with_shift);
69
70 for (int i = 0; i < kNumKeysWithShift; ++i) {
71 EXPECT_EQ(ui::EF_SHIFT_DOWN,
72 KeyEventFromKeyIdentifier(keys_with_shift[i]).flags());
73 }
74 }
75
76 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/key_identifier_conversion_views.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698