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/test/base/testing_profile.h" | |
6 #include "content/browser/browser_url_handler.h" | 5 #include "content/browser/browser_url_handler.h" |
7 #include "content/browser/renderer_host/test_backing_store.h" | 6 #include "content/browser/renderer_host/test_backing_store.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance.h" | 8 #include "content/browser/site_instance.h" |
10 #include "content/browser/tab_contents/navigation_controller.h" | 9 #include "content/browser/tab_contents/navigation_controller.h" |
11 #include "content/browser/tab_contents/test_tab_contents.h" | 10 #include "content/browser/tab_contents/test_tab_contents.h" |
12 #include "content/common/content_client.h" | 11 #include "content/common/content_client.h" |
13 #include "content/common/dom_storage_common.h" | 12 #include "content/common/dom_storage_common.h" |
14 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/test/test_browser_context.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
16 #include "webkit/glue/webkit_glue.h" | 16 #include "webkit/glue/webkit_glue.h" |
17 #include "webkit/glue/webpreferences.h" | 17 #include "webkit/glue/webpreferences.h" |
18 #include "webkit/glue/password_form.h" | 18 #include "webkit/glue/password_form.h" |
19 | 19 |
20 using webkit_glue::PasswordForm; | 20 using webkit_glue::PasswordForm; |
21 | 21 |
22 void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, | 22 void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, |
23 int page_id, | 23 int page_id, |
24 const GURL& url, | 24 const GURL& url, |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 TestRenderViewHost* RenderViewHostTestHarness::pending_rvh() { | 301 TestRenderViewHost* RenderViewHostTestHarness::pending_rvh() { |
302 return static_cast<TestRenderViewHost*>( | 302 return static_cast<TestRenderViewHost*>( |
303 contents()->render_manager()->pending_render_view_host()); | 303 contents()->render_manager()->pending_render_view_host()); |
304 } | 304 } |
305 | 305 |
306 TestRenderViewHost* RenderViewHostTestHarness::active_rvh() { | 306 TestRenderViewHost* RenderViewHostTestHarness::active_rvh() { |
307 return pending_rvh() ? pending_rvh() : rvh(); | 307 return pending_rvh() ? pending_rvh() : rvh(); |
308 } | 308 } |
309 | 309 |
310 TestingProfile* RenderViewHostTestHarness::profile() { | 310 content::BrowserContext* RenderViewHostTestHarness::browser_context() { |
311 return profile_.get(); | 311 return browser_context_.get(); |
312 } | 312 } |
313 | 313 |
314 MockRenderProcessHost* RenderViewHostTestHarness::process() { | 314 MockRenderProcessHost* RenderViewHostTestHarness::process() { |
315 if (pending_rvh()) | 315 if (pending_rvh()) |
316 return static_cast<MockRenderProcessHost*>(pending_rvh()->process()); | 316 return static_cast<MockRenderProcessHost*>(pending_rvh()->process()); |
317 return static_cast<MockRenderProcessHost*>(rvh()->process()); | 317 return static_cast<MockRenderProcessHost*>(rvh()->process()); |
318 } | 318 } |
319 | 319 |
320 void RenderViewHostTestHarness::DeleteContents() { | 320 void RenderViewHostTestHarness::DeleteContents() { |
321 SetContents(NULL); | 321 SetContents(NULL); |
322 } | 322 } |
323 | 323 |
324 void RenderViewHostTestHarness::SetContents(TestTabContents* contents) { | 324 void RenderViewHostTestHarness::SetContents(TestTabContents* contents) { |
325 contents_.reset(contents); | 325 contents_.reset(contents); |
326 } | 326 } |
327 | 327 |
328 TestTabContents* RenderViewHostTestHarness::CreateTestTabContents() { | 328 TestTabContents* RenderViewHostTestHarness::CreateTestTabContents() { |
329 // See comment above profile_ decl for why we check for NULL here. | 329 // See comment above browser_context_ decl for why we check for NULL here. |
330 if (!profile_.get()) | 330 if (!browser_context_.get()) |
331 profile_.reset(new TestingProfile()); | 331 browser_context_.reset(new TestBrowserContext()); |
332 | 332 |
333 // This will be deleted when the TabContents goes away. | 333 // This will be deleted when the TabContents goes away. |
334 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); | 334 SiteInstance* instance = |
| 335 SiteInstance::CreateSiteInstance(browser_context_.get()); |
335 | 336 |
336 return new TestTabContents(profile_.get(), instance); | 337 return new TestTabContents(browser_context_.get(), instance); |
337 } | 338 } |
338 | 339 |
339 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { | 340 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { |
340 contents()->NavigateAndCommit(url); | 341 contents()->NavigateAndCommit(url); |
341 } | 342 } |
342 | 343 |
343 void RenderViewHostTestHarness::Reload() { | 344 void RenderViewHostTestHarness::Reload() { |
344 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 345 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
345 DCHECK(entry); | 346 DCHECK(entry); |
346 controller().Reload(false); | 347 controller().Reload(false); |
347 rvh()->SendNavigate(entry->page_id(), entry->url()); | 348 rvh()->SendNavigate(entry->page_id(), entry->url()); |
348 } | 349 } |
349 | 350 |
350 void RenderViewHostTestHarness::SetUp() { | 351 void RenderViewHostTestHarness::SetUp() { |
351 SetContents(CreateTestTabContents()); | 352 SetContents(CreateTestTabContents()); |
352 } | 353 } |
353 | 354 |
354 void RenderViewHostTestHarness::TearDown() { | 355 void RenderViewHostTestHarness::TearDown() { |
355 SetContents(NULL); | 356 SetContents(NULL); |
356 | 357 |
357 // Make sure that we flush any messages related to TabContents destruction | 358 // Make sure that we flush any messages related to TabContents destruction |
358 // before we destroy the profile. | 359 // before we destroy the browser context. |
359 MessageLoop::current()->RunAllPending(); | 360 MessageLoop::current()->RunAllPending(); |
360 | 361 |
361 // Release the profile on the UI thread. | 362 // Release the browser context on the UI thread. |
362 message_loop_.DeleteSoon(FROM_HERE, profile_.release()); | 363 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
363 message_loop_.RunAllPending(); | 364 message_loop_.RunAllPending(); |
364 } | 365 } |
OLD | NEW |