| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 133 |
| 134 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { | 134 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { |
| 135 } | 135 } |
| 136 | 136 |
| 137 void RenderViewHostTestEnabler::SetUp() { |
| 138 #if !defined(OS_ANDROID) |
| 139 ImageTransportFactory::InitializeForUnitTests( |
| 140 base::WrapUnique(new NoTransportImageTransportFactory)); |
| 141 #else |
| 142 gpu_channel_factory_ = base::MakeUnique<MockGpuChannelEstablishFactory>(); |
| 143 ContextProviderFactoryImpl::Initialize(gpu_channel_factory_.get()); |
| 144 ui::ContextProviderFactory::SetInstance( |
| 145 ContextProviderFactoryImpl::GetInstance()); |
| 146 if (!screen_) |
| 147 screen_.reset(ui::CreateDummyScreenAndroid()); |
| 148 display::Screen::SetScreenInstance(screen_.get()); |
| 149 #endif |
| 150 } |
| 151 |
| 152 void RenderViewHostTestEnabler::TearDown() { |
| 153 #if !defined(OS_ANDROID) |
| 154 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it |
| 155 // must be shut down before the ImageTransportFactory. |
| 156 ImageTransportFactory::Terminate(); |
| 157 #else |
| 158 display::Screen::SetScreenInstance(nullptr); |
| 159 ui::ContextProviderFactory::SetInstance(nullptr); |
| 160 ContextProviderFactoryImpl::Terminate(); |
| 161 gpu_channel_factory_.reset(); |
| 162 #endif |
| 163 } |
| 164 |
| 137 | 165 |
| 138 // RenderViewHostTestHarness -------------------------------------------------- | 166 // RenderViewHostTestHarness -------------------------------------------------- |
| 139 | 167 |
| 140 RenderViewHostTestHarness::RenderViewHostTestHarness() | 168 RenderViewHostTestHarness::RenderViewHostTestHarness() |
| 141 : thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {} | 169 : thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {} |
| 142 | 170 |
| 143 RenderViewHostTestHarness::~RenderViewHostTestHarness() { | 171 RenderViewHostTestHarness::~RenderViewHostTestHarness() { |
| 144 } | 172 } |
| 145 | 173 |
| 146 NavigationController& RenderViewHostTestHarness::controller() { | 174 NavigationController& RenderViewHostTestHarness::controller() { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void RenderViewHostTestHarness::SetUp() { | 258 void RenderViewHostTestHarness::SetUp() { |
| 231 // ContentTestSuiteBase might have already initialized | 259 // ContentTestSuiteBase might have already initialized |
| 232 // MaterialDesignController in unit_tests suite. | 260 // MaterialDesignController in unit_tests suite. |
| 233 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | 261 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); |
| 234 ui::MaterialDesignController::Initialize(); | 262 ui::MaterialDesignController::Initialize(); |
| 235 thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_)); | 263 thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_)); |
| 236 | 264 |
| 237 #if defined(OS_WIN) | 265 #if defined(OS_WIN) |
| 238 ole_initializer_.reset(new ui::ScopedOleInitializer()); | 266 ole_initializer_.reset(new ui::ScopedOleInitializer()); |
| 239 #endif | 267 #endif |
| 240 #if !defined(OS_ANDROID) | 268 |
| 241 ImageTransportFactory::InitializeForUnitTests( | 269 rvh_test_enabler_.SetUp(); |
| 242 base::WrapUnique(new NoTransportImageTransportFactory)); | 270 |
| 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) | 271 #if defined(USE_AURA) |
| 253 ui::ContextFactory* context_factory = | 272 ui::ContextFactory* context_factory = |
| 254 ImageTransportFactory::GetInstance()->GetContextFactory(); | 273 ImageTransportFactory::GetInstance()->GetContextFactory(); |
| 255 | 274 |
| 256 aura_test_helper_.reset( | 275 aura_test_helper_.reset( |
| 257 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 276 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
| 258 aura_test_helper_->SetUp(context_factory); | 277 aura_test_helper_->SetUp(context_factory); |
| 259 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 278 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
| 260 #endif | 279 #endif |
| 261 | 280 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 320 |
| 302 // Release the browser context by posting itself on the end of the task | 321 // 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 | 322 // queue. This is preferable to immediate deletion because it will behave |
| 304 // properly if the |rph_factory_| reset above enqueued any tasks which | 323 // properly if the |rph_factory_| reset above enqueued any tasks which |
| 305 // depend on |browser_context_|. | 324 // depend on |browser_context_|. |
| 306 BrowserThread::DeleteSoon(content::BrowserThread::UI, | 325 BrowserThread::DeleteSoon(content::BrowserThread::UI, |
| 307 FROM_HERE, | 326 FROM_HERE, |
| 308 browser_context_.release()); | 327 browser_context_.release()); |
| 309 thread_bundle_.reset(); | 328 thread_bundle_.reset(); |
| 310 | 329 |
| 311 #if !defined(OS_ANDROID) | 330 rvh_test_enabler_.TearDown(); |
| 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 } | 331 } |
| 322 | 332 |
| 323 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { | 333 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { |
| 324 return new TestBrowserContext(); | 334 return new TestBrowserContext(); |
| 325 } | 335 } |
| 326 | 336 |
| 327 void RenderViewHostTestHarness::SetRenderProcessHostFactory( | 337 void RenderViewHostTestHarness::SetRenderProcessHostFactory( |
| 328 RenderProcessHostFactory* factory) { | 338 RenderProcessHostFactory* factory) { |
| 329 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); | 339 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); |
| 330 } | 340 } |
| 331 | 341 |
| 332 } // namespace content | 342 } // namespace content |
| OLD | NEW |