OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/test/ash_test_helper.h" | 5 #include "ash/test/ash_test_helper.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller_delegate_aura.h" | 7 #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
9 #include "ash/common/test/material_design_controller_test_api.h" | 9 #include "ash/common/test/material_design_controller_test_api.h" |
10 #include "ash/common/test/test_session_state_delegate.h" | 10 #include "ash/common/test/test_session_state_delegate.h" |
11 #include "ash/common/test/test_system_tray_delegate.h" | 11 #include "ash/common/test/test_system_tray_delegate.h" |
12 #include "ash/common/test/wm_shell_test_api.h" | 12 #include "ash/common/test/wm_shell_test_api.h" |
13 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/shell_init_params.h" | 15 #include "ash/shell_init_params.h" |
16 #include "ash/system/chromeos/screen_layout_observer.h" | |
16 #include "ash/test/ash_test_environment.h" | 17 #include "ash/test/ash_test_environment.h" |
17 #include "ash/test/ash_test_views_delegate.h" | 18 #include "ash/test/ash_test_views_delegate.h" |
18 #include "ash/test/shell_test_api.h" | 19 #include "ash/test/shell_test_api.h" |
19 #include "ash/test/test_screenshot_delegate.h" | 20 #include "ash/test/test_screenshot_delegate.h" |
20 #include "ash/test/test_shell_delegate.h" | 21 #include "ash/test/test_shell_delegate.h" |
21 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
24 #include "chromeos/audio/cras_audio_handler.h" | |
25 #include "chromeos/dbus/dbus_thread_manager.h" | |
26 #include "device/bluetooth/bluetooth_adapter_factory.h" | |
27 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | |
23 #include "ui/aura/env.h" | 28 #include "ui/aura/env.h" |
24 #include "ui/aura/input_state_lookup.h" | 29 #include "ui/aura/input_state_lookup.h" |
25 #include "ui/aura/test/env_test_helper.h" | 30 #include "ui/aura/test/env_test_helper.h" |
26 #include "ui/aura/test/event_generator_delegate_aura.h" | 31 #include "ui/aura/test/event_generator_delegate_aura.h" |
27 #include "ui/base/ime/input_method_initializer.h" | 32 #include "ui/base/ime/input_method_initializer.h" |
28 #include "ui/base/material_design/material_design_controller.h" | 33 #include "ui/base/material_design/material_design_controller.h" |
29 #include "ui/base/test/material_design_controller_test_api.h" | 34 #include "ui/base/test/material_design_controller_test_api.h" |
30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 35 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
31 #include "ui/compositor/test/context_factories_for_test.h" | 36 #include "ui/compositor/test/context_factories_for_test.h" |
32 #include "ui/display/manager/managed_display_info.h" | 37 #include "ui/display/manager/managed_display_info.h" |
33 #include "ui/display/test/display_manager_test_api.h" | 38 #include "ui/display/test/display_manager_test_api.h" |
34 #include "ui/message_center/message_center.h" | 39 #include "ui/message_center/message_center.h" |
35 #include "ui/wm/core/capture_controller.h" | 40 #include "ui/wm/core/capture_controller.h" |
36 #include "ui/wm/core/cursor_manager.h" | 41 #include "ui/wm/core/cursor_manager.h" |
37 #include "ui/wm/core/wm_state.h" | 42 #include "ui/wm/core/wm_state.h" |
38 | 43 |
39 #if defined(OS_CHROMEOS) | |
40 #include "ash/system/chromeos/screen_layout_observer.h" | |
41 #include "chromeos/audio/cras_audio_handler.h" | |
42 #include "chromeos/dbus/dbus_thread_manager.h" | |
43 #include "device/bluetooth/bluetooth_adapter_factory.h" | |
44 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | |
45 #endif | |
46 | |
47 #if defined(OS_WIN) | |
48 #include "base/win/windows_version.h" | |
49 #endif | |
50 | |
51 #if defined(USE_X11) | 44 #if defined(USE_X11) |
52 #include "ui/aura/window_tree_host_x11.h" | 45 #include "ui/aura/window_tree_host_x11.h" |
53 #endif | 46 #endif |
54 | 47 |
55 namespace ash { | 48 namespace ash { |
56 namespace test { | 49 namespace test { |
57 | 50 |
58 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) | 51 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) |
59 : ash_test_environment_(ash_test_environment), | 52 : ash_test_environment_(ash_test_environment), |
60 test_shell_delegate_(nullptr), | 53 test_shell_delegate_(nullptr), |
61 test_screenshot_delegate_(nullptr) { | 54 test_screenshot_delegate_(nullptr), |
62 #if defined(OS_CHROMEOS) | 55 dbus_thread_manager_initialized_(false), |
63 dbus_thread_manager_initialized_ = false; | 56 bluez_dbus_manager_initialized_(false) { |
64 bluez_dbus_manager_initialized_ = false; | |
65 #endif | |
66 #if defined(USE_X11) | 57 #if defined(USE_X11) |
67 aura::test::SetUseOverrideRedirectWindowByDefault(true); | 58 aura::test::SetUseOverrideRedirectWindowByDefault(true); |
68 #endif | 59 #endif |
69 aura::test::InitializeAuraEventGeneratorDelegate(); | 60 aura::test::InitializeAuraEventGeneratorDelegate(); |
70 } | 61 } |
71 | 62 |
72 AshTestHelper::~AshTestHelper() {} | 63 AshTestHelper::~AshTestHelper() {} |
73 | 64 |
74 void AshTestHelper::SetUp(bool start_session, | 65 void AshTestHelper::SetUp(bool start_session, |
75 MaterialDesignController::Mode material_mode) { | 66 MaterialDesignController::Mode material_mode) { |
(...skipping 13 matching lines...) Expand all Loading... | |
89 &context_factory_private); | 80 &context_factory_private); |
90 | 81 |
91 // Creates Shell and hook with Desktop. | 82 // Creates Shell and hook with Desktop. |
92 if (!test_shell_delegate_) | 83 if (!test_shell_delegate_) |
93 test_shell_delegate_ = new TestShellDelegate; | 84 test_shell_delegate_ = new TestShellDelegate; |
94 | 85 |
95 // Creates MessageCenter since g_browser_process is not created in AshTestBase | 86 // Creates MessageCenter since g_browser_process is not created in AshTestBase |
96 // tests. | 87 // tests. |
97 message_center::MessageCenter::Initialize(); | 88 message_center::MessageCenter::Initialize(); |
98 | 89 |
99 #if defined(OS_CHROMEOS) | |
100 // Create DBusThreadManager for testing. | 90 // Create DBusThreadManager for testing. |
101 if (!chromeos::DBusThreadManager::IsInitialized()) { | 91 if (!chromeos::DBusThreadManager::IsInitialized()) { |
102 chromeos::DBusThreadManager::Initialize( | 92 chromeos::DBusThreadManager::Initialize( |
103 chromeos::DBusThreadManager::PROCESS_ASH); | 93 chromeos::DBusThreadManager::PROCESS_ASH); |
104 dbus_thread_manager_initialized_ = true; | 94 dbus_thread_manager_initialized_ = true; |
105 } | 95 } |
106 | 96 |
107 if (!bluez::BluezDBusManager::IsInitialized()) { | 97 if (!bluez::BluezDBusManager::IsInitialized()) { |
108 bluez::BluezDBusManager::Initialize( | 98 bluez::BluezDBusManager::Initialize( |
109 chromeos::DBusThreadManager::Get()->GetSystemBus(), | 99 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
110 chromeos::DBusThreadManager::Get()->IsUsingFakes()); | 100 chromeos::DBusThreadManager::Get()->IsUsingFakes()); |
111 bluez_dbus_manager_initialized_ = true; | 101 bluez_dbus_manager_initialized_ = true; |
112 } | 102 } |
113 | 103 |
114 // Create CrasAudioHandler for testing since g_browser_process is not | 104 // Create CrasAudioHandler for testing since g_browser_process is not |
115 // created in AshTestBase tests. | 105 // created in AshTestBase tests. |
116 chromeos::CrasAudioHandler::InitializeForTesting(); | 106 chromeos::CrasAudioHandler::InitializeForTesting(); |
117 #endif | 107 |
118 ash_test_environment_->SetUp(); | 108 ash_test_environment_->SetUp(); |
119 // Reset the global state for the cursor manager. This includes the | 109 // Reset the global state for the cursor manager. This includes the |
120 // last cursor visibility state, etc. | 110 // last cursor visibility state, etc. |
121 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); | 111 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); |
122 | 112 |
123 // ContentTestSuiteBase might have already initialized | 113 // ContentTestSuiteBase might have already initialized |
124 // MaterialDesignController in unit_tests suite. | 114 // MaterialDesignController in unit_tests suite. |
125 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | 115 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); |
126 ui::MaterialDesignController::Initialize(); | 116 ui::MaterialDesignController::Initialize(); |
127 ash::MaterialDesignController::Initialize(); | 117 ash::MaterialDesignController::Initialize(); |
(...skipping 10 matching lines...) Expand all Loading... | |
138 Shell::CreateInstance(init_params); | 128 Shell::CreateInstance(init_params); |
139 aura::test::EnvTestHelper(aura::Env::GetInstance()) | 129 aura::test::EnvTestHelper(aura::Env::GetInstance()) |
140 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); | 130 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); |
141 | 131 |
142 Shell* shell = Shell::GetInstance(); | 132 Shell* shell = Shell::GetInstance(); |
143 if (start_session) { | 133 if (start_session) { |
144 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); | 134 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); |
145 GetTestSessionStateDelegate()->SetHasActiveUser(true); | 135 GetTestSessionStateDelegate()->SetHasActiveUser(true); |
146 } | 136 } |
147 | 137 |
148 #if defined(OS_CHROMEOS) | |
149 // Tests that change the display configuration generally don't care about the | 138 // Tests that change the display configuration generally don't care about the |
150 // notifications and the popup UI can interfere with things like cursors. | 139 // notifications and the popup UI can interfere with things like cursors. |
151 shell->screen_layout_observer()->set_show_notifications_for_testing(false); | 140 shell->screen_layout_observer()->set_show_notifications_for_testing(false); |
152 #endif | |
153 | 141 |
154 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) | 142 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) |
155 .DisableChangeDisplayUponHostResize(); | 143 .DisableChangeDisplayUponHostResize(); |
156 ShellTestApi(shell).DisableDisplayAnimator(); | 144 ShellTestApi(shell).DisableDisplayAnimator(); |
157 | 145 |
158 test_screenshot_delegate_ = new TestScreenshotDelegate(); | 146 test_screenshot_delegate_ = new TestScreenshotDelegate(); |
159 shell->accelerator_controller_delegate()->SetScreenshotDelegate( | 147 shell->accelerator_controller_delegate()->SetScreenshotDelegate( |
160 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); | 148 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); |
161 } | 149 } |
162 | 150 |
163 void AshTestHelper::TearDown() { | 151 void AshTestHelper::TearDown() { |
164 // Tear down the shell. | 152 // Tear down the shell. |
165 Shell::DeleteInstance(); | 153 Shell::DeleteInstance(); |
166 | 154 |
167 // Suspend the tear down until all resources are returned via | 155 // Suspend the tear down until all resources are returned via |
168 // MojoCompositorFrameSinkClient::ReclaimResources() | 156 // MojoCompositorFrameSinkClient::ReclaimResources() |
169 RunAllPendingInMessageLoop(); | 157 RunAllPendingInMessageLoop(); |
170 material_design_state_.reset(); | 158 material_design_state_.reset(); |
171 test::MaterialDesignControllerTestAPI::Uninitialize(); | 159 test::MaterialDesignControllerTestAPI::Uninitialize(); |
172 ash_test_environment_->TearDown(); | 160 ash_test_environment_->TearDown(); |
173 | 161 |
174 test_screenshot_delegate_ = NULL; | 162 test_screenshot_delegate_ = NULL; |
175 | 163 |
176 // Remove global message center state. | 164 // Remove global message center state. |
177 message_center::MessageCenter::Shutdown(); | 165 message_center::MessageCenter::Shutdown(); |
178 | 166 |
179 #if defined(OS_CHROMEOS) | |
180 chromeos::CrasAudioHandler::Shutdown(); | 167 chromeos::CrasAudioHandler::Shutdown(); |
181 if (bluez_dbus_manager_initialized_) { | 168 if (bluez_dbus_manager_initialized_) { |
182 device::BluetoothAdapterFactory::Shutdown(); | 169 device::BluetoothAdapterFactory::Shutdown(); |
183 bluez::BluezDBusManager::Shutdown(); | 170 bluez::BluezDBusManager::Shutdown(); |
184 bluez_dbus_manager_initialized_ = false; | 171 bluez_dbus_manager_initialized_ = false; |
185 } | 172 } |
186 if (dbus_thread_manager_initialized_) { | 173 if (dbus_thread_manager_initialized_) { |
187 chromeos::DBusThreadManager::Shutdown(); | 174 chromeos::DBusThreadManager::Shutdown(); |
188 dbus_thread_manager_initialized_ = false; | 175 dbus_thread_manager_initialized_ = false; |
189 } | 176 } |
190 #endif | |
191 | 177 |
192 ui::TerminateContextFactoryForTests(); | 178 ui::TerminateContextFactoryForTests(); |
193 | 179 |
194 ui::ShutdownInputMethodForTesting(); | 180 ui::ShutdownInputMethodForTesting(); |
195 zero_duration_mode_.reset(); | 181 zero_duration_mode_.reset(); |
196 | 182 |
197 views_delegate_.reset(); | 183 views_delegate_.reset(); |
198 wm_state_.reset(); | 184 wm_state_.reset(); |
199 | 185 |
200 CHECK(!::wm::CaptureController::Get()); | 186 CHECK(!::wm::CaptureController::Get()); |
(...skipping 14 matching lines...) Expand all Loading... | |
215 aura::Window* AshTestHelper::CurrentContext() { | 201 aura::Window* AshTestHelper::CurrentContext() { |
216 aura::Window* root_window = Shell::GetTargetRootWindow(); | 202 aura::Window* root_window = Shell::GetTargetRootWindow(); |
217 if (!root_window) | 203 if (!root_window) |
218 root_window = Shell::GetPrimaryRootWindow(); | 204 root_window = Shell::GetPrimaryRootWindow(); |
219 DCHECK(root_window); | 205 DCHECK(root_window); |
220 return root_window; | 206 return root_window; |
221 } | 207 } |
222 | 208 |
223 // static | 209 // static |
224 bool AshTestHelper::SupportsMultipleDisplays() { | 210 bool AshTestHelper::SupportsMultipleDisplays() { |
225 #if defined(OS_WIN) | 211 // TODO(jamescook): Figure out if we want SupportsMultipleDisplays() to return |
226 return false; | 212 // false on mustash. If not, remove this function and the AshTestBase version |
227 #else | 213 // and remove calls from all the tests. For now just leave the ifdef strings |
214 // OS_CHROMEOS and OS_WIN in this comment as a reminder to clean up. | |
Evan Stade
2017/01/20 15:45:49
sneaky!
| |
215 // http://crbug.com/682990 | |
James Cook
2017/01/20 05:10:50
I didn't just rip this out because it's called in
| |
228 return true; | 216 return true; |
229 #endif | |
230 } | 217 } |
231 | 218 |
232 } // namespace test | 219 } // namespace test |
233 } // namespace ash | 220 } // namespace ash |
OLD | NEW |