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/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_table.h" | 7 #include "ash/accelerators/accelerator_table.h" |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/ime_control_delegate.h" | 11 #include "ash/ime_control_delegate.h" |
12 #include "ash/screen_util.h" | 12 #include "ash/screen_util.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "ash/system/brightness_control_delegate.h" | 15 #include "ash/system/brightness_control_delegate.h" |
16 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" | 16 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" |
17 #include "ash/system/tray/system_tray_delegate.h" | 17 #include "ash/system/tray/system_tray_delegate.h" |
18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
19 #include "ash/test/display_manager_test_api.h" | 19 #include "ash/test/display_manager_test_api.h" |
20 #include "ash/test/test_screenshot_delegate.h" | 20 #include "ash/test/test_screenshot_delegate.h" |
| 21 #include "ash/test/test_session_state_animator.h" |
21 #include "ash/test/test_shell_delegate.h" | 22 #include "ash/test/test_shell_delegate.h" |
22 #include "ash/test/test_volume_control_delegate.h" | 23 #include "ash/test/test_volume_control_delegate.h" |
23 #include "ash/volume_control_delegate.h" | 24 #include "ash/volume_control_delegate.h" |
| 25 #include "ash/wm/lock_state_controller.h" |
24 #include "ash/wm/window_state.h" | 26 #include "ash/wm/window_state.h" |
25 #include "ash/wm/window_util.h" | 27 #include "ash/wm/window_util.h" |
| 28 #include "ash/wm/wm_event.h" |
26 #include "base/command_line.h" | 29 #include "base/command_line.h" |
27 #include "ui/aura/client/aura_constants.h" | 30 #include "ui/aura/client/aura_constants.h" |
28 #include "ui/aura/test/test_window_delegate.h" | 31 #include "ui/aura/test/test_window_delegate.h" |
29 #include "ui/aura/test/test_windows.h" | 32 #include "ui/aura/test/test_windows.h" |
30 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
31 #include "ui/events/event.h" | 34 #include "ui/events/event.h" |
32 #include "ui/events/event_processor.h" | 35 #include "ui/events/event_processor.h" |
33 #include "ui/events/test/event_generator.h" | 36 #include "ui/events/test/event_generator.h" |
34 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
35 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 const ui::Accelerator shift_alt_return_press( | 1053 const ui::Accelerator shift_alt_return_press( |
1051 ui::VKEY_RETURN, | 1054 ui::VKEY_RETURN, |
1052 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 1055 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1053 EXPECT_FALSE(GetController()->Process(shift_alt_return_press)); | 1056 EXPECT_FALSE(GetController()->Process(shift_alt_return_press)); |
1054 const ui::Accelerator shift_alt_space_press( | 1057 const ui::Accelerator shift_alt_space_press( |
1055 ui::VKEY_SPACE, | 1058 ui::VKEY_SPACE, |
1056 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 1059 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1057 EXPECT_FALSE(GetController()->Process(shift_alt_space_press)); | 1060 EXPECT_FALSE(GetController()->Process(shift_alt_space_press)); |
1058 } | 1061 } |
1059 | 1062 |
1060 TEST_F(AcceleratorControllerTest, ReservedAccelerators) { | 1063 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) { |
1061 // (Shift+)Alt+Tab and Chrome OS top-row keys are reserved. | |
1062 EXPECT_TRUE(GetController()->IsReservedAccelerator( | |
1063 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | |
1064 EXPECT_TRUE(GetController()->IsReservedAccelerator( | |
1065 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | |
1066 #if defined(OS_CHROMEOS) | 1064 #if defined(OS_CHROMEOS) |
1067 EXPECT_TRUE(GetController()->IsReservedAccelerator( | 1065 // Power key is reserved on chromeos. |
| 1066 EXPECT_TRUE(GetController()->IsReserved( |
| 1067 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
| 1068 EXPECT_FALSE(GetController()->IsPreferred( |
1068 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); | 1069 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
1069 #endif | 1070 #endif |
1070 // Others are not reserved. | 1071 // ALT+Tab are not reserved but preferred. |
1071 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1072 EXPECT_FALSE(GetController()->IsReserved( |
| 1073 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
| 1074 EXPECT_FALSE(GetController()->IsReserved( |
| 1075 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
| 1076 EXPECT_TRUE(GetController()->IsPreferred( |
| 1077 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
| 1078 EXPECT_TRUE(GetController()->IsPreferred( |
| 1079 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
| 1080 |
| 1081 // Others are not reserved nor preferred |
| 1082 EXPECT_FALSE(GetController()->IsReserved( |
1072 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 1083 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1073 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1084 EXPECT_FALSE(GetController()->IsPreferred( |
| 1085 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
| 1086 EXPECT_FALSE(GetController()->IsReserved( |
1074 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 1087 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1075 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1088 EXPECT_FALSE(GetController()->IsPreferred( |
| 1089 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
| 1090 EXPECT_FALSE(GetController()->IsReserved( |
| 1091 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
| 1092 EXPECT_FALSE(GetController()->IsPreferred( |
1076 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 1093 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1077 } | 1094 } |
1078 | 1095 |
| 1096 namespace { |
| 1097 |
| 1098 class PreferredReservedAcceleratorsTest : public test::AshTestBase { |
| 1099 public: |
| 1100 PreferredReservedAcceleratorsTest() {} |
| 1101 virtual ~PreferredReservedAcceleratorsTest() {} |
| 1102 |
| 1103 // test::AshTestBase: |
| 1104 virtual void SetUp() OVERRIDE { |
| 1105 AshTestBase::SetUp(); |
| 1106 Shell::GetInstance()->lock_state_controller()-> |
| 1107 set_animator_for_test(new test::TestSessionStateAnimator); |
| 1108 } |
| 1109 |
| 1110 private: |
| 1111 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); |
| 1112 }; |
| 1113 |
| 1114 } // namespace |
| 1115 |
| 1116 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { |
| 1117 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 1118 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| 1119 wm::ActivateWindow(w1); |
| 1120 |
| 1121 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); |
| 1122 wm::WindowState* w1_state = wm::GetWindowState(w1); |
| 1123 w1_state->OnWMEvent(&fullscreen); |
| 1124 ASSERT_TRUE(w1_state->IsFullscreen()); |
| 1125 |
| 1126 ui::test::EventGenerator& generator = GetEventGenerator(); |
1079 #if defined(OS_CHROMEOS) | 1127 #if defined(OS_CHROMEOS) |
| 1128 // Power key (reserved) should always be handled. |
| 1129 LockStateController::TestApi test_api( |
| 1130 Shell::GetInstance()->lock_state_controller()); |
| 1131 EXPECT_FALSE(test_api.is_animating_lock()); |
| 1132 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); |
| 1133 EXPECT_TRUE(test_api.is_animating_lock()); |
| 1134 #endif |
| 1135 |
| 1136 // A fullscreen window can consume ALT-TAB (preferred). |
| 1137 ASSERT_EQ(w1, wm::GetActiveWindow()); |
| 1138 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 1139 ASSERT_EQ(w1, wm::GetActiveWindow()); |
| 1140 ASSERT_NE(w2, wm::GetActiveWindow()); |
| 1141 |
| 1142 // ALT-TAB is non repeatable. Press A to cancel the |
| 1143 // repeat record. |
| 1144 generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 1145 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
| 1146 |
| 1147 // A normal window shouldn't consume preferred accelerator. |
| 1148 wm::WMEvent normal(wm::WM_EVENT_NORMAL); |
| 1149 w1_state->OnWMEvent(&normal); |
| 1150 ASSERT_FALSE(w1_state->IsFullscreen()); |
| 1151 |
| 1152 EXPECT_EQ(w1, wm::GetActiveWindow()); |
| 1153 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 1154 ASSERT_NE(w1, wm::GetActiveWindow()); |
| 1155 ASSERT_EQ(w2, wm::GetActiveWindow()); |
| 1156 } |
| 1157 |
| 1158 #if defined(OS_CHROMEOS) |
1080 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { | 1159 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { |
1081 std::set<AcceleratorAction> all_actions; | 1160 std::set<AcceleratorAction> all_actions; |
1082 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i) | 1161 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i) |
1083 all_actions.insert(kAcceleratorData[i].action); | 1162 all_actions.insert(kAcceleratorData[i].action); |
1084 #if !defined(NDEBUG) | 1163 #if !defined(NDEBUG) |
1085 std::set<AcceleratorAction> all_desktop_actions; | 1164 std::set<AcceleratorAction> all_desktop_actions; |
1086 for (size_t i = 0 ; i < kDesktopAcceleratorDataLength; ++i) | 1165 for (size_t i = 0 ; i < kDesktopAcceleratorDataLength; ++i) |
1087 all_desktop_actions.insert(kDesktopAcceleratorData[i].action); | 1166 all_desktop_actions.insert(kDesktopAcceleratorData[i].action); |
1088 #endif | 1167 #endif |
1089 | 1168 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 1323 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
1245 wm::ActivateWindow(window.get()); | 1324 wm::ActivateWindow(window.get()); |
1246 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); | 1325 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); |
1247 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1326 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
1248 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); | 1327 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); |
1249 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); | 1328 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); |
1250 } | 1329 } |
1251 } | 1330 } |
1252 | 1331 |
1253 } // namespace ash | 1332 } // namespace ash |
OLD | NEW |