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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 void set_should_create_webui(bool should_create_webui) { | 254 void set_should_create_webui(bool should_create_webui) { |
255 factory_.set_should_create_webui(should_create_webui); | 255 factory_.set_should_create_webui(should_create_webui); |
256 } | 256 } |
257 | 257 |
258 void NavigateActiveAndCommit(const GURL& url) { | 258 void NavigateActiveAndCommit(const GURL& url) { |
259 // Note: we navigate the active RenderFrameHost because previous navigations | 259 // Note: we navigate the active RenderFrameHost because previous navigations |
260 // won't have committed yet, so NavigateAndCommit does the wrong thing | 260 // won't have committed yet, so NavigateAndCommit does the wrong thing |
261 // for us. | 261 // for us. |
262 controller().LoadURL( | 262 controller().LoadURL( |
263 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 263 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
264 | |
265 // Simulate the BeforeUnload_ACK that is received from the current renderer | |
266 // for a cross-site navigation. | |
267 contents()->GetMainFrame()->PrepareForCommit(url); | |
clamy
2015/01/13 12:41:59
It was necessary to move this above the part where
nasko
2015/01/17 00:22:01
Can you put some of this explanation in the actual
clamy
2015/01/19 17:29:20
Done.
| |
268 | |
264 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); | 269 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); |
265 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() | 270 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() |
266 ? contents()->GetPendingMainFrame() | 271 ? contents()->GetPendingMainFrame() |
267 : old_rfh; | 272 : old_rfh; |
268 | 273 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); |
269 // Simulate the BeforeUnload_ACK that is received from the current renderer | |
270 // for a cross-site navigation. | |
271 if (old_rfh != active_rfh) { | |
272 old_rfh->SendBeforeUnloadACK(true); | |
273 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); | |
274 } | |
275 | 274 |
276 // Commit the navigation with a new page ID. | 275 // Commit the navigation with a new page ID. |
277 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 276 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
278 active_rfh->GetSiteInstance()); | 277 active_rfh->GetSiteInstance()); |
279 | 278 |
280 // Use an observer to avoid accessing a deleted renderer later on when the | 279 // Use an observer to avoid accessing a deleted renderer later on when the |
281 // state is being checked. | 280 // state is being checked. |
282 RenderFrameHostDeletedObserver rfh_observer(old_rfh); | 281 RenderFrameHostDeletedObserver rfh_observer(old_rfh); |
283 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); | 282 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); |
284 active_rfh->SendNavigate(max_page_id + 1, url); | 283 active_rfh->SendNavigate(max_page_id + 1, url); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 const GURL kChromeURL("chrome://foo"); | 336 const GURL kChromeURL("chrome://foo"); |
338 const GURL kDestUrl("http://www.google.com/"); | 337 const GURL kDestUrl("http://www.google.com/"); |
339 | 338 |
340 // Navigate our first tab to a chrome url and then to the destination. | 339 // Navigate our first tab to a chrome url and then to the destination. |
341 NavigateActiveAndCommit(kChromeURL); | 340 NavigateActiveAndCommit(kChromeURL); |
342 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 341 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
343 | 342 |
344 // Navigate to a cross-site URL. | 343 // Navigate to a cross-site URL. |
345 contents()->GetController().LoadURL( | 344 contents()->GetController().LoadURL( |
346 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 345 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
346 contents()->GetMainFrame()->PrepareForCommit(kDestUrl); | |
347 EXPECT_TRUE(contents()->cross_navigation_pending()); | 347 EXPECT_TRUE(contents()->cross_navigation_pending()); |
348 | 348 |
349 // Manually increase the number of active frames in the | 349 // Manually increase the number of active frames in the |
350 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 350 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
351 // destroyed when it gets swapped out. | 351 // destroyed when it gets swapped out. |
352 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); | 352 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
353 | 353 |
354 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 354 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
355 CHECK(dest_rfh); | 355 CHECK(dest_rfh); |
356 EXPECT_NE(ntp_rfh, dest_rfh); | 356 EXPECT_NE(ntp_rfh, dest_rfh); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 | 388 |
389 // Make a second tab. | 389 // Make a second tab. |
390 scoped_ptr<TestWebContents> contents2( | 390 scoped_ptr<TestWebContents> contents2( |
391 TestWebContents::Create(browser_context(), NULL)); | 391 TestWebContents::Create(browser_context(), NULL)); |
392 | 392 |
393 // Load the two URLs in the second tab. Note that the first navigation creates | 393 // Load the two URLs in the second tab. Note that the first navigation creates |
394 // a RFH that's not pending (since there is no cross-site transition), so | 394 // a RFH that's not pending (since there is no cross-site transition), so |
395 // we use the committed one. | 395 // we use the committed one. |
396 contents2->GetController().LoadURL( | 396 contents2->GetController().LoadURL( |
397 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 397 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
398 contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); | |
398 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 399 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
399 EXPECT_FALSE(contents2->cross_navigation_pending()); | 400 EXPECT_FALSE(contents2->cross_navigation_pending()); |
400 ntp_rfh2->SendNavigate(100, kChromeUrl); | 401 ntp_rfh2->SendNavigate(100, kChromeUrl); |
401 | 402 |
402 // The second one is the opposite, creating a cross-site transition and | 403 // The second one is the opposite, creating a cross-site transition and |
403 // requiring a beforeunload ack. | 404 // requiring a beforeunload ack. |
404 contents2->GetController().LoadURL( | 405 contents2->GetController().LoadURL( |
405 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 406 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
407 contents2->GetMainFrame()->PrepareForCommit(kDestUrl); | |
406 EXPECT_TRUE(contents2->cross_navigation_pending()); | 408 EXPECT_TRUE(contents2->cross_navigation_pending()); |
407 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 409 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
408 ASSERT_TRUE(dest_rfh2); | 410 ASSERT_TRUE(dest_rfh2); |
409 | 411 |
410 ntp_rfh2->SendBeforeUnloadACK(true); | |
411 dest_rfh2->SendNavigate(101, kDestUrl); | 412 dest_rfh2->SendNavigate(101, kDestUrl); |
412 | 413 |
413 // The two RFH's should be different in every way. | 414 // The two RFH's should be different in every way. |
414 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 415 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
415 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 416 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
416 dest_rfh2->GetSiteInstance()); | 417 dest_rfh2->GetSiteInstance()); |
417 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 418 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
418 contents()->GetMainFrame()->GetSiteInstance())); | 419 contents()->GetMainFrame()->GetSiteInstance())); |
419 | 420 |
420 // Navigate both to the new tab page, and verify that they share a | 421 // Navigate both to the new tab page, and verify that they share a |
421 // RenderProcessHost (not a SiteInstance). | 422 // RenderProcessHost (not a SiteInstance). |
422 NavigateActiveAndCommit(kChromeUrl); | 423 NavigateActiveAndCommit(kChromeUrl); |
423 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 424 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
424 | 425 |
425 contents2->GetController().LoadURL( | 426 contents2->GetController().LoadURL( |
426 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 427 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
427 dest_rfh2->SendBeforeUnloadACK(true); | 428 contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); |
428 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 429 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); |
429 | 430 |
430 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 431 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
431 contents2->GetMainFrame()->GetSiteInstance()); | 432 contents2->GetMainFrame()->GetSiteInstance()); |
432 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 433 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
433 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 434 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
434 } | 435 } |
435 | 436 |
436 // Ensure that the browser ignores most IPC messages that arrive from a | 437 // Ensure that the browser ignores most IPC messages that arrive from a |
437 // RenderViewHost that has been swapped out. We do not want to take | 438 // RenderViewHost that has been swapped out. We do not want to take |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 // one will create a new SiteInstance. Because current_instance and | 751 // one will create a new SiteInstance. Because current_instance and |
751 // new_instance will be different, a new RenderViewHost will be created for | 752 // new_instance will be different, a new RenderViewHost will be created for |
752 // the second navigation. We have to avoid this in order to exercise the | 753 // the second navigation. We have to avoid this in order to exercise the |
753 // target code patch. | 754 // target code patch. |
754 NavigateActiveAndCommit(kChromeUrl); | 755 NavigateActiveAndCommit(kChromeUrl); |
755 | 756 |
756 // Navigate. | 757 // Navigate. |
757 controller().LoadURL( | 758 controller().LoadURL( |
758 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 759 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
759 // Simulate response from RenderFrame for DispatchBeforeUnload. | 760 // Simulate response from RenderFrame for DispatchBeforeUnload. |
760 base::TimeTicks now = base::TimeTicks::Now(); | 761 contents()->GetMainFrame()->PrepareForCommit(kUrl); |
761 contents()->GetMainFrame()->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK( | |
762 contents()->GetMainFrame()->GetRoutingID(), true, now, now)); | |
763 ASSERT_TRUE(contents()->GetPendingMainFrame()) | 762 ASSERT_TRUE(contents()->GetPendingMainFrame()) |
764 << "Expected new pending RenderFrameHost to be created."; | 763 << "Expected new pending RenderFrameHost to be created."; |
765 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); | 764 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); |
766 int32 new_id = | 765 int32 new_id = |
767 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; | 766 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; |
768 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); | 767 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); |
769 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 768 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
770 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 769 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
771 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 770 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
772 EXPECT_FALSE(controller().GetPendingEntry()); | 771 EXPECT_FALSE(controller().GetPendingEntry()); |
773 // Because we're using TestWebContents and TestRenderViewHost in this | 772 // Because we're using TestWebContents and TestRenderViewHost in this |
774 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no | 773 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no |
775 // EnableViewSourceMode message, here. | 774 // EnableViewSourceMode message, here. |
776 | 775 |
777 // Clear queued messages before load. | 776 // Clear queued messages before load. |
778 process()->sink().ClearMessages(); | 777 process()->sink().ClearMessages(); |
779 // Navigate, again. | 778 // Navigate, again. |
780 controller().LoadURL( | 779 controller().LoadURL( |
781 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 780 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
781 contents()->GetMainFrame()->PrepareForCommit(kUrl); | |
782 // The same RenderViewHost should be reused. | 782 // The same RenderViewHost should be reused. |
783 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 783 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
784 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); | 784 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); |
785 // Navigate using the returned page_id. | 785 // Navigate using the returned page_id. |
786 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); | 786 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); |
787 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 787 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
788 EXPECT_FALSE(controller().GetPendingEntry()); | 788 EXPECT_FALSE(controller().GetPendingEntry()); |
789 // New message should be sent out to make sure to enter view-source mode. | 789 // New message should be sent out to make sure to enter view-source mode. |
790 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 790 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
791 ViewMsg_EnableViewSourceMode::ID)); | 791 ViewMsg_EnableViewSourceMode::ID)); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1015 // Navigate to a safe site, then an evil site. | 1015 // Navigate to a safe site, then an evil site. |
1016 // This will switch RenderFrameHosts. We cannot assert that the first and | 1016 // This will switch RenderFrameHosts. We cannot assert that the first and |
1017 // second RFHs are different, though, because the first one may be promptly | 1017 // second RFHs are different, though, because the first one may be promptly |
1018 // deleted. | 1018 // deleted. |
1019 contents()->NavigateAndCommit(kUrl1); | 1019 contents()->NavigateAndCommit(kUrl1); |
1020 contents()->NavigateAndCommit(kUrl2); | 1020 contents()->NavigateAndCommit(kUrl2); |
1021 TestRenderFrameHost* evil_rfh = contents()->GetMainFrame(); | 1021 TestRenderFrameHost* evil_rfh = contents()->GetMainFrame(); |
1022 | 1022 |
1023 // Now let's simulate the evil page calling history.back(). | 1023 // Now let's simulate the evil page calling history.back(). |
1024 contents()->OnGoToEntryAtOffset(-1); | 1024 contents()->OnGoToEntryAtOffset(-1); |
1025 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | |
1025 // We should have a new pending RFH. | 1026 // We should have a new pending RFH. |
1026 // Note that in this case, the navigation has not committed, so evil_rfh will | 1027 // Note that in this case, the navigation has not committed, so evil_rfh will |
1027 // not be deleted yet. | 1028 // not be deleted yet. |
1028 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); | 1029 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); |
1029 EXPECT_NE(evil_rfh->GetRenderViewHost(), | 1030 EXPECT_NE(evil_rfh->GetRenderViewHost(), |
1030 contents()->GetPendingMainFrame()->GetRenderViewHost()); | 1031 contents()->GetPendingMainFrame()->GetRenderViewHost()); |
1031 | 1032 |
1032 // Before that RFH has committed, the evil page reloads itself. | 1033 // Before that RFH has committed, the evil page reloads itself. |
1033 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1034 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1034 params.page_id = 1; | 1035 params.page_id = 1; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1098 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1099 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1099 | 1100 |
1100 contents()->NavigateAndCommit(kUrl2); | 1101 contents()->NavigateAndCommit(kUrl2); |
1101 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1102 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1102 rfh2->GetSiteInstance()->increment_active_frame_count(); | 1103 rfh2->GetSiteInstance()->increment_active_frame_count(); |
1103 | 1104 |
1104 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1105 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
1105 // happen, but we have seen it when going back quickly across many entries | 1106 // happen, but we have seen it when going back quickly across many entries |
1106 // (http://crbug.com/93427). | 1107 // (http://crbug.com/93427). |
1107 contents()->GetController().GoBack(); | 1108 contents()->GetController().GoBack(); |
1108 EXPECT_TRUE(rfh2->is_waiting_for_beforeunload_ack()); | 1109 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); |
1109 contents()->ProceedWithCrossSiteNavigation(); | 1110 contents()->GetMainFrame()->PrepareForCommit(kUrl1); |
1110 EXPECT_FALSE(rfh2->is_waiting_for_beforeunload_ack()); | 1111 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); |
1111 | 1112 |
1112 // The back navigation commits. | 1113 // The back navigation commits. |
1113 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1114 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1114 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1115 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
1115 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); | 1116 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
1116 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); | 1117 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); |
1117 | 1118 |
1118 // We should be able to navigate forward. | 1119 // We should be able to navigate forward. |
1119 contents()->GetController().GoForward(); | 1120 contents()->GetController().GoForward(); |
1120 contents()->ProceedWithCrossSiteNavigation(); | 1121 contents()->GetMainFrame()->PrepareForCommit(kUrl2); |
1121 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1122 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
1122 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 1123 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
1123 EXPECT_EQ(rfh2, main_test_rfh()); | 1124 EXPECT_EQ(rfh2, main_test_rfh()); |
1124 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1125 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1125 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1126 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1126 rfh1->OnSwappedOut(); | 1127 rfh1->OnSwappedOut(); |
1127 EXPECT_TRUE(rfh1->is_swapped_out()); | 1128 EXPECT_TRUE(rfh1->is_swapped_out()); |
1128 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); | 1129 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); |
1129 } | 1130 } |
1130 | 1131 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 EXPECT_TRUE(contents()->HasOpener()); | 1282 EXPECT_TRUE(contents()->HasOpener()); |
1282 | 1283 |
1283 // Navigate to a cross-site URL (different SiteInstance but same | 1284 // Navigate to a cross-site URL (different SiteInstance but same |
1284 // BrowsingInstance). | 1285 // BrowsingInstance). |
1285 contents()->NavigateAndCommit(kUrl2); | 1286 contents()->NavigateAndCommit(kUrl2); |
1286 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1287 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1287 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1288 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
1288 | 1289 |
1289 // Start a back navigation so that rfh1 becomes the pending RFH. | 1290 // Start a back navigation so that rfh1 becomes the pending RFH. |
1290 contents()->GetController().GoBack(); | 1291 contents()->GetController().GoBack(); |
1291 contents()->ProceedWithCrossSiteNavigation(); | 1292 contents()->GetMainFrame()->PrepareForCommit(kUrl1); |
1292 | 1293 |
1293 // Disown the opener from rfh2. | 1294 // Disown the opener from rfh2. |
1294 rfh2->DidDisownOpener(); | 1295 rfh2->DidDisownOpener(); |
1295 | 1296 |
1296 // Ensure the opener is cleared. | 1297 // Ensure the opener is cleared. |
1297 EXPECT_FALSE(contents()->HasOpener()); | 1298 EXPECT_FALSE(contents()->HasOpener()); |
1298 | 1299 |
1299 // The back navigation commits. | 1300 // The back navigation commits. |
1300 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1301 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1301 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1302 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
(...skipping 20 matching lines...) Expand all Loading... | |
1322 | 1323 |
1323 // Navigate to a cross-site URL (different SiteInstance but same | 1324 // Navigate to a cross-site URL (different SiteInstance but same |
1324 // BrowsingInstance). | 1325 // BrowsingInstance). |
1325 contents()->NavigateAndCommit(kUrl2); | 1326 contents()->NavigateAndCommit(kUrl2); |
1326 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1327 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1327 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1328 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
1328 | 1329 |
1329 // Commit a back navigation before the DidDisownOpener message arrives. | 1330 // Commit a back navigation before the DidDisownOpener message arrives. |
1330 // rfh1 will be kept alive because of the opener tab. | 1331 // rfh1 will be kept alive because of the opener tab. |
1331 contents()->GetController().GoBack(); | 1332 contents()->GetController().GoBack(); |
1332 contents()->ProceedWithCrossSiteNavigation(); | 1333 contents()->GetMainFrame()->PrepareForCommit(kUrl1); |
1333 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1334 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1334 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1335 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
1335 | 1336 |
1336 // Disown the opener from rfh2. | 1337 // Disown the opener from rfh2. |
1337 rfh2->DidDisownOpener(); | 1338 rfh2->DidDisownOpener(); |
1338 EXPECT_FALSE(contents()->HasOpener()); | 1339 EXPECT_FALSE(contents()->HasOpener()); |
1339 } | 1340 } |
1340 | 1341 |
1341 // Test that we clean up swapped out RenderViewHosts when a process hosting | 1342 // Test that we clean up swapped out RenderViewHosts when a process hosting |
1342 // those associated RenderViews crashes. http://crbug.com/258993 | 1343 // those associated RenderViews crashes. http://crbug.com/258993 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 Details<RenderProcessHost::RendererClosedDetails>(&details)); | 1379 Details<RenderProcessHost::RendererClosedDetails>(&details)); |
1379 rvh1->set_render_view_created(false); | 1380 rvh1->set_render_view_created(false); |
1380 | 1381 |
1381 // Ensure that the swapped out RenderViewHost has been deleted. | 1382 // Ensure that the swapped out RenderViewHost has been deleted. |
1382 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( | 1383 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
1383 rvh1->GetSiteInstance())); | 1384 rvh1->GetSiteInstance())); |
1384 | 1385 |
1385 // Reload the initial tab. This should recreate the opener's swapped out RVH | 1386 // Reload the initial tab. This should recreate the opener's swapped out RVH |
1386 // in the original SiteInstance. | 1387 // in the original SiteInstance. |
1387 contents()->GetController().Reload(true); | 1388 contents()->GetController().Reload(true); |
1389 contents()->GetMainFrame()->PrepareForCommit(kUrl1); | |
1388 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( | 1390 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( |
1389 rvh1->GetSiteInstance())->GetRoutingID(), | 1391 rvh1->GetSiteInstance())->GetRoutingID(), |
1390 test_rvh()->opener_route_id()); | 1392 test_rvh()->opener_route_id()); |
1391 } | 1393 } |
1392 | 1394 |
1393 // Test that RenderViewHosts created for WebUI navigations are properly | 1395 // Test that RenderViewHosts created for WebUI navigations are properly |
1394 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost | 1396 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost |
1395 // is in the same process (http://crbug.com/79918). | 1397 // is in the same process (http://crbug.com/79918). |
1396 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { | 1398 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { |
1397 set_should_create_webui(true); | 1399 set_should_create_webui(true); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1570 contents()->NavigateAndCommit(kUrl1); | 1572 contents()->NavigateAndCommit(kUrl1); |
1571 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1573 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1572 | 1574 |
1573 // Start to close the tab, but assume it's unresponsive. | 1575 // Start to close the tab, but assume it's unresponsive. |
1574 rfh1->render_view_host()->ClosePage(); | 1576 rfh1->render_view_host()->ClosePage(); |
1575 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1577 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
1576 | 1578 |
1577 // Start a navigation to a new site. | 1579 // Start a navigation to a new site. |
1578 controller().LoadURL( | 1580 controller().LoadURL( |
1579 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1581 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1582 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1583 switches::kEnableBrowserSideNavigation)) { | |
1584 rfh1->PrepareForCommit(kUrl2); | |
1585 } | |
1580 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1586 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1581 | 1587 |
1582 // Simulate the unresponsiveness timer. The tab should close. | 1588 // Simulate the unresponsiveness timer. The tab should close. |
1583 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1589 contents()->RendererUnresponsive(rfh1->render_view_host()); |
1584 EXPECT_TRUE(close_delegate.is_closed()); | 1590 EXPECT_TRUE(close_delegate.is_closed()); |
1585 } | 1591 } |
1586 | 1592 |
1587 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1593 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
1588 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1594 // received. (SwapOut and the corresponding ACK always occur after commit.) |
1589 // Also tests that an early SwapOutACK is properly ignored. | 1595 // Also tests that an early SwapOutACK is properly ignored. |
1590 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1596 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
1591 const GURL kUrl1("http://www.google.com/"); | 1597 const GURL kUrl1("http://www.google.com/"); |
1592 const GURL kUrl2("http://www.chromium.org/"); | 1598 const GURL kUrl2("http://www.chromium.org/"); |
1593 | 1599 |
1594 // Navigate to the first page. | 1600 // Navigate to the first page. |
1595 contents()->NavigateAndCommit(kUrl1); | 1601 contents()->NavigateAndCommit(kUrl1); |
1596 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1602 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1597 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1603 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1598 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1604 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1599 | 1605 |
1600 // Navigate to new site, simulating onbeforeunload approval. | 1606 // Navigate to new site, simulating onbeforeunload approval. |
1601 controller().LoadURL( | 1607 controller().LoadURL( |
1602 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1608 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1603 base::TimeTicks now = base::TimeTicks::Now(); | 1609 contents()->GetMainFrame()->PrepareForCommit(kUrl2); |
1604 contents()->GetMainFrame()->OnMessageReceived( | |
1605 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1606 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1610 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1607 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1611 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1608 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1612 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1609 | 1613 |
1610 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1614 // Simulate the swap out ack, unexpectedly early (before commit). It should |
1611 // have no effect. | 1615 // have no effect. |
1612 rfh1->OnSwappedOut(); | 1616 rfh1->OnSwappedOut(); |
1613 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1617 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1614 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1618 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1615 | 1619 |
(...skipping 27 matching lines...) Expand all Loading... | |
1643 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1647 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1644 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1648 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1645 | 1649 |
1646 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1650 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1647 // not deleted on swap out. | 1651 // not deleted on swap out. |
1648 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1652 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1649 | 1653 |
1650 // Navigate to new site, simulating onbeforeunload approval. | 1654 // Navigate to new site, simulating onbeforeunload approval. |
1651 controller().LoadURL( | 1655 controller().LoadURL( |
1652 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1656 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1653 base::TimeTicks now = base::TimeTicks::Now(); | 1657 contents()->GetMainFrame()->PrepareForCommit(kUrl2); |
1654 contents()->GetMainFrame()->OnMessageReceived( | |
1655 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1656 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1658 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1657 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1659 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1658 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1660 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1659 | 1661 |
1660 // The new page commits. | 1662 // The new page commits. |
1661 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1663 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1662 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1664 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1663 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1665 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1664 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1666 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1665 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1667 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
(...skipping 22 matching lines...) Expand all Loading... | |
1688 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1690 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1689 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1691 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1690 | 1692 |
1691 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1693 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1692 // not deleted on swap out. | 1694 // not deleted on swap out. |
1693 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1695 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1694 | 1696 |
1695 // Navigate to new site, simulating onbeforeunload approval. | 1697 // Navigate to new site, simulating onbeforeunload approval. |
1696 controller().LoadURL( | 1698 controller().LoadURL( |
1697 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1699 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1698 base::TimeTicks now = base::TimeTicks::Now(); | 1700 rfh1->PrepareForCommit(kUrl2); |
1699 rfh1->OnMessageReceived( | |
1700 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | |
1701 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1701 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1702 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1702 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1703 | 1703 |
1704 // The new page commits. | 1704 // The new page commits. |
1705 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1705 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1706 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1706 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1707 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1707 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1708 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1708 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1709 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1709 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1710 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1710 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1844 #if 0 | 1844 #if 0 |
1845 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. | 1845 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. |
1846 // Enable this assert below once the proxies to the subframe are correctly | 1846 // Enable this assert below once the proxies to the subframe are correctly |
1847 // cleaned up after detach. http://crbug.com/444955. | 1847 // cleaned up after detach. http://crbug.com/444955. |
1848 ASSERT_TRUE(site_instance->HasOneRef()) | 1848 ASSERT_TRUE(site_instance->HasOneRef()) |
1849 << "This SiteInstance should be destroyable now."; | 1849 << "This SiteInstance should be destroyable now."; |
1850 #endif | 1850 #endif |
1851 } | 1851 } |
1852 | 1852 |
1853 } // namespace content | 1853 } // namespace content |
OLD | NEW |