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

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: nit per comment. 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_unittest.cc ('k') | ui/base/ime/mock_input_method.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 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"
28 #include "ui/events/event.h" 26 #include "ui/events/event.h"
29 #include "ui/events/event_utils.h" 27 #include "ui/events/event_utils.h"
30 #include "ui/events/keycodes/dom/dom_code.h" 28 #include "ui/events/keycodes/dom/dom_code.h"
31 #include "ui/events/keycodes/dom/keycode_converter.h" 29 #include "ui/events/keycodes/dom/keycode_converter.h"
32 #include "ui/events/test/events_test_utils_x11.h" 30 #include "ui/events/test/events_test_utils_x11.h"
33 #include "ui/gfx/geometry/rect.h" 31 #include "ui/gfx/geometry/rect.h"
34 32
35 using base::UTF8ToUTF16; 33 using base::UTF8ToUTF16;
36 using base::UTF16ToUTF8; 34 using base::UTF16ToUTF8;
37 35
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 new chromeos::MockIMEEngineHandler()); 211 new chromeos::MockIMEEngineHandler());
214 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( 212 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(
215 mock_ime_engine_handler_.get()); 213 mock_ime_engine_handler_.get());
216 214
217 mock_ime_candidate_window_handler_.reset( 215 mock_ime_candidate_window_handler_.reset(
218 new chromeos::MockIMECandidateWindowHandler()); 216 new chromeos::MockIMECandidateWindowHandler());
219 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( 217 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(
220 mock_ime_candidate_window_handler_.get()); 218 mock_ime_candidate_window_handler_.get());
221 219
222 ime_.reset(new TestableInputMethodChromeOS(this)); 220 ime_.reset(new TestableInputMethodChromeOS(this));
223 if (switches::IsTextInputFocusManagerEnabled()) 221 ime_->SetFocusedTextInputClient(this);
224 TextInputFocusManager::GetInstance()->FocusTextInputClient(this);
225 else
226 ime_->SetFocusedTextInputClient(this);
227 } 222 }
228 223
229 void TearDown() override { 224 void TearDown() override {
230 if (ime_.get()) { 225 if (ime_.get())
231 if (switches::IsTextInputFocusManagerEnabled()) 226 ime_->SetFocusedTextInputClient(NULL);
232 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
233 else
234 ime_->SetFocusedTextInputClient(NULL);
235 }
236 ime_.reset(); 227 ime_.reset();
237 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); 228 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL);
238 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); 229 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL);
239 mock_ime_engine_handler_.reset(); 230 mock_ime_engine_handler_.reset();
240 mock_ime_candidate_window_handler_.reset(); 231 mock_ime_candidate_window_handler_.reset();
241 chromeos::IMEBridge::Shutdown(); 232 chromeos::IMEBridge::Shutdown();
242 233
243 ResetFlags(); 234 ResetFlags();
244 } 235 }
245 236
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ime_->OnFocus(); 361 ime_->OnFocus();
371 EXPECT_TRUE(ime_->CanComposeInline()); 362 EXPECT_TRUE(ime_->CanComposeInline());
372 can_compose_inline_ = false; 363 can_compose_inline_ = false;
373 ime_->OnTextInputTypeChanged(this); 364 ime_->OnTextInputTypeChanged(this);
374 EXPECT_FALSE(ime_->CanComposeInline()); 365 EXPECT_FALSE(ime_->CanComposeInline());
375 } 366 }
376 367
377 TEST_F(InputMethodChromeOSTest, GetTextInputClient) { 368 TEST_F(InputMethodChromeOSTest, GetTextInputClient) {
378 ime_->OnFocus(); 369 ime_->OnFocus();
379 EXPECT_EQ(this, ime_->GetTextInputClient()); 370 EXPECT_EQ(this, ime_->GetTextInputClient());
380 if (switches::IsTextInputFocusManagerEnabled()) 371 ime_->SetFocusedTextInputClient(NULL);
381 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
382 else
383 ime_->SetFocusedTextInputClient(NULL);
384 EXPECT_EQ(NULL, ime_->GetTextInputClient()); 372 EXPECT_EQ(NULL, ime_->GetTextInputClient());
385 } 373 }
386 374
387 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) { 375 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) {
388 ime_->OnFocus(); 376 ime_->OnFocus();
389 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 377 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
390 if (switches::IsTextInputFocusManagerEnabled()) 378 ime_->SetFocusedTextInputClient(NULL);
391 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
392 else
393 ime_->SetFocusedTextInputClient(NULL);
394 input_type_ = TEXT_INPUT_TYPE_PASSWORD; 379 input_type_ = TEXT_INPUT_TYPE_PASSWORD;
395 ime_->OnTextInputTypeChanged(this); 380 ime_->OnTextInputTypeChanged(this);
396 // The OnTextInputTypeChanged() call above should be ignored since |this| is 381 // The OnTextInputTypeChanged() call above should be ignored since |this| is
397 // not the current focused client. 382 // not the current focused client.
398 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 383 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
399 384
400 if (switches::IsTextInputFocusManagerEnabled()) 385 ime_->SetFocusedTextInputClient(this);
401 TextInputFocusManager::GetInstance()->FocusTextInputClient(this);
402 else
403 ime_->SetFocusedTextInputClient(this);
404 ime_->OnTextInputTypeChanged(this); 386 ime_->OnTextInputTypeChanged(this);
405 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); 387 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType());
406 } 388 }
407 389
408 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) { 390 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) {
409 ime_->OnFocus(); 391 ime_->OnFocus();
410 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 392 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
411 if (switches::IsTextInputFocusManagerEnabled()) 393 ime_->OnBlur();
412 TextInputFocusManager::GetInstance()->BlurTextInputClient(this);
413 else
414 ime_->OnBlur();
415 input_type_ = TEXT_INPUT_TYPE_PASSWORD; 394 input_type_ = TEXT_INPUT_TYPE_PASSWORD;
416 ime_->OnTextInputTypeChanged(this); 395 ime_->OnTextInputTypeChanged(this);
417 // The OnTextInputTypeChanged() call above should be ignored since the top- 396 // The OnTextInputTypeChanged() call above should be ignored since the top-
418 // level window which the ime_ is attached to is not currently focused. 397 // level window which the ime_ is attached to is not currently focused.
419 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 398 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
420 399
421 if (switches::IsTextInputFocusManagerEnabled()) 400 ime_->OnFocus();
422 TextInputFocusManager::GetInstance()->FocusTextInputClient(this);
423 else
424 ime_->OnFocus();
425 ime_->OnTextInputTypeChanged(this); 401 ime_->OnTextInputTypeChanged(this);
426 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); 402 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType());
427 } 403 }
428 404
429 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) { 405 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) {
430 if (switches::IsTextInputFocusManagerEnabled())
431 return;
432
433 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 406 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
434 input_type_ = TEXT_INPUT_TYPE_PASSWORD; 407 input_type_ = TEXT_INPUT_TYPE_PASSWORD;
435 ime_->OnTextInputTypeChanged(this); 408 ime_->OnTextInputTypeChanged(this);
436 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); 409 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType());
437 410
438 ime_->OnFocus(); 411 ime_->OnFocus();
439 ime_->OnTextInputTypeChanged(this); 412 ime_->OnTextInputTypeChanged(this);
440 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); 413 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType());
441 } 414 }
442 415
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 ime_->OnTextInputTypeChanged(this); 506 ime_->OnTextInputTypeChanged(this);
534 // Confirm that both FocusIn and FocusOut are called and the TextInputType is 507 // Confirm that both FocusIn and FocusOut are called and the TextInputType is
535 // changed to URL. 508 // changed to URL.
536 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); 509 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count());
537 EXPECT_EQ(2, mock_ime_engine_handler_->focus_out_call_count()); 510 EXPECT_EQ(2, mock_ime_engine_handler_->focus_out_call_count());
538 EXPECT_EQ(TEXT_INPUT_TYPE_URL, 511 EXPECT_EQ(TEXT_INPUT_TYPE_URL,
539 mock_ime_engine_handler_->last_text_input_context().type); 512 mock_ime_engine_handler_->last_text_input_context().type);
540 EXPECT_EQ(TEXT_INPUT_MODE_KANA, 513 EXPECT_EQ(TEXT_INPUT_MODE_KANA,
541 mock_ime_engine_handler_->last_text_input_context().mode); 514 mock_ime_engine_handler_->last_text_input_context().mode);
542 515
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. 516 // Confirm that FocusOut is called when set focus to NULL client.
548 ime_->SetFocusedTextInputClient(NULL); 517 ime_->SetFocusedTextInputClient(NULL);
549 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); 518 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count());
550 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); 519 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count());
551 // Confirm that FocusIn is called when set focus to this client. 520 // Confirm that FocusIn is called when set focus to this client.
552 ime_->SetFocusedTextInputClient(this); 521 ime_->SetFocusedTextInputClient(this);
553 EXPECT_EQ(4, mock_ime_engine_handler_->focus_in_call_count()); 522 EXPECT_EQ(4, mock_ime_engine_handler_->focus_in_call_count());
554 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); 523 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count());
555 } 524 }
556 525
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 EXPECT_EQ(ui::VKEY_C, stored_event->key_code()); 977 EXPECT_EQ(ui::VKEY_C, stored_event->key_code());
1009 EXPECT_EQ(kFlags, stored_event->flags()); 978 EXPECT_EQ(kFlags, stored_event->flags());
1010 EXPECT_FALSE(ime_->process_key_event_post_ime_args().handled); 979 EXPECT_FALSE(ime_->process_key_event_post_ime_args().handled);
1011 980
1012 EXPECT_EQ(L'C', inserted_char_); 981 EXPECT_EQ(L'C', inserted_char_);
1013 } 982 }
1014 983
1015 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). 984 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593).
1016 985
1017 } // namespace ui 986 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_base_unittest.cc ('k') | ui/base/ime/mock_input_method.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698