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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Make a second tab. | 165 // Make a second tab. |
166 TestTabContents contents2(browser_context(), NULL); | 166 TestTabContents contents2(browser_context(), NULL); |
167 | 167 |
168 // Load the two URLs in the second tab. Note that the first navigation creates | 168 // Load the two URLs in the second tab. Note that the first navigation creates |
169 // a RVH that's not pending (since there is no cross-site transition), so | 169 // a RVH that's not pending (since there is no cross-site transition), so |
170 // we use the committed one. | 170 // we use the committed one. |
171 contents2.GetController().LoadURL( | 171 contents2.GetController().LoadURL( |
172 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 172 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
173 std::string()); | 173 std::string()); |
174 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( | 174 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( |
175 contents2.render_manager_for_testing()->current_host()); | 175 contents2.GetRenderManagerForTesting()->current_host()); |
176 EXPECT_FALSE(contents2.cross_navigation_pending()); | 176 EXPECT_FALSE(contents2.cross_navigation_pending()); |
177 ntp_rvh2->SendNavigate(100, kNtpUrl); | 177 ntp_rvh2->SendNavigate(100, kNtpUrl); |
178 | 178 |
179 // The second one is the opposite, creating a cross-site transition and | 179 // The second one is the opposite, creating a cross-site transition and |
180 // requiring a beforeunload ack. | 180 // requiring a beforeunload ack. |
181 contents2.GetController().LoadURL( | 181 contents2.GetController().LoadURL( |
182 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 182 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
183 std::string()); | 183 std::string()); |
184 EXPECT_TRUE(contents2.cross_navigation_pending()); | 184 EXPECT_TRUE(contents2.cross_navigation_pending()); |
185 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( | 185 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( |
186 contents2.render_manager_for_testing()->pending_render_view_host()); | 186 contents2.GetRenderManagerForTesting()->pending_render_view_host()); |
187 ASSERT_TRUE(dest_rvh2); | 187 ASSERT_TRUE(dest_rvh2); |
188 ntp_rvh2->SendShouldCloseACK(true); | 188 ntp_rvh2->SendShouldCloseACK(true); |
189 dest_rvh2->SendNavigate(101, kDestUrl); | 189 dest_rvh2->SendNavigate(101, kDestUrl); |
190 ntp_rvh2->OnSwapOutACK(); | 190 ntp_rvh2->OnSwapOutACK(); |
191 | 191 |
192 // The two RVH's should be different in every way. | 192 // The two RVH's should be different in every way. |
193 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); | 193 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); |
194 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); | 194 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); |
195 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), | 195 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), |
196 dest_rvh2->site_instance()->browsing_instance()); | 196 dest_rvh2->site_instance()->browsing_instance()); |
197 | 197 |
198 // Navigate both to the new tab page, and verify that they share a | 198 // Navigate both to the new tab page, and verify that they share a |
199 // SiteInstance. | 199 // SiteInstance. |
200 NavigateActiveAndCommit(kNtpUrl); | 200 NavigateActiveAndCommit(kNtpUrl); |
201 | 201 |
202 contents2.GetController().LoadURL( | 202 contents2.GetController().LoadURL( |
203 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 203 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
204 std::string()); | 204 std::string()); |
205 dest_rvh2->SendShouldCloseACK(true); | 205 dest_rvh2->SendShouldCloseACK(true); |
206 static_cast<TestRenderViewHost*>(contents2.render_manager_for_testing()-> | 206 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> |
207 pending_render_view_host())->SendNavigate(102, kNtpUrl); | 207 pending_render_view_host())->SendNavigate(102, kNtpUrl); |
208 dest_rvh2->OnSwapOutACK(); | 208 dest_rvh2->OnSwapOutACK(); |
209 | 209 |
210 EXPECT_EQ(active_rvh()->site_instance(), | 210 EXPECT_EQ(active_rvh()->site_instance(), |
211 contents2.GetRenderViewHost()->site_instance()); | 211 contents2.GetRenderViewHost()->site_instance()); |
212 } | 212 } |
213 | 213 |
214 // When there is an error with the specified page, renderer exits view-source | 214 // When there is an error with the specified page, renderer exits view-source |
215 // mode. See WebFrameImpl::DidFail(). We check by this test that | 215 // mode. See WebFrameImpl::DidFail(). We check by this test that |
216 // EnableViewSourceMode message is sent on every navigation regardless | 216 // EnableViewSourceMode message is sent on every navigation regardless |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // deleted. | 581 // deleted. |
582 contents()->NavigateAndCommit(kUrl1); | 582 contents()->NavigateAndCommit(kUrl1); |
583 contents()->NavigateAndCommit(kUrl2); | 583 contents()->NavigateAndCommit(kUrl2); |
584 RenderViewHost* evil_rvh = contents()->GetRenderViewHost(); | 584 RenderViewHost* evil_rvh = contents()->GetRenderViewHost(); |
585 | 585 |
586 // Now let's simulate the evil page calling history.back(). | 586 // Now let's simulate the evil page calling history.back(). |
587 contents()->OnGoToEntryAtOffset(-1); | 587 contents()->OnGoToEntryAtOffset(-1); |
588 // We should have a new pending RVH. | 588 // We should have a new pending RVH. |
589 // Note that in this case, the navigation has not committed, so evil_rvh will | 589 // Note that in this case, the navigation has not committed, so evil_rvh will |
590 // not be deleted yet. | 590 // not be deleted yet. |
591 EXPECT_NE(evil_rvh, contents()->render_manager_for_testing()-> | 591 EXPECT_NE(evil_rvh, contents()->GetRenderManagerForTesting()-> |
592 pending_render_view_host()); | 592 pending_render_view_host()); |
593 | 593 |
594 // Before that RVH has committed, the evil page reloads itself. | 594 // Before that RVH has committed, the evil page reloads itself. |
595 ViewHostMsg_FrameNavigate_Params params; | 595 ViewHostMsg_FrameNavigate_Params params; |
596 params.page_id = 1; | 596 params.page_id = 1; |
597 params.url = kUrl2; | 597 params.url = kUrl2; |
598 params.transition = content::PAGE_TRANSITION_CLIENT_REDIRECT; | 598 params.transition = content::PAGE_TRANSITION_CLIENT_REDIRECT; |
599 params.should_update_history = false; | 599 params.should_update_history = false; |
600 params.gesture = NavigationGestureAuto; | 600 params.gesture = NavigationGestureAuto; |
601 params.was_within_same_page = false; | 601 params.was_within_same_page = false; |
602 params.is_post = false; | 602 params.is_post = false; |
603 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(kUrl2)); | 603 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(kUrl2)); |
604 contents()->DidNavigate(evil_rvh, params); | 604 contents()->DidNavigate(evil_rvh, params); |
605 | 605 |
606 // That should have cancelled the pending RVH, and the evil RVH should be the | 606 // That should have cancelled the pending RVH, and the evil RVH should be the |
607 // current one. | 607 // current one. |
608 EXPECT_TRUE(contents()->render_manager_for_testing()-> | 608 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
609 pending_render_view_host() == NULL); | 609 pending_render_view_host() == NULL); |
610 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); | 610 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); |
611 | 611 |
612 // Also we should not have a pending navigation entry. | 612 // Also we should not have a pending navigation entry. |
613 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); | 613 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); |
614 ASSERT_TRUE(entry != NULL); | 614 ASSERT_TRUE(entry != NULL); |
615 EXPECT_EQ(kUrl2, entry->url()); | 615 EXPECT_EQ(kUrl2, entry->url()); |
616 } | 616 } |
OLD | NEW |