OLD | NEW |
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" |
11 #include "ash/common/ime_control_delegate.h" | 11 #include "ash/common/ime_control_delegate.h" |
12 #include "ash/common/session/session_state_delegate.h" | 12 #include "ash/common/session/session_state_delegate.h" |
13 #include "ash/common/system/brightness_control_delegate.h" | 13 #include "ash/common/system/brightness_control_delegate.h" |
14 #include "ash/common/system/keyboard_brightness_control_delegate.h" | 14 #include "ash/common/system/keyboard_brightness_control_delegate.h" |
15 #include "ash/common/system/tray/system_tray_delegate.h" | 15 #include "ash/common/system/tray/system_tray_delegate.h" |
16 #include "ash/common/system/volume_control_delegate.h" | |
17 #include "ash/common/test/test_volume_control_delegate.h" | |
18 #include "ash/common/wm/panels/panel_layout_manager.h" | 16 #include "ash/common/wm/panels/panel_layout_manager.h" |
19 #include "ash/common/wm/window_positioning_utils.h" | 17 #include "ash/common/wm/window_positioning_utils.h" |
20 #include "ash/common/wm/window_state.h" | 18 #include "ash/common/wm/window_state.h" |
21 #include "ash/common/wm/wm_event.h" | 19 #include "ash/common/wm/wm_event.h" |
22 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
23 #include "ash/display/display_manager.h" | 21 #include "ash/display/display_manager.h" |
24 #include "ash/public/cpp/shell_window_ids.h" | 22 #include "ash/public/cpp/shell_window_ids.h" |
25 #include "ash/shell.h" | 23 #include "ash/shell.h" |
26 #include "ash/test/ash_test_base.h" | 24 #include "ash/test/ash_test_base.h" |
27 #include "ash/test/display_manager_test_api.h" | 25 #include "ash/test/display_manager_test_api.h" |
28 #include "ash/test/test_screenshot_delegate.h" | 26 #include "ash/test/test_screenshot_delegate.h" |
29 #include "ash/test/test_session_state_animator.h" | 27 #include "ash/test/test_session_state_animator.h" |
30 #include "ash/test/test_shelf_delegate.h" | 28 #include "ash/test/test_shelf_delegate.h" |
31 #include "ash/wm/lock_state_controller.h" | 29 #include "ash/wm/lock_state_controller.h" |
32 #include "ash/wm/window_state_aura.h" | 30 #include "ash/wm/window_state_aura.h" |
33 #include "ash/wm/window_util.h" | 31 #include "ash/wm/window_util.h" |
| 32 #include "base/test/user_action_tester.cc" |
34 #include "ui/aura/client/aura_constants.h" | 33 #include "ui/aura/client/aura_constants.h" |
35 #include "ui/aura/test/test_window_delegate.h" | 34 #include "ui/aura/test/test_window_delegate.h" |
36 #include "ui/aura/test/test_windows.h" | 35 #include "ui/aura/test/test_windows.h" |
37 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
38 #include "ui/display/screen.h" | 37 #include "ui/display/screen.h" |
39 #include "ui/events/event.h" | 38 #include "ui/events/event.h" |
40 #include "ui/events/event_processor.h" | 39 #include "ui/events/event_processor.h" |
41 #include "ui/events/test/event_generator.h" | 40 #include "ui/events/test/event_generator.h" |
42 #include "ui/message_center/message_center.h" | 41 #include "ui/message_center/message_center.h" |
43 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 831 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
833 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 832 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
834 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 833 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
835 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 834 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
836 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 835 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
837 } | 836 } |
838 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 837 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
839 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 838 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
840 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); | 839 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); |
841 { | 840 { |
842 TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate; | 841 base::UserActionTester user_action_tester; |
843 WmShell::Get()->system_tray_delegate()->SetVolumeControlDelegate( | 842 ui::AcceleratorHistory* history = GetController()->accelerator_history(); |
844 std::unique_ptr<VolumeControlDelegate>(delegate)); | 843 |
845 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | 844 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); |
846 EXPECT_TRUE(ProcessInController(volume_mute)); | 845 EXPECT_TRUE(ProcessInController(volume_mute)); |
847 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | 846 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); |
848 EXPECT_EQ(volume_mute, delegate->last_accelerator()); | 847 EXPECT_EQ(volume_mute, history->current_accelerator()); |
849 EXPECT_EQ(0, delegate->handle_volume_down_count()); | 848 |
| 849 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); |
850 EXPECT_TRUE(ProcessInController(volume_down)); | 850 EXPECT_TRUE(ProcessInController(volume_down)); |
851 EXPECT_EQ(1, delegate->handle_volume_down_count()); | 851 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); |
852 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 852 EXPECT_EQ(volume_down, history->current_accelerator()); |
853 EXPECT_EQ(0, delegate->handle_volume_up_count()); | 853 |
| 854 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); |
854 EXPECT_TRUE(ProcessInController(volume_up)); | 855 EXPECT_TRUE(ProcessInController(volume_up)); |
855 EXPECT_EQ(1, delegate->handle_volume_up_count()); | 856 EXPECT_EQ(volume_up, history->current_accelerator()); |
856 EXPECT_EQ(volume_up, delegate->last_accelerator()); | 857 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); |
857 } | 858 } |
858 // Brightness | 859 // Brightness |
859 // ui::VKEY_BRIGHTNESS_DOWN/UP are not defined on Windows. | 860 // ui::VKEY_BRIGHTNESS_DOWN/UP are not defined on Windows. |
860 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); | 861 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); |
861 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); | 862 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); |
862 { | 863 { |
863 DummyBrightnessControlDelegate* delegate = | 864 DummyBrightnessControlDelegate* delegate = |
864 new DummyBrightnessControlDelegate; | 865 new DummyBrightnessControlDelegate; |
865 SetBrightnessControlDelegate( | 866 SetBrightnessControlDelegate( |
866 std::unique_ptr<BrightnessControlDelegate>(delegate)); | 867 std::unique_ptr<BrightnessControlDelegate>(delegate)); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 EXPECT_EQ(0, delegate->handle_brightness_up_count()); | 1257 EXPECT_EQ(0, delegate->handle_brightness_up_count()); |
1257 EXPECT_TRUE(ProcessInController(brightness_up)); | 1258 EXPECT_TRUE(ProcessInController(brightness_up)); |
1258 EXPECT_EQ(1, delegate->handle_brightness_up_count()); | 1259 EXPECT_EQ(1, delegate->handle_brightness_up_count()); |
1259 EXPECT_EQ(brightness_up, delegate->last_accelerator()); | 1260 EXPECT_EQ(brightness_up, delegate->last_accelerator()); |
1260 } | 1261 } |
1261 // Volume | 1262 // Volume |
1262 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 1263 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
1263 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 1264 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
1264 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); | 1265 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); |
1265 { | 1266 { |
| 1267 base::UserActionTester user_action_tester; |
| 1268 ui::AcceleratorHistory* history = GetController()->accelerator_history(); |
| 1269 |
| 1270 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); |
1266 EXPECT_TRUE(ProcessInController(volume_mute)); | 1271 EXPECT_TRUE(ProcessInController(volume_mute)); |
| 1272 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); |
| 1273 EXPECT_EQ(volume_mute, history->current_accelerator()); |
| 1274 |
| 1275 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); |
1267 EXPECT_TRUE(ProcessInController(volume_down)); | 1276 EXPECT_TRUE(ProcessInController(volume_down)); |
| 1277 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); |
| 1278 EXPECT_EQ(volume_down, history->current_accelerator()); |
| 1279 |
| 1280 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); |
1268 EXPECT_TRUE(ProcessInController(volume_up)); | 1281 EXPECT_TRUE(ProcessInController(volume_up)); |
1269 TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate; | 1282 EXPECT_EQ(volume_up, history->current_accelerator()); |
1270 WmShell::Get()->system_tray_delegate()->SetVolumeControlDelegate( | 1283 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); |
1271 std::unique_ptr<VolumeControlDelegate>(delegate)); | |
1272 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | |
1273 EXPECT_TRUE(ProcessInController(volume_mute)); | |
1274 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | |
1275 EXPECT_EQ(volume_mute, delegate->last_accelerator()); | |
1276 EXPECT_EQ(0, delegate->handle_volume_down_count()); | |
1277 EXPECT_TRUE(ProcessInController(volume_down)); | |
1278 EXPECT_EQ(1, delegate->handle_volume_down_count()); | |
1279 EXPECT_EQ(volume_down, delegate->last_accelerator()); | |
1280 EXPECT_EQ(0, delegate->handle_volume_up_count()); | |
1281 EXPECT_TRUE(ProcessInController(volume_up)); | |
1282 EXPECT_EQ(1, delegate->handle_volume_up_count()); | |
1283 EXPECT_EQ(volume_up, delegate->last_accelerator()); | |
1284 } | 1284 } |
1285 } | 1285 } |
1286 #endif | 1286 #endif |
1287 | 1287 |
1288 TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) { | 1288 TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) { |
1289 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); | 1289 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); |
1290 | 1290 |
1291 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { | 1291 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { |
1292 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1292 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
1293 EXPECT_TRUE( | 1293 EXPECT_TRUE( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 EXPECT_TRUE(IsMessageCenterEmpty()); | 1414 EXPECT_TRUE(IsMessageCenterEmpty()); |
1415 | 1415 |
1416 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1416 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
1417 // screen before we proceed testing the rest of accelerators. | 1417 // screen before we proceed testing the rest of accelerators. |
1418 ResetStateIfNeeded(); | 1418 ResetStateIfNeeded(); |
1419 } | 1419 } |
1420 } | 1420 } |
1421 #endif // defined(OS_CHROMEOS) | 1421 #endif // defined(OS_CHROMEOS) |
1422 | 1422 |
1423 } // namespace ash | 1423 } // namespace ash |
OLD | NEW |