Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: ash/test/ash_test_helper.cc

Issue 2303453003: Revert of Moves ash content specific tests into ash_content_unittests (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/test/ash_test_helper.h ('k') | ash/test/ash_test_helper_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
15 #include "ash/test/ash_test_views_delegate.h" 14 #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"
23 #include "ui/aura/env.h" 24 #include "ui/aura/env.h"
24 #include "ui/aura/input_state_lookup.h" 25 #include "ui/aura/input_state_lookup.h"
25 #include "ui/aura/test/env_test_helper.h" 26 #include "ui/aura/test/env_test_helper.h"
26 #include "ui/aura/test/event_generator_delegate_aura.h" 27 #include "ui/aura/test/event_generator_delegate_aura.h"
27 #include "ui/base/ime/input_method_initializer.h" 28 #include "ui/base/ime/input_method_initializer.h"
28 #include "ui/base/material_design/material_design_controller.h" 29 #include "ui/base/material_design/material_design_controller.h"
29 #include "ui/base/test/material_design_controller_test_api.h" 30 #include "ui/base/test/material_design_controller_test_api.h"
30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 31 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
31 #include "ui/compositor/test/context_factories_for_test.h" 32 #include "ui/compositor/test/context_factories_for_test.h"
32 #include "ui/display/manager/managed_display_info.h" 33 #include "ui/display/manager/managed_display_info.h"
33 #include "ui/message_center/message_center.h" 34 #include "ui/message_center/message_center.h"
34 #include "ui/wm/core/capture_controller.h" 35 #include "ui/wm/core/capture_controller.h"
35 #include "ui/wm/core/cursor_manager.h" 36 #include "ui/wm/core/cursor_manager.h"
36 37
37 #if defined(OS_CHROMEOS) 38 #if defined(OS_CHROMEOS)
38 #include "chromeos/audio/cras_audio_handler.h" 39 #include "chromeos/audio/cras_audio_handler.h"
39 #include "chromeos/dbus/dbus_thread_manager.h" 40 #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(AshTestEnvironment* ash_test_environment) 55 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop)
56 : ash_test_environment_(ash_test_environment), 56 : message_loop_(message_loop),
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_);
59 #if defined(OS_CHROMEOS) 62 #if defined(OS_CHROMEOS)
60 dbus_thread_manager_initialized_ = false; 63 dbus_thread_manager_initialized_ = false;
61 bluez_dbus_manager_initialized_ = false; 64 bluez_dbus_manager_initialized_ = false;
62 #endif 65 #endif
63 #if defined(USE_X11) 66 #if defined(USE_X11)
64 aura::test::SetUseOverrideRedirectWindowByDefault(true); 67 aura::test::SetUseOverrideRedirectWindowByDefault(true);
65 #endif 68 #endif
66 aura::test::InitializeAuraEventGeneratorDelegate(); 69 aura::test::InitializeAuraEventGeneratorDelegate();
67 } 70 }
68 71
69 AshTestHelper::~AshTestHelper() {} 72 AshTestHelper::~AshTestHelper() {}
70 73
71 void AshTestHelper::SetUp(bool start_session, 74 void AshTestHelper::SetUp(bool start_session,
72 MaterialDesignController::Mode material_mode) { 75 MaterialDesignController::Mode material_mode) {
73 display::ResetDisplayIdForTest(); 76 display::ResetDisplayIdForTest();
74 views_delegate_ = ash_test_environment_->CreateViewsDelegate(); 77 views_delegate_.reset(new AshTestViewsDelegate);
75 78
76 // Disable animations during tests. 79 // Disable animations during tests.
77 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 80 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
78 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 81 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
79 ui::InitializeInputMethodForTesting(); 82 ui::InitializeInputMethodForTesting();
80 83
81 bool enable_pixel_output = false; 84 bool enable_pixel_output = false;
82 ui::ContextFactory* context_factory = 85 ui::ContextFactory* context_factory =
83 ui::InitializeContextFactoryForTests(enable_pixel_output); 86 ui::InitializeContextFactoryForTests(enable_pixel_output);
84 87
(...skipping 17 matching lines...) Expand all
102 chromeos::DBusThreadManager::Get()->GetSystemBus(), 105 chromeos::DBusThreadManager::Get()->GetSystemBus(),
103 chromeos::DBusThreadManager::Get()->IsUsingStub( 106 chromeos::DBusThreadManager::Get()->IsUsingStub(
104 chromeos::DBusClientBundle::BLUETOOTH)); 107 chromeos::DBusClientBundle::BLUETOOTH));
105 bluez_dbus_manager_initialized_ = true; 108 bluez_dbus_manager_initialized_ = true;
106 } 109 }
107 110
108 // Create CrasAudioHandler for testing since g_browser_process is not 111 // Create CrasAudioHandler for testing since g_browser_process is not
109 // created in AshTestBase tests. 112 // created in AshTestBase tests.
110 chromeos::CrasAudioHandler::InitializeForTesting(); 113 chromeos::CrasAudioHandler::InitializeForTesting();
111 #endif 114 #endif
112 ash_test_environment_->SetUp(); 115 ShellContentState* content_state = content_state_;
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
113 // Reset the global state for the cursor manager. This includes the 122 // Reset the global state for the cursor manager. This includes the
114 // last cursor visibility state, etc. 123 // last cursor visibility state, etc.
115 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); 124 ::wm::CursorManager::ResetCursorVisibilityStateForTest();
116 125
117 // ContentTestSuiteBase might have already initialized 126 // ContentTestSuiteBase might have already initialized
118 // MaterialDesignController in unit_tests suite. 127 // MaterialDesignController in unit_tests suite.
119 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); 128 ui::test::MaterialDesignControllerTestAPI::Uninitialize();
120 ui::MaterialDesignController::Initialize(); 129 ui::MaterialDesignController::Initialize();
121 ash::MaterialDesignController::Initialize(); 130 ash::MaterialDesignController::Initialize();
122 if (material_mode == MaterialDesignController::Mode::UNINITIALIZED) 131 if (material_mode == MaterialDesignController::Mode::UNINITIALIZED)
123 material_mode = MaterialDesignController::GetMode(); 132 material_mode = MaterialDesignController::GetMode();
124 material_design_state_.reset( 133 material_design_state_.reset(
125 new test::MaterialDesignControllerTestAPI(material_mode)); 134 new test::MaterialDesignControllerTestAPI(material_mode));
126 135
127 ShellInitParams init_params; 136 ShellInitParams init_params;
128 init_params.delegate = test_shell_delegate_; 137 init_params.delegate = test_shell_delegate_;
129 init_params.context_factory = context_factory; 138 init_params.context_factory = context_factory;
130 init_params.blocking_pool = ash_test_environment_->GetBlockingPool(); 139 init_params.blocking_pool = content::BrowserThread::GetBlockingPool();
131 Shell::CreateInstance(init_params); 140 Shell::CreateInstance(init_params);
132 aura::test::EnvTestHelper(aura::Env::GetInstance()) 141 aura::test::EnvTestHelper(aura::Env::GetInstance())
133 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); 142 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>());
134 143
135 Shell* shell = Shell::GetInstance(); 144 Shell* shell = Shell::GetInstance();
136 if (start_session) { 145 if (start_session) {
137 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); 146 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true);
138 GetTestSessionStateDelegate()->SetHasActiveUser(true); 147 GetTestSessionStateDelegate()->SetHasActiveUser(true);
139 } 148 }
140 149
141 test::DisplayManagerTestApi().DisableChangeDisplayUponHostResize(); 150 test::DisplayManagerTestApi().DisableChangeDisplayUponHostResize();
142 ShellTestApi(shell).DisableDisplayAnimator(); 151 ShellTestApi(shell).DisableDisplayAnimator();
143 152
144 test_screenshot_delegate_ = new TestScreenshotDelegate(); 153 test_screenshot_delegate_ = new TestScreenshotDelegate();
145 shell->accelerator_controller_delegate()->SetScreenshotDelegate( 154 shell->accelerator_controller_delegate()->SetScreenshotDelegate(
146 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); 155 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_));
147 } 156 }
148 157
149 void AshTestHelper::TearDown() { 158 void AshTestHelper::TearDown() {
150 // Tear down the shell. 159 // Tear down the shell.
151 Shell::DeleteInstance(); 160 Shell::DeleteInstance();
152 material_design_state_.reset(); 161 material_design_state_.reset();
153 test::MaterialDesignControllerTestAPI::Uninitialize(); 162 test::MaterialDesignControllerTestAPI::Uninitialize();
154 ash_test_environment_->TearDown(); 163 ShellContentState::DestroyInstance();
155 164
156 test_screenshot_delegate_ = NULL; 165 test_screenshot_delegate_ = NULL;
157 166
158 // Remove global message center state. 167 // Remove global message center state.
159 message_center::MessageCenter::Shutdown(); 168 message_center::MessageCenter::Shutdown();
160 169
161 #if defined(OS_CHROMEOS) 170 #if defined(OS_CHROMEOS)
162 chromeos::CrasAudioHandler::Shutdown(); 171 chromeos::CrasAudioHandler::Shutdown();
163 if (bluez_dbus_manager_initialized_) { 172 if (bluez_dbus_manager_initialized_) {
164 device::BluetoothAdapterFactory::Shutdown();
165 bluez::BluezDBusManager::Shutdown(); 173 bluez::BluezDBusManager::Shutdown();
166 bluez_dbus_manager_initialized_ = false; 174 bluez_dbus_manager_initialized_ = false;
167 } 175 }
168 if (dbus_thread_manager_initialized_) { 176 if (dbus_thread_manager_initialized_) {
169 chromeos::DBusThreadManager::Shutdown(); 177 chromeos::DBusThreadManager::Shutdown();
170 dbus_thread_manager_initialized_ = false; 178 dbus_thread_manager_initialized_ = false;
171 } 179 }
172 #endif 180 #endif
173 181
174 ui::TerminateContextFactoryForTests(); 182 ui::TerminateContextFactoryForTests();
175 183
176 // Need to reset the initial login status. 184 // Need to reset the initial login status.
177 TestSystemTrayDelegate::SetInitialLoginStatus(LoginStatus::USER); 185 TestSystemTrayDelegate::SetInitialLoginStatus(LoginStatus::USER);
178 TestSystemTrayDelegate::SetSystemUpdateRequired(false); 186 TestSystemTrayDelegate::SetSystemUpdateRequired(false);
179 187
180 ui::ShutdownInputMethodForTesting(); 188 ui::ShutdownInputMethodForTesting();
181 zero_duration_mode_.reset(); 189 zero_duration_mode_.reset();
182 190
183 CHECK(!::wm::ScopedCaptureClient::IsActive()); 191 CHECK(!::wm::ScopedCaptureClient::IsActive());
184 192
185 views_delegate_.reset(); 193 views_delegate_.reset();
186 } 194 }
187 195
188 void AshTestHelper::RunAllPendingInMessageLoop() { 196 void AshTestHelper::RunAllPendingInMessageLoop() {
197 DCHECK(base::MessageLoopForUI::current() == message_loop_);
189 base::RunLoop run_loop; 198 base::RunLoop run_loop;
190 run_loop.RunUntilIdle(); 199 run_loop.RunUntilIdle();
191 } 200 }
192 201
193 // static 202 // static
194 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { 203 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() {
195 CHECK(WmShell::HasInstance()); 204 CHECK(WmShell::HasInstance());
196 return static_cast<TestSessionStateDelegate*>( 205 return static_cast<TestSessionStateDelegate*>(
197 WmShell::Get()->GetSessionStateDelegate()); 206 WmShell::Get()->GetSessionStateDelegate());
198 } 207 }
(...skipping 19 matching lines...) Expand all
218 bool AshTestHelper::SupportsHostWindowResize() { 227 bool AshTestHelper::SupportsHostWindowResize() {
219 #if defined(OS_WIN) 228 #if defined(OS_WIN)
220 return false; 229 return false;
221 #else 230 #else
222 return true; 231 return true;
223 #endif 232 #endif
224 } 233 }
225 234
226 } // namespace test 235 } // namespace test
227 } // namespace ash 236 } // namespace ash
OLDNEW
« no previous file with comments | « ash/test/ash_test_helper.h ('k') | ash/test/ash_test_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698