Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /ash /shell_test_api.cc
blob: 3752ba0e3fa808f0a7460fe38bc029f7b00af3a2 [file] [log] [blame]
Avi Drissman3a215d1e2022-09-07 19:43:09[diff] [blame]1// Copyright 2012 The Chromium Authors
oshima@chromium.org0c68e892012-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 Mukai44986382019-05-14 18:19:20[diff] [blame]5#include"ash/public/cpp/test/shell_test_api.h"
Arthur Sonzogni834e018f2023-04-22 10:20:02[diff] [blame]6#include"base/memory/raw_ptr.h"
sky5ad143a2017-03-22 04:31:23[diff] [blame]7
Scott Violetd8ceadb2019-03-21 01:31:43[diff] [blame]8#include<memory>
xiyuan317fdbe2017-05-31 15:02:02[diff] [blame]9
Evan Stade7768d472018-10-25 22:40:17[diff] [blame]10#include"ash/accelerators/accelerator_commands.h"
Alexander Alekseev2b4c9592021-05-04 22:26:44[diff] [blame]11#include"ash/accelerators/accelerator_controller_impl.h"
Mitsuru Oshima8abd8b1d02019-05-09 17:55:23[diff] [blame]12#include"ash/accelerometer/accelerometer_reader.h"
Alexander Alekseev2b4c9592021-05-04 22:26:44[diff] [blame]13#include"ash/hud_display/hud_display.h"
Darren Shen7daf3e12019-07-02 07:25:49[diff] [blame]14#include"ash/keyboard/keyboard_controller_impl.h"
Mitsuru Oshima9a6378d92019-11-01 00:48:15[diff] [blame]15#include"ash/public/cpp/autotest_private_api_utils.h"
Mitsuru Oshimaa6adca4f2019-07-10 23:30:46[diff] [blame]16#include"ash/public/cpp/tablet_mode_observer.h"
oshima@chromium.org0c68e892012-12-08 16:54:53[diff] [blame]17#include"ash/root_window_controller.h"
18#include"ash/shell.h"
Ahmed Mehfooz283be8c2023-12-21 00:35:22[diff] [blame]19#include"ash/system/notification_center/session_state_notification_blocker.h"
Toni Barzic9d0c82f42017-12-06 00:53:52[diff] [blame]20#include"ash/system/power/backlights_forced_off_setter.h"
Qiang Xu0a86020f2017-10-12 08:34:54[diff] [blame]21#include"ash/system/power/power_button_controller.h"
Jun Mukai2b91e702019-09-05 18:24:38[diff] [blame]22#include"ash/wm/overview/overview_animation_state_waiter.h"
Sammie Quon80e82a12019-01-23 19:55:22[diff] [blame]23#include"ash/wm/overview/overview_controller.h"
Evan Stade426a2982018-10-19 22:42:07[diff] [blame]24#include"ash/wm/splitview/split_view_controller.h"
Evan Staded689b332018-08-02 01:17:22[diff] [blame]25#include"ash/wm/tablet_mode/tablet_mode_controller.h"
Ahmed Fakhryfee7a0a2019-04-05 22:49:48[diff] [blame]26#include"ash/wm/workspace_controller.h"
Avi Drissman4de6dab2023-01-06 23:17:35[diff] [blame]27#include"base/functional/bind.h"
Scott Violetd8ceadb2019-03-21 01:31:43[diff] [blame]28#include"base/run_loop.h"
James Cookbbe5cb12017-08-08 18:32:21[diff] [blame]29#include"components/prefs/testing_pref_service.h"
Scott Violetd8ceadb2019-03-21 01:31:43[diff] [blame]30#include"ui/compositor/compositor.h"
Lei Zhang0c043322021-04-27 16:43:05[diff] [blame]31#include"ui/compositor/layer.h"
Sammie Quon358e9572019-11-21 04:38:02[diff] [blame]32#include"ui/compositor/layer_animation_observer.h"
David Sanders0a524ec2022-03-20 07:31:28[diff] [blame]33#include"ui/compositor/layer_animator.h"
Sammie Quon4986fdf2020-05-15 19:33:58[diff] [blame]34#include"ui/display/manager/display_manager.h"
Ahmed Fakhry607ade02019-10-31 15:59:39[diff] [blame]35#include"ui/events/devices/device_data_manager_test_api.h"
Jun Mukai2af6db52019-01-09 00:22:42[diff] [blame]36#include"ui/events/gesture_detection/gesture_configuration.h"
oshima@chromium.org0c68e892012-12-08 16:54:53[diff] [blame]37
38namespace ash{
Scott Violetd8ceadb2019-03-21 01:31:43[diff] [blame]39namespace{
40
Sammie Quon358e9572019-11-21 04:38:02[diff] [blame]41classWindowAnimationWaiter:public ui::LayerAnimationObserver{
42public:
43explicitWindowAnimationWaiter(aura::Window* window)
44: animator_(window->layer()->GetAnimator()){
45 animator_->AddObserver(this);
46}
47~WindowAnimationWaiter() override=default;
48
49WindowAnimationWaiter(constWindowAnimationWaiter& other)=delete;
50WindowAnimationWaiter&operator=(constWindowAnimationWaiter& rhs)=delete;
51
52// ui::LayerAnimationObserver:
53voidOnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override{
54if(!animator_->is_animating()){
55 animator_->RemoveObserver(this);
56 run_loop_.Quit();
57}
58}
59voidOnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override{}
60voidOnLayerAnimationScheduled(
61 ui::LayerAnimationSequence* sequence) override{}
62
nergi7d04d012022-03-07 04:00:22[diff] [blame]63voidWait(){ run_loop_.Run();}
Sammie Quon358e9572019-11-21 04:38:02[diff] [blame]64
65private:
Bartek Nowierskideb75842023-12-27 02:32:42[diff] [blame]66 raw_ptr<ui::LayerAnimator,DanglingUntriaged> animator_;
Sammie Quon358e9572019-11-21 04:38:02[diff] [blame]67 base::RunLoop run_loop_;
68};
69
Scott Violetd8ceadb2019-03-21 01:31:43[diff] [blame]70}// namespace
oshima@chromium.org0c68e892012-12-08 16:54:53[diff] [blame]71
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]72ShellTestApi::ShellTestApi(): shell_(Shell::Get()){}
73ShellTestApi::~ShellTestApi()=default;
James Cook00848f02018-01-05 18:02:57[diff] [blame]74
Sammie Quon408e9da2019-06-20 19:36:21[diff] [blame]75// static
76voidShellTestApi::SetTabletControllerUseScreenshotForTest(
77bool use_screenshot){
78TabletModeController::SetUseScreenshotForTest(use_screenshot);
79}
80
Ahmed Mehfooz812c5422021-03-29 22:42:16[diff] [blame]81// static
82voidShellTestApi::SetUseLoginNotificationDelayForTest(bool use_delay){
83SessionStateNotificationBlocker::SetUseLoginNotificationDelayForTest(
84 use_delay);
85}
86
James Cook459354b32017-09-27 23:18:01[diff] [blame]87MessageCenterController*ShellTestApi::message_center_controller(){
88return shell_->message_center_controller_.get();
89}
90
oshima@chromium.org093b8d642014-04-03 20:59:28[diff] [blame]91WorkspaceController*ShellTestApi::workspace_controller(){
Ahmed Fakhryfee7a0a2019-04-05 22:49:48[diff] [blame]92// TODO(afakhry): Split this into two, one for root, and one for context.
93returnGetActiveWorkspaceController(shell_->GetPrimaryRootWindow());
oshima@chromium.org0c68e892012-12-08 16:54:53[diff] [blame]94}
95
oshima@chromium.org093b8d642014-04-03 20:59:28[diff] [blame]96ScreenPositionController*ShellTestApi::screen_position_controller(){
oshima@chromium.org0c68e892012-12-08 16:54:53[diff] [blame]97return shell_->screen_position_controller_.get();
98}
99
erg36cfb952017-06-21 19:41:45[diff] [blame]100NativeCursorManagerAsh*ShellTestApi::native_cursor_manager_ash(){
erg@chromium.orgc0ff0342013-02-27 00:41:29[diff] [blame]101return shell_->native_cursor_manager_;
102}
103
oshima@chromium.org093b8d642014-04-03 20:59:28[diff] [blame]104DragDropController*ShellTestApi::drag_drop_controller(){
varunjain@chromium.orgc086bab2013-06-06 21:46:44[diff] [blame]105return shell_->drag_drop_controller_.get();
106}
107
Qiang Xu36234e532018-04-11 04:54:02[diff] [blame]108PowerPrefs*ShellTestApi::power_prefs(){
109return shell_->power_prefs_.get();
110}
111
Sammie Quon4986fdf2020-05-15 19:33:58[diff] [blame]112display::DisplayManager*ShellTestApi::display_manager(){
113return shell_->display_manager();
114}
115
Qiang Xu50c6f8c2017-08-31 20:55:24[diff] [blame]116voidShellTestApi::ResetPowerButtonControllerForTest(){
Toni Barzic9d0c82f42017-12-06 00:53:52[diff] [blame]117 shell_->backlights_forced_off_setter_->ResetForTest();
nergi7d04d012022-03-07 04:00:22[diff] [blame]118 shell_->power_button_controller_.reset();
Toni Barzic9d0c82f42017-12-06 00:53:52[diff] [blame]119 shell_->power_button_controller_= std::make_unique<PowerButtonController>(
120 shell_->backlights_forced_off_setter_.get());
Qiang Xu50c6f8c2017-08-31 20:55:24[diff] [blame]121}
122
James Cook7b7c6a52018-01-04 23:40:03[diff] [blame]123voidShellTestApi::SimulateModalWindowOpenForTest(bool modal_window_open){
124 shell_->simulate_modal_window_open_for_test_= modal_window_open;
125}
126
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]127boolShellTestApi::IsSystemModalWindowOpen(){
128returnShell::IsSystemModalWindowOpen();
James Cook00848f02018-01-05 18:02:57[diff] [blame]129}
130
James Cookbbca6452021-01-13 17:26:03[diff] [blame]131voidShellTestApi::SetTabletModeEnabledForTest(bool enable){
Ahmed Fakhry607ade02019-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 Dai7e182452020-05-05 23:29:19[diff] [blame]137 ui::DeviceDataManagerTestApi().OnDeviceListsComplete();
Ahmed Fakhry607ade02019-10-31 15:59:39[diff] [blame]138 ui::DeviceDataManagerTestApi().SetMouseDevices({});
139
Mitsuru Oshimaa6adca4f2019-07-10 23:30:46[diff] [blame]140TabletMode::Waiter waiter(enable);
Mitsuru Oshima9e05edd2019-06-17 19:35:39[diff] [blame]141 shell_->tablet_mode_controller()->SetEnabledForTest(enable);
Mitsuru Oshimaa6adca4f2019-07-10 23:30:46[diff] [blame]142 waiter.Wait();
Evan Staded689b332018-08-02 01:17:22[diff] [blame]143}
144
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]145voidShellTestApi::EnableVirtualKeyboard(){
Darren Shen7daf3e12019-07-02 07:25:49[diff] [blame]146 shell_->keyboard_controller()->SetEnableFlag(
Darren Shen8604a212019-06-07 00:41:38[diff] [blame]147 keyboard::KeyboardEnableFlag::kCommandLineEnabled);
Noel Gordonfe3ac342018-09-10 05:12:57[diff] [blame]148}
149
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]150voidShellTestApi::ToggleFullscreen(){
Manu Cornetc3511d902020-01-10 22:44:43[diff] [blame]151 accelerators::ToggleFullscreen();
Evan Stade7768d472018-10-25 22:40:17[diff] [blame]152}
153
Jun Mukaiaa8479c82019-01-08 02:30:39[diff] [blame]154voidShellTestApi::AddRemoveDisplay(){
155 shell_->display_manager()->AddRemoveDisplay();
156}
157
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]158voidShellTestApi::WaitForOverviewAnimationState(OverviewAnimationState state){
159auto* overview_controller= shell_->overview_controller();
160if(state==OverviewAnimationState::kEnterAnimationComplete&&
Sammie Quon2c85f73d2019-05-08 23:10:27[diff] [blame]161 overview_controller->InOverviewSession()&&
Mitsuru Oshima57cc7852019-04-10 00:15:27[diff] [blame]162!overview_controller->IsInStartAnimation()){
163// If there is no animation applied, call the callback immediately.
Mitsuru Oshima57cc7852019-04-10 00:15:27[diff] [blame]164return;
165}
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]166if(state==OverviewAnimationState::kExitAnimationComplete&&
Sammie Quon2c85f73d2019-05-08 23:10:27[diff] [blame]167!overview_controller->InOverviewSession()&&
Mitsuru Oshima57cc7852019-04-10 00:15:27[diff] [blame]168!overview_controller->IsCompletingShutdownAnimations()){
169// If there is no animation applied, call the callback immediately.
Mitsuru Oshima57cc7852019-04-10 00:15:27[diff] [blame]170return;
171}
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]172 base::RunLoop run_loop;
Jun Mukai2b91e702019-09-05 18:24:38[diff] [blame]173newOverviewAnimationStateWaiter(
Reilly Grantb6702232019-11-26 22:46:04[diff] [blame]174 state, base::BindOnce([](base::RunLoop* run_loop,
175bool finished){ run_loop->QuitWhenIdle();},
176 base::Unretained(&run_loop)));
Jun Mukai44986382019-05-14 18:19:20[diff] [blame]177 run_loop.Run();
Mitsuru Oshima57cc7852019-04-10 00:15:27[diff] [blame]178}
179
Sammie Quon358e9572019-11-21 04:38:02[diff] [blame]180voidShellTestApi::WaitForWindowFinishAnimating(aura::Window* window){
181WindowAnimationWaiter waiter(window);
182 waiter.Wait();
183}
184
Sammie Quond322167b2021-01-11 22:10:40[diff] [blame]185boolShellTestApi::IsContextMenuShown()const{
Sammie Quon6b789012024-08-09 17:29:28[diff] [blame]186returnShell::GetPrimaryRootWindowController()->IsContextMenuShownForTest();
Sammie Quond322167b2021-01-11 22:10:40[diff] [blame]187}
188
Alexander Alekseev2b4c9592021-05-04 22:26:44[diff] [blame]189boolShellTestApi::IsActionForAcceleratorEnabled(
190const ui::Accelerator& accelerator)const{
Zentaro Kavanagh628ab4a2021-07-27 22:19:37[diff] [blame]191auto* controller=Shell::Get()->accelerator_controller();
192returnAcceleratorControllerImpl::TestApi(controller)
193.IsActionForAcceleratorEnabled(accelerator);
Alexander Alekseev2b4c9592021-05-04 22:26:44[diff] [blame]194}
195
196boolShellTestApi::PressAccelerator(const ui::Accelerator& accelerator){
197returnShell::Get()->accelerator_controller()->AcceleratorPressed(
198 accelerator);
199}
200
201boolShellTestApi::IsHUDShown(){
202return hud_display::HUDDisplayView::IsShown();
203}
204
oshima@chromium.org0c68e892012-12-08 16:54:53[diff] [blame]205}// namespace ash

[8]ページ先頭

©2009-2025 Movatter.jp