| OLD | NEW |
| 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/remote_input_method_win.h" | 5 #include "ui/base/ime/remote_input_method_win.h" |
| 6 | 6 |
| 7 #include <InputScope.h> | 7 #include <InputScope.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 328 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 329 | 329 |
| 330 RemoteInputMethodPrivateWin* private_ptr = | 330 RemoteInputMethodPrivateWin* private_ptr = |
| 331 RemoteInputMethodPrivateWin::Get(input_method.get()); | 331 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 332 ASSERT_TRUE(private_ptr != NULL); | 332 ASSERT_TRUE(private_ptr != NULL); |
| 333 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 333 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 334 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 334 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 335 | 335 |
| 336 // Initial state must be synced. | 336 // Initial state must be synced. |
| 337 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 337 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 338 ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); | 338 ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); |
| 339 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), | 339 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), |
| 340 mock_remote_delegate.composition_character_bounds()[0]); | 340 mock_remote_delegate.composition_character_bounds()[0]); |
| 341 ASSERT_EQ(1, mock_remote_delegate.input_scopes().size()); | 341 ASSERT_EQ(1u, mock_remote_delegate.input_scopes().size()); |
| 342 EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); | 342 EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); |
| 343 | 343 |
| 344 // State must be cleared by SetFocusedTextInputClient(NULL). | 344 // State must be cleared by SetFocusedTextInputClient(NULL). |
| 345 mock_remote_delegate.Reset(); | 345 mock_remote_delegate.Reset(); |
| 346 input_method->SetFocusedTextInputClient(NULL); | 346 input_method->SetFocusedTextInputClient(NULL); |
| 347 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 347 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 348 EXPECT_TRUE(mock_remote_delegate.composition_character_bounds().empty()); | 348 EXPECT_TRUE(mock_remote_delegate.composition_character_bounds().empty()); |
| 349 EXPECT_TRUE(mock_remote_delegate.input_scopes().empty()); | 349 EXPECT_TRUE(mock_remote_delegate.input_scopes().empty()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 TEST(RemoteInputMethodWinTest, DetachTextInputClient) { | 352 TEST(RemoteInputMethodWinTest, DetachTextInputClient) { |
| 353 MockInputMethodDelegate delegate_; | 353 MockInputMethodDelegate delegate_; |
| 354 MockTextInputClient mock_text_input_client; | 354 MockTextInputClient mock_text_input_client; |
| 355 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 355 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 356 | 356 |
| 357 mock_text_input_client.set_caret_bounds(gfx::Rect(10, 0, 10, 20)); | 357 mock_text_input_client.set_caret_bounds(gfx::Rect(10, 0, 10, 20)); |
| 358 mock_text_input_client.set_text_input_type(ui::TEXT_INPUT_TYPE_URL); | 358 mock_text_input_client.set_text_input_type(ui::TEXT_INPUT_TYPE_URL); |
| 359 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 359 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 360 | 360 |
| 361 RemoteInputMethodPrivateWin* private_ptr = | 361 RemoteInputMethodPrivateWin* private_ptr = |
| 362 RemoteInputMethodPrivateWin::Get(input_method.get()); | 362 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 363 ASSERT_TRUE(private_ptr != NULL); | 363 ASSERT_TRUE(private_ptr != NULL); |
| 364 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 364 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 365 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 365 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 366 | 366 |
| 367 // Initial state must be synced. | 367 // Initial state must be synced. |
| 368 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 368 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 369 ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); | 369 ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); |
| 370 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), | 370 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), |
| 371 mock_remote_delegate.composition_character_bounds()[0]); | 371 mock_remote_delegate.composition_character_bounds()[0]); |
| 372 ASSERT_EQ(1, mock_remote_delegate.input_scopes().size()); | 372 ASSERT_EQ(1u, mock_remote_delegate.input_scopes().size()); |
| 373 EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); | 373 EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); |
| 374 | 374 |
| 375 // State must be cleared by DetachTextInputClient | 375 // State must be cleared by DetachTextInputClient |
| 376 mock_remote_delegate.Reset(); | 376 mock_remote_delegate.Reset(); |
| 377 input_method->DetachTextInputClient(&mock_text_input_client); | 377 input_method->DetachTextInputClient(&mock_text_input_client); |
| 378 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 378 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 379 EXPECT_TRUE(mock_remote_delegate.composition_character_bounds().empty()); | 379 EXPECT_TRUE(mock_remote_delegate.composition_character_bounds().empty()); |
| 380 EXPECT_TRUE(mock_remote_delegate.input_scopes().empty()); | 380 EXPECT_TRUE(mock_remote_delegate.input_scopes().empty()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST(RemoteInputMethodWinTest, OnCaretBoundsChanged) { | 383 TEST(RemoteInputMethodWinTest, OnCaretBoundsChanged) { |
| 384 MockInputMethodDelegate delegate_; | 384 MockInputMethodDelegate delegate_; |
| 385 MockTextInputClient mock_text_input_client; | 385 MockTextInputClient mock_text_input_client; |
| 386 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 386 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 387 | 387 |
| 388 // This must not cause a crash. | 388 // This must not cause a crash. |
| 389 input_method->OnCaretBoundsChanged(&mock_text_input_client); | 389 input_method->OnCaretBoundsChanged(&mock_text_input_client); |
| 390 | 390 |
| 391 mock_text_input_client.set_caret_bounds(gfx::Rect(10, 0, 10, 20)); | 391 mock_text_input_client.set_caret_bounds(gfx::Rect(10, 0, 10, 20)); |
| 392 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 392 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 393 | 393 |
| 394 RemoteInputMethodPrivateWin* private_ptr = | 394 RemoteInputMethodPrivateWin* private_ptr = |
| 395 RemoteInputMethodPrivateWin::Get(input_method.get()); | 395 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 396 ASSERT_TRUE(private_ptr != NULL); | 396 ASSERT_TRUE(private_ptr != NULL); |
| 397 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 397 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 398 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 398 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 399 | 399 |
| 400 // Initial state must be synced. | 400 // Initial state must be synced. |
| 401 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 401 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 402 ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); | 402 ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); |
| 403 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), | 403 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), |
| 404 mock_remote_delegate.composition_character_bounds()[0]); | 404 mock_remote_delegate.composition_character_bounds()[0]); |
| 405 | 405 |
| 406 // Redundant OnCaretBoundsChanged must be ignored. | 406 // Redundant OnCaretBoundsChanged must be ignored. |
| 407 mock_remote_delegate.Reset(); | 407 mock_remote_delegate.Reset(); |
| 408 input_method->OnCaretBoundsChanged(&mock_text_input_client); | 408 input_method->OnCaretBoundsChanged(&mock_text_input_client); |
| 409 EXPECT_FALSE(mock_remote_delegate.text_input_client_updated_called()); | 409 EXPECT_FALSE(mock_remote_delegate.text_input_client_updated_called()); |
| 410 | 410 |
| 411 // Check OnCaretBoundsChanged is handled. (w/o composition) | 411 // Check OnCaretBoundsChanged is handled. (w/o composition) |
| 412 mock_remote_delegate.Reset(); | 412 mock_remote_delegate.Reset(); |
| 413 mock_text_input_client.Reset(); | 413 mock_text_input_client.Reset(); |
| 414 mock_text_input_client.set_caret_bounds(gfx::Rect(10, 20, 30, 40)); | 414 mock_text_input_client.set_caret_bounds(gfx::Rect(10, 20, 30, 40)); |
| 415 input_method->OnCaretBoundsChanged(&mock_text_input_client); | 415 input_method->OnCaretBoundsChanged(&mock_text_input_client); |
| 416 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 416 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 417 ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); | 417 ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); |
| 418 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), | 418 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), |
| 419 mock_remote_delegate.composition_character_bounds()[0]); | 419 mock_remote_delegate.composition_character_bounds()[0]); |
| 420 | 420 |
| 421 // Check OnCaretBoundsChanged is handled. (w/ composition) | 421 // Check OnCaretBoundsChanged is handled. (w/ composition) |
| 422 { | 422 { |
| 423 mock_remote_delegate.Reset(); | 423 mock_remote_delegate.Reset(); |
| 424 mock_text_input_client.Reset(); | 424 mock_text_input_client.Reset(); |
| 425 | 425 |
| 426 std::vector<gfx::Rect> bounds; | 426 std::vector<gfx::Rect> bounds; |
| 427 bounds.push_back(gfx::Rect(10, 20, 30, 40)); | 427 bounds.push_back(gfx::Rect(10, 20, 30, 40)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 477 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 478 | 478 |
| 479 RemoteInputMethodPrivateWin* private_ptr = | 479 RemoteInputMethodPrivateWin* private_ptr = |
| 480 RemoteInputMethodPrivateWin::Get(input_method.get()); | 480 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 481 ASSERT_TRUE(private_ptr != NULL); | 481 ASSERT_TRUE(private_ptr != NULL); |
| 482 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 482 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 483 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 483 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 484 | 484 |
| 485 // Initial state must be synced. | 485 // Initial state must be synced. |
| 486 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 486 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 487 ASSERT_EQ(1, mock_remote_delegate.input_scopes().size()); | 487 ASSERT_EQ(1u, mock_remote_delegate.input_scopes().size()); |
| 488 EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); | 488 EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); |
| 489 | 489 |
| 490 // Check TEXT_INPUT_TYPE_NONE is handled. | 490 // Check TEXT_INPUT_TYPE_NONE is handled. |
| 491 mock_remote_delegate.Reset(); | 491 mock_remote_delegate.Reset(); |
| 492 mock_text_input_client.Reset(); | 492 mock_text_input_client.Reset(); |
| 493 mock_text_input_client.set_text_input_type(ui::TEXT_INPUT_TYPE_NONE); | 493 mock_text_input_client.set_text_input_type(ui::TEXT_INPUT_TYPE_NONE); |
| 494 mock_text_input_client.set_text_input_mode(ui::TEXT_INPUT_MODE_KATAKANA); | 494 mock_text_input_client.set_text_input_mode(ui::TEXT_INPUT_MODE_KATAKANA); |
| 495 input_method->OnTextInputTypeChanged(&mock_text_input_client); | 495 input_method->OnTextInputTypeChanged(&mock_text_input_client); |
| 496 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); | 496 EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); |
| 497 EXPECT_TRUE(mock_remote_delegate.input_scopes().empty()); | 497 EXPECT_TRUE(mock_remote_delegate.input_scopes().empty()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 609 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 610 | 610 |
| 611 ui::KeyEvent new_keydown(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 611 ui::KeyEvent new_keydown(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 612 new_keydown.set_character(L'A'); | 612 new_keydown.set_character(L'A'); |
| 613 ui::KeyEvent fabricated_keydown(new_keydown); | 613 ui::KeyEvent fabricated_keydown(new_keydown); |
| 614 | 614 |
| 615 // This must not cause a crash. | 615 // This must not cause a crash. |
| 616 input_method->DispatchKeyEvent(&fabricated_keydown); | 616 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 617 EXPECT_TRUE(fabricated_keydown.handled()); | 617 EXPECT_TRUE(fabricated_keydown.handled()); |
| 618 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 618 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 619 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 619 ASSERT_EQ(1u, delegate_.fabricated_key_events().size()); |
| 620 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 620 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
| 621 delegate_.Reset(); | 621 delegate_.Reset(); |
| 622 mock_text_input_client.Reset(); | 622 mock_text_input_client.Reset(); |
| 623 | 623 |
| 624 RemoteInputMethodPrivateWin* private_ptr = | 624 RemoteInputMethodPrivateWin* private_ptr = |
| 625 RemoteInputMethodPrivateWin::Get(input_method.get()); | 625 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 626 ASSERT_TRUE(private_ptr != NULL); | 626 ASSERT_TRUE(private_ptr != NULL); |
| 627 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 627 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 628 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 628 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 629 | 629 |
| 630 // TextInputClient is not focused yet here. | 630 // TextInputClient is not focused yet here. |
| 631 fabricated_keydown = new_keydown; | 631 fabricated_keydown = new_keydown; |
| 632 input_method->DispatchKeyEvent(&fabricated_keydown); | 632 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 633 EXPECT_TRUE(fabricated_keydown.handled()); | 633 EXPECT_TRUE(fabricated_keydown.handled()); |
| 634 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 634 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 635 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 635 ASSERT_EQ(1u, delegate_.fabricated_key_events().size()); |
| 636 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 636 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
| 637 delegate_.Reset(); | 637 delegate_.Reset(); |
| 638 mock_text_input_client.Reset(); | 638 mock_text_input_client.Reset(); |
| 639 | 639 |
| 640 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 640 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 641 // TextInputClient is now focused here. | 641 // TextInputClient is now focused here. |
| 642 fabricated_keydown = new_keydown; | 642 fabricated_keydown = new_keydown; |
| 643 input_method->DispatchKeyEvent(&fabricated_keydown); | 643 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 644 EXPECT_TRUE(fabricated_keydown.handled()); | 644 EXPECT_TRUE(fabricated_keydown.handled()); |
| 645 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 645 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 646 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 646 ASSERT_EQ(1u, delegate_.fabricated_key_events().size()); |
| 647 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 647 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
| 648 delegate_.Reset(); | 648 delegate_.Reset(); |
| 649 mock_text_input_client.Reset(); | 649 mock_text_input_client.Reset(); |
| 650 | 650 |
| 651 input_method->SetDelegate(NULL); | 651 input_method->SetDelegate(NULL); |
| 652 // RemoteInputMethodDelegateWin is no longer set here. | 652 // RemoteInputMethodDelegateWin is no longer set here. |
| 653 fabricated_keydown = new_keydown; | 653 fabricated_keydown = new_keydown; |
| 654 input_method->DispatchKeyEvent(&fabricated_keydown); | 654 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 655 EXPECT_FALSE(fabricated_keydown.handled()); | 655 EXPECT_FALSE(fabricated_keydown.handled()); |
| 656 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 656 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 RemoteInputMethodPrivateWin::Get(input_method.get()); | 711 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 712 ASSERT_TRUE(private_ptr != NULL); | 712 ASSERT_TRUE(private_ptr != NULL); |
| 713 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 713 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 714 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 714 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 715 | 715 |
| 716 CompositionText composition_text; | 716 CompositionText composition_text; |
| 717 | 717 |
| 718 // TextInputClient is not focused yet here. | 718 // TextInputClient is not focused yet here. |
| 719 | 719 |
| 720 private_ptr->OnCompositionChanged(composition_text); | 720 private_ptr->OnCompositionChanged(composition_text); |
| 721 EXPECT_EQ(0, mock_text_input_client.call_count_set_composition_text()); | 721 EXPECT_EQ(0u, mock_text_input_client.call_count_set_composition_text()); |
| 722 delegate_.Reset(); | 722 delegate_.Reset(); |
| 723 mock_text_input_client.Reset(); | 723 mock_text_input_client.Reset(); |
| 724 | 724 |
| 725 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 725 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 726 | 726 |
| 727 // TextInputClient is now focused here. | 727 // TextInputClient is now focused here. |
| 728 | 728 |
| 729 private_ptr->OnCompositionChanged(composition_text); | 729 private_ptr->OnCompositionChanged(composition_text); |
| 730 EXPECT_EQ(1, mock_text_input_client.call_count_set_composition_text()); | 730 EXPECT_EQ(1u, mock_text_input_client.call_count_set_composition_text()); |
| 731 delegate_.Reset(); | 731 delegate_.Reset(); |
| 732 mock_text_input_client.Reset(); | 732 mock_text_input_client.Reset(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 TEST(RemoteInputMethodWinTest, OnTextCommitted) { | 735 TEST(RemoteInputMethodWinTest, OnTextCommitted) { |
| 736 MockInputMethodDelegate delegate_; | 736 MockInputMethodDelegate delegate_; |
| 737 MockTextInputClient mock_text_input_client; | 737 MockTextInputClient mock_text_input_client; |
| 738 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 738 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 739 | 739 |
| 740 RemoteInputMethodPrivateWin* private_ptr = | 740 RemoteInputMethodPrivateWin* private_ptr = |
| 741 RemoteInputMethodPrivateWin::Get(input_method.get()); | 741 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 742 ASSERT_TRUE(private_ptr != NULL); | 742 ASSERT_TRUE(private_ptr != NULL); |
| 743 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 743 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 744 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 744 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 745 | 745 |
| 746 base::string16 committed_text = L"Hello"; | 746 base::string16 committed_text = L"Hello"; |
| 747 | 747 |
| 748 // TextInputClient is not focused yet here. | 748 // TextInputClient is not focused yet here. |
| 749 | 749 |
| 750 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT); | 750 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT); |
| 751 private_ptr->OnTextCommitted(committed_text); | 751 private_ptr->OnTextCommitted(committed_text); |
| 752 EXPECT_EQ(0, mock_text_input_client.call_count_insert_char()); | 752 EXPECT_EQ(0u, mock_text_input_client.call_count_insert_char()); |
| 753 EXPECT_EQ(0, mock_text_input_client.call_count_insert_text()); | 753 EXPECT_EQ(0u, mock_text_input_client.call_count_insert_text()); |
| 754 EXPECT_EQ(L"", mock_text_input_client.inserted_text()); | 754 EXPECT_EQ(L"", mock_text_input_client.inserted_text()); |
| 755 delegate_.Reset(); | 755 delegate_.Reset(); |
| 756 mock_text_input_client.Reset(); | 756 mock_text_input_client.Reset(); |
| 757 | 757 |
| 758 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 758 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 759 | 759 |
| 760 // TextInputClient is now focused here. | 760 // TextInputClient is now focused here. |
| 761 | 761 |
| 762 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT); | 762 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT); |
| 763 private_ptr->OnTextCommitted(committed_text); | 763 private_ptr->OnTextCommitted(committed_text); |
| 764 EXPECT_EQ(0, mock_text_input_client.call_count_insert_char()); | 764 EXPECT_EQ(0u, mock_text_input_client.call_count_insert_char()); |
| 765 EXPECT_EQ(1, mock_text_input_client.call_count_insert_text()); | 765 EXPECT_EQ(1u, mock_text_input_client.call_count_insert_text()); |
| 766 EXPECT_EQ(committed_text, mock_text_input_client.inserted_text()); | 766 EXPECT_EQ(committed_text, mock_text_input_client.inserted_text()); |
| 767 delegate_.Reset(); | 767 delegate_.Reset(); |
| 768 mock_text_input_client.Reset(); | 768 mock_text_input_client.Reset(); |
| 769 | 769 |
| 770 // When TextInputType is TEXT_INPUT_TYPE_NONE, TextInputClient::InsertText | 770 // When TextInputType is TEXT_INPUT_TYPE_NONE, TextInputClient::InsertText |
| 771 // should not be used. | 771 // should not be used. |
| 772 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_NONE); | 772 mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_NONE); |
| 773 private_ptr->OnTextCommitted(committed_text); | 773 private_ptr->OnTextCommitted(committed_text); |
| 774 EXPECT_EQ(committed_text.size(), | 774 EXPECT_EQ(committed_text.size(), |
| 775 mock_text_input_client.call_count_insert_char()); | 775 mock_text_input_client.call_count_insert_char()); |
| 776 EXPECT_EQ(0, mock_text_input_client.call_count_insert_text()); | 776 EXPECT_EQ(0u, mock_text_input_client.call_count_insert_text()); |
| 777 EXPECT_EQ(committed_text, mock_text_input_client.inserted_text()); | 777 EXPECT_EQ(committed_text, mock_text_input_client.inserted_text()); |
| 778 delegate_.Reset(); | 778 delegate_.Reset(); |
| 779 mock_text_input_client.Reset(); | 779 mock_text_input_client.Reset(); |
| 780 } | 780 } |
| 781 | 781 |
| 782 TEST(RemoteInputMethodWinTest, OnTextInputStateChanged_Observer) { | 782 TEST(RemoteInputMethodWinTest, OnTextInputStateChanged_Observer) { |
| 783 DummyTextInputClient text_input_client; | 783 DummyTextInputClient text_input_client; |
| 784 DummyTextInputClient text_input_client_the_other; | 784 DummyTextInputClient text_input_client_the_other; |
| 785 | 785 |
| 786 MockInputMethodObserver input_method_observer; | 786 MockInputMethodObserver input_method_observer; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 821 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 822 input_method->AddObserver(&input_method_observer); | 822 input_method->AddObserver(&input_method_observer); |
| 823 | 823 |
| 824 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); | 824 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); |
| 825 input_method.reset(); | 825 input_method.reset(); |
| 826 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); | 826 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); |
| 827 } | 827 } |
| 828 | 828 |
| 829 } // namespace | 829 } // namespace |
| 830 } // namespace ui | 830 } // namespace ui |
| OLD | NEW |