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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 : rph_factory_(new MockRenderProcessHostFactory()), | 65 : rph_factory_(new MockRenderProcessHostFactory()), |
66 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())) { | 66 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())) { |
67 } | 67 } |
68 | 68 |
69 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { | 69 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { |
70 } | 70 } |
71 | 71 |
72 | 72 |
73 // RenderViewHostTestHarness -------------------------------------------------- | 73 // RenderViewHostTestHarness -------------------------------------------------- |
74 | 74 |
75 RenderViewHostTestHarness::RenderViewHostTestHarness() : contents_(NULL) { | 75 RenderViewHostTestHarness::RenderViewHostTestHarness() |
| 76 : contents_(NULL), |
| 77 real_threads_mask_(TestBrowserThreadBundle::NO_REAL_THREAD) { |
76 } | 78 } |
77 | 79 |
78 RenderViewHostTestHarness::~RenderViewHostTestHarness() { | 80 RenderViewHostTestHarness::~RenderViewHostTestHarness() { |
79 } | 81 } |
80 | 82 |
81 NavigationController& RenderViewHostTestHarness::controller() { | 83 NavigationController& RenderViewHostTestHarness::controller() { |
82 return web_contents()->GetController(); | 84 return web_contents()->GetController(); |
83 } | 85 } |
84 | 86 |
85 WebContents* RenderViewHostTestHarness::web_contents() { | 87 WebContents* RenderViewHostTestHarness::web_contents() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 150 |
149 void RenderViewHostTestHarness::FailedReload() { | 151 void RenderViewHostTestHarness::FailedReload() { |
150 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 152 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
151 DCHECK(entry); | 153 DCHECK(entry); |
152 controller().Reload(false); | 154 controller().Reload(false); |
153 static_cast<TestRenderViewHost*>( | 155 static_cast<TestRenderViewHost*>( |
154 rvh())->SendFailedNavigate(entry->GetPageID(), entry->GetURL()); | 156 rvh())->SendFailedNavigate(entry->GetPageID(), entry->GetURL()); |
155 } | 157 } |
156 | 158 |
157 void RenderViewHostTestHarness::SetUp() { | 159 void RenderViewHostTestHarness::SetUp() { |
| 160 thread_bundle_.reset(new TestBrowserThreadBundle(real_threads_mask_)); |
| 161 |
158 #if defined(OS_WIN) | 162 #if defined(OS_WIN) |
159 ole_initializer_.reset(new ui::ScopedOleInitializer()); | 163 ole_initializer_.reset(new ui::ScopedOleInitializer()); |
160 #endif | 164 #endif |
161 #if defined(USE_AURA) | 165 #if defined(USE_AURA) |
162 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 166 aura_test_helper_.reset( |
| 167 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
163 aura_test_helper_->SetUp(); | 168 aura_test_helper_->SetUp(); |
164 #endif | 169 #endif |
165 SetContents(CreateTestWebContents()); | 170 SetContents(CreateTestWebContents()); |
166 } | 171 } |
167 | 172 |
168 void RenderViewHostTestHarness::TearDown() { | 173 void RenderViewHostTestHarness::TearDown() { |
169 SetContents(NULL); | 174 SetContents(NULL); |
170 #if defined(USE_AURA) | 175 #if defined(USE_AURA) |
171 aura_test_helper_->TearDown(); | 176 aura_test_helper_->TearDown(); |
172 #endif | 177 #endif |
173 // Make sure that we flush any messages related to WebContentsImpl destruction | 178 // Make sure that we flush any messages related to WebContentsImpl destruction |
174 // before we destroy the browser context. | 179 // before we destroy the browser context. |
175 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
176 | 181 |
177 // Delete any RenderProcessHosts before the BrowserContext goes away. | 182 // Delete any RenderProcessHosts before the BrowserContext goes away. |
178 if (rvh_test_enabler_.rph_factory_) | 183 if (rvh_test_enabler_.rph_factory_) |
179 rvh_test_enabler_.rph_factory_.reset(); | 184 rvh_test_enabler_.rph_factory_.reset(); |
180 | 185 |
181 // Release the browser context on the UI thread. | 186 // Release the browser context by posting itself on the end of the task |
182 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 187 // queue. This is preferable to immediate deletion because it will behave |
| 188 // properly if the |rph_factory_| reset above enqueued any tasks which |
| 189 // depend on |browser_context_|. |
| 190 BrowserThread::DeleteSoon(content::BrowserThread::UI, |
| 191 FROM_HERE, |
| 192 browser_context_.release()); |
183 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
184 | 194 |
185 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
186 ole_initializer_.reset(); | 196 ole_initializer_.reset(); |
187 #endif | 197 #endif |
| 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 |