Chromium Code Reviews| 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 "ui/base/keycodes/keyboard_code_conversion.h" | 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 "chrome/browser/browser_thread.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 6 #include "ui/base/keycodes/keyboard_codes.h" | 12 #include "ui/base/keycodes/keyboard_codes.h" |
| 7 #include "base/logging.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | 13 |
| 10 namespace ui { | 14 namespace { |
| 11 | 15 |
| 12 TEST(KeyCodeFromKeyIdentifierTest, MatchOnIdentifier) { | 16 class KeyEventFromKeyIdentifierTest : public testing::Test { |
| 13 EXPECT_EQ(VKEY_APPS, KeyCodeFromKeyIdentifier("Apps")); | 17 protected: |
| 14 EXPECT_EQ(VKEY_UNKNOWN, KeyCodeFromKeyIdentifier("Nonsense")); | 18 KeyEventFromKeyIdentifierTest() |
| 19 : ui_thread_(BrowserThread::UI, &message_loop_) {} | |
| 20 | |
| 21 MessageLoopForUI message_loop_; | |
| 22 BrowserThread ui_thread_; | |
| 23 }; | |
| 24 | |
| 25 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnIdentifier) { | |
| 26 EXPECT_EQ(ui::VKEY_APPS, KeyEventFromKeyIdentifier("Apps").GetKeyCode()); | |
| 27 EXPECT_EQ(ui::VKEY_UNKNOWN, | |
| 28 KeyEventFromKeyIdentifier("Nonsense").GetKeyCode()); | |
| 15 } | 29 } |
| 16 | 30 |
| 17 TEST(KeyCodeFromKeyIdentifierTest, MatchOnCharacter) { | 31 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnCharacter) { |
| 18 EXPECT_EQ(VKEY_A, KeyCodeFromKeyIdentifier("a")); | 32 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("a").GetKeyCode()); |
| 19 EXPECT_EQ(VKEY_A, KeyCodeFromKeyIdentifier("A")); | 33 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("A").GetKeyCode()); |
| 20 EXPECT_EQ(VKEY_OEM_PERIOD, KeyCodeFromKeyIdentifier(">")); | 34 EXPECT_EQ(ui::VKEY_OEM_PERIOD, KeyEventFromKeyIdentifier(">").GetKeyCode()); |
| 21 | 35 |
| 22 std::string non_printing_char(" "); | 36 std::string non_printing_char(" "); |
| 23 non_printing_char[0] = static_cast<char>(1); | 37 non_printing_char[0] = static_cast<char>(1); |
| 24 EXPECT_EQ(VKEY_UNKNOWN, KeyCodeFromKeyIdentifier(non_printing_char)); | 38 EXPECT_EQ(ui::VKEY_UNKNOWN, |
| 39 KeyEventFromKeyIdentifier(non_printing_char).GetKeyCode()); | |
| 25 } | 40 } |
| 26 | 41 |
| 27 TEST(KeyCodeFromKeyIdentifierTest, MatchOnUnicodeCodepoint) { | 42 TEST_F(KeyEventFromKeyIdentifierTest, MatchOnUnicodeCodepoint) { |
| 28 EXPECT_EQ(VKEY_A, KeyCodeFromKeyIdentifier("U+0041")); | 43 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0041").GetKeyCode()); |
| 29 EXPECT_EQ(VKEY_A, KeyCodeFromKeyIdentifier("U+0061")); | 44 EXPECT_EQ(ui::VKEY_A, KeyEventFromKeyIdentifier("U+0061").GetKeyCode()); |
| 30 EXPECT_EQ(VKEY_DELETE, KeyCodeFromKeyIdentifier("U+007F")); | 45 EXPECT_EQ(ui::VKEY_DELETE, KeyEventFromKeyIdentifier("U+007F").GetKeyCode()); |
| 31 | 46 |
| 32 // this one exists in the map, but has no valid VKEY | 47 // this one exists in the map, but has no valid ui::VKEY |
| 33 EXPECT_EQ(VKEY_UNKNOWN, KeyCodeFromKeyIdentifier("U+030A")); | 48 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+030A").GetKeyCode()); |
| 34 | 49 |
| 35 // this one is not in the map | 50 // this one is not in the map |
| 36 EXPECT_EQ(VKEY_UNKNOWN, KeyCodeFromKeyIdentifier("U+0001")); | 51 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("U+0001").GetKeyCode()); |
| 37 } | 52 } |
| 38 | 53 |
| 39 TEST(KeyCodeFromKeyIdentifierTest, DoesNotMatchEmptyString) { | 54 TEST_F(KeyEventFromKeyIdentifierTest, DoesNotMatchEmptyString) { |
| 40 EXPECT_EQ(VKEY_UNKNOWN, KeyCodeFromKeyIdentifier("")); | 55 EXPECT_EQ(ui::VKEY_UNKNOWN, KeyEventFromKeyIdentifier("").GetKeyCode()); |
| 41 } | 56 } |
| 42 | 57 |
| 43 } // namespace ui | 58 TEST_F(KeyEventFromKeyIdentifierTest, ModifiersAreSetCorrectly) { |
| 59 EXPECT_EQ(0, KeyEventFromKeyIdentifier("1").GetFlags()); | |
| 60 EXPECT_EQ(views::Event::EF_SHIFT_DOWN, | |
|
Erik does not do reviews
2011/01/31 06:28:35
isn't this exact case also tested in the next test
bryeung
2011/02/02 20:56:44
This was testing both set and unset. I've moved t
| |
| 61 KeyEventFromKeyIdentifier("!").GetFlags()); | |
| 62 } | |
| 63 | |
| 64 TEST_F(KeyEventFromKeyIdentifierTest, ShiftModifiersAreSet) { | |
|
Erik does not do reviews
2011/01/31 06:28:35
should there be a similar control modifier test?
bryeung
2011/02/02 20:56:44
Currently we don't have any identifiers returning
| |
| 65 const char* keys_with_shift[] = { | |
| 66 "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", | |
| 67 "{", "}", "|", ":", "<", ">", "?", "\"" | |
| 68 }; | |
| 69 int kNumKeysWithShift = arraysize(keys_with_shift); | |
| 70 | |
| 71 for (int i = 0; i < kNumKeysWithShift; ++i) { | |
| 72 EXPECT_EQ(views::Event::EF_SHIFT_DOWN, | |
| 73 KeyEventFromKeyIdentifier(keys_with_shift[i]).GetFlags()); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 } // namespace | |
| OLD | NEW |