| 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/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/test/material_design_controller_test_api.h" | 10 #include "ash/common/test/material_design_controller_test_api.h" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_init_params.h" | 13 #include "ash/shell_init_params.h" |
| 14 #include "ash/test/ash_test_environment.h" |
| 14 #include "ash/test/ash_test_views_delegate.h" | 15 #include "ash/test/ash_test_views_delegate.h" |
| 15 #include "ash/test/content/test_shell_content_state.h" | |
| 16 #include "ash/test/display_manager_test_api.h" | 16 #include "ash/test/display_manager_test_api.h" |
| 17 #include "ash/test/shell_test_api.h" | 17 #include "ash/test/shell_test_api.h" |
| 18 #include "ash/test/test_screenshot_delegate.h" | 18 #include "ash/test/test_screenshot_delegate.h" |
| 19 #include "ash/test/test_session_state_delegate.h" | 19 #include "ash/test/test_session_state_delegate.h" |
| 20 #include "ash/test/test_shell_delegate.h" | 20 #include "ash/test/test_shell_delegate.h" |
| 21 #include "ash/test/test_system_tray_delegate.h" | 21 #include "ash/test/test_system_tray_delegate.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "content/public/browser/browser_thread.h" | |
| 24 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 25 #include "ui/aura/input_state_lookup.h" | 24 #include "ui/aura/input_state_lookup.h" |
| 26 #include "ui/aura/test/env_test_helper.h" | 25 #include "ui/aura/test/env_test_helper.h" |
| 27 #include "ui/aura/test/event_generator_delegate_aura.h" | 26 #include "ui/aura/test/event_generator_delegate_aura.h" |
| 28 #include "ui/base/ime/input_method_initializer.h" | 27 #include "ui/base/ime/input_method_initializer.h" |
| 29 #include "ui/base/material_design/material_design_controller.h" | 28 #include "ui/base/material_design/material_design_controller.h" |
| 30 #include "ui/base/test/material_design_controller_test_api.h" | 29 #include "ui/base/test/material_design_controller_test_api.h" |
| 31 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 32 #include "ui/compositor/test/context_factories_for_test.h" | 31 #include "ui/compositor/test/context_factories_for_test.h" |
| 33 #include "ui/display/manager/managed_display_info.h" | 32 #include "ui/display/manager/managed_display_info.h" |
| 34 #include "ui/message_center/message_center.h" | 33 #include "ui/message_center/message_center.h" |
| 35 #include "ui/wm/core/capture_controller.h" | 34 #include "ui/wm/core/capture_controller.h" |
| 36 #include "ui/wm/core/cursor_manager.h" | 35 #include "ui/wm/core/cursor_manager.h" |
| 37 | 36 |
| 38 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
| 39 #include "chromeos/audio/cras_audio_handler.h" | 38 #include "chromeos/audio/cras_audio_handler.h" |
| 40 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
| 40 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 41 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 41 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 45 #include "base/win/windows_version.h" | 45 #include "base/win/windows_version.h" |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 #if defined(USE_X11) | 48 #if defined(USE_X11) |
| 49 #include "ui/aura/window_tree_host_x11.h" | 49 #include "ui/aura/window_tree_host_x11.h" |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 namespace ash { | 52 namespace ash { |
| 53 namespace test { | 53 namespace test { |
| 54 | 54 |
| 55 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) | 55 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) |
| 56 : message_loop_(message_loop), | 56 : ash_test_environment_(ash_test_environment), |
| 57 test_shell_delegate_(nullptr), | 57 test_shell_delegate_(nullptr), |
| 58 test_screenshot_delegate_(nullptr), | 58 test_screenshot_delegate_(nullptr) { |
| 59 content_state_(nullptr), | |
| 60 test_shell_content_state_(nullptr) { | |
| 61 CHECK(message_loop_); | |
| 62 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
| 63 dbus_thread_manager_initialized_ = false; | 60 dbus_thread_manager_initialized_ = false; |
| 64 bluez_dbus_manager_initialized_ = false; | 61 bluez_dbus_manager_initialized_ = false; |
| 65 #endif | 62 #endif |
| 66 #if defined(USE_X11) | 63 #if defined(USE_X11) |
| 67 aura::test::SetUseOverrideRedirectWindowByDefault(true); | 64 aura::test::SetUseOverrideRedirectWindowByDefault(true); |
| 68 #endif | 65 #endif |
| 69 aura::test::InitializeAuraEventGeneratorDelegate(); | 66 aura::test::InitializeAuraEventGeneratorDelegate(); |
| 70 } | 67 } |
| 71 | 68 |
| 72 AshTestHelper::~AshTestHelper() {} | 69 AshTestHelper::~AshTestHelper() {} |
| 73 | 70 |
| 74 void AshTestHelper::SetUp(bool start_session, | 71 void AshTestHelper::SetUp(bool start_session, |
| 75 MaterialDesignController::Mode material_mode) { | 72 MaterialDesignController::Mode material_mode) { |
| 76 display::ResetDisplayIdForTest(); | 73 display::ResetDisplayIdForTest(); |
| 77 views_delegate_.reset(new AshTestViewsDelegate); | 74 views_delegate_ = ash_test_environment_->CreateViewsDelegate(); |
| 78 | 75 |
| 79 // Disable animations during tests. | 76 // Disable animations during tests. |
| 80 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 77 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 81 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 78 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| 82 ui::InitializeInputMethodForTesting(); | 79 ui::InitializeInputMethodForTesting(); |
| 83 | 80 |
| 84 bool enable_pixel_output = false; | 81 bool enable_pixel_output = false; |
| 85 ui::ContextFactory* context_factory = | 82 ui::ContextFactory* context_factory = |
| 86 ui::InitializeContextFactoryForTests(enable_pixel_output); | 83 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 87 | 84 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 chromeos::DBusThreadManager::Get()->GetSystemBus(), | 102 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
| 106 chromeos::DBusThreadManager::Get()->IsUsingStub( | 103 chromeos::DBusThreadManager::Get()->IsUsingStub( |
| 107 chromeos::DBusClientBundle::BLUETOOTH)); | 104 chromeos::DBusClientBundle::BLUETOOTH)); |
| 108 bluez_dbus_manager_initialized_ = true; | 105 bluez_dbus_manager_initialized_ = true; |
| 109 } | 106 } |
| 110 | 107 |
| 111 // Create CrasAudioHandler for testing since g_browser_process is not | 108 // Create CrasAudioHandler for testing since g_browser_process is not |
| 112 // created in AshTestBase tests. | 109 // created in AshTestBase tests. |
| 113 chromeos::CrasAudioHandler::InitializeForTesting(); | 110 chromeos::CrasAudioHandler::InitializeForTesting(); |
| 114 #endif | 111 #endif |
| 115 ShellContentState* content_state = content_state_; | 112 ash_test_environment_->SetUp(); |
| 116 if (!content_state) { | |
| 117 test_shell_content_state_ = new TestShellContentState; | |
| 118 content_state = test_shell_content_state_; | |
| 119 } | |
| 120 ShellContentState::SetInstance(content_state); | |
| 121 | |
| 122 // Reset the global state for the cursor manager. This includes the | 113 // Reset the global state for the cursor manager. This includes the |
| 123 // last cursor visibility state, etc. | 114 // last cursor visibility state, etc. |
| 124 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); | 115 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); |
| 125 | 116 |
| 126 // ContentTestSuiteBase might have already initialized | 117 // ContentTestSuiteBase might have already initialized |
| 127 // MaterialDesignController in unit_tests suite. | 118 // MaterialDesignController in unit_tests suite. |
| 128 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | 119 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); |
| 129 ui::MaterialDesignController::Initialize(); | 120 ui::MaterialDesignController::Initialize(); |
| 130 ash::MaterialDesignController::Initialize(); | 121 ash::MaterialDesignController::Initialize(); |
| 131 if (material_mode == MaterialDesignController::Mode::UNINITIALIZED) | 122 if (material_mode == MaterialDesignController::Mode::UNINITIALIZED) |
| 132 material_mode = MaterialDesignController::GetMode(); | 123 material_mode = MaterialDesignController::GetMode(); |
| 133 material_design_state_.reset( | 124 material_design_state_.reset( |
| 134 new test::MaterialDesignControllerTestAPI(material_mode)); | 125 new test::MaterialDesignControllerTestAPI(material_mode)); |
| 135 | 126 |
| 136 ShellInitParams init_params; | 127 ShellInitParams init_params; |
| 137 init_params.delegate = test_shell_delegate_; | 128 init_params.delegate = test_shell_delegate_; |
| 138 init_params.context_factory = context_factory; | 129 init_params.context_factory = context_factory; |
| 139 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); | 130 init_params.blocking_pool = ash_test_environment_->GetBlockingPool(); |
| 140 Shell::CreateInstance(init_params); | 131 Shell::CreateInstance(init_params); |
| 141 aura::test::EnvTestHelper(aura::Env::GetInstance()) | 132 aura::test::EnvTestHelper(aura::Env::GetInstance()) |
| 142 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); | 133 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); |
| 143 | 134 |
| 144 Shell* shell = Shell::GetInstance(); | 135 Shell* shell = Shell::GetInstance(); |
| 145 if (start_session) { | 136 if (start_session) { |
| 146 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); | 137 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); |
| 147 GetTestSessionStateDelegate()->SetHasActiveUser(true); | 138 GetTestSessionStateDelegate()->SetHasActiveUser(true); |
| 148 } | 139 } |
| 149 | 140 |
| 150 test::DisplayManagerTestApi().DisableChangeDisplayUponHostResize(); | 141 test::DisplayManagerTestApi().DisableChangeDisplayUponHostResize(); |
| 151 ShellTestApi(shell).DisableDisplayAnimator(); | 142 ShellTestApi(shell).DisableDisplayAnimator(); |
| 152 | 143 |
| 153 test_screenshot_delegate_ = new TestScreenshotDelegate(); | 144 test_screenshot_delegate_ = new TestScreenshotDelegate(); |
| 154 shell->accelerator_controller_delegate()->SetScreenshotDelegate( | 145 shell->accelerator_controller_delegate()->SetScreenshotDelegate( |
| 155 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); | 146 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); |
| 156 } | 147 } |
| 157 | 148 |
| 158 void AshTestHelper::TearDown() { | 149 void AshTestHelper::TearDown() { |
| 159 // Tear down the shell. | 150 // Tear down the shell. |
| 160 Shell::DeleteInstance(); | 151 Shell::DeleteInstance(); |
| 161 material_design_state_.reset(); | 152 material_design_state_.reset(); |
| 162 test::MaterialDesignControllerTestAPI::Uninitialize(); | 153 test::MaterialDesignControllerTestAPI::Uninitialize(); |
| 163 ShellContentState::DestroyInstance(); | 154 ash_test_environment_->TearDown(); |
| 164 | 155 |
| 165 test_screenshot_delegate_ = NULL; | 156 test_screenshot_delegate_ = NULL; |
| 166 | 157 |
| 167 // Remove global message center state. | 158 // Remove global message center state. |
| 168 message_center::MessageCenter::Shutdown(); | 159 message_center::MessageCenter::Shutdown(); |
| 169 | 160 |
| 170 #if defined(OS_CHROMEOS) | 161 #if defined(OS_CHROMEOS) |
| 171 chromeos::CrasAudioHandler::Shutdown(); | 162 chromeos::CrasAudioHandler::Shutdown(); |
| 172 if (bluez_dbus_manager_initialized_) { | 163 if (bluez_dbus_manager_initialized_) { |
| 164 device::BluetoothAdapterFactory::Shutdown(); |
| 173 bluez::BluezDBusManager::Shutdown(); | 165 bluez::BluezDBusManager::Shutdown(); |
| 174 bluez_dbus_manager_initialized_ = false; | 166 bluez_dbus_manager_initialized_ = false; |
| 175 } | 167 } |
| 176 if (dbus_thread_manager_initialized_) { | 168 if (dbus_thread_manager_initialized_) { |
| 177 chromeos::DBusThreadManager::Shutdown(); | 169 chromeos::DBusThreadManager::Shutdown(); |
| 178 dbus_thread_manager_initialized_ = false; | 170 dbus_thread_manager_initialized_ = false; |
| 179 } | 171 } |
| 180 #endif | 172 #endif |
| 181 | 173 |
| 182 ui::TerminateContextFactoryForTests(); | 174 ui::TerminateContextFactoryForTests(); |
| 183 | 175 |
| 184 // Need to reset the initial login status. | 176 // Need to reset the initial login status. |
| 185 TestSystemTrayDelegate::SetInitialLoginStatus(LoginStatus::USER); | 177 TestSystemTrayDelegate::SetInitialLoginStatus(LoginStatus::USER); |
| 186 TestSystemTrayDelegate::SetSystemUpdateRequired(false); | 178 TestSystemTrayDelegate::SetSystemUpdateRequired(false); |
| 187 | 179 |
| 188 ui::ShutdownInputMethodForTesting(); | 180 ui::ShutdownInputMethodForTesting(); |
| 189 zero_duration_mode_.reset(); | 181 zero_duration_mode_.reset(); |
| 190 | 182 |
| 191 CHECK(!::wm::ScopedCaptureClient::IsActive()); | 183 CHECK(!::wm::ScopedCaptureClient::IsActive()); |
| 192 | 184 |
| 193 views_delegate_.reset(); | 185 views_delegate_.reset(); |
| 194 } | 186 } |
| 195 | 187 |
| 196 void AshTestHelper::RunAllPendingInMessageLoop() { | 188 void AshTestHelper::RunAllPendingInMessageLoop() { |
| 197 DCHECK(base::MessageLoopForUI::current() == message_loop_); | |
| 198 base::RunLoop run_loop; | 189 base::RunLoop run_loop; |
| 199 run_loop.RunUntilIdle(); | 190 run_loop.RunUntilIdle(); |
| 200 } | 191 } |
| 201 | 192 |
| 202 // static | 193 // static |
| 203 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { | 194 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { |
| 204 CHECK(WmShell::HasInstance()); | 195 CHECK(WmShell::HasInstance()); |
| 205 return static_cast<TestSessionStateDelegate*>( | 196 return static_cast<TestSessionStateDelegate*>( |
| 206 WmShell::Get()->GetSessionStateDelegate()); | 197 WmShell::Get()->GetSessionStateDelegate()); |
| 207 } | 198 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 bool AshTestHelper::SupportsHostWindowResize() { | 218 bool AshTestHelper::SupportsHostWindowResize() { |
| 228 #if defined(OS_WIN) | 219 #if defined(OS_WIN) |
| 229 return false; | 220 return false; |
| 230 #else | 221 #else |
| 231 return true; | 222 return true; |
| 232 #endif | 223 #endif |
| 233 } | 224 } |
| 234 | 225 |
| 235 } // namespace test | 226 } // namespace test |
| 236 } // namespace ash | 227 } // namespace ash |
| OLD | NEW |