Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 const GURL kDestUrl("http://www.google.com/"); | 345 const GURL kDestUrl("http://www.google.com/"); |
| 346 | 346 |
| 347 // Navigate our first tab to a chrome url and then to the destination. | 347 // Navigate our first tab to a chrome url and then to the destination. |
| 348 NavigateActiveAndCommit(kChromeURL); | 348 NavigateActiveAndCommit(kChromeURL); |
| 349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
| 350 | 350 |
| 351 // Navigate to a cross-site URL. | 351 // Navigate to a cross-site URL. |
| 352 contents()->GetController().LoadURL( | 352 contents()->GetController().LoadURL( |
| 353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 354 contents()->GetMainFrame()->PrepareForCommit(); | 354 contents()->GetMainFrame()->PrepareForCommit(); |
| 355 EXPECT_TRUE(contents()->cross_navigation_pending()); | 355 EXPECT_TRUE(contents()->CrossNavigationPending()); |
| 356 | 356 |
| 357 // Manually increase the number of active frames in the | 357 // Manually increase the number of active frames in the |
| 358 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 358 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
| 359 // destroyed when it gets swapped out. | 359 // destroyed when it gets swapped out. |
| 360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); | 360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 361 | 361 |
| 362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
| 363 CHECK(dest_rfh); | 363 CHECK(dest_rfh); |
| 364 EXPECT_NE(ntp_rfh, dest_rfh); | 364 EXPECT_NE(ntp_rfh, dest_rfh); |
| 365 | 365 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 378 RenderFrameHostImpl* GetFrameHostForNavigation( | 378 RenderFrameHostImpl* GetFrameHostForNavigation( |
| 379 RenderFrameHostManager* manager, | 379 RenderFrameHostManager* manager, |
| 380 const NavigationEntryImpl& entry) { | 380 const NavigationEntryImpl& entry) { |
| 381 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 381 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 382 switches::kEnableBrowserSideNavigation)) { | 382 switches::kEnableBrowserSideNavigation)) { |
| 383 scoped_ptr<NavigationRequest> navigation_request = | 383 scoped_ptr<NavigationRequest> navigation_request = |
| 384 NavigationRequest::CreateBrowserInitiated( | 384 NavigationRequest::CreateBrowserInitiated( |
| 385 manager->frame_tree_node_, entry, FrameMsg_Navigate_Type::NORMAL, | 385 manager->frame_tree_node_, entry, FrameMsg_Navigate_Type::NORMAL, |
| 386 base::TimeTicks::Now(), | 386 base::TimeTicks::Now(), |
| 387 static_cast<NavigationControllerImpl*>(&controller())); | 387 static_cast<NavigationControllerImpl*>(&controller())); |
| 388 return manager->GetFrameHostForNavigation(*navigation_request); | 388 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( |
| 389 manager->GetFrameHostForNavigation(*navigation_request)); | |
| 390 CHECK(frame_host); | |
| 391 frame_host->set_pending_commit(true); | |
| 392 return frame_host; | |
| 389 } | 393 } |
| 390 return manager->Navigate(entry); | 394 return manager->Navigate(entry); |
| 391 } | 395 } |
| 392 | 396 |
| 393 // Returns the pending RenderFrameHost. | 397 // Returns the pending RenderFrameHost. |
| 394 // PlzNavigate: returns the speculative RenderFrameHost. | 398 // PlzNavigate: returns the speculative RenderFrameHost. |
| 395 RenderFrameHostImpl* GetPendingFrameHost( | 399 RenderFrameHostImpl* GetPendingFrameHost( |
| 396 RenderFrameHostManager* manager) { | 400 RenderFrameHostManager* manager) { |
| 397 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 401 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 398 switches::kEnableBrowserSideNavigation)) { | 402 switches::kEnableBrowserSideNavigation)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 scoped_ptr<TestWebContents> contents2( | 448 scoped_ptr<TestWebContents> contents2( |
| 445 TestWebContents::Create(browser_context(), NULL)); | 449 TestWebContents::Create(browser_context(), NULL)); |
| 446 | 450 |
| 447 // Load the two URLs in the second tab. Note that the first navigation creates | 451 // Load the two URLs in the second tab. Note that the first navigation creates |
| 448 // a RFH that's not pending (since there is no cross-site transition), so | 452 // a RFH that's not pending (since there is no cross-site transition), so |
| 449 // we use the committed one. | 453 // we use the committed one. |
| 450 contents2->GetController().LoadURL( | 454 contents2->GetController().LoadURL( |
| 451 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 455 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 452 contents2->GetMainFrame()->PrepareForCommit(); | 456 contents2->GetMainFrame()->PrepareForCommit(); |
| 453 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 457 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
| 454 EXPECT_FALSE(contents2->cross_navigation_pending()); | 458 EXPECT_FALSE(contents2->CrossNavigationPending()); |
| 455 ntp_rfh2->SendNavigate(100, kChromeUrl); | 459 ntp_rfh2->SendNavigate(100, kChromeUrl); |
| 456 | 460 |
| 457 // The second one is the opposite, creating a cross-site transition and | 461 // The second one is the opposite, creating a cross-site transition and |
| 458 // requiring a beforeunload ack. | 462 // requiring a beforeunload ack. |
| 459 contents2->GetController().LoadURL( | 463 contents2->GetController().LoadURL( |
| 460 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 464 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 461 contents2->GetMainFrame()->PrepareForCommit(); | 465 contents2->GetMainFrame()->PrepareForCommit(); |
| 462 EXPECT_TRUE(contents2->cross_navigation_pending()); | 466 EXPECT_TRUE(contents2->CrossNavigationPending()); |
| 463 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 467 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
| 464 ASSERT_TRUE(dest_rfh2); | 468 ASSERT_TRUE(dest_rfh2); |
| 465 | 469 |
| 466 dest_rfh2->SendNavigate(101, kDestUrl); | 470 dest_rfh2->SendNavigate(101, kDestUrl); |
| 467 | 471 |
| 468 // The two RFH's should be different in every way. | 472 // The two RFH's should be different in every way. |
| 469 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 473 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
| 470 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 474 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
| 471 dest_rfh2->GetSiteInstance()); | 475 dest_rfh2->GetSiteInstance()); |
| 472 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 476 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1558 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1562 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1559 | 1563 |
| 1560 RenderFrameHostImpl* host = NULL; | 1564 RenderFrameHostImpl* host = NULL; |
| 1561 | 1565 |
| 1562 // 1) The first navigation. -------------------------- | 1566 // 1) The first navigation. -------------------------- |
| 1563 const GURL kUrl1("http://www.google.com/"); | 1567 const GURL kUrl1("http://www.google.com/"); |
| 1564 NavigationEntryImpl entry1( | 1568 NavigationEntryImpl entry1( |
| 1565 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 1569 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 1566 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1570 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 1567 false /* is_renderer_init */); | 1571 false /* is_renderer_init */); |
| 1568 host = manager->Navigate(entry1); | 1572 host = GetFrameHostForNavigation(manager, entry1); |
|
nasko
2015/04/15 21:12:45
It seems a bit strange to replace a "Navigate" cal
Charlie Reis
2015/04/15 21:54:17
I agree that the name of the helper function feels
clamy
2015/04/16 13:18:36
I've renamed the function NavigateToEntry since it
| |
| 1569 | 1573 |
| 1570 // The RenderFrameHost created in Init will be reused. | 1574 // The RenderFrameHost created in Init will be reused. |
| 1571 EXPECT_TRUE(host == manager->current_frame_host()); | 1575 EXPECT_TRUE(host == manager->current_frame_host()); |
| 1572 EXPECT_FALSE(manager->pending_frame_host()); | 1576 EXPECT_FALSE(manager->pending_frame_host()); |
| 1573 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); | 1577 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); |
| 1574 | 1578 |
| 1575 // Commit. | 1579 // Commit. |
| 1576 manager->DidNavigateFrame(host, true); | 1580 manager->DidNavigateFrame(host, true); |
| 1577 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1581 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 1578 EXPECT_EQ(host, manager->current_frame_host()); | 1582 EXPECT_EQ(host, manager->current_frame_host()); |
| 1579 ASSERT_TRUE(host); | 1583 ASSERT_TRUE(host); |
| 1580 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1584 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 1581 | 1585 |
| 1582 // 2) Navigate to a different domain. ------------------------- | 1586 // 2) Navigate to a different domain. ------------------------- |
| 1583 // Guests stay in the same process on navigation. | 1587 // Guests stay in the same process on navigation. |
| 1584 const GURL kUrl2("http://www.chromium.org"); | 1588 const GURL kUrl2("http://www.chromium.org"); |
| 1585 NavigationEntryImpl entry2( | 1589 NavigationEntryImpl entry2( |
| 1586 NULL /* instance */, -1 /* page_id */, kUrl2, | 1590 NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1587 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1591 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 1588 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 1592 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 1589 true /* is_renderer_init */); | 1593 true /* is_renderer_init */); |
| 1590 host = manager->Navigate(entry2); | 1594 host = GetFrameHostForNavigation(manager, entry2); |
| 1591 | 1595 |
| 1592 // The RenderFrameHost created in Init will be reused. | 1596 // The RenderFrameHost created in Init will be reused. |
| 1593 EXPECT_EQ(host, manager->current_frame_host()); | 1597 EXPECT_EQ(host, manager->current_frame_host()); |
| 1594 EXPECT_FALSE(manager->pending_frame_host()); | 1598 EXPECT_FALSE(manager->pending_frame_host()); |
| 1595 | 1599 |
| 1596 // Commit. | 1600 // Commit. |
| 1597 manager->DidNavigateFrame(host, true); | 1601 manager->DidNavigateFrame(host, true); |
| 1598 EXPECT_EQ(host, manager->current_frame_host()); | 1602 EXPECT_EQ(host, manager->current_frame_host()); |
| 1599 ASSERT_TRUE(host); | 1603 ASSERT_TRUE(host); |
| 1600 EXPECT_EQ(host->GetSiteInstance(), instance); | 1604 EXPECT_EQ(host->GetSiteInstance(), instance); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1615 Source<WebContents>(web_contents.get())); | 1619 Source<WebContents>(web_contents.get())); |
| 1616 | 1620 |
| 1617 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1621 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1618 | 1622 |
| 1619 // 1) The first navigation. -------------------------- | 1623 // 1) The first navigation. -------------------------- |
| 1620 const GURL kUrl1("http://www.google.com/"); | 1624 const GURL kUrl1("http://www.google.com/"); |
| 1621 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1625 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 1622 Referrer(), base::string16() /* title */, | 1626 Referrer(), base::string16() /* title */, |
| 1623 ui::PAGE_TRANSITION_TYPED, | 1627 ui::PAGE_TRANSITION_TYPED, |
| 1624 false /* is_renderer_init */); | 1628 false /* is_renderer_init */); |
| 1625 RenderFrameHostImpl* host = manager->Navigate(entry1); | 1629 RenderFrameHostImpl* host = GetFrameHostForNavigation(manager, entry1); |
| 1626 | 1630 |
| 1627 // The RenderFrameHost created in Init will be reused. | 1631 // The RenderFrameHost created in Init will be reused. |
| 1628 EXPECT_EQ(host, manager->current_frame_host()); | 1632 EXPECT_EQ(host, manager->current_frame_host()); |
| 1629 EXPECT_FALSE(manager->pending_frame_host()); | 1633 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1630 | 1634 |
| 1631 // We should observe a notification. | 1635 // We should observe a notification. |
| 1632 EXPECT_TRUE( | 1636 EXPECT_TRUE( |
| 1633 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 1637 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 1634 notifications.Reset(); | 1638 notifications.Reset(); |
| 1635 | 1639 |
| 1636 // Commit. | 1640 // Commit. |
| 1637 manager->DidNavigateFrame(host, true); | 1641 manager->DidNavigateFrame(host, true); |
| 1638 | 1642 |
| 1639 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1643 // Commit to SiteInstance should be delayed until RenderFrame commits. |
| 1640 EXPECT_EQ(host, manager->current_frame_host()); | 1644 EXPECT_EQ(host, manager->current_frame_host()); |
| 1641 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 1645 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
| 1642 host->GetSiteInstance()->SetSite(kUrl1); | 1646 host->GetSiteInstance()->SetSite(kUrl1); |
| 1643 | 1647 |
| 1644 // 2) Cross-site navigate to next site. ------------------------- | 1648 // 2) Cross-site navigate to next site. ------------------------- |
| 1645 const GURL kUrl2("http://www.example.com"); | 1649 const GURL kUrl2("http://www.example.com"); |
| 1646 NavigationEntryImpl entry2( | 1650 NavigationEntryImpl entry2( |
| 1647 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | 1651 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), |
| 1648 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1652 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 1649 false /* is_renderer_init */); | 1653 false /* is_renderer_init */); |
| 1650 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | 1654 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(manager, entry2); |
| 1651 | 1655 |
| 1652 // A new RenderFrameHost should be created. | 1656 // A new RenderFrameHost should be created. |
| 1653 ASSERT_EQ(host2, manager->pending_frame_host()); | 1657 ASSERT_EQ(host2, GetPendingFrameHost(manager)); |
| 1654 EXPECT_NE(host2, host); | 1658 EXPECT_NE(host2, host); |
| 1655 | 1659 |
| 1656 EXPECT_EQ(host, manager->current_frame_host()); | 1660 EXPECT_EQ(host, manager->current_frame_host()); |
| 1657 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | 1661 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); |
| 1658 EXPECT_EQ(host2, manager->pending_frame_host()); | 1662 EXPECT_EQ(host2, GetPendingFrameHost(manager)); |
| 1659 | 1663 |
| 1660 // 3) Close the tab. ------------------------- | 1664 // 3) Close the tab. ------------------------- |
| 1661 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1665 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1662 Source<RenderWidgetHost>(host2->render_view_host())); | 1666 Source<RenderWidgetHost>(host2->render_view_host())); |
| 1663 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); | 1667 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); |
| 1664 | 1668 |
| 1665 EXPECT_TRUE( | 1669 EXPECT_TRUE( |
| 1666 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); | 1670 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); |
| 1667 EXPECT_FALSE(manager->pending_frame_host()); | 1671 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1668 EXPECT_EQ(host, manager->current_frame_host()); | 1672 EXPECT_EQ(host, manager->current_frame_host()); |
| 1669 } | 1673 } |
| 1670 | 1674 |
| 1671 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { | 1675 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { |
| 1672 const GURL kUrl1("http://www.google.com/"); | 1676 const GURL kUrl1("http://www.google.com/"); |
| 1673 const GURL kUrl2("http://www.chromium.org/"); | 1677 const GURL kUrl2("http://www.chromium.org/"); |
| 1674 | 1678 |
| 1675 CloseWebContentsDelegate close_delegate; | 1679 CloseWebContentsDelegate close_delegate; |
| 1676 contents()->SetDelegate(&close_delegate); | 1680 contents()->SetDelegate(&close_delegate); |
| 1677 | 1681 |
| 1678 // Navigate to the first page. | 1682 // Navigate to the first page. |
| 1679 contents()->NavigateAndCommit(kUrl1); | 1683 contents()->NavigateAndCommit(kUrl1); |
| 1680 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1684 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1681 | 1685 |
| 1682 // Start to close the tab, but assume it's unresponsive. | 1686 // Start to close the tab, but assume it's unresponsive. |
| 1683 rfh1->render_view_host()->ClosePage(); | 1687 rfh1->render_view_host()->ClosePage(); |
| 1684 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1688 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
| 1685 | 1689 |
| 1686 // Start a navigation to a new site. | 1690 // Start a navigation to a new site. |
| 1687 controller().LoadURL( | 1691 controller().LoadURL( |
| 1688 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1692 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1689 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1693 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1690 switches::kEnableBrowserSideNavigation)) { | 1694 switches::kEnableBrowserSideNavigation)) { |
| 1691 rfh1->PrepareForCommit(); | 1695 rfh1->PrepareForCommit(); |
| 1692 } | 1696 } |
| 1693 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1697 EXPECT_TRUE(contents()->CrossNavigationPending()); |
| 1694 | 1698 |
| 1695 // Simulate the unresponsiveness timer. The tab should close. | 1699 // Simulate the unresponsiveness timer. The tab should close. |
| 1696 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1700 contents()->RendererUnresponsive(rfh1->render_view_host()); |
| 1697 EXPECT_TRUE(close_delegate.is_closed()); | 1701 EXPECT_TRUE(close_delegate.is_closed()); |
| 1698 } | 1702 } |
| 1699 | 1703 |
| 1700 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1704 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
| 1701 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1705 // received. (SwapOut and the corresponding ACK always occur after commit.) |
| 1702 // Also tests that an early SwapOutACK is properly ignored. | 1706 // Also tests that an early SwapOutACK is properly ignored. |
| 1703 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1707 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
| 1704 const GURL kUrl1("http://www.google.com/"); | 1708 const GURL kUrl1("http://www.google.com/"); |
| 1705 const GURL kUrl2("http://www.chromium.org/"); | 1709 const GURL kUrl2("http://www.chromium.org/"); |
| 1706 | 1710 |
| 1707 // Navigate to the first page. | 1711 // Navigate to the first page. |
| 1708 contents()->NavigateAndCommit(kUrl1); | 1712 contents()->NavigateAndCommit(kUrl1); |
| 1709 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1713 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1710 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1714 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
| 1711 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1715 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1712 | 1716 |
| 1713 // Navigate to new site, simulating onbeforeunload approval. | 1717 // Navigate to new site, simulating onbeforeunload approval. |
| 1714 controller().LoadURL( | 1718 controller().LoadURL( |
| 1715 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1719 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1716 contents()->GetMainFrame()->PrepareForCommit(); | 1720 contents()->GetMainFrame()->PrepareForCommit(); |
| 1717 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1721 EXPECT_TRUE(contents()->CrossNavigationPending()); |
| 1718 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1722 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1719 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1723 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1720 | 1724 |
| 1721 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1725 // Simulate the swap out ack, unexpectedly early (before commit). It should |
| 1722 // have no effect. | 1726 // have no effect. |
| 1723 rfh1->OnSwappedOut(); | 1727 rfh1->OnSwappedOut(); |
| 1724 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1728 EXPECT_TRUE(contents()->CrossNavigationPending()); |
| 1725 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1729 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1726 | 1730 |
| 1727 // The new page commits. | 1731 // The new page commits. |
| 1728 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1732 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1729 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1733 EXPECT_FALSE(contents()->CrossNavigationPending()); |
| 1730 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1734 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1731 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1735 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1732 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1736 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1733 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1737 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1734 EXPECT_TRUE( | 1738 EXPECT_TRUE( |
| 1735 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); | 1739 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); |
| 1736 | 1740 |
| 1737 // Simulate the swap out ack. | 1741 // Simulate the swap out ack. |
| 1738 rfh1->OnSwappedOut(); | 1742 rfh1->OnSwappedOut(); |
| 1739 | 1743 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1755 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1759 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1756 | 1760 |
| 1757 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1761 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1758 // not deleted on swap out. | 1762 // not deleted on swap out. |
| 1759 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1763 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1760 | 1764 |
| 1761 // Navigate to new site, simulating onbeforeunload approval. | 1765 // Navigate to new site, simulating onbeforeunload approval. |
| 1762 controller().LoadURL( | 1766 controller().LoadURL( |
| 1763 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1767 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1764 contents()->GetMainFrame()->PrepareForCommit(); | 1768 contents()->GetMainFrame()->PrepareForCommit(); |
| 1765 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1769 EXPECT_TRUE(contents()->CrossNavigationPending()); |
| 1766 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1770 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1767 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1771 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1768 | 1772 |
| 1769 // The new page commits. | 1773 // The new page commits. |
| 1770 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1774 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1771 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1775 EXPECT_FALSE(contents()->CrossNavigationPending()); |
| 1772 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1776 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1773 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1777 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1774 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1778 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1775 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1779 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1776 | 1780 |
| 1777 // Simulate the swap out ack. | 1781 // Simulate the swap out ack. |
| 1778 rfh1->OnSwappedOut(); | 1782 rfh1->OnSwappedOut(); |
| 1779 | 1783 |
| 1780 // rfh1 should be swapped out. | 1784 // rfh1 should be swapped out. |
| 1781 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1785 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1798 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1802 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1799 | 1803 |
| 1800 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1804 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1801 // not deleted on swap out. | 1805 // not deleted on swap out. |
| 1802 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1806 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1803 | 1807 |
| 1804 // Navigate to new site, simulating onbeforeunload approval. | 1808 // Navigate to new site, simulating onbeforeunload approval. |
| 1805 controller().LoadURL( | 1809 controller().LoadURL( |
| 1806 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1810 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1807 rfh1->PrepareForCommit(); | 1811 rfh1->PrepareForCommit(); |
| 1808 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1812 EXPECT_TRUE(contents()->CrossNavigationPending()); |
| 1809 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1813 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1810 | 1814 |
| 1811 // The new page commits. | 1815 // The new page commits. |
| 1812 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1816 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1813 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1817 EXPECT_FALSE(contents()->CrossNavigationPending()); |
| 1814 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1818 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1815 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1819 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1816 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1820 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1817 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1821 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1818 | 1822 |
| 1819 // Simulate the swap out ack. | 1823 // Simulate the swap out ack. |
| 1820 rfh1->OnSwappedOut(); | 1824 rfh1->OnSwappedOut(); |
| 1821 | 1825 |
| 1822 // rfh1 should be swapped out. | 1826 // rfh1 should be swapped out. |
| 1823 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1827 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1842 controller().LoadURL( | 1846 controller().LoadURL( |
| 1843 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1847 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1844 { | 1848 { |
| 1845 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1849 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1846 ->pending_frame_host(); | 1850 ->pending_frame_host(); |
| 1847 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1851 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1848 | 1852 |
| 1849 // Cancel the navigation by simulating a declined beforeunload dialog. | 1853 // Cancel the navigation by simulating a declined beforeunload dialog. |
| 1850 contents()->GetMainFrame()->OnMessageReceived( | 1854 contents()->GetMainFrame()->OnMessageReceived( |
| 1851 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1855 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1852 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1856 EXPECT_FALSE(contents()->CrossNavigationPending()); |
| 1853 | 1857 |
| 1854 // Since the pending RFH is the only one for the new SiteInstance, it should | 1858 // Since the pending RFH is the only one for the new SiteInstance, it should |
| 1855 // be deleted. | 1859 // be deleted. |
| 1856 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1860 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1857 } | 1861 } |
| 1858 | 1862 |
| 1859 // Start another cross-site navigation. | 1863 // Start another cross-site navigation. |
| 1860 controller().LoadURL( | 1864 controller().LoadURL( |
| 1861 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1865 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1862 { | 1866 { |
| 1863 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1867 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1864 ->pending_frame_host(); | 1868 ->pending_frame_host(); |
| 1865 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1869 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1866 | 1870 |
| 1867 // Increment the number of active frames in the new SiteInstance, which will | 1871 // Increment the number of active frames in the new SiteInstance, which will |
| 1868 // cause the pending RFH to be swapped out instead of deleted. | 1872 // cause the pending RFH to be swapped out instead of deleted. |
| 1869 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1873 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1870 | 1874 |
| 1871 contents()->GetMainFrame()->OnMessageReceived( | 1875 contents()->GetMainFrame()->OnMessageReceived( |
| 1872 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1876 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1873 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1877 EXPECT_FALSE(contents()->CrossNavigationPending()); |
| 1874 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1878 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 1875 } | 1879 } |
| 1876 } | 1880 } |
| 1877 | 1881 |
| 1878 // Test that a pending RenderFrameHost in a non-root frame tree node is properly | 1882 // Test that a pending RenderFrameHost in a non-root frame tree node is properly |
| 1879 // deleted when the node is detached. Motivated by http://crbug.com/441357 and | 1883 // deleted when the node is detached. Motivated by http://crbug.com/441357 and |
| 1880 // http://crbug.com/444955. | 1884 // http://crbug.com/444955. |
| 1881 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { | 1885 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { |
| 1882 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1886 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1883 switches::kSitePerProcess); | 1887 switches::kSitePerProcess); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1934 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); | 1938 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); |
| 1935 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 1939 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( |
| 1936 GetPendingFrameHost(iframe1)->rfh_state())); | 1940 GetPendingFrameHost(iframe1)->rfh_state())); |
| 1937 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 1941 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( |
| 1938 GetPendingFrameHost(iframe2)->rfh_state())); | 1942 GetPendingFrameHost(iframe2)->rfh_state())); |
| 1939 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); | 1943 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); |
| 1940 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), | 1944 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), |
| 1941 GetPendingFrameHost(iframe2)->GetSiteInstance()); | 1945 GetPendingFrameHost(iframe2)->GetSiteInstance()); |
| 1942 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); | 1946 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); |
| 1943 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); | 1947 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); |
| 1944 EXPECT_FALSE(contents()->cross_navigation_pending()) | 1948 EXPECT_FALSE(contents()->CrossNavigationPending()); |
|
nasko
2015/04/15 21:12:45
Why did we lose the string here?
clamy
2015/04/16 13:18:35
Done.
| |
| 1945 << "There should be no top-level pending navigation."; | |
| 1946 | 1949 |
| 1947 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); | 1950 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); |
| 1948 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); | 1951 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); |
| 1949 EXPECT_FALSE(delete_watcher1.deleted()); | 1952 EXPECT_FALSE(delete_watcher1.deleted()); |
| 1950 EXPECT_FALSE(delete_watcher2.deleted()); | 1953 EXPECT_FALSE(delete_watcher2.deleted()); |
| 1951 | 1954 |
| 1952 // Keep the SiteInstance alive for testing. | 1955 // Keep the SiteInstance alive for testing. |
| 1953 scoped_refptr<SiteInstanceImpl> site_instance = | 1956 scoped_refptr<SiteInstanceImpl> site_instance = |
| 1954 GetPendingFrameHost(iframe1)->GetSiteInstance(); | 1957 GetPendingFrameHost(iframe1)->GetSiteInstance(); |
| 1955 EXPECT_TRUE(site_instance->HasSite()); | 1958 EXPECT_TRUE(site_instance->HasSite()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2053 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2056 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
| 2054 contents2->NavigateAndCommit(kUrl3); | 2057 contents2->NavigateAndCommit(kUrl3); |
| 2055 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2058 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
| 2056 EXPECT_NE(nullptr, | 2059 EXPECT_NE(nullptr, |
| 2057 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2060 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
| 2058 EXPECT_EQ(nullptr, | 2061 EXPECT_EQ(nullptr, |
| 2059 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2062 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
| 2060 } | 2063 } |
| 2061 | 2064 |
| 2062 } // namespace content | 2065 } // namespace content |
| OLD | NEW |