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