Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 a same-site opener of the WebContents. | |
| 1191 TEST_F(RenderFrameHostManagerTest, DisownSameSiteOpener) { | |
| 1192 const GURL kUrl1("http://www.google.com/"); | |
| 1193 const GURL kUrl2("http://www.chromium.org/"); | |
|
nasko
2014/08/25 14:17:57
nit: kUrl2 is unused.
Charlie Reis
2014/08/25 17:24:00
Fixed in patch 3 of https://codereview.chromium.or
| |
| 1194 | |
| 1195 // Navigate to an initial URL. | |
| 1196 contents()->NavigateAndCommit(kUrl1); | |
| 1197 TestRenderFrameHost* rfh1 = main_test_rfh(); | |
| 1198 | |
| 1199 // Create a new tab and simulate having it be the opener for the main tab. | |
| 1200 scoped_ptr<TestWebContents> opener1( | |
| 1201 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | |
| 1202 contents()->SetOpener(opener1.get()); | |
| 1203 EXPECT_TRUE(contents()->HasOpener()); | |
| 1204 | |
| 1205 // Disown the opener from rfh1. | |
| 1206 rfh1->DidDisownOpener(); | |
| 1207 | |
| 1208 // Ensure the opener is cleared even if it is in the same process. | |
| 1209 EXPECT_FALSE(contents()->HasOpener()); | |
| 1210 } | |
| 1211 | |
| 1212 // Test that a page can disown the opener just as a cross-process navigation is | |
| 1213 // in progress. | |
| 1214 TEST_F(RenderFrameHostManagerTest, DisownOpenerDuringNavigation) { | |
| 1215 const GURL kUrl1("http://www.google.com/"); | |
| 1216 const GURL kUrl2("http://www.chromium.org/"); | |
| 1217 | |
| 1218 // Navigate to an initial URL. | |
| 1219 contents()->NavigateAndCommit(kUrl1); | |
| 1220 TestRenderFrameHost* rfh1 = main_test_rfh(); | |
| 1221 | |
| 1222 // Create a new tab and simulate having it be the opener for the main tab. | |
| 1223 scoped_ptr<TestWebContents> opener1( | |
| 1224 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | |
| 1225 contents()->SetOpener(opener1.get()); | |
| 1226 EXPECT_TRUE(contents()->HasOpener()); | |
| 1227 | |
| 1228 // Navigate to a cross-site URL (different SiteInstance but same | |
| 1229 // BrowsingInstance). | |
| 1230 contents()->NavigateAndCommit(kUrl2); | |
| 1231 TestRenderFrameHost* rfh2 = main_test_rfh(); | |
| 1232 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | |
| 1233 | |
| 1234 // Start a back navigation so that rfh1 becomes the pending RFH. | |
| 1235 contents()->GetController().GoBack(); | |
| 1236 contents()->ProceedWithCrossSiteNavigation(); | |
| 1237 | |
| 1238 // Disown the opener from rfh2. | |
| 1239 rfh2->DidDisownOpener(); | |
| 1240 | |
| 1241 // Ensure the opener is cleared. | |
| 1242 EXPECT_FALSE(contents()->HasOpener()); | |
| 1243 | |
| 1244 // The back navigation commits. | |
| 1245 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | |
| 1246 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | |
| 1247 | |
| 1248 // Ensure the opener is still cleared. | |
| 1249 EXPECT_FALSE(contents()->HasOpener()); | |
| 1250 } | |
| 1251 | |
| 1252 // Test that a page can disown the opener just after a cross-process navigation | |
| 1253 // commits. | |
| 1254 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { | |
| 1255 const GURL kUrl1("http://www.google.com/"); | |
| 1256 const GURL kUrl2("http://www.chromium.org/"); | |
| 1257 | |
| 1258 // Navigate to an initial URL. | |
| 1259 contents()->NavigateAndCommit(kUrl1); | |
| 1260 TestRenderFrameHost* rfh1 = main_test_rfh(); | |
| 1261 | |
| 1262 // Create a new tab and simulate having it be the opener for the main tab. | |
| 1263 scoped_ptr<TestWebContents> opener1( | |
| 1264 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | |
| 1265 contents()->SetOpener(opener1.get()); | |
| 1266 EXPECT_TRUE(contents()->HasOpener()); | |
| 1267 | |
| 1268 // Navigate to a cross-site URL (different SiteInstance but same | |
| 1269 // BrowsingInstance). | |
| 1270 contents()->NavigateAndCommit(kUrl2); | |
| 1271 TestRenderFrameHost* rfh2 = main_test_rfh(); | |
| 1272 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | |
| 1273 | |
| 1274 // Commit a back navigation before the DidDisownOpener message arrives. | |
| 1275 // rfh1 will be kept alive because of the opener tab. | |
| 1276 contents()->GetController().GoBack(); | |
| 1277 contents()->ProceedWithCrossSiteNavigation(); | |
| 1278 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | |
| 1279 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | |
| 1280 | |
| 1281 // Disown the opener from rfh2. | |
| 1282 rfh2->DidDisownOpener(); | |
| 1283 EXPECT_FALSE(contents()->HasOpener()); | |
| 1284 } | |
| 1285 | |
| 1162 // Test that we clean up swapped out RenderViewHosts when a process hosting | 1286 // Test that we clean up swapped out RenderViewHosts when a process hosting |
| 1163 // those associated RenderViews crashes. http://crbug.com/258993 | 1287 // those associated RenderViews crashes. http://crbug.com/258993 |
| 1164 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { | 1288 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { |
| 1165 const GURL kUrl1("http://www.google.com/"); | 1289 const GURL kUrl1("http://www.google.com/"); |
| 1166 const GURL kUrl2("http://www.chromium.org/"); | 1290 const GURL kUrl2("http://www.chromium.org/"); |
| 1167 | 1291 |
| 1168 // Navigate to an initial URL. | 1292 // Navigate to an initial URL. |
| 1169 contents()->NavigateAndCommit(kUrl1); | 1293 contents()->NavigateAndCommit(kUrl1); |
| 1170 TestRenderViewHost* rvh1 = test_rvh(); | 1294 TestRenderViewHost* rvh1 = test_rvh(); |
| 1171 | 1295 |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1664 ASSERT_TRUE(main_request); | 1788 ASSERT_TRUE(main_request); |
| 1665 | 1789 |
| 1666 NavigationBeforeCommitInfo commit_info; | 1790 NavigationBeforeCommitInfo commit_info; |
| 1667 commit_info.navigation_url = kUrl2; | 1791 commit_info.navigation_url = kUrl2; |
| 1668 render_manager->CommitNavigation(commit_info); | 1792 render_manager->CommitNavigation(commit_info); |
| 1669 main_request = GetNavigationRequestForRenderFrameManager(render_manager); | 1793 main_request = GetNavigationRequestForRenderFrameManager(render_manager); |
| 1670 EXPECT_NE(main_test_rfh(), rfh); | 1794 EXPECT_NE(main_test_rfh(), rfh); |
| 1671 } | 1795 } |
| 1672 | 1796 |
| 1673 } // namespace content | 1797 } // namespace content |
| OLD | NEW |