OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/test_renderer_host.h" | 5 #include "content/public/test/test_renderer_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 RenderWidgetHostImpl::From(rvh->GetWidget()); | 122 RenderWidgetHostImpl::From(rvh->GetWidget()); |
123 return host_impl->has_touch_handler(); | 123 return host_impl->has_touch_handler(); |
124 } | 124 } |
125 | 125 |
126 | 126 |
127 // RenderViewHostTestEnabler -------------------------------------------------- | 127 // RenderViewHostTestEnabler -------------------------------------------------- |
128 | 128 |
129 RenderViewHostTestEnabler::RenderViewHostTestEnabler() | 129 RenderViewHostTestEnabler::RenderViewHostTestEnabler() |
130 : rph_factory_(new MockRenderProcessHostFactory()), | 130 : rph_factory_(new MockRenderProcessHostFactory()), |
131 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())), | 131 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())), |
132 rfh_factory_(new TestRenderFrameHostFactory()) {} | 132 rfh_factory_(new TestRenderFrameHostFactory()) { |
| 133 #if !defined(OS_ANDROID) |
| 134 ImageTransportFactory::InitializeForUnitTests( |
| 135 base::WrapUnique(new NoTransportImageTransportFactory)); |
| 136 #else |
| 137 gpu_channel_factory_ = base::MakeUnique<MockGpuChannelEstablishFactory>(); |
| 138 ContextProviderFactoryImpl::Initialize(gpu_channel_factory_.get()); |
| 139 ui::ContextProviderFactory::SetInstance( |
| 140 ContextProviderFactoryImpl::GetInstance()); |
| 141 if (!screen_) |
| 142 screen_.reset(ui::CreateDummyScreenAndroid()); |
| 143 display::Screen::SetScreenInstance(screen_.get()); |
| 144 #endif |
| 145 #if defined(OS_MACOSX) |
| 146 if (base::ThreadTaskRunnerHandle::IsSet()) |
| 147 ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get()); |
| 148 #endif // OS_MACOSX |
| 149 } |
133 | 150 |
134 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { | 151 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { |
| 152 #if defined(OS_MACOSX) |
| 153 ui::WindowResizeHelperMac::Get()->ShutdownForTests(); |
| 154 #endif // OS_MACOSX |
| 155 #if !defined(OS_ANDROID) |
| 156 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it |
| 157 // must be shut down before the ImageTransportFactory. |
| 158 ImageTransportFactory::Terminate(); |
| 159 #else |
| 160 display::Screen::SetScreenInstance(nullptr); |
| 161 ui::ContextProviderFactory::SetInstance(nullptr); |
| 162 ContextProviderFactoryImpl::Terminate(); |
| 163 gpu_channel_factory_.reset(); |
| 164 #endif |
135 } | 165 } |
136 | 166 |
137 | 167 |
138 // RenderViewHostTestHarness -------------------------------------------------- | 168 // RenderViewHostTestHarness -------------------------------------------------- |
139 | 169 |
140 RenderViewHostTestHarness::RenderViewHostTestHarness() | 170 RenderViewHostTestHarness::RenderViewHostTestHarness() |
141 : thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {} | 171 : thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {} |
142 | 172 |
143 RenderViewHostTestHarness::~RenderViewHostTestHarness() { | 173 RenderViewHostTestHarness::~RenderViewHostTestHarness() { |
144 } | 174 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 ->SendFailedNavigate(entry->GetUniqueID(), false, entry->GetURL()); | 257 ->SendFailedNavigate(entry->GetUniqueID(), false, entry->GetURL()); |
228 } | 258 } |
229 | 259 |
230 void RenderViewHostTestHarness::SetUp() { | 260 void RenderViewHostTestHarness::SetUp() { |
231 // ContentTestSuiteBase might have already initialized | 261 // ContentTestSuiteBase might have already initialized |
232 // MaterialDesignController in unit_tests suite. | 262 // MaterialDesignController in unit_tests suite. |
233 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | 263 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); |
234 ui::MaterialDesignController::Initialize(); | 264 ui::MaterialDesignController::Initialize(); |
235 thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_)); | 265 thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_)); |
236 | 266 |
| 267 rvh_test_enabler_.reset(new RenderViewHostTestEnabler); |
| 268 if (factory_) |
| 269 rvh_test_enabler_->rvh_factory_->set_render_process_host_factory(factory_); |
| 270 |
237 #if defined(OS_WIN) | 271 #if defined(OS_WIN) |
238 ole_initializer_.reset(new ui::ScopedOleInitializer()); | 272 ole_initializer_.reset(new ui::ScopedOleInitializer()); |
239 #endif | 273 #endif |
240 #if !defined(OS_ANDROID) | |
241 ImageTransportFactory::InitializeForUnitTests( | |
242 base::WrapUnique(new NoTransportImageTransportFactory)); | |
243 #else | |
244 gpu_channel_factory_ = base::MakeUnique<MockGpuChannelEstablishFactory>(); | |
245 ContextProviderFactoryImpl::Initialize(gpu_channel_factory_.get()); | |
246 ui::ContextProviderFactory::SetInstance( | |
247 ContextProviderFactoryImpl::GetInstance()); | |
248 if (!screen_) | |
249 screen_.reset(ui::CreateDummyScreenAndroid()); | |
250 display::Screen::SetScreenInstance(screen_.get()); | |
251 #endif | |
252 #if defined(USE_AURA) | 274 #if defined(USE_AURA) |
253 ui::ContextFactory* context_factory = | 275 ui::ContextFactory* context_factory = |
254 ImageTransportFactory::GetInstance()->GetContextFactory(); | 276 ImageTransportFactory::GetInstance()->GetContextFactory(); |
255 | 277 |
256 aura_test_helper_.reset( | 278 aura_test_helper_.reset( |
257 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 279 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
258 aura_test_helper_->SetUp(context_factory); | 280 aura_test_helper_->SetUp(context_factory); |
259 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 281 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
260 #endif | 282 #endif |
261 | 283 |
262 sanity_checker_.reset(new ContentBrowserSanityChecker()); | 284 sanity_checker_.reset(new ContentBrowserSanityChecker()); |
263 | 285 |
264 DCHECK(!browser_context_); | 286 DCHECK(!browser_context_); |
265 browser_context_.reset(CreateBrowserContext()); | 287 browser_context_.reset(CreateBrowserContext()); |
266 | 288 |
267 SetContents(CreateTestWebContents()); | 289 SetContents(CreateTestWebContents()); |
268 | 290 |
269 if (IsBrowserSideNavigationEnabled()) | 291 if (IsBrowserSideNavigationEnabled()) |
270 BrowserSideNavigationSetUp(); | 292 BrowserSideNavigationSetUp(); |
271 | |
272 #if defined(OS_MACOSX) | |
273 ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get()); | |
274 #endif // OS_MACOSX | |
275 } | 293 } |
276 | 294 |
277 void RenderViewHostTestHarness::TearDown() { | 295 void RenderViewHostTestHarness::TearDown() { |
278 if (IsBrowserSideNavigationEnabled()) | 296 if (IsBrowserSideNavigationEnabled()) |
279 BrowserSideNavigationTearDown(); | 297 BrowserSideNavigationTearDown(); |
280 | 298 |
281 SetContents(NULL); | 299 SetContents(NULL); |
282 #if defined(USE_AURA) | 300 #if defined(USE_AURA) |
283 aura_test_helper_->TearDown(); | 301 aura_test_helper_->TearDown(); |
284 ui::TerminateContextFactoryForTests(); | 302 ui::TerminateContextFactoryForTests(); |
285 #endif | 303 #endif |
286 // Make sure that we flush any messages related to WebContentsImpl destruction | 304 // Make sure that we flush any messages related to WebContentsImpl destruction |
287 // before we destroy the browser context. | 305 // before we destroy the browser context. |
288 base::RunLoop().RunUntilIdle(); | 306 base::RunLoop().RunUntilIdle(); |
289 | 307 |
290 #if defined(OS_MACOSX) | |
291 ui::WindowResizeHelperMac::Get()->ShutdownForTests(); | |
292 #endif // OS_MACOSX | |
293 | |
294 #if defined(OS_WIN) | 308 #if defined(OS_WIN) |
295 ole_initializer_.reset(); | 309 ole_initializer_.reset(); |
296 #endif | 310 #endif |
297 | 311 |
298 // Delete any RenderProcessHosts before the BrowserContext goes away. | 312 // Delete any RenderProcessHosts before the BrowserContext goes away. |
299 if (rvh_test_enabler_.rph_factory_) | 313 if (rvh_test_enabler_->rph_factory_) |
300 rvh_test_enabler_.rph_factory_.reset(); | 314 rvh_test_enabler_->rph_factory_.reset(); |
| 315 |
| 316 rvh_test_enabler_.reset(); |
301 | 317 |
302 // Release the browser context by posting itself on the end of the task | 318 // Release the browser context by posting itself on the end of the task |
303 // queue. This is preferable to immediate deletion because it will behave | 319 // queue. This is preferable to immediate deletion because it will behave |
304 // properly if the |rph_factory_| reset above enqueued any tasks which | 320 // properly if the |rph_factory_| reset above enqueued any tasks which |
305 // depend on |browser_context_|. | 321 // depend on |browser_context_|. |
306 BrowserThread::DeleteSoon(content::BrowserThread::UI, | 322 BrowserThread::DeleteSoon(content::BrowserThread::UI, |
307 FROM_HERE, | 323 FROM_HERE, |
308 browser_context_.release()); | 324 browser_context_.release()); |
309 thread_bundle_.reset(); | 325 thread_bundle_.reset(); |
310 | |
311 #if !defined(OS_ANDROID) | |
312 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it | |
313 // must be shut down before the ImageTransportFactory. | |
314 ImageTransportFactory::Terminate(); | |
315 #else | |
316 display::Screen::SetScreenInstance(nullptr); | |
317 ui::ContextProviderFactory::SetInstance(nullptr); | |
318 ContextProviderFactoryImpl::Terminate(); | |
319 gpu_channel_factory_.reset(); | |
320 #endif | |
321 } | 326 } |
322 | 327 |
323 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { | 328 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { |
324 return new TestBrowserContext(); | 329 return new TestBrowserContext(); |
325 } | 330 } |
326 | 331 |
327 void RenderViewHostTestHarness::SetRenderProcessHostFactory( | 332 void RenderViewHostTestHarness::SetRenderProcessHostFactory( |
328 RenderProcessHostFactory* factory) { | 333 RenderProcessHostFactory* factory) { |
329 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); | 334 if (rvh_test_enabler_) |
| 335 rvh_test_enabler_->rvh_factory_->set_render_process_host_factory(factory); |
| 336 else |
| 337 factory_ = factory; |
330 } | 338 } |
331 | 339 |
332 } // namespace content | 340 } // namespace content |
OLD | NEW |