OLD | NEW |
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 "chromeos/ime/composition_text.h" | 18 #include "chromeos/ime/composition_text.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.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/input_method_delegate.h" | 23 #include "ui/base/ime/input_method_delegate.h" |
24 #include "ui/base/ime/text_input_client.h" | 24 #include "ui/base/ime/text_input_client.h" |
| 25 #include "ui/base/ime/text_input_focus_manager.h" |
| 26 #include "ui/base/ui_base_switches_util.h" |
25 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
26 #include "ui/events/test/events_test_utils_x11.h" | 28 #include "ui/events/test/events_test_utils_x11.h" |
27 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
28 | 30 |
29 using base::UTF8ToUTF16; | 31 using base::UTF8ToUTF16; |
30 using base::UTF16ToUTF8; | 32 using base::UTF16ToUTF8; |
31 | 33 |
32 namespace ui { | 34 namespace ui { |
33 namespace { | 35 namespace { |
34 | 36 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 new chromeos::MockIMEEngineHandler()); | 217 new chromeos::MockIMEEngineHandler()); |
216 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( | 218 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( |
217 mock_ime_engine_handler_.get()); | 219 mock_ime_engine_handler_.get()); |
218 | 220 |
219 mock_ime_candidate_window_handler_.reset( | 221 mock_ime_candidate_window_handler_.reset( |
220 new chromeos::MockIMECandidateWindowHandler()); | 222 new chromeos::MockIMECandidateWindowHandler()); |
221 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( | 223 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( |
222 mock_ime_candidate_window_handler_.get()); | 224 mock_ime_candidate_window_handler_.get()); |
223 | 225 |
224 ime_.reset(new TestableInputMethodChromeOS(this)); | 226 ime_.reset(new TestableInputMethodChromeOS(this)); |
225 ime_->SetFocusedTextInputClient(this); | 227 if (switches::IsTextInputFocusManagerEnabled()) |
| 228 TextInputFocusManager::GetInstance()->FocusTextInputClient(this); |
| 229 else |
| 230 ime_->SetFocusedTextInputClient(this); |
226 } | 231 } |
227 | 232 |
228 virtual void TearDown() OVERRIDE { | 233 virtual void TearDown() OVERRIDE { |
229 if (ime_.get()) | 234 if (ime_.get()) { |
230 ime_->SetFocusedTextInputClient(NULL); | 235 if (switches::IsTextInputFocusManagerEnabled()) |
| 236 TextInputFocusManager::GetInstance()->BlurTextInputClient(this); |
| 237 else |
| 238 ime_->SetFocusedTextInputClient(NULL); |
| 239 } |
231 ime_.reset(); | 240 ime_.reset(); |
232 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); | 241 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
233 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); | 242 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); |
234 mock_ime_engine_handler_.reset(); | 243 mock_ime_engine_handler_.reset(); |
235 mock_ime_candidate_window_handler_.reset(); | 244 mock_ime_candidate_window_handler_.reset(); |
236 chromeos::IMEBridge::Shutdown(); | 245 chromeos::IMEBridge::Shutdown(); |
237 } | 246 } |
238 | 247 |
239 // Overridden from ui::internal::InputMethodDelegate: | 248 // Overridden from ui::internal::InputMethodDelegate: |
240 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE { | 249 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 ime_->Init(true); | 410 ime_->Init(true); |
402 EXPECT_TRUE(ime_->CanComposeInline()); | 411 EXPECT_TRUE(ime_->CanComposeInline()); |
403 can_compose_inline_ = false; | 412 can_compose_inline_ = false; |
404 ime_->OnTextInputTypeChanged(this); | 413 ime_->OnTextInputTypeChanged(this); |
405 EXPECT_FALSE(ime_->CanComposeInline()); | 414 EXPECT_FALSE(ime_->CanComposeInline()); |
406 } | 415 } |
407 | 416 |
408 TEST_F(InputMethodChromeOSTest, GetTextInputClient) { | 417 TEST_F(InputMethodChromeOSTest, GetTextInputClient) { |
409 ime_->Init(true); | 418 ime_->Init(true); |
410 EXPECT_EQ(this, ime_->GetTextInputClient()); | 419 EXPECT_EQ(this, ime_->GetTextInputClient()); |
411 ime_->SetFocusedTextInputClient(NULL); | 420 if (switches::IsTextInputFocusManagerEnabled()) |
| 421 TextInputFocusManager::GetInstance()->BlurTextInputClient(this); |
| 422 else |
| 423 ime_->SetFocusedTextInputClient(NULL); |
412 EXPECT_EQ(NULL, ime_->GetTextInputClient()); | 424 EXPECT_EQ(NULL, ime_->GetTextInputClient()); |
413 } | 425 } |
414 | 426 |
415 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) { | 427 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedClient) { |
416 ime_->Init(true); | 428 ime_->Init(true); |
417 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); | 429 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); |
418 ime_->SetFocusedTextInputClient(NULL); | 430 if (switches::IsTextInputFocusManagerEnabled()) |
| 431 TextInputFocusManager::GetInstance()->BlurTextInputClient(this); |
| 432 else |
| 433 ime_->SetFocusedTextInputClient(NULL); |
419 input_type_ = TEXT_INPUT_TYPE_PASSWORD; | 434 input_type_ = TEXT_INPUT_TYPE_PASSWORD; |
420 ime_->OnTextInputTypeChanged(this); | 435 ime_->OnTextInputTypeChanged(this); |
421 // The OnTextInputTypeChanged() call above should be ignored since |this| is | 436 // The OnTextInputTypeChanged() call above should be ignored since |this| is |
422 // not the current focused client. | 437 // not the current focused client. |
423 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); | 438 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); |
424 | 439 |
425 ime_->SetFocusedTextInputClient(this); | 440 if (switches::IsTextInputFocusManagerEnabled()) |
| 441 TextInputFocusManager::GetInstance()->FocusTextInputClient(this); |
| 442 else |
| 443 ime_->SetFocusedTextInputClient(this); |
426 ime_->OnTextInputTypeChanged(this); | 444 ime_->OnTextInputTypeChanged(this); |
427 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); | 445 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); |
428 } | 446 } |
429 | 447 |
430 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) { | 448 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow) { |
431 ime_->Init(true); | 449 ime_->Init(true); |
432 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); | 450 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); |
433 ime_->OnBlur(); | 451 if (switches::IsTextInputFocusManagerEnabled()) |
| 452 TextInputFocusManager::GetInstance()->BlurTextInputClient(this); |
| 453 else |
| 454 ime_->OnBlur(); |
434 input_type_ = TEXT_INPUT_TYPE_PASSWORD; | 455 input_type_ = TEXT_INPUT_TYPE_PASSWORD; |
435 ime_->OnTextInputTypeChanged(this); | 456 ime_->OnTextInputTypeChanged(this); |
436 // The OnTextInputTypeChanged() call above should be ignored since the top- | 457 // The OnTextInputTypeChanged() call above should be ignored since the top- |
437 // level window which the ime_ is attached to is not currently focused. | 458 // level window which the ime_ is attached to is not currently focused. |
438 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); | 459 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); |
439 | 460 |
440 ime_->OnFocus(); | 461 if (switches::IsTextInputFocusManagerEnabled()) |
| 462 TextInputFocusManager::GetInstance()->FocusTextInputClient(this); |
| 463 else |
| 464 ime_->OnFocus(); |
441 ime_->OnTextInputTypeChanged(this); | 465 ime_->OnTextInputTypeChanged(this); |
442 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); | 466 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); |
443 } | 467 } |
444 | 468 |
445 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) { | 469 TEST_F(InputMethodChromeOSTest, GetInputTextType_WithoutFocusedWindow2) { |
| 470 // We no longer support the case that |ime_->Init(false)| because no one |
| 471 // actually uses it. |
| 472 if (switches::IsTextInputFocusManagerEnabled()) |
| 473 return; |
| 474 |
446 ime_->Init(false); // the top-level is initially unfocused. | 475 ime_->Init(false); // the top-level is initially unfocused. |
447 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); | 476 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); |
448 input_type_ = TEXT_INPUT_TYPE_PASSWORD; | 477 input_type_ = TEXT_INPUT_TYPE_PASSWORD; |
449 ime_->OnTextInputTypeChanged(this); | 478 ime_->OnTextInputTypeChanged(this); |
450 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); | 479 EXPECT_EQ(TEXT_INPUT_TYPE_NONE, ime_->GetTextInputType()); |
451 | 480 |
452 ime_->OnFocus(); | 481 ime_->OnFocus(); |
453 ime_->OnTextInputTypeChanged(this); | 482 ime_->OnTextInputTypeChanged(this); |
454 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); | 483 EXPECT_EQ(TEXT_INPUT_TYPE_PASSWORD, ime_->GetTextInputType()); |
455 } | 484 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 input_type_ = TEXT_INPUT_TYPE_URL; | 575 input_type_ = TEXT_INPUT_TYPE_URL; |
547 ime_->OnTextInputTypeChanged(this); | 576 ime_->OnTextInputTypeChanged(this); |
548 // Confirm that both FocusIn and FocusOut are called and the TextInputType is | 577 // Confirm that both FocusIn and FocusOut are called and the TextInputType is |
549 // changed to URL. | 578 // changed to URL. |
550 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); | 579 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); |
551 EXPECT_EQ(2, mock_ime_engine_handler_->focus_out_call_count()); | 580 EXPECT_EQ(2, mock_ime_engine_handler_->focus_out_call_count()); |
552 EXPECT_EQ(TEXT_INPUT_TYPE_URL, | 581 EXPECT_EQ(TEXT_INPUT_TYPE_URL, |
553 mock_ime_engine_handler_->last_text_input_context().type); | 582 mock_ime_engine_handler_->last_text_input_context().type); |
554 EXPECT_EQ(TEXT_INPUT_MODE_KANA, | 583 EXPECT_EQ(TEXT_INPUT_MODE_KANA, |
555 mock_ime_engine_handler_->last_text_input_context().mode); | 584 mock_ime_engine_handler_->last_text_input_context().mode); |
| 585 |
| 586 // When IsTextInputFocusManagerEnabled, InputMethod::SetFocusedTextInputClient |
| 587 // is not supported and it's no-op. |
| 588 if (switches::IsTextInputFocusManagerEnabled()) |
| 589 return; |
556 // Confirm that FocusOut is called when set focus to NULL client. | 590 // Confirm that FocusOut is called when set focus to NULL client. |
557 ime_->SetFocusedTextInputClient(NULL); | 591 ime_->SetFocusedTextInputClient(NULL); |
558 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); | 592 EXPECT_EQ(3, mock_ime_engine_handler_->focus_in_call_count()); |
559 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); | 593 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); |
560 // Confirm that FocusIn is called when set focus to this client. | 594 // Confirm that FocusIn is called when set focus to this client. |
561 ime_->SetFocusedTextInputClient(this); | 595 ime_->SetFocusedTextInputClient(this); |
562 EXPECT_EQ(4, mock_ime_engine_handler_->focus_in_call_count()); | 596 EXPECT_EQ(4, mock_ime_engine_handler_->focus_in_call_count()); |
563 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); | 597 EXPECT_EQ(3, mock_ime_engine_handler_->focus_out_call_count()); |
564 } | 598 } |
565 | 599 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 ime_->ResetContext(); | 1052 ime_->ResetContext(); |
1019 | 1053 |
1020 // Do callback. | 1054 // Do callback. |
1021 mock_ime_engine_handler_->last_passed_callback().Run(true); | 1055 mock_ime_engine_handler_->last_passed_callback().Run(true); |
1022 | 1056 |
1023 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); | 1057 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); |
1024 } | 1058 } |
1025 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 1059 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). |
1026 | 1060 |
1027 } // namespace ui | 1061 } // namespace ui |
OLD | NEW |