| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/tab_contents/test_tab_contents.h" | 5 #include "chrome/browser/tab_contents/test_tab_contents.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_url_handler.h" | 7 #include "chrome/browser/browser_url_handler.h" |
| 8 #include "chrome/browser/renderer_host/mock_render_process_host.h" | 8 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 10 #include "chrome/browser/renderer_host/site_instance.h" | 10 #include "chrome/browser/renderer_host/site_instance.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: | 38 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: |
| 39 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr()-> | 39 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr()-> |
| 40 first->InfoBarClosed(); | 40 first->InfoBarClosed(); |
| 41 break; | 41 break; |
| 42 default: | 42 default: |
| 43 TabContents::Observe(type, source, details); | 43 TabContents::Observe(type, source, details); |
| 44 break; | 44 break; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 TestRenderViewHost* TestTabContents::pending_rvh() { | 48 TestRenderViewHost* TestTabContents::pending_rvh() const { |
| 49 return static_cast<TestRenderViewHost*>( | 49 return static_cast<TestRenderViewHost*>( |
| 50 render_manager_.pending_render_view_host_); | 50 render_manager_.pending_render_view_host_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool TestTabContents::CreateRenderViewForRenderManager( | 53 bool TestTabContents::CreateRenderViewForRenderManager( |
| 54 RenderViewHost* render_view_host) { | 54 RenderViewHost* render_view_host) { |
| 55 // This will go to a TestRenderViewHost. | 55 // This will go to a TestRenderViewHost. |
| 56 render_view_host->CreateRenderView(string16()); | 56 render_view_host->CreateRenderView(string16()); |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 TabContents* TestTabContents::Clone() { | 60 TabContents* TestTabContents::Clone() { |
| 61 TabContents* tc = new TestTabContents( | 61 TabContents* tc = new TestTabContents( |
| 62 profile(), SiteInstance::CreateSiteInstance(profile())); | 62 profile(), SiteInstance::CreateSiteInstance(profile())); |
| 63 tc->controller().CopyStateFrom(controller_); | 63 tc->controller().CopyStateFrom(controller_); |
| 64 return tc; | 64 return tc; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void TestTabContents::NavigateAndCommit(const GURL& url) { | 67 void TestTabContents::NavigateAndCommit(const GURL& url) { |
| 68 controller().LoadURL(url, GURL(), 0); | 68 controller().LoadURL(url, GURL(), 0); |
| 69 GURL loaded_url(url); | 69 GURL loaded_url(url); |
| 70 bool reverse_on_redirect = false; | 70 bool reverse_on_redirect = false; |
| 71 BrowserURLHandler::RewriteURLIfNecessary( | 71 BrowserURLHandler::RewriteURLIfNecessary( |
| 72 &loaded_url, profile(), &reverse_on_redirect); | 72 &loaded_url, profile(), &reverse_on_redirect); |
| 73 static_cast<TestRenderViewHost*>(render_view_host())->SendNavigate( | 73 |
| 74 static_cast<MockRenderProcessHost*>(render_view_host()->process())-> | 74 // LoadURL created a navigation entry, now simulate the RenderView sending |
| 75 max_page_id() + 1, loaded_url); | 75 // a notification that it actually navigated. |
| 76 CommitPendingNavigation(); |
| 76 } | 77 } |
| 78 |
| 79 void TestTabContents::CommitPendingNavigation() { |
| 80 // If we are doing a cross-site navigation, this simulates the current RVH |
| 81 // notifying that it has unloaded so the pending RVH is resumed and can |
| 82 // navigate. |
| 83 ProceedWithCrossSiteNavigation(); |
| 84 TestRenderViewHost* rvh = pending_rvh(); |
| 85 if (!rvh) |
| 86 rvh = static_cast<TestRenderViewHost*>(render_manager_.current_host()); |
| 87 |
| 88 const NavigationEntry* entry = controller().pending_entry(); |
| 89 DCHECK(entry); |
| 90 int page_id = entry->page_id(); |
| 91 if (page_id == -1) { |
| 92 // It's a new navigation, assign a never-seen page id to it. |
| 93 page_id = |
| 94 static_cast<MockRenderProcessHost*>(rvh->process())->max_page_id() + 1; |
| 95 } |
| 96 rvh->SendNavigate(page_id, entry->url()); |
| 97 } |
| 98 |
| 99 void TestTabContents::ProceedWithCrossSiteNavigation() { |
| 100 if (!pending_rvh()) |
| 101 return; |
| 102 render_manager_.ShouldClosePage(true, true); |
| 103 } |
| OLD | NEW |