| 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 "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/browser/renderer_host/render_view_host_factory.h" | 8 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 10 #include "content/browser/renderer_host/test_render_view_host.h" | 10 #include "content/browser/renderer_host/test_render_view_host.h" |
| 11 #include "content/browser/site_instance_impl.h" | 11 #include "content/browser/site_instance_impl.h" |
| 12 #include "content/browser/web_contents/navigation_entry_impl.h" | 12 #include "content/browser/web_contents/navigation_entry_impl.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/mock_render_process_host.h" | 15 #include "content/public/test/mock_render_process_host.h" |
| 15 #include "content/public/test/test_browser_context.h" | 16 #include "content/public/test/test_browser_context.h" |
| 16 #include "content/test/test_render_view_host_factory.h" | 17 #include "content/test/test_render_view_host_factory.h" |
| 17 #include "content/test/test_web_contents.h" | 18 #include "content/test/test_web_contents.h" |
| 18 | 19 |
| 19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 20 #include "ui/base/win/scoped_ole_initializer.h" | 21 #include "ui/base/win/scoped_ole_initializer.h" |
| 21 #endif | 22 #endif |
| 22 | 23 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 : rph_factory_(new MockRenderProcessHostFactory()), | 66 : rph_factory_(new MockRenderProcessHostFactory()), |
| 66 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())) { | 67 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())) { |
| 67 } | 68 } |
| 68 | 69 |
| 69 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { | 70 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { |
| 70 } | 71 } |
| 71 | 72 |
| 72 | 73 |
| 73 // RenderViewHostTestHarness -------------------------------------------------- | 74 // RenderViewHostTestHarness -------------------------------------------------- |
| 74 | 75 |
| 75 RenderViewHostTestHarness::RenderViewHostTestHarness() : contents_(NULL) { | 76 RenderViewHostTestHarness::RenderViewHostTestHarness() |
| 77 : contents_(NULL), |
| 78 thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) { |
| 76 } | 79 } |
| 77 | 80 |
| 78 RenderViewHostTestHarness::~RenderViewHostTestHarness() { | 81 RenderViewHostTestHarness::~RenderViewHostTestHarness() { |
| 79 } | 82 } |
| 80 | 83 |
| 81 NavigationController& RenderViewHostTestHarness::controller() { | 84 NavigationController& RenderViewHostTestHarness::controller() { |
| 82 return web_contents()->GetController(); | 85 return web_contents()->GetController(); |
| 83 } | 86 } |
| 84 | 87 |
| 85 WebContents* RenderViewHostTestHarness::web_contents() { | 88 WebContents* RenderViewHostTestHarness::web_contents() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 151 |
| 149 void RenderViewHostTestHarness::FailedReload() { | 152 void RenderViewHostTestHarness::FailedReload() { |
| 150 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 153 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
| 151 DCHECK(entry); | 154 DCHECK(entry); |
| 152 controller().Reload(false); | 155 controller().Reload(false); |
| 153 static_cast<TestRenderViewHost*>( | 156 static_cast<TestRenderViewHost*>( |
| 154 rvh())->SendFailedNavigate(entry->GetPageID(), entry->GetURL()); | 157 rvh())->SendFailedNavigate(entry->GetPageID(), entry->GetURL()); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void RenderViewHostTestHarness::SetUp() { | 160 void RenderViewHostTestHarness::SetUp() { |
| 161 thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_)); |
| 162 |
| 158 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
| 159 ole_initializer_.reset(new ui::ScopedOleInitializer()); | 164 ole_initializer_.reset(new ui::ScopedOleInitializer()); |
| 160 #endif | 165 #endif |
| 161 #if defined(USE_AURA) | 166 #if defined(USE_AURA) |
| 162 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 167 aura_test_helper_.reset( |
| 168 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
| 163 aura_test_helper_->SetUp(); | 169 aura_test_helper_->SetUp(); |
| 164 #endif | 170 #endif |
| 165 SetContents(CreateTestWebContents()); | 171 SetContents(CreateTestWebContents()); |
| 166 } | 172 } |
| 167 | 173 |
| 168 void RenderViewHostTestHarness::TearDown() { | 174 void RenderViewHostTestHarness::TearDown() { |
| 169 SetContents(NULL); | 175 SetContents(NULL); |
| 170 #if defined(USE_AURA) | 176 #if defined(USE_AURA) |
| 171 aura_test_helper_->TearDown(); | 177 aura_test_helper_->TearDown(); |
| 172 #endif | 178 #endif |
| 173 // Make sure that we flush any messages related to WebContentsImpl destruction | 179 // Make sure that we flush any messages related to WebContentsImpl destruction |
| 174 // before we destroy the browser context. | 180 // before we destroy the browser context. |
| 175 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
| 176 | 182 |
| 183 #if defined(OS_WIN) |
| 184 ole_initializer_.reset(); |
| 185 #endif |
| 186 |
| 177 // Delete any RenderProcessHosts before the BrowserContext goes away. | 187 // Delete any RenderProcessHosts before the BrowserContext goes away. |
| 178 if (rvh_test_enabler_.rph_factory_) | 188 if (rvh_test_enabler_.rph_factory_) |
| 179 rvh_test_enabler_.rph_factory_.reset(); | 189 rvh_test_enabler_.rph_factory_.reset(); |
| 180 | 190 |
| 181 // Release the browser context on the UI thread. | 191 // Release the browser context by posting itself on the end of the task |
| 182 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 192 // queue. This is preferable to immediate deletion because it will behave |
| 183 base::RunLoop().RunUntilIdle(); | 193 // properly if the |rph_factory_| reset above enqueued any tasks which |
| 184 | 194 // depend on |browser_context_|. |
| 185 #if defined(OS_WIN) | 195 BrowserThread::DeleteSoon(content::BrowserThread::UI, |
| 186 ole_initializer_.reset(); | 196 FROM_HERE, |
| 187 #endif | 197 browser_context_.release()); |
| 198 thread_bundle_.reset(); |
| 188 } | 199 } |
| 189 | 200 |
| 190 void RenderViewHostTestHarness::SetRenderProcessHostFactory( | 201 void RenderViewHostTestHarness::SetRenderProcessHostFactory( |
| 191 RenderProcessHostFactory* factory) { | 202 RenderProcessHostFactory* factory) { |
| 192 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); | 203 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); |
| 193 } | 204 } |
| 194 | 205 |
| 195 } // namespace content | 206 } // namespace content |
| OLD | NEW |