OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/extensions/key_identifier_conversion_views.h" | 5 #include "ui/base/events/key_identifier_conversion.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.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" | 9 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/base/events/event.h" | 10 #include "ui/base/events/event.h" |
13 #include "ui/base/keycodes/keyboard_codes.h" | 11 #include "ui/base/keycodes/keyboard_codes.h" |
14 | 12 |
15 using content::BrowserThread; | 13 namespace ui { |
16 | 14 |
17 namespace { | 15 TEST(KeyEventFromKeyIdentifierTest, MatchOnIdentifier) { |
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()); | 16 EXPECT_EQ(ui::VKEY_APPS, KeyEventFromKeyIdentifier("Apps").key_code()); |
30 EXPECT_EQ(ui::VKEY_UNKNOWN, | 17 EXPECT_EQ(ui::VKEY_UNKNOWN, |
31 KeyEventFromKeyIdentifier("Nonsense").key_code()); | 18 KeyEventFromKeyIdentifier("Nonsense").key_code()); |
32 } | 19 } |
33 | 20 |
34 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnCharacter) { | 21 TEST(KeyEventFromKeyIdentifierTest, MatchOnCharacter) { |
35 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("a").key_code()); | 22 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("a").key_code()); |
36 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("A").key_code()); | 23 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("A").key_code()); |
37 EXPECT_EQ(ui::VKEY_OEM_PERIOD, KeyEventFromKeyIdentifier(">").key_code()); | 24 EXPECT_EQ(ui::VKEY_OEM_PERIOD, KeyEventFromKeyIdentifier(">").key_code()); |
38 | 25 |
39 std::string non_printing_char(" "); | 26 std::string non_printing_char(" "); |
40 non_printing_char[0] = static_cast<char>(1); | 27 non_printing_char[0] = static_cast<char>(1); |
41 EXPECT_EQ(ui::VKEY_UNKNOWN, | 28 EXPECT_EQ(ui::VKEY_UNKNOWN, |
42 KeyEventFromKeyIdentifier(non_printing_char).key_code()); | 29 KeyEventFromKeyIdentifier(non_printing_char).key_code()); |
43 } | 30 } |
44 | 31 |
45 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnUnicodeCodepoint) { | 32 TEST(KeyEventFromKeyIdentifierTest, MatchOnUnicodeCodepoint) { |
46 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0041").key_code()); | 33 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0041").key_code()); |
47 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0061").key_code()); | 34 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0061").key_code()); |
48 EXPECT_EQ(ui::VKEY_DELETE, KeyEventFromKeyIdentifier("U+007F").key_code()); | 35 EXPECT_EQ(ui::VKEY_DELETE, KeyEventFromKeyIdentifier("U+007F").key_code()); |
49 | 36 |
50 // this one exists in the map, but has no valid ui::VKEY | 37 // this one exists in the map, but has no valid ui::VKEY |
51 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+030A").key_code()); | 38 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+030A").key_code()); |
52 | 39 |
53 // this one is not in the map | 40 // this one is not in the map |
54 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+0001").key_code()); | 41 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+0001").key_code()); |
55 } | 42 } |
56 | 43 |
57 TEST_F(KeyEventFromKeyIdentifierTest, DoesNotMatchEmptyString) { | 44 TEST(KeyEventFromKeyIdentifierTest, DoesNotMatchEmptyString) { |
58 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("").key_code()); | 45 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("").key_code()); |
59 } | 46 } |
60 | 47 |
61 TEST_F(KeyEventFromKeyIdentifierTest, ShiftModifiersAreSet) { | 48 TEST(KeyEventFromKeyIdentifierTest, ShiftModifiersAreSet) { |
62 EXPECT_EQ(0, KeyEventFromKeyIdentifier("1").flags()); | 49 EXPECT_EQ(0, KeyEventFromKeyIdentifier("1").flags()); |
63 | 50 |
64 const char* keys_with_shift[] = { | 51 const char* keys_with_shift[] = { |
65 "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", | 52 "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", |
66 "{", "}", "|", ":", "<", ">", "?", "\"" | 53 "{", "}", "|", ":", "<", ">", "?", "\"" |
67 }; | 54 }; |
68 int kNumKeysWithShift = arraysize(keys_with_shift); | 55 int kNumKeysWithShift = arraysize(keys_with_shift); |
69 | 56 |
70 for (int i = 0; i < kNumKeysWithShift; ++i) { | 57 for (int i = 0; i < kNumKeysWithShift; ++i) { |
71 EXPECT_EQ(ui::EF_SHIFT_DOWN, | 58 EXPECT_EQ(ui::EF_SHIFT_DOWN, |
72 KeyEventFromKeyIdentifier(keys_with_shift[i]).flags()); | 59 KeyEventFromKeyIdentifier(keys_with_shift[i]).flags()); |
73 } | 60 } |
74 } | 61 } |
75 | 62 |
76 } // namespace | 63 } // namespace ui |
OLD | NEW |