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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/interstitial_page_impl.h" | 8 #include "content/browser/frame_host/interstitial_page_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_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 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1165 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1166 EXPECT_FALSE( | 1166 EXPECT_FALSE( |
1167 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1167 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1168 | 1168 |
1169 // The pending navigation should be able to commit successfully. | 1169 // The pending navigation should be able to commit successfully. |
1170 contents()->TestDidNavigate(pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 1170 contents()->TestDidNavigate(pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); |
1171 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1171 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1172 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 1172 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
1173 } | 1173 } |
1174 | 1174 |
1175 // Test that the original renderer cannot preempt a cross-site navigation once | |
1176 // the unload request has been made. At this point, the cross-site navigation | |
1177 // is almost ready to be displayed, and the original renderer is only given a | |
1178 // short chance to run an unload handler. Prevents regression of bug 23942. | |
1179 TEST_F(WebContentsImplTest, CrossSiteCantPreemptAfterUnload) { | |
1180 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | |
1181 SiteInstance* instance1 = contents()->GetSiteInstance(); | |
1182 | |
1183 // Navigate to URL. First URL should use first RenderViewHost. | |
1184 const GURL url("http://www.google.com"); | |
1185 controller().LoadURL( | |
1186 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | |
1187 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | |
1188 EXPECT_FALSE(contents()->cross_navigation_pending()); | |
1189 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | |
1190 | |
1191 // Navigate to new site, simulating an onbeforeunload approval. | |
1192 const GURL url2("http://www.yahoo.com"); | |
1193 controller().LoadURL( | |
1194 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | |
1195 base::TimeTicks now = base::TimeTicks::Now(); | |
1196 orig_rfh->OnMessageReceived( | |
1197 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1198 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
1199 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | |
1200 | |
1201 // Simulate the pending renderer's response, which leads to an unload request | |
1202 // being sent to orig_rfh. | |
1203 std::vector<GURL> url_chain; | |
1204 url_chain.push_back(GURL()); | |
1205 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse( | |
1206 contents()->GetRenderManagerForTesting()->pending_frame_host(), | |
1207 GlobalRequestID(0, 0), scoped_ptr<CrossSiteTransferringRequest>(), | |
1208 url_chain, Referrer(), PAGE_TRANSITION_TYPED, false); | |
1209 | |
1210 // Suppose the original renderer navigates now, while the unload request is in | |
1211 // flight. We should ignore it, wait for the unload ack, and let the pending | |
1212 // request continue. Otherwise, the contents may close spontaneously or stop | |
1213 // responding to navigation requests. (See bug 23942.) | |
1214 FrameHostMsg_DidCommitProvisionalLoad_Params params1a; | |
1215 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), | |
1216 PAGE_TRANSITION_TYPED); | |
1217 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); | |
1218 | |
1219 // Verify that the pending navigation is still in progress. | |
1220 EXPECT_TRUE(contents()->cross_navigation_pending()); | |
1221 EXPECT_TRUE(contents()->GetPendingMainFrame() != NULL); | |
1222 | |
1223 // DidNavigate from the pending page should commit it. | |
1224 contents()->TestDidNavigate( | |
1225 pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | |
1226 SiteInstance* instance2 = contents()->GetSiteInstance(); | |
1227 EXPECT_FALSE(contents()->cross_navigation_pending()); | |
1228 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | |
1229 EXPECT_NE(instance1, instance2); | |
1230 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | |
1231 } | |
1232 | |
1233 // Test that a cross-site navigation that doesn't commit after the unload | 1175 // Test that a cross-site navigation that doesn't commit after the unload |
1234 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 | 1176 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 |
1235 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { | 1177 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { |
1236 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1178 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1237 SiteInstance* instance1 = contents()->GetSiteInstance(); | 1179 SiteInstance* instance1 = contents()->GetSiteInstance(); |
1238 | 1180 |
1239 // Navigate to URL. First URL should use original RenderFrameHost. | 1181 // Navigate to URL. First URL should use original RenderFrameHost. |
1240 const GURL url("http://www.google.com"); | 1182 const GURL url("http://www.google.com"); |
1241 controller().LoadURL( | 1183 controller().LoadURL( |
1242 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1184 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2737 contents->CommitPendingNavigation(); | 2679 contents->CommitPendingNavigation(); |
2738 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2680 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2739 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); | 2681 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); |
2740 | 2682 |
2741 contents.reset(); | 2683 contents.reset(); |
2742 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2684 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2743 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); | 2685 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
2744 } | 2686 } |
2745 | 2687 |
2746 } // namespace content | 2688 } // namespace content |
OLD | NEW |