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 "chrome/browser/chromeos/events/event_rewriter.h" | 5 #include "chrome/browser/chromeos/events/event_rewriter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 rewriter.set_pref_service_for_testing(&prefs); | 598 rewriter.set_pref_service_for_testing(&prefs); |
599 | 599 |
600 KeyTestCase tests[] = { | 600 KeyTestCase tests[] = { |
601 // Press Alt with Shift. Confirm the event is not rewritten. | 601 // Press Alt with Shift. Confirm the event is not rewritten. |
602 {ui::ET_KEY_PRESSED, | 602 {ui::ET_KEY_PRESSED, |
603 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, | 603 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, |
604 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}, | 604 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}, |
605 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, | 605 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, |
606 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}}, | 606 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}}, |
607 | 607 |
| 608 // Press Escape with Alt and Shift. Confirm the event is not rewritten. |
| 609 {ui::ET_KEY_PRESSED, |
| 610 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, |
| 611 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ESCAPE}, |
| 612 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, |
| 613 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ESCAPE}}, |
| 614 |
608 // Press Search with Caps Lock mask. Confirm the event is not rewritten. | 615 // Press Search with Caps Lock mask. Confirm the event is not rewritten. |
609 {ui::ET_KEY_PRESSED, | 616 {ui::ET_KEY_PRESSED, |
610 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 617 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, |
611 ui::EF_CAPS_LOCK_ON | ui::EF_COMMAND_DOWN, ui::DomKey::META}, | 618 ui::EF_CAPS_LOCK_ON | ui::EF_COMMAND_DOWN, ui::DomKey::META}, |
612 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 619 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, |
613 ui::EF_CAPS_LOCK_ON | ui::EF_COMMAND_DOWN, ui::DomKey::META}}, | 620 ui::EF_CAPS_LOCK_ON | ui::EF_COMMAND_DOWN, ui::DomKey::META}}, |
614 | 621 |
615 // Release Search with Caps Lock mask. Confirm the event is not rewritten. | 622 // Release Search with Caps Lock mask. Confirm the event is not rewritten. |
616 {ui::ET_KEY_RELEASED, | 623 {ui::ET_KEY_RELEASED, |
617 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_CAPS_LOCK_ON, | 624 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_CAPS_LOCK_ON, |
618 ui::DomKey::META}, | 625 ui::DomKey::META}, |
619 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_CAPS_LOCK_ON, | 626 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_CAPS_LOCK_ON, |
620 ui::DomKey::META}}, | 627 ui::DomKey::META}}, |
621 | 628 |
622 // Press Shift+Ctrl+Alt+Search+A. Confirm the event is not rewritten. | 629 // Press Shift+Ctrl+Alt+Search+Escape. Confirm the event is not rewritten. |
| 630 {ui::ET_KEY_PRESSED, |
| 631 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, |
| 632 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
| 633 ui::EF_COMMAND_DOWN, |
| 634 ui::DomKey::ESCAPE}, |
| 635 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, |
| 636 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
| 637 ui::EF_COMMAND_DOWN, |
| 638 ui::DomKey::ESCAPE}}, |
| 639 |
| 640 // Press Shift+Ctrl+Alt+Search+B. Confirm the event is not rewritten. |
623 {ui::ET_KEY_PRESSED, | 641 {ui::ET_KEY_PRESSED, |
624 {ui::VKEY_B, ui::DomCode::US_B, | 642 {ui::VKEY_B, ui::DomCode::US_B, |
625 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | | 643 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
626 ui::EF_COMMAND_DOWN, | 644 ui::EF_COMMAND_DOWN, |
627 ui::DomKey::Constant<'B'>::Character}, | 645 ui::DomKey::Constant<'B'>::Character}, |
628 {ui::VKEY_B, ui::DomCode::US_B, | 646 {ui::VKEY_B, ui::DomCode::US_B, |
629 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | | 647 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
630 ui::EF_COMMAND_DOWN, | 648 ui::EF_COMMAND_DOWN, |
631 ui::DomKey::Constant<'B'>::Character}}, | 649 ui::DomKey::Constant<'B'>::Character}}, |
632 }; | 650 }; |
633 | 651 |
634 for (const auto& test : tests) { | 652 for (const auto& test : tests) { |
635 CheckKeyTestCase(&rewriter, test); | 653 CheckKeyTestCase(&rewriter, test); |
636 } | 654 } |
637 } | 655 } |
638 | 656 |
639 TEST_F(EventRewriterTest, TestRewriteModifiersDisableSome) { | 657 TEST_F(EventRewriterTest, TestRewriteModifiersDisableSome) { |
640 // Disable Search and Control keys. | 658 // Disable Search, Control and Escape keys. |
641 syncable_prefs::TestingPrefServiceSyncable prefs; | 659 syncable_prefs::TestingPrefServiceSyncable prefs; |
642 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 660 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
643 IntegerPrefMember search; | 661 IntegerPrefMember search; |
644 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); | 662 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); |
645 search.SetValue(chromeos::input_method::kVoidKey); | 663 search.SetValue(chromeos::input_method::kVoidKey); |
646 IntegerPrefMember control; | 664 IntegerPrefMember control; |
647 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); | 665 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); |
648 control.SetValue(chromeos::input_method::kVoidKey); | 666 control.SetValue(chromeos::input_method::kVoidKey); |
| 667 IntegerPrefMember escape; |
| 668 escape.Init(prefs::kLanguageRemapEscapeKeyTo, &prefs); |
| 669 escape.SetValue(chromeos::input_method::kVoidKey); |
649 | 670 |
650 EventRewriter rewriter(NULL); | 671 EventRewriter rewriter(NULL); |
651 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 672 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
652 rewriter.set_pref_service_for_testing(&prefs); | 673 rewriter.set_pref_service_for_testing(&prefs); |
653 | 674 |
654 KeyTestCase disabled_modifier_tests[] = { | 675 KeyTestCase disabled_modifier_tests[] = { |
655 // Press Alt with Shift. This key press shouldn't be affected by the | 676 // Press Alt with Shift. This key press shouldn't be affected by the |
656 // pref. Confirm the event is not rewritten. | 677 // pref. Confirm the event is not rewritten. |
657 {ui::ET_KEY_PRESSED, | 678 {ui::ET_KEY_PRESSED, |
658 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, | 679 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, |
659 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}, | 680 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}, |
660 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, | 681 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, |
661 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}}, | 682 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, ui::DomKey::ALT}}, |
662 | 683 |
663 // Press Search. Confirm the event is now VKEY_UNKNOWN. | 684 // Press Search. Confirm the event is now VKEY_UNKNOWN. |
664 {ui::ET_KEY_PRESSED, | 685 {ui::ET_KEY_PRESSED, |
665 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_NONE, ui::DomKey::META}, | 686 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_NONE, ui::DomKey::META}, |
666 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, | 687 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, |
667 ui::DomKey::UNIDENTIFIED}}, | 688 ui::DomKey::UNIDENTIFIED}}, |
668 | 689 |
669 // Press Control. Confirm the event is now VKEY_UNKNOWN. | 690 // Press Control. Confirm the event is now VKEY_UNKNOWN. |
670 {ui::ET_KEY_PRESSED, | 691 {ui::ET_KEY_PRESSED, |
671 {ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT, ui::EF_CONTROL_DOWN, | 692 {ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT, ui::EF_CONTROL_DOWN, |
672 ui::DomKey::CONTROL}, | 693 ui::DomKey::CONTROL}, |
673 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, | 694 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, |
674 ui::DomKey::UNIDENTIFIED}}, | 695 ui::DomKey::UNIDENTIFIED}}, |
675 | 696 |
| 697 // Press Escape. Confirm the event is now VKEY_UNKNOWN. |
| 698 {ui::ET_KEY_PRESSED, |
| 699 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}, |
| 700 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, |
| 701 ui::DomKey::UNIDENTIFIED}}, |
| 702 |
676 // Press Control+Search. Confirm the event is now VKEY_UNKNOWN | 703 // Press Control+Search. Confirm the event is now VKEY_UNKNOWN |
677 // without any modifiers. | 704 // without any modifiers. |
678 {ui::ET_KEY_PRESSED, | 705 {ui::ET_KEY_PRESSED, |
679 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_CONTROL_DOWN, | 706 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_CONTROL_DOWN, |
680 ui::DomKey::META}, | 707 ui::DomKey::META}, |
681 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, | 708 {ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE, |
682 ui::DomKey::UNIDENTIFIED}}, | 709 ui::DomKey::UNIDENTIFIED}}, |
683 | 710 |
684 // Press Control+Search+a. Confirm the event is now VKEY_A without any | 711 // Press Control+Search+a. Confirm the event is now VKEY_A without any |
685 // modifiers. | 712 // modifiers. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 {ui::VKEY_B, ui::DomCode::US_B, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, | 828 {ui::VKEY_B, ui::DomCode::US_B, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, |
802 ui::DomKey::Constant<'B'>::Character}}, | 829 ui::DomKey::Constant<'B'>::Character}}, |
803 }; | 830 }; |
804 | 831 |
805 for (const auto& test : sa_tests) { | 832 for (const auto& test : sa_tests) { |
806 CheckKeyTestCase(&rewriter, test); | 833 CheckKeyTestCase(&rewriter, test); |
807 } | 834 } |
808 } | 835 } |
809 | 836 |
810 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToEscape) { | 837 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToEscape) { |
811 // Remap Search to ESC. | 838 // Remap Search to Escape. |
812 syncable_prefs::TestingPrefServiceSyncable prefs; | 839 syncable_prefs::TestingPrefServiceSyncable prefs; |
813 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 840 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
814 IntegerPrefMember search; | 841 IntegerPrefMember search; |
815 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); | 842 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); |
816 search.SetValue(chromeos::input_method::kEscapeKey); | 843 search.SetValue(chromeos::input_method::kEscapeKey); |
817 | 844 |
818 EventRewriter rewriter(NULL); | 845 EventRewriter rewriter(NULL); |
819 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 846 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
820 rewriter.set_pref_service_for_testing(&prefs); | 847 rewriter.set_pref_service_for_testing(&prefs); |
821 | 848 |
822 KeyTestCase tests[] = { | 849 KeyTestCase tests[] = { |
823 // Press Search. Confirm the event is now VKEY_ESCAPE. | 850 // Press Search. Confirm the event is now VKEY_ESCAPE. |
824 {ui::ET_KEY_PRESSED, | 851 {ui::ET_KEY_PRESSED, |
825 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_COMMAND_DOWN, | 852 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_COMMAND_DOWN, |
826 ui::DomKey::META}, | 853 ui::DomKey::META}, |
827 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}}, | 854 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}}, |
828 }; | 855 }; |
829 | 856 |
830 for (const auto& test : tests) { | 857 for (const auto& test : tests) { |
831 CheckKeyTestCase(&rewriter, test); | 858 CheckKeyTestCase(&rewriter, test); |
832 } | 859 } |
833 } | 860 } |
834 | 861 |
835 TEST_F(EventRewriterTest, TestRewriteModifiersRemapMany) { | 862 TEST_F(EventRewriterTest, TestRewriteModifiersRemapMany) { |
836 // Remap Search to Alt. | 863 // Remap Escape to Alt. |
837 syncable_prefs::TestingPrefServiceSyncable prefs; | 864 syncable_prefs::TestingPrefServiceSyncable prefs; |
838 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 865 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
839 IntegerPrefMember search; | 866 IntegerPrefMember escape; |
840 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); | 867 escape.Init(prefs::kLanguageRemapEscapeKeyTo, &prefs); |
841 search.SetValue(chromeos::input_method::kAltKey); | 868 escape.SetValue(chromeos::input_method::kAltKey); |
842 | 869 |
843 EventRewriter rewriter(NULL); | 870 EventRewriter rewriter(NULL); |
844 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 871 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
845 rewriter.set_pref_service_for_testing(&prefs); | 872 rewriter.set_pref_service_for_testing(&prefs); |
846 | 873 |
847 KeyTestCase s2a_tests[] = { | 874 KeyTestCase e2a_tests[] = { |
848 // Press Search. Confirm the event is now VKEY_MENU. | 875 // Press Escape. Confirm the event is now VKEY_MENU. |
849 {ui::ET_KEY_PRESSED, | 876 {ui::ET_KEY_PRESSED, |
850 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_COMMAND_DOWN, | 877 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}, |
851 ui::DomKey::META}, | |
852 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, ui::EF_ALT_DOWN, | 878 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, ui::EF_ALT_DOWN, |
853 ui::DomKey::ALT}}, | 879 ui::DomKey::ALT}}, |
| 880 // Release Escape to clear flags. |
| 881 {ui::ET_KEY_RELEASED, |
| 882 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}, |
| 883 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, ui::EF_NONE, ui::DomKey::ALT}}, |
854 }; | 884 }; |
855 | 885 |
856 for (const auto& test : s2a_tests) { | 886 for (const auto& test : e2a_tests) { |
857 CheckKeyTestCase(&rewriter, test); | 887 CheckKeyTestCase(&rewriter, test); |
858 } | 888 } |
859 | 889 |
860 // Remap Alt to Control. | 890 // Remap Alt to Control. |
861 IntegerPrefMember alt; | 891 IntegerPrefMember alt; |
862 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs); | 892 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs); |
863 alt.SetValue(chromeos::input_method::kControlKey); | 893 alt.SetValue(chromeos::input_method::kControlKey); |
864 | 894 |
865 KeyTestCase a2c_tests[] = { | 895 KeyTestCase a2c_tests[] = { |
866 // Press left Alt. Confirm the event is now VKEY_CONTROL. | 896 // Press left Alt. Confirm the event is now VKEY_CONTROL. |
(...skipping 27 matching lines...) Expand all Loading... |
894 control.SetValue(chromeos::input_method::kSearchKey); | 924 control.SetValue(chromeos::input_method::kSearchKey); |
895 | 925 |
896 KeyTestCase c2s_tests[] = { | 926 KeyTestCase c2s_tests[] = { |
897 // Press left Control. Confirm the event is now VKEY_LWIN. | 927 // Press left Control. Confirm the event is now VKEY_LWIN. |
898 {ui::ET_KEY_PRESSED, | 928 {ui::ET_KEY_PRESSED, |
899 {ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT, ui::EF_CONTROL_DOWN, | 929 {ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT, ui::EF_CONTROL_DOWN, |
900 ui::DomKey::CONTROL}, | 930 ui::DomKey::CONTROL}, |
901 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_COMMAND_DOWN, | 931 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_COMMAND_DOWN, |
902 ui::DomKey::META}}, | 932 ui::DomKey::META}}, |
903 | 933 |
904 // Then, press all of the three, Control+Alt+Search. | 934 // Then, press all of the three, Control+Alt+Escape. |
905 {ui::ET_KEY_PRESSED, | 935 {ui::ET_KEY_PRESSED, |
906 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 936 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, |
907 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN, | 937 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, ui::DomKey::CONTROL}, |
908 ui::DomKey::META}, | |
909 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, | 938 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, |
910 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN, | 939 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN, |
911 ui::DomKey::ALT}}, | 940 ui::DomKey::ALT}}, |
912 | 941 |
913 // Press Shift+Control+Alt+Search. | 942 // Press Shift+Control+Alt+Escape. |
914 {ui::ET_KEY_PRESSED, | 943 {ui::ET_KEY_PRESSED, |
915 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, | 944 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, |
916 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | | 945 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, |
917 ui::EF_COMMAND_DOWN, | 946 ui::DomKey::ESCAPE}, |
918 ui::DomKey::META}, | |
919 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, | 947 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, |
920 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | | 948 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
921 ui::EF_COMMAND_DOWN, | 949 ui::EF_COMMAND_DOWN, |
922 ui::DomKey::ALT}}, | 950 ui::DomKey::ALT}}, |
923 | 951 |
924 // Press Shift+Control+Alt+Search+B | 952 // Press Shift+Control+Alt+B |
925 {ui::ET_KEY_PRESSED, | 953 {ui::ET_KEY_PRESSED, |
926 {ui::VKEY_B, ui::DomCode::US_B, | 954 {ui::VKEY_B, ui::DomCode::US_B, |
927 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | | 955 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, |
928 ui::EF_COMMAND_DOWN, | |
929 ui::DomKey::Constant<'B'>::Character}, | 956 ui::DomKey::Constant<'B'>::Character}, |
930 {ui::VKEY_B, ui::DomCode::US_B, | 957 {ui::VKEY_B, ui::DomCode::US_B, |
931 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | | 958 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
932 ui::EF_COMMAND_DOWN, | 959 ui::EF_COMMAND_DOWN, |
933 ui::DomKey::Constant<'B'>::Character}}, | 960 ui::DomKey::Constant<'B'>::Character}}, |
934 }; | 961 }; |
935 | 962 |
936 for (const auto& test : c2s_tests) { | 963 for (const auto& test : c2s_tests) { |
937 CheckKeyTestCase(&rewriter, test); | 964 CheckKeyTestCase(&rewriter, test); |
938 } | 965 } |
| 966 |
| 967 // Remap Search to Backspace. |
| 968 IntegerPrefMember search; |
| 969 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); |
| 970 search.SetValue(chromeos::input_method::kBackspaceKey); |
| 971 |
| 972 KeyTestCase s2b_tests[] = { |
| 973 // Release Control and Escape, as Search and Alt would transform Backspace |
| 974 // to Delete. |
| 975 {ui::ET_KEY_RELEASED, |
| 976 {ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT, ui::EF_NONE, |
| 977 ui::DomKey::CONTROL}, |
| 978 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_ALT_DOWN, |
| 979 ui::DomKey::META}}, |
| 980 {ui::ET_KEY_RELEASED, |
| 981 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}, |
| 982 {ui::VKEY_MENU, ui::DomCode::ALT_LEFT, ui::EF_NONE, ui::DomKey::ALT}}, |
| 983 // Press Search. Confirm the event is now VKEY_BACK. |
| 984 {ui::ET_KEY_PRESSED, |
| 985 {ui::VKEY_LWIN, ui::DomCode::META_LEFT, ui::EF_COMMAND_DOWN, |
| 986 ui::DomKey::META}, |
| 987 {ui::VKEY_BACK, ui::DomCode::BACKSPACE, ui::EF_NONE, |
| 988 ui::DomKey::BACKSPACE}}, |
| 989 }; |
| 990 |
| 991 for (const auto& test : s2b_tests) { |
| 992 CheckKeyTestCase(&rewriter, test); |
| 993 } |
| 994 |
| 995 // Remap Backspace to Escape. |
| 996 IntegerPrefMember backspace; |
| 997 backspace.Init(prefs::kLanguageRemapBackspaceKeyTo, &prefs); |
| 998 backspace.SetValue(chromeos::input_method::kEscapeKey); |
| 999 |
| 1000 KeyTestCase b2e_tests[] = { |
| 1001 // Press Backspace. Confirm the event is now VKEY_ESCAPE. |
| 1002 {ui::ET_KEY_PRESSED, |
| 1003 {ui::VKEY_BACK, ui::DomCode::BACKSPACE, ui::EF_NONE, |
| 1004 ui::DomKey::BACKSPACE}, |
| 1005 {ui::VKEY_ESCAPE, ui::DomCode::ESCAPE, ui::EF_NONE, ui::DomKey::ESCAPE}}, |
| 1006 }; |
| 1007 |
| 1008 for (const auto& test : b2e_tests) { |
| 1009 CheckKeyTestCase(&rewriter, test); |
| 1010 } |
939 } | 1011 } |
940 | 1012 |
941 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) { | 1013 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) { |
942 // Remap Search to Caps Lock. | 1014 // Remap Search to Caps Lock. |
943 syncable_prefs::TestingPrefServiceSyncable prefs; | 1015 syncable_prefs::TestingPrefServiceSyncable prefs; |
944 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 1016 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
945 IntegerPrefMember search; | 1017 IntegerPrefMember search; |
946 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); | 1018 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); |
947 search.SetValue(chromeos::input_method::kCapsLockKey); | 1019 search.SetValue(chromeos::input_method::kCapsLockKey); |
948 | 1020 |
(...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2613 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2685 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
2614 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2686 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
2615 | 2687 |
2616 // Turn off AltGr and Mod3. | 2688 // Turn off AltGr and Mod3. |
2617 sticky_keys_controller_->SetModifiersEnabled(false, false); | 2689 sticky_keys_controller_->SetModifiersEnabled(false, false); |
2618 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2690 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
2619 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2691 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
2620 } | 2692 } |
2621 | 2693 |
2622 } // namespace chromeos | 2694 } // namespace chromeos |
OLD | NEW |