Chromium Code Reviews| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 MockInputMethodDelegate() {} | 131 MockInputMethodDelegate() {} |
| 132 | 132 |
| 133 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { | 133 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { |
| 134 return fabricated_key_events_; | 134 return fabricated_key_events_; |
| 135 } | 135 } |
| 136 void Reset() { | 136 void Reset() { |
| 137 fabricated_key_events_.clear(); | 137 fabricated_key_events_.clear(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { | 141 ui::EventDispatchDetails DispatchKeyEventPostIME( |
| 142 EXPECT_FALSE(event.HasNativeEvent()); | 142 ui::KeyEvent* event) override { |
| 143 fabricated_key_events_.push_back(event.key_code()); | 143 EXPECT_FALSE(event->HasNativeEvent()); |
| 144 return true; | 144 fabricated_key_events_.push_back(event->key_code()); |
| 145 return ui::EventDispatchDetails(); | |
| 145 } | 146 } |
| 146 | 147 |
| 147 std::vector<ui::KeyboardCode> fabricated_key_events_; | 148 std::vector<ui::KeyboardCode> fabricated_key_events_; |
| 148 DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); | 149 DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); |
| 149 }; | 150 }; |
| 150 | 151 |
| 151 class MockRemoteInputMethodDelegateWin | 152 class MockRemoteInputMethodDelegateWin |
| 152 : public internal::RemoteInputMethodDelegateWin { | 153 : public internal::RemoteInputMethodDelegateWin { |
| 153 public: | 154 public: |
| 154 MockRemoteInputMethodDelegateWin() | 155 MockRemoteInputMethodDelegateWin() |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 // Basically RemoteInputMethodWin does not handle native keydown event. | 510 // Basically RemoteInputMethodWin does not handle native keydown event. |
| 510 | 511 |
| 511 MockInputMethodDelegate delegate_; | 512 MockInputMethodDelegate delegate_; |
| 512 MockTextInputClient mock_text_input_client; | 513 MockTextInputClient mock_text_input_client; |
| 513 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 514 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 514 | 515 |
| 515 const MSG wm_keydown = { NULL, WM_KEYDOWN, ui::VKEY_A }; | 516 const MSG wm_keydown = { NULL, WM_KEYDOWN, ui::VKEY_A }; |
| 516 ui::KeyEvent native_keydown(wm_keydown); | 517 ui::KeyEvent native_keydown(wm_keydown); |
| 517 | 518 |
| 518 // This must not cause a crash. | 519 // This must not cause a crash. |
| 519 EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); | 520 input_method->DispatchKeyEvent(&native_keydown); |
|
yukawa
2015/07/30 18:11:39
Does it make sense to check |native_keydown.handle
Shu Chen
2015/07/31 01:18:47
Yes, makes sense. Thanks for catching this.
| |
| 520 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 521 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 521 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 522 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 522 delegate_.Reset(); | 523 delegate_.Reset(); |
| 523 mock_text_input_client.Reset(); | 524 mock_text_input_client.Reset(); |
| 524 | 525 |
| 525 RemoteInputMethodPrivateWin* private_ptr = | 526 RemoteInputMethodPrivateWin* private_ptr = |
| 526 RemoteInputMethodPrivateWin::Get(input_method.get()); | 527 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 527 ASSERT_TRUE(private_ptr != NULL); | 528 ASSERT_TRUE(private_ptr != NULL); |
| 528 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 529 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 529 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 530 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 530 | 531 |
| 531 // TextInputClient is not focused yet here. | 532 // TextInputClient is not focused yet here. |
| 532 | 533 |
| 533 EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); | 534 input_method->DispatchKeyEvent(&native_keydown); |
| 534 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 535 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 535 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 536 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 536 delegate_.Reset(); | 537 delegate_.Reset(); |
| 537 mock_text_input_client.Reset(); | 538 mock_text_input_client.Reset(); |
| 538 | 539 |
| 539 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 540 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 540 | 541 |
| 541 // TextInputClient is now focused here. | 542 // TextInputClient is now focused here. |
| 542 | 543 |
| 543 EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); | 544 input_method->DispatchKeyEvent(&native_keydown); |
| 544 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 545 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 545 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 546 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 546 delegate_.Reset(); | 547 delegate_.Reset(); |
| 547 mock_text_input_client.Reset(); | 548 mock_text_input_client.Reset(); |
| 548 } | 549 } |
| 549 | 550 |
| 550 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { | 551 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { |
| 551 // RemoteInputMethodWin handles native char event if possible. | 552 // RemoteInputMethodWin handles native char event if possible. |
| 552 | 553 |
| 553 MockInputMethodDelegate delegate_; | 554 MockInputMethodDelegate delegate_; |
| 554 MockTextInputClient mock_text_input_client; | 555 MockTextInputClient mock_text_input_client; |
| 555 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 556 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 556 | 557 |
| 557 const MSG wm_char = { NULL, WM_CHAR, 'A', 0 }; | 558 const MSG wm_char = { NULL, WM_CHAR, 'A', 0 }; |
| 558 ui::KeyEvent native_char(wm_char); | 559 ui::KeyEvent native_char(wm_char); |
| 559 | 560 |
| 560 // This must not cause a crash. | 561 // This must not cause a crash. |
| 561 EXPECT_FALSE(input_method->DispatchKeyEvent(native_char)); | 562 input_method->DispatchKeyEvent(&native_char); |
| 562 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 563 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 563 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 564 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 564 delegate_.Reset(); | 565 delegate_.Reset(); |
| 565 mock_text_input_client.Reset(); | 566 mock_text_input_client.Reset(); |
| 566 | 567 |
| 567 RemoteInputMethodPrivateWin* private_ptr = | 568 RemoteInputMethodPrivateWin* private_ptr = |
| 568 RemoteInputMethodPrivateWin::Get(input_method.get()); | 569 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 569 ASSERT_TRUE(private_ptr != NULL); | 570 ASSERT_TRUE(private_ptr != NULL); |
| 570 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 571 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 571 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 572 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 572 | 573 |
| 573 // TextInputClient is not focused yet here. | 574 // TextInputClient is not focused yet here. |
| 574 | 575 |
| 575 EXPECT_FALSE(input_method->DispatchKeyEvent(native_char)); | 576 input_method->DispatchKeyEvent(&native_char); |
| 576 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 577 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 577 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 578 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 578 delegate_.Reset(); | 579 delegate_.Reset(); |
| 579 mock_text_input_client.Reset(); | 580 mock_text_input_client.Reset(); |
| 580 | 581 |
| 581 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 582 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 582 | 583 |
| 583 // TextInputClient is now focused here. | 584 // TextInputClient is now focused here. |
| 584 | 585 |
| 585 EXPECT_TRUE(input_method->DispatchKeyEvent(native_char)); | 586 input_method->DispatchKeyEvent(&native_char); |
| 586 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); | 587 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); |
| 587 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 588 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 588 delegate_.Reset(); | 589 delegate_.Reset(); |
| 589 mock_text_input_client.Reset(); | 590 mock_text_input_client.Reset(); |
| 590 } | 591 } |
| 591 | 592 |
| 592 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { | 593 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { |
| 593 // Fabricated non-char event will be delegated to | 594 // Fabricated non-char event will be delegated to |
| 594 // InputMethodDelegate::DispatchFabricatedKeyEventPostIME as long as the | 595 // InputMethodDelegate::DispatchFabricatedKeyEventPostIME as long as the |
| 595 // delegate is installed. | 596 // delegate is installed. |
| 596 | 597 |
| 597 MockInputMethodDelegate delegate_; | 598 MockInputMethodDelegate delegate_; |
| 598 MockTextInputClient mock_text_input_client; | 599 MockTextInputClient mock_text_input_client; |
| 599 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 600 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 600 | 601 |
| 601 ui::KeyEvent fabricated_keydown(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 602 ui::KeyEvent fabricated_keydown(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 602 fabricated_keydown.set_character(L'A'); | 603 fabricated_keydown.set_character(L'A'); |
| 603 | 604 |
| 604 // This must not cause a crash. | 605 // This must not cause a crash. |
| 605 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); | 606 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 606 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 607 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 607 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 608 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); |
| 608 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 609 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
| 609 delegate_.Reset(); | 610 delegate_.Reset(); |
| 610 mock_text_input_client.Reset(); | 611 mock_text_input_client.Reset(); |
| 611 | 612 |
| 612 RemoteInputMethodPrivateWin* private_ptr = | 613 RemoteInputMethodPrivateWin* private_ptr = |
| 613 RemoteInputMethodPrivateWin::Get(input_method.get()); | 614 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 614 ASSERT_TRUE(private_ptr != NULL); | 615 ASSERT_TRUE(private_ptr != NULL); |
| 615 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 616 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 616 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 617 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 617 | 618 |
| 618 // TextInputClient is not focused yet here. | 619 // TextInputClient is not focused yet here. |
| 619 | 620 |
| 620 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); | 621 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 621 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 622 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 622 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 623 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); |
| 623 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 624 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
| 624 delegate_.Reset(); | 625 delegate_.Reset(); |
| 625 mock_text_input_client.Reset(); | 626 mock_text_input_client.Reset(); |
| 626 | 627 |
| 627 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 628 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 628 // TextInputClient is now focused here. | 629 // TextInputClient is now focused here. |
| 629 | 630 |
| 630 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); | 631 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 631 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 632 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 632 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 633 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); |
| 633 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 634 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
| 634 delegate_.Reset(); | 635 delegate_.Reset(); |
| 635 mock_text_input_client.Reset(); | 636 mock_text_input_client.Reset(); |
| 636 | 637 |
| 637 input_method->SetDelegate(NULL); | 638 input_method->SetDelegate(NULL); |
| 638 // RemoteInputMethodDelegateWin is no longer set here. | 639 // RemoteInputMethodDelegateWin is no longer set here. |
| 639 | 640 |
| 640 EXPECT_FALSE(input_method->DispatchKeyEvent(fabricated_keydown)); | 641 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 641 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 642 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 642 } | 643 } |
| 643 | 644 |
| 644 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { | 645 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { |
| 645 // Note: RemoteInputMethodWin::DispatchKeyEvent should always return true | 646 // Note: RemoteInputMethodWin::DispatchKeyEvent should always return true |
| 646 // for fabricated character events. | 647 // for fabricated character events. |
| 647 | 648 |
| 648 MockInputMethodDelegate delegate_; | 649 MockInputMethodDelegate delegate_; |
| 649 MockTextInputClient mock_text_input_client; | 650 MockTextInputClient mock_text_input_client; |
| 650 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 651 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 651 | 652 |
| 652 ui::KeyEvent fabricated_char(L'A', ui::VKEY_A, ui::EF_NONE); | 653 ui::KeyEvent fabricated_char(L'A', ui::VKEY_A, ui::EF_NONE); |
| 653 | 654 |
| 654 // This must not cause a crash. | 655 // This must not cause a crash. |
| 655 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); | 656 input_method->DispatchKeyEvent(&fabricated_char); |
| 656 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 657 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 657 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 658 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 658 delegate_.Reset(); | 659 delegate_.Reset(); |
| 659 mock_text_input_client.Reset(); | 660 mock_text_input_client.Reset(); |
| 660 | 661 |
| 661 RemoteInputMethodPrivateWin* private_ptr = | 662 RemoteInputMethodPrivateWin* private_ptr = |
| 662 RemoteInputMethodPrivateWin::Get(input_method.get()); | 663 RemoteInputMethodPrivateWin::Get(input_method.get()); |
| 663 ASSERT_TRUE(private_ptr != NULL); | 664 ASSERT_TRUE(private_ptr != NULL); |
| 664 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 665 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
| 665 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 666 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
| 666 | 667 |
| 667 // TextInputClient is not focused yet here. | 668 // TextInputClient is not focused yet here. |
| 668 | 669 |
| 669 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); | 670 input_method->DispatchKeyEvent(&fabricated_char); |
| 670 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 671 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
| 671 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 672 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 672 delegate_.Reset(); | 673 delegate_.Reset(); |
| 673 mock_text_input_client.Reset(); | 674 mock_text_input_client.Reset(); |
| 674 | 675 |
| 675 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 676 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
| 676 | 677 |
| 677 // TextInputClient is now focused here. | 678 // TextInputClient is now focused here. |
| 678 | 679 |
| 679 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); | 680 input_method->DispatchKeyEvent(&fabricated_char); |
| 680 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); | 681 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); |
| 681 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 682 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
| 682 delegate_.Reset(); | 683 delegate_.Reset(); |
| 683 mock_text_input_client.Reset(); | 684 mock_text_input_client.Reset(); |
| 684 } | 685 } |
| 685 | 686 |
| 686 TEST(RemoteInputMethodWinTest, OnCompositionChanged) { | 687 TEST(RemoteInputMethodWinTest, OnCompositionChanged) { |
| 687 MockInputMethodDelegate delegate_; | 688 MockInputMethodDelegate delegate_; |
| 688 MockTextInputClient mock_text_input_client; | 689 MockTextInputClient mock_text_input_client; |
| 689 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 690 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 803 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
| 803 input_method->AddObserver(&input_method_observer); | 804 input_method->AddObserver(&input_method_observer); |
| 804 | 805 |
| 805 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); | 806 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); |
| 806 input_method.reset(); | 807 input_method.reset(); |
| 807 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); | 808 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); |
| 808 } | 809 } |
| 809 | 810 |
| 810 } // namespace | 811 } // namespace |
| 811 } // namespace ui | 812 } // namespace ui |
| OLD | NEW |