| 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/browser/tab_contents/test_tab_contents.h" | 5 #include "content/browser/tab_contents/test_tab_contents.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/browser_url_handler_impl.h" | 9 #include "content/browser/browser_url_handler_impl.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 delegate_view_override_(NULL), | 31 delegate_view_override_(NULL), |
| 32 expect_set_history_length_and_prune_(false), | 32 expect_set_history_length_and_prune_(false), |
| 33 expect_set_history_length_and_prune_site_instance_(NULL), | 33 expect_set_history_length_and_prune_site_instance_(NULL), |
| 34 expect_set_history_length_and_prune_history_length_(0), | 34 expect_set_history_length_and_prune_history_length_(0), |
| 35 expect_set_history_length_and_prune_min_page_id_(-1) { | 35 expect_set_history_length_and_prune_min_page_id_(-1) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 TestTabContents::~TestTabContents() { | 38 TestTabContents::~TestTabContents() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 RenderViewHost* TestTabContents::pending_rvh() const { | 41 RenderViewHost* TestTabContents::GetPendingRvh() const { |
| 42 return render_manager_.pending_render_view_host_; | 42 return render_manager_.pending_render_view_host_; |
| 43 } | 43 } |
| 44 | 44 |
| 45 TestRenderViewHost* TestTabContents::pending_test_rvh() const { | 45 TestRenderViewHost* TestTabContents::pending_test_rvh() const { |
| 46 return static_cast<TestRenderViewHost*>(pending_rvh()); | 46 return static_cast<TestRenderViewHost*>(GetPendingRvh()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void TestTabContents::TestDidNavigate(RenderViewHost* render_view_host, | 49 void TestTabContents::TestDidNavigate(RenderViewHost* render_view_host, |
| 50 int page_id, | 50 int page_id, |
| 51 const GURL& url, | 51 const GURL& url, |
| 52 content::PageTransition transition) { | 52 content::PageTransition transition) { |
| 53 TestDidNavigateWithReferrer(render_view_host, | 53 TestDidNavigateWithReferrer(render_view_host, |
| 54 page_id, | 54 page_id, |
| 55 url, | 55 url, |
| 56 content::Referrer(), | 56 content::Referrer(), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // a notification that it actually navigated. | 115 // a notification that it actually navigated. |
| 116 CommitPendingNavigation(); | 116 CommitPendingNavigation(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void TestTabContents::CommitPendingNavigation() { | 119 void TestTabContents::CommitPendingNavigation() { |
| 120 // If we are doing a cross-site navigation, this simulates the current RVH | 120 // If we are doing a cross-site navigation, this simulates the current RVH |
| 121 // notifying that it has unloaded so the pending RVH is resumed and can | 121 // notifying that it has unloaded so the pending RVH is resumed and can |
| 122 // navigate. | 122 // navigate. |
| 123 ProceedWithCrossSiteNavigation(); | 123 ProceedWithCrossSiteNavigation(); |
| 124 RenderViewHost* old_rvh = render_manager_.current_host(); | 124 RenderViewHost* old_rvh = render_manager_.current_host(); |
| 125 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>(pending_rvh()); | 125 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>(GetPendingRvh()); |
| 126 if (!rvh) | 126 if (!rvh) |
| 127 rvh = static_cast<TestRenderViewHost*>(old_rvh); | 127 rvh = static_cast<TestRenderViewHost*>(old_rvh); |
| 128 | 128 |
| 129 const NavigationEntry* entry = GetController().GetPendingEntry(); | 129 const NavigationEntry* entry = GetController().GetPendingEntry(); |
| 130 DCHECK(entry); | 130 DCHECK(entry); |
| 131 int page_id = entry->GetPageID(); | 131 int page_id = entry->GetPageID(); |
| 132 if (page_id == -1) { | 132 if (page_id == -1) { |
| 133 // It's a new navigation, assign a never-seen page id to it. | 133 // It's a new navigation, assign a never-seen page id to it. |
| 134 page_id = GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()) + 1; | 134 page_id = GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()) + 1; |
| 135 } | 135 } |
| 136 rvh->SendNavigate(page_id, entry->GetURL()); | 136 rvh->SendNavigate(page_id, entry->GetURL()); |
| 137 | 137 |
| 138 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation | 138 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation |
| 139 // without making any network requests. | 139 // without making any network requests. |
| 140 if (old_rvh != rvh) | 140 if (old_rvh != rvh) |
| 141 static_cast<RenderViewHostImpl*>(old_rvh)->OnSwapOutACK(); | 141 static_cast<RenderViewHostImpl*>(old_rvh)->OnSwapOutACK(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 int TestTabContents::GetNumberOfFocusCalls() { | 144 int TestTabContents::GetNumberOfFocusCalls() { |
| 145 NOTREACHED(); | 145 NOTREACHED(); |
| 146 return 0; | 146 return 0; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void TestTabContents::ProceedWithCrossSiteNavigation() { | 149 void TestTabContents::ProceedWithCrossSiteNavigation() { |
| 150 if (!pending_rvh()) | 150 if (!GetPendingRvh()) |
| 151 return; | 151 return; |
| 152 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>( | 152 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>( |
| 153 render_manager_.current_host()); | 153 render_manager_.current_host()); |
| 154 rvh->SendShouldCloseACK(true); | 154 rvh->SendShouldCloseACK(true); |
| 155 } | 155 } |
| 156 | 156 |
| 157 content::RenderViewHostDelegate::View* TestTabContents::GetViewDelegate() { | 157 content::RenderViewHostDelegate::View* TestTabContents::GetViewDelegate() { |
| 158 if (delegate_view_override_) | 158 if (delegate_view_override_) |
| 159 return delegate_view_override_; | 159 return delegate_view_override_; |
| 160 return TabContents::GetViewDelegate(); | 160 return TabContents::GetViewDelegate(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 174 void TestTabContents::SetHistoryLengthAndPrune( | 174 void TestTabContents::SetHistoryLengthAndPrune( |
| 175 const SiteInstance* site_instance, int history_length, | 175 const SiteInstance* site_instance, int history_length, |
| 176 int32 min_page_id) { | 176 int32 min_page_id) { |
| 177 EXPECT_TRUE(expect_set_history_length_and_prune_); | 177 EXPECT_TRUE(expect_set_history_length_and_prune_); |
| 178 expect_set_history_length_and_prune_ = false; | 178 expect_set_history_length_and_prune_ = false; |
| 179 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance); | 179 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance); |
| 180 EXPECT_EQ(expect_set_history_length_and_prune_history_length_, | 180 EXPECT_EQ(expect_set_history_length_and_prune_history_length_, |
| 181 history_length); | 181 history_length); |
| 182 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id); | 182 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id); |
| 183 } | 183 } |
| OLD | NEW |