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

Side by Side Diff: ui/base/ime/remote_input_method_win_unittest.cc

Issue 85063002: Add OnCompositionChanged and OnTextCommitted to RemoteInputMethodPrivateWin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « ui/base/ime/remote_input_method_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/remote_input_method_win.h" 5 #include "ui/base/ime/remote_input_method_win.h"
6 6
7 #include <InputScope.h> 7 #include <InputScope.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h" 12 #include "base/scoped_observer.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/ime/composition_text.h"
15 #include "ui/base/ime/dummy_text_input_client.h" 16 #include "ui/base/ime/dummy_text_input_client.h"
16 #include "ui/base/ime/input_method.h" 17 #include "ui/base/ime/input_method.h"
17 #include "ui/base/ime/input_method_delegate.h" 18 #include "ui/base/ime/input_method_delegate.h"
18 #include "ui/base/ime/input_method_observer.h" 19 #include "ui/base/ime/input_method_observer.h"
19 #include "ui/base/ime/remote_input_method_delegate_win.h" 20 #include "ui/base/ime/remote_input_method_delegate_win.h"
20 #include "ui/events/event.h" 21 #include "ui/events/event.h"
21 22
22 namespace ui { 23 namespace ui {
23 namespace { 24 namespace {
24 25
25 class MockTextInputClient : public DummyTextInputClient { 26 class MockTextInputClient : public DummyTextInputClient {
26 public: 27 public:
27 MockTextInputClient() 28 MockTextInputClient()
28 : text_input_type_(TEXT_INPUT_TYPE_NONE), 29 : text_input_type_(TEXT_INPUT_TYPE_NONE),
29 text_input_mode_(TEXT_INPUT_MODE_DEFAULT) { 30 text_input_mode_(TEXT_INPUT_MODE_DEFAULT),
31 call_count_set_composition_text_(0),
32 call_count_insert_char_(0),
33 call_count_insert_text_(0) {
30 } 34 }
31 35
36 size_t call_count_set_composition_text() const {
37 return call_count_set_composition_text_;
38 }
32 const base::string16& inserted_text() const { 39 const base::string16& inserted_text() const {
33 return inserted_text_; 40 return inserted_text_;
34 } 41 }
42 size_t call_count_insert_char() const {
43 return call_count_insert_char_;
44 }
45 size_t call_count_insert_text() const {
46 return call_count_insert_text_;
47 }
35 void Reset() { 48 void Reset() {
36 inserted_text_.clear();
37 text_input_type_ = TEXT_INPUT_TYPE_NONE; 49 text_input_type_ = TEXT_INPUT_TYPE_NONE;
38 text_input_mode_ = TEXT_INPUT_MODE_DEFAULT; 50 text_input_mode_ = TEXT_INPUT_MODE_DEFAULT;
51 call_count_set_composition_text_ = 0;
52 inserted_text_.clear();
53 call_count_insert_char_ = 0;
54 call_count_insert_text_ = 0;
39 caret_bounds_ = gfx::Rect(); 55 caret_bounds_ = gfx::Rect();
40 composition_character_bounds_.clear(); 56 composition_character_bounds_.clear();
41 } 57 }
42 void set_text_input_type(ui::TextInputType type) { 58 void set_text_input_type(ui::TextInputType type) {
43 text_input_type_ = type; 59 text_input_type_ = type;
44 } 60 }
45 void set_text_input_mode(ui::TextInputMode mode) { 61 void set_text_input_mode(ui::TextInputMode mode) {
46 text_input_mode_ = mode; 62 text_input_mode_ = mode;
47 } 63 }
48 void set_caret_bounds(const gfx::Rect& caret_bounds) { 64 void set_caret_bounds(const gfx::Rect& caret_bounds) {
49 caret_bounds_ = caret_bounds; 65 caret_bounds_ = caret_bounds;
50 } 66 }
51 void set_composition_character_bounds( 67 void set_composition_character_bounds(
52 const std::vector<gfx::Rect>& composition_character_bounds) { 68 const std::vector<gfx::Rect>& composition_character_bounds) {
53 composition_character_bounds_ = composition_character_bounds; 69 composition_character_bounds_ = composition_character_bounds;
54 } 70 }
55 71
56 private: 72 private:
73 // Overriden from DummyTextInputClient.
74 virtual void SetCompositionText(
75 const ui::CompositionText& composition) OVERRIDE {
76 ++call_count_set_composition_text_;
77 }
57 virtual void InsertChar(char16 ch, int flags) OVERRIDE{ 78 virtual void InsertChar(char16 ch, int flags) OVERRIDE{
58 inserted_text_.append(1, ch); 79 inserted_text_.append(1, ch);
80 ++call_count_insert_char_;
59 } 81 }
60 virtual void InsertText(const string16& text) OVERRIDE{ 82 virtual void InsertText(const string16& text) OVERRIDE{
61 EXPECT_TRUE(false) << "RemoteInputMethodWin does not use this method"; 83 inserted_text_.append(text);
84 ++call_count_insert_text_;
62 } 85 }
63 virtual ui::TextInputType GetTextInputType() const OVERRIDE { 86 virtual ui::TextInputType GetTextInputType() const OVERRIDE {
64 return text_input_type_; 87 return text_input_type_;
65 } 88 }
66 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE { 89 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE {
67 return text_input_mode_; 90 return text_input_mode_;
68 } 91 }
69 virtual gfx::Rect GetCaretBounds() const { 92 virtual gfx::Rect GetCaretBounds() const {
70 return caret_bounds_; 93 return caret_bounds_;
71 } 94 }
72 virtual bool GetCompositionCharacterBounds(uint32 index, 95 virtual bool GetCompositionCharacterBounds(uint32 index,
73 gfx::Rect* rect) const OVERRIDE { 96 gfx::Rect* rect) const OVERRIDE {
74 if (!rect || composition_character_bounds_.size() <= index) 97 if (!rect || composition_character_bounds_.size() <= index)
75 return false; 98 return false;
76 *rect = composition_character_bounds_[index]; 99 *rect = composition_character_bounds_[index];
77 return true; 100 return true;
78 } 101 }
79 virtual bool HasCompositionText() const OVERRIDE { 102 virtual bool HasCompositionText() const OVERRIDE {
80 return !composition_character_bounds_.empty(); 103 return !composition_character_bounds_.empty();
81 } 104 }
82 105
83 ui::TextInputType text_input_type_; 106 ui::TextInputType text_input_type_;
84 ui::TextInputMode text_input_mode_; 107 ui::TextInputMode text_input_mode_;
85 gfx::Rect caret_bounds_; 108 gfx::Rect caret_bounds_;
86 std::vector<gfx::Rect> composition_character_bounds_; 109 std::vector<gfx::Rect> composition_character_bounds_;
87 base::string16 inserted_text_; 110 base::string16 inserted_text_;
111 size_t call_count_set_composition_text_;
112 size_t call_count_insert_char_;
113 size_t call_count_insert_text_;
88 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); 114 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient);
89 }; 115 };
90 116
91 class MockInputMethodDelegate : public internal::InputMethodDelegate { 117 class MockInputMethodDelegate : public internal::InputMethodDelegate {
92 public: 118 public:
93 MockInputMethodDelegate() {} 119 MockInputMethodDelegate() {}
94 120
95 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { 121 const std::vector<ui::KeyboardCode>& fabricated_key_events() const {
96 return fabricated_key_events_; 122 return fabricated_key_events_;
97 } 123 }
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 652
627 // TextInputClient is now focused here. 653 // TextInputClient is now focused here.
628 654
629 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); 655 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char));
630 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); 656 EXPECT_EQ(L"A", mock_text_input_client.inserted_text());
631 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); 657 EXPECT_TRUE(delegate_.fabricated_key_events().empty());
632 delegate_.Reset(); 658 delegate_.Reset();
633 mock_text_input_client.Reset(); 659 mock_text_input_client.Reset();
634 } 660 }
635 661
662 TEST(RemoteInputMethodWinTest, OnCompositionChanged) {
663 MockInputMethodDelegate delegate_;
664 MockTextInputClient mock_text_input_client;
665 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_));
666
667 RemoteInputMethodPrivateWin* private_ptr =
668 RemoteInputMethodPrivateWin::Get(input_method.get());
669 ASSERT_TRUE(private_ptr != NULL);
670 MockRemoteInputMethodDelegateWin mock_remote_delegate;
671 private_ptr->SetRemoteDelegate(&mock_remote_delegate);
672
673 CompositionText composition_text;
674
675 // TextInputClient is not focused yet here.
676
677 private_ptr->OnCompositionChanged(composition_text);
678 EXPECT_EQ(0, mock_text_input_client.call_count_set_composition_text());
679 delegate_.Reset();
680 mock_text_input_client.Reset();
681
682 input_method->SetFocusedTextInputClient(&mock_text_input_client);
683
684 // TextInputClient is now focused here.
685
686 private_ptr->OnCompositionChanged(composition_text);
687 EXPECT_EQ(1, mock_text_input_client.call_count_set_composition_text());
688 delegate_.Reset();
689 mock_text_input_client.Reset();
690 }
691
692 TEST(RemoteInputMethodWinTest, OnTextCommitted) {
693 MockInputMethodDelegate delegate_;
694 MockTextInputClient mock_text_input_client;
695 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_));
696
697 RemoteInputMethodPrivateWin* private_ptr =
698 RemoteInputMethodPrivateWin::Get(input_method.get());
699 ASSERT_TRUE(private_ptr != NULL);
700 MockRemoteInputMethodDelegateWin mock_remote_delegate;
701 private_ptr->SetRemoteDelegate(&mock_remote_delegate);
702
703 base::string16 committed_text = L"Hello";
704
705 // TextInputClient is not focused yet here.
706
707 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT);
708 private_ptr->OnTextCommitted(committed_text);
709 EXPECT_EQ(0, mock_text_input_client.call_count_insert_char());
710 EXPECT_EQ(0, mock_text_input_client.call_count_insert_text());
711 EXPECT_EQ(L"", mock_text_input_client.inserted_text());
712 delegate_.Reset();
713 mock_text_input_client.Reset();
714
715 input_method->SetFocusedTextInputClient(&mock_text_input_client);
716
717 // TextInputClient is now focused here.
718
719 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT);
720 private_ptr->OnTextCommitted(committed_text);
721 EXPECT_EQ(0, mock_text_input_client.call_count_insert_char());
722 EXPECT_EQ(1, mock_text_input_client.call_count_insert_text());
723 EXPECT_EQ(committed_text, mock_text_input_client.inserted_text());
724 delegate_.Reset();
725 mock_text_input_client.Reset();
726
727 // When TextInputType is TEXT_INPUT_TYPE_NONE, TextInputClient::InsertText
728 // should not be used.
729 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_NONE);
730 private_ptr->OnTextCommitted(committed_text);
731 EXPECT_EQ(committed_text.size(),
732 mock_text_input_client.call_count_insert_char());
733 EXPECT_EQ(0, mock_text_input_client.call_count_insert_text());
734 EXPECT_EQ(committed_text, mock_text_input_client.inserted_text());
735 delegate_.Reset();
736 mock_text_input_client.Reset();
737 }
738
636 TEST(RemoteInputMethodWinTest, OnTextInputStateChanged_Observer) { 739 TEST(RemoteInputMethodWinTest, OnTextInputStateChanged_Observer) {
637 DummyTextInputClient text_input_client; 740 DummyTextInputClient text_input_client;
638 DummyTextInputClient text_input_client_the_other; 741 DummyTextInputClient text_input_client_the_other;
639 742
640 MockInputMethodObserver input_method_observer; 743 MockInputMethodObserver input_method_observer;
641 MockInputMethodDelegate delegate_; 744 MockInputMethodDelegate delegate_;
642 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); 745 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_));
643 InputMethodScopedObserver scoped_observer(&input_method_observer); 746 InputMethodScopedObserver scoped_observer(&input_method_observer);
644 scoped_observer.Add(input_method.get()); 747 scoped_observer.Add(input_method.get());
645 748
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); 824 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_));
722 input_method->AddObserver(&input_method_observer); 825 input_method->AddObserver(&input_method_observer);
723 826
724 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); 827 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed());
725 input_method.reset(); 828 input_method.reset();
726 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); 829 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed());
727 } 830 }
728 831
729 } // namespace 832 } // namespace
730 } // namespace ui 833 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/remote_input_method_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698