[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 | |||||
sky | 44a0989 | 2016-07-20 17:46:58 | [diff] [blame] | 7 | #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
bruthig | a2239af | 2016-08-02 17:07:29 | [diff] [blame] | 8 | #include "ash/common/material_design/material_design_controller.h" |
sky | aec2890 | 2016-08-03 00:14:55 | [diff] [blame] | 9 | #include "ash/common/test/material_design_controller_test_api.h" |
sky | 1593c7bf | 2016-10-07 21:07:53 | [diff] [blame] | 10 | #include "ash/common/test/test_session_state_delegate.h" |
jamescook | a800305 | 2016-10-11 17:02:34 | [diff] [blame] | 11 | #include "ash/common/test/test_system_tray_delegate.h" |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 12 | #include "ash/common/wm_shell.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 13 | #include "ash/shell.h" |
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 14 | #include "ash/shell_init_params.h" |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 15 | #include "ash/test/ash_test_environment.h" |
[email protected] | 93e828f | 2014-05-14 14:08:11 | [diff] [blame] | 16 | #include "ash/test/ash_test_views_delegate.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 17 | #include "ash/test/display_manager_test_api.h" |
18 | #include "ash/test/shell_test_api.h" | ||||
[email protected] | c7283444 | 2013-10-01 03:11:29 | [diff] [blame] | 19 | #include "ash/test/test_screenshot_delegate.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 20 | #include "ash/test/test_shell_delegate.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 21 | #include "base/run_loop.h" |
22 | #include "ui/aura/env.h" | ||||
[email protected] | ccf28b8 | 2013-10-14 17:19:15 | [diff] [blame] | 23 | #include "ui/aura/input_state_lookup.h" |
24 | #include "ui/aura/test/env_test_helper.h" | ||||
[email protected] | 1f0ece91 | 2014-08-11 05:52:20 | [diff] [blame] | 25 | #include "ui/aura/test/event_generator_delegate_aura.h" |
[email protected] | 749bf643 | 2013-06-12 16:00:08 | [diff] [blame] | 26 | #include "ui/base/ime/input_method_initializer.h" |
varkha | 0b40cc39 | 2016-04-14 01:13:05 | [diff] [blame] | 27 | #include "ui/base/material_design/material_design_controller.h" |
28 | #include "ui/base/test/material_design_controller_test_api.h" | ||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 29 | #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
[email protected] | f633394 | 2013-10-30 17:32:55 | [diff] [blame] | 30 | #include "ui/compositor/test/context_factories_for_test.h" |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 31 | #include "ui/display/manager/managed_display_info.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 32 | #include "ui/message_center/message_center.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 33 | #include "ui/wm/core/capture_controller.h" |
ananta | f2b280f | 2016-04-13 21:49:35 | [diff] [blame] | 34 | #include "ui/wm/core/cursor_manager.h" |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 35 | |
[email protected] | 6d8c8f0 | 2013-05-13 17:33:12 | [diff] [blame] | 36 | #if defined(OS_CHROMEOS) |
jamescook | f60d6ea | 2016-10-11 21:37:37 | [diff] [blame^] | 37 | #include "ash/system/chromeos/screen_layout_observer.h" |
[email protected] | 6d8c8f0 | 2013-05-13 17:33:12 | [diff] [blame] | 38 | #include "chromeos/audio/cras_audio_handler.h" |
[email protected] | f08f39b | 2013-12-19 06:14:11 | [diff] [blame] | 39 | #include "chromeos/dbus/dbus_thread_manager.h" |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 40 | #include "device/bluetooth/bluetooth_adapter_factory.h" |
rkc | 06c92c0 | 2015-11-05 01:55:40 | [diff] [blame] | 41 | #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
[email protected] | 6d8c8f0 | 2013-05-13 17:33:12 | [diff] [blame] | 42 | #endif |
43 | |||||
[email protected] | 3f4c26e | 2014-04-09 23:53:07 | [diff] [blame] | 44 | #if defined(OS_WIN) |
45 | #include "base/win/windows_version.h" | ||||
46 | #endif | ||||
47 | |||||
[email protected] | 6b9aa60 | 2013-05-18 09:08:40 | [diff] [blame] | 48 | #if defined(USE_X11) |
[email protected] | e8cf733 | 2014-02-14 18:54:58 | [diff] [blame] | 49 | #include "ui/aura/window_tree_host_x11.h" |
[email protected] | 6b9aa60 | 2013-05-18 09:08:40 | [diff] [blame] | 50 | #endif |
51 | |||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 52 | namespace ash { |
53 | namespace test { | ||||
54 | |||||
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 55 | AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) |
56 | : ash_test_environment_(ash_test_environment), | ||||
ben | 9307244 | 2015-10-05 19:14:32 | [diff] [blame] | 57 | test_shell_delegate_(nullptr), |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 58 | test_screenshot_delegate_(nullptr) { |
tfarina | d7f1236f | 2015-01-16 16:21:20 | [diff] [blame] | 59 | #if defined(OS_CHROMEOS) |
60 | dbus_thread_manager_initialized_ = false; | ||||
rkc | 06c92c0 | 2015-11-05 01:55:40 | [diff] [blame] | 61 | bluez_dbus_manager_initialized_ = false; |
tfarina | d7f1236f | 2015-01-16 16:21:20 | [diff] [blame] | 62 | #endif |
[email protected] | 6b9aa60 | 2013-05-18 09:08:40 | [diff] [blame] | 63 | #if defined(USE_X11) |
64 | aura::test::SetUseOverrideRedirectWindowByDefault(true); | ||||
65 | #endif | ||||
[email protected] | 1f0ece91 | 2014-08-11 05:52:20 | [diff] [blame] | 66 | aura::test::InitializeAuraEventGeneratorDelegate(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 67 | } |
68 | |||||
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 69 | AshTestHelper::~AshTestHelper() {} |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 70 | |
mohsen | c66d687 | 2016-07-30 01:46:08 | [diff] [blame] | 71 | void AshTestHelper::SetUp(bool start_session, |
72 | MaterialDesignController::Mode material_mode) { | ||||
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 73 | display::ResetDisplayIdForTest(); |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 74 | views_delegate_ = ash_test_environment_->CreateViewsDelegate(); |
[email protected] | ef663fa | 2013-12-20 17:55:00 | [diff] [blame] | 75 | |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 76 | // Disable animations during tests. |
77 | zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | ||||
78 | ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | ||||
[email protected] | 749bf643 | 2013-06-12 16:00:08 | [diff] [blame] | 79 | ui::InitializeInputMethodForTesting(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 80 | |
[email protected] | 380a8bdf | 2014-02-20 19:02:54 | [diff] [blame] | 81 | bool enable_pixel_output = false; |
[email protected] | fa69f2b6 | 2014-05-22 21:47:58 | [diff] [blame] | 82 | ui::ContextFactory* context_factory = |
83 | ui::InitializeContextFactoryForTests(enable_pixel_output); | ||||
[email protected] | f633394 | 2013-10-30 17:32:55 | [diff] [blame] | 84 | |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 85 | // Creates Shell and hook with Desktop. |
[email protected] | b2e2a4a | 2014-03-15 05:39:28 | [diff] [blame] | 86 | if (!test_shell_delegate_) |
87 | test_shell_delegate_ = new TestShellDelegate; | ||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 88 | |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 89 | // Creates MessageCenter since g_browser_process is not created in AshTestBase |
90 | // tests. | ||||
91 | message_center::MessageCenter::Initialize(); | ||||
[email protected] | 6d8c8f0 | 2013-05-13 17:33:12 | [diff] [blame] | 92 | |
93 | #if defined(OS_CHROMEOS) | ||||
[email protected] | f08f39b | 2013-12-19 06:14:11 | [diff] [blame] | 94 | // Create DBusThreadManager for testing. |
95 | if (!chromeos::DBusThreadManager::IsInitialized()) { | ||||
jamescook | dd61838 | 2016-09-19 16:42:08 | [diff] [blame] | 96 | chromeos::DBusThreadManager::Initialize( |
97 | chromeos::DBusThreadManager::PROCESS_ASH); | ||||
[email protected] | f08f39b | 2013-12-19 06:14:11 | [diff] [blame] | 98 | dbus_thread_manager_initialized_ = true; |
99 | } | ||||
rkc | 06c92c0 | 2015-11-05 01:55:40 | [diff] [blame] | 100 | |
101 | if (!bluez::BluezDBusManager::IsInitialized()) { | ||||
102 | bluez::BluezDBusManager::Initialize( | ||||
103 | chromeos::DBusThreadManager::Get()->GetSystemBus(), | ||||
jamescook | 9be05a4 | 2016-09-19 19:09:49 | [diff] [blame] | 104 | chromeos::DBusThreadManager::Get()->IsUsingFakes()); |
rkc | 06c92c0 | 2015-11-05 01:55:40 | [diff] [blame] | 105 | bluez_dbus_manager_initialized_ = true; |
106 | } | ||||
107 | |||||
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 108 | // Create CrasAudioHandler for testing since g_browser_process is not |
109 | // created in AshTestBase tests. | ||||
110 | chromeos::CrasAudioHandler::InitializeForTesting(); | ||||
[email protected] | 0734308 | 2013-08-13 03:46:34 | [diff] [blame] | 111 | #endif |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 112 | ash_test_environment_->SetUp(); |
ananta | f2b280f | 2016-04-13 21:49:35 | [diff] [blame] | 113 | // Reset the global state for the cursor manager. This includes the |
114 | // last cursor visibility state, etc. | ||||
sky | 984c189 | 2016-04-20 00:00:34 | [diff] [blame] | 115 | ::wm::CursorManager::ResetCursorVisibilityStateForTest(); |
ananta | f2b280f | 2016-04-13 21:49:35 | [diff] [blame] | 116 | |
varkha | 0b40cc39 | 2016-04-14 01:13:05 | [diff] [blame] | 117 | // ContentTestSuiteBase might have already initialized |
118 | // MaterialDesignController in unit_tests suite. | ||||
119 | ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | ||||
120 | ui::MaterialDesignController::Initialize(); | ||||
varkha | b6a59711 | 2016-04-28 00:50:41 | [diff] [blame] | 121 | ash::MaterialDesignController::Initialize(); |
mohsen | c66d687 | 2016-07-30 01:46:08 | [diff] [blame] | 122 | if (material_mode == MaterialDesignController::Mode::UNINITIALIZED) |
123 | material_mode = MaterialDesignController::GetMode(); | ||||
124 | material_design_state_.reset( | ||||
125 | new test::MaterialDesignControllerTestAPI(material_mode)); | ||||
126 | |||||
[email protected] | 1b4c747 | 2014-05-15 18:32:23 | [diff] [blame] | 127 | ShellInitParams init_params; |
128 | init_params.delegate = test_shell_delegate_; | ||||
[email protected] | fa69f2b6 | 2014-05-22 21:47:58 | [diff] [blame] | 129 | init_params.context_factory = context_factory; |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 130 | init_params.blocking_pool = ash_test_environment_->GetBlockingPool(); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 131 | Shell::CreateInstance(init_params); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 132 | aura::test::EnvTestHelper(aura::Env::GetInstance()) |
133 | .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); | ||||
[email protected] | ccf28b8 | 2013-10-14 17:19:15 | [diff] [blame] | 134 | |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 135 | Shell* shell = Shell::GetInstance(); |
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 136 | if (start_session) { |
afakhry | 86c8884 | 2015-02-27 01:11:16 | [diff] [blame] | 137 | GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); |
138 | GetTestSessionStateDelegate()->SetHasActiveUser(true); | ||||
[email protected] | cf6fea2 | 2013-08-07 14:24:01 | [diff] [blame] | 139 | } |
[email protected] | ad2f5df | 2013-07-02 08:21:56 | [diff] [blame] | 140 | |
jamescook | f60d6ea | 2016-10-11 21:37:37 | [diff] [blame^] | 141 | #if defined(OS_CHROMEOS) |
142 | // Tests that change the display configuration generally don't care about the | ||||
143 | // notifications and the popup UI can interfere with things like cursors. | ||||
144 | shell->screen_layout_observer()->set_show_notifications_for_testing(false); | ||||
145 | #endif | ||||
146 | |||||
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 147 | test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) |
148 | .DisableChangeDisplayUponHostResize(); | ||||
stevenjb | f402ac5 | 2016-01-16 00:30:49 | [diff] [blame] | 149 | ShellTestApi(shell).DisableDisplayAnimator(); |
[email protected] | c7283444 | 2013-10-01 03:11:29 | [diff] [blame] | 150 | |
151 | test_screenshot_delegate_ = new TestScreenshotDelegate(); | ||||
sky | 44a0989 | 2016-07-20 17:46:58 | [diff] [blame] | 152 | shell->accelerator_controller_delegate()->SetScreenshotDelegate( |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 153 | std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 154 | } |
155 | |||||
156 | void AshTestHelper::TearDown() { | ||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 157 | // Tear down the shell. |
158 | Shell::DeleteInstance(); | ||||
mohsen | c66d687 | 2016-07-30 01:46:08 | [diff] [blame] | 159 | material_design_state_.reset(); |
varkha | b6a59711 | 2016-04-28 00:50:41 | [diff] [blame] | 160 | test::MaterialDesignControllerTestAPI::Uninitialize(); |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 161 | ash_test_environment_->TearDown(); |
ben | b91330f | 2015-10-03 22:20:18 | [diff] [blame] | 162 | |
[email protected] | c7283444 | 2013-10-01 03:11:29 | [diff] [blame] | 163 | test_screenshot_delegate_ = NULL; |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 164 | |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 165 | // Remove global message center state. |
166 | message_center::MessageCenter::Shutdown(); | ||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 167 | |
[email protected] | 6d8c8f0 | 2013-05-13 17:33:12 | [diff] [blame] | 168 | #if defined(OS_CHROMEOS) |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 169 | chromeos::CrasAudioHandler::Shutdown(); |
rkc | 06c92c0 | 2015-11-05 01:55:40 | [diff] [blame] | 170 | if (bluez_dbus_manager_initialized_) { |
sky | cf094f67 | 2016-09-01 19:40:12 | [diff] [blame] | 171 | device::BluetoothAdapterFactory::Shutdown(); |
rkc | 06c92c0 | 2015-11-05 01:55:40 | [diff] [blame] | 172 | bluez::BluezDBusManager::Shutdown(); |
173 | bluez_dbus_manager_initialized_ = false; | ||||
174 | } | ||||
[email protected] | f08f39b | 2013-12-19 06:14:11 | [diff] [blame] | 175 | if (dbus_thread_manager_initialized_) { |
176 | chromeos::DBusThreadManager::Shutdown(); | ||||
177 | dbus_thread_manager_initialized_ = false; | ||||
178 | } | ||||
[email protected] | 6d8c8f0 | 2013-05-13 17:33:12 | [diff] [blame] | 179 | #endif |
180 | |||||
[email protected] | f633394 | 2013-10-30 17:32:55 | [diff] [blame] | 181 | ui::TerminateContextFactoryForTests(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 182 | |
[email protected] | f7ff7ba | 2013-08-21 21:03:04 | [diff] [blame] | 183 | // Need to reset the initial login status. |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 184 | TestSystemTrayDelegate::SetInitialLoginStatus(LoginStatus::USER); |
jamescook | a1257f1 | 2016-06-12 07:02:25 | [diff] [blame] | 185 | TestSystemTrayDelegate::SetSystemUpdateRequired(false); |
[email protected] | f7ff7ba | 2013-08-21 21:03:04 | [diff] [blame] | 186 | |
[email protected] | 749bf643 | 2013-06-12 16:00:08 | [diff] [blame] | 187 | ui::ShutdownInputMethodForTesting(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 188 | zero_duration_mode_.reset(); |
[email protected] | 23a2dc8d | 2013-08-22 15:04:22 | [diff] [blame] | 189 | |
sky | 984c189 | 2016-04-20 00:00:34 | [diff] [blame] | 190 | CHECK(!::wm::ScopedCaptureClient::IsActive()); |
[email protected] | 96610354 | 2013-12-12 22:13:27 | [diff] [blame] | 191 | |
[email protected] | 93e828f | 2014-05-14 14:08:11 | [diff] [blame] | 192 | views_delegate_.reset(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 193 | } |
194 | |||||
195 | void AshTestHelper::RunAllPendingInMessageLoop() { | ||||
[email protected] | 42968f7 | 2014-02-05 20:58:23 | [diff] [blame] | 196 | base::RunLoop run_loop; |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 197 | run_loop.RunUntilIdle(); |
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 198 | } |
199 | |||||
afakhry | 86c8884 | 2015-02-27 01:11:16 | [diff] [blame] | 200 | // static |
201 | TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { | ||||
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 202 | CHECK(WmShell::HasInstance()); |
afakhry | 86c8884 | 2015-02-27 01:11:16 | [diff] [blame] | 203 | return static_cast<TestSessionStateDelegate*>( |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 204 | WmShell::Get()->GetSessionStateDelegate()); |
afakhry | 86c8884 | 2015-02-27 01:11:16 | [diff] [blame] | 205 | } |
206 | |||||
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 207 | aura::Window* AshTestHelper::CurrentContext() { |
208 | aura::Window* root_window = Shell::GetTargetRootWindow(); | ||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 209 | if (!root_window) |
210 | root_window = Shell::GetPrimaryRootWindow(); | ||||
211 | DCHECK(root_window); | ||||
212 | return root_window; | ||||
213 | } | ||||
214 | |||||
[email protected] | 3f4c26e | 2014-04-09 23:53:07 | [diff] [blame] | 215 | // static |
216 | bool AshTestHelper::SupportsMultipleDisplays() { | ||||
217 | #if defined(OS_WIN) | ||||
[email protected] | 45214559 | 2014-04-18 00:04:59 | [diff] [blame] | 218 | return false; |
[email protected] | 3f4c26e | 2014-04-09 23:53:07 | [diff] [blame] | 219 | #else |
220 | return true; | ||||
221 | #endif | ||||
222 | } | ||||
223 | |||||
[email protected] | 09464c7 | 2013-04-26 07:31:28 | [diff] [blame] | 224 | } // namespace test |
225 | } // namespace ash |