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

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

Issue 1182523003: Removes TextInputFocusManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_chromeos.h" 5 #include "ui/base/ime/input_method_chromeos.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 #undef Bool 8 #undef Bool
9 #undef FocusIn 9 #undef FocusIn
10 #undef FocusOut 10 #undef FocusOut
11 #undef None 11 #undef None
12 12
13 #include <cstring> 13 #include <cstring>
14 14
15 #include "base/i18n/char_iterator.h" 15 #include "base/i18n/char_iterator.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/ime/chromeos/composition_text_chromeos.h" 19 #include "ui/base/ime/chromeos/composition_text_chromeos.h"
20 #include "ui/base/ime/chromeos/ime_bridge.h" 20 #include "ui/base/ime/chromeos/ime_bridge.h"
21 #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h" 21 #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h"
22 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" 22 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h"
23 #include "ui/base/ime/dummy_text_input_client.h" 23 #include "ui/base/ime/dummy_text_input_client.h"
24 #include "ui/base/ime/input_method_delegate.h" 24 #include "ui/base/ime/input_method_delegate.h"
25 #include "ui/base/ime/text_input_client.h" 25 #include "ui/base/ime/text_input_client.h"
26 #include "ui/base/ime/text_input_focus_manager.h"
27 #include "ui/base/ui_base_switches_util.h" 26 #include "ui/base/ui_base_switches_util.h"
28 #include "ui/events/event.h" 27 #include "ui/events/event.h"
29 #include "ui/events/event_utils.h" 28 #include "ui/events/event_utils.h"
30 #include "ui/events/keycodes/dom/dom_code.h" 29 #include "ui/events/keycodes/dom/dom_code.h"
31 #include "ui/events/keycodes/dom/keycode_converter.h" 30 #include "ui/events/keycodes/dom/keycode_converter.h"
32 #include "ui/events/test/events_test_utils_x11.h" 31 #include "ui/events/test/events_test_utils_x11.h"
33 #include "ui/gfx/geometry/rect.h" 32 #include "ui/gfx/geometry/rect.h"
34 33
35 using base::UTF8ToUTF16; 34 using base::UTF8ToUTF16;
36 using base::UTF16ToUTF8; 35 using base::UTF16ToUTF8;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 new chromeos::MockIMEEngineHandler()); 212 new chromeos::MockIMEEngineHandler());
214 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( 213 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(
215 mock_ime_engine_handler_.get()); 214 mock_ime_engine_handler_.get());
216 215
217 mock_ime_candidate_window_handler_.reset( 216 mock_ime_candidate_window_handler_.reset(
218 new chromeos::MockIMECandidateWindowHandler()); 217 new chromeos::MockIMECandidateWindowHandler());
219 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( 218 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(
220 mock_ime_candidate_window_handler_.get()); 219 mock_ime_candidate_window_handler_.get());
221 220
222 ime_.reset(new TestableInputMethodChromeOS(this)); 221 ime_.reset(new TestableInputMethodChromeOS(this));
223 if (switches::IsTextInputFocusManagerEnabled()) 222 ime_->SetFocusedTextInputClient(this);
224 TextInputFocusManager::GetInstance()->FocusTextInputClient(this);
225 else
226 ime_->SetFocusedTextInputClient(this);
227 } 223 }
228 224
229 void TearDown() override { 225 void TearDown() override {
230 if (ime_.get()) { 226 if (ime_.get())
231 if (switches::IsTextInputFocusManagerEnabled()) 227 ime_->SetFocusedTextInputClient(NULL);
232 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
233 else
234 ime_->SetFocusedTextInputClient(NULL);
235 }
236 ime_.reset(); 228 ime_.reset();
237 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); 229 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL);
238 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); 230 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL);
239 mock_ime_engine_handler_.reset(); 231 mock_ime_engine_handler_.reset();
240 mock_ime_candidate_window_handler_.reset(); 232 mock_ime_candidate_window_handler_.reset();
241 chromeos::IMEBridge::Shutdown(); 233 chromeos::IMEBridge::Shutdown();
242 234
243 ResetFlags(); 235 ResetFlags();
244 } 236 }
245 237
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ime_->OnFocus(); 362 ime_->OnFocus();
371 EXPECT_TRUE(ime_->CanComposeInline()); 363 EXPECT_TRUE(ime_->CanComposeInline());
372 can_compose_inline_ = false; 364 can_compose_inline_ = false;
373 ime_->OnTextInputTypeChanged(this); 365 ime_->OnTextInputTypeChanged(this);
374 EXPECT_FALSE(ime_->CanComposeInline()); 366 EXPECT_FALSE(ime_->CanComposeInline());
375 } 367 }
376 368
377 TEST_F(InputMethodChromeOSTest, GetTextInputClient) { 369 TEST_F(InputMethodChromeOSTest, GetTextInputClient) {
378 ime_->OnFocus(); 370 ime_->OnFocus();
379 EXPECT_EQ(this, ime_->GetTextInputClient()); 371 EXPECT_EQ(this, ime_->GetTextInputClient());
380 if (switches::IsTextInputFocusManagerEnabled()) 372 ime_->SetFocusedTextInputClient(NULL);
381 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
382 else
383 ime_->SetFocusedTextInputClient(NULL);
384 EXPECT_EQ(NULL, ime_->GetTextInputClient()); 373 EXPECT_EQ(NULL, ime_->GetTextInputClient());
385 } 374 }
386 375
387 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) { 376 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) {
388 ime_->OnFocus(); 377 ime_->OnFocus();
389 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 378 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
390 if (switches::IsTextInputFocusManagerEnabled()) 379 ime_->SetFocusedTextInputClient(NULL);
391 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
392 else
393 ime_->SetFocusedTextInputClient(NULL);
394 input_type_ = TEXT_INPUT_TYPE_PASSWORD; 380 input_type_ = TEXT_INPUT_TYPE_PASSWORD;
395 ime_->OnTextInputTypeChanged(this); 381 ime_->OnTextInputTypeChanged(this);
396 // The OnTextInputTypeChanged() call above should be ignored since |this| is 382 // The OnTextInputTypeChanged() call above should be ignored since |this| is
397 // not the current focused client. 383 // not the current focused client.
398 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 384 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
399 385
400 if (switches::IsTextInputFocusManagerEnabled()) 386 ime_->SetFocusedTextInputClient(this);
401 TextInputFocusManager::GetInstance()->FocusTextInputClient(this);
402 else
403 ime_->SetFocusedTextInputClient(this);
404 ime_->OnTextInputTypeChanged(this); 387 ime_->OnTextInputTypeChanged(this);
405 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); 388 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType());
406 } 389 }
407 390
408 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) { 391 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) {
409 ime_->OnFocus(); 392 ime_->OnFocus();
410 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 393 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
411 if (switches::IsTextInputFocusManagerEnabled()) 394 ime_->OnBlur();
412 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
413 else
414 ime_->OnBlur();
415 input_type_ = TEXT_INPUT_TYPE_PASSWORD; 395 input_type_ = TEXT_INPUT_TYPE_PASSWORD;
416 ime_->OnTextInputTypeChanged(this); 396 ime_->OnTextInputTypeChanged(this);
417 // The OnTextInputTypeChanged() call above should be ignored since the top- 397 // The OnTextInputTypeChanged() call above should be ignored since the top-
418 // level window which the ime_ is attached to is not currently focused. 398 // level window which the ime_ is attached to is not currently focused.
419 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 399 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
420 400
421 if (switches::IsTextInputFocusManagerEnabled()) 401 ime_->OnFocus();
422 TextInputFocusManager::GetInstance()->FocusTextInputClient(this);
423 else
424 ime_->OnFocus();
425 ime_->OnTextInputTypeChanged(this); 402 ime_->OnTextInputTypeChanged(this);
426 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); 403 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType());
427 } 404 }
428 405
429 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) { 406 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) {
430 if (switches::IsTextInputFocusManagerEnabled())
431 return;
432
433 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 407 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
434 input_type_ = TEXT_INPUT_TYPE_PASSWORD; 408 input_type_ = TEXT_INPUT_TYPE_PASSWORD;
435 ime_->OnTextInputTypeChanged(this); 409 ime_->OnTextInputTypeChanged(this);
436 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 410 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
437 411
438 ime_->OnFocus(); 412 ime_->OnFocus();
439 ime_->OnTextInputTypeChanged(this); 413 ime_->OnTextInputTypeChanged(this);
440 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); 414 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType());
441 } 415 }
442 416
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 ime_->OnTextInputTypeChanged(this); 507 ime_->OnTextInputTypeChanged(this);
534 // Confirm that both FocusIn and FocusOut are called and the TextInputType is 508 // Confirm that both FocusIn and FocusOut are called and the TextInputType is
535 // changed to URL. 509 // changed to URL.
536 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); 510 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count());
537 EXPECT_EQ(2, mock_ime_engine_handler_->focus_out_call_count()); 511 EXPECT_EQ(2, mock_ime_engine_handler_->focus_out_call_count());
538 EXPECT_EQ(TEXT_INPUT_TYPE_URL, 512 EXPECT_EQ(TEXT_INPUT_TYPE_URL,
539 mock_ime_engine_handler_->last_text_input_context().type); 513 mock_ime_engine_handler_->last_text_input_context().type);
540 EXPECT_EQ(TEXT_INPUT_MODE_KANA, 514 EXPECT_EQ(TEXT_INPUT_MODE_KANA,
541 mock_ime_engine_handler_->last_text_input_context().mode); 515 mock_ime_engine_handler_->last_text_input_context().mode);
542 516
543 // When IsTextInputFocusManagerEnabled, InputMethod::SetFocusedTextInputClient
544 // is not supported and it's no-op.
545 if (switches::IsTextInputFocusManagerEnabled())
546 return;
547 // Confirm that FocusOut is called when set focus to NULL client. 517 // Confirm that FocusOut is called when set focus to NULL client.
548 ime_->SetFocusedTextInputClient(NULL); 518 ime_->SetFocusedTextInputClient(NULL);
549 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); 519 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count());
550 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); 520 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count());
551 // Confirm that FocusIn is called when set focus to this client. 521 // Confirm that FocusIn is called when set focus to this client.
552 ime_->SetFocusedTextInputClient(this); 522 ime_->SetFocusedTextInputClient(this);
553 EXPECT_EQ(4, mock_ime_engine_handler_->focus_in_call_count()); 523 EXPECT_EQ(4, mock_ime_engine_handler_->focus_in_call_count());
554 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); 524 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count());
555 } 525 }
556 526
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 EXPECT_EQ(ui::VKEY_C, stored_event->key_code()); 978 EXPECT_EQ(ui::VKEY_C, stored_event->key_code());
1009 EXPECT_EQ(kFlags, stored_event->flags()); 979 EXPECT_EQ(kFlags, stored_event->flags());
1010 EXPECT_FALSE(ime_->process_key_event_post_ime_args().handled); 980 EXPECT_FALSE(ime_->process_key_event_post_ime_args().handled);
1011 981
1012 EXPECT_EQ(L'C', inserted_char_); 982 EXPECT_EQ(L'C', inserted_char_);
1013 } 983 }
1014 984
1015 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). 985 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593).
1016 986
1017 } // namespace ui 987 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698