OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/arc/ime/arc_ime_service.h" | 5 #include "components/arc/ime/arc_ime_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 EXPECT_TRUE(instance_->HasCompositionText()); | 135 EXPECT_TRUE(instance_->HasCompositionText()); |
136 instance_->SetCompositionText(ui::CompositionText()); | 136 instance_->SetCompositionText(ui::CompositionText()); |
137 EXPECT_FALSE(instance_->HasCompositionText()); | 137 EXPECT_FALSE(instance_->HasCompositionText()); |
138 } | 138 } |
139 | 139 |
140 TEST_F(ArcImeServiceTest, ShowImeIfNeeded) { | 140 TEST_F(ArcImeServiceTest, ShowImeIfNeeded) { |
141 fake_input_method_->SetFocusedTextInputClient(instance_.get()); | 141 fake_input_method_->SetFocusedTextInputClient(instance_.get()); |
142 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); | 142 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); |
143 ASSERT_EQ(0, fake_input_method_->count_show_ime_if_needed()); | 143 ASSERT_EQ(0, fake_input_method_->count_show_ime_if_needed()); |
144 | 144 |
| 145 // Text input type change does not imply the show ime request. |
145 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); | 146 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); |
| 147 EXPECT_EQ(0, fake_input_method_->count_show_ime_if_needed()); |
| 148 |
| 149 instance_->ShowImeIfNeeded(); |
146 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); | 150 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); |
147 | |
148 // The type is not changing, hence no call. | |
149 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); | |
150 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); | |
151 | |
152 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_SEARCH); | |
153 EXPECT_EQ(2, fake_input_method_->count_show_ime_if_needed()); | |
154 | |
155 // Change to NONE should not trigger the showing event. | |
156 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); | |
157 EXPECT_EQ(2, fake_input_method_->count_show_ime_if_needed()); | |
158 } | 151 } |
159 | 152 |
160 TEST_F(ArcImeServiceTest, CancelComposition) { | 153 TEST_F(ArcImeServiceTest, CancelComposition) { |
161 // The bridge should forward the cancel event to the input method. | 154 // The bridge should forward the cancel event to the input method. |
162 fake_input_method_->SetFocusedTextInputClient(instance_.get()); | 155 fake_input_method_->SetFocusedTextInputClient(instance_.get()); |
163 instance_->OnCancelComposition(); | 156 instance_->OnCancelComposition(); |
164 EXPECT_EQ(1, fake_input_method_->count_cancel_composition()); | 157 EXPECT_EQ(1, fake_input_method_->count_cancel_composition()); |
165 } | 158 } |
166 | 159 |
167 TEST_F(ArcImeServiceTest, InsertChar) { | 160 TEST_F(ArcImeServiceTest, InsertChar) { |
168 fake_input_method_->SetFocusedTextInputClient(instance_.get()); | 161 fake_input_method_->SetFocusedTextInputClient(instance_.get()); |
169 | 162 |
170 // When text input type is NONE, the event is not forwarded. | 163 // When text input type is NONE, the event is not forwarded. |
171 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); | 164 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); |
172 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); | 165 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); |
173 EXPECT_EQ(0, fake_arc_ime_bridge_->count_send_insert_text()); | 166 EXPECT_EQ(0, fake_arc_ime_bridge_->count_send_insert_text()); |
174 | 167 |
175 // When the bridge is accepting text inputs, forward the event. | 168 // When the bridge is accepting text inputs, forward the event. |
176 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); | 169 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); |
177 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); | 170 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); |
178 EXPECT_EQ(1, fake_arc_ime_bridge_->count_send_insert_text()); | 171 EXPECT_EQ(1, fake_arc_ime_bridge_->count_send_insert_text()); |
179 } | 172 } |
180 | 173 |
181 } // namespace arc | 174 } // namespace arc |
OLD | NEW |