OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ime/chromeos/character_composer.h" | 5 #include "ui/base/ime/chromeos/character_composer.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const base::char16 kCombiningHorn = 0x031B; | 27 const base::char16 kCombiningHorn = 0x031B; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 class CharacterComposerTest : public testing::Test { | 31 class CharacterComposerTest : public testing::Test { |
32 protected: | 32 protected: |
33 // Returns a |KeyEvent| for a dead key press. | 33 // Returns a |KeyEvent| for a dead key press. |
34 KeyEvent* DeadKeyPress(base::char16 combining_character) const { | 34 KeyEvent* DeadKeyPress(base::char16 combining_character) const { |
35 KeyEvent* event = | 35 KeyEvent* event = |
36 new KeyEvent(ET_KEY_PRESSED, VKEY_UNKNOWN, DomCode::NONE, EF_NONE, | 36 new KeyEvent(ET_KEY_PRESSED, VKEY_UNKNOWN, DomCode::NONE, EF_NONE, |
37 DomKey::DEAD, combining_character, EventTimeForNow()); | 37 DomKey::Dead(combining_character), EventTimeForNow()); |
38 return event; | 38 return event; |
39 } | 39 } |
40 | 40 |
41 // Expects key is filtered and no character is composed. | 41 // Expects key is filtered and no character is composed. |
42 void ExpectDeadKeyFiltered(base::char16 combining_character) { | 42 void ExpectDeadKeyFiltered(base::char16 combining_character) { |
43 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); | 43 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); |
44 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); | 44 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); |
45 EXPECT_TRUE(character_composer_.composed_character().empty()); | 45 EXPECT_TRUE(character_composer_.composed_character().empty()); |
46 } | 46 } |
47 | 47 |
48 // Expects key is filtered and the given character is composed. | 48 // Expects key is filtered and the given character is composed. |
49 void ExpectDeadKeyComposed(base::char16 combining_character, | 49 void ExpectDeadKeyComposed(base::char16 combining_character, |
50 const base::string16& expected_character) { | 50 const base::string16& expected_character) { |
51 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); | 51 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); |
52 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); | 52 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); |
53 EXPECT_EQ(expected_character, character_composer_.composed_character()); | 53 EXPECT_EQ(expected_character, character_composer_.composed_character()); |
54 } | 54 } |
55 | 55 |
56 // Returns a |KeyEvent| for a character key press. | 56 // Returns a |KeyEvent| for a character key press. |
57 KeyEvent* UnicodeKeyPress(KeyboardCode vkey, | 57 KeyEvent* UnicodeKeyPress(KeyboardCode vkey, |
58 DomCode code, | 58 DomCode code, |
59 int flags, | 59 int flags, |
60 base::char16 character) const { | 60 base::char16 character) const { |
61 KeyEvent* event = new KeyEvent(ET_KEY_PRESSED, vkey, code, flags, | 61 KeyEvent* event = new KeyEvent(ET_KEY_PRESSED, vkey, code, flags, |
62 CharacterToDomKey(character), character, | 62 character, |
63 EventTimeForNow()); | 63 EventTimeForNow()); |
64 return event; | 64 return event; |
65 } | 65 } |
66 | 66 |
67 // Expects key is not filtered and no character is composed. | 67 // Expects key is not filtered and no character is composed. |
68 void ExpectUnicodeKeyNotFiltered(KeyboardCode vkey, | 68 void ExpectUnicodeKeyNotFiltered(KeyboardCode vkey, |
69 DomCode code, | 69 DomCode code, |
70 int flags, | 70 int flags, |
71 base::char16 character) { | 71 base::char16 character) { |
72 scoped_ptr<KeyEvent> event(UnicodeKeyPress(vkey, code, flags, character)); | 72 scoped_ptr<KeyEvent> event(UnicodeKeyPress(vkey, code, flags, character)); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 ExpectUnicodeKeyFiltered(VKEY_3, DomCode::DIGIT3, EF_NONE, '3'); | 497 ExpectUnicodeKeyFiltered(VKEY_3, DomCode::DIGIT3, EF_NONE, '3'); |
498 ExpectUnicodeKeyFiltered(VKEY_0, DomCode::DIGIT0, EF_NONE, '0'); | 498 ExpectUnicodeKeyFiltered(VKEY_0, DomCode::DIGIT0, EF_NONE, '0'); |
499 ExpectDeadKeyFiltered(kCombiningAcute); | 499 ExpectDeadKeyFiltered(kCombiningAcute); |
500 ExpectUnicodeKeyFiltered(VKEY_4, DomCode::DIGIT4, EF_NONE, '4'); | 500 ExpectUnicodeKeyFiltered(VKEY_4, DomCode::DIGIT4, EF_NONE, '4'); |
501 ExpectUnicodeKeyFiltered(VKEY_2, DomCode::DIGIT2, EF_NONE, '2'); | 501 ExpectUnicodeKeyFiltered(VKEY_2, DomCode::DIGIT2, EF_NONE, '2'); |
502 ExpectUnicodeKeyComposed(VKEY_SPACE, DomCode::SPACE, EF_NONE, ' ', | 502 ExpectUnicodeKeyComposed(VKEY_SPACE, DomCode::SPACE, EF_NONE, ' ', |
503 base::string16(1, 0x3042)); | 503 base::string16(1, 0x3042)); |
504 } | 504 } |
505 | 505 |
506 } // namespace ui | 506 } // namespace ui |
OLD | NEW |