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

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

Issue 1163603004: Remove candidate show/hide/update related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 6 months 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/input_method_base.cc ('k') | ui/base/ime/input_method_win.cc » ('j') | 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/input_method_base.h" 5 #include "ui/base/ime/input_method_base.h"
6 6
7 #include "base/gtest_prod_util.h" 7 #include "base/gtest_prod_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 void OnTextInputStateChanged(const TextInputClient* client) override { 191 void OnTextInputStateChanged(const TextInputClient* client) override {
192 verifier_->OnTextInputStateChanged(client); 192 verifier_->OnTextInputStateChanged(client);
193 } 193 }
194 void OnShowImeIfNeeded() override {} 194 void OnShowImeIfNeeded() override {}
195 void OnInputMethodDestroyed(const InputMethod* client) override {} 195 void OnInputMethodDestroyed(const InputMethod* client) override {}
196 196
197 ClientChangeVerifier* verifier_; 197 ClientChangeVerifier* verifier_;
198 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); 198 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver);
199 }; 199 };
200 200
201 class MockTextInputClient : public DummyTextInputClient {
202 public:
203 MockTextInputClient()
204 : shown_event_count_(0), updated_event_count_(0), hidden_event_count_(0) {
205 }
206 ~MockTextInputClient() override {}
207
208 void OnCandidateWindowShown() override { ++shown_event_count_; }
209 void OnCandidateWindowUpdated() override { ++updated_event_count_; }
210 void OnCandidateWindowHidden() override { ++hidden_event_count_; }
211
212 int shown_event_count() const { return shown_event_count_; }
213 int updated_event_count() const { return updated_event_count_; }
214 int hidden_event_count() const { return hidden_event_count_; }
215
216 private:
217 int shown_event_count_;
218 int updated_event_count_;
219 int hidden_event_count_;
220 };
221
222 typedef ScopedObserver<InputMethod, InputMethodObserver> 201 typedef ScopedObserver<InputMethod, InputMethodObserver>
223 InputMethodScopedObserver; 202 InputMethodScopedObserver;
224 203
225 void SetFocusedTextInputClient(InputMethod* input_method, 204 void SetFocusedTextInputClient(InputMethod* input_method,
226 TextInputClient* text_input_client) { 205 TextInputClient* text_input_client) {
227 if (switches::IsTextInputFocusManagerEnabled()) { 206 if (switches::IsTextInputFocusManagerEnabled()) {
228 TextInputFocusManager::GetInstance()->FocusTextInputClient( 207 TextInputFocusManager::GetInstance()->FocusTextInputClient(
229 text_input_client); 208 text_input_client);
230 } else { 209 } else {
231 input_method->SetFocusedTextInputClient(text_input_client); 210 input_method->SetFocusedTextInputClient(text_input_client);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 ASSERT_EQ(&text_input_client, input_method.GetTextInputClient()); 310 ASSERT_EQ(&text_input_client, input_method.GetTextInputClient());
332 input_method.OnBlur(); 311 input_method.OnBlur();
333 input_method.OnFocus(); 312 input_method.OnFocus();
334 verifier.ExpectClientChange(&text_input_client, NULL); 313 verifier.ExpectClientChange(&text_input_client, NULL);
335 input_method.DetachTextInputClient(&text_input_client); 314 input_method.DetachTextInputClient(&text_input_client);
336 EXPECT_EQ(NULL, input_method.GetTextInputClient()); 315 EXPECT_EQ(NULL, input_method.GetTextInputClient());
337 verifier.Verify(); 316 verifier.Verify();
338 } 317 }
339 } 318 }
340 319
341 TEST_F(InputMethodBaseTest, CandidateWindowEvents) {
342 MockTextInputClient text_input_client;
343
344 {
345 ClientChangeVerifier verifier;
346 MockInputMethodBase input_method_base(&verifier);
347 input_method_base.OnFocus();
348
349 verifier.ExpectClientChange(NULL, &text_input_client);
350 SetFocusedTextInputClient(&input_method_base, &text_input_client);
351
352 EXPECT_EQ(0, text_input_client.shown_event_count());
353 EXPECT_EQ(0, text_input_client.updated_event_count());
354 EXPECT_EQ(0, text_input_client.hidden_event_count());
355
356 input_method_base.OnCandidateWindowShown();
357 base::RunLoop().RunUntilIdle();
358
359 EXPECT_EQ(1, text_input_client.shown_event_count());
360 EXPECT_EQ(0, text_input_client.updated_event_count());
361 EXPECT_EQ(0, text_input_client.hidden_event_count());
362
363 input_method_base.OnCandidateWindowUpdated();
364 base::RunLoop().RunUntilIdle();
365
366 EXPECT_EQ(1, text_input_client.shown_event_count());
367 EXPECT_EQ(1, text_input_client.updated_event_count());
368 EXPECT_EQ(0, text_input_client.hidden_event_count());
369
370 input_method_base.OnCandidateWindowHidden();
371 base::RunLoop().RunUntilIdle();
372
373 EXPECT_EQ(1, text_input_client.shown_event_count());
374 EXPECT_EQ(1, text_input_client.updated_event_count());
375 EXPECT_EQ(1, text_input_client.hidden_event_count());
376
377 input_method_base.OnCandidateWindowShown();
378 }
379
380 // If InputMethod is deleted immediately after an event happens, but before
381 // its callback is invoked, the callback will be cancelled.
382 base::RunLoop().RunUntilIdle();
383 EXPECT_EQ(1, text_input_client.shown_event_count());
384 EXPECT_EQ(1, text_input_client.updated_event_count());
385 EXPECT_EQ(1, text_input_client.hidden_event_count());
386 }
387
388 } // namespace 320 } // namespace
389 } // namespace ui 321 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_base.cc ('k') | ui/base/ime/input_method_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698