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 "content/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
6 #include "content/browser/browser_url_handler.h" | 6 #include "content/browser/browser_url_handler.h" |
7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 void set_should_create_webui(bool should_create_webui) { | 108 void set_should_create_webui(bool should_create_webui) { |
109 browser_client_.set_should_create_webui(should_create_webui); | 109 browser_client_.set_should_create_webui(should_create_webui); |
110 } | 110 } |
111 | 111 |
112 void NavigateActiveAndCommit(const GURL& url) { | 112 void NavigateActiveAndCommit(const GURL& url) { |
113 // Note: we navigate the active RenderViewHost because previous navigations | 113 // Note: we navigate the active RenderViewHost because previous navigations |
114 // won't have committed yet, so NavigateAndCommit does the wrong thing | 114 // won't have committed yet, so NavigateAndCommit does the wrong thing |
115 // for us. | 115 // for us. |
116 controller().LoadURL( | 116 controller().LoadURL( |
117 url, GURL(), content::PAGE_TRANSITION_LINK, std::string()); | 117 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
118 TestRenderViewHost* old_rvh = rvh(); | 118 TestRenderViewHost* old_rvh = rvh(); |
119 | 119 |
120 // Simulate the ShouldClose_ACK that is received from the current renderer | 120 // Simulate the ShouldClose_ACK that is received from the current renderer |
121 // for a cross-site navigation. | 121 // for a cross-site navigation. |
122 if (old_rvh != active_rvh()) | 122 if (old_rvh != active_rvh()) |
123 old_rvh->SendShouldCloseACK(true); | 123 old_rvh->SendShouldCloseACK(true); |
124 | 124 |
125 // Commit the navigation. | 125 // Commit the navigation. |
126 active_rvh()->SendNavigate( | 126 active_rvh()->SendNavigate( |
127 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> | 127 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> |
(...skipping 30 matching lines...) Expand all Loading... |
158 NavigateActiveAndCommit(kNtpUrl); | 158 NavigateActiveAndCommit(kNtpUrl); |
159 NavigateActiveAndCommit(kDestUrl); | 159 NavigateActiveAndCommit(kDestUrl); |
160 | 160 |
161 // Make a second tab. | 161 // Make a second tab. |
162 TestTabContents contents2(browser_context(), NULL); | 162 TestTabContents contents2(browser_context(), NULL); |
163 | 163 |
164 // Load the two URLs in the second tab. Note that the first navigation creates | 164 // Load the two URLs in the second tab. Note that the first navigation creates |
165 // a RVH that's not pending (since there is no cross-site transition), so | 165 // a RVH that's not pending (since there is no cross-site transition), so |
166 // we use the committed one. | 166 // we use the committed one. |
167 contents2.controller().LoadURL( | 167 contents2.controller().LoadURL( |
168 kNtpUrl, GURL(), content::PAGE_TRANSITION_LINK, std::string()); | 168 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 169 std::string()); |
169 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( | 170 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( |
170 contents2.render_manager_for_testing()->current_host()); | 171 contents2.render_manager_for_testing()->current_host()); |
171 EXPECT_FALSE(contents2.cross_navigation_pending()); | 172 EXPECT_FALSE(contents2.cross_navigation_pending()); |
172 ntp_rvh2->SendNavigate(100, kNtpUrl); | 173 ntp_rvh2->SendNavigate(100, kNtpUrl); |
173 | 174 |
174 // The second one is the opposite, creating a cross-site transition and | 175 // The second one is the opposite, creating a cross-site transition and |
175 // requiring a beforeunload ack. | 176 // requiring a beforeunload ack. |
176 contents2.controller().LoadURL( | 177 contents2.controller().LoadURL( |
177 kDestUrl, GURL(), content::PAGE_TRANSITION_LINK, std::string()); | 178 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 179 std::string()); |
178 EXPECT_TRUE(contents2.cross_navigation_pending()); | 180 EXPECT_TRUE(contents2.cross_navigation_pending()); |
179 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( | 181 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( |
180 contents2.render_manager_for_testing()->pending_render_view_host()); | 182 contents2.render_manager_for_testing()->pending_render_view_host()); |
181 ASSERT_TRUE(dest_rvh2); | 183 ASSERT_TRUE(dest_rvh2); |
182 ntp_rvh2->SendShouldCloseACK(true); | 184 ntp_rvh2->SendShouldCloseACK(true); |
183 dest_rvh2->SendNavigate(101, kDestUrl); | 185 dest_rvh2->SendNavigate(101, kDestUrl); |
184 ntp_rvh2->OnSwapOutACK(); | 186 ntp_rvh2->OnSwapOutACK(); |
185 | 187 |
186 // The two RVH's should be different in every way. | 188 // The two RVH's should be different in every way. |
187 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); | 189 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); |
188 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); | 190 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); |
189 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), | 191 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), |
190 dest_rvh2->site_instance()->browsing_instance()); | 192 dest_rvh2->site_instance()->browsing_instance()); |
191 | 193 |
192 // Navigate both to the new tab page, and verify that they share a | 194 // Navigate both to the new tab page, and verify that they share a |
193 // SiteInstance. | 195 // SiteInstance. |
194 NavigateActiveAndCommit(kNtpUrl); | 196 NavigateActiveAndCommit(kNtpUrl); |
195 | 197 |
196 contents2.controller().LoadURL( | 198 contents2.controller().LoadURL( |
197 kNtpUrl, GURL(), content::PAGE_TRANSITION_LINK, std::string()); | 199 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 200 std::string()); |
198 dest_rvh2->SendShouldCloseACK(true); | 201 dest_rvh2->SendShouldCloseACK(true); |
199 static_cast<TestRenderViewHost*>(contents2.render_manager_for_testing()-> | 202 static_cast<TestRenderViewHost*>(contents2.render_manager_for_testing()-> |
200 pending_render_view_host())->SendNavigate(102, kNtpUrl); | 203 pending_render_view_host())->SendNavigate(102, kNtpUrl); |
201 dest_rvh2->OnSwapOutACK(); | 204 dest_rvh2->OnSwapOutACK(); |
202 | 205 |
203 EXPECT_EQ(active_rvh()->site_instance(), | 206 EXPECT_EQ(active_rvh()->site_instance(), |
204 contents2.render_view_host()->site_instance()); | 207 contents2.render_view_host()->site_instance()); |
205 } | 208 } |
206 | 209 |
207 // When there is an error with the specified page, renderer exits view-source | 210 // When there is an error with the specified page, renderer exits view-source |
208 // mode. See WebFrameImpl::DidFail(). We check by this test that | 211 // mode. See WebFrameImpl::DidFail(). We check by this test that |
209 // EnableViewSourceMode message is sent on every navigation regardless | 212 // EnableViewSourceMode message is sent on every navigation regardless |
210 // RenderView is being newly created or reused. | 213 // RenderView is being newly created or reused. |
211 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { | 214 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { |
212 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 215 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
213 const GURL kNtpUrl(chrome::kTestNewTabURL); | 216 const GURL kNtpUrl(chrome::kTestNewTabURL); |
214 const GURL kUrl("view-source:http://foo"); | 217 const GURL kUrl("view-source:http://foo"); |
215 | 218 |
216 // We have to navigate to some page at first since without this, the first | 219 // We have to navigate to some page at first since without this, the first |
217 // navigation will reuse the SiteInstance created by Init(), and the second | 220 // navigation will reuse the SiteInstance created by Init(), and the second |
218 // one will create a new SiteInstance. Because current_instance and | 221 // one will create a new SiteInstance. Because current_instance and |
219 // new_instance will be different, a new RenderViewHost will be created for | 222 // new_instance will be different, a new RenderViewHost will be created for |
220 // the second navigation. We have to avoid this in order to exercise the | 223 // the second navigation. We have to avoid this in order to exercise the |
221 // target code patch. | 224 // target code patch. |
222 NavigateActiveAndCommit(kNtpUrl); | 225 NavigateActiveAndCommit(kNtpUrl); |
223 | 226 |
224 // Navigate. | 227 // Navigate. |
225 controller().LoadURL( | 228 controller().LoadURL( |
226 kUrl, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 229 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
227 // Simulate response from RenderView for FirePageBeforeUnload. | 230 // Simulate response from RenderView for FirePageBeforeUnload. |
228 rvh()->TestOnMessageReceived( | 231 rvh()->TestOnMessageReceived( |
229 ViewHostMsg_ShouldClose_ACK(rvh()->routing_id(), true)); | 232 ViewHostMsg_ShouldClose_ACK(rvh()->routing_id(), true)); |
230 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. | 233 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. |
231 RenderViewHost* last_rvh = pending_rvh(); | 234 RenderViewHost* last_rvh = pending_rvh(); |
232 int new_id = static_cast<MockRenderProcessHost*>(pending_rvh()->process())-> | 235 int new_id = static_cast<MockRenderProcessHost*>(pending_rvh()->process())-> |
233 max_page_id() + 1; | 236 max_page_id() + 1; |
234 pending_rvh()->SendNavigate(new_id, kUrl); | 237 pending_rvh()->SendNavigate(new_id, kUrl); |
235 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 238 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
236 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 239 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
237 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->url()); | 240 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->url()); |
238 EXPECT_FALSE(controller().pending_entry()); | 241 EXPECT_FALSE(controller().pending_entry()); |
239 // Because we're using TestTabContents and TestRenderViewHost in this | 242 // Because we're using TestTabContents and TestRenderViewHost in this |
240 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no | 243 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no |
241 // EnableViewSourceMode message, here. | 244 // EnableViewSourceMode message, here. |
242 | 245 |
243 // Clear queued messages before load. | 246 // Clear queued messages before load. |
244 process()->sink().ClearMessages(); | 247 process()->sink().ClearMessages(); |
245 // Navigate, again. | 248 // Navigate, again. |
246 controller().LoadURL( | 249 controller().LoadURL( |
247 kUrl, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); | 250 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
248 // The same RenderViewHost should be reused. | 251 // The same RenderViewHost should be reused. |
249 EXPECT_FALSE(pending_rvh()); | 252 EXPECT_FALSE(pending_rvh()); |
250 EXPECT_TRUE(last_rvh == rvh()); | 253 EXPECT_TRUE(last_rvh == rvh()); |
251 rvh()->SendNavigate(new_id, kUrl); // The same page_id returned. | 254 rvh()->SendNavigate(new_id, kUrl); // The same page_id returned. |
252 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 255 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
253 EXPECT_FALSE(controller().pending_entry()); | 256 EXPECT_FALSE(controller().pending_entry()); |
254 // New message should be sent out to make sure to enter view-source mode. | 257 // New message should be sent out to make sure to enter view-source mode. |
255 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 258 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
256 ViewMsg_EnableViewSourceMode::ID)); | 259 ViewMsg_EnableViewSourceMode::ID)); |
257 } | 260 } |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 // current one. | 601 // current one. |
599 EXPECT_TRUE(contents()->render_manager_for_testing()-> | 602 EXPECT_TRUE(contents()->render_manager_for_testing()-> |
600 pending_render_view_host() == NULL); | 603 pending_render_view_host() == NULL); |
601 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); | 604 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); |
602 | 605 |
603 // Also we should not have a pending navigation entry. | 606 // Also we should not have a pending navigation entry. |
604 NavigationEntry* entry = contents()->controller().GetActiveEntry(); | 607 NavigationEntry* entry = contents()->controller().GetActiveEntry(); |
605 ASSERT_TRUE(entry != NULL); | 608 ASSERT_TRUE(entry != NULL); |
606 EXPECT_EQ(kUrl2, entry->url()); | 609 EXPECT_EQ(kUrl2, entry->url()); |
607 } | 610 } |
OLD | NEW |