| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 13 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| 14 #include "content/browser/frame_host/navigation_entry_impl.h" | 14 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 15 #include "content/browser/loader/loader_globals.h" |
| 15 #include "content/browser/renderer_host/render_view_host_factory.h" | 16 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 17 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 17 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/browser_side_navigation_policy.h" | 21 #include "content/public/common/browser_side_navigation_policy.h" |
| 21 #include "content/public/test/browser_side_navigation_test_utils.h" | 22 #include "content/public/test/browser_side_navigation_test_utils.h" |
| 22 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
| 23 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
| 24 #include "content/test/content_browser_sanity_checker.h" | 25 #include "content/test/content_browser_sanity_checker.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 base::WrapUnique(new NoTransportImageTransportFactory)); | 135 base::WrapUnique(new NoTransportImageTransportFactory)); |
| 135 #else | 136 #else |
| 136 if (!screen_) | 137 if (!screen_) |
| 137 screen_.reset(ui::CreateDummyScreenAndroid()); | 138 screen_.reset(ui::CreateDummyScreenAndroid()); |
| 138 display::Screen::SetScreenInstance(screen_.get()); | 139 display::Screen::SetScreenInstance(screen_.get()); |
| 139 #endif | 140 #endif |
| 140 #if defined(OS_MACOSX) | 141 #if defined(OS_MACOSX) |
| 141 if (base::ThreadTaskRunnerHandle::IsSet()) | 142 if (base::ThreadTaskRunnerHandle::IsSet()) |
| 142 ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get()); | 143 ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get()); |
| 143 #endif // OS_MACOSX | 144 #endif // OS_MACOSX |
| 145 // TODO(ananta) |
| 146 // Tests which use the RenderViewHostTestEnabler can run |
| 147 // content/browser/loader code which assumes UI thread, IO thread task runner |
| 148 // availability. As a workaround we instantiate the |
| 149 // content/browser/loader/LoaderGlobals class which provides access to these |
| 150 // task runners to the relevant code. This hack will go away when the loader |
| 151 // code becomes part of the network service. We don't want to create the |
| 152 // LoaderGlobals class if it already exists. |
| 153 if (!LoaderGlobals::Get()) { |
| 154 loader_globals_.reset(new content::LoaderGlobals( |
| 155 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 156 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
| 157 } |
| 144 } | 158 } |
| 145 | 159 |
| 146 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { | 160 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { |
| 147 #if defined(OS_MACOSX) | 161 #if defined(OS_MACOSX) |
| 148 ui::WindowResizeHelperMac::Get()->ShutdownForTests(); | 162 ui::WindowResizeHelperMac::Get()->ShutdownForTests(); |
| 149 #endif // OS_MACOSX | 163 #endif // OS_MACOSX |
| 150 #if !defined(OS_ANDROID) | 164 #if !defined(OS_ANDROID) |
| 151 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it | 165 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it |
| 152 // must be shut down before the ImageTransportFactory. | 166 // must be shut down before the ImageTransportFactory. |
| 153 ImageTransportFactory::Terminate(); | 167 ImageTransportFactory::Terminate(); |
| 154 #else | 168 #else |
| 155 display::Screen::SetScreenInstance(nullptr); | 169 display::Screen::SetScreenInstance(nullptr); |
| 156 #endif | 170 #endif |
| 157 } | 171 } |
| 158 | 172 |
| 159 | 173 |
| 160 // RenderViewHostTestHarness -------------------------------------------------- | 174 // RenderViewHostTestHarness -------------------------------------------------- |
| 161 | |
| 162 RenderViewHostTestHarness::RenderViewHostTestHarness() | 175 RenderViewHostTestHarness::RenderViewHostTestHarness() |
| 163 : thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {} | 176 : thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {} |
| 164 | 177 |
| 165 RenderViewHostTestHarness::~RenderViewHostTestHarness() { | 178 RenderViewHostTestHarness::~RenderViewHostTestHarness() { |
| 166 } | 179 } |
| 167 | 180 |
| 168 NavigationController& RenderViewHostTestHarness::controller() { | 181 NavigationController& RenderViewHostTestHarness::controller() { |
| 169 return web_contents()->GetController(); | 182 return web_contents()->GetController(); |
| 170 } | 183 } |
| 171 | 184 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 290 |
| 278 sanity_checker_.reset(new ContentBrowserSanityChecker()); | 291 sanity_checker_.reset(new ContentBrowserSanityChecker()); |
| 279 | 292 |
| 280 DCHECK(!browser_context_); | 293 DCHECK(!browser_context_); |
| 281 browser_context_.reset(CreateBrowserContext()); | 294 browser_context_.reset(CreateBrowserContext()); |
| 282 | 295 |
| 283 SetContents(CreateTestWebContents()); | 296 SetContents(CreateTestWebContents()); |
| 284 | 297 |
| 285 if (IsBrowserSideNavigationEnabled()) | 298 if (IsBrowserSideNavigationEnabled()) |
| 286 BrowserSideNavigationSetUp(); | 299 BrowserSideNavigationSetUp(); |
| 300 |
| 301 // TODO(ananta) |
| 302 // Tests which use the RenderViewHostTestHarness can run |
| 303 // content/browser/loader code which assumes UI thread, IO thread task runner |
| 304 // availability. As a workaround we instantiate the |
| 305 // content/browser/loader/LoaderGlobals class which provides access to these |
| 306 // task runners to the relevant code. This hack will go away when the loader |
| 307 // code becomes part of the network service. We don't want to create the |
| 308 // LoaderGlobals class if it already exists. |
| 309 if (!LoaderGlobals::Get()) { |
| 310 loader_globals_.reset(new content::LoaderGlobals( |
| 311 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 312 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
| 313 } |
| 287 } | 314 } |
| 288 | 315 |
| 289 void RenderViewHostTestHarness::TearDown() { | 316 void RenderViewHostTestHarness::TearDown() { |
| 290 if (IsBrowserSideNavigationEnabled()) | 317 if (IsBrowserSideNavigationEnabled()) |
| 291 BrowserSideNavigationTearDown(); | 318 BrowserSideNavigationTearDown(); |
| 292 | 319 |
| 293 SetContents(NULL); | 320 SetContents(NULL); |
| 294 #if defined(USE_AURA) | 321 #if defined(USE_AURA) |
| 295 aura_test_helper_->TearDown(); | 322 aura_test_helper_->TearDown(); |
| 296 ui::TerminateContextFactoryForTests(); | 323 ui::TerminateContextFactoryForTests(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 325 | 352 |
| 326 void RenderViewHostTestHarness::SetRenderProcessHostFactory( | 353 void RenderViewHostTestHarness::SetRenderProcessHostFactory( |
| 327 RenderProcessHostFactory* factory) { | 354 RenderProcessHostFactory* factory) { |
| 328 if (rvh_test_enabler_) | 355 if (rvh_test_enabler_) |
| 329 rvh_test_enabler_->rvh_factory_->set_render_process_host_factory(factory); | 356 rvh_test_enabler_->rvh_factory_->set_render_process_host_factory(factory); |
| 330 else | 357 else |
| 331 factory_ = factory; | 358 factory_ = factory; |
| 332 } | 359 } |
| 333 | 360 |
| 334 } // namespace content | 361 } // namespace content |
| OLD | NEW |