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