Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 497183003: Fix DisownOpener and related tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/browser/frame_host/cross_site_transferring_request.h" 9 #include "content/browser/frame_host/cross_site_transferring_request.h"
10 #include "content/browser/frame_host/navigation_before_commit_info.h" 10 #include "content/browser/frame_host/navigation_before_commit_info.h"
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 rvh3->GetSiteInstance())); 1152 rvh3->GetSiteInstance()));
1153 1153
1154 // No scripting is allowed across BrowsingInstances, so we should not create 1154 // No scripting is allowed across BrowsingInstances, so we should not create
1155 // swapped out RVHs for the opener chain in this case. 1155 // swapped out RVHs for the opener chain in this case.
1156 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( 1156 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost(
1157 rvh3->GetSiteInstance())); 1157 rvh3->GetSiteInstance()));
1158 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( 1158 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost(
1159 rvh3->GetSiteInstance())); 1159 rvh3->GetSiteInstance()));
1160 } 1160 }
1161 1161
1162 // Test that a page can disown the opener of the WebContents.
1163 TEST_F(RenderFrameHostManagerTest, DisownOpener) {
1164 const GURL kUrl1("http://www.google.com/");
1165 const GURL kUrl2("http://www.chromium.org/");
1166
1167 // Navigate to an initial URL.
1168 contents()->NavigateAndCommit(kUrl1);
1169 TestRenderFrameHost* rfh1 = main_test_rfh();
1170
1171 // Create a new tab and simulate having it be the opener for the main tab.
1172 scoped_ptr<TestWebContents> opener1(
1173 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance()));
1174 contents()->SetOpener(opener1.get());
1175 EXPECT_TRUE(contents()->HasOpener());
1176
1177 // Navigate to a cross-site URL (different SiteInstance but same
1178 // BrowsingInstance).
1179 contents()->NavigateAndCommit(kUrl2);
1180 TestRenderFrameHost* rfh2 = main_test_rfh();
1181 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance());
1182
1183 // Disown the opener from rfh2.
1184 rfh2->DidDisownOpener();
1185
1186 // Ensure the opener is cleared.
1187 EXPECT_FALSE(contents()->HasOpener());
1188 }
1189
1190 // Test that a page can disown the opener just as a cross-process navigation is
1191 // in progress.
1192 TEST_F(RenderFrameHostManagerTest, DisownOpenerDuringNavigation) {
1193 const GURL kUrl1("http://www.google.com/");
1194 const GURL kUrl2("http://www.chromium.org/");
1195
1196 // Navigate to an initial URL.
1197 contents()->NavigateAndCommit(kUrl1);
1198 TestRenderFrameHost* rfh1 = main_test_rfh();
1199
1200 // Create a new tab and simulate having it be the opener for the main tab.
1201 scoped_ptr<TestWebContents> opener1(
1202 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance()));
1203 contents()->SetOpener(opener1.get());
1204 EXPECT_TRUE(contents()->HasOpener());
1205
1206 // Navigate to a cross-site URL (different SiteInstance but same
1207 // BrowsingInstance).
1208 contents()->NavigateAndCommit(kUrl2);
1209 TestRenderFrameHost* rfh2 = main_test_rfh();
1210 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance());
1211
1212 // Start a back navigation so that rfh1 becomes the pending RFH.
1213 contents()->GetController().GoBack();
1214 contents()->ProceedWithCrossSiteNavigation();
1215
1216 // Disown the opener from rfh2.
1217 rfh2->DidDisownOpener();
1218
1219 // Ensure the opener is cleared.
1220 EXPECT_FALSE(contents()->HasOpener());
1221
1222 // The back navigation commits.
1223 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1224 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL());
1225
1226 // Ensure the opener is still cleared.
1227 EXPECT_FALSE(contents()->HasOpener());
1228 }
1229
1230 // Test that a page can disown the opener just after a cross-process navigation
1231 // commits.
1232 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) {
1233 const GURL kUrl1("http://www.google.com/");
1234 const GURL kUrl2("http://www.chromium.org/");
1235
1236 // Navigate to an initial URL.
1237 contents()->NavigateAndCommit(kUrl1);
1238 TestRenderFrameHost* rfh1 = main_test_rfh();
1239
1240 // Create a new tab and simulate having it be the opener for the main tab.
1241 scoped_ptr<TestWebContents> opener1(
1242 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance()));
1243 contents()->SetOpener(opener1.get());
1244 EXPECT_TRUE(contents()->HasOpener());
1245
1246 // Navigate to a cross-site URL (different SiteInstance but same
1247 // BrowsingInstance).
1248 contents()->NavigateAndCommit(kUrl2);
1249 TestRenderFrameHost* rfh2 = main_test_rfh();
1250 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance());
1251
1252 // Commit a back navigation before the DidDisownOpener message arrives.
1253 // rfh1 will be kept alive because of the opener tab.
1254 contents()->GetController().GoBack();
1255 contents()->ProceedWithCrossSiteNavigation();
1256 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1257 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL());
1258
1259 // Disown the opener from rfh2.
1260 rfh2->DidDisownOpener();
1261 EXPECT_FALSE(contents()->HasOpener());
1262 }
1263
1162 // Test that we clean up swapped out RenderViewHosts when a process hosting 1264 // Test that we clean up swapped out RenderViewHosts when a process hosting
1163 // those associated RenderViews crashes. http://crbug.com/258993 1265 // those associated RenderViews crashes. http://crbug.com/258993
1164 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { 1266 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) {
1165 const GURL kUrl1("http://www.google.com/"); 1267 const GURL kUrl1("http://www.google.com/");
1166 const GURL kUrl2("http://www.chromium.org/"); 1268 const GURL kUrl2("http://www.chromium.org/");
1167 1269
1168 // Navigate to an initial URL. 1270 // Navigate to an initial URL.
1169 contents()->NavigateAndCommit(kUrl1); 1271 contents()->NavigateAndCommit(kUrl1);
1170 TestRenderViewHost* rvh1 = test_rvh(); 1272 TestRenderViewHost* rvh1 = test_rvh();
1171 1273
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 ASSERT_TRUE(main_request); 1766 ASSERT_TRUE(main_request);
1665 1767
1666 NavigationBeforeCommitInfo commit_info; 1768 NavigationBeforeCommitInfo commit_info;
1667 commit_info.navigation_url = kUrl2; 1769 commit_info.navigation_url = kUrl2;
1668 render_manager->CommitNavigation(commit_info); 1770 render_manager->CommitNavigation(commit_info);
1669 main_request = GetNavigationRequestForRenderFrameManager(render_manager); 1771 main_request = GetNavigationRequestForRenderFrameManager(render_manager);
1670 EXPECT_NE(main_test_rfh(), rfh); 1772 EXPECT_NE(main_test_rfh(), rfh);
1671 } 1773 }
1672 1774
1673 } // namespace content 1775 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698