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/accessibility_types.h" | 9 #include "ash/accessibility_types.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/ime_control_delegate.h" | 11 #include "ash/ime_control_delegate.h" |
12 #include "ash/public/cpp/shell_window_ids.h" | 12 #include "ash/public/cpp/shell_window_ids.h" |
13 #include "ash/session/session_controller.h" | 13 #include "ash/session/session_controller.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/shell_port.h" |
15 #include "ash/system/brightness_control_delegate.h" | 16 #include "ash/system/brightness_control_delegate.h" |
16 #include "ash/system/keyboard_brightness_control_delegate.h" | 17 #include "ash/system/keyboard_brightness_control_delegate.h" |
17 #include "ash/system/tray/system_tray_delegate.h" | 18 #include "ash/system/tray/system_tray_delegate.h" |
18 #include "ash/test/ash_test_base.h" | 19 #include "ash/test/ash_test_base.h" |
19 #include "ash/test/lock_state_controller_test_api.h" | 20 #include "ash/test/lock_state_controller_test_api.h" |
20 #include "ash/test/test_screenshot_delegate.h" | 21 #include "ash/test/test_screenshot_delegate.h" |
21 #include "ash/test/test_session_state_animator.h" | 22 #include "ash/test/test_session_state_animator.h" |
22 #include "ash/test/test_shelf_delegate.h" | 23 #include "ash/test/test_shelf_delegate.h" |
23 #include "ash/wm/lock_state_controller.h" | 24 #include "ash/wm/lock_state_controller.h" |
24 #include "ash/wm/panels/panel_layout_manager.h" | 25 #include "ash/wm/panels/panel_layout_manager.h" |
25 #include "ash/wm/window_positioning_utils.h" | 26 #include "ash/wm/window_positioning_utils.h" |
26 #include "ash/wm/window_state.h" | 27 #include "ash/wm/window_state.h" |
27 #include "ash/wm/window_state_aura.h" | 28 #include "ash/wm/window_state_aura.h" |
28 #include "ash/wm/window_util.h" | 29 #include "ash/wm/window_util.h" |
29 #include "ash/wm/wm_event.h" | 30 #include "ash/wm/wm_event.h" |
30 #include "ash/wm_shell.h" | |
31 #include "ash/wm_window.h" | 31 #include "ash/wm_window.h" |
32 #include "base/command_line.h" | 32 #include "base/command_line.h" |
33 #include "base/test/user_action_tester.cc" | 33 #include "base/test/user_action_tester.cc" |
34 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 34 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
35 #include "ui/app_list/presenter/app_list.h" | 35 #include "ui/app_list/presenter/app_list.h" |
36 #include "ui/app_list/presenter/test/test_app_list_presenter.h" | 36 #include "ui/app_list/presenter/test/test_app_list_presenter.h" |
37 #include "ui/aura/client/aura_constants.h" | 37 #include "ui/aura/client/aura_constants.h" |
38 #include "ui/aura/test/test_window_delegate.h" | 38 #include "ui/aura/test/test_window_delegate.h" |
39 #include "ui/aura/test/test_windows.h" | 39 #include "ui/aura/test/test_windows.h" |
40 #include "ui/aura/window.h" | 40 #include "ui/aura/window.h" |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 WmWindow::Get(window.get())); | 516 WmWindow::Get(window.get())); |
517 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 517 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
518 // Snap left again ->> becomes normal. | 518 // Snap left again ->> becomes normal. |
519 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); | 519 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
520 EXPECT_TRUE(window_state->IsNormalStateType()); | 520 EXPECT_TRUE(window_state->IsNormalStateType()); |
521 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | 521 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); |
522 } | 522 } |
523 | 523 |
524 TEST_F(AcceleratorControllerTest, RotateScreen) { | 524 TEST_F(AcceleratorControllerTest, RotateScreen) { |
525 // TODO: needs GetDisplayInfo http://crbug.com/622480. | 525 // TODO: needs GetDisplayInfo http://crbug.com/622480. |
526 if (WmShell::Get()->IsRunningInMash()) | 526 if (ShellPort::Get()->IsRunningInMash()) |
527 return; | 527 return; |
528 | 528 |
529 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | 529 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
530 display::Display::Rotation initial_rotation = | 530 display::Display::Rotation initial_rotation = |
531 GetActiveDisplayRotation(display.id()); | 531 GetActiveDisplayRotation(display.id()); |
532 ui::test::EventGenerator& generator = GetEventGenerator(); | 532 ui::test::EventGenerator& generator = GetEventGenerator(); |
533 generator.PressKey(ui::VKEY_BROWSER_REFRESH, | 533 generator.PressKey(ui::VKEY_BROWSER_REFRESH, |
534 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | 534 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); |
535 generator.ReleaseKey(ui::VKEY_BROWSER_REFRESH, | 535 generator.ReleaseKey(ui::VKEY_BROWSER_REFRESH, |
536 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | 536 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); | 656 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); |
657 ui::KeyEvent key_event3(key_event); | 657 ui::KeyEvent key_event3(key_event); |
658 details = sink->OnEventFromSource(&key_event3); | 658 details = sink->OnEventFromSource(&key_event3); |
659 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); | 659 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); |
660 EXPECT_EQ(1, target.accelerator_pressed_count()); | 660 EXPECT_EQ(1, target.accelerator_pressed_count()); |
661 } | 661 } |
662 #endif | 662 #endif |
663 | 663 |
664 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { | 664 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { |
665 // TODO: TestScreenshotDelegate is null in mash http://crbug.com/632111. | 665 // TODO: TestScreenshotDelegate is null in mash http://crbug.com/632111. |
666 if (WmShell::Get()->IsRunningInMash()) | 666 if (ShellPort::Get()->IsRunningInMash()) |
667 return; | 667 return; |
668 | 668 |
669 // CycleBackward | 669 // CycleBackward |
670 EXPECT_TRUE(ProcessInController( | 670 EXPECT_TRUE(ProcessInController( |
671 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 671 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
672 // CycleForward | 672 // CycleForward |
673 EXPECT_TRUE( | 673 EXPECT_TRUE( |
674 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 674 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
675 // CycleLinear | 675 // CycleLinear |
676 EXPECT_TRUE(ProcessInController( | 676 EXPECT_TRUE(ProcessInController( |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 } | 1034 } |
1035 | 1035 |
1036 private: | 1036 private: |
1037 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); | 1037 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); |
1038 }; | 1038 }; |
1039 | 1039 |
1040 } // namespace | 1040 } // namespace |
1041 | 1041 |
1042 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { | 1042 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { |
1043 // TODO: needs LockStateController ported: http://crbug.com/632189. | 1043 // TODO: needs LockStateController ported: http://crbug.com/632189. |
1044 if (WmShell::Get()->IsRunningInMash()) | 1044 if (ShellPort::Get()->IsRunningInMash()) |
1045 return; | 1045 return; |
1046 | 1046 |
1047 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 1047 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
1048 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 1048 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
1049 wm::ActivateWindow(w1); | 1049 wm::ActivateWindow(w1); |
1050 | 1050 |
1051 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); | 1051 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); |
1052 wm::WindowState* w1_state = wm::GetWindowState(w1); | 1052 wm::WindowState* w1_state = wm::GetWindowState(w1); |
1053 w1_state->OnWMEvent(&fullscreen); | 1053 w1_state->OnWMEvent(&fullscreen); |
1054 ASSERT_TRUE(w1_state->IsFullscreen()); | 1054 ASSERT_TRUE(w1_state->IsFullscreen()); |
(...skipping 30 matching lines...) Expand all Loading... |
1085 ASSERT_FALSE(w1_state->IsFullscreen()); | 1085 ASSERT_FALSE(w1_state->IsFullscreen()); |
1086 | 1086 |
1087 EXPECT_EQ(w1, wm::GetActiveWindow()); | 1087 EXPECT_EQ(w1, wm::GetActiveWindow()); |
1088 press_and_release_alt_tab(); | 1088 press_and_release_alt_tab(); |
1089 ASSERT_NE(w1, wm::GetActiveWindow()); | 1089 ASSERT_NE(w1, wm::GetActiveWindow()); |
1090 ASSERT_EQ(w2, wm::GetActiveWindow()); | 1090 ASSERT_EQ(w2, wm::GetActiveWindow()); |
1091 } | 1091 } |
1092 | 1092 |
1093 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithPinned) { | 1093 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithPinned) { |
1094 // TODO: needs LockStateController ported: http://crbug.com/632189. | 1094 // TODO: needs LockStateController ported: http://crbug.com/632189. |
1095 if (WmShell::Get()->IsRunningInMash()) | 1095 if (ShellPort::Get()->IsRunningInMash()) |
1096 return; | 1096 return; |
1097 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 1097 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
1098 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 1098 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
1099 wm::ActivateWindow(w1); | 1099 wm::ActivateWindow(w1); |
1100 | 1100 |
1101 { | 1101 { |
1102 wm::WMEvent pin_event(wm::WM_EVENT_PIN); | 1102 wm::WMEvent pin_event(wm::WM_EVENT_PIN); |
1103 wm::WindowState* w1_state = wm::GetWindowState(w1); | 1103 wm::WindowState* w1_state = wm::GetWindowState(w1); |
1104 w1_state->OnWMEvent(&pin_event); | 1104 w1_state->OnWMEvent(&pin_event); |
1105 ASSERT_TRUE(w1_state->IsPinned()); | 1105 ASSERT_TRUE(w1_state->IsPinned()); |
(...skipping 11 matching lines...) Expand all Loading... |
1117 // A pinned window can consume ALT-TAB (preferred), but no side effect. | 1117 // A pinned window can consume ALT-TAB (preferred), but no side effect. |
1118 ASSERT_EQ(w1, wm::GetActiveWindow()); | 1118 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1119 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 1119 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1120 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 1120 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1121 ASSERT_EQ(w1, wm::GetActiveWindow()); | 1121 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1122 ASSERT_NE(w2, wm::GetActiveWindow()); | 1122 ASSERT_NE(w2, wm::GetActiveWindow()); |
1123 } | 1123 } |
1124 | 1124 |
1125 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { | 1125 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { |
1126 // TODO: TestScreenshotDelegate is null in mash http://crbug.com/632111. | 1126 // TODO: TestScreenshotDelegate is null in mash http://crbug.com/632111. |
1127 if (WmShell::Get()->IsRunningInMash()) | 1127 if (ShellPort::Get()->IsRunningInMash()) |
1128 return; | 1128 return; |
1129 | 1129 |
1130 std::set<AcceleratorAction> all_actions; | 1130 std::set<AcceleratorAction> all_actions; |
1131 for (size_t i = 0; i < kAcceleratorDataLength; ++i) | 1131 for (size_t i = 0; i < kAcceleratorDataLength; ++i) |
1132 all_actions.insert(kAcceleratorData[i].action); | 1132 all_actions.insert(kAcceleratorData[i].action); |
1133 std::set<AcceleratorAction> all_debug_actions; | 1133 std::set<AcceleratorAction> all_debug_actions; |
1134 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) | 1134 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) |
1135 all_debug_actions.insert(kDebugAcceleratorData[i].action); | 1135 all_debug_actions.insert(kDebugAcceleratorData[i].action); |
1136 std::set<AcceleratorAction> all_dev_actions; | 1136 std::set<AcceleratorAction> all_dev_actions; |
1137 for (size_t i = 0; i < kDeveloperAcceleratorDataLength; ++i) | 1137 for (size_t i = 0; i < kDeveloperAcceleratorDataLength; ++i) |
1138 all_dev_actions.insert(kDeveloperAcceleratorData[i].action); | 1138 all_dev_actions.insert(kDeveloperAcceleratorData[i].action); |
1139 | 1139 |
1140 std::set<AcceleratorAction> actionsAllowedAtModalWindow; | 1140 std::set<AcceleratorAction> actionsAllowedAtModalWindow; |
1141 for (size_t k = 0; k < kActionsAllowedAtModalWindowLength; ++k) | 1141 for (size_t k = 0; k < kActionsAllowedAtModalWindowLength; ++k) |
1142 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); | 1142 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); |
1143 for (const auto& action : actionsAllowedAtModalWindow) { | 1143 for (const auto& action : actionsAllowedAtModalWindow) { |
1144 EXPECT_TRUE(all_actions.find(action) != all_actions.end() || | 1144 EXPECT_TRUE(all_actions.find(action) != all_actions.end() || |
1145 all_debug_actions.find(action) != all_debug_actions.end() || | 1145 all_debug_actions.find(action) != all_debug_actions.end() || |
1146 all_dev_actions.find(action) != all_dev_actions.end()) | 1146 all_dev_actions.find(action) != all_dev_actions.end()) |
1147 << " action from kActionsAllowedAtModalWindow" | 1147 << " action from kActionsAllowedAtModalWindow" |
1148 << " not found in kAcceleratorData, kDebugAcceleratorData or" | 1148 << " not found in kAcceleratorData, kDebugAcceleratorData or" |
1149 << " kDeveloperAcceleratorData action: " << action; | 1149 << " kDeveloperAcceleratorData action: " << action; |
1150 } | 1150 } |
1151 std::unique_ptr<aura::Window> window( | 1151 std::unique_ptr<aura::Window> window( |
1152 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 1152 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
1153 wm::ActivateWindow(window.get()); | 1153 wm::ActivateWindow(window.get()); |
1154 WmShell::Get()->SimulateModalWindowOpenForTesting(true); | 1154 ShellPort::Get()->SimulateModalWindowOpenForTesting(true); |
1155 for (const auto& action : all_actions) { | 1155 for (const auto& action : all_actions) { |
1156 if (actionsAllowedAtModalWindow.find(action) == | 1156 if (actionsAllowedAtModalWindow.find(action) == |
1157 actionsAllowedAtModalWindow.end()) { | 1157 actionsAllowedAtModalWindow.end()) { |
1158 EXPECT_TRUE(GetController()->PerformActionIfEnabled(action)) | 1158 EXPECT_TRUE(GetController()->PerformActionIfEnabled(action)) |
1159 << " for action (disallowed at modal window): " << action; | 1159 << " for action (disallowed at modal window): " << action; |
1160 } | 1160 } |
1161 } | 1161 } |
1162 // Testing of top row (F5-F10) accelerators that should still work | 1162 // Testing of top row (F5-F10) accelerators that should still work |
1163 // when a modal window is open | 1163 // when a modal window is open |
1164 // | 1164 // |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 | 1308 |
1309 private: | 1309 private: |
1310 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester); | 1310 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester); |
1311 }; | 1311 }; |
1312 | 1312 |
1313 } // namespace | 1313 } // namespace |
1314 | 1314 |
1315 TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) { | 1315 TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) { |
1316 // TODO: disabled because of UnblockUserSession() not working: | 1316 // TODO: disabled because of UnblockUserSession() not working: |
1317 // http://crbug.com/632201. | 1317 // http://crbug.com/632201. |
1318 if (WmShell::Get()->IsRunningInMash()) | 1318 if (ShellPort::Get()->IsRunningInMash()) |
1319 return; | 1319 return; |
1320 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { | 1320 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { |
1321 const AcceleratorData& entry = kDeprecatedAccelerators[i]; | 1321 const AcceleratorData& entry = kDeprecatedAccelerators[i]; |
1322 | 1322 |
1323 auto itr = GetController()->actions_with_deprecations_.find(entry.action); | 1323 auto itr = GetController()->actions_with_deprecations_.find(entry.action); |
1324 ASSERT_TRUE(itr != GetController()->actions_with_deprecations_.end()); | 1324 ASSERT_TRUE(itr != GetController()->actions_with_deprecations_.end()); |
1325 const DeprecatedAcceleratorData* data = itr->second; | 1325 const DeprecatedAcceleratorData* data = itr->second; |
1326 | 1326 |
1327 EXPECT_TRUE(IsMessageCenterEmpty()); | 1327 EXPECT_TRUE(IsMessageCenterEmpty()); |
1328 ui::Accelerator deprecated_accelerator = CreateAccelerator(entry); | 1328 ui::Accelerator deprecated_accelerator = CreateAccelerator(entry); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 // Expect no notifications from the new accelerators. | 1360 // Expect no notifications from the new accelerators. |
1361 EXPECT_TRUE(IsMessageCenterEmpty()); | 1361 EXPECT_TRUE(IsMessageCenterEmpty()); |
1362 | 1362 |
1363 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1363 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
1364 // screen before we proceed testing the rest of accelerators. | 1364 // screen before we proceed testing the rest of accelerators. |
1365 ResetStateIfNeeded(); | 1365 ResetStateIfNeeded(); |
1366 } | 1366 } |
1367 } | 1367 } |
1368 | 1368 |
1369 } // namespace ash | 1369 } // namespace ash |
OLD | NEW |