| 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 "content/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 RenderViewHostImplTestHarness::TearDown(); | 311 RenderViewHostImplTestHarness::TearDown(); |
| 312 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); | 312 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void set_should_create_webui(bool should_create_webui) { | 315 void set_should_create_webui(bool should_create_webui) { |
| 316 factory_.set_should_create_webui(should_create_webui); | 316 factory_.set_should_create_webui(should_create_webui); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void set_webui_type(int type) { factory_.set_webui_type(type); } | 319 void set_webui_type(int type) { factory_.set_webui_type(type); } |
| 320 | 320 |
| 321 void NavigateActiveAndCommit(const GURL& url) { | 321 void NavigateActiveAndCommit(const GURL& url, bool dont_swap_out = false) { |
| 322 // Note: we navigate the active RenderFrameHost because previous navigations | 322 // Note: we navigate the active RenderFrameHost because previous navigations |
| 323 // won't have committed yet, so NavigateAndCommit does the wrong thing | 323 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 324 // for us. | 324 // for us. |
| 325 controller().LoadURL( | 325 controller().LoadURL( |
| 326 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 326 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 327 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 327 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 328 | 328 |
| 329 // Simulate the BeforeUnload_ACK that is received from the current renderer | 329 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 330 // for a cross-site navigation. | 330 // for a cross-site navigation. |
| 331 // PlzNavigate: it is necessary to call PrepareForCommit before getting the | 331 // PlzNavigate: it is necessary to call PrepareForCommit before getting the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 350 active_rfh->SendNavigate(entry_id, true, url); | 350 active_rfh->SendNavigate(entry_id, true, url); |
| 351 | 351 |
| 352 // Make sure that we start to run the unload handler at the time of commit. | 352 // Make sure that we start to run the unload handler at the time of commit. |
| 353 if (old_rfh != active_rfh && !rfh_observer.deleted()) { | 353 if (old_rfh != active_rfh && !rfh_observer.deleted()) { |
| 354 EXPECT_FALSE(old_rfh->is_active()); | 354 EXPECT_FALSE(old_rfh->is_active()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Simulate the swap out ACK coming from the pending renderer. This should | 357 // Simulate the swap out ACK coming from the pending renderer. This should |
| 358 // either shut down the old RFH or leave it in a swapped out state. | 358 // either shut down the old RFH or leave it in a swapped out state. |
| 359 if (old_rfh != active_rfh) { | 359 if (old_rfh != active_rfh) { |
| 360 if (dont_swap_out) |
| 361 return; |
| 360 old_rfh->OnSwappedOut(); | 362 old_rfh->OnSwappedOut(); |
| 361 EXPECT_TRUE(rfh_observer.deleted()); | 363 EXPECT_TRUE(rfh_observer.deleted()); |
| 362 } | 364 } |
| 363 EXPECT_EQ(active_rfh, contents()->GetMainFrame()); | 365 EXPECT_EQ(active_rfh, contents()->GetMainFrame()); |
| 364 EXPECT_EQ(NULL, contents()->GetPendingMainFrame()); | 366 EXPECT_EQ(NULL, contents()->GetPendingMainFrame()); |
| 365 } | 367 } |
| 366 | 368 |
| 367 bool ShouldSwapProcesses(RenderFrameHostManager* manager, | 369 bool ShouldSwapProcesses(RenderFrameHostManager* manager, |
| 368 const NavigationEntryImpl* current_entry, | 370 const NavigationEntryImpl* current_entry, |
| 369 const NavigationEntryImpl* new_entry) const { | 371 const NavigationEntryImpl* new_entry) const { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // for synchronous messages, which cannot be ignored without leaving the | 569 // for synchronous messages, which cannot be ignored without leaving the |
| 568 // renderer in a stuck state. See http://crbug.com/93427. | 570 // renderer in a stuck state. See http://crbug.com/93427. |
| 569 TEST_F(RenderFrameHostManagerTest, FilterMessagesWhileSwappedOut) { | 571 TEST_F(RenderFrameHostManagerTest, FilterMessagesWhileSwappedOut) { |
| 570 const GURL kChromeURL("chrome://foo"); | 572 const GURL kChromeURL("chrome://foo"); |
| 571 const GURL kDestUrl("http://www.google.com/"); | 573 const GURL kDestUrl("http://www.google.com/"); |
| 572 std::vector<FaviconURL> icons; | 574 std::vector<FaviconURL> icons; |
| 573 | 575 |
| 574 // Navigate our first tab to a chrome url and then to the destination. | 576 // Navigate our first tab to a chrome url and then to the destination. |
| 575 NavigateActiveAndCommit(kChromeURL); | 577 NavigateActiveAndCommit(kChromeURL); |
| 576 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 578 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
| 577 TestRenderViewHost* ntp_rvh = ntp_rfh->GetRenderViewHost(); | |
| 578 | 579 |
| 579 // Send an update favicon message and make sure it works. | 580 // Send an update favicon message and make sure it works. |
| 580 { | 581 { |
| 581 PluginFaviconMessageObserver observer(contents()); | 582 PluginFaviconMessageObserver observer(contents()); |
| 582 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetWidget()->OnMessageReceived( | 583 EXPECT_TRUE(ntp_rfh->OnMessageReceived( |
| 583 ViewHostMsg_UpdateFaviconURL( | 584 FrameHostMsg_UpdateFaviconURL(ntp_rfh->GetRoutingID(), icons))); |
| 584 ntp_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | |
| 585 EXPECT_TRUE(observer.favicon_received()); | 585 EXPECT_TRUE(observer.favicon_received()); |
| 586 } | 586 } |
| 587 // Create one more frame in the same SiteInstance where ntp_rfh | 587 // Create one more frame in the same SiteInstance where ntp_rfh |
| 588 // exists so that it doesn't get deleted on navigation to another | 588 // exists so that it doesn't get deleted on navigation to another |
| 589 // site. | 589 // site. |
| 590 ntp_rfh->GetSiteInstance()->IncrementActiveFrameCount(); | 590 ntp_rfh->GetSiteInstance()->IncrementActiveFrameCount(); |
| 591 | 591 |
| 592 // Navigate to a cross-site URL. | 592 // Navigate to a cross-site URL (don't swap out to keep |ntp_rfh| alive). |
| 593 NavigateActiveAndCommit(kDestUrl); | 593 NavigateActiveAndCommit(kDestUrl, true /* dont_swap_out */); |
| 594 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); | 594 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); |
| 595 ASSERT_TRUE(dest_rfh); | 595 ASSERT_TRUE(dest_rfh); |
| 596 EXPECT_NE(ntp_rfh, dest_rfh); | 596 EXPECT_NE(ntp_rfh, dest_rfh); |
| 597 | 597 |
| 598 // The new RVH should be able to update its favicon. | 598 // The new RVH should be able to update its favicon. |
| 599 { | 599 { |
| 600 PluginFaviconMessageObserver observer(contents()); | 600 PluginFaviconMessageObserver observer(contents()); |
| 601 EXPECT_TRUE(dest_rfh->GetRenderViewHost()->GetWidget()->OnMessageReceived( | 601 EXPECT_TRUE(dest_rfh->OnMessageReceived( |
| 602 ViewHostMsg_UpdateFaviconURL( | 602 FrameHostMsg_UpdateFaviconURL(dest_rfh->GetRoutingID(), icons))); |
| 603 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | |
| 604 EXPECT_TRUE(observer.favicon_received()); | 603 EXPECT_TRUE(observer.favicon_received()); |
| 605 } | 604 } |
| 606 | 605 |
| 607 // The old renderer, being slow, now updates the favicon. It should be | 606 // The old renderer, being slow, now updates the favicon. It should be |
| 608 // filtered out and not take effect. | 607 // filtered out and not take effect. |
| 609 { | 608 { |
| 610 PluginFaviconMessageObserver observer(contents()); | 609 PluginFaviconMessageObserver observer(contents()); |
| 611 EXPECT_TRUE( | 610 EXPECT_TRUE(ntp_rfh->OnMessageReceived( |
| 612 ntp_rvh->GetWidget()->OnMessageReceived(ViewHostMsg_UpdateFaviconURL( | 611 FrameHostMsg_UpdateFaviconURL(ntp_rfh->GetRoutingID(), icons))); |
| 613 dest_rfh->GetRenderViewHost()->GetRoutingID(), icons))); | |
| 614 EXPECT_FALSE(observer.favicon_received()); | 612 EXPECT_FALSE(observer.favicon_received()); |
| 615 } | 613 } |
| 616 } | 614 } |
| 617 | 615 |
| 618 // Test that the ViewHostMsg_UpdateFaviconURL IPC message is ignored if the | 616 // Test that the FrameHostMsg_UpdateFaviconURL IPC message is ignored if the |
| 619 // renderer is in the STATE_PENDING_SWAP_OUT_STATE. The favicon code assumes | 617 // renderer is in the STATE_PENDING_SWAP_OUT_STATE. The favicon code assumes |
| 620 // that it only gets ViewHostMsg_UpdateFaviconURL messages for the most recently | 618 // that it only gets FrameHostMsg_UpdateFaviconURL messages for the most |
| 621 // committed navigation for each WebContentsImpl. | 619 // recently committed navigation for each WebContentsImpl. |
| 622 TEST_F(RenderFrameHostManagerTest, UpdateFaviconURLWhilePendingSwapOut) { | 620 TEST_F(RenderFrameHostManagerTest, UpdateFaviconURLWhilePendingSwapOut) { |
| 623 const GURL kChromeURL("chrome://foo"); | 621 const GURL kChromeURL("chrome://foo"); |
| 624 const GURL kDestUrl("http://www.google.com/"); | 622 const GURL kDestUrl("http://www.google.com/"); |
| 625 std::vector<FaviconURL> icons; | 623 std::vector<FaviconURL> icons; |
| 626 | 624 |
| 627 // Navigate our first tab to a chrome url and then to the destination. | 625 // Navigate our first tab to a chrome url and then to the destination. |
| 628 NavigateActiveAndCommit(kChromeURL); | 626 NavigateActiveAndCommit(kChromeURL); |
| 629 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 627 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 630 | 628 |
| 631 // Send an update favicon message and make sure it works. | 629 // Send an update favicon message and make sure it works. |
| 632 { | 630 { |
| 633 PluginFaviconMessageObserver observer(contents()); | 631 PluginFaviconMessageObserver observer(contents()); |
| 634 EXPECT_TRUE(rfh1->GetRenderViewHost()->GetWidget()->OnMessageReceived( | 632 EXPECT_TRUE(rfh1->OnMessageReceived( |
| 635 ViewHostMsg_UpdateFaviconURL(rfh1->GetRenderViewHost()->GetRoutingID(), | 633 FrameHostMsg_UpdateFaviconURL(rfh1->GetRoutingID(), icons))); |
| 636 icons))); | |
| 637 EXPECT_TRUE(observer.favicon_received()); | 634 EXPECT_TRUE(observer.favicon_received()); |
| 638 } | 635 } |
| 639 | 636 |
| 640 // Create one more frame in the same SiteInstance where |rfh1| exists so that | 637 // Create one more frame in the same SiteInstance where |rfh1| exists so that |
| 641 // it doesn't get deleted on navigation to another site. | 638 // it doesn't get deleted on navigation to another site. |
| 642 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); | 639 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); |
| 643 | 640 |
| 644 // Navigate to a cross-site URL and commit the new page. | 641 // Navigate to a cross-site URL and commit the new page. |
| 645 controller().LoadURL( | 642 controller().LoadURL( |
| 646 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 643 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 647 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 644 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 648 contents()->GetMainFrame()->PrepareForCommit(); | 645 contents()->GetMainFrame()->PrepareForCommit(); |
| 649 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 646 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 650 contents()->TestDidNavigate(rfh2, entry_id, true, kDestUrl, | 647 contents()->TestDidNavigate(rfh2, entry_id, true, kDestUrl, |
| 651 ui::PAGE_TRANSITION_TYPED); | 648 ui::PAGE_TRANSITION_TYPED); |
| 652 EXPECT_FALSE(rfh1->is_active()); | 649 EXPECT_FALSE(rfh1->is_active()); |
| 653 EXPECT_TRUE(rfh2->is_active()); | 650 EXPECT_TRUE(rfh2->is_active()); |
| 654 | 651 |
| 655 // The new RVH should be able to update its favicons. | 652 // The new RVH should be able to update its favicons. |
| 656 { | 653 { |
| 657 PluginFaviconMessageObserver observer(contents()); | 654 PluginFaviconMessageObserver observer(contents()); |
| 658 EXPECT_TRUE(rfh2->GetRenderViewHost()->GetWidget()->OnMessageReceived( | 655 EXPECT_TRUE(rfh2->OnMessageReceived( |
| 659 ViewHostMsg_UpdateFaviconURL(rfh2->GetRenderViewHost()->GetRoutingID(), | 656 FrameHostMsg_UpdateFaviconURL(rfh2->GetRoutingID(), icons))); |
| 660 icons))); | |
| 661 EXPECT_TRUE(observer.favicon_received()); | 657 EXPECT_TRUE(observer.favicon_received()); |
| 662 } | 658 } |
| 663 | 659 |
| 664 // The old renderer, being slow, now updates its favicons. The message should | 660 // The old renderer, being slow, now updates its favicons. The message should |
| 665 // be ignored. | 661 // be ignored. |
| 666 { | 662 { |
| 667 PluginFaviconMessageObserver observer(contents()); | 663 PluginFaviconMessageObserver observer(contents()); |
| 668 EXPECT_TRUE(rfh1->GetRenderViewHost()->GetWidget()->OnMessageReceived( | 664 EXPECT_TRUE(rfh1->OnMessageReceived( |
| 669 ViewHostMsg_UpdateFaviconURL(rfh1->GetRenderViewHost()->GetRoutingID(), | 665 FrameHostMsg_UpdateFaviconURL(rfh1->GetRoutingID(), icons))); |
| 670 icons))); | |
| 671 EXPECT_FALSE(observer.favicon_received()); | 666 EXPECT_FALSE(observer.favicon_received()); |
| 672 } | 667 } |
| 673 } | 668 } |
| 674 | 669 |
| 675 // Test if RenderViewHost::GetRenderWidgetHosts() only returns active | 670 // Test if RenderViewHost::GetRenderWidgetHosts() only returns active |
| 676 // widgets. | 671 // widgets. |
| 677 TEST_F(RenderFrameHostManagerTest, GetRenderWidgetHostsReturnsActiveViews) { | 672 TEST_F(RenderFrameHostManagerTest, GetRenderWidgetHostsReturnsActiveViews) { |
| 678 CreateSwappedOutRenderViewHost(); | 673 CreateSwappedOutRenderViewHost(); |
| 679 std::unique_ptr<RenderWidgetHostIterator> widgets( | 674 std::unique_ptr<RenderWidgetHostIterator> widgets( |
| 680 RenderWidgetHost::GetRenderWidgetHosts()); | 675 RenderWidgetHost::GetRenderWidgetHosts()); |
| (...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3161 ASSERT_FALSE(delete_observer.deleted()); | 3156 ASSERT_FALSE(delete_observer.deleted()); |
| 3162 EXPECT_FALSE(initial_rfh->is_active()); | 3157 EXPECT_FALSE(initial_rfh->is_active()); |
| 3163 | 3158 |
| 3164 // The initial RFH receives a DidStartProvisionalLoad IPC. It should not | 3159 // The initial RFH receives a DidStartProvisionalLoad IPC. It should not |
| 3165 // create a NavigationHandle. | 3160 // create a NavigationHandle. |
| 3166 initial_rfh->SimulateNavigationStart(kUrl3); | 3161 initial_rfh->SimulateNavigationStart(kUrl3); |
| 3167 EXPECT_FALSE(initial_rfh->navigation_handle()); | 3162 EXPECT_FALSE(initial_rfh->navigation_handle()); |
| 3168 } | 3163 } |
| 3169 | 3164 |
| 3170 } // namespace content | 3165 } // namespace content |
| OLD | NEW |