Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 5 | #include"ash/public/cpp/test/shell_test_api.h" |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 6 | #include"base/memory/raw_ptr.h" |
sky | 5ad143a | 2017-03-22 04:31:23 | [diff] [blame] | 7 | |
Scott Violet | d8ceadb | 2019-03-21 01:31:43 | [diff] [blame] | 8 | #include<memory> |
xiyuan | 317fdbe | 2017-05-31 15:02:02 | [diff] [blame] | 9 | |
Evan Stade | 7768d47 | 2018-10-25 22:40:17 | [diff] [blame] | 10 | #include"ash/accelerators/accelerator_commands.h" |
Alexander Alekseev | 2b4c959 | 2021-05-04 22:26:44 | [diff] [blame] | 11 | #include"ash/accelerators/accelerator_controller_impl.h" |
Mitsuru Oshima | 8abd8b1d0 | 2019-05-09 17:55:23 | [diff] [blame] | 12 | #include"ash/accelerometer/accelerometer_reader.h" |
Alexander Alekseev | 2b4c959 | 2021-05-04 22:26:44 | [diff] [blame] | 13 | #include"ash/hud_display/hud_display.h" |
Darren Shen | 7daf3e1 | 2019-07-02 07:25:49 | [diff] [blame] | 14 | #include"ash/keyboard/keyboard_controller_impl.h" |
Mitsuru Oshima | 9a6378d9 | 2019-11-01 00:48:15 | [diff] [blame] | 15 | #include"ash/public/cpp/autotest_private_api_utils.h" |
Mitsuru Oshima | a6adca4f | 2019-07-10 23:30:46 | [diff] [blame] | 16 | #include"ash/public/cpp/tablet_mode_observer.h" |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 17 | #include"ash/root_window_controller.h" |
| 18 | #include"ash/shell.h" |
Ahmed Mehfooz | 283be8c | 2023-12-21 00:35:22 | [diff] [blame] | 19 | #include"ash/system/notification_center/session_state_notification_blocker.h" |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 20 | #include"ash/system/power/backlights_forced_off_setter.h" |
Qiang Xu | 0a86020f | 2017-10-12 08:34:54 | [diff] [blame] | 21 | #include"ash/system/power/power_button_controller.h" |
Jun Mukai | 2b91e70 | 2019-09-05 18:24:38 | [diff] [blame] | 22 | #include"ash/wm/overview/overview_animation_state_waiter.h" |
Sammie Quon | 80e82a1 | 2019-01-23 19:55:22 | [diff] [blame] | 23 | #include"ash/wm/overview/overview_controller.h" |
Evan Stade | 426a298 | 2018-10-19 22:42:07 | [diff] [blame] | 24 | #include"ash/wm/splitview/split_view_controller.h" |
Evan Stade | d689b33 | 2018-08-02 01:17:22 | [diff] [blame] | 25 | #include"ash/wm/tablet_mode/tablet_mode_controller.h" |
Ahmed Fakhry | fee7a0a | 2019-04-05 22:49:48 | [diff] [blame] | 26 | #include"ash/wm/workspace_controller.h" |
Avi Drissman | 4de6dab | 2023-01-06 23:17:35 | [diff] [blame] | 27 | #include"base/functional/bind.h" |
Scott Violet | d8ceadb | 2019-03-21 01:31:43 | [diff] [blame] | 28 | #include"base/run_loop.h" |
James Cook | bbe5cb1 | 2017-08-08 18:32:21 | [diff] [blame] | 29 | #include"components/prefs/testing_pref_service.h" |
Scott Violet | d8ceadb | 2019-03-21 01:31:43 | [diff] [blame] | 30 | #include"ui/compositor/compositor.h" |
Lei Zhang | 0c04332 | 2021-04-27 16:43:05 | [diff] [blame] | 31 | #include"ui/compositor/layer.h" |
Sammie Quon | 358e957 | 2019-11-21 04:38:02 | [diff] [blame] | 32 | #include"ui/compositor/layer_animation_observer.h" |
David Sanders | 0a524ec | 2022-03-20 07:31:28 | [diff] [blame] | 33 | #include"ui/compositor/layer_animator.h" |
Sammie Quon | 4986fdf | 2020-05-15 19:33:58 | [diff] [blame] | 34 | #include"ui/display/manager/display_manager.h" |
Ahmed Fakhry | 607ade0 | 2019-10-31 15:59:39 | [diff] [blame] | 35 | #include"ui/events/devices/device_data_manager_test_api.h" |
Jun Mukai | 2af6db5 | 2019-01-09 00:22:42 | [diff] [blame] | 36 | #include"ui/events/gesture_detection/gesture_configuration.h" |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 37 | |
| 38 | namespace ash{ |
Scott Violet | d8ceadb | 2019-03-21 01:31:43 | [diff] [blame] | 39 | namespace{ |
| 40 | |
Sammie Quon | 358e957 | 2019-11-21 04:38:02 | [diff] [blame] | 41 | classWindowAnimationWaiter:public ui::LayerAnimationObserver{ |
| 42 | public: |
| 43 | explicitWindowAnimationWaiter(aura::Window* window) |
| 44 | : animator_(window->layer()->GetAnimator()){ |
| 45 | animator_->AddObserver(this); |
| 46 | } |
| 47 | ~WindowAnimationWaiter() override=default; |
| 48 | |
| 49 | WindowAnimationWaiter(constWindowAnimationWaiter& other)=delete; |
| 50 | WindowAnimationWaiter&operator=(constWindowAnimationWaiter& rhs)=delete; |
| 51 | |
| 52 | // ui::LayerAnimationObserver: |
| 53 | voidOnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override{ |
| 54 | if(!animator_->is_animating()){ |
| 55 | animator_->RemoveObserver(this); |
| 56 | run_loop_.Quit(); |
| 57 | } |
| 58 | } |
| 59 | voidOnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override{} |
| 60 | voidOnLayerAnimationScheduled( |
| 61 | ui::LayerAnimationSequence* sequence) override{} |
| 62 | |
nergi | 7d04d01 | 2022-03-07 04:00:22 | [diff] [blame] | 63 | voidWait(){ run_loop_.Run();} |
Sammie Quon | 358e957 | 2019-11-21 04:38:02 | [diff] [blame] | 64 | |
| 65 | private: |
Bartek Nowierski | deb7584 | 2023-12-27 02:32:42 | [diff] [blame] | 66 | raw_ptr<ui::LayerAnimator,DanglingUntriaged> animator_; |
Sammie Quon | 358e957 | 2019-11-21 04:38:02 | [diff] [blame] | 67 | base::RunLoop run_loop_; |
| 68 | }; |
| 69 | |
Scott Violet | d8ceadb | 2019-03-21 01:31:43 | [diff] [blame] | 70 | }// namespace |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 71 | |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 72 | ShellTestApi::ShellTestApi(): shell_(Shell::Get()){} |
| 73 | ShellTestApi::~ShellTestApi()=default; |
James Cook | 00848f0 | 2018-01-05 18:02:57 | [diff] [blame] | 74 | |
Sammie Quon | 408e9da | 2019-06-20 19:36:21 | [diff] [blame] | 75 | // static |
| 76 | voidShellTestApi::SetTabletControllerUseScreenshotForTest( |
| 77 | bool use_screenshot){ |
| 78 | TabletModeController::SetUseScreenshotForTest(use_screenshot); |
| 79 | } |
| 80 | |
Ahmed Mehfooz | 812c542 | 2021-03-29 22:42:16 | [diff] [blame] | 81 | // static |
| 82 | voidShellTestApi::SetUseLoginNotificationDelayForTest(bool use_delay){ |
| 83 | SessionStateNotificationBlocker::SetUseLoginNotificationDelayForTest( |
| 84 | use_delay); |
| 85 | } |
| 86 | |
James Cook | 459354b3 | 2017-09-27 23:18:01 | [diff] [blame] | 87 | MessageCenterController*ShellTestApi::message_center_controller(){ |
| 88 | return shell_->message_center_controller_.get(); |
| 89 | } |
| 90 | |
oshima@chromium.org | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 91 | WorkspaceController*ShellTestApi::workspace_controller(){ |
Ahmed Fakhry | fee7a0a | 2019-04-05 22:49:48 | [diff] [blame] | 92 | // TODO(afakhry): Split this into two, one for root, and one for context. |
| 93 | returnGetActiveWorkspaceController(shell_->GetPrimaryRootWindow()); |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 94 | } |
| 95 | |
oshima@chromium.org | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 96 | ScreenPositionController*ShellTestApi::screen_position_controller(){ |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 97 | return shell_->screen_position_controller_.get(); |
| 98 | } |
| 99 | |
erg | 36cfb95 | 2017-06-21 19:41:45 | [diff] [blame] | 100 | NativeCursorManagerAsh*ShellTestApi::native_cursor_manager_ash(){ |
erg@chromium.org | c0ff034 | 2013-02-27 00:41:29 | [diff] [blame] | 101 | return shell_->native_cursor_manager_; |
| 102 | } |
| 103 | |
oshima@chromium.org | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 104 | DragDropController*ShellTestApi::drag_drop_controller(){ |
varunjain@chromium.org | c086bab | 2013-06-06 21:46:44 | [diff] [blame] | 105 | return shell_->drag_drop_controller_.get(); |
| 106 | } |
| 107 | |
Qiang Xu | 36234e53 | 2018-04-11 04:54:02 | [diff] [blame] | 108 | PowerPrefs*ShellTestApi::power_prefs(){ |
| 109 | return shell_->power_prefs_.get(); |
| 110 | } |
| 111 | |
Sammie Quon | 4986fdf | 2020-05-15 19:33:58 | [diff] [blame] | 112 | display::DisplayManager*ShellTestApi::display_manager(){ |
| 113 | return shell_->display_manager(); |
| 114 | } |
| 115 | |
Qiang Xu | 50c6f8c | 2017-08-31 20:55:24 | [diff] [blame] | 116 | voidShellTestApi::ResetPowerButtonControllerForTest(){ |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 117 | shell_->backlights_forced_off_setter_->ResetForTest(); |
nergi | 7d04d01 | 2022-03-07 04:00:22 | [diff] [blame] | 118 | shell_->power_button_controller_.reset(); |
Toni Barzic | 9d0c82f4 | 2017-12-06 00:53:52 | [diff] [blame] | 119 | shell_->power_button_controller_= std::make_unique<PowerButtonController>( |
| 120 | shell_->backlights_forced_off_setter_.get()); |
Qiang Xu | 50c6f8c | 2017-08-31 20:55:24 | [diff] [blame] | 121 | } |
| 122 | |
James Cook | 7b7c6a5 | 2018-01-04 23:40:03 | [diff] [blame] | 123 | voidShellTestApi::SimulateModalWindowOpenForTest(bool modal_window_open){ |
| 124 | shell_->simulate_modal_window_open_for_test_= modal_window_open; |
| 125 | } |
| 126 | |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 127 | boolShellTestApi::IsSystemModalWindowOpen(){ |
| 128 | returnShell::IsSystemModalWindowOpen(); |
James Cook | 00848f0 | 2018-01-05 18:02:57 | [diff] [blame] | 129 | } |
| 130 | |
James Cook | bbca645 | 2021-01-13 17:26:03 | [diff] [blame] | 131 | voidShellTestApi::SetTabletModeEnabledForTest(bool enable){ |
Ahmed Fakhry | 607ade0 | 2019-10-31 15:59:39 | [diff] [blame] | 132 | // Detach mouse devices, so we can enter tablet mode. |
| 133 | // Calling RunUntilIdle() here is necessary before setting the mouse devices |
| 134 | // to prevent the callback from evdev thread from overwriting whatever we set |
| 135 | // here below. See `InputDeviceFactoryEvdevProxy::OnStartupScanComplete()`. |
| 136 | base::RunLoop().RunUntilIdle(); |
Xiaoqian Dai | 7e18245 | 2020-05-05 23:29:19 | [diff] [blame] | 137 | ui::DeviceDataManagerTestApi().OnDeviceListsComplete(); |
Ahmed Fakhry | 607ade0 | 2019-10-31 15:59:39 | [diff] [blame] | 138 | ui::DeviceDataManagerTestApi().SetMouseDevices({}); |
| 139 | |
Mitsuru Oshima | a6adca4f | 2019-07-10 23:30:46 | [diff] [blame] | 140 | TabletMode::Waiter waiter(enable); |
Mitsuru Oshima | 9e05edd | 2019-06-17 19:35:39 | [diff] [blame] | 141 | shell_->tablet_mode_controller()->SetEnabledForTest(enable); |
Mitsuru Oshima | a6adca4f | 2019-07-10 23:30:46 | [diff] [blame] | 142 | waiter.Wait(); |
Evan Stade | d689b33 | 2018-08-02 01:17:22 | [diff] [blame] | 143 | } |
| 144 | |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 145 | voidShellTestApi::EnableVirtualKeyboard(){ |
Darren Shen | 7daf3e1 | 2019-07-02 07:25:49 | [diff] [blame] | 146 | shell_->keyboard_controller()->SetEnableFlag( |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 147 | keyboard::KeyboardEnableFlag::kCommandLineEnabled); |
Noel Gordon | fe3ac34 | 2018-09-10 05:12:57 | [diff] [blame] | 148 | } |
| 149 | |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 150 | voidShellTestApi::ToggleFullscreen(){ |
Manu Cornet | c3511d90 | 2020-01-10 22:44:43 | [diff] [blame] | 151 | accelerators::ToggleFullscreen(); |
Evan Stade | 7768d47 | 2018-10-25 22:40:17 | [diff] [blame] | 152 | } |
| 153 | |
Jun Mukai | aa8479c8 | 2019-01-08 02:30:39 | [diff] [blame] | 154 | voidShellTestApi::AddRemoveDisplay(){ |
| 155 | shell_->display_manager()->AddRemoveDisplay(); |
| 156 | } |
| 157 | |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 158 | voidShellTestApi::WaitForOverviewAnimationState(OverviewAnimationState state){ |
| 159 | auto* overview_controller= shell_->overview_controller(); |
| 160 | if(state==OverviewAnimationState::kEnterAnimationComplete&& |
Sammie Quon | 2c85f73d | 2019-05-08 23:10:27 | [diff] [blame] | 161 | overview_controller->InOverviewSession()&& |
Mitsuru Oshima | 57cc785 | 2019-04-10 00:15:27 | [diff] [blame] | 162 | !overview_controller->IsInStartAnimation()){ |
| 163 | // If there is no animation applied, call the callback immediately. |
Mitsuru Oshima | 57cc785 | 2019-04-10 00:15:27 | [diff] [blame] | 164 | return; |
| 165 | } |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 166 | if(state==OverviewAnimationState::kExitAnimationComplete&& |
Sammie Quon | 2c85f73d | 2019-05-08 23:10:27 | [diff] [blame] | 167 | !overview_controller->InOverviewSession()&& |
Mitsuru Oshima | 57cc785 | 2019-04-10 00:15:27 | [diff] [blame] | 168 | !overview_controller->IsCompletingShutdownAnimations()){ |
| 169 | // If there is no animation applied, call the callback immediately. |
Mitsuru Oshima | 57cc785 | 2019-04-10 00:15:27 | [diff] [blame] | 170 | return; |
| 171 | } |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 172 | base::RunLoop run_loop; |
Jun Mukai | 2b91e70 | 2019-09-05 18:24:38 | [diff] [blame] | 173 | newOverviewAnimationStateWaiter( |
Reilly Grant | b670223 | 2019-11-26 22:46:04 | [diff] [blame] | 174 | state, base::BindOnce([](base::RunLoop* run_loop, |
| 175 | bool finished){ run_loop->QuitWhenIdle();}, |
| 176 | base::Unretained(&run_loop))); |
Jun Mukai | 4498638 | 2019-05-14 18:19:20 | [diff] [blame] | 177 | run_loop.Run(); |
Mitsuru Oshima | 57cc785 | 2019-04-10 00:15:27 | [diff] [blame] | 178 | } |
| 179 | |
Sammie Quon | 358e957 | 2019-11-21 04:38:02 | [diff] [blame] | 180 | voidShellTestApi::WaitForWindowFinishAnimating(aura::Window* window){ |
| 181 | WindowAnimationWaiter waiter(window); |
| 182 | waiter.Wait(); |
| 183 | } |
| 184 | |
Sammie Quon | d322167b | 2021-01-11 22:10:40 | [diff] [blame] | 185 | boolShellTestApi::IsContextMenuShown()const{ |
Sammie Quon | 6b78901 | 2024-08-09 17:29:28 | [diff] [blame] | 186 | returnShell::GetPrimaryRootWindowController()->IsContextMenuShownForTest(); |
Sammie Quon | d322167b | 2021-01-11 22:10:40 | [diff] [blame] | 187 | } |
| 188 | |
Alexander Alekseev | 2b4c959 | 2021-05-04 22:26:44 | [diff] [blame] | 189 | boolShellTestApi::IsActionForAcceleratorEnabled( |
| 190 | const ui::Accelerator& accelerator)const{ |
Zentaro Kavanagh | 628ab4a | 2021-07-27 22:19:37 | [diff] [blame] | 191 | auto* controller=Shell::Get()->accelerator_controller(); |
| 192 | returnAcceleratorControllerImpl::TestApi(controller) |
| 193 | .IsActionForAcceleratorEnabled(accelerator); |
Alexander Alekseev | 2b4c959 | 2021-05-04 22:26:44 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | boolShellTestApi::PressAccelerator(const ui::Accelerator& accelerator){ |
| 197 | returnShell::Get()->accelerator_controller()->AcceleratorPressed( |
| 198 | accelerator); |
| 199 | } |
| 200 | |
| 201 | boolShellTestApi::IsHUDShown(){ |
| 202 | return hud_display::HUDDisplayView::IsShown(); |
| 203 | } |
| 204 | |
oshima@chromium.org | 0c68e89 | 2012-12-08 16:54:53 | [diff] [blame] | 205 | }// namespace ash |