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()->IsReserved( |
1074 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 1085 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1075 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1086 EXPECT_FALSE(GetController()->IsReserved( |
1076 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 1087 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
James Cook
2014/09/19 16:13:15
How about an EXPECT_FALSE( IsPreferred() ) here al
oshima
2014/09/19 18:55:19
Done. I was going to add them but apparently forgo
| |
1077 } | 1088 } |
1078 | 1089 |
1090 namespace { | |
1091 | |
1092 class PowerAcceleratorTest : public test::AshTestBase { | |
1093 public: | |
1094 PowerAcceleratorTest() { | |
James Cook
2014/09/19 16:13:15
nit: match {} style with line below
oshima
2014/09/19 18:55:19
Done.
| |
1095 } | |
1096 virtual ~PowerAcceleratorTest() {} | |
1097 | |
1098 // test::AshTestBase: | |
1099 virtual void SetUp() OVERRIDE { | |
1100 AshTestBase::SetUp(); | |
1101 Shell::GetInstance()->lock_state_controller()-> | |
1102 set_animator_for_test(new test::TestSessionStateAnimator); | |
1103 } | |
1104 | |
1105 private: | |
1106 DISALLOW_COPY_AND_ASSIGN(PowerAcceleratorTest); | |
1107 }; | |
1108 | |
1109 } // namespace | |
James Cook
2014/09/19 16:13:15
nit: two spaces after }
oshima
2014/09/19 18:55:19
Done.
| |
1110 | |
1111 TEST_F(PowerAcceleratorTest, AcceleratorsWithFullsccreen) { | |
James Cook
2014/09/19 16:13:15
nit: Fullsccreen -> Fullscreen
oshima
2014/09/19 18:55:19
Done.
| |
1112 aura::Window* w1 = CreateTestWindowInShellWithId(0); | |
1113 aura::Window* w2 = CreateTestWindowInShellWithId(1); | |
1114 wm::ActivateWindow(w1); | |
1115 ASSERT_EQ(wm::GetActiveWindow(), w1); | |
1116 | |
1117 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); | |
1118 wm::WindowState* w1_state = wm::GetWindowState(w1); | |
1119 w1_state->OnWMEvent(&fullscreen); | |
1120 ASSERT_TRUE(w1_state->IsFullscreen()); | |
1121 | |
1122 ui::test::EventGenerator& generator = GetEventGenerator(); | |
1123 // Power key (reserved) should always be handled. | |
1124 LockStateController::TestApi test_api( | |
1125 Shell::GetInstance()->lock_state_controller()); | |
1126 EXPECT_FALSE(test_api.is_animating_lock()); | |
1127 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); | |
1128 EXPECT_TRUE(test_api.is_animating_lock()); | |
1129 | |
1130 // A fullscreen can consume ALT-TAB (preferred). | |
James Cook
2014/09/19 16:13:15
nit: "A fullscreen" -> "A fullscreen window"
oshima
2014/09/19 18:55:19
Done.
| |
1131 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | |
1132 aura::Window* active = wm::GetActiveWindow(); | |
1133 ASSERT_EQ(active, w1); | |
James Cook
2014/09/19 16:13:15
nit: This might be a little clearer if you did som
oshima
2014/09/19 18:55:19
Done.
| |
1134 ASSERT_NE(active, w2); | |
1135 | |
1136 // ALT-TAB is non repeatable. Press A to cancel the | |
1137 // repeat record. | |
1138 generator.PressKey(ui::VKEY_A, ui::EF_NONE); | |
1139 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | |
1140 | |
1141 // A normal window shouldn't consume preferred accelerator. | |
1142 wm::WMEvent normal(wm::WM_EVENT_NORMAL); | |
1143 w1_state->OnWMEvent(&normal); | |
1144 ASSERT_FALSE(w1_state->IsFullscreen()); | |
1145 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | |
1146 active = wm::GetActiveWindow(); | |
1147 EXPECT_NE(w1, active); | |
1148 EXPECT_EQ(w2, active); | |
1149 } | |
James Cook
2014/09/19 16:13:15
nice test. You always write excellent tests.
| |
1150 | |
1079 #if defined(OS_CHROMEOS) | 1151 #if defined(OS_CHROMEOS) |
1080 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { | 1152 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { |
1081 std::set<AcceleratorAction> all_actions; | 1153 std::set<AcceleratorAction> all_actions; |
1082 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i) | 1154 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i) |
1083 all_actions.insert(kAcceleratorData[i].action); | 1155 all_actions.insert(kAcceleratorData[i].action); |
1084 #if !defined(NDEBUG) | 1156 #if !defined(NDEBUG) |
1085 std::set<AcceleratorAction> all_desktop_actions; | 1157 std::set<AcceleratorAction> all_desktop_actions; |
1086 for (size_t i = 0 ; i < kDesktopAcceleratorDataLength; ++i) | 1158 for (size_t i = 0 ; i < kDesktopAcceleratorDataLength; ++i) |
1087 all_desktop_actions.insert(kDesktopAcceleratorData[i].action); | 1159 all_desktop_actions.insert(kDesktopAcceleratorData[i].action); |
1088 #endif | 1160 #endif |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1244 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 1316 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
1245 wm::ActivateWindow(window.get()); | 1317 wm::ActivateWindow(window.get()); |
1246 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); | 1318 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); |
1247 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1319 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
1248 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); | 1320 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); |
1249 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); | 1321 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); |
1250 } | 1322 } |
1251 } | 1323 } |
1252 | 1324 |
1253 } // namespace ash | 1325 } // namespace ash |
OLD | NEW |