| 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/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 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 bool cancel_composition_called_; | 159 bool cancel_composition_called_; |
| 160 bool text_input_client_updated_called_; | 160 bool text_input_client_updated_called_; |
| 161 std::vector<int32> input_scopes_; | 161 std::vector<int32> input_scopes_; |
| 162 std::vector<gfx::Rect> composition_character_bounds_; | 162 std::vector<gfx::Rect> composition_character_bounds_; |
| 163 DISALLOW_COPY_AND_ASSIGN(MockRemoteInputMethodDelegateWin); | 163 DISALLOW_COPY_AND_ASSIGN(MockRemoteInputMethodDelegateWin); |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 class MockInputMethodObserver : public InputMethodObserver { | 166 class MockInputMethodObserver : public InputMethodObserver { |
| 167 public: | 167 public: |
| 168 MockInputMethodObserver() | 168 MockInputMethodObserver() |
| 169 : on_text_input_type_changed_(0), | 169 : on_text_input_state_changed_(0), |
| 170 on_caret_bounds_changed_(0), | |
| 171 on_text_input_state_changed_(0), | |
| 172 on_input_method_destroyed_changed_(0) { | 170 on_input_method_destroyed_changed_(0) { |
| 173 } | 171 } |
| 174 virtual ~MockInputMethodObserver() { | 172 virtual ~MockInputMethodObserver() { |
| 175 } | 173 } |
| 176 void Reset() { | 174 void Reset() { |
| 177 on_text_input_type_changed_ = 0; | |
| 178 on_caret_bounds_changed_ = 0; | |
| 179 on_text_input_state_changed_ = 0; | 175 on_text_input_state_changed_ = 0; |
| 180 on_input_method_destroyed_changed_ = 0; | 176 on_input_method_destroyed_changed_ = 0; |
| 181 } | 177 } |
| 182 size_t on_text_input_type_changed() const { | |
| 183 return on_text_input_type_changed_; | |
| 184 } | |
| 185 size_t on_caret_bounds_changed() const { | |
| 186 return on_caret_bounds_changed_; | |
| 187 } | |
| 188 size_t on_text_input_state_changed() const { | 178 size_t on_text_input_state_changed() const { |
| 189 return on_text_input_state_changed_; | 179 return on_text_input_state_changed_; |
| 190 } | 180 } |
| 191 size_t on_input_method_destroyed_changed() const { | 181 size_t on_input_method_destroyed_changed() const { |
| 192 return on_input_method_destroyed_changed_; | 182 return on_input_method_destroyed_changed_; |
| 193 } | 183 } |
| 194 | 184 |
| 195 private: | 185 private: |
| 196 // Overriden from InputMethodObserver. | 186 // Overriden from InputMethodObserver. |
| 197 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { | 187 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { |
| 198 ++on_text_input_type_changed_; | |
| 199 } | 188 } |
| 200 virtual void OnFocus() OVERRIDE { | 189 virtual void OnFocus() OVERRIDE { |
| 201 } | 190 } |
| 202 virtual void OnBlur() OVERRIDE { | 191 virtual void OnBlur() OVERRIDE { |
| 203 } | 192 } |
| 204 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { | 193 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { |
| 205 ++on_caret_bounds_changed_; | |
| 206 } | 194 } |
| 207 virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE { | 195 virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE { |
| 208 ++on_text_input_state_changed_; | 196 ++on_text_input_state_changed_; |
| 209 } | 197 } |
| 210 virtual void OnInputMethodDestroyed(const InputMethod* client) OVERRIDE { | 198 virtual void OnInputMethodDestroyed(const InputMethod* client) OVERRIDE { |
| 211 ++on_input_method_destroyed_changed_; | 199 ++on_input_method_destroyed_changed_; |
| 212 } | 200 } |
| 213 | 201 |
| 214 size_t on_text_input_type_changed_; | |
| 215 size_t on_caret_bounds_changed_; | |
| 216 size_t on_text_input_state_changed_; | 202 size_t on_text_input_state_changed_; |
| 217 size_t on_input_method_destroyed_changed_; | 203 size_t on_input_method_destroyed_changed_; |
| 218 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); | 204 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); |
| 219 }; | 205 }; |
| 220 | 206 |
| 221 typedef ScopedObserver<InputMethod, InputMethodObserver> | 207 typedef ScopedObserver<InputMethod, InputMethodObserver> |
| 222 InputMethodScopedObserver; | 208 InputMethodScopedObserver; |
| 223 | 209 |
| 224 TEST(RemoteInputMethodWinTest, RemoteInputMethodPrivateWin) { | 210 TEST(RemoteInputMethodWinTest, RemoteInputMethodPrivateWin) { |
| 225 InputMethod* other_ptr = static_cast<InputMethod*>(NULL) + 1; | 211 InputMethod* other_ptr = static_cast<InputMethod*>(NULL) + 1; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 ASSERT_EQ(&text_input_client_the_other, input_method->GetTextInputClient()); | 643 ASSERT_EQ(&text_input_client_the_other, input_method->GetTextInputClient()); |
| 658 EXPECT_EQ(1u, input_method_observer.on_text_input_state_changed()); | 644 EXPECT_EQ(1u, input_method_observer.on_text_input_state_changed()); |
| 659 input_method_observer.Reset(); | 645 input_method_observer.Reset(); |
| 660 | 646 |
| 661 input_method->DetachTextInputClient(&text_input_client_the_other); | 647 input_method->DetachTextInputClient(&text_input_client_the_other); |
| 662 ASSERT_TRUE(input_method->GetTextInputClient() == NULL); | 648 ASSERT_TRUE(input_method->GetTextInputClient() == NULL); |
| 663 EXPECT_EQ(1u, input_method_observer.on_text_input_state_changed()); | 649 EXPECT_EQ(1u, input_method_observer.on_text_input_state_changed()); |
| 664 input_method_observer.Reset(); | 650 input_method_observer.Reset(); |
| 665 } | 651 } |
| 666 | 652 |
| 667 TEST(RemoteInputMethodWinTest, OnCaretBoundsChanged_Observer) { | |
| 668 DummyTextInputClient text_input_client; | |
| 669 DummyTextInputClient text_input_client_the_other; | |
| 670 | |
| 671 MockInputMethodObserver input_method_observer; | |
| 672 MockInputMethodDelegate delegate_; | |
| 673 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | |
| 674 InputMethodScopedObserver scoped_observer(&input_method_observer); | |
| 675 scoped_observer.Add(input_method.get()); | |
| 676 | |
| 677 { | |
| 678 SCOPED_TRACE("OnCaretBoundsChanged callback must not be fired when no text " | |
| 679 "input client is focused"); | |
| 680 ASSERT_EQ(NULL, input_method->GetTextInputClient()); | |
| 681 | |
| 682 input_method_observer.Reset(); | |
| 683 input_method->OnCaretBoundsChanged(&text_input_client); | |
| 684 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); | |
| 685 input_method->OnCaretBoundsChanged(NULL); | |
| 686 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); | |
| 687 } | |
| 688 | |
| 689 { | |
| 690 SCOPED_TRACE("OnCaretBoundsChanged callback must be fired when and only " | |
| 691 "the event is notified from the focused text input client"); | |
| 692 | |
| 693 input_method->SetFocusedTextInputClient(&text_input_client); | |
| 694 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); | |
| 695 | |
| 696 // Must fire the event | |
| 697 input_method_observer.Reset(); | |
| 698 input_method->OnCaretBoundsChanged(&text_input_client); | |
| 699 EXPECT_EQ(1u, input_method_observer.on_caret_bounds_changed()); | |
| 700 | |
| 701 // Must not fire the event | |
| 702 input_method_observer.Reset(); | |
| 703 input_method->OnCaretBoundsChanged(NULL); | |
| 704 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); | |
| 705 | |
| 706 // Must not fire the event | |
| 707 input_method_observer.Reset(); | |
| 708 input_method->OnCaretBoundsChanged(&text_input_client_the_other); | |
| 709 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); | |
| 710 } | |
| 711 } | |
| 712 | |
| 713 TEST(RemoteInputMethodWinTest, OnInputMethodDestroyed_Observer) { | 653 TEST(RemoteInputMethodWinTest, OnInputMethodDestroyed_Observer) { |
| 714 DummyTextInputClient text_input_client; | 654 DummyTextInputClient text_input_client; |
| 715 DummyTextInputClient text_input_client_the_other; | 655 DummyTextInputClient text_input_client_the_other; |
| 716 | 656 |
| 717 MockInputMethodObserver input_method_observer; | 657 MockInputMethodObserver input_method_observer; |
| 718 InputMethodScopedObserver scoped_observer(&input_method_observer); | 658 InputMethodScopedObserver scoped_observer(&input_method_observer); |
| 719 | 659 |
| 720 MockInputMethodDelegate delegate_; | 660 MockInputMethodDelegate delegate_; |
| 721 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 661 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 722 input_method->AddObserver(&input_method_observer); | 662 input_method->AddObserver(&input_method_observer); |
| 723 | 663 |
| 724 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); | 664 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); |
| 725 input_method.reset(); | 665 input_method.reset(); |
| 726 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); | 666 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); |
| 727 } | 667 } |
| 728 | 668 |
| 729 } // namespace | 669 } // namespace |
| 730 } // namespace ui | 670 } // namespace ui |
| OLD | NEW |