[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/test/ash_test_helper.h" |
| 6 | |
xiyuan | 317fdbe | 2017-05-31 15:02:02 | [diff] [blame] | 7 | #include <algorithm> |
xiyuan | 317fdbe | 2017-05-31 15:02:02 | [diff] [blame] | 8 | |
Zentaro Kavanagh | 1f43649 | 2021-05-20 23:29:36 | [diff] [blame] | 9 | #include "ash/accelerators/accelerator_controller_impl.h" |
Harvey Yang | d830659 | 2020-10-29 05:09:08 | [diff] [blame] | 10 | #include "ash/accelerometer/accelerometer_reader.h" |
wutao | 92a8f5c | 2020-11-09 23:25:54 | [diff] [blame] | 11 | #include "ash/ambient/test/ambient_ash_test_helper.h" |
Scott Violet | 42d669578 | 2018-06-04 16:12:17 | [diff] [blame] | 12 | #include "ash/app_list/test/app_list_test_helper.h" |
David Black | ec4cbcd | 2020-04-15 20:35:25 | [diff] [blame] | 13 | #include "ash/assistant/assistant_controller_impl.h" |
Xiaohui Chen | e5d3b43 | 2019-06-14 17:51:24 | [diff] [blame] | 14 | #include "ash/assistant/test/test_assistant_service.h" |
Henrique Ferreiro | 7b69376 | 2021-02-18 23:01:46 | [diff] [blame] | 15 | #include "ash/components/audio/cras_audio_handler.h" |
Henrique Ferreiro | 54c89f8 | 2021-06-15 15:41:28 | [diff] [blame] | 16 | #include "ash/constants/ash_switches.h" |
James Cook | 346c8c6 | 2017-07-18 19:38:37 | [diff] [blame] | 17 | #include "ash/display/display_configuration_controller_test_api.h" |
James Cook | d3cf52c | 2018-05-24 14:57:30 | [diff] [blame] | 18 | #include "ash/display/screen_ash.h" |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 19 | #include "ash/host/ash_window_tree_host.h" |
Darren Shen | 7daf3e1 | 2019-07-02 07:25:49 | [diff] [blame] | 20 | #include "ash/keyboard/keyboard_controller_impl.h" |
Jun Mukai | f235779 | 2018-12-20 19:58:00 | [diff] [blame] | 21 | #include "ash/keyboard/test_keyboard_ui.h" |
Steven Bennetts | 99f5b69 | 2018-11-27 16:31:40 | [diff] [blame] | 22 | #include "ash/public/cpp/test/test_keyboard_controller_observer.h" |
Jun Mukai | 688f8b42 | 2019-05-22 00:54:48 | [diff] [blame] | 23 | #include "ash/public/cpp/test/test_new_window_delegate.h" |
Scott Violet | 42d669578 | 2018-06-04 16:12:17 | [diff] [blame] | 24 | #include "ash/session/test_session_controller_client.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 25 | #include "ash/shell.h" |
Peter Kasting | 16204ab2 | 2020-03-12 03:38:43 | [diff] [blame] | 26 | #include "ash/shell_init_params.h" |
Ahmed Mehfooz | 812c542 | 2021-03-29 22:42:16 | [diff] [blame] | 27 | #include "ash/system/message_center/session_state_notification_blocker.h" |
James Cook | ee5fc73 | 2019-06-07 14:48:52 | [diff] [blame] | 28 | #include "ash/system/model/system_tray_model.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame] | 29 | #include "ash/system/screen_layout_observer.h" |
[email protected] | 93e828f | 2014-05-14 14:08:11 | [diff] [blame] | 30 | #include "ash/test/ash_test_views_delegate.h" |
Jun Mukai | 5a703633 | 2020-07-20 21:35:35 | [diff] [blame] | 31 | #include "ash/test/toplevel_window.h" |
James Cook | 346c8c6 | 2017-07-18 19:38:37 | [diff] [blame] | 32 | #include "ash/test_shell_delegate.h" |
Jeffrey Young | 708db7f | 2021-09-20 19:38:46 | [diff] [blame] | 33 | #include "ash/wallpaper/test_wallpaper_controller_client.h" |
Mike Wasserman | a5352da | 2019-05-30 17:26:08 | [diff] [blame] | 34 | #include "ash/wallpaper/wallpaper_controller_impl.h" |
Sammie Quon | 8bac828 | 2019-03-30 03:06:46 | [diff] [blame] | 35 | #include "ash/wm/overview/overview_controller.h" |
Sammie Quon | a071cc59 | 2019-06-12 17:16:45 | [diff] [blame] | 36 | #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 37 | #include "base/run_loop.h" |
Mitsuru Oshima | 513902c | 2019-07-30 23:56:55 | [diff] [blame] | 38 | #include "base/system/sys_info.h" |
Steven Bennetts | c5caf70d1 | 2019-04-08 22:12:39 | [diff] [blame] | 39 | #include "chromeos/dbus/audio/cras_audio_client.h" |
Steven Bennetts | 3330b9f | 2019-03-15 20:24:13 | [diff] [blame] | 40 | #include "chromeos/dbus/power/power_policy_controller.h" |
Mitsuru Oshima | ca97b108 | 2021-01-29 21:12:38 | [diff] [blame] | 41 | #include "chromeos/login/login_state/login_state.h" |
jamescook | e96488a | 2017-01-20 15:49:44 | [diff] [blame] | 42 | #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 43 | #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
Scott Violet | ac41062 | 2018-08-11 18:33:22 | [diff] [blame] | 44 | #include "ui/aura/test/test_windows.h" |
| 45 | #include "ui/aura/window.h" |
Peter Kasting | 86d2b581 | 2020-04-01 22:32:14 | [diff] [blame] | 46 | #include "ui/aura/window_tree_host.h" |
Henrique Ferreiro | 1220b39 | 2021-09-16 19:58:07 | [diff] [blame] | 47 | #include "ui/base/ime/ash/mock_input_method_manager.h" |
varkha | c8621dd | 2017-05-31 19:09:01 | [diff] [blame] | 48 | #include "ui/display/display.h" |
wutao | b161bf2 | 2017-04-26 16:55:03 | [diff] [blame] | 49 | #include "ui/display/display_switches.h" |
sky | d06586d | 2017-02-22 17:46:36 | [diff] [blame] | 50 | #include "ui/display/manager/display_manager.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 51 | #include "ui/display/test/display_manager_test_api.h" |
Peter Kasting | 86d2b581 | 2020-04-01 22:32:14 | [diff] [blame] | 52 | #include "ui/events/gesture_detection/gesture_configuration.h" |
| 53 | #include "ui/gfx/geometry/point.h" |
Maksim Sisov | f6382c2 | 2019-09-03 13:36:38 | [diff] [blame] | 54 | #include "ui/platform_window/common/platform_window_defaults.h" |
Peter Kasting | 0639dc7 | 2020-03-27 16:43:54 | [diff] [blame] | 55 | #include "ui/views/test/views_test_helper_aura.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 56 | #include "ui/wm/core/capture_controller.h" |
ananta | f2b280f | 2016-04-13 21:49:35 | [diff] [blame] | 57 | #include "ui/wm/core/cursor_manager.h" |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 58 | #include "ui/wm/core/focus_controller.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 59 | |
| 60 | namespace ash { |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 61 | |
Peter Kasting | 0639dc7 | 2020-03-27 16:43:54 | [diff] [blame] | 62 | namespace { |
Peter Kasting | 37122d0 | 2020-04-02 00:08:55 | [diff] [blame] | 63 | std::unique_ptr<views::TestViewsDelegate> MakeTestViewsDelegate() { |
Peter Kasting | 0639dc7 | 2020-03-27 16:43:54 | [diff] [blame] | 64 | return std::make_unique<AshTestViewsDelegate>(); |
| 65 | } |
| 66 | } // namespace |
| 67 | |
Peter Kasting | 16204ab2 | 2020-03-12 03:38:43 | [diff] [blame] | 68 | AshTestHelper::InitParams::InitParams() = default; |
| 69 | AshTestHelper::InitParams::InitParams(InitParams&&) = default; |
| 70 | AshTestHelper::InitParams::~InitParams() = default; |
| 71 | |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 72 | class AshTestHelper::BluezDBusManagerInitializer { |
| 73 | public: |
| 74 | BluezDBusManagerInitializer() { bluez::BluezDBusManager::InitializeFake(); } |
| 75 | ~BluezDBusManagerInitializer() { |
| 76 | device::BluetoothAdapterFactory::Shutdown(); |
| 77 | bluez::BluezDBusManager::Shutdown(); |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | class AshTestHelper::PowerPolicyControllerInitializer { |
| 82 | public: |
| 83 | PowerPolicyControllerInitializer() { |
| 84 | chromeos::PowerPolicyController::Initialize( |
| 85 | chromeos::PowerManagerClient::Get()); |
| 86 | } |
| 87 | ~PowerPolicyControllerInitializer() { |
| 88 | chromeos::PowerPolicyController::Shutdown(); |
| 89 | } |
| 90 | }; |
| 91 | |
James Cook | 0eda254 | 2021-03-30 23:49:19 | [diff] [blame] | 92 | AshTestHelper::AshTestHelper(ui::ContextFactory* context_factory) |
| 93 | : AuraTestHelper(context_factory) { |
Peter Kasting | 0639dc7 | 2020-03-27 16:43:54 | [diff] [blame] | 94 | views::ViewsTestHelperAura::SetFallbackTestViewsDelegateFactory( |
Peter Kasting | 37122d0 | 2020-04-02 00:08:55 | [diff] [blame] | 95 | &MakeTestViewsDelegate); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 96 | |
| 97 | // TODO(jamescook): Can we do this without changing command line? |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 98 | // Use the origin (1,1) so that it doesn't overlap with the native mouse |
| 99 | // cursor. |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 100 | if (!base::SysInfo::IsRunningOnChromeOS() && |
| 101 | !command_line_->GetProcessCommandLine()->HasSwitch( |
| 102 | ::switches::kHostWindowBounds)) { |
| 103 | // TODO(oshima): Disable native events instead of adding offset. |
| 104 | command_line_->GetProcessCommandLine()->AppendSwitchASCII( |
| 105 | ::switches::kHostWindowBounds, "10+10-800x600"); |
| 106 | } |
| 107 | |
James Cook | 0eda254 | 2021-03-30 23:49:19 | [diff] [blame] | 108 | TabletModeController::SetUseScreenshotForTest(false); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 109 | |
James Cook | 0eda254 | 2021-03-30 23:49:19 | [diff] [blame] | 110 | display::ResetDisplayIdForTest(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 111 | |
| 112 | chromeos::CrasAudioClient::InitializeFake(); |
| 113 | // Create CrasAudioHandler for testing since g_browser_process is not |
| 114 | // created in AshTestBase tests. |
Henrique Ferreiro | 3d9d93d | 2021-02-19 22:17:39 | [diff] [blame] | 115 | CrasAudioHandler::InitializeForTesting(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 116 | |
| 117 | // Reset the global state for the cursor manager. This includes the |
| 118 | // last cursor visibility state, etc. |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 119 | wm::CursorManager::ResetCursorVisibilityStateForTest(); |
Peter Kasting | 86d2b581 | 2020-04-01 22:32:14 | [diff] [blame] | 120 | |
| 121 | // Clears the saved state so that test doesn't use on the wrong |
| 122 | // default state. |
| 123 | shell::ToplevelWindow::ClearSavedStateForTest(); |
Peter Kasting | 0639dc7 | 2020-03-27 16:43:54 | [diff] [blame] | 124 | } |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 125 | |
James Cook | d3cf52c | 2018-05-24 14:57:30 | [diff] [blame] | 126 | AshTestHelper::~AshTestHelper() { |
Peter Kasting | 3b81c72f | 2020-03-30 23:28:19 | [diff] [blame] | 127 | if (app_list_test_helper_) |
| 128 | TearDown(); |
| 129 | |
Peter Kasting | ec1e1cfb | 2020-03-26 23:11:18 | [diff] [blame] | 130 | // Ensure the next test starts with a null display::Screen. This must be done |
| 131 | // here instead of in TearDown() since some tests test access to the Screen |
| 132 | // after the shell shuts down (which they use TearDown() to trigger). |
James Cook | d3cf52c | 2018-05-24 14:57:30 | [diff] [blame] | 133 | ScreenAsh::DeleteScreenForShutdown(); |
Peter Kasting | 0639dc7 | 2020-03-27 16:43:54 | [diff] [blame] | 134 | |
| 135 | // This should never have a meaningful effect, since either there is no |
| 136 | // ViewsTestHelperAura instance or the instance is currently in its |
| 137 | // destructor. |
Peter Kasting | 37122d0 | 2020-04-02 00:08:55 | [diff] [blame] | 138 | views::ViewsTestHelperAura::SetFallbackTestViewsDelegateFactory(nullptr); |
James Cook | d3cf52c | 2018-05-24 14:57:30 | [diff] [blame] | 139 | } |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 140 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 141 | void AshTestHelper::SetUp() { |
| 142 | SetUp(InitParams()); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void AshTestHelper::TearDown() { |
wutao | 92a8f5c | 2020-11-09 23:25:54 | [diff] [blame] | 146 | ambient_ash_test_helper_.reset(); |
| 147 | |
Peter Kasting | ec1e1cfb | 2020-03-26 23:11:18 | [diff] [blame] | 148 | // The AppListTestHelper holds a pointer to the AppListController the Shell |
| 149 | // owns, so shut the test helper down first. |
Jiaquan He | dbfd451 | 2018-03-02 02:16:38 | [diff] [blame] | 150 | app_list_test_helper_.reset(); |
| 151 | |
Scott Violet | c43ea0c6 | 2018-07-20 15:13:00 | [diff] [blame] | 152 | Shell::DeleteInstance(); |
staraz | d8f4f64 | 2016-12-10 23:49:20 | [diff] [blame] | 153 | // Suspend the tear down until all resources are returned via |
danakj | 2e3aca0 | 2017-06-23 22:58:52 | [diff] [blame] | 154 | // CompositorFrameSinkClient::ReclaimResources() |
Steven Bennetts | a1f686d | 2018-06-05 18:01:19 | [diff] [blame] | 155 | base::RunLoop().RunUntilIdle(); |
ben | b91330f | 2015-10-03 22:20:18 | [diff] [blame] | 156 | |
Mitsuru Oshima | ca97b108 | 2021-01-29 21:12:38 | [diff] [blame] | 157 | chromeos::LoginState::Shutdown(); |
| 158 | |
Henrique Ferreiro | 3d9d93d | 2021-02-19 22:17:39 | [diff] [blame] | 159 | CrasAudioHandler::Shutdown(); |
Steven Bennetts | 10ecd9d | 2019-04-08 20:36:46 | [diff] [blame] | 160 | chromeos::CrasAudioClient::Shutdown(); |
sky | d06586d | 2017-02-22 17:46:36 | [diff] [blame] | 161 | |
Peter Kasting | ec1e1cfb | 2020-03-26 23:11:18 | [diff] [blame] | 162 | // The PowerPolicyController holds a pointer to the PowerManagementClient, so |
| 163 | // shut the controller down first. |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 164 | power_policy_controller_initializer_.reset(); |
Evan Stade | 523f7fc | 2019-03-02 19:20:51 | [diff] [blame] | 165 | chromeos::PowerManagerClient::Shutdown(); |
| 166 | |
Peter Kasting | ec1e1cfb | 2020-03-26 23:11:18 | [diff] [blame] | 167 | TabletModeController::SetUseScreenshotForTest(true); |
| 168 | |
| 169 | // Destroy all owned objects to prevent tests from depending on their state |
| 170 | // after this returns. |
| 171 | test_keyboard_controller_observer_.reset(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 172 | session_controller_client_.reset(); |
Peter Kasting | ec1e1cfb | 2020-03-26 23:11:18 | [diff] [blame] | 173 | test_views_delegate_.reset(); |
Hidehiko Abe | 6e3e57f4 | 2021-03-23 11:23:58 | [diff] [blame] | 174 | new_window_delegate_provider_.reset(); |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 175 | bluez_dbus_manager_initializer_.reset(); |
Peter Kasting | ec1e1cfb | 2020-03-26 23:11:18 | [diff] [blame] | 176 | system_tray_client_.reset(); |
| 177 | assistant_service_.reset(); |
| 178 | notifier_settings_controller_.reset(); |
| 179 | prefs_provider_.reset(); |
| 180 | statistics_provider_.reset(); |
| 181 | command_line_.reset(); |
sky | d06586d | 2017-02-22 17:46:36 | [diff] [blame] | 182 | |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 183 | AuraTestHelper::TearDown(); |
Zentaro Kavanagh | 930de99 | 2021-05-10 15:51:07 | [diff] [blame] | 184 | |
| 185 | // Cleanup the global state for InputMethodManager, but only if |
| 186 | // it was setup by this test helper. This allows tests to implement |
| 187 | // their own override, and in that case we shouldn't call Shutdown |
| 188 | // otherwise the global state will be deleted twice. |
| 189 | if (input_method_manager_) { |
Henrique Ferreiro | e08cf1b | 2021-09-22 19:33:58 | [diff] [blame] | 190 | input_method::InputMethodManager::Shutdown(); |
Zentaro Kavanagh | 930de99 | 2021-05-10 15:51:07 | [diff] [blame] | 191 | input_method_manager_ = nullptr; |
| 192 | } |
Scott Violet | ac41062 | 2018-08-11 18:33:22 | [diff] [blame] | 193 | } |
| 194 | |
Peter Kasting | 97defc9 | 2020-03-05 18:49:02 | [diff] [blame] | 195 | aura::Window* AshTestHelper::GetContext() { |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 196 | aura::Window* root_window = Shell::GetRootWindowForNewWindows(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 197 | if (!root_window) |
| 198 | root_window = Shell::GetPrimaryRootWindow(); |
| 199 | DCHECK(root_window); |
| 200 | return root_window; |
| 201 | } |
| 202 | |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 203 | aura::WindowTreeHost* AshTestHelper::GetHost() { |
| 204 | auto* manager = Shell::Get()->window_tree_host_manager(); |
| 205 | const int64_t id = manager->GetPrimaryDisplayId(); |
| 206 | return manager->GetAshWindowTreeHostForDisplayId(id)->AsWindowTreeHost(); |
| 207 | } |
| 208 | |
| 209 | aura::TestScreen* AshTestHelper::GetTestScreen() { |
| 210 | // If a test needs this, we may need to refactor TestScreen such that its |
| 211 | // methods can operate atop some sort of real screen/host/display, and hook |
| 212 | // them to the ones provided by the shell. For now, not bothering. |
| 213 | NOTIMPLEMENTED(); |
| 214 | return nullptr; |
| 215 | } |
| 216 | |
| 217 | aura::client::FocusClient* AshTestHelper::GetFocusClient() { |
| 218 | return Shell::Get()->focus_controller(); |
| 219 | } |
| 220 | |
| 221 | aura::client::CaptureClient* AshTestHelper::GetCaptureClient() { |
| 222 | return wm::CaptureController::Get(); |
| 223 | } |
| 224 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 225 | void AshTestHelper::SetUp(InitParams init_params) { |
| 226 | // This block of objects are conditionally initialized here rather than in the |
| 227 | // constructor to make it easier for test classes to override them. |
Zentaro Kavanagh | 930de99 | 2021-05-10 15:51:07 | [diff] [blame] | 228 | if (!input_method::InputMethodManager::Get()) { |
| 229 | // |input_method_manager_| is not owned and is cleaned up in TearDown() |
| 230 | // by calling InputMethodManager::Shutdown(). |
Henrique Ferreiro | e08cf1b | 2021-09-22 19:33:58 | [diff] [blame] | 231 | input_method_manager_ = new input_method::MockInputMethodManager(); |
Zentaro Kavanagh | 930de99 | 2021-05-10 15:51:07 | [diff] [blame] | 232 | input_method::InputMethodManager::Initialize(input_method_manager_); |
| 233 | } |
| 234 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 235 | if (!bluez::BluezDBusManager::IsInitialized()) { |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 236 | bluez_dbus_manager_initializer_ = |
| 237 | std::make_unique<BluezDBusManagerInitializer>(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 238 | } |
| 239 | if (!chromeos::PowerManagerClient::Get()) |
| 240 | chromeos::PowerManagerClient::InitializeFake(); |
| 241 | if (!chromeos::PowerPolicyController::IsInitialized()) { |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 242 | power_policy_controller_initializer_ = |
| 243 | std::make_unique<PowerPolicyControllerInitializer>(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 244 | } |
Hidehiko Abe | 6e3e57f4 | 2021-03-23 11:23:58 | [diff] [blame] | 245 | if (!NewWindowDelegate::GetInstance()) { |
| 246 | new_window_delegate_provider_ = |
| 247 | std::make_unique<TestNewWindowDelegateProvider>( |
| 248 | std::make_unique<TestNewWindowDelegate>()); |
| 249 | } |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 250 | if (!views::ViewsDelegate::GetInstance()) |
Peter Kasting | 37122d0 | 2020-04-02 00:08:55 | [diff] [blame] | 251 | test_views_delegate_ = MakeTestViewsDelegate(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 252 | |
Mitsuru Oshima | ca97b108 | 2021-01-29 21:12:38 | [diff] [blame] | 253 | chromeos::LoginState::Initialize(); |
| 254 | |
wutao | 92a8f5c | 2020-11-09 23:25:54 | [diff] [blame] | 255 | ambient_ash_test_helper_ = std::make_unique<AmbientAshTestHelper>(); |
| 256 | |
Zentaro Kavanagh | 1f43649 | 2021-05-20 23:29:36 | [diff] [blame] | 257 | // There is a temporary M92-M94 notification that shows once to users |
| 258 | // at startup, but this interferes with many tests that expect a |
| 259 | // specific active window, or a certain number of notifications. |
| 260 | AcceleratorControllerImpl::SetShouldShowShortcutNotificationForTest(false); |
| 261 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 262 | ShellInitParams shell_init_params; |
| 263 | shell_init_params.delegate = std::move(init_params.delegate); |
| 264 | if (!shell_init_params.delegate) |
| 265 | shell_init_params.delegate = std::make_unique<TestShellDelegate>(); |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 266 | shell_init_params.context_factory = GetContextFactory(); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 267 | shell_init_params.local_state = init_params.local_state; |
| 268 | shell_init_params.keyboard_ui_factory = |
| 269 | std::make_unique<TestKeyboardUIFactory>(); |
| 270 | Shell::CreateInstance(std::move(shell_init_params)); |
| 271 | Shell* shell = Shell::Get(); |
| 272 | |
Jeffrey Young | 708db7f | 2021-09-20 19:38:46 | [diff] [blame] | 273 | // Set up a test wallpaper controller client before signing in any users. At |
| 274 | // the time a user logs in, Wallpaper controller relies on |
| 275 | // WallpaperControllerClient to check if user data should be synced. |
| 276 | wallpaper_controller_client_ = |
| 277 | std::make_unique<TestWallpaperControllerClient>(); |
| 278 | shell->wallpaper_controller()->SetClient(wallpaper_controller_client_.get()); |
| 279 | |
Ahmed Mehfooz | 812c542 | 2021-03-29 22:42:16 | [diff] [blame] | 280 | // Disable the notification delay timer used to prevent non system |
| 281 | // notifications from showing up right after login. This needs to be done |
| 282 | // before any user sessions are added since the delay timer starts right |
| 283 | // after that. |
| 284 | SessionStateNotificationBlocker::SetUseLoginNotificationDelayForTest(false); |
| 285 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 286 | // Cursor is visible by default in tests. |
| 287 | shell->cursor_manager()->ShowCursor(); |
| 288 | |
Xiaohui Chen | 2af0930 | 2020-06-25 04:06:00 | [diff] [blame] | 289 | shell->assistant_controller()->SetAssistant(assistant_service_.get()); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 290 | |
| 291 | shell->system_tray_model()->SetClient(system_tray_client_.get()); |
| 292 | |
Peter Kasting | 4d66384d | 2020-03-30 23:28:49 | [diff] [blame] | 293 | session_controller_client_ = std::make_unique<TestSessionControllerClient>( |
| 294 | shell->session_controller(), prefs_provider_.get()); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 295 | session_controller_client_->InitializeAndSetClient(); |
| 296 | if (init_params.start_session) |
| 297 | session_controller_client_->CreatePredefinedUserSessions(1); |
| 298 | |
| 299 | // Requires the AppListController the Shell creates. |
| 300 | app_list_test_helper_ = std::make_unique<AppListTestHelper>(); |
| 301 | |
Peter Kasting | 86d2b581 | 2020-04-01 22:32:14 | [diff] [blame] | 302 | Shell::GetPrimaryRootWindow()->Show(); |
| 303 | Shell::GetPrimaryRootWindow()->GetHost()->Show(); |
| 304 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 305 | // Don't change the display size due to host size resize. |
| 306 | display::test::DisplayManagerTestApi(shell->display_manager()) |
| 307 | .DisableChangeDisplayUponHostResize(); |
| 308 | |
| 309 | // Create the test keyboard controller observer to respond to |
| 310 | // OnLoadKeyboardContentsRequested(). |
| 311 | test_keyboard_controller_observer_ = |
| 312 | std::make_unique<TestKeyboardControllerObserver>( |
| 313 | shell->keyboard_controller()); |
| 314 | |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 315 | // Tests that change the display configuration generally don't care about the |
| 316 | // notifications and the popup UI can interfere with things like cursors. |
| 317 | shell->screen_layout_observer()->set_show_notifications_for_testing(false); |
| 318 | |
| 319 | // Disable display change animations in unit tests. |
| 320 | DisplayConfigurationControllerTestApi( |
| 321 | shell->display_configuration_controller()) |
| 322 | .SetDisplayAnimator(false); |
| 323 | |
| 324 | // Remove the app dragging animations delay for testing purposes. |
| 325 | shell->overview_controller()->set_delayed_animation_task_delay_for_test( |
| 326 | base::TimeDelta()); |
| 327 | |
| 328 | // Tests expect empty wallpaper. |
| 329 | shell->wallpaper_controller()->CreateEmptyWallpaperForTesting(); |
Peter Kasting | 86d2b581 | 2020-04-01 22:32:14 | [diff] [blame] | 330 | |
| 331 | // Move the mouse cursor to far away so that native events don't interfere |
| 332 | // with test expectations. |
| 333 | Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000)); |
| 334 | Shell::Get()->cursor_manager()->EnableMouseEvents(); |
| 335 | |
| 336 | // Changing GestureConfiguration shouldn't make tests fail. These values |
| 337 | // prevent unexpected events from being generated during tests. Such as |
| 338 | // delayed events which create race conditions on slower tests. |
| 339 | ui::GestureConfiguration* gesture_config = |
| 340 | ui::GestureConfiguration::GetInstance(); |
| 341 | gesture_config->set_max_touch_down_duration_for_click_in_ms(800); |
| 342 | gesture_config->set_long_press_time_in_ms(1000); |
| 343 | gesture_config->set_max_touch_move_in_pixels_for_click(5); |
Harvey Yang | d830659 | 2020-10-29 05:09:08 | [diff] [blame] | 344 | |
| 345 | // Fake the |ec_lid_angle_driver_status_| in the unittests. |
| 346 | AccelerometerReader::GetInstance()->SetECLidAngleDriverStatusForTesting( |
| 347 | ECLidAngleDriverStatus::NOT_SUPPORTED); |
Peter Kasting | 9eaedfd9 | 2020-03-30 23:24:50 | [diff] [blame] | 348 | } |
| 349 | |
Andrew Xu | bd59c16 | 2019-08-01 01:35:00 | [diff] [blame] | 350 | display::Display AshTestHelper::GetSecondaryDisplay() const { |
Su Hong Koo | 777e83d | 2020-02-07 01:45:33 | [diff] [blame] | 351 | return display::test::DisplayManagerTestApi(Shell::Get()->display_manager()) |
| 352 | .GetSecondaryDisplay(); |
sky | d06586d | 2017-02-22 17:46:36 | [diff] [blame] | 353 | } |
| 354 | |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 355 | } // namespace ash |