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::GetPendingRenderViewHost() 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*>(GetPendingRenderViewHost()); |
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 = |
| 126 static_cast<TestRenderViewHost*>(GetPendingRenderViewHost()); |
126 if (!rvh) | 127 if (!rvh) |
127 rvh = static_cast<TestRenderViewHost*>(old_rvh); | 128 rvh = static_cast<TestRenderViewHost*>(old_rvh); |
128 | 129 |
129 const NavigationEntry* entry = GetController().GetPendingEntry(); | 130 const NavigationEntry* entry = GetController().GetPendingEntry(); |
130 DCHECK(entry); | 131 DCHECK(entry); |
131 int page_id = entry->GetPageID(); | 132 int page_id = entry->GetPageID(); |
132 if (page_id == -1) { | 133 if (page_id == -1) { |
133 // It's a new navigation, assign a never-seen page id to it. | 134 // It's a new navigation, assign a never-seen page id to it. |
134 page_id = GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()) + 1; | 135 page_id = GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()) + 1; |
135 } | 136 } |
136 rvh->SendNavigate(page_id, entry->GetURL()); | 137 rvh->SendNavigate(page_id, entry->GetURL()); |
137 | 138 |
138 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation | 139 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation |
139 // without making any network requests. | 140 // without making any network requests. |
140 if (old_rvh != rvh) | 141 if (old_rvh != rvh) |
141 static_cast<RenderViewHostImpl*>(old_rvh)->OnSwapOutACK(); | 142 static_cast<RenderViewHostImpl*>(old_rvh)->OnSwapOutACK(); |
142 } | 143 } |
143 | 144 |
144 int TestTabContents::GetNumberOfFocusCalls() { | 145 int TestTabContents::GetNumberOfFocusCalls() { |
145 NOTREACHED(); | 146 NOTREACHED(); |
146 return 0; | 147 return 0; |
147 } | 148 } |
148 | 149 |
149 void TestTabContents::ProceedWithCrossSiteNavigation() { | 150 void TestTabContents::ProceedWithCrossSiteNavigation() { |
150 if (!pending_rvh()) | 151 if (!GetPendingRenderViewHost()) |
151 return; | 152 return; |
152 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>( | 153 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>( |
153 render_manager_.current_host()); | 154 render_manager_.current_host()); |
154 rvh->SendShouldCloseACK(true); | 155 rvh->SendShouldCloseACK(true); |
155 } | 156 } |
156 | 157 |
157 content::RenderViewHostDelegate::View* TestTabContents::GetViewDelegate() { | 158 content::RenderViewHostDelegate::View* TestTabContents::GetViewDelegate() { |
158 if (delegate_view_override_) | 159 if (delegate_view_override_) |
159 return delegate_view_override_; | 160 return delegate_view_override_; |
160 return TabContents::GetViewDelegate(); | 161 return TabContents::GetViewDelegate(); |
(...skipping 13 matching lines...) Expand all Loading... |
174 void TestTabContents::SetHistoryLengthAndPrune( | 175 void TestTabContents::SetHistoryLengthAndPrune( |
175 const SiteInstance* site_instance, int history_length, | 176 const SiteInstance* site_instance, int history_length, |
176 int32 min_page_id) { | 177 int32 min_page_id) { |
177 EXPECT_TRUE(expect_set_history_length_and_prune_); | 178 EXPECT_TRUE(expect_set_history_length_and_prune_); |
178 expect_set_history_length_and_prune_ = false; | 179 expect_set_history_length_and_prune_ = false; |
179 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance); | 180 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance); |
180 EXPECT_EQ(expect_set_history_length_and_prune_history_length_, | 181 EXPECT_EQ(expect_set_history_length_and_prune_history_length_, |
181 history_length); | 182 history_length); |
182 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id); | 183 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id); |
183 } | 184 } |
OLD | NEW |