Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 2576913002: Use mojo app list interfaces for mash and classic ash. (Closed)
Patch Set: Sync and rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/accelerators/DEPS ('k') | ash/accelerators/accelerator_interactive_uitest_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/accelerators/accelerator_controller.h" 5 #include "ash/common/accelerators/accelerator_controller.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/accelerators/accelerator_table.h" 8 #include "ash/common/accelerators/accelerator_table.h"
9 #include "ash/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/accessibility_types.h" 10 #include "ash/common/accessibility_types.h"
(...skipping 12 matching lines...) Expand all
23 #include "ash/shell.h" 23 #include "ash/shell.h"
24 #include "ash/test/ash_test_base.h" 24 #include "ash/test/ash_test_base.h"
25 #include "ash/test/lock_state_controller_test_api.h" 25 #include "ash/test/lock_state_controller_test_api.h"
26 #include "ash/test/test_screenshot_delegate.h" 26 #include "ash/test/test_screenshot_delegate.h"
27 #include "ash/test/test_session_state_animator.h" 27 #include "ash/test/test_session_state_animator.h"
28 #include "ash/wm/lock_state_controller.h" 28 #include "ash/wm/lock_state_controller.h"
29 #include "ash/wm/window_state_aura.h" 29 #include "ash/wm/window_state_aura.h"
30 #include "ash/wm/window_util.h" 30 #include "ash/wm/window_util.h"
31 #include "base/test/user_action_tester.cc" 31 #include "base/test/user_action_tester.cc"
32 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" 32 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
33 #include "ui/app_list/presenter/app_list.h"
34 #include "ui/app_list/presenter/test/test_app_list_presenter.h"
33 #include "ui/aura/client/aura_constants.h" 35 #include "ui/aura/client/aura_constants.h"
34 #include "ui/aura/test/test_window_delegate.h" 36 #include "ui/aura/test/test_window_delegate.h"
35 #include "ui/aura/test/test_windows.h" 37 #include "ui/aura/test/test_windows.h"
36 #include "ui/aura/window.h" 38 #include "ui/aura/window.h"
37 #include "ui/display/manager/display_manager.h" 39 #include "ui/display/manager/display_manager.h"
38 #include "ui/display/screen.h" 40 #include "ui/display/screen.h"
39 #include "ui/events/event.h" 41 #include "ui/events/event.h"
40 #include "ui/events/event_processor.h" 42 #include "ui/events/event_processor.h"
41 #include "ui/events/test/event_generator.h" 43 #include "ui/events/test/event_generator.h"
42 #include "ui/message_center/message_center.h" 44 #include "ui/message_center/message_center.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 269 }
268 270
269 private: 271 private:
270 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); 272 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest);
271 }; 273 };
272 274
273 AcceleratorController* AcceleratorControllerTest::GetController() { 275 AcceleratorController* AcceleratorControllerTest::GetController() {
274 return WmShell::Get()->accelerator_controller(); 276 return WmShell::Get()->accelerator_controller();
275 } 277 }
276 278
277 #if !defined(OS_WIN)
278 // Double press of exit shortcut => exiting 279 // Double press of exit shortcut => exiting
279 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) { 280 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) {
280 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); 281 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
281 ui::Accelerator release(press); 282 ui::Accelerator release(press);
282 release.set_type(ui::ET_KEY_RELEASED); 283 release.set_type(ui::ET_KEY_RELEASED);
283 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); 284 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
284 ASSERT_TRUE(ewh); 285 ASSERT_TRUE(ewh);
285 StubForTest(ewh); 286 StubForTest(ewh);
286 EXPECT_TRUE(is_idle(ewh)); 287 EXPECT_TRUE(is_idle(ewh));
287 EXPECT_FALSE(is_ui_shown(ewh)); 288 EXPECT_FALSE(is_ui_shown(ewh));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 ASSERT_TRUE(ewh); 324 ASSERT_TRUE(ewh);
324 StubForTest(ewh); 325 StubForTest(ewh);
325 326
326 // Trigger once to show the bubble. 327 // Trigger once to show the bubble.
327 ewh->HandleAccelerator(); 328 ewh->HandleAccelerator();
328 EXPECT_FALSE(is_idle(ewh)); 329 EXPECT_FALSE(is_idle(ewh));
329 EXPECT_TRUE(is_ui_shown(ewh)); 330 EXPECT_TRUE(is_ui_shown(ewh));
330 331
331 // Exit ash and there should be no crash 332 // Exit ash and there should be no crash
332 } 333 }
333 #endif // !defined(OS_WIN)
334 334
335 TEST_F(AcceleratorControllerTest, Register) { 335 TEST_F(AcceleratorControllerTest, Register) {
336 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 336 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
337 TestTarget target; 337 TestTarget target;
338 GetController()->Register(accelerator_a, &target); 338 GetController()->Register(accelerator_a, &target);
339 339
340 // The registered accelerator is processed. 340 // The registered accelerator is processed.
341 EXPECT_TRUE(ProcessInController(accelerator_a)); 341 EXPECT_TRUE(ProcessInController(accelerator_a));
342 EXPECT_EQ(1, target.accelerator_pressed_count()); 342 EXPECT_EQ(1, target.accelerator_pressed_count());
343 } 343 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 // The same accelerator - toggling suppressed. 736 // The same accelerator - toggling suppressed.
737 generator.PressKey(ui::VKEY_J, ui::EF_ALT_DOWN | ui::EF_IS_REPEAT); 737 generator.PressKey(ui::VKEY_J, ui::EF_ALT_DOWN | ui::EF_IS_REPEAT);
738 EXPECT_TRUE(window_state->IsFullscreen()); 738 EXPECT_TRUE(window_state->IsFullscreen());
739 739
740 // Different accelerator. 740 // Different accelerator.
741 generator.PressKey(ui::VKEY_K, ui::EF_ALT_DOWN); 741 generator.PressKey(ui::VKEY_K, ui::EF_ALT_DOWN);
742 EXPECT_FALSE(window_state->IsFullscreen()); 742 EXPECT_FALSE(window_state->IsFullscreen());
743 } 743 }
744 744
745 // TODO(oshima): Fix this test to use EventGenerator. 745 // TODO(oshima): Fix this test to use EventGenerator.
746 #if defined(OS_WIN) 746 #if defined(USE_X11)
747 // crbug.com/317592 747 TEST_F(AcceleratorControllerTest, ProcessOnce) {
748 #define MAYBE_ProcessOnce DISABLED_ProcessOnce
749 #else
750 #define MAYBE_ProcessOnce ProcessOnce
751 #endif
752
753 #if defined(OS_WIN) || defined(USE_X11)
754 TEST_F(AcceleratorControllerTest, MAYBE_ProcessOnce) {
755 // The IME event filter interferes with the basic key event propagation we 748 // The IME event filter interferes with the basic key event propagation we
756 // attempt to do here, so we disable it. 749 // attempt to do here, so we disable it.
757 DisableIME(); 750 DisableIME();
758 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 751 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
759 TestTarget target; 752 TestTarget target;
760 GetController()->Register(accelerator_a, &target); 753 GetController()->Register(accelerator_a, &target);
761 754
762 // The accelerator is processed only once. 755 // The accelerator is processed only once.
763 ui::EventProcessor* dispatcher = 756 ui::EventProcessor* dispatcher =
764 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); 757 Shell::GetPrimaryRootWindow()->GetHost()->event_processor();
765 #if defined(OS_WIN)
766 MSG msg1 = {NULL, WM_KEYDOWN, ui::VKEY_A, 0};
767 ui::KeyEvent key_event1(msg1);
768 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1);
769 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed);
770 758
771 MSG msg2 = {NULL, WM_CHAR, L'A', 0};
772 ui::KeyEvent key_event2(msg2);
773 details = dispatcher->OnEventFromSource(&key_event2);
774 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed);
775
776 MSG msg3 = {NULL, WM_KEYUP, ui::VKEY_A, 0};
777 ui::KeyEvent key_event3(msg3);
778 details = dispatcher->OnEventFromSource(&key_event3);
779 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed);
780 #elif defined(USE_X11)
781 ui::ScopedXI2Event key_event; 759 ui::ScopedXI2Event key_event;
782 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); 760 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
783 ui::KeyEvent key_event1(key_event); 761 ui::KeyEvent key_event1(key_event);
784 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); 762 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1);
785 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); 763 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed);
786 764
787 ui::KeyEvent key_event2('A', ui::VKEY_A, ui::EF_NONE); 765 ui::KeyEvent key_event2('A', ui::VKEY_A, ui::EF_NONE);
788 details = dispatcher->OnEventFromSource(&key_event2); 766 details = dispatcher->OnEventFromSource(&key_event2);
789 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed); 767 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed);
790 768
791 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); 769 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0);
792 ui::KeyEvent key_event3(key_event); 770 ui::KeyEvent key_event3(key_event);
793 details = dispatcher->OnEventFromSource(&key_event3); 771 details = dispatcher->OnEventFromSource(&key_event3);
794 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); 772 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed);
795 #endif
796 EXPECT_EQ(1, target.accelerator_pressed_count()); 773 EXPECT_EQ(1, target.accelerator_pressed_count());
797 } 774 }
798 #endif 775 #endif
799 776
800 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { 777 TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
801 // CycleBackward 778 // CycleBackward
802 EXPECT_TRUE(ProcessInController( 779 EXPECT_TRUE(ProcessInController(
803 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); 780 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN)));
804 // CycleForward 781 // CycleForward
805 EXPECT_TRUE( 782 EXPECT_TRUE(
806 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); 783 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN)));
807 // CycleLinear 784 // CycleLinear
808 EXPECT_TRUE(ProcessInController( 785 EXPECT_TRUE(ProcessInController(
809 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_NONE))); 786 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_NONE)));
810 787
811 #if defined(OS_CHROMEOS)
812 // The "Take Screenshot", "Take Partial Screenshot", volume, brightness, and 788 // The "Take Screenshot", "Take Partial Screenshot", volume, brightness, and
813 // keyboard brightness accelerators are only defined on ChromeOS. 789 // keyboard brightness accelerators are only defined on ChromeOS.
814 { 790 {
815 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); 791 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
816 delegate->set_can_take_screenshot(false); 792 delegate->set_can_take_screenshot(false);
817 EXPECT_TRUE(ProcessInController( 793 EXPECT_TRUE(ProcessInController(
818 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); 794 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN)));
819 EXPECT_TRUE( 795 EXPECT_TRUE(
820 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); 796 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE)));
821 EXPECT_TRUE(ProcessInController(ui::Accelerator( 797 EXPECT_TRUE(ProcessInController(ui::Accelerator(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 std::unique_ptr<KeyboardBrightnessControlDelegate>(delegate)); 864 std::unique_ptr<KeyboardBrightnessControlDelegate>(delegate));
889 EXPECT_EQ(0, delegate->handle_keyboard_brightness_down_count()); 865 EXPECT_EQ(0, delegate->handle_keyboard_brightness_down_count());
890 EXPECT_TRUE(ProcessInController(alt_brightness_down)); 866 EXPECT_TRUE(ProcessInController(alt_brightness_down));
891 EXPECT_EQ(1, delegate->handle_keyboard_brightness_down_count()); 867 EXPECT_EQ(1, delegate->handle_keyboard_brightness_down_count());
892 EXPECT_EQ(alt_brightness_down, delegate->last_accelerator()); 868 EXPECT_EQ(alt_brightness_down, delegate->last_accelerator());
893 EXPECT_EQ(0, delegate->handle_keyboard_brightness_up_count()); 869 EXPECT_EQ(0, delegate->handle_keyboard_brightness_up_count());
894 EXPECT_TRUE(ProcessInController(alt_brightness_up)); 870 EXPECT_TRUE(ProcessInController(alt_brightness_up));
895 EXPECT_EQ(1, delegate->handle_keyboard_brightness_up_count()); 871 EXPECT_EQ(1, delegate->handle_keyboard_brightness_up_count());
896 EXPECT_EQ(alt_brightness_up, delegate->last_accelerator()); 872 EXPECT_EQ(alt_brightness_up, delegate->last_accelerator());
897 } 873 }
898 #endif
899 874
900 #if !defined(OS_WIN)
901 // Exit 875 // Exit
902 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); 876 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
903 ASSERT_TRUE(ewh); 877 ASSERT_TRUE(ewh);
904 StubForTest(ewh); 878 StubForTest(ewh);
905 EXPECT_TRUE(is_idle(ewh)); 879 EXPECT_TRUE(is_idle(ewh));
906 EXPECT_FALSE(is_ui_shown(ewh)); 880 EXPECT_FALSE(is_ui_shown(ewh));
907 EXPECT_TRUE(ProcessInController( 881 EXPECT_TRUE(ProcessInController(
908 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 882 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
909 EXPECT_FALSE(is_idle(ewh)); 883 EXPECT_FALSE(is_idle(ewh));
910 EXPECT_TRUE(is_ui_shown(ewh)); 884 EXPECT_TRUE(is_ui_shown(ewh));
911 SimulateTimerExpired(ewh); 885 SimulateTimerExpired(ewh);
912 EXPECT_TRUE(is_idle(ewh)); 886 EXPECT_TRUE(is_idle(ewh));
913 EXPECT_FALSE(is_ui_shown(ewh)); 887 EXPECT_FALSE(is_ui_shown(ewh));
914 Reset(ewh); 888 Reset(ewh);
915 #endif
916 889
917 // New tab 890 // New tab
918 EXPECT_TRUE( 891 EXPECT_TRUE(
919 ProcessInController(ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN))); 892 ProcessInController(ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN)));
920 893
921 // New incognito window 894 // New incognito window
922 EXPECT_TRUE(ProcessInController( 895 EXPECT_TRUE(ProcessInController(
923 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 896 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
924 897
925 // New window 898 // New window
926 EXPECT_TRUE( 899 EXPECT_TRUE(
927 ProcessInController(ui::Accelerator(ui::VKEY_N, ui::EF_CONTROL_DOWN))); 900 ProcessInController(ui::Accelerator(ui::VKEY_N, ui::EF_CONTROL_DOWN)));
928 901
929 // Restore tab 902 // Restore tab
930 EXPECT_TRUE(ProcessInController( 903 EXPECT_TRUE(ProcessInController(
931 ui::Accelerator(ui::VKEY_T, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 904 ui::Accelerator(ui::VKEY_T, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
932 905
933 // Show task manager 906 // Show task manager
934 EXPECT_TRUE( 907 EXPECT_TRUE(
935 ProcessInController(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN))); 908 ProcessInController(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN)));
936 909
937 #if defined(OS_CHROMEOS)
938 // Open file manager 910 // Open file manager
939 EXPECT_TRUE(ProcessInController( 911 EXPECT_TRUE(ProcessInController(
940 ui::Accelerator(ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); 912 ui::Accelerator(ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN)));
941 913
942 // Lock screen 914 // Lock screen
943 // NOTE: Accelerators that do not work on the lock screen need to be 915 // NOTE: Accelerators that do not work on the lock screen need to be
944 // tested before the sequence below is invoked because it causes a side 916 // tested before the sequence below is invoked because it causes a side
945 // effect of locking the screen. 917 // effect of locking the screen.
946 EXPECT_TRUE( 918 EXPECT_TRUE(
947 ProcessInController(ui::Accelerator(ui::VKEY_L, ui::EF_COMMAND_DOWN))); 919 ProcessInController(ui::Accelerator(ui::VKEY_L, ui::EF_COMMAND_DOWN)));
948 #endif
949 } 920 }
950 921
951 TEST_F(AcceleratorControllerTest, GlobalAcceleratorsToggleAppList) { 922 TEST_F(AcceleratorControllerTest, GlobalAcceleratorsToggleAppList) {
923 app_list::test::TestAppListPresenter test_app_list_presenter;
924 WmShell::Get()->app_list()->SetAppListPresenter(
925 test_app_list_presenter.CreateInterfacePtrAndBind());
952 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); 926 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate();
953 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
954 927
955 // The press event should not open the AppList, the release should instead. 928 // The press event should not toggle the AppList, the release should instead.
956 EXPECT_FALSE( 929 EXPECT_FALSE(
957 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); 930 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE)));
931 RunAllPendingInMessageLoop();
958 EXPECT_EQ(ui::VKEY_LWIN, GetCurrentAccelerator().key_code()); 932 EXPECT_EQ(ui::VKEY_LWIN, GetCurrentAccelerator().key_code());
959 933 EXPECT_EQ(0u, test_app_list_presenter.toggle_count());
960 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
961 934
962 EXPECT_TRUE( 935 EXPECT_TRUE(
963 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); 936 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE)));
964 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 937 RunAllPendingInMessageLoop();
965 938 EXPECT_EQ(1u, test_app_list_presenter.toggle_count());
966 EXPECT_EQ(ui::VKEY_LWIN, GetPreviousAccelerator().key_code()); 939 EXPECT_EQ(ui::VKEY_LWIN, GetPreviousAccelerator().key_code());
967 940
968 // When spoken feedback is on, the AppList should not toggle. 941 // When spoken feedback is on, the AppList should not toggle.
969 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); 942 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE);
970 EXPECT_FALSE( 943 EXPECT_FALSE(
971 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); 944 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE)));
972 EXPECT_FALSE( 945 EXPECT_FALSE(
973 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); 946 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE)));
974 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); 947 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE);
975 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 948 RunAllPendingInMessageLoop();
949 EXPECT_EQ(1u, test_app_list_presenter.toggle_count());
976 950
951 // Turning off spoken feedback should allow the AppList to toggle again.
977 EXPECT_FALSE( 952 EXPECT_FALSE(
978 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); 953 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE)));
979 EXPECT_TRUE( 954 EXPECT_TRUE(
980 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); 955 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE)));
981 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); 956 RunAllPendingInMessageLoop();
957 EXPECT_EQ(2u, test_app_list_presenter.toggle_count());
982 958
983 // When spoken feedback is on, the AppList should not toggle.
984 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE);
985 EXPECT_FALSE(
986 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE)));
987 EXPECT_FALSE(
988 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE)));
989 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE);
990 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
991
992 #if defined(OS_CHROMEOS)
993 // The press of VKEY_BROWSER_SEARCH should toggle the AppList 959 // The press of VKEY_BROWSER_SEARCH should toggle the AppList
994 EXPECT_TRUE(ProcessInController( 960 EXPECT_TRUE(ProcessInController(
995 ui::Accelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); 961 ui::Accelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE)));
996 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 962 RunAllPendingInMessageLoop();
963 EXPECT_EQ(3u, test_app_list_presenter.toggle_count());
997 EXPECT_FALSE(ProcessInController( 964 EXPECT_FALSE(ProcessInController(
998 ReleaseAccelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); 965 ReleaseAccelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE)));
999 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 966 RunAllPendingInMessageLoop();
1000 #endif 967 EXPECT_EQ(3u, test_app_list_presenter.toggle_count());
1001 } 968 }
1002 969
1003 TEST_F(AcceleratorControllerTest, ImeGlobalAccelerators) { 970 TEST_F(AcceleratorControllerTest, ImeGlobalAccelerators) {
1004 // Test IME shortcuts. 971 // Test IME shortcuts.
1005 ui::Accelerator control_space_down(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 972 ui::Accelerator control_space_down(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
1006 control_space_down.set_type(ui::ET_KEY_PRESSED); 973 control_space_down.set_type(ui::ET_KEY_PRESSED);
1007 ui::Accelerator control_space_up(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); 974 ui::Accelerator control_space_up(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN);
1008 control_space_up.set_type(ui::ET_KEY_RELEASED); 975 control_space_up.set_type(ui::ET_KEY_RELEASED);
1009 const ui::Accelerator convert(ui::VKEY_CONVERT, ui::EF_NONE); 976 const ui::Accelerator convert(ui::VKEY_CONVERT, ui::EF_NONE);
1010 const ui::Accelerator non_convert(ui::VKEY_NONCONVERT, ui::EF_NONE); 977 const ui::Accelerator non_convert(ui::VKEY_NONCONVERT, ui::EF_NONE);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it. 1012 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it.
1046 const ui::Accelerator shift_alt_return_press( 1013 const ui::Accelerator shift_alt_return_press(
1047 ui::VKEY_RETURN, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1014 ui::VKEY_RETURN, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1048 EXPECT_FALSE(ProcessInController(shift_alt_return_press)); 1015 EXPECT_FALSE(ProcessInController(shift_alt_return_press));
1049 const ui::Accelerator shift_alt_space_press( 1016 const ui::Accelerator shift_alt_space_press(
1050 ui::VKEY_SPACE, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1017 ui::VKEY_SPACE, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1051 EXPECT_FALSE(ProcessInController(shift_alt_space_press)); 1018 EXPECT_FALSE(ProcessInController(shift_alt_space_press));
1052 } 1019 }
1053 1020
1054 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) { 1021 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) {
1055 #if defined(OS_CHROMEOS)
1056 // Power key is reserved on chromeos. 1022 // Power key is reserved on chromeos.
1057 EXPECT_TRUE(GetController()->IsReserved( 1023 EXPECT_TRUE(GetController()->IsReserved(
1058 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); 1024 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE)));
1059 EXPECT_FALSE(GetController()->IsPreferred( 1025 EXPECT_FALSE(GetController()->IsPreferred(
1060 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); 1026 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE)));
1061 #endif 1027
1062 // ALT+Tab are not reserved but preferred. 1028 // ALT+Tab are not reserved but preferred.
1063 EXPECT_FALSE(GetController()->IsReserved( 1029 EXPECT_FALSE(GetController()->IsReserved(
1064 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); 1030 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN)));
1065 EXPECT_FALSE(GetController()->IsReserved( 1031 EXPECT_FALSE(GetController()->IsReserved(
1066 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); 1032 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN)));
1067 EXPECT_TRUE(GetController()->IsPreferred( 1033 EXPECT_TRUE(GetController()->IsPreferred(
1068 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); 1034 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN)));
1069 EXPECT_TRUE(GetController()->IsPreferred( 1035 EXPECT_TRUE(GetController()->IsPreferred(
1070 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); 1036 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN)));
1071 1037
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 aura::Window* w1 = CreateTestWindowInShellWithId(0); 1074 aura::Window* w1 = CreateTestWindowInShellWithId(0);
1109 aura::Window* w2 = CreateTestWindowInShellWithId(1); 1075 aura::Window* w2 = CreateTestWindowInShellWithId(1);
1110 wm::ActivateWindow(w1); 1076 wm::ActivateWindow(w1);
1111 1077
1112 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); 1078 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN);
1113 wm::WindowState* w1_state = wm::GetWindowState(w1); 1079 wm::WindowState* w1_state = wm::GetWindowState(w1);
1114 w1_state->OnWMEvent(&fullscreen); 1080 w1_state->OnWMEvent(&fullscreen);
1115 ASSERT_TRUE(w1_state->IsFullscreen()); 1081 ASSERT_TRUE(w1_state->IsFullscreen());
1116 1082
1117 ui::test::EventGenerator& generator = GetEventGenerator(); 1083 ui::test::EventGenerator& generator = GetEventGenerator();
1118 #if defined(OS_CHROMEOS) 1084
1119 // Power key (reserved) should always be handled. 1085 // Power key (reserved) should always be handled.
1120 test::LockStateControllerTestApi test_api( 1086 test::LockStateControllerTestApi test_api(
1121 Shell::GetInstance()->lock_state_controller()); 1087 Shell::GetInstance()->lock_state_controller());
1122 EXPECT_FALSE(test_api.is_animating_lock()); 1088 EXPECT_FALSE(test_api.is_animating_lock());
1123 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); 1089 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE);
1124 EXPECT_TRUE(test_api.is_animating_lock()); 1090 EXPECT_TRUE(test_api.is_animating_lock());
1125 #endif
1126 1091
1127 auto press_and_release_alt_tab = [&generator]() { 1092 auto press_and_release_alt_tab = [&generator]() {
1128 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 1093 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
1129 // Release the alt key to trigger the window activation. 1094 // Release the alt key to trigger the window activation.
1130 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); 1095 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE);
1131 }; 1096 };
1132 1097
1133 // A fullscreen window can consume ALT-TAB (preferred). 1098 // A fullscreen window can consume ALT-TAB (preferred).
1134 ASSERT_EQ(w1, wm::GetActiveWindow()); 1099 ASSERT_EQ(w1, wm::GetActiveWindow());
1135 press_and_release_alt_tab(); 1100 press_and_release_alt_tab();
(...skipping 22 matching lines...) Expand all
1158 wm::ActivateWindow(w1); 1123 wm::ActivateWindow(w1);
1159 1124
1160 { 1125 {
1161 wm::WMEvent pin_event(wm::WM_EVENT_PIN); 1126 wm::WMEvent pin_event(wm::WM_EVENT_PIN);
1162 wm::WindowState* w1_state = wm::GetWindowState(w1); 1127 wm::WindowState* w1_state = wm::GetWindowState(w1);
1163 w1_state->OnWMEvent(&pin_event); 1128 w1_state->OnWMEvent(&pin_event);
1164 ASSERT_TRUE(w1_state->IsPinned()); 1129 ASSERT_TRUE(w1_state->IsPinned());
1165 } 1130 }
1166 1131
1167 ui::test::EventGenerator& generator = GetEventGenerator(); 1132 ui::test::EventGenerator& generator = GetEventGenerator();
1168 #if defined(OS_CHROMEOS) 1133
1169 // Power key (reserved) should always be handled. 1134 // Power key (reserved) should always be handled.
1170 test::LockStateControllerTestApi test_api( 1135 test::LockStateControllerTestApi test_api(
1171 Shell::GetInstance()->lock_state_controller()); 1136 Shell::GetInstance()->lock_state_controller());
1172 EXPECT_FALSE(test_api.is_animating_lock()); 1137 EXPECT_FALSE(test_api.is_animating_lock());
1173 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); 1138 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE);
1174 EXPECT_TRUE(test_api.is_animating_lock()); 1139 EXPECT_TRUE(test_api.is_animating_lock());
1175 #endif
1176 1140
1177 // A pinned window can consume ALT-TAB (preferred), but no side effect. 1141 // A pinned window can consume ALT-TAB (preferred), but no side effect.
1178 ASSERT_EQ(w1, wm::GetActiveWindow()); 1142 ASSERT_EQ(w1, wm::GetActiveWindow());
1179 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 1143 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
1180 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 1144 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
1181 ASSERT_EQ(w1, wm::GetActiveWindow()); 1145 ASSERT_EQ(w1, wm::GetActiveWindow());
1182 ASSERT_NE(w2, wm::GetActiveWindow()); 1146 ASSERT_NE(w2, wm::GetActiveWindow());
1183 } 1147 }
1184 1148
1185 #if defined(OS_CHROMEOS)
1186 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { 1149 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
1187 std::set<AcceleratorAction> all_actions; 1150 std::set<AcceleratorAction> all_actions;
1188 for (size_t i = 0; i < kAcceleratorDataLength; ++i) 1151 for (size_t i = 0; i < kAcceleratorDataLength; ++i)
1189 all_actions.insert(kAcceleratorData[i].action); 1152 all_actions.insert(kAcceleratorData[i].action);
1190 std::set<AcceleratorAction> all_debug_actions; 1153 std::set<AcceleratorAction> all_debug_actions;
1191 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) 1154 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
1192 all_debug_actions.insert(kDebugAcceleratorData[i].action); 1155 all_debug_actions.insert(kDebugAcceleratorData[i].action);
1193 std::set<AcceleratorAction> all_dev_actions; 1156 std::set<AcceleratorAction> all_dev_actions;
1194 for (size_t i = 0; i < kDeveloperAcceleratorDataLength; ++i) 1157 for (size_t i = 0; i < kDeveloperAcceleratorDataLength; ++i)
1195 all_dev_actions.insert(kDeveloperAcceleratorData[i].action); 1158 all_dev_actions.insert(kDeveloperAcceleratorData[i].action);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 EXPECT_TRUE(ProcessInController(volume_down)); 1238 EXPECT_TRUE(ProcessInController(volume_down));
1276 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); 1239 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeDown_F9"));
1277 EXPECT_EQ(volume_down, history->current_accelerator()); 1240 EXPECT_EQ(volume_down, history->current_accelerator());
1278 1241
1279 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); 1242 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeUp_F10"));
1280 EXPECT_TRUE(ProcessInController(volume_up)); 1243 EXPECT_TRUE(ProcessInController(volume_up));
1281 EXPECT_EQ(volume_up, history->current_accelerator()); 1244 EXPECT_EQ(volume_up, history->current_accelerator());
1282 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); 1245 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeUp_F10"));
1283 } 1246 }
1284 } 1247 }
1285 #endif
1286 1248
1287 TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) { 1249 TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) {
1288 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); 1250 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate();
1289 1251
1290 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { 1252 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) {
1291 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); 1253 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE);
1292 EXPECT_TRUE( 1254 EXPECT_TRUE(
1293 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i])); 1255 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]));
1294 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); 1256 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED);
1295 } 1257 }
(...skipping 12 matching lines...) Expand all
1308 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { 1270 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) {
1309 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 1271 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
1310 wm::ActivateWindow(window.get()); 1272 wm::ActivateWindow(window.get());
1311 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); 1273 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE);
1312 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); 1274 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE);
1313 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); 1275 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]);
1314 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); 1276 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED);
1315 } 1277 }
1316 } 1278 }
1317 1279
1318 #if defined(OS_CHROMEOS)
1319 namespace { 1280 namespace {
1320 1281
1321 // defines a class to test the behavior of deprecated accelerators. 1282 // defines a class to test the behavior of deprecated accelerators.
1322 class DeprecatedAcceleratorTester : public AcceleratorControllerTest { 1283 class DeprecatedAcceleratorTester : public AcceleratorControllerTest {
1323 public: 1284 public:
1324 DeprecatedAcceleratorTester() {} 1285 DeprecatedAcceleratorTester() {}
1325 ~DeprecatedAcceleratorTester() override {} 1286 ~DeprecatedAcceleratorTester() override {}
1326 1287
1327 void SetUp() override { 1288 void SetUp() override {
1328 AcceleratorControllerTest::SetUp(); 1289 AcceleratorControllerTest::SetUp();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 EXPECT_TRUE(ProcessInController(CreateAccelerator(data))); 1371 EXPECT_TRUE(ProcessInController(CreateAccelerator(data)));
1411 1372
1412 // Expect no notifications from the new accelerators. 1373 // Expect no notifications from the new accelerators.
1413 EXPECT_TRUE(IsMessageCenterEmpty()); 1374 EXPECT_TRUE(IsMessageCenterEmpty());
1414 1375
1415 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1376 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1416 // screen before we proceed testing the rest of accelerators. 1377 // screen before we proceed testing the rest of accelerators.
1417 ResetStateIfNeeded(); 1378 ResetStateIfNeeded();
1418 } 1379 }
1419 } 1380 }
1420 #endif // defined(OS_CHROMEOS)
1421 1381
1422 } // namespace ash 1382 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/DEPS ('k') | ash/accelerators/accelerator_interactive_uitest_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698