| 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 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class MockTextInputClient : public DummyTextInputClient { | 26 class MockTextInputClient : public DummyTextInputClient { |
| 27 public: | 27 public: |
| 28 MockTextInputClient() | 28 MockTextInputClient() |
| 29 : text_input_type_(TEXT_INPUT_TYPE_NONE), | 29 : text_input_type_(TEXT_INPUT_TYPE_NONE), |
| 30 text_input_mode_(TEXT_INPUT_MODE_DEFAULT), | 30 text_input_mode_(TEXT_INPUT_MODE_DEFAULT), |
| 31 call_count_set_composition_text_(0), | 31 call_count_set_composition_text_(0), |
| 32 call_count_insert_char_(0), | 32 call_count_insert_char_(0), |
| 33 call_count_insert_text_(0), | 33 call_count_insert_text_(0), |
| 34 emulate_pepper_flash_(false), | 34 emulate_pepper_flash_(false) { |
| 35 is_candidate_window_shown_called_(false), | |
| 36 is_candidate_window_hidden_called_(false) { | |
| 37 } | 35 } |
| 38 | 36 |
| 39 size_t call_count_set_composition_text() const { | 37 size_t call_count_set_composition_text() const { |
| 40 return call_count_set_composition_text_; | 38 return call_count_set_composition_text_; |
| 41 } | 39 } |
| 42 const base::string16& inserted_text() const { | 40 const base::string16& inserted_text() const { |
| 43 return inserted_text_; | 41 return inserted_text_; |
| 44 } | 42 } |
| 45 size_t call_count_insert_char() const { | 43 size_t call_count_insert_char() const { |
| 46 return call_count_insert_char_; | 44 return call_count_insert_char_; |
| 47 } | 45 } |
| 48 size_t call_count_insert_text() const { | 46 size_t call_count_insert_text() const { |
| 49 return call_count_insert_text_; | 47 return call_count_insert_text_; |
| 50 } | 48 } |
| 51 bool is_candidate_window_shown_called() const { | |
| 52 return is_candidate_window_shown_called_; | |
| 53 } | |
| 54 bool is_candidate_window_hidden_called() const { | |
| 55 return is_candidate_window_hidden_called_; | |
| 56 } | |
| 57 void Reset() { | 49 void Reset() { |
| 58 text_input_type_ = TEXT_INPUT_TYPE_NONE; | 50 text_input_type_ = TEXT_INPUT_TYPE_NONE; |
| 59 text_input_mode_ = TEXT_INPUT_MODE_DEFAULT; | 51 text_input_mode_ = TEXT_INPUT_MODE_DEFAULT; |
| 60 call_count_set_composition_text_ = 0; | 52 call_count_set_composition_text_ = 0; |
| 61 inserted_text_.clear(); | 53 inserted_text_.clear(); |
| 62 call_count_insert_char_ = 0; | 54 call_count_insert_char_ = 0; |
| 63 call_count_insert_text_ = 0; | 55 call_count_insert_text_ = 0; |
| 64 caret_bounds_ = gfx::Rect(); | 56 caret_bounds_ = gfx::Rect(); |
| 65 composition_character_bounds_.clear(); | 57 composition_character_bounds_.clear(); |
| 66 emulate_pepper_flash_ = false; | 58 emulate_pepper_flash_ = false; |
| 67 is_candidate_window_shown_called_ = false; | |
| 68 is_candidate_window_hidden_called_ = false; | |
| 69 } | 59 } |
| 70 void set_text_input_type(ui::TextInputType type) { | 60 void set_text_input_type(ui::TextInputType type) { |
| 71 text_input_type_ = type; | 61 text_input_type_ = type; |
| 72 } | 62 } |
| 73 void set_text_input_mode(ui::TextInputMode mode) { | 63 void set_text_input_mode(ui::TextInputMode mode) { |
| 74 text_input_mode_ = mode; | 64 text_input_mode_ = mode; |
| 75 } | 65 } |
| 76 void set_caret_bounds(const gfx::Rect& caret_bounds) { | 66 void set_caret_bounds(const gfx::Rect& caret_bounds) { |
| 77 caret_bounds_ = caret_bounds; | 67 caret_bounds_ = caret_bounds; |
| 78 } | 68 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 106 } |
| 117 bool HasCompositionText() const override { | 107 bool HasCompositionText() const override { |
| 118 return !composition_character_bounds_.empty(); | 108 return !composition_character_bounds_.empty(); |
| 119 } | 109 } |
| 120 bool GetCompositionTextRange(gfx::Range* range) const override { | 110 bool GetCompositionTextRange(gfx::Range* range) const override { |
| 121 if (composition_character_bounds_.empty()) | 111 if (composition_character_bounds_.empty()) |
| 122 return false; | 112 return false; |
| 123 *range = gfx::Range(0, composition_character_bounds_.size()); | 113 *range = gfx::Range(0, composition_character_bounds_.size()); |
| 124 return true; | 114 return true; |
| 125 } | 115 } |
| 126 void OnCandidateWindowShown() override { | |
| 127 is_candidate_window_shown_called_ = true; | |
| 128 } | |
| 129 void OnCandidateWindowHidden() override { | |
| 130 is_candidate_window_hidden_called_ = true; | |
| 131 } | |
| 132 | 116 |
| 133 ui::TextInputType text_input_type_; | 117 ui::TextInputType text_input_type_; |
| 134 ui::TextInputMode text_input_mode_; | 118 ui::TextInputMode text_input_mode_; |
| 135 gfx::Rect caret_bounds_; | 119 gfx::Rect caret_bounds_; |
| 136 std::vector<gfx::Rect> composition_character_bounds_; | 120 std::vector<gfx::Rect> composition_character_bounds_; |
| 137 base::string16 inserted_text_; | 121 base::string16 inserted_text_; |
| 138 size_t call_count_set_composition_text_; | 122 size_t call_count_set_composition_text_; |
| 139 size_t call_count_insert_char_; | 123 size_t call_count_insert_char_; |
| 140 size_t call_count_insert_text_; | 124 size_t call_count_insert_text_; |
| 141 bool emulate_pepper_flash_; | 125 bool emulate_pepper_flash_; |
| 142 bool is_candidate_window_shown_called_; | |
| 143 bool is_candidate_window_hidden_called_; | |
| 144 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); | 126 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
| 145 }; | 127 }; |
| 146 | 128 |
| 147 class MockInputMethodDelegate : public internal::InputMethodDelegate { | 129 class MockInputMethodDelegate : public internal::InputMethodDelegate { |
| 148 public: | 130 public: |
| 149 MockInputMethodDelegate() {} | 131 MockInputMethodDelegate() {} |
| 150 | 132 |
| 151 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { | 133 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { |
| 152 return fabricated_key_events_; | 134 return fabricated_key_events_; |
| 153 } | 135 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 278 |
| 297 // RemoteInputMethodWin::OnCandidatePopupChanged can be called even when the | 279 // RemoteInputMethodWin::OnCandidatePopupChanged can be called even when the |
| 298 // focused text input client is NULL. | 280 // focused text input client is NULL. |
| 299 ASSERT_TRUE(input_method->GetTextInputClient() == NULL); | 281 ASSERT_TRUE(input_method->GetTextInputClient() == NULL); |
| 300 private_ptr->OnCandidatePopupChanged(false); | 282 private_ptr->OnCandidatePopupChanged(false); |
| 301 private_ptr->OnCandidatePopupChanged(true); | 283 private_ptr->OnCandidatePopupChanged(true); |
| 302 | 284 |
| 303 MockTextInputClient mock_text_input_client; | 285 MockTextInputClient mock_text_input_client; |
| 304 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 286 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 305 | 287 |
| 306 ASSERT_FALSE(mock_text_input_client.is_candidate_window_shown_called()); | |
| 307 ASSERT_FALSE(mock_text_input_client.is_candidate_window_hidden_called()); | |
| 308 mock_text_input_client.Reset(); | 288 mock_text_input_client.Reset(); |
| 309 | 289 |
| 310 private_ptr->OnCandidatePopupChanged(true); | 290 private_ptr->OnCandidatePopupChanged(true); |
| 311 EXPECT_TRUE(input_method->IsCandidatePopupOpen()); | 291 EXPECT_TRUE(input_method->IsCandidatePopupOpen()); |
| 312 EXPECT_TRUE(mock_text_input_client.is_candidate_window_shown_called()); | |
| 313 EXPECT_FALSE(mock_text_input_client.is_candidate_window_hidden_called()); | |
| 314 | 292 |
| 315 private_ptr->OnCandidatePopupChanged(false); | 293 private_ptr->OnCandidatePopupChanged(false); |
| 316 EXPECT_FALSE(input_method->IsCandidatePopupOpen()); | 294 EXPECT_FALSE(input_method->IsCandidatePopupOpen()); |
| 317 EXPECT_TRUE(mock_text_input_client.is_candidate_window_shown_called()); | |
| 318 EXPECT_TRUE(mock_text_input_client.is_candidate_window_hidden_called()); | |
| 319 } | 295 } |
| 320 | 296 |
| 321 TEST(RemoteInputMethodWinTest, CancelComposition) { | 297 TEST(RemoteInputMethodWinTest, CancelComposition) { |
| 322 MockInputMethodDelegate delegate_; | 298 MockInputMethodDelegate delegate_; |
| 323 MockTextInputClient mock_text_input_client; | 299 MockTextInputClient mock_text_input_client; |
| 324 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 300 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 325 | 301 |
| 326 // This must not cause a crash. | 302 // This must not cause a crash. |
| 327 input_method->CancelComposition(&mock_text_input_client); | 303 input_method->CancelComposition(&mock_text_input_client); |
| 328 | 304 |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 802 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 827 input_method->AddObserver(&input_method_observer); | 803 input_method->AddObserver(&input_method_observer); |
| 828 | 804 |
| 829 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); | 805 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); |
| 830 input_method.reset(); | 806 input_method.reset(); |
| 831 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); | 807 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); |
| 832 } | 808 } |
| 833 | 809 |
| 834 } // namespace | 810 } // namespace |
| 835 } // namespace ui | 811 } // namespace ui |
| OLD | NEW |