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::DeadKeyFromCombiningCharacter(combining_character), |
| 38 EventTimeForNow()); |
38 return event; | 39 return event; |
39 } | 40 } |
40 | 41 |
41 // Expects key is filtered and no character is composed. | 42 // Expects key is filtered and no character is composed. |
42 void ExpectDeadKeyFiltered(base::char16 combining_character) { | 43 void ExpectDeadKeyFiltered(base::char16 combining_character) { |
43 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); | 44 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); |
44 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); | 45 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); |
45 EXPECT_TRUE(character_composer_.composed_character().empty()); | 46 EXPECT_TRUE(character_composer_.composed_character().empty()); |
46 } | 47 } |
47 | 48 |
48 // Expects key is filtered and the given character is composed. | 49 // Expects key is filtered and the given character is composed. |
49 void ExpectDeadKeyComposed(base::char16 combining_character, | 50 void ExpectDeadKeyComposed(base::char16 combining_character, |
50 const base::string16& expected_character) { | 51 const base::string16& expected_character) { |
51 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); | 52 scoped_ptr<KeyEvent> event(DeadKeyPress(combining_character)); |
52 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); | 53 EXPECT_TRUE(character_composer_.FilterKeyPress(*event)); |
53 EXPECT_EQ(expected_character, character_composer_.composed_character()); | 54 EXPECT_EQ(expected_character, character_composer_.composed_character()); |
54 } | 55 } |
55 | 56 |
56 // Returns a |KeyEvent| for a character key press. | 57 // Returns a |KeyEvent| for a character key press. |
57 KeyEvent* UnicodeKeyPress(KeyboardCode vkey, | 58 KeyEvent* UnicodeKeyPress(KeyboardCode vkey, |
58 DomCode code, | 59 DomCode code, |
59 int flags, | 60 int flags, |
60 base::char16 character) const { | 61 base::char16 character) const { |
61 KeyEvent* event = new KeyEvent(ET_KEY_PRESSED, vkey, code, flags, | 62 KeyEvent* event = new KeyEvent(ET_KEY_PRESSED, vkey, code, flags, |
62 CharacterToDomKey(character), character, | 63 DomKey::FromCharacter(character), |
63 EventTimeForNow()); | 64 EventTimeForNow()); |
64 return event; | 65 return event; |
65 } | 66 } |
66 | 67 |
67 // Expects key is not filtered and no character is composed. | 68 // Expects key is not filtered and no character is composed. |
68 void ExpectUnicodeKeyNotFiltered(KeyboardCode vkey, | 69 void ExpectUnicodeKeyNotFiltered(KeyboardCode vkey, |
69 DomCode code, | 70 DomCode code, |
70 int flags, | 71 int flags, |
71 base::char16 character) { | 72 base::char16 character) { |
72 scoped_ptr<KeyEvent> event(UnicodeKeyPress(vkey, code, flags, character)); | 73 scoped_ptr<KeyEvent> event(UnicodeKeyPress(vkey, code, flags, character)); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 ExpectUnicodeKeyFiltered(VKEY_3, DomCode::DIGIT3, EF_NONE, '3'); | 502 ExpectUnicodeKeyFiltered(VKEY_3, DomCode::DIGIT3, EF_NONE, '3'); |
502 ExpectUnicodeKeyFiltered(VKEY_0, DomCode::DIGIT0, EF_NONE, '0'); | 503 ExpectUnicodeKeyFiltered(VKEY_0, DomCode::DIGIT0, EF_NONE, '0'); |
503 ExpectDeadKeyFiltered(kCombiningAcute); | 504 ExpectDeadKeyFiltered(kCombiningAcute); |
504 ExpectUnicodeKeyFiltered(VKEY_4, DomCode::DIGIT4, EF_NONE, '4'); | 505 ExpectUnicodeKeyFiltered(VKEY_4, DomCode::DIGIT4, EF_NONE, '4'); |
505 ExpectUnicodeKeyFiltered(VKEY_2, DomCode::DIGIT2, EF_NONE, '2'); | 506 ExpectUnicodeKeyFiltered(VKEY_2, DomCode::DIGIT2, EF_NONE, '2'); |
506 ExpectUnicodeKeyComposed(VKEY_SPACE, DomCode::SPACE, EF_NONE, ' ', | 507 ExpectUnicodeKeyComposed(VKEY_SPACE, DomCode::SPACE, EF_NONE, ' ', |
507 base::string16(1, 0x3042)); | 508 base::string16(1, 0x3042)); |
508 } | 509 } |
509 | 510 |
510 } // namespace ui | 511 } // namespace ui |
OLD | NEW |