Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: ui/base/ime/chromeos/character_composer_unittest.cc

Issue 1284433002: Revise ui::DomKey to unify character and non-character codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 DomKey::FromCharacter(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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 ExpectUnicodeKeyFiltered(VKEY_3, DomCode::DIGIT3, EF_NONE, '3'); 501 ExpectUnicodeKeyFiltered(VKEY_3, DomCode::DIGIT3, EF_NONE, '3');
502 ExpectUnicodeKeyFiltered(VKEY_0, DomCode::DIGIT0, EF_NONE, '0'); 502 ExpectUnicodeKeyFiltered(VKEY_0, DomCode::DIGIT0, EF_NONE, '0');
503 ExpectDeadKeyFiltered(kCombiningAcute); 503 ExpectDeadKeyFiltered(kCombiningAcute);
504 ExpectUnicodeKeyFiltered(VKEY_4, DomCode::DIGIT4, EF_NONE, '4'); 504 ExpectUnicodeKeyFiltered(VKEY_4, DomCode::DIGIT4, EF_NONE, '4');
505 ExpectUnicodeKeyFiltered(VKEY_2, DomCode::DIGIT2, EF_NONE, '2'); 505 ExpectUnicodeKeyFiltered(VKEY_2, DomCode::DIGIT2, EF_NONE, '2');
506 ExpectUnicodeKeyComposed(VKEY_SPACE, DomCode::SPACE, EF_NONE, ' ', 506 ExpectUnicodeKeyComposed(VKEY_SPACE, DomCode::SPACE, EF_NONE, ' ',
507 base::string16(1, 0x3042)); 507 base::string16(1, 0x3042));
508 } 508 }
509 509
510 } // namespace ui 510 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698