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

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

Issue 334573004: Fixes unittests with --enable-text-input-focus-manager flag enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed more unittests. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/ime/input_method_base.cc ('k') | ui/base/ime/input_method_chromeos_unittest.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"
11 #include "base/scoped_observer.h" 11 #include "base/scoped_observer.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/ime/dummy_text_input_client.h" 13 #include "ui/base/ime/dummy_text_input_client.h"
14 #include "ui/base/ime/input_method_observer.h" 14 #include "ui/base/ime/input_method_observer.h"
15 #include "ui/base/ime/text_input_focus_manager.h"
16 #include "ui/base/ui_base_switches_util.h"
15 #include "ui/events/event.h" 17 #include "ui/events/event.h"
16 18
17 namespace ui { 19 namespace ui {
18 namespace { 20 namespace {
19 21
20 class ClientChangeVerifier { 22 class ClientChangeVerifier {
21 public: 23 public:
22 ClientChangeVerifier() 24 ClientChangeVerifier()
23 : previous_client_(NULL), 25 : previous_client_(NULL),
24 next_client_(NULL), 26 next_client_(NULL),
(...skipping 20 matching lines...) Expand all
45 previous_client_ = previous_client; 47 previous_client_ = previous_client;
46 next_client_ = next_client; 48 next_client_ = next_client;
47 call_expected_ = true; 49 call_expected_ = true;
48 on_will_change_focused_client_called_ = false; 50 on_will_change_focused_client_called_ = false;
49 on_did_change_focused_client_called_ = false; 51 on_did_change_focused_client_called_ = false;
50 on_text_input_state_changed_ = false; 52 on_text_input_state_changed_ = false;
51 } 53 }
52 54
53 // Verifies the result satisfies the expectation or not. 55 // Verifies the result satisfies the expectation or not.
54 void Verify() { 56 void Verify() {
55 EXPECT_EQ(call_expected_, on_will_change_focused_client_called_); 57 if (switches::IsTextInputFocusManagerEnabled()) {
56 EXPECT_EQ(call_expected_, on_did_change_focused_client_called_); 58 EXPECT_FALSE(on_will_change_focused_client_called_);
57 EXPECT_EQ(call_expected_, on_text_input_state_changed_); 59 EXPECT_FALSE(on_did_change_focused_client_called_);
60 EXPECT_FALSE(on_text_input_state_changed_);
61 } else {
62 EXPECT_EQ(call_expected_, on_will_change_focused_client_called_);
63 EXPECT_EQ(call_expected_, on_did_change_focused_client_called_);
64 EXPECT_EQ(call_expected_, on_text_input_state_changed_);
65 }
58 } 66 }
59 67
60 void OnWillChangeFocusedClient(TextInputClient* focused_before, 68 void OnWillChangeFocusedClient(TextInputClient* focused_before,
61 TextInputClient* focused) { 69 TextInputClient* focused) {
62 EXPECT_TRUE(call_expected_); 70 EXPECT_TRUE(call_expected_);
63 71
64 // Check arguments 72 // Check arguments
65 EXPECT_EQ(previous_client_, focused_before); 73 EXPECT_EQ(previous_client_, focused_before);
66 EXPECT_EQ(next_client_, focused); 74 EXPECT_EQ(next_client_, focused);
67 75
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 246
239 private: 247 private:
240 int shown_event_count_; 248 int shown_event_count_;
241 int updated_event_count_; 249 int updated_event_count_;
242 int hidden_event_count_; 250 int hidden_event_count_;
243 }; 251 };
244 252
245 typedef ScopedObserver<InputMethod, InputMethodObserver> 253 typedef ScopedObserver<InputMethod, InputMethodObserver>
246 InputMethodScopedObserver; 254 InputMethodScopedObserver;
247 255
256 void SetFocusedTextInputClient(InputMethod* input_method,
257 TextInputClient* text_input_client) {
258 if (switches::IsTextInputFocusManagerEnabled()) {
259 TextInputFocusManager::GetInstance()->FocusTextInputClient(
260 text_input_client);
261 } else {
262 input_method->SetFocusedTextInputClient(text_input_client);
263 }
264 }
265
248 TEST_F(InputMethodBaseTest, SetFocusedTextInputClient) { 266 TEST_F(InputMethodBaseTest, SetFocusedTextInputClient) {
249 DummyTextInputClient text_input_client_1st; 267 DummyTextInputClient text_input_client_1st;
250 DummyTextInputClient text_input_client_2nd; 268 DummyTextInputClient text_input_client_2nd;
251 269
252 ClientChangeVerifier verifier; 270 ClientChangeVerifier verifier;
253 MockInputMethodBase input_method(&verifier); 271 MockInputMethodBase input_method(&verifier);
254 MockInputMethodObserver input_method_observer(&verifier); 272 MockInputMethodObserver input_method_observer(&verifier);
255 InputMethodScopedObserver scoped_observer(&input_method_observer); 273 InputMethodScopedObserver scoped_observer(&input_method_observer);
256 scoped_observer.Add(&input_method); 274 scoped_observer.Add(&input_method);
257 275
258 // Assume that the top-level-widget gains focus. 276 // Assume that the top-level-widget gains focus.
259 input_method.OnFocus(); 277 input_method.OnFocus();
260 278
261 { 279 {
262 SCOPED_TRACE("Focus from NULL to 1st TextInputClient"); 280 SCOPED_TRACE("Focus from NULL to 1st TextInputClient");
263 281
264 ASSERT_EQ(NULL, input_method.GetTextInputClient()); 282 ASSERT_EQ(NULL, input_method.GetTextInputClient());
265 verifier.ExpectClientChange(NULL, &text_input_client_1st); 283 verifier.ExpectClientChange(NULL, &text_input_client_1st);
266 input_method.SetFocusedTextInputClient(&text_input_client_1st); 284 SetFocusedTextInputClient(&input_method, &text_input_client_1st);
267 EXPECT_EQ(&text_input_client_1st, input_method.GetTextInputClient()); 285 EXPECT_EQ(&text_input_client_1st, input_method.GetTextInputClient());
268 verifier.Verify(); 286 verifier.Verify();
269 } 287 }
270 288
271 { 289 {
272 SCOPED_TRACE("Redundant focus events must be ignored"); 290 SCOPED_TRACE("Redundant focus events must be ignored");
273 verifier.ExpectClientDoesNotChange(); 291 verifier.ExpectClientDoesNotChange();
274 input_method.SetFocusedTextInputClient(&text_input_client_1st); 292 SetFocusedTextInputClient(&input_method, &text_input_client_1st);
275 verifier.Verify(); 293 verifier.Verify();
276 } 294 }
277 295
278 { 296 {
279 SCOPED_TRACE("Focus from 1st to 2nd TextInputClient"); 297 SCOPED_TRACE("Focus from 1st to 2nd TextInputClient");
280 298
281 ASSERT_EQ(&text_input_client_1st, input_method.GetTextInputClient()); 299 ASSERT_EQ(&text_input_client_1st, input_method.GetTextInputClient());
282 verifier.ExpectClientChange(&text_input_client_1st, 300 verifier.ExpectClientChange(&text_input_client_1st,
283 &text_input_client_2nd); 301 &text_input_client_2nd);
284 input_method.SetFocusedTextInputClient(&text_input_client_2nd); 302 SetFocusedTextInputClient(&input_method, &text_input_client_2nd);
285 EXPECT_EQ(&text_input_client_2nd, input_method.GetTextInputClient()); 303 EXPECT_EQ(&text_input_client_2nd, input_method.GetTextInputClient());
286 verifier.Verify(); 304 verifier.Verify();
287 } 305 }
288 306
289 { 307 {
290 SCOPED_TRACE("Focus from 2nd TextInputClient to NULL"); 308 SCOPED_TRACE("Focus from 2nd TextInputClient to NULL");
291 309
292 ASSERT_EQ(&text_input_client_2nd, input_method.GetTextInputClient()); 310 ASSERT_EQ(&text_input_client_2nd, input_method.GetTextInputClient());
293 verifier.ExpectClientChange(&text_input_client_2nd, NULL); 311 verifier.ExpectClientChange(&text_input_client_2nd, NULL);
294 input_method.SetFocusedTextInputClient(NULL); 312 SetFocusedTextInputClient(&input_method, NULL);
295 EXPECT_EQ(NULL, input_method.GetTextInputClient()); 313 EXPECT_EQ(NULL, input_method.GetTextInputClient());
296 verifier.Verify(); 314 verifier.Verify();
297 } 315 }
298 316
299 { 317 {
300 SCOPED_TRACE("Redundant focus events must be ignored"); 318 SCOPED_TRACE("Redundant focus events must be ignored");
301 verifier.ExpectClientDoesNotChange(); 319 verifier.ExpectClientDoesNotChange();
302 input_method.SetFocusedTextInputClient(NULL); 320 SetFocusedTextInputClient(&input_method, NULL);
303 verifier.Verify(); 321 verifier.Verify();
304 } 322 }
305 } 323 }
306 324
307 TEST_F(InputMethodBaseTest, DetachTextInputClient) { 325 TEST_F(InputMethodBaseTest, DetachTextInputClient) {
326 // DetachTextInputClient is not supported when IsTextInputFocusManagerEnabled.
327 if (switches::IsTextInputFocusManagerEnabled())
328 return;
329
308 DummyTextInputClient text_input_client; 330 DummyTextInputClient text_input_client;
309 DummyTextInputClient text_input_client_the_other; 331 DummyTextInputClient text_input_client_the_other;
310 332
311 ClientChangeVerifier verifier; 333 ClientChangeVerifier verifier;
312 MockInputMethodBase input_method(&verifier); 334 MockInputMethodBase input_method(&verifier);
313 MockInputMethodObserver input_method_observer(&verifier); 335 MockInputMethodObserver input_method_observer(&verifier);
314 InputMethodScopedObserver scoped_observer(&input_method_observer); 336 InputMethodScopedObserver scoped_observer(&input_method_observer);
315 scoped_observer.Add(&input_method); 337 scoped_observer.Add(&input_method);
316 338
317 // Assume that the top-level-widget gains focus. 339 // Assume that the top-level-widget gains focus.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 371
350 TEST_F(InputMethodBaseTest, CandidateWindowEvents) { 372 TEST_F(InputMethodBaseTest, CandidateWindowEvents) {
351 MockTextInputClient text_input_client; 373 MockTextInputClient text_input_client;
352 374
353 { 375 {
354 ClientChangeVerifier verifier; 376 ClientChangeVerifier verifier;
355 MockInputMethodBase input_method_base(&verifier); 377 MockInputMethodBase input_method_base(&verifier);
356 input_method_base.OnFocus(); 378 input_method_base.OnFocus();
357 379
358 verifier.ExpectClientChange(NULL, &text_input_client); 380 verifier.ExpectClientChange(NULL, &text_input_client);
359 input_method_base.SetFocusedTextInputClient(&text_input_client); 381 SetFocusedTextInputClient(&input_method_base, &text_input_client);
360 382
361 EXPECT_EQ(0, text_input_client.shown_event_count()); 383 EXPECT_EQ(0, text_input_client.shown_event_count());
362 EXPECT_EQ(0, text_input_client.updated_event_count()); 384 EXPECT_EQ(0, text_input_client.updated_event_count());
363 EXPECT_EQ(0, text_input_client.hidden_event_count()); 385 EXPECT_EQ(0, text_input_client.hidden_event_count());
364 386
365 input_method_base.OnCandidateWindowShown(); 387 input_method_base.OnCandidateWindowShown();
366 base::RunLoop().RunUntilIdle(); 388 base::RunLoop().RunUntilIdle();
367 389
368 EXPECT_EQ(1, text_input_client.shown_event_count()); 390 EXPECT_EQ(1, text_input_client.shown_event_count());
369 EXPECT_EQ(0, text_input_client.updated_event_count()); 391 EXPECT_EQ(0, text_input_client.updated_event_count());
(...skipping 19 matching lines...) Expand all
389 // If InputMethod is deleted immediately after an event happens, but before 411 // If InputMethod is deleted immediately after an event happens, but before
390 // its callback is invoked, the callback will be cancelled. 412 // its callback is invoked, the callback will be cancelled.
391 base::RunLoop().RunUntilIdle(); 413 base::RunLoop().RunUntilIdle();
392 EXPECT_EQ(1, text_input_client.shown_event_count()); 414 EXPECT_EQ(1, text_input_client.shown_event_count());
393 EXPECT_EQ(1, text_input_client.updated_event_count()); 415 EXPECT_EQ(1, text_input_client.updated_event_count());
394 EXPECT_EQ(1, text_input_client.hidden_event_count()); 416 EXPECT_EQ(1, text_input_client.hidden_event_count());
395 } 417 }
396 418
397 } // namespace 419 } // namespace
398 } // namespace ui 420 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_base.cc ('k') | ui/base/ime/input_method_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698