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 event->SetHandled(); |
| 146 return ui::EventDispatchDetails(); |
145 } | 147 } |
146 | 148 |
147 std::vector<ui::KeyboardCode> fabricated_key_events_; | 149 std::vector<ui::KeyboardCode> fabricated_key_events_; |
148 DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); | 150 DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); |
149 }; | 151 }; |
150 | 152 |
151 class MockRemoteInputMethodDelegateWin | 153 class MockRemoteInputMethodDelegateWin |
152 : public internal::RemoteInputMethodDelegateWin { | 154 : public internal::RemoteInputMethodDelegateWin { |
153 public: | 155 public: |
154 MockRemoteInputMethodDelegateWin() | 156 MockRemoteInputMethodDelegateWin() |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 508 } |
507 | 509 |
508 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeKeyEvent) { | 510 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeKeyEvent) { |
509 // Basically RemoteInputMethodWin does not handle native keydown event. | 511 // Basically RemoteInputMethodWin does not handle native keydown event. |
510 | 512 |
511 MockInputMethodDelegate delegate_; | 513 MockInputMethodDelegate delegate_; |
512 MockTextInputClient mock_text_input_client; | 514 MockTextInputClient mock_text_input_client; |
513 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 515 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
514 | 516 |
515 const MSG wm_keydown = { NULL, WM_KEYDOWN, ui::VKEY_A }; | 517 const MSG wm_keydown = { NULL, WM_KEYDOWN, ui::VKEY_A }; |
516 ui::KeyEvent native_keydown(wm_keydown); | 518 ui::KeyEvent new_keydown(wm_keydown); |
| 519 ui::KeyEvent native_keydown(new_keydown); |
517 | 520 |
518 // This must not cause a crash. | 521 // This must not cause a crash. |
519 EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); | 522 input_method->DispatchKeyEvent(&native_keydown); |
| 523 EXPECT_FALSE(native_keydown.handled()); |
520 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 524 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
521 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 525 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
522 delegate_.Reset(); | 526 delegate_.Reset(); |
523 mock_text_input_client.Reset(); | 527 mock_text_input_client.Reset(); |
524 | 528 |
525 RemoteInputMethodPrivateWin* private_ptr = | 529 RemoteInputMethodPrivateWin* private_ptr = |
526 RemoteInputMethodPrivateWin::Get(input_method.get()); | 530 RemoteInputMethodPrivateWin::Get(input_method.get()); |
527 ASSERT_TRUE(private_ptr != NULL); | 531 ASSERT_TRUE(private_ptr != NULL); |
528 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 532 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
529 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 533 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
530 | 534 |
531 // TextInputClient is not focused yet here. | 535 // TextInputClient is not focused yet here. |
532 | 536 native_keydown = new_keydown; |
533 EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); | 537 input_method->DispatchKeyEvent(&native_keydown); |
| 538 EXPECT_FALSE(native_keydown.handled()); |
534 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 539 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
535 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 540 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
536 delegate_.Reset(); | 541 delegate_.Reset(); |
537 mock_text_input_client.Reset(); | 542 mock_text_input_client.Reset(); |
538 | 543 |
539 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 544 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
540 | 545 |
541 // TextInputClient is now focused here. | 546 // TextInputClient is now focused here. |
542 | 547 native_keydown = new_keydown; |
543 EXPECT_FALSE(input_method->DispatchKeyEvent(native_keydown)); | 548 input_method->DispatchKeyEvent(&native_keydown); |
| 549 EXPECT_FALSE(native_keydown.handled()); |
544 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 550 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
545 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 551 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
546 delegate_.Reset(); | 552 delegate_.Reset(); |
547 mock_text_input_client.Reset(); | 553 mock_text_input_client.Reset(); |
548 } | 554 } |
549 | 555 |
550 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { | 556 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_NativeCharEvent) { |
551 // RemoteInputMethodWin handles native char event if possible. | 557 // RemoteInputMethodWin handles native char event if possible. |
552 | 558 |
553 MockInputMethodDelegate delegate_; | 559 MockInputMethodDelegate delegate_; |
554 MockTextInputClient mock_text_input_client; | 560 MockTextInputClient mock_text_input_client; |
555 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 561 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
556 | 562 |
557 const MSG wm_char = { NULL, WM_CHAR, 'A', 0 }; | 563 const MSG wm_char = { NULL, WM_CHAR, 'A', 0 }; |
558 ui::KeyEvent native_char(wm_char); | 564 ui::KeyEvent new_char(wm_char); |
| 565 ui::KeyEvent native_char(new_char); |
559 | 566 |
560 // This must not cause a crash. | 567 // This must not cause a crash. |
561 EXPECT_FALSE(input_method->DispatchKeyEvent(native_char)); | 568 input_method->DispatchKeyEvent(&native_char); |
| 569 EXPECT_FALSE(native_char.handled()); |
562 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 570 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
563 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 571 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
564 delegate_.Reset(); | 572 delegate_.Reset(); |
565 mock_text_input_client.Reset(); | 573 mock_text_input_client.Reset(); |
566 | 574 |
567 RemoteInputMethodPrivateWin* private_ptr = | 575 RemoteInputMethodPrivateWin* private_ptr = |
568 RemoteInputMethodPrivateWin::Get(input_method.get()); | 576 RemoteInputMethodPrivateWin::Get(input_method.get()); |
569 ASSERT_TRUE(private_ptr != NULL); | 577 ASSERT_TRUE(private_ptr != NULL); |
570 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 578 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
571 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 579 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
572 | 580 |
573 // TextInputClient is not focused yet here. | 581 // TextInputClient is not focused yet here. |
574 | 582 native_char = new_char; |
575 EXPECT_FALSE(input_method->DispatchKeyEvent(native_char)); | 583 input_method->DispatchKeyEvent(&native_char); |
| 584 EXPECT_FALSE(native_char.handled()); |
576 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 585 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
577 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 586 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
578 delegate_.Reset(); | 587 delegate_.Reset(); |
579 mock_text_input_client.Reset(); | 588 mock_text_input_client.Reset(); |
580 | 589 |
581 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 590 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
582 | 591 |
583 // TextInputClient is now focused here. | 592 // TextInputClient is now focused here. |
584 | 593 native_char = new_char; |
585 EXPECT_TRUE(input_method->DispatchKeyEvent(native_char)); | 594 input_method->DispatchKeyEvent(&native_char); |
| 595 EXPECT_TRUE(native_char.handled()); |
586 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); | 596 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); |
587 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 597 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
588 delegate_.Reset(); | 598 delegate_.Reset(); |
589 mock_text_input_client.Reset(); | 599 mock_text_input_client.Reset(); |
590 } | 600 } |
591 | 601 |
592 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { | 602 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { |
593 // Fabricated non-char event will be delegated to | 603 // Fabricated non-char event will be delegated to |
594 // InputMethodDelegate::DispatchFabricatedKeyEventPostIME as long as the | 604 // InputMethodDelegate::DispatchFabricatedKeyEventPostIME as long as the |
595 // delegate is installed. | 605 // delegate is installed. |
596 | 606 |
597 MockInputMethodDelegate delegate_; | 607 MockInputMethodDelegate delegate_; |
598 MockTextInputClient mock_text_input_client; | 608 MockTextInputClient mock_text_input_client; |
599 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 609 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
600 | 610 |
601 ui::KeyEvent fabricated_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); |
602 fabricated_keydown.set_character(L'A'); | 612 new_keydown.set_character(L'A'); |
| 613 ui::KeyEvent fabricated_keydown(new_keydown); |
603 | 614 |
604 // This must not cause a crash. | 615 // This must not cause a crash. |
605 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); | 616 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 617 EXPECT_TRUE(fabricated_keydown.handled()); |
606 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 618 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
607 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 619 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); |
608 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 620 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
609 delegate_.Reset(); | 621 delegate_.Reset(); |
610 mock_text_input_client.Reset(); | 622 mock_text_input_client.Reset(); |
611 | 623 |
612 RemoteInputMethodPrivateWin* private_ptr = | 624 RemoteInputMethodPrivateWin* private_ptr = |
613 RemoteInputMethodPrivateWin::Get(input_method.get()); | 625 RemoteInputMethodPrivateWin::Get(input_method.get()); |
614 ASSERT_TRUE(private_ptr != NULL); | 626 ASSERT_TRUE(private_ptr != NULL); |
615 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 627 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
616 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 628 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
617 | 629 |
618 // TextInputClient is not focused yet here. | 630 // TextInputClient is not focused yet here. |
619 | 631 fabricated_keydown = new_keydown; |
620 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); | 632 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 633 EXPECT_TRUE(fabricated_keydown.handled()); |
621 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 634 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
622 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 635 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); |
623 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 636 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
624 delegate_.Reset(); | 637 delegate_.Reset(); |
625 mock_text_input_client.Reset(); | 638 mock_text_input_client.Reset(); |
626 | 639 |
627 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 640 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
628 // TextInputClient is now focused here. | 641 // TextInputClient is now focused here. |
629 | 642 fabricated_keydown = new_keydown; |
630 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_keydown)); | 643 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 644 EXPECT_TRUE(fabricated_keydown.handled()); |
631 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 645 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
632 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); | 646 ASSERT_EQ(1, delegate_.fabricated_key_events().size()); |
633 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); | 647 EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); |
634 delegate_.Reset(); | 648 delegate_.Reset(); |
635 mock_text_input_client.Reset(); | 649 mock_text_input_client.Reset(); |
636 | 650 |
637 input_method->SetDelegate(NULL); | 651 input_method->SetDelegate(NULL); |
638 // RemoteInputMethodDelegateWin is no longer set here. | 652 // RemoteInputMethodDelegateWin is no longer set here. |
639 | 653 fabricated_keydown = new_keydown; |
640 EXPECT_FALSE(input_method->DispatchKeyEvent(fabricated_keydown)); | 654 input_method->DispatchKeyEvent(&fabricated_keydown); |
| 655 EXPECT_FALSE(fabricated_keydown.handled()); |
641 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 656 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
642 } | 657 } |
643 | 658 |
644 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { | 659 TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedChar) { |
645 // Note: RemoteInputMethodWin::DispatchKeyEvent should always return true | 660 // Note: RemoteInputMethodWin::DispatchKeyEvent should always return true |
646 // for fabricated character events. | 661 // for fabricated character events. |
647 | 662 |
648 MockInputMethodDelegate delegate_; | 663 MockInputMethodDelegate delegate_; |
649 MockTextInputClient mock_text_input_client; | 664 MockTextInputClient mock_text_input_client; |
650 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 665 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
651 | 666 |
652 ui::KeyEvent fabricated_char(L'A', ui::VKEY_A, ui::EF_NONE); | 667 ui::KeyEvent new_char(L'A', ui::VKEY_A, ui::EF_NONE); |
| 668 ui::KeyEvent fabricated_char(new_char); |
653 | 669 |
654 // This must not cause a crash. | 670 // This must not cause a crash. |
655 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); | 671 input_method->DispatchKeyEvent(&fabricated_char); |
| 672 EXPECT_TRUE(fabricated_char.handled()); |
656 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 673 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
657 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 674 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
658 delegate_.Reset(); | 675 delegate_.Reset(); |
659 mock_text_input_client.Reset(); | 676 mock_text_input_client.Reset(); |
660 | 677 |
661 RemoteInputMethodPrivateWin* private_ptr = | 678 RemoteInputMethodPrivateWin* private_ptr = |
662 RemoteInputMethodPrivateWin::Get(input_method.get()); | 679 RemoteInputMethodPrivateWin::Get(input_method.get()); |
663 ASSERT_TRUE(private_ptr != NULL); | 680 ASSERT_TRUE(private_ptr != NULL); |
664 MockRemoteInputMethodDelegateWin mock_remote_delegate; | 681 MockRemoteInputMethodDelegateWin mock_remote_delegate; |
665 private_ptr->SetRemoteDelegate(&mock_remote_delegate); | 682 private_ptr->SetRemoteDelegate(&mock_remote_delegate); |
666 | 683 |
667 // TextInputClient is not focused yet here. | 684 // TextInputClient is not focused yet here. |
668 | 685 fabricated_char = new_char; |
669 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); | 686 input_method->DispatchKeyEvent(&fabricated_char); |
| 687 EXPECT_TRUE(fabricated_char.handled()); |
670 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); | 688 EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); |
671 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 689 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
672 delegate_.Reset(); | 690 delegate_.Reset(); |
673 mock_text_input_client.Reset(); | 691 mock_text_input_client.Reset(); |
674 | 692 |
675 input_method->SetFocusedTextInputClient(&mock_text_input_client); | 693 input_method->SetFocusedTextInputClient(&mock_text_input_client); |
676 | 694 |
677 // TextInputClient is now focused here. | 695 // TextInputClient is now focused here. |
678 | 696 fabricated_char = new_char; |
679 EXPECT_TRUE(input_method->DispatchKeyEvent(fabricated_char)); | 697 input_method->DispatchKeyEvent(&fabricated_char); |
| 698 EXPECT_TRUE(fabricated_char.handled()); |
680 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); | 699 EXPECT_EQ(L"A", mock_text_input_client.inserted_text()); |
681 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); | 700 EXPECT_TRUE(delegate_.fabricated_key_events().empty()); |
682 delegate_.Reset(); | 701 delegate_.Reset(); |
683 mock_text_input_client.Reset(); | 702 mock_text_input_client.Reset(); |
684 } | 703 } |
685 | 704 |
686 TEST(RemoteInputMethodWinTest, OnCompositionChanged) { | 705 TEST(RemoteInputMethodWinTest, OnCompositionChanged) { |
687 MockInputMethodDelegate delegate_; | 706 MockInputMethodDelegate delegate_; |
688 MockTextInputClient mock_text_input_client; | 707 MockTextInputClient mock_text_input_client; |
689 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 708 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_)); | 821 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
803 input_method->AddObserver(&input_method_observer); | 822 input_method->AddObserver(&input_method_observer); |
804 | 823 |
805 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); | 824 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); |
806 input_method.reset(); | 825 input_method.reset(); |
807 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); | 826 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); |
808 } | 827 } |
809 | 828 |
810 } // namespace | 829 } // namespace |
811 } // namespace ui | 830 } // namespace ui |
OLD | NEW |