Chromium Code Reviews| 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 <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 class ArcImeServiceTest : public testing::Test { | 131 class ArcImeServiceTest : public testing::Test { |
| 132 public: | 132 public: |
| 133 ArcImeServiceTest() {} | 133 ArcImeServiceTest() {} |
| 134 | 134 |
| 135 protected: | 135 protected: |
| 136 std::unique_ptr<FakeArcBridgeService> fake_arc_bridge_service_; | 136 std::unique_ptr<FakeArcBridgeService> fake_arc_bridge_service_; |
| 137 std::unique_ptr<FakeInputMethod> fake_input_method_; | 137 std::unique_ptr<FakeInputMethod> fake_input_method_; |
| 138 std::unique_ptr<ArcImeService> instance_; | 138 std::unique_ptr<ArcImeService> instance_; |
| 139 FakeArcImeBridge* fake_arc_ime_bridge_; // Owned by |instance_| | 139 FakeArcImeBridge* fake_arc_ime_bridge_; // Owned by |instance_| |
| 140 | 140 |
| 141 FakeArcWindowDetector* fake_window_detector_; // Owned by |instance_| | |
| 142 std::unique_ptr<aura::Window> arc_win_; | |
| 143 | |
| 141 private: | 144 private: |
| 142 void SetUp() override { | 145 void SetUp() override { |
| 143 fake_arc_bridge_service_.reset(new FakeArcBridgeService); | 146 fake_arc_bridge_service_.reset(new FakeArcBridgeService); |
| 144 instance_.reset(new ArcImeService(fake_arc_bridge_service_.get())); | 147 instance_.reset(new ArcImeService(fake_arc_bridge_service_.get())); |
| 145 fake_arc_ime_bridge_ = new FakeArcImeBridge; | 148 fake_arc_ime_bridge_ = new FakeArcImeBridge; |
| 146 instance_->SetImeBridgeForTesting(base::WrapUnique(fake_arc_ime_bridge_)); | 149 instance_->SetImeBridgeForTesting(base::WrapUnique(fake_arc_ime_bridge_)); |
| 147 | 150 |
| 148 fake_input_method_.reset(new FakeInputMethod); | 151 fake_input_method_.reset(new FakeInputMethod); |
| 149 instance_->SetInputMethodForTesting(fake_input_method_.get()); | 152 instance_->SetInputMethodForTesting(fake_input_method_.get()); |
| 153 | |
| 154 fake_window_detector_ = new FakeArcWindowDetector; | |
|
hidehiko
2016/12/14 09:25:27
nit: () is missing.
kinaba
2016/12/14 12:12:56
Done.
| |
| 155 instance_->SetArcWindowDetectorForTesting( | |
| 156 base::WrapUnique(fake_window_detector_)); | |
| 157 arc_win_ = fake_window_detector_->CreateFakeArcTopLevelWindow(); | |
| 150 } | 158 } |
| 151 | 159 |
| 152 void TearDown() override { | 160 void TearDown() override { |
| 161 arc_win_.reset(); | |
| 162 fake_window_detector_ = nullptr; | |
| 153 fake_arc_ime_bridge_ = nullptr; | 163 fake_arc_ime_bridge_ = nullptr; |
| 154 instance_.reset(); | 164 instance_.reset(); |
| 155 fake_arc_bridge_service_.reset(); | 165 fake_arc_bridge_service_.reset(); |
| 156 } | 166 } |
| 157 }; | 167 }; |
| 158 | 168 |
| 159 TEST_F(ArcImeServiceTest, HasCompositionText) { | 169 TEST_F(ArcImeServiceTest, HasCompositionText) { |
| 170 instance_->OnWindowFocused(arc_win_.get(), nullptr); | |
| 171 | |
| 160 ui::CompositionText composition; | 172 ui::CompositionText composition; |
| 161 composition.text = base::UTF8ToUTF16("nonempty text"); | 173 composition.text = base::UTF8ToUTF16("nonempty text"); |
| 162 | 174 |
| 163 EXPECT_FALSE(instance_->HasCompositionText()); | 175 EXPECT_FALSE(instance_->HasCompositionText()); |
| 164 | 176 |
| 165 instance_->SetCompositionText(composition); | 177 instance_->SetCompositionText(composition); |
| 166 EXPECT_TRUE(instance_->HasCompositionText()); | 178 EXPECT_TRUE(instance_->HasCompositionText()); |
| 167 instance_->ClearCompositionText(); | 179 instance_->ClearCompositionText(); |
| 168 EXPECT_FALSE(instance_->HasCompositionText()); | 180 EXPECT_FALSE(instance_->HasCompositionText()); |
| 169 | 181 |
| 170 instance_->SetCompositionText(composition); | 182 instance_->SetCompositionText(composition); |
| 171 EXPECT_TRUE(instance_->HasCompositionText()); | 183 EXPECT_TRUE(instance_->HasCompositionText()); |
| 172 instance_->ConfirmCompositionText(); | 184 instance_->ConfirmCompositionText(); |
| 173 EXPECT_FALSE(instance_->HasCompositionText()); | 185 EXPECT_FALSE(instance_->HasCompositionText()); |
| 174 | 186 |
| 175 instance_->SetCompositionText(composition); | 187 instance_->SetCompositionText(composition); |
| 176 EXPECT_TRUE(instance_->HasCompositionText()); | 188 EXPECT_TRUE(instance_->HasCompositionText()); |
| 177 instance_->InsertText(base::UTF8ToUTF16("another text")); | 189 instance_->InsertText(base::UTF8ToUTF16("another text")); |
| 178 EXPECT_FALSE(instance_->HasCompositionText()); | 190 EXPECT_FALSE(instance_->HasCompositionText()); |
| 179 | 191 |
| 180 instance_->SetCompositionText(composition); | 192 instance_->SetCompositionText(composition); |
| 181 EXPECT_TRUE(instance_->HasCompositionText()); | 193 EXPECT_TRUE(instance_->HasCompositionText()); |
| 182 instance_->SetCompositionText(ui::CompositionText()); | 194 instance_->SetCompositionText(ui::CompositionText()); |
| 183 EXPECT_FALSE(instance_->HasCompositionText()); | 195 EXPECT_FALSE(instance_->HasCompositionText()); |
| 184 } | 196 } |
| 185 | 197 |
| 186 TEST_F(ArcImeServiceTest, ShowImeIfNeeded) { | 198 TEST_F(ArcImeServiceTest, ShowImeIfNeeded) { |
| 187 fake_input_method_->SetFocusedTextInputClient(instance_.get()); | 199 instance_->OnWindowFocused(arc_win_.get(), nullptr); |
| 200 | |
| 188 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); | 201 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); |
| 189 ASSERT_EQ(0, fake_input_method_->count_show_ime_if_needed()); | 202 ASSERT_EQ(0, fake_input_method_->count_show_ime_if_needed()); |
| 190 | 203 |
| 191 // Text input type change does not imply the show ime request. | 204 // Text input type change does not imply the show ime request. |
| 192 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); | 205 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); |
| 193 EXPECT_EQ(0, fake_input_method_->count_show_ime_if_needed()); | 206 EXPECT_EQ(0, fake_input_method_->count_show_ime_if_needed()); |
| 194 | 207 |
| 195 instance_->ShowImeIfNeeded(); | 208 instance_->ShowImeIfNeeded(); |
| 196 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); | 209 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); |
| 197 } | 210 } |
| 198 | 211 |
| 199 TEST_F(ArcImeServiceTest, CancelComposition) { | 212 TEST_F(ArcImeServiceTest, CancelComposition) { |
| 213 instance_->OnWindowFocused(arc_win_.get(), nullptr); | |
| 214 | |
| 200 // The bridge should forward the cancel event to the input method. | 215 // The bridge should forward the cancel event to the input method. |
| 201 fake_input_method_->SetFocusedTextInputClient(instance_.get()); | |
| 202 instance_->OnCancelComposition(); | 216 instance_->OnCancelComposition(); |
| 203 EXPECT_EQ(1, fake_input_method_->count_cancel_composition()); | 217 EXPECT_EQ(1, fake_input_method_->count_cancel_composition()); |
| 204 } | 218 } |
| 205 | 219 |
| 206 TEST_F(ArcImeServiceTest, InsertChar) { | 220 TEST_F(ArcImeServiceTest, InsertChar) { |
| 207 fake_input_method_->SetFocusedTextInputClient(instance_.get()); | 221 instance_->OnWindowFocused(arc_win_.get(), nullptr); |
| 208 | 222 |
| 209 // When text input type is NONE, the event is not forwarded. | 223 // When text input type is NONE, the event is not forwarded. |
| 210 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); | 224 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); |
| 211 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); | 225 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); |
| 212 EXPECT_EQ(0, fake_arc_ime_bridge_->count_send_insert_text()); | 226 EXPECT_EQ(0, fake_arc_ime_bridge_->count_send_insert_text()); |
| 213 | 227 |
| 214 // When the bridge is accepting text inputs, forward the event. | 228 // When the bridge is accepting text inputs, forward the event. |
| 215 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); | 229 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); |
| 216 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); | 230 instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, 0)); |
| 217 EXPECT_EQ(1, fake_arc_ime_bridge_->count_send_insert_text()); | 231 EXPECT_EQ(1, fake_arc_ime_bridge_->count_send_insert_text()); |
| 218 } | 232 } |
| 219 | 233 |
| 220 TEST_F(ArcImeServiceTest, WindowFocusTracking) { | 234 TEST_F(ArcImeServiceTest, WindowFocusTracking) { |
| 221 auto window_detector = base::MakeUnique<FakeArcWindowDetector>(); | |
| 222 std::unique_ptr<aura::Window> arc_win1 = | |
| 223 window_detector->CreateFakeArcTopLevelWindow(); | |
| 224 std::unique_ptr<aura::Window> arc_win2 = | 235 std::unique_ptr<aura::Window> arc_win2 = |
| 225 window_detector->CreateFakeArcTopLevelWindow(); | 236 fake_window_detector_->CreateFakeArcTopLevelWindow(); |
| 226 std::unique_ptr<aura::Window> nonarc_win = | 237 std::unique_ptr<aura::Window> nonarc_win = |
| 227 window_detector->CreateFakeNonArcTopLevelWindow(); | 238 fake_window_detector_->CreateFakeNonArcTopLevelWindow(); |
| 228 instance_->SetArcWindowDetectorForTesting(std::move(window_detector)); | |
| 229 | 239 |
| 230 // ARC window is focused. ArcImeService is set as the text input client. | 240 // ARC window is focused. ArcImeService is set as the text input client. |
| 231 instance_->OnWindowFocused(arc_win1.get(), nullptr); | 241 instance_->OnWindowFocused(arc_win_.get(), nullptr); |
| 232 EXPECT_EQ(instance_.get(), fake_input_method_->GetTextInputClient()); | 242 EXPECT_EQ(instance_.get(), fake_input_method_->GetTextInputClient()); |
| 233 EXPECT_EQ(1, fake_input_method_->count_set_focused_text_input_client()); | 243 EXPECT_EQ(1, fake_input_method_->count_set_focused_text_input_client()); |
| 234 | 244 |
| 235 // Focus is moving between ARC windows. No state change should happen. | 245 // Focus is moving between ARC windows. No state change should happen. |
| 236 instance_->OnWindowFocused(arc_win2.get(), arc_win1.get()); | 246 instance_->OnWindowFocused(arc_win2.get(), arc_win_.get()); |
| 237 EXPECT_EQ(instance_.get(), fake_input_method_->GetTextInputClient()); | 247 EXPECT_EQ(instance_.get(), fake_input_method_->GetTextInputClient()); |
| 238 EXPECT_EQ(1, fake_input_method_->count_set_focused_text_input_client()); | 248 EXPECT_EQ(1, fake_input_method_->count_set_focused_text_input_client()); |
| 239 | 249 |
| 240 // Focus moved to a non-ARC window. ArcImeService is detached. | 250 // Focus moved to a non-ARC window. ArcImeService is detached. |
| 241 instance_->OnWindowFocused(nonarc_win.get(), arc_win2.get()); | 251 instance_->OnWindowFocused(nonarc_win.get(), arc_win2.get()); |
| 242 EXPECT_EQ(nullptr, fake_input_method_->GetTextInputClient()); | 252 EXPECT_EQ(nullptr, fake_input_method_->GetTextInputClient()); |
|
kinaba
2016/12/14 09:02:40
note: this assert will fail without the fix.
| |
| 243 EXPECT_EQ(1, fake_input_method_->count_set_focused_text_input_client()); | 253 EXPECT_EQ(1, fake_input_method_->count_set_focused_text_input_client()); |
| 244 | 254 |
| 245 // Focus came back to an ARC window. ArcImeService is re-attached. | 255 // Focus came back to an ARC window. ArcImeService is re-attached. |
| 246 instance_->OnWindowFocused(arc_win1.get(), nonarc_win.get()); | 256 instance_->OnWindowFocused(arc_win_.get(), nonarc_win.get()); |
| 247 EXPECT_EQ(instance_.get(), fake_input_method_->GetTextInputClient()); | 257 EXPECT_EQ(instance_.get(), fake_input_method_->GetTextInputClient()); |
| 248 EXPECT_EQ(2, fake_input_method_->count_set_focused_text_input_client()); | 258 EXPECT_EQ(2, fake_input_method_->count_set_focused_text_input_client()); |
| 249 | 259 |
| 250 // Focus is moving out. | 260 // Focus is moving out. |
| 251 instance_->OnWindowFocused(nullptr, arc_win1.get()); | 261 instance_->OnWindowFocused(nullptr, arc_win_.get()); |
| 252 EXPECT_EQ(nullptr, fake_input_method_->GetTextInputClient()); | 262 EXPECT_EQ(nullptr, fake_input_method_->GetTextInputClient()); |
|
kinaba
2016/12/14 09:02:40
ditto
| |
| 253 EXPECT_EQ(2, fake_input_method_->count_set_focused_text_input_client()); | 263 EXPECT_EQ(2, fake_input_method_->count_set_focused_text_input_client()); |
| 254 } | 264 } |
| 255 | 265 |
| 256 } // namespace arc | 266 } // namespace arc |
| OLD | NEW |