| 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/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 // Simulate the BeforeUnload_ACK that is received from the current renderer | 266 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 267 // for a cross-site navigation. | 267 // for a cross-site navigation. |
| 268 // PlzNavigate: it is necessary to call PrepareForCommit before getting the | 268 // PlzNavigate: it is necessary to call PrepareForCommit before getting the |
| 269 // main and the pending frame because when we are trying to navigate to a | 269 // main and the pending frame because when we are trying to navigate to a |
| 270 // WebUI from a new tab, a RenderFrameHost is created to display it that is | 270 // WebUI from a new tab, a RenderFrameHost is created to display it that is |
| 271 // committed immediately (since it is a new tab). Therefore the main frame | 271 // committed immediately (since it is a new tab). Therefore the main frame |
| 272 // is replaced without a pending frame being created, and we don't get the | 272 // is replaced without a pending frame being created, and we don't get the |
| 273 // right values for the RFH to navigate: we try to use the old one that has | 273 // right values for the RFH to navigate: we try to use the old one that has |
| 274 // been deleted in the meantime. | 274 // been deleted in the meantime. |
| 275 contents()->GetMainFrame()->PrepareForCommit(url); | 275 contents()->GetMainFrame()->PrepareForCommit(); |
| 276 | 276 |
| 277 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); | 277 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); |
| 278 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() | 278 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() |
| 279 ? contents()->GetPendingMainFrame() | 279 ? contents()->GetPendingMainFrame() |
| 280 : old_rfh; | 280 : old_rfh; |
| 281 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); | 281 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); |
| 282 | 282 |
| 283 // Commit the navigation with a new page ID. | 283 // Commit the navigation with a new page ID. |
| 284 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 284 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
| 285 active_rfh->GetSiteInstance()); | 285 active_rfh->GetSiteInstance()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 const GURL kChromeURL("chrome://foo"); | 344 const GURL kChromeURL("chrome://foo"); |
| 345 const GURL kDestUrl("http://www.google.com/"); | 345 const GURL kDestUrl("http://www.google.com/"); |
| 346 | 346 |
| 347 // Navigate our first tab to a chrome url and then to the destination. | 347 // Navigate our first tab to a chrome url and then to the destination. |
| 348 NavigateActiveAndCommit(kChromeURL); | 348 NavigateActiveAndCommit(kChromeURL); |
| 349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
| 350 | 350 |
| 351 // Navigate to a cross-site URL. | 351 // Navigate to a cross-site URL. |
| 352 contents()->GetController().LoadURL( | 352 contents()->GetController().LoadURL( |
| 353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 354 contents()->GetMainFrame()->PrepareForCommit(kDestUrl); | 354 contents()->GetMainFrame()->PrepareForCommit(); |
| 355 EXPECT_TRUE(contents()->cross_navigation_pending()); | 355 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 356 | 356 |
| 357 // Manually increase the number of active frames in the | 357 // Manually increase the number of active frames in the |
| 358 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 358 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
| 359 // destroyed when it gets swapped out. | 359 // destroyed when it gets swapped out. |
| 360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); | 360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 361 | 361 |
| 362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
| 363 CHECK(dest_rfh); | 363 CHECK(dest_rfh); |
| 364 EXPECT_NE(ntp_rfh, dest_rfh); | 364 EXPECT_NE(ntp_rfh, dest_rfh); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 423 |
| 424 // Make a second tab. | 424 // Make a second tab. |
| 425 scoped_ptr<TestWebContents> contents2( | 425 scoped_ptr<TestWebContents> contents2( |
| 426 TestWebContents::Create(browser_context(), NULL)); | 426 TestWebContents::Create(browser_context(), NULL)); |
| 427 | 427 |
| 428 // Load the two URLs in the second tab. Note that the first navigation creates | 428 // Load the two URLs in the second tab. Note that the first navigation creates |
| 429 // a RFH that's not pending (since there is no cross-site transition), so | 429 // a RFH that's not pending (since there is no cross-site transition), so |
| 430 // we use the committed one. | 430 // we use the committed one. |
| 431 contents2->GetController().LoadURL( | 431 contents2->GetController().LoadURL( |
| 432 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 432 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 433 contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); | 433 contents2->GetMainFrame()->PrepareForCommit(); |
| 434 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 434 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
| 435 EXPECT_FALSE(contents2->cross_navigation_pending()); | 435 EXPECT_FALSE(contents2->cross_navigation_pending()); |
| 436 ntp_rfh2->SendNavigate(100, kChromeUrl); | 436 ntp_rfh2->SendNavigate(100, kChromeUrl); |
| 437 | 437 |
| 438 // The second one is the opposite, creating a cross-site transition and | 438 // The second one is the opposite, creating a cross-site transition and |
| 439 // requiring a beforeunload ack. | 439 // requiring a beforeunload ack. |
| 440 contents2->GetController().LoadURL( | 440 contents2->GetController().LoadURL( |
| 441 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 441 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 442 contents2->GetMainFrame()->PrepareForCommit(kDestUrl); | 442 contents2->GetMainFrame()->PrepareForCommit(); |
| 443 EXPECT_TRUE(contents2->cross_navigation_pending()); | 443 EXPECT_TRUE(contents2->cross_navigation_pending()); |
| 444 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 444 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
| 445 ASSERT_TRUE(dest_rfh2); | 445 ASSERT_TRUE(dest_rfh2); |
| 446 | 446 |
| 447 dest_rfh2->SendNavigate(101, kDestUrl); | 447 dest_rfh2->SendNavigate(101, kDestUrl); |
| 448 | 448 |
| 449 // The two RFH's should be different in every way. | 449 // The two RFH's should be different in every way. |
| 450 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 450 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
| 451 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 451 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
| 452 dest_rfh2->GetSiteInstance()); | 452 dest_rfh2->GetSiteInstance()); |
| 453 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 453 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
| 454 contents()->GetMainFrame()->GetSiteInstance())); | 454 contents()->GetMainFrame()->GetSiteInstance())); |
| 455 | 455 |
| 456 // Navigate both to the new tab page, and verify that they share a | 456 // Navigate both to the new tab page, and verify that they share a |
| 457 // RenderProcessHost (not a SiteInstance). | 457 // RenderProcessHost (not a SiteInstance). |
| 458 NavigateActiveAndCommit(kChromeUrl); | 458 NavigateActiveAndCommit(kChromeUrl); |
| 459 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 459 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
| 460 | 460 |
| 461 contents2->GetController().LoadURL( | 461 contents2->GetController().LoadURL( |
| 462 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 462 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 463 contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); | 463 contents2->GetMainFrame()->PrepareForCommit(); |
| 464 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 464 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); |
| 465 | 465 |
| 466 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 466 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
| 467 contents2->GetMainFrame()->GetSiteInstance()); | 467 contents2->GetMainFrame()->GetSiteInstance()); |
| 468 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 468 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
| 469 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 469 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 // Ensure that the browser ignores most IPC messages that arrive from a | 472 // Ensure that the browser ignores most IPC messages that arrive from a |
| 473 // RenderViewHost that has been swapped out. We do not want to take | 473 // RenderViewHost that has been swapped out. We do not want to take |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 // one will create a new SiteInstance. Because current_instance and | 788 // one will create a new SiteInstance. Because current_instance and |
| 789 // new_instance will be different, a new RenderViewHost will be created for | 789 // new_instance will be different, a new RenderViewHost will be created for |
| 790 // the second navigation. We have to avoid this in order to exercise the | 790 // the second navigation. We have to avoid this in order to exercise the |
| 791 // target code patch. | 791 // target code patch. |
| 792 NavigateActiveAndCommit(kChromeUrl); | 792 NavigateActiveAndCommit(kChromeUrl); |
| 793 | 793 |
| 794 // Navigate. | 794 // Navigate. |
| 795 controller().LoadURL( | 795 controller().LoadURL( |
| 796 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 796 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 797 // Simulate response from RenderFrame for DispatchBeforeUnload. | 797 // Simulate response from RenderFrame for DispatchBeforeUnload. |
| 798 contents()->GetMainFrame()->PrepareForCommit(kUrl); | 798 contents()->GetMainFrame()->PrepareForCommit(); |
| 799 ASSERT_TRUE(contents()->GetPendingMainFrame()) | 799 ASSERT_TRUE(contents()->GetPendingMainFrame()) |
| 800 << "Expected new pending RenderFrameHost to be created."; | 800 << "Expected new pending RenderFrameHost to be created."; |
| 801 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); | 801 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); |
| 802 int32 new_id = | 802 int32 new_id = |
| 803 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; | 803 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; |
| 804 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); | 804 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); |
| 805 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 805 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
| 806 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 806 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
| 807 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 807 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
| 808 EXPECT_FALSE(controller().GetPendingEntry()); | 808 EXPECT_FALSE(controller().GetPendingEntry()); |
| 809 // Because we're using TestWebContents and TestRenderViewHost in this | 809 // Because we're using TestWebContents and TestRenderViewHost in this |
| 810 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no | 810 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no |
| 811 // EnableViewSourceMode message, here. | 811 // EnableViewSourceMode message, here. |
| 812 | 812 |
| 813 // Clear queued messages before load. | 813 // Clear queued messages before load. |
| 814 process()->sink().ClearMessages(); | 814 process()->sink().ClearMessages(); |
| 815 // Navigate, again. | 815 // Navigate, again. |
| 816 controller().LoadURL( | 816 controller().LoadURL( |
| 817 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 817 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 818 contents()->GetMainFrame()->PrepareForCommit(kUrl); | 818 contents()->GetMainFrame()->PrepareForCommit(); |
| 819 // The same RenderViewHost should be reused. | 819 // The same RenderViewHost should be reused. |
| 820 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 820 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
| 821 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); | 821 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); |
| 822 // Navigate using the returned page_id. | 822 // Navigate using the returned page_id. |
| 823 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); | 823 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); |
| 824 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 824 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
| 825 EXPECT_FALSE(controller().GetPendingEntry()); | 825 EXPECT_FALSE(controller().GetPendingEntry()); |
| 826 // New message should be sent out to make sure to enter view-source mode. | 826 // New message should be sent out to make sure to enter view-source mode. |
| 827 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 827 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
| 828 ViewMsg_EnableViewSourceMode::ID)); | 828 ViewMsg_EnableViewSourceMode::ID)); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 // Navigate to a safe site, then an evil site. | 1068 // Navigate to a safe site, then an evil site. |
| 1069 // This will switch RenderFrameHosts. We cannot assert that the first and | 1069 // This will switch RenderFrameHosts. We cannot assert that the first and |
| 1070 // second RFHs are different, though, because the first one may be promptly | 1070 // second RFHs are different, though, because the first one may be promptly |
| 1071 // deleted. | 1071 // deleted. |
| 1072 contents()->NavigateAndCommit(kUrl1); | 1072 contents()->NavigateAndCommit(kUrl1); |
| 1073 contents()->NavigateAndCommit(kUrl2); | 1073 contents()->NavigateAndCommit(kUrl2); |
| 1074 TestRenderFrameHost* evil_rfh = contents()->GetMainFrame(); | 1074 TestRenderFrameHost* evil_rfh = contents()->GetMainFrame(); |
| 1075 | 1075 |
| 1076 // Now let's simulate the evil page calling history.back(). | 1076 // Now let's simulate the evil page calling history.back(). |
| 1077 contents()->OnGoToEntryAtOffset(-1); | 1077 contents()->OnGoToEntryAtOffset(-1); |
| 1078 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | 1078 contents()->GetMainFrame()->PrepareForCommit(); |
| 1079 // We should have a new pending RFH. | 1079 // We should have a new pending RFH. |
| 1080 // Note that in this case, the navigation has not committed, so evil_rfh will | 1080 // Note that in this case, the navigation has not committed, so evil_rfh will |
| 1081 // not be deleted yet. | 1081 // not be deleted yet. |
| 1082 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); | 1082 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); |
| 1083 EXPECT_NE(evil_rfh->GetRenderViewHost(), | 1083 EXPECT_NE(evil_rfh->GetRenderViewHost(), |
| 1084 contents()->GetPendingMainFrame()->GetRenderViewHost()); | 1084 contents()->GetPendingMainFrame()->GetRenderViewHost()); |
| 1085 | 1085 |
| 1086 // Before that RFH has committed, the evil page reloads itself. | 1086 // Before that RFH has committed, the evil page reloads itself. |
| 1087 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1087 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 1088 params.page_id = 1; | 1088 params.page_id = 1; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 | 1153 |
| 1154 contents()->NavigateAndCommit(kUrl2); | 1154 contents()->NavigateAndCommit(kUrl2); |
| 1155 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1155 TestRenderFrameHost* rfh2 = main_test_rfh(); |
| 1156 rfh2->GetSiteInstance()->increment_active_frame_count(); | 1156 rfh2->GetSiteInstance()->increment_active_frame_count(); |
| 1157 | 1157 |
| 1158 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1158 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
| 1159 // happen, but we have seen it when going back quickly across many entries | 1159 // happen, but we have seen it when going back quickly across many entries |
| 1160 // (http://crbug.com/93427). | 1160 // (http://crbug.com/93427). |
| 1161 contents()->GetController().GoBack(); | 1161 contents()->GetController().GoBack(); |
| 1162 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); | 1162 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); |
| 1163 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | 1163 contents()->GetMainFrame()->PrepareForCommit(); |
| 1164 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); | 1164 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); |
| 1165 | 1165 |
| 1166 // The back navigation commits. | 1166 // The back navigation commits. |
| 1167 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1167 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
| 1168 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1168 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
| 1169 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); | 1169 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
| 1170 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); | 1170 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); |
| 1171 | 1171 |
| 1172 // We should be able to navigate forward. | 1172 // We should be able to navigate forward. |
| 1173 contents()->GetController().GoForward(); | 1173 contents()->GetController().GoForward(); |
| 1174 contents()->GetMainFrame()->PrepareForCommit(kUrl2); | 1174 contents()->GetMainFrame()->PrepareForCommit(); |
| 1175 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1175 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
| 1176 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 1176 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
| 1177 EXPECT_EQ(rfh2, main_test_rfh()); | 1177 EXPECT_EQ(rfh2, main_test_rfh()); |
| 1178 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1178 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1179 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1179 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1180 rfh1->OnSwappedOut(); | 1180 rfh1->OnSwappedOut(); |
| 1181 EXPECT_TRUE(rfh1->is_swapped_out()); | 1181 EXPECT_TRUE(rfh1->is_swapped_out()); |
| 1182 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); | 1182 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); |
| 1183 } | 1183 } |
| 1184 | 1184 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 EXPECT_TRUE(contents()->HasOpener()); | 1335 EXPECT_TRUE(contents()->HasOpener()); |
| 1336 | 1336 |
| 1337 // Navigate to a cross-site URL (different SiteInstance but same | 1337 // Navigate to a cross-site URL (different SiteInstance but same |
| 1338 // BrowsingInstance). | 1338 // BrowsingInstance). |
| 1339 contents()->NavigateAndCommit(kUrl2); | 1339 contents()->NavigateAndCommit(kUrl2); |
| 1340 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1340 TestRenderFrameHost* rfh2 = main_test_rfh(); |
| 1341 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1341 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
| 1342 | 1342 |
| 1343 // Start a back navigation so that rfh1 becomes the pending RFH. | 1343 // Start a back navigation so that rfh1 becomes the pending RFH. |
| 1344 contents()->GetController().GoBack(); | 1344 contents()->GetController().GoBack(); |
| 1345 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | 1345 contents()->GetMainFrame()->PrepareForCommit(); |
| 1346 | 1346 |
| 1347 // Disown the opener from rfh2. | 1347 // Disown the opener from rfh2. |
| 1348 rfh2->DidDisownOpener(); | 1348 rfh2->DidDisownOpener(); |
| 1349 | 1349 |
| 1350 // Ensure the opener is cleared. | 1350 // Ensure the opener is cleared. |
| 1351 EXPECT_FALSE(contents()->HasOpener()); | 1351 EXPECT_FALSE(contents()->HasOpener()); |
| 1352 | 1352 |
| 1353 // The back navigation commits. | 1353 // The back navigation commits. |
| 1354 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1354 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
| 1355 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1355 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1376 | 1376 |
| 1377 // Navigate to a cross-site URL (different SiteInstance but same | 1377 // Navigate to a cross-site URL (different SiteInstance but same |
| 1378 // BrowsingInstance). | 1378 // BrowsingInstance). |
| 1379 contents()->NavigateAndCommit(kUrl2); | 1379 contents()->NavigateAndCommit(kUrl2); |
| 1380 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1380 TestRenderFrameHost* rfh2 = main_test_rfh(); |
| 1381 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1381 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
| 1382 | 1382 |
| 1383 // Commit a back navigation before the DidDisownOpener message arrives. | 1383 // Commit a back navigation before the DidDisownOpener message arrives. |
| 1384 // rfh1 will be kept alive because of the opener tab. | 1384 // rfh1 will be kept alive because of the opener tab. |
| 1385 contents()->GetController().GoBack(); | 1385 contents()->GetController().GoBack(); |
| 1386 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | 1386 contents()->GetMainFrame()->PrepareForCommit(); |
| 1387 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1387 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
| 1388 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1388 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
| 1389 | 1389 |
| 1390 // Disown the opener from rfh2. | 1390 // Disown the opener from rfh2. |
| 1391 rfh2->DidDisownOpener(); | 1391 rfh2->DidDisownOpener(); |
| 1392 EXPECT_FALSE(contents()->HasOpener()); | 1392 EXPECT_FALSE(contents()->HasOpener()); |
| 1393 } | 1393 } |
| 1394 | 1394 |
| 1395 // Test that we clean up swapped out RenderViewHosts when a process hosting | 1395 // Test that we clean up swapped out RenderViewHosts when a process hosting |
| 1396 // those associated RenderViews crashes. http://crbug.com/258993 | 1396 // those associated RenderViews crashes. http://crbug.com/258993 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 EXPECT_TRUE(render_frame_proxy_host); | 1442 EXPECT_TRUE(render_frame_proxy_host); |
| 1443 EXPECT_FALSE(render_frame_proxy_host->is_render_frame_proxy_live()); | 1443 EXPECT_FALSE(render_frame_proxy_host->is_render_frame_proxy_live()); |
| 1444 | 1444 |
| 1445 // Expect the swapped out RVH to exist. | 1445 // Expect the swapped out RVH to exist. |
| 1446 EXPECT_TRUE(opener1_manager->GetSwappedOutRenderViewHost( | 1446 EXPECT_TRUE(opener1_manager->GetSwappedOutRenderViewHost( |
| 1447 rvh1->GetSiteInstance())); | 1447 rvh1->GetSiteInstance())); |
| 1448 | 1448 |
| 1449 // Reload the initial tab. This should recreate the opener's swapped out RVH | 1449 // Reload the initial tab. This should recreate the opener's swapped out RVH |
| 1450 // in the original SiteInstance. | 1450 // in the original SiteInstance. |
| 1451 contents()->GetController().Reload(true); | 1451 contents()->GetController().Reload(true); |
| 1452 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | 1452 contents()->GetMainFrame()->PrepareForCommit(); |
| 1453 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( | 1453 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( |
| 1454 rvh1->GetSiteInstance())->GetRoutingID(), | 1454 rvh1->GetSiteInstance())->GetRoutingID(), |
| 1455 test_rvh()->opener_route_id()); | 1455 test_rvh()->opener_route_id()); |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 // Test that RenderViewHosts created for WebUI navigations are properly | 1458 // Test that RenderViewHosts created for WebUI navigations are properly |
| 1459 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost | 1459 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost |
| 1460 // is in the same process (http://crbug.com/79918). | 1460 // is in the same process (http://crbug.com/79918). |
| 1461 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { | 1461 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { |
| 1462 set_should_create_webui(true); | 1462 set_should_create_webui(true); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 | 1637 |
| 1638 // Start to close the tab, but assume it's unresponsive. | 1638 // Start to close the tab, but assume it's unresponsive. |
| 1639 rfh1->render_view_host()->ClosePage(); | 1639 rfh1->render_view_host()->ClosePage(); |
| 1640 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1640 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
| 1641 | 1641 |
| 1642 // Start a navigation to a new site. | 1642 // Start a navigation to a new site. |
| 1643 controller().LoadURL( | 1643 controller().LoadURL( |
| 1644 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1644 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1645 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1645 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1646 switches::kEnableBrowserSideNavigation)) { | 1646 switches::kEnableBrowserSideNavigation)) { |
| 1647 rfh1->PrepareForCommit(kUrl2); | 1647 rfh1->PrepareForCommit(); |
| 1648 } | 1648 } |
| 1649 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1649 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1650 | 1650 |
| 1651 // Simulate the unresponsiveness timer. The tab should close. | 1651 // Simulate the unresponsiveness timer. The tab should close. |
| 1652 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1652 contents()->RendererUnresponsive(rfh1->render_view_host()); |
| 1653 EXPECT_TRUE(close_delegate.is_closed()); | 1653 EXPECT_TRUE(close_delegate.is_closed()); |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1656 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
| 1657 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1657 // received. (SwapOut and the corresponding ACK always occur after commit.) |
| 1658 // Also tests that an early SwapOutACK is properly ignored. | 1658 // Also tests that an early SwapOutACK is properly ignored. |
| 1659 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1659 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
| 1660 const GURL kUrl1("http://www.google.com/"); | 1660 const GURL kUrl1("http://www.google.com/"); |
| 1661 const GURL kUrl2("http://www.chromium.org/"); | 1661 const GURL kUrl2("http://www.chromium.org/"); |
| 1662 | 1662 |
| 1663 // Navigate to the first page. | 1663 // Navigate to the first page. |
| 1664 contents()->NavigateAndCommit(kUrl1); | 1664 contents()->NavigateAndCommit(kUrl1); |
| 1665 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1665 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1666 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1666 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
| 1667 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1667 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1668 | 1668 |
| 1669 // Navigate to new site, simulating onbeforeunload approval. | 1669 // Navigate to new site, simulating onbeforeunload approval. |
| 1670 controller().LoadURL( | 1670 controller().LoadURL( |
| 1671 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1671 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1672 contents()->GetMainFrame()->PrepareForCommit(kUrl2); | 1672 contents()->GetMainFrame()->PrepareForCommit(); |
| 1673 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1673 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1674 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1674 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1675 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1675 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1676 | 1676 |
| 1677 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1677 // Simulate the swap out ack, unexpectedly early (before commit). It should |
| 1678 // have no effect. | 1678 // have no effect. |
| 1679 rfh1->OnSwappedOut(); | 1679 rfh1->OnSwappedOut(); |
| 1680 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1680 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1681 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1681 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1682 | 1682 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1710 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1710 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
| 1711 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1711 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1712 | 1712 |
| 1713 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1713 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1714 // not deleted on swap out. | 1714 // not deleted on swap out. |
| 1715 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1715 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1716 | 1716 |
| 1717 // Navigate to new site, simulating onbeforeunload approval. | 1717 // Navigate to new site, simulating onbeforeunload approval. |
| 1718 controller().LoadURL( | 1718 controller().LoadURL( |
| 1719 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1719 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1720 contents()->GetMainFrame()->PrepareForCommit(kUrl2); | 1720 contents()->GetMainFrame()->PrepareForCommit(); |
| 1721 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1721 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1722 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1722 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1723 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1723 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1724 | 1724 |
| 1725 // The new page commits. | 1725 // The new page commits. |
| 1726 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1726 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1727 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1727 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 1728 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1728 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1729 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1729 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1730 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1730 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1753 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1753 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
| 1754 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1754 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1755 | 1755 |
| 1756 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1756 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1757 // not deleted on swap out. | 1757 // not deleted on swap out. |
| 1758 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1758 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1759 | 1759 |
| 1760 // Navigate to new site, simulating onbeforeunload approval. | 1760 // Navigate to new site, simulating onbeforeunload approval. |
| 1761 controller().LoadURL( | 1761 controller().LoadURL( |
| 1762 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1762 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1763 rfh1->PrepareForCommit(kUrl2); | 1763 rfh1->PrepareForCommit(); |
| 1764 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1764 EXPECT_TRUE(contents()->cross_navigation_pending()); |
| 1765 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1765 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1766 | 1766 |
| 1767 // The new page commits. | 1767 // The new page commits. |
| 1768 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1768 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1769 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1769 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 1770 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1770 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1771 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1771 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1772 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1772 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1773 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1773 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 #if 0 | 1907 #if 0 |
| 1908 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. | 1908 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. |
| 1909 // Enable this assert below once the proxies to the subframe are correctly | 1909 // Enable this assert below once the proxies to the subframe are correctly |
| 1910 // cleaned up after detach. http://crbug.com/444955. | 1910 // cleaned up after detach. http://crbug.com/444955. |
| 1911 ASSERT_TRUE(site_instance->HasOneRef()) | 1911 ASSERT_TRUE(site_instance->HasOneRef()) |
| 1912 << "This SiteInstance should be destroyable now."; | 1912 << "This SiteInstance should be destroyable now."; |
| 1913 #endif | 1913 #endif |
| 1914 } | 1914 } |
| 1915 | 1915 |
| 1916 } // namespace content | 1916 } // namespace content |
| OLD | NEW |