OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/browser_url_handler.h" | 5 #include "chrome/browser/browser_url_handler.h" |
6 #include "chrome/test/testing_profile.h" | 6 #include "chrome/test/testing_profile.h" |
7 #include "content/browser/renderer_host/test_backing_store.h" | 7 #include "content/browser/renderer_host/test_backing_store.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance.h" | 9 #include "content/browser/site_instance.h" |
10 #include "content/browser/tab_contents/navigation_controller.h" | 10 #include "content/browser/tab_contents/navigation_controller.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 return profile_.get(); | 305 return profile_.get(); |
306 } | 306 } |
307 | 307 |
308 MockRenderProcessHost* RenderViewHostTestHarness::process() { | 308 MockRenderProcessHost* RenderViewHostTestHarness::process() { |
309 if (pending_rvh()) | 309 if (pending_rvh()) |
310 return static_cast<MockRenderProcessHost*>(pending_rvh()->process()); | 310 return static_cast<MockRenderProcessHost*>(pending_rvh()->process()); |
311 return static_cast<MockRenderProcessHost*>(rvh()->process()); | 311 return static_cast<MockRenderProcessHost*>(rvh()->process()); |
312 } | 312 } |
313 | 313 |
314 void RenderViewHostTestHarness::DeleteContents() { | 314 void RenderViewHostTestHarness::DeleteContents() { |
315 contents_.reset(); | 315 SetContents(NULL); |
| 316 } |
| 317 |
| 318 void RenderViewHostTestHarness::SetContents(TestTabContents* contents) { |
| 319 contents_.reset(contents); |
316 } | 320 } |
317 | 321 |
318 TestTabContents* RenderViewHostTestHarness::CreateTestTabContents() { | 322 TestTabContents* RenderViewHostTestHarness::CreateTestTabContents() { |
319 // See comment above profile_ decl for why we check for NULL here. | 323 // See comment above profile_ decl for why we check for NULL here. |
320 if (!profile_.get()) | 324 if (!profile_.get()) |
321 profile_.reset(new TestingProfile()); | 325 profile_.reset(new TestingProfile()); |
322 | 326 |
323 // This will be deleted when the TabContents goes away. | 327 // This will be deleted when the TabContents goes away. |
324 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); | 328 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); |
325 | 329 |
326 return new TestTabContents(profile_.get(), instance); | 330 return new TestTabContents(profile_.get(), instance); |
327 } | 331 } |
328 | 332 |
329 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { | 333 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { |
330 contents()->NavigateAndCommit(url); | 334 contents()->NavigateAndCommit(url); |
331 } | 335 } |
332 | 336 |
333 void RenderViewHostTestHarness::Reload() { | 337 void RenderViewHostTestHarness::Reload() { |
334 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 338 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
335 DCHECK(entry); | 339 DCHECK(entry); |
336 controller().Reload(false); | 340 controller().Reload(false); |
337 rvh()->SendNavigate(entry->page_id(), entry->url()); | 341 rvh()->SendNavigate(entry->page_id(), entry->url()); |
338 } | 342 } |
339 | 343 |
340 void RenderViewHostTestHarness::SetUp() { | 344 void RenderViewHostTestHarness::SetUp() { |
341 contents_.reset(CreateTestTabContents()); | 345 SetContents(CreateTestTabContents()); |
342 } | 346 } |
343 | 347 |
344 void RenderViewHostTestHarness::TearDown() { | 348 void RenderViewHostTestHarness::TearDown() { |
345 contents_.reset(); | 349 SetContents(NULL); |
346 | 350 |
347 // Make sure that we flush any messages related to TabContents destruction | 351 // Make sure that we flush any messages related to TabContents destruction |
348 // before we destroy the profile. | 352 // before we destroy the profile. |
349 MessageLoop::current()->RunAllPending(); | 353 MessageLoop::current()->RunAllPending(); |
350 | 354 |
351 // Release the profile on the UI thread. | 355 // Release the profile on the UI thread. |
352 message_loop_.DeleteSoon(FROM_HERE, profile_.release()); | 356 message_loop_.DeleteSoon(FROM_HERE, profile_.release()); |
353 message_loop_.RunAllPending(); | 357 message_loop_.RunAllPending(); |
354 } | 358 } |
OLD | NEW |