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/compositor/test/no_transport_image_transport_factory.h
" | 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // state is being checked. | 323 // state is being checked. |
324 RenderFrameHostDeletedObserver rfh_observer(old_rfh); | 324 RenderFrameHostDeletedObserver rfh_observer(old_rfh); |
325 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); | 325 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); |
326 active_rfh->SendNavigate(max_page_id + 1, entry_id, true, url); | 326 active_rfh->SendNavigate(max_page_id + 1, entry_id, true, url); |
327 | 327 |
328 // Make sure that we start to run the unload handler at the time of commit. | 328 // Make sure that we start to run the unload handler at the time of commit. |
329 bool expecting_rfh_shutdown = false; | 329 bool expecting_rfh_shutdown = false; |
330 if (old_rfh != active_rfh && !rfh_observer.deleted()) { | 330 if (old_rfh != active_rfh && !rfh_observer.deleted()) { |
331 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, | 331 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, |
332 old_rfh->rfh_state()); | 332 old_rfh->rfh_state()); |
333 if (!old_rfh->GetSiteInstance()->active_frame_count()) { | 333 if (!old_rfh->GetSiteInstance()->active_frame_count() || |
| 334 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 335 switches::kSitePerProcess)) { |
334 expecting_rfh_shutdown = true; | 336 expecting_rfh_shutdown = true; |
335 EXPECT_TRUE( | 337 EXPECT_TRUE( |
336 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion( | 338 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion( |
337 old_rfh)); | 339 old_rfh)); |
338 } | 340 } |
339 } | 341 } |
340 | 342 |
341 // Simulate the swap out ACK coming from the pending renderer. This should | 343 // Simulate the swap out ACK coming from the pending renderer. This should |
342 // either shut down the old RFH or leave it in a swapped out state. | 344 // either shut down the old RFH or leave it in a swapped out state. |
343 if (old_rfh != active_rfh) { | 345 if (old_rfh != active_rfh) { |
344 old_rfh->OnSwappedOut(); | 346 old_rfh->OnSwappedOut(); |
345 if (expecting_rfh_shutdown) { | 347 if (expecting_rfh_shutdown) { |
346 EXPECT_TRUE(rfh_observer.deleted()); | 348 EXPECT_TRUE(rfh_observer.deleted()); |
347 EXPECT_TRUE(rvh_observer.deleted()); | 349 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 350 switches::kSitePerProcess)) { |
| 351 EXPECT_TRUE(rvh_observer.deleted()); |
| 352 } |
348 } else { | 353 } else { |
349 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, | 354 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, |
350 old_rfh->rfh_state()); | 355 old_rfh->rfh_state()); |
351 } | 356 } |
352 } | 357 } |
353 EXPECT_EQ(active_rfh, contents()->GetMainFrame()); | 358 EXPECT_EQ(active_rfh, contents()->GetMainFrame()); |
354 EXPECT_EQ(NULL, contents()->GetPendingMainFrame()); | 359 EXPECT_EQ(NULL, contents()->GetPendingMainFrame()); |
355 } | 360 } |
356 | 361 |
357 bool ShouldSwapProcesses(RenderFrameHostManager* manager, | 362 bool ShouldSwapProcesses(RenderFrameHostManager* manager, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 // for synchronous messages, which cannot be ignored without leaving the | 525 // for synchronous messages, which cannot be ignored without leaving the |
521 // renderer in a stuck state. See http://crbug.com/93427. | 526 // renderer in a stuck state. See http://crbug.com/93427. |
522 TEST_F(RenderFrameHostManagerTest, FilterMessagesWhileSwappedOut) { | 527 TEST_F(RenderFrameHostManagerTest, FilterMessagesWhileSwappedOut) { |
523 const GURL kChromeURL("chrome://foo"); | 528 const GURL kChromeURL("chrome://foo"); |
524 const GURL kDestUrl("http://www.google.com/"); | 529 const GURL kDestUrl("http://www.google.com/"); |
525 std::vector<FaviconURL> icons; | 530 std::vector<FaviconURL> icons; |
526 | 531 |
527 // Navigate our first tab to a chrome url and then to the destination. | 532 // Navigate our first tab to a chrome url and then to the destination. |
528 NavigateActiveAndCommit(kChromeURL); | 533 NavigateActiveAndCommit(kChromeURL); |
529 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 534 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
| 535 TestRenderViewHost* ntp_rvh = ntp_rfh->GetRenderViewHost(); |
530 | 536 |
531 // Send an update favicon message and make sure it works. | 537 // Send an update favicon message and make sure it works. |
532 { | 538 { |
533 PluginFaviconMessageObserver observer(contents()); | 539 PluginFaviconMessageObserver observer(contents()); |
534 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->OnMessageReceived( | 540 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->OnMessageReceived( |
535 ViewHostMsg_UpdateFaviconURL( | 541 ViewHostMsg_UpdateFaviconURL( |
536 ntp_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | 542 ntp_rfh->GetRenderViewHost()->GetRoutingID(), icons))); |
537 EXPECT_TRUE(observer.favicon_received()); | 543 EXPECT_TRUE(observer.favicon_received()); |
538 } | 544 } |
539 // Create one more frame in the same SiteInstance where ntp_rfh | 545 // Create one more frame in the same SiteInstance where ntp_rfh |
(...skipping 12 matching lines...) Expand all Loading... |
552 PluginFaviconMessageObserver observer(contents()); | 558 PluginFaviconMessageObserver observer(contents()); |
553 EXPECT_TRUE( | 559 EXPECT_TRUE( |
554 dest_rfh->GetRenderViewHost()->OnMessageReceived( | 560 dest_rfh->GetRenderViewHost()->OnMessageReceived( |
555 ViewHostMsg_UpdateFaviconURL( | 561 ViewHostMsg_UpdateFaviconURL( |
556 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | 562 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); |
557 EXPECT_TRUE(observer.favicon_received()); | 563 EXPECT_TRUE(observer.favicon_received()); |
558 } | 564 } |
559 | 565 |
560 // The old renderer, being slow, now updates the favicon. It should be | 566 // The old renderer, being slow, now updates the favicon. It should be |
561 // filtered out and not take effect. | 567 // filtered out and not take effect. |
562 EXPECT_TRUE(ntp_rfh->is_swapped_out()); | |
563 { | 568 { |
564 PluginFaviconMessageObserver observer(contents()); | 569 PluginFaviconMessageObserver observer(contents()); |
565 EXPECT_TRUE( | 570 EXPECT_TRUE( |
566 ntp_rfh->GetRenderViewHost()->OnMessageReceived( | 571 ntp_rvh->OnMessageReceived( |
567 ViewHostMsg_UpdateFaviconURL( | 572 ViewHostMsg_UpdateFaviconURL( |
568 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | 573 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); |
569 EXPECT_FALSE(observer.favicon_received()); | 574 EXPECT_FALSE(observer.favicon_received()); |
570 } | 575 } |
571 | 576 |
| 577 // In --site-per-process, the RenderFrameHost is deleted on cross-process |
| 578 // navigation, so the rest of the test case doesn't apply. |
| 579 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 580 switches::kSitePerProcess)) { |
| 581 return; |
| 582 } |
| 583 |
572 #if defined(ENABLE_PLUGINS) | 584 #if defined(ENABLE_PLUGINS) |
573 // The same logic should apply to RenderFrameHosts as well and routing through | 585 // The same logic should apply to RenderFrameHosts as well and routing through |
574 // swapped out RFH shouldn't be allowed. Use a PluginCrashObserver to check | 586 // swapped out RFH shouldn't be allowed. Use a PluginCrashObserver to check |
575 // if the IPC message is allowed through or not. | 587 // if the IPC message is allowed through or not. |
576 { | 588 { |
577 PluginFaviconMessageObserver observer(contents()); | 589 PluginFaviconMessageObserver observer(contents()); |
578 EXPECT_TRUE(ntp_rfh->OnMessageReceived( | 590 EXPECT_TRUE(ntp_rfh->OnMessageReceived( |
579 FrameHostMsg_PluginCrashed( | 591 FrameHostMsg_PluginCrashed( |
580 ntp_rfh->GetRoutingID(), base::FilePath(), 0))); | 592 ntp_rfh->GetRoutingID(), base::FilePath(), 0))); |
581 EXPECT_FALSE(observer.plugin_crashed()); | 593 EXPECT_FALSE(observer.plugin_crashed()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 } | 678 } |
667 | 679 |
668 // Ensure that frames aren't added to the frame tree, if the message is coming | 680 // Ensure that frames aren't added to the frame tree, if the message is coming |
669 // from a process different than the parent frame's current RenderFrameHost | 681 // from a process different than the parent frame's current RenderFrameHost |
670 // process. Otherwise it is possible to have collisions of routing ids, as they | 682 // process. Otherwise it is possible to have collisions of routing ids, as they |
671 // are scoped per process. See https://crbug.com/415059. | 683 // are scoped per process. See https://crbug.com/415059. |
672 TEST_F(RenderFrameHostManagerTest, DropCreateChildFrameWhileSwappedOut) { | 684 TEST_F(RenderFrameHostManagerTest, DropCreateChildFrameWhileSwappedOut) { |
673 const GURL kUrl1("http://foo.com"); | 685 const GURL kUrl1("http://foo.com"); |
674 const GURL kUrl2("http://www.google.com/"); | 686 const GURL kUrl2("http://www.google.com/"); |
675 | 687 |
| 688 // This test is invalid in --site-per-process mode, as swapped-out is no |
| 689 // longer used. |
| 690 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 691 switches::kSitePerProcess)) { |
| 692 return; |
| 693 } |
| 694 |
676 // Navigate to the first site. | 695 // Navigate to the first site. |
677 NavigateActiveAndCommit(kUrl1); | 696 NavigateActiveAndCommit(kUrl1); |
678 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame(); | 697 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame(); |
679 { | 698 { |
680 RenderFrameHostCreatedObserver observer(contents()); | 699 RenderFrameHostCreatedObserver observer(contents()); |
681 initial_rfh->OnCreateChildFrame( | 700 initial_rfh->OnCreateChildFrame( |
682 initial_rfh->GetProcess()->GetNextRoutingID(), | 701 initial_rfh->GetProcess()->GetNextRoutingID(), |
683 blink::WebTreeScopeType::Document, std::string(), | 702 blink::WebTreeScopeType::Document, std::string(), |
684 blink::WebSandboxFlags::None); | 703 blink::WebSandboxFlags::None); |
685 EXPECT_TRUE(observer.created()); | 704 EXPECT_TRUE(observer.created()); |
(...skipping 18 matching lines...) Expand all Loading... |
704 RenderFrameHostCreatedObserver observer(contents()); | 723 RenderFrameHostCreatedObserver observer(contents()); |
705 initial_rfh->OnCreateChildFrame( | 724 initial_rfh->OnCreateChildFrame( |
706 initial_rfh->GetProcess()->GetNextRoutingID(), | 725 initial_rfh->GetProcess()->GetNextRoutingID(), |
707 blink::WebTreeScopeType::Document, std::string(), | 726 blink::WebTreeScopeType::Document, std::string(), |
708 blink::WebSandboxFlags::None); | 727 blink::WebSandboxFlags::None); |
709 EXPECT_FALSE(observer.created()); | 728 EXPECT_FALSE(observer.created()); |
710 } | 729 } |
711 } | 730 } |
712 | 731 |
713 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { | 732 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { |
| 733 // TODO(nasko): Check with kenrb whether this test can be rewritten and |
| 734 // whether it makes sense when swapped out is replaced with proxies. |
| 735 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 736 switches::kSitePerProcess)) { |
| 737 return; |
| 738 } |
714 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); | 739 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
715 TestRenderWidgetHostView* swapped_out_rwhv = | 740 TestRenderWidgetHostView* swapped_out_rwhv = |
716 static_cast<TestRenderWidgetHostView*>( | 741 static_cast<TestRenderWidgetHostView*>( |
717 swapped_out_rfh->GetRenderViewHost()->GetView()); | 742 swapped_out_rfh->GetRenderViewHost()->GetView()); |
718 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); | 743 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); |
719 | 744 |
720 MockRenderProcessHost* process_host = swapped_out_rfh->GetProcess(); | 745 MockRenderProcessHost* process_host = swapped_out_rfh->GetProcess(); |
721 process_host->sink().ClearMessages(); | 746 process_host->sink().ClearMessages(); |
722 | 747 |
723 cc::CompositorFrame frame; | 748 cc::CompositorFrame frame; |
724 ViewHostMsg_SwapCompositorFrame msg( | 749 ViewHostMsg_SwapCompositorFrame msg( |
725 rvh()->GetRoutingID(), 0, frame, std::vector<IPC::Message>()); | 750 rvh()->GetRoutingID(), 0, frame, std::vector<IPC::Message>()); |
726 | 751 |
727 EXPECT_TRUE(swapped_out_rfh->render_view_host()->OnMessageReceived(msg)); | 752 EXPECT_TRUE(swapped_out_rfh->render_view_host()->OnMessageReceived(msg)); |
728 EXPECT_TRUE(swapped_out_rwhv->did_swap_compositor_frame()); | 753 EXPECT_TRUE(swapped_out_rwhv->did_swap_compositor_frame()); |
729 } | 754 } |
730 | 755 |
731 // Test if RenderViewHost::GetRenderWidgetHosts() only returns active | 756 // Test if RenderViewHost::GetRenderWidgetHosts() only returns active |
732 // widgets. | 757 // widgets. |
733 TEST_F(RenderFrameHostManagerTest, GetRenderWidgetHostsReturnsActiveViews) { | 758 TEST_F(RenderFrameHostManagerTest, GetRenderWidgetHostsReturnsActiveViews) { |
| 759 // This test is invalid in --site-per-process mode, as swapped-out is no |
| 760 // longer used. |
| 761 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 762 switches::kSitePerProcess)) { |
| 763 return; |
| 764 } |
| 765 |
734 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); | 766 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
735 EXPECT_TRUE(swapped_out_rfh->is_swapped_out()); | 767 EXPECT_TRUE(swapped_out_rfh->is_swapped_out()); |
736 | 768 |
737 scoped_ptr<RenderWidgetHostIterator> widgets( | 769 scoped_ptr<RenderWidgetHostIterator> widgets( |
738 RenderWidgetHost::GetRenderWidgetHosts()); | 770 RenderWidgetHost::GetRenderWidgetHosts()); |
739 // We know that there is the only one active widget. Another view is | 771 // We know that there is the only one active widget. Another view is |
740 // now swapped out, so the swapped out view is not included in the | 772 // now swapped out, so the swapped out view is not included in the |
741 // list. | 773 // list. |
742 RenderWidgetHost* widget = widgets->GetNextHost(); | 774 RenderWidgetHost* widget = widgets->GetNextHost(); |
743 EXPECT_FALSE(widgets->GetNextHost()); | 775 EXPECT_FALSE(widgets->GetNextHost()); |
744 RenderViewHost* rvh = RenderViewHost::From(widget); | 776 RenderViewHost* rvh = RenderViewHost::From(widget); |
745 EXPECT_TRUE(static_cast<RenderViewHostImpl*>(rvh)->is_active()); | 777 EXPECT_TRUE(static_cast<RenderViewHostImpl*>(rvh)->is_active()); |
746 } | 778 } |
747 | 779 |
748 // Test if RenderViewHost::GetRenderWidgetHosts() returns a subset of | 780 // Test if RenderViewHost::GetRenderWidgetHosts() returns a subset of |
749 // RenderViewHostImpl::GetAllRenderWidgetHosts(). | 781 // RenderViewHostImpl::GetAllRenderWidgetHosts(). |
750 // RenderViewHost::GetRenderWidgetHosts() returns only active widgets, but | 782 // RenderViewHost::GetRenderWidgetHosts() returns only active widgets, but |
751 // RenderViewHostImpl::GetAllRenderWidgetHosts() returns everything | 783 // RenderViewHostImpl::GetAllRenderWidgetHosts() returns everything |
752 // including swapped out ones. | 784 // including swapped out ones. |
753 TEST_F(RenderFrameHostManagerTest, | 785 TEST_F(RenderFrameHostManagerTest, |
754 GetRenderWidgetHostsWithinGetAllRenderWidgetHosts) { | 786 GetRenderWidgetHostsWithinGetAllRenderWidgetHosts) { |
| 787 // This test is invalid in --site-per-process mode, as swapped-out is no |
| 788 // longer used. |
| 789 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 790 switches::kSitePerProcess)) { |
| 791 return; |
| 792 } |
| 793 |
755 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); | 794 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
756 EXPECT_TRUE(swapped_out_rfh->is_swapped_out()); | 795 EXPECT_TRUE(swapped_out_rfh->is_swapped_out()); |
757 | 796 |
758 scoped_ptr<RenderWidgetHostIterator> widgets( | 797 scoped_ptr<RenderWidgetHostIterator> widgets( |
759 RenderWidgetHost::GetRenderWidgetHosts()); | 798 RenderWidgetHost::GetRenderWidgetHosts()); |
760 | 799 |
761 while (RenderWidgetHost* w = widgets->GetNextHost()) { | 800 while (RenderWidgetHost* w = widgets->GetNextHost()) { |
762 bool found = false; | 801 bool found = false; |
763 scoped_ptr<RenderWidgetHostIterator> all_widgets( | 802 scoped_ptr<RenderWidgetHostIterator> all_widgets( |
764 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 803 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1345 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
1307 // happen, but we have seen it when going back quickly across many entries | 1346 // happen, but we have seen it when going back quickly across many entries |
1308 // (http://crbug.com/93427). | 1347 // (http://crbug.com/93427). |
1309 contents()->GetController().GoBack(); | 1348 contents()->GetController().GoBack(); |
1310 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); | 1349 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); |
1311 contents()->GetMainFrame()->PrepareForCommit(); | 1350 contents()->GetMainFrame()->PrepareForCommit(); |
1312 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); | 1351 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); |
1313 | 1352 |
1314 // The back navigation commits. | 1353 // The back navigation commits. |
1315 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1354 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1316 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false, | 1355 contents()->GetPendingMainFrame()->SendNavigate( |
1317 entry1->GetURL()); | 1356 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL()); |
1318 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); | 1357 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
1319 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); | 1358 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); |
1320 | 1359 |
1321 // We should be able to navigate forward. | 1360 // We should be able to navigate forward. |
1322 contents()->GetController().GoForward(); | 1361 contents()->GetController().GoForward(); |
1323 contents()->GetMainFrame()->PrepareForCommit(); | 1362 contents()->GetMainFrame()->PrepareForCommit(); |
1324 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1363 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
1325 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetUniqueID(), false, | 1364 contents()->GetPendingMainFrame()->SendNavigate( |
1326 entry2->GetURL()); | 1365 entry2->GetPageID(), entry2->GetUniqueID(), false, entry2->GetURL()); |
1327 EXPECT_EQ(rfh2, main_test_rfh()); | 1366 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); |
1328 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1367 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
1329 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1368 switches::kSitePerProcess)) { |
1330 rfh1->OnSwappedOut(); | 1369 EXPECT_EQ(rfh2, main_test_rfh()); |
1331 EXPECT_TRUE(rfh1->is_swapped_out()); | 1370 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1332 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); | 1371 rfh1->OnSwappedOut(); |
| 1372 EXPECT_TRUE(rfh1->is_swapped_out()); |
| 1373 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); |
| 1374 } |
1333 } | 1375 } |
1334 | 1376 |
1335 // Test that we create swapped out RFHs for the opener chain when navigating an | 1377 // Test that we create swapped out RFHs for the opener chain when navigating an |
1336 // opened tab cross-process. This allows us to support certain cross-process | 1378 // opened tab cross-process. This allows us to support certain cross-process |
1337 // JavaScript calls (http://crbug.com/99202). | 1379 // JavaScript calls (http://crbug.com/99202). |
1338 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRFHs) { | 1380 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRFHs) { |
1339 const GURL kUrl1("http://www.google.com/"); | 1381 const GURL kUrl1("http://www.google.com/"); |
1340 const GURL kUrl2("http://www.chromium.org/"); | 1382 const GURL kUrl2("http://www.chromium.org/"); |
1341 const GURL kChromeUrl("chrome://foo"); | 1383 const GURL kChromeUrl("chrome://foo"); |
| 1384 bool is_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1385 switches::kSitePerProcess); |
1342 | 1386 |
1343 // Navigate to an initial URL. | 1387 // Navigate to an initial URL. |
1344 contents()->NavigateAndCommit(kUrl1); | 1388 contents()->NavigateAndCommit(kUrl1); |
1345 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | 1389 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); |
1346 TestRenderFrameHost* rfh1 = main_test_rfh(); | 1390 TestRenderFrameHost* rfh1 = main_test_rfh(); |
| 1391 scoped_refptr<SiteInstanceImpl> site_instance1 = rfh1->GetSiteInstance(); |
| 1392 RenderFrameHostDeletedObserver rfh1_deleted_observer(rfh1); |
1347 TestRenderViewHost* rvh1 = test_rvh(); | 1393 TestRenderViewHost* rvh1 = test_rvh(); |
1348 | 1394 |
1349 // Create 2 new tabs and simulate them being the opener chain for the main | 1395 // Create 2 new tabs and simulate them being the opener chain for the main |
1350 // tab. They should be in the same SiteInstance. | 1396 // tab. They should be in the same SiteInstance. |
1351 scoped_ptr<TestWebContents> opener1( | 1397 scoped_ptr<TestWebContents> opener1( |
1352 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | 1398 TestWebContents::Create(browser_context(), site_instance1.get())); |
1353 RenderFrameHostManager* opener1_manager = | 1399 RenderFrameHostManager* opener1_manager = |
1354 opener1->GetRenderManagerForTesting(); | 1400 opener1->GetRenderManagerForTesting(); |
1355 contents()->SetOpener(opener1.get()); | 1401 contents()->SetOpener(opener1.get()); |
1356 | 1402 |
1357 scoped_ptr<TestWebContents> opener2( | 1403 scoped_ptr<TestWebContents> opener2( |
1358 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | 1404 TestWebContents::Create(browser_context(), site_instance1.get())); |
1359 RenderFrameHostManager* opener2_manager = | 1405 RenderFrameHostManager* opener2_manager = |
1360 opener2->GetRenderManagerForTesting(); | 1406 opener2->GetRenderManagerForTesting(); |
1361 opener1->SetOpener(opener2.get()); | 1407 opener1->SetOpener(opener2.get()); |
1362 | 1408 |
1363 // Navigate to a cross-site URL (different SiteInstance but same | 1409 // Navigate to a cross-site URL (different SiteInstance but same |
1364 // BrowsingInstance). | 1410 // BrowsingInstance). |
1365 contents()->NavigateAndCommit(kUrl2); | 1411 contents()->NavigateAndCommit(kUrl2); |
1366 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1412 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1367 TestRenderViewHost* rvh2 = test_rvh(); | 1413 TestRenderViewHost* rvh2 = test_rvh(); |
1368 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1414 EXPECT_NE(site_instance1, rfh2->GetSiteInstance()); |
1369 EXPECT_TRUE(rfh1->GetSiteInstance()->IsRelatedSiteInstance( | 1415 EXPECT_TRUE(site_instance1->IsRelatedSiteInstance(rfh2->GetSiteInstance())); |
1370 rfh2->GetSiteInstance())); | |
1371 | 1416 |
1372 // Ensure rvh1 is placed on swapped out list of the current tab. | 1417 // Ensure rvh1 is placed on swapped out list of the current tab. |
1373 EXPECT_TRUE(manager->IsOnSwappedOutList(rfh1)); | 1418 if (!is_site_per_process) { |
1374 EXPECT_TRUE(manager->IsRVHOnSwappedOutList(rvh1)); | 1419 EXPECT_TRUE(manager->IsRVHOnSwappedOutList(rvh1)); |
1375 EXPECT_EQ(rfh1, | 1420 EXPECT_FALSE(rfh1_deleted_observer.deleted()); |
1376 manager->GetRenderFrameProxyHost(rfh1->GetSiteInstance()) | 1421 EXPECT_TRUE(manager->IsOnSwappedOutList(rfh1)); |
1377 ->render_frame_host()); | 1422 EXPECT_EQ(rfh1, |
| 1423 manager->GetRenderFrameProxyHost(site_instance1.get()) |
| 1424 ->render_frame_host()); |
| 1425 } else { |
| 1426 EXPECT_TRUE(rfh1_deleted_observer.deleted()); |
| 1427 EXPECT_TRUE(manager->GetRenderFrameProxyHost(site_instance1.get())); |
| 1428 } |
1378 EXPECT_EQ(rvh1, | 1429 EXPECT_EQ(rvh1, |
1379 manager->GetSwappedOutRenderViewHost(rvh1->GetSiteInstance())); | 1430 manager->GetSwappedOutRenderViewHost(rvh1->GetSiteInstance())); |
1380 | 1431 |
1381 // Ensure a swapped out RFH and RFH is created in the first opener tab. | 1432 // Ensure a swapped out RFH and RFH is created in the first opener tab. |
1382 RenderFrameProxyHost* opener1_proxy = | 1433 RenderFrameProxyHost* opener1_proxy = |
1383 opener1_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance()); | 1434 opener1_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance()); |
1384 RenderFrameHostImpl* opener1_rfh = opener1_proxy->render_frame_host(); | 1435 RenderFrameHostImpl* opener1_rfh = opener1_proxy->render_frame_host(); |
1385 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 1436 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
1386 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1437 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
1387 EXPECT_TRUE(opener1_manager->IsOnSwappedOutList(opener1_rfh)); | 1438 if (!is_site_per_process) { |
1388 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); | 1439 EXPECT_TRUE(opener1_manager->IsOnSwappedOutList(opener1_rfh)); |
1389 EXPECT_TRUE(opener1_rfh->is_swapped_out()); | 1440 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); |
| 1441 EXPECT_TRUE(opener1_rfh->is_swapped_out()); |
| 1442 } else { |
| 1443 EXPECT_FALSE(opener1_rfh); |
| 1444 } |
1390 EXPECT_FALSE(opener1_rvh->is_active()); | 1445 EXPECT_FALSE(opener1_rvh->is_active()); |
1391 | 1446 |
1392 // Ensure a swapped out RFH and RVH is created in the second opener tab. | 1447 // Ensure a swapped out RFH and RVH is created in the second opener tab. |
1393 RenderFrameProxyHost* opener2_proxy = | 1448 RenderFrameProxyHost* opener2_proxy = |
1394 opener2_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance()); | 1449 opener2_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance()); |
1395 RenderFrameHostImpl* opener2_rfh = opener2_proxy->render_frame_host(); | 1450 RenderFrameHostImpl* opener2_rfh = opener2_proxy->render_frame_host(); |
1396 TestRenderViewHost* opener2_rvh = static_cast<TestRenderViewHost*>( | 1451 TestRenderViewHost* opener2_rvh = static_cast<TestRenderViewHost*>( |
1397 opener2_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1452 opener2_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
1398 EXPECT_TRUE(opener2_manager->IsOnSwappedOutList(opener2_rfh)); | 1453 if (!is_site_per_process) { |
1399 EXPECT_TRUE(opener2_manager->IsRVHOnSwappedOutList(opener2_rvh)); | 1454 EXPECT_TRUE(opener2_manager->IsOnSwappedOutList(opener2_rfh)); |
1400 EXPECT_TRUE(opener2_rfh->is_swapped_out()); | 1455 EXPECT_TRUE(opener2_manager->IsRVHOnSwappedOutList(opener2_rvh)); |
| 1456 EXPECT_TRUE(opener2_rfh->is_swapped_out()); |
| 1457 } else { |
| 1458 EXPECT_FALSE(opener2_rfh); |
| 1459 } |
1401 EXPECT_FALSE(opener2_rvh->is_active()); | 1460 EXPECT_FALSE(opener2_rvh->is_active()); |
1402 | 1461 |
1403 // Navigate to a cross-BrowsingInstance URL. | 1462 // Navigate to a cross-BrowsingInstance URL. |
1404 contents()->NavigateAndCommit(kChromeUrl); | 1463 contents()->NavigateAndCommit(kChromeUrl); |
1405 TestRenderFrameHost* rfh3 = main_test_rfh(); | 1464 TestRenderFrameHost* rfh3 = main_test_rfh(); |
1406 EXPECT_NE(rfh1->GetSiteInstance(), rfh3->GetSiteInstance()); | 1465 EXPECT_NE(site_instance1, rfh3->GetSiteInstance()); |
1407 EXPECT_FALSE(rfh1->GetSiteInstance()->IsRelatedSiteInstance( | 1466 EXPECT_FALSE(site_instance1->IsRelatedSiteInstance(rfh3->GetSiteInstance())); |
1408 rfh3->GetSiteInstance())); | |
1409 | 1467 |
1410 // No scripting is allowed across BrowsingInstances, so we should not create | 1468 // No scripting is allowed across BrowsingInstances, so we should not create |
1411 // swapped out RVHs for the opener chain in this case. | 1469 // swapped out RVHs for the opener chain in this case. |
1412 EXPECT_FALSE(opener1_manager->GetRenderFrameProxyHost( | 1470 EXPECT_FALSE(opener1_manager->GetRenderFrameProxyHost( |
1413 rfh3->GetSiteInstance())); | 1471 rfh3->GetSiteInstance())); |
1414 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( | 1472 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
1415 rfh3->GetSiteInstance())); | 1473 rfh3->GetSiteInstance())); |
1416 EXPECT_FALSE(opener2_manager->GetRenderFrameProxyHost( | 1474 EXPECT_FALSE(opener2_manager->GetRenderFrameProxyHost( |
1417 rfh3->GetSiteInstance())); | 1475 rfh3->GetSiteInstance())); |
1418 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( | 1476 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( |
1419 rfh3->GetSiteInstance())); | 1477 rfh3->GetSiteInstance())); |
1420 } | 1478 } |
1421 | 1479 |
1422 // Test that a page can disown the opener of the WebContents. | 1480 // Test that a page can disown the opener of the WebContents. |
1423 TEST_F(RenderFrameHostManagerTest, DisownOpener) { | 1481 TEST_F(RenderFrameHostManagerTest, DisownOpener) { |
1424 const GURL kUrl1("http://www.google.com/"); | 1482 const GURL kUrl1("http://www.google.com/"); |
1425 const GURL kUrl2("http://www.chromium.org/"); | 1483 const GURL kUrl2("http://www.chromium.org/"); |
1426 | 1484 |
1427 // Navigate to an initial URL. | 1485 // Navigate to an initial URL. |
1428 contents()->NavigateAndCommit(kUrl1); | 1486 contents()->NavigateAndCommit(kUrl1); |
1429 TestRenderFrameHost* rfh1 = main_test_rfh(); | 1487 TestRenderFrameHost* rfh1 = main_test_rfh(); |
| 1488 scoped_refptr<SiteInstanceImpl> site_instance1 = rfh1->GetSiteInstance(); |
1430 | 1489 |
1431 // Create a new tab and simulate having it be the opener for the main tab. | 1490 // Create a new tab and simulate having it be the opener for the main tab. |
1432 scoped_ptr<TestWebContents> opener1( | 1491 scoped_ptr<TestWebContents> opener1( |
1433 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | 1492 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); |
1434 contents()->SetOpener(opener1.get()); | 1493 contents()->SetOpener(opener1.get()); |
1435 EXPECT_TRUE(contents()->HasOpener()); | 1494 EXPECT_TRUE(contents()->HasOpener()); |
1436 | 1495 |
1437 // Navigate to a cross-site URL (different SiteInstance but same | 1496 // Navigate to a cross-site URL (different SiteInstance but same |
1438 // BrowsingInstance). | 1497 // BrowsingInstance). |
1439 contents()->NavigateAndCommit(kUrl2); | 1498 contents()->NavigateAndCommit(kUrl2); |
1440 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1499 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1441 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1500 EXPECT_NE(site_instance1, rfh2->GetSiteInstance()); |
1442 | 1501 |
1443 // Disown the opener from rfh2. | 1502 // Disown the opener from rfh2. |
1444 rfh2->DidDisownOpener(); | 1503 rfh2->DidDisownOpener(); |
1445 | 1504 |
1446 // Ensure the opener is cleared. | 1505 // Ensure the opener is cleared. |
1447 EXPECT_FALSE(contents()->HasOpener()); | 1506 EXPECT_FALSE(contents()->HasOpener()); |
1448 } | 1507 } |
1449 | 1508 |
1450 // Test that a page can disown a same-site opener of the WebContents. | 1509 // Test that a page can disown a same-site opener of the WebContents. |
1451 TEST_F(RenderFrameHostManagerTest, DisownSameSiteOpener) { | 1510 TEST_F(RenderFrameHostManagerTest, DisownSameSiteOpener) { |
(...skipping 17 matching lines...) Expand all Loading... |
1469 } | 1528 } |
1470 | 1529 |
1471 // Test that a page can disown the opener just as a cross-process navigation is | 1530 // Test that a page can disown the opener just as a cross-process navigation is |
1472 // in progress. | 1531 // in progress. |
1473 TEST_F(RenderFrameHostManagerTest, DisownOpenerDuringNavigation) { | 1532 TEST_F(RenderFrameHostManagerTest, DisownOpenerDuringNavigation) { |
1474 const GURL kUrl1("http://www.google.com/"); | 1533 const GURL kUrl1("http://www.google.com/"); |
1475 const GURL kUrl2("http://www.chromium.org/"); | 1534 const GURL kUrl2("http://www.chromium.org/"); |
1476 | 1535 |
1477 // Navigate to an initial URL. | 1536 // Navigate to an initial URL. |
1478 contents()->NavigateAndCommit(kUrl1); | 1537 contents()->NavigateAndCommit(kUrl1); |
1479 TestRenderFrameHost* rfh1 = main_test_rfh(); | 1538 scoped_refptr<SiteInstanceImpl> site_instance1 = |
| 1539 main_test_rfh()->GetSiteInstance(); |
1480 | 1540 |
1481 // Create a new tab and simulate having it be the opener for the main tab. | 1541 // Create a new tab and simulate having it be the opener for the main tab. |
1482 scoped_ptr<TestWebContents> opener1( | 1542 scoped_ptr<TestWebContents> opener1( |
1483 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | 1543 TestWebContents::Create(browser_context(), site_instance1.get())); |
1484 contents()->SetOpener(opener1.get()); | 1544 contents()->SetOpener(opener1.get()); |
1485 EXPECT_TRUE(contents()->HasOpener()); | 1545 EXPECT_TRUE(contents()->HasOpener()); |
1486 | 1546 |
1487 // Navigate to a cross-site URL (different SiteInstance but same | 1547 // Navigate to a cross-site URL (different SiteInstance but same |
1488 // BrowsingInstance). | 1548 // BrowsingInstance). |
1489 contents()->NavigateAndCommit(kUrl2); | 1549 contents()->NavigateAndCommit(kUrl2); |
1490 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1550 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1491 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1551 EXPECT_NE(site_instance1, rfh2->GetSiteInstance()); |
1492 | 1552 |
1493 // Start a back navigation so that rfh1 becomes the pending RFH. | 1553 // Start a back navigation. |
1494 contents()->GetController().GoBack(); | 1554 contents()->GetController().GoBack(); |
1495 contents()->GetMainFrame()->PrepareForCommit(); | 1555 contents()->GetMainFrame()->PrepareForCommit(); |
1496 | 1556 |
1497 // Disown the opener from rfh2. | 1557 // Disown the opener from rfh2. |
1498 rfh2->DidDisownOpener(); | 1558 rfh2->DidDisownOpener(); |
1499 | 1559 |
1500 // Ensure the opener is cleared. | 1560 // Ensure the opener is cleared. |
1501 EXPECT_FALSE(contents()->HasOpener()); | 1561 EXPECT_FALSE(contents()->HasOpener()); |
1502 | 1562 |
1503 // The back navigation commits. | 1563 // The back navigation commits. |
1504 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1564 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1505 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false, | 1565 contents()->GetPendingMainFrame()->SendNavigate( |
1506 entry1->GetURL()); | 1566 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL()); |
1507 | 1567 |
1508 // Ensure the opener is still cleared. | 1568 // Ensure the opener is still cleared. |
1509 EXPECT_FALSE(contents()->HasOpener()); | 1569 EXPECT_FALSE(contents()->HasOpener()); |
1510 } | 1570 } |
1511 | 1571 |
1512 // Test that a page can disown the opener just after a cross-process navigation | 1572 // Test that a page can disown the opener just after a cross-process navigation |
1513 // commits. | 1573 // commits. |
1514 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { | 1574 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { |
1515 const GURL kUrl1("http://www.google.com/"); | 1575 const GURL kUrl1("http://www.google.com/"); |
1516 const GURL kUrl2("http://www.chromium.org/"); | 1576 const GURL kUrl2("http://www.chromium.org/"); |
1517 | 1577 |
1518 // Navigate to an initial URL. | 1578 // Navigate to an initial URL. |
1519 contents()->NavigateAndCommit(kUrl1); | 1579 contents()->NavigateAndCommit(kUrl1); |
1520 TestRenderFrameHost* rfh1 = main_test_rfh(); | 1580 scoped_refptr<SiteInstanceImpl> site_instance1 = |
| 1581 main_test_rfh()->GetSiteInstance(); |
1521 | 1582 |
1522 // Create a new tab and simulate having it be the opener for the main tab. | 1583 // Create a new tab and simulate having it be the opener for the main tab. |
1523 scoped_ptr<TestWebContents> opener1( | 1584 scoped_ptr<TestWebContents> opener1( |
1524 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance())); | 1585 TestWebContents::Create(browser_context(), site_instance1.get())); |
1525 contents()->SetOpener(opener1.get()); | 1586 contents()->SetOpener(opener1.get()); |
1526 EXPECT_TRUE(contents()->HasOpener()); | 1587 EXPECT_TRUE(contents()->HasOpener()); |
1527 | 1588 |
1528 // Navigate to a cross-site URL (different SiteInstance but same | 1589 // Navigate to a cross-site URL (different SiteInstance but same |
1529 // BrowsingInstance). | 1590 // BrowsingInstance). |
1530 contents()->NavigateAndCommit(kUrl2); | 1591 contents()->NavigateAndCommit(kUrl2); |
1531 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1592 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1532 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1593 EXPECT_NE(site_instance1, rfh2->GetSiteInstance()); |
1533 | 1594 |
1534 // Commit a back navigation before the DidDisownOpener message arrives. | 1595 // Commit a back navigation before the DidDisownOpener message arrives. |
1535 // rfh1 will be kept alive because of the opener tab. | |
1536 contents()->GetController().GoBack(); | 1596 contents()->GetController().GoBack(); |
1537 contents()->GetMainFrame()->PrepareForCommit(); | 1597 contents()->GetMainFrame()->PrepareForCommit(); |
1538 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1598 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1539 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false, | 1599 contents()->GetPendingMainFrame()->SendNavigate( |
1540 entry1->GetURL()); | 1600 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL()); |
1541 | 1601 |
1542 // Disown the opener from rfh2. | 1602 // Disown the opener from rfh2. |
1543 rfh2->DidDisownOpener(); | 1603 rfh2->DidDisownOpener(); |
1544 EXPECT_FALSE(contents()->HasOpener()); | 1604 EXPECT_FALSE(contents()->HasOpener()); |
1545 } | 1605 } |
1546 | 1606 |
1547 // Test that we clean up swapped out RenderViewHosts when a process hosting | 1607 // Test that we clean up swapped out RenderViewHosts when a process hosting |
1548 // those associated RenderViews crashes. http://crbug.com/258993 | 1608 // those associated RenderViews crashes. http://crbug.com/258993 |
1549 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { | 1609 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { |
1550 const GURL kUrl1("http://www.google.com/"); | 1610 const GURL kUrl1("http://www.google.com/"); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 1687 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
1628 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 1688 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
1629 rvh2->GetSiteInstance())); | 1689 rvh2->GetSiteInstance())); |
1630 | 1690 |
1631 // Ensure a swapped out RFH and RVH is created in the first opener tab. | 1691 // Ensure a swapped out RFH and RVH is created in the first opener tab. |
1632 RenderFrameProxyHost* opener1_proxy = | 1692 RenderFrameProxyHost* opener1_proxy = |
1633 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance()); | 1693 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance()); |
1634 RenderFrameHostImpl* opener1_rfh = opener1_proxy->render_frame_host(); | 1694 RenderFrameHostImpl* opener1_rfh = opener1_proxy->render_frame_host(); |
1635 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 1695 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
1636 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1696 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
1637 EXPECT_TRUE(opener1_manager->IsOnSwappedOutList(opener1_rfh)); | 1697 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
1638 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); | 1698 switches::kSitePerProcess)) { |
1639 EXPECT_TRUE(opener1_rfh->is_swapped_out()); | 1699 EXPECT_TRUE(opener1_manager->IsOnSwappedOutList(opener1_rfh)); |
| 1700 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); |
| 1701 EXPECT_TRUE(opener1_rfh->is_swapped_out()); |
| 1702 } else { |
| 1703 EXPECT_FALSE(opener1_rfh); |
| 1704 } |
1640 EXPECT_FALSE(opener1_rvh->is_active()); | 1705 EXPECT_FALSE(opener1_rvh->is_active()); |
1641 | 1706 |
1642 // Ensure the new RVH has WebUI bindings. | 1707 // Ensure the new RVH has WebUI bindings. |
1643 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1708 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1644 } | 1709 } |
1645 | 1710 |
1646 // Test that we reuse the same guest SiteInstance if we navigate across sites. | 1711 // Test that we reuse the same guest SiteInstance if we navigate across sites. |
1647 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { | 1712 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { |
1648 GURL guest_url(std::string(kGuestScheme).append("://abc123")); | 1713 GURL guest_url(std::string(kGuestScheme).append("://abc123")); |
1649 SiteInstance* instance = | 1714 SiteInstance* instance = |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 ui::PAGE_TRANSITION_TYPED); | 1932 ui::PAGE_TRANSITION_TYPED); |
1868 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1933 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
1869 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1934 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1870 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1935 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1871 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1936 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1872 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1937 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1873 | 1938 |
1874 // Simulate the swap out ack. | 1939 // Simulate the swap out ack. |
1875 rfh1->OnSwappedOut(); | 1940 rfh1->OnSwappedOut(); |
1876 | 1941 |
1877 // rfh1 should be swapped out. | 1942 // rfh1 should be swapped out or deleted in --site-per-process. |
1878 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1943 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
1879 EXPECT_TRUE(rfh1->is_swapped_out()); | 1944 switches::kSitePerProcess)) { |
| 1945 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 1946 EXPECT_TRUE(rfh1->is_swapped_out()); |
| 1947 } else { |
| 1948 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1949 } |
1880 } | 1950 } |
1881 | 1951 |
1882 // Test that the RenderViewHost is properly swapped out if a navigation in the | 1952 // Test that the RenderViewHost is properly swapped out if a navigation in the |
1883 // new renderer commits before sending the SwapOut message to the old renderer. | 1953 // new renderer commits before sending the SwapOut message to the old renderer. |
1884 // This simulates a cross-site navigation to a synchronously committing URL | 1954 // This simulates a cross-site navigation to a synchronously committing URL |
1885 // (e.g., a data URL) and ensures it works properly. | 1955 // (e.g., a data URL) and ensures it works properly. |
1886 TEST_F(RenderFrameHostManagerTest, | 1956 TEST_F(RenderFrameHostManagerTest, |
1887 CommitNewNavigationBeforeSendingSwapOut) { | 1957 CommitNewNavigationBeforeSendingSwapOut) { |
1888 const GURL kUrl1("http://www.google.com/"); | 1958 const GURL kUrl1("http://www.google.com/"); |
1889 const GURL kUrl2("http://www.chromium.org/"); | 1959 const GURL kUrl2("http://www.chromium.org/"); |
1890 | 1960 |
1891 // Navigate to the first page. | 1961 // Navigate to the first page. |
1892 contents()->NavigateAndCommit(kUrl1); | 1962 contents()->NavigateAndCommit(kUrl1); |
1893 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1963 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1894 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1964 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1895 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1965 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1896 | 1966 |
1897 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1967 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1898 // not deleted on swap out. | 1968 // not deleted on swap out. |
1899 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1969 scoped_refptr<SiteInstanceImpl> site_instance = rfh1->GetSiteInstance(); |
| 1970 site_instance->increment_active_frame_count(); |
1900 | 1971 |
1901 // Navigate to new site, simulating onbeforeunload approval. | 1972 // Navigate to new site, simulating onbeforeunload approval. |
1902 controller().LoadURL( | 1973 controller().LoadURL( |
1903 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1974 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1904 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 1975 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
1905 rfh1->PrepareForCommit(); | 1976 rfh1->PrepareForCommit(); |
1906 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 1977 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
1907 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1978 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1908 | 1979 |
1909 // The new page commits. | 1980 // The new page commits. |
1910 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, | 1981 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
1911 ui::PAGE_TRANSITION_TYPED); | 1982 ui::PAGE_TRANSITION_TYPED); |
1912 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1983 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
1913 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1984 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1914 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1985 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1915 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1986 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1916 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1987 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1917 | 1988 |
1918 // Simulate the swap out ack. | 1989 // Simulate the swap out ack. |
1919 rfh1->OnSwappedOut(); | 1990 rfh1->OnSwappedOut(); |
1920 | 1991 |
1921 // rfh1 should be swapped out. | 1992 // rfh1 should be swapped out. |
1922 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1993 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1923 EXPECT_TRUE(rfh1->is_swapped_out()); | 1994 switches::kSitePerProcess)) { |
| 1995 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1996 EXPECT_TRUE(contents()->GetFrameTree()->root()->render_manager() |
| 1997 ->GetRenderFrameProxyHost(site_instance.get())); |
| 1998 } else { |
| 1999 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 2000 EXPECT_TRUE(rfh1->is_swapped_out()); |
| 2001 } |
1924 } | 2002 } |
1925 | 2003 |
1926 // Test that a RenderFrameHost is properly deleted or swapped out when a | 2004 // Test that a RenderFrameHost is properly deleted when a cross-site navigation |
1927 // cross-site navigation is cancelled. | 2005 // is cancelled. |
1928 TEST_F(RenderFrameHostManagerTest, | 2006 TEST_F(RenderFrameHostManagerTest, |
1929 CancelPendingProperlyDeletesOrSwaps) { | 2007 CancelPendingProperlyDeletesOrSwaps) { |
1930 const GURL kUrl1("http://www.google.com/"); | 2008 const GURL kUrl1("http://www.google.com/"); |
1931 const GURL kUrl2("http://www.chromium.org/"); | 2009 const GURL kUrl2("http://www.chromium.org/"); |
1932 RenderFrameHostImpl* pending_rfh = NULL; | 2010 RenderFrameHostImpl* pending_rfh = NULL; |
1933 base::TimeTicks now = base::TimeTicks::Now(); | 2011 base::TimeTicks now = base::TimeTicks::Now(); |
1934 | 2012 |
1935 // Navigate to the first page. | 2013 // Navigate to the first page. |
1936 contents()->NavigateAndCommit(kUrl1); | 2014 contents()->NavigateAndCommit(kUrl1); |
1937 TestRenderFrameHost* rfh1 = main_test_rfh(); | 2015 TestRenderFrameHost* rfh1 = main_test_rfh(); |
(...skipping 19 matching lines...) Expand all Loading... |
1957 | 2035 |
1958 // Start another cross-site navigation. | 2036 // Start another cross-site navigation. |
1959 controller().LoadURL( | 2037 controller().LoadURL( |
1960 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 2038 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1961 { | 2039 { |
1962 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 2040 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1963 ->pending_frame_host(); | 2041 ->pending_frame_host(); |
1964 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 2042 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
1965 | 2043 |
1966 // Increment the number of active frames in the new SiteInstance, which will | 2044 // Increment the number of active frames in the new SiteInstance, which will |
1967 // cause the pending RFH to be swapped out instead of deleted. | 2045 // cause the pending RFH to be deleted and a RenderFrameProxyHost to be |
1968 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 2046 // created. |
| 2047 scoped_refptr<SiteInstanceImpl> site_instance = |
| 2048 pending_rfh->GetSiteInstance(); |
| 2049 site_instance->increment_active_frame_count(); |
1969 | 2050 |
1970 contents()->GetMainFrame()->OnMessageReceived( | 2051 contents()->GetMainFrame()->OnMessageReceived( |
1971 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 2052 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1972 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 2053 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
1973 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 2054 |
| 2055 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2056 switches::kSitePerProcess)) { |
| 2057 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 2058 EXPECT_TRUE(contents()->GetFrameTree()->root()->render_manager() |
| 2059 ->GetRenderFrameProxyHost(site_instance.get())); |
| 2060 } else { |
| 2061 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 2062 } |
1974 } | 2063 } |
1975 } | 2064 } |
1976 | 2065 |
1977 // Test that a pending RenderFrameHost in a non-root frame tree node is properly | 2066 // Test that a pending RenderFrameHost in a non-root frame tree node is properly |
1978 // deleted when the node is detached. Motivated by http://crbug.com/441357 and | 2067 // deleted when the node is detached. Motivated by http://crbug.com/441357 and |
1979 // http://crbug.com/444955. | 2068 // http://crbug.com/444955. |
1980 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { | 2069 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { |
1981 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 2070 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1982 switches::kSitePerProcess); | 2071 switches::kSitePerProcess); |
1983 | 2072 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2246 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2158 contents2->NavigateAndCommit(kUrl3); | 2247 contents2->NavigateAndCommit(kUrl3); |
2159 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2248 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2160 EXPECT_NE(nullptr, | 2249 EXPECT_NE(nullptr, |
2161 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2250 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
2162 EXPECT_EQ(nullptr, | 2251 EXPECT_EQ(nullptr, |
2163 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2252 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
2164 } | 2253 } |
2165 | 2254 |
2166 } // namespace content | 2255 } // namespace content |
OLD | NEW |