Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1048463004: PlzNavigate: track pending commits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved state tracking to RFH Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); 1527 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1524 1528
1525 RenderFrameHostImpl* host = NULL; 1529 RenderFrameHostImpl* host = NULL;
1526 1530
1527 // 1) The first navigation. -------------------------- 1531 // 1) The first navigation. --------------------------
1528 const GURL kUrl1("http://www.google.com/"); 1532 const GURL kUrl1("http://www.google.com/");
1529 NavigationEntryImpl entry1( 1533 NavigationEntryImpl entry1(
1530 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 1534 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
1531 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, 1535 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED,
1532 false /* is_renderer_init */); 1536 false /* is_renderer_init */);
1533 host = manager->Navigate(entry1); 1537 host = GetFrameHostForNavigation(manager, entry1);
1534 1538
1535 // The RenderFrameHost created in Init will be reused. 1539 // The RenderFrameHost created in Init will be reused.
1536 EXPECT_TRUE(host == manager->current_frame_host()); 1540 EXPECT_TRUE(host == manager->current_frame_host());
1537 EXPECT_FALSE(manager->pending_frame_host()); 1541 EXPECT_FALSE(manager->pending_frame_host());
1538 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); 1542 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance);
1539 1543
1540 // Commit. 1544 // Commit.
1541 manager->DidNavigateFrame(host, true); 1545 manager->DidNavigateFrame(host, true);
1542 // Commit to SiteInstance should be delayed until RenderFrame commit. 1546 // Commit to SiteInstance should be delayed until RenderFrame commit.
1543 EXPECT_EQ(host, manager->current_frame_host()); 1547 EXPECT_EQ(host, manager->current_frame_host());
1544 ASSERT_TRUE(host); 1548 ASSERT_TRUE(host);
1545 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); 1549 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1546 1550
1547 // 2) Navigate to a different domain. ------------------------- 1551 // 2) Navigate to a different domain. -------------------------
1548 // Guests stay in the same process on navigation. 1552 // Guests stay in the same process on navigation.
1549 const GURL kUrl2("http://www.chromium.org"); 1553 const GURL kUrl2("http://www.chromium.org");
1550 NavigationEntryImpl entry2( 1554 NavigationEntryImpl entry2(
1551 NULL /* instance */, -1 /* page_id */, kUrl2, 1555 NULL /* instance */, -1 /* page_id */, kUrl2,
1552 Referrer(kUrl1, blink::WebReferrerPolicyDefault), 1556 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
1553 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, 1557 base::string16() /* title */, ui::PAGE_TRANSITION_LINK,
1554 true /* is_renderer_init */); 1558 true /* is_renderer_init */);
1555 host = manager->Navigate(entry2); 1559 host = GetFrameHostForNavigation(manager, entry2);
1556 1560
1557 // The RenderFrameHost created in Init will be reused. 1561 // The RenderFrameHost created in Init will be reused.
1558 EXPECT_EQ(host, manager->current_frame_host()); 1562 EXPECT_EQ(host, manager->current_frame_host());
1559 EXPECT_FALSE(manager->pending_frame_host()); 1563 EXPECT_FALSE(manager->pending_frame_host());
1560 1564
1561 // Commit. 1565 // Commit.
1562 manager->DidNavigateFrame(host, true); 1566 manager->DidNavigateFrame(host, true);
1563 EXPECT_EQ(host, manager->current_frame_host()); 1567 EXPECT_EQ(host, manager->current_frame_host());
1564 ASSERT_TRUE(host); 1568 ASSERT_TRUE(host);
1565 EXPECT_EQ(host->GetSiteInstance(), instance); 1569 EXPECT_EQ(host->GetSiteInstance(), instance);
(...skipping 14 matching lines...) Expand all
1580 Source<WebContents>(web_contents.get())); 1584 Source<WebContents>(web_contents.get()));
1581 1585
1582 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); 1586 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1583 1587
1584 // 1) The first navigation. -------------------------- 1588 // 1) The first navigation. --------------------------
1585 const GURL kUrl1("http://www.google.com/"); 1589 const GURL kUrl1("http://www.google.com/");
1586 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 1590 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1587 Referrer(), base::string16() /* title */, 1591 Referrer(), base::string16() /* title */,
1588 ui::PAGE_TRANSITION_TYPED, 1592 ui::PAGE_TRANSITION_TYPED,
1589 false /* is_renderer_init */); 1593 false /* is_renderer_init */);
1590 RenderFrameHostImpl* host = manager->Navigate(entry1); 1594 RenderFrameHostImpl* host = GetFrameHostForNavigation(manager, entry1);
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(GetPendingFrameHost(manager));
1595 1599
1596 // We should observe a notification. 1600 // We should observe a notification.
1597 EXPECT_TRUE( 1601 EXPECT_TRUE(
1598 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 1602 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
1599 notifications.Reset(); 1603 notifications.Reset();
1600 1604
1601 // Commit. 1605 // Commit.
1602 manager->DidNavigateFrame(host, true); 1606 manager->DidNavigateFrame(host, true);
1603 1607
1604 // Commit to SiteInstance should be delayed until RenderFrame commits. 1608 // Commit to SiteInstance should be delayed until RenderFrame commits.
1605 EXPECT_EQ(host, manager->current_frame_host()); 1609 EXPECT_EQ(host, manager->current_frame_host());
1606 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); 1610 EXPECT_FALSE(host->GetSiteInstance()->HasSite());
1607 host->GetSiteInstance()->SetSite(kUrl1); 1611 host->GetSiteInstance()->SetSite(kUrl1);
1608 1612
1609 // 2) Cross-site navigate to next site. ------------------------- 1613 // 2) Cross-site navigate to next site. -------------------------
1610 const GURL kUrl2("http://www.example.com"); 1614 const GURL kUrl2("http://www.example.com");
1611 NavigationEntryImpl entry2( 1615 NavigationEntryImpl entry2(
1612 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), 1616 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(),
1613 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, 1617 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED,
1614 false /* is_renderer_init */); 1618 false /* is_renderer_init */);
1615 RenderFrameHostImpl* host2 = manager->Navigate(entry2); 1619 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(manager, entry2);
1616 1620
1617 // A new RenderFrameHost should be created. 1621 // A new RenderFrameHost should be created.
1618 ASSERT_EQ(host2, manager->pending_frame_host()); 1622 ASSERT_EQ(host2, GetPendingFrameHost(manager));
1619 EXPECT_NE(host2, host); 1623 EXPECT_NE(host2, host);
1620 1624
1621 EXPECT_EQ(host, manager->current_frame_host()); 1625 EXPECT_EQ(host, manager->current_frame_host());
1622 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); 1626 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out());
1623 EXPECT_EQ(host2, manager->pending_frame_host()); 1627 EXPECT_EQ(host2, GetPendingFrameHost(manager));
1624 1628
1625 // 3) Close the tab. ------------------------- 1629 // 3) Close the tab. -------------------------
1626 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 1630 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1627 Source<RenderWidgetHost>(host2->render_view_host())); 1631 Source<RenderWidgetHost>(host2->render_view_host()));
1628 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); 1632 manager->OnBeforeUnloadACK(false, true, base::TimeTicks());
1629 1633
1630 EXPECT_TRUE( 1634 EXPECT_TRUE(
1631 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); 1635 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED));
1632 EXPECT_FALSE(manager->pending_frame_host()); 1636 EXPECT_FALSE(GetPendingFrameHost(manager));
1633 EXPECT_EQ(host, manager->current_frame_host()); 1637 EXPECT_EQ(host, manager->current_frame_host());
1634 } 1638 }
1635 1639
1636 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { 1640 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) {
1637 const GURL kUrl1("http://www.google.com/"); 1641 const GURL kUrl1("http://www.google.com/");
1638 const GURL kUrl2("http://www.chromium.org/"); 1642 const GURL kUrl2("http://www.chromium.org/");
1639 1643
1640 CloseWebContentsDelegate close_delegate; 1644 CloseWebContentsDelegate close_delegate;
1641 contents()->SetDelegate(&close_delegate); 1645 contents()->SetDelegate(&close_delegate);
1642 1646
1643 // Navigate to the first page. 1647 // Navigate to the first page.
1644 contents()->NavigateAndCommit(kUrl1); 1648 contents()->NavigateAndCommit(kUrl1);
1645 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); 1649 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
1646 1650
1647 // Start to close the tab, but assume it's unresponsive. 1651 // Start to close the tab, but assume it's unresponsive.
1648 rfh1->render_view_host()->ClosePage(); 1652 rfh1->render_view_host()->ClosePage();
1649 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); 1653 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack());
1650 1654
1651 // Start a navigation to a new site. 1655 // Start a navigation to a new site.
1652 controller().LoadURL( 1656 controller().LoadURL(
1653 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1657 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1654 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1658 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1655 switches::kEnableBrowserSideNavigation)) { 1659 switches::kEnableBrowserSideNavigation)) {
1656 rfh1->PrepareForCommit(); 1660 rfh1->PrepareForCommit();
1657 } 1661 }
1658 EXPECT_TRUE(contents()->cross_navigation_pending()); 1662 EXPECT_TRUE(contents()->CrossNavigationPending());
1659 1663
1660 // Simulate the unresponsiveness timer. The tab should close. 1664 // Simulate the unresponsiveness timer. The tab should close.
1661 contents()->RendererUnresponsive(rfh1->render_view_host()); 1665 contents()->RendererUnresponsive(rfh1->render_view_host());
1662 EXPECT_TRUE(close_delegate.is_closed()); 1666 EXPECT_TRUE(close_delegate.is_closed());
1663 } 1667 }
1664 1668
1665 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is 1669 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is
1666 // received. (SwapOut and the corresponding ACK always occur after commit.) 1670 // received. (SwapOut and the corresponding ACK always occur after commit.)
1667 // Also tests that an early SwapOutACK is properly ignored. 1671 // Also tests that an early SwapOutACK is properly ignored.
1668 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { 1672 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) {
1669 const GURL kUrl1("http://www.google.com/"); 1673 const GURL kUrl1("http://www.google.com/");
1670 const GURL kUrl2("http://www.chromium.org/"); 1674 const GURL kUrl2("http://www.chromium.org/");
1671 1675
1672 // Navigate to the first page. 1676 // Navigate to the first page.
1673 contents()->NavigateAndCommit(kUrl1); 1677 contents()->NavigateAndCommit(kUrl1);
1674 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); 1678 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
1675 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1679 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1676 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1680 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1677 1681
1678 // Navigate to new site, simulating onbeforeunload approval. 1682 // Navigate to new site, simulating onbeforeunload approval.
1679 controller().LoadURL( 1683 controller().LoadURL(
1680 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1684 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1681 contents()->GetMainFrame()->PrepareForCommit(); 1685 contents()->GetMainFrame()->PrepareForCommit();
1682 EXPECT_TRUE(contents()->cross_navigation_pending()); 1686 EXPECT_TRUE(contents()->CrossNavigationPending());
1683 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1687 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1684 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1688 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1685 1689
1686 // Simulate the swap out ack, unexpectedly early (before commit). It should 1690 // Simulate the swap out ack, unexpectedly early (before commit). It should
1687 // have no effect. 1691 // have no effect.
1688 rfh1->OnSwappedOut(); 1692 rfh1->OnSwappedOut();
1689 EXPECT_TRUE(contents()->cross_navigation_pending()); 1693 EXPECT_TRUE(contents()->CrossNavigationPending());
1690 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1694 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1691 1695
1692 // The new page commits. 1696 // The new page commits.
1693 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1697 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED);
1694 EXPECT_FALSE(contents()->cross_navigation_pending()); 1698 EXPECT_FALSE(contents()->CrossNavigationPending());
1695 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1699 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1696 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1700 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1697 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1701 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1698 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1702 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1699 EXPECT_TRUE( 1703 EXPECT_TRUE(
1700 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); 1704 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1));
1701 1705
1702 // Simulate the swap out ack. 1706 // Simulate the swap out ack.
1703 rfh1->OnSwappedOut(); 1707 rfh1->OnSwappedOut();
1704 1708
(...skipping 15 matching lines...) Expand all
1720 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1724 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1721 1725
1722 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is 1726 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is
1723 // not deleted on swap out. 1727 // not deleted on swap out.
1724 rfh1->GetSiteInstance()->increment_active_frame_count(); 1728 rfh1->GetSiteInstance()->increment_active_frame_count();
1725 1729
1726 // Navigate to new site, simulating onbeforeunload approval. 1730 // Navigate to new site, simulating onbeforeunload approval.
1727 controller().LoadURL( 1731 controller().LoadURL(
1728 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1732 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1729 contents()->GetMainFrame()->PrepareForCommit(); 1733 contents()->GetMainFrame()->PrepareForCommit();
1730 EXPECT_TRUE(contents()->cross_navigation_pending()); 1734 EXPECT_TRUE(contents()->CrossNavigationPending());
1731 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1735 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1732 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1736 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1733 1737
1734 // The new page commits. 1738 // The new page commits.
1735 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1739 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED);
1736 EXPECT_FALSE(contents()->cross_navigation_pending()); 1740 EXPECT_FALSE(contents()->CrossNavigationPending());
1737 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1741 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1738 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1742 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1739 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1743 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1740 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1744 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1741 1745
1742 // Simulate the swap out ack. 1746 // Simulate the swap out ack.
1743 rfh1->OnSwappedOut(); 1747 rfh1->OnSwappedOut();
1744 1748
1745 // rfh1 should be swapped out. 1749 // rfh1 should be swapped out.
1746 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1750 EXPECT_FALSE(rfh_deleted_observer.deleted());
(...skipping 16 matching lines...) Expand all
1763 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1767 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1764 1768
1765 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is 1769 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is
1766 // not deleted on swap out. 1770 // not deleted on swap out.
1767 rfh1->GetSiteInstance()->increment_active_frame_count(); 1771 rfh1->GetSiteInstance()->increment_active_frame_count();
1768 1772
1769 // Navigate to new site, simulating onbeforeunload approval. 1773 // Navigate to new site, simulating onbeforeunload approval.
1770 controller().LoadURL( 1774 controller().LoadURL(
1771 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1775 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1772 rfh1->PrepareForCommit(); 1776 rfh1->PrepareForCommit();
1773 EXPECT_TRUE(contents()->cross_navigation_pending()); 1777 EXPECT_TRUE(contents()->CrossNavigationPending());
1774 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1778 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1775 1779
1776 // The new page commits. 1780 // The new page commits.
1777 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1781 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED);
1778 EXPECT_FALSE(contents()->cross_navigation_pending()); 1782 EXPECT_FALSE(contents()->CrossNavigationPending());
1779 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1783 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1780 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1784 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1781 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1785 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1782 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1786 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1783 1787
1784 // Simulate the swap out ack. 1788 // Simulate the swap out ack.
1785 rfh1->OnSwappedOut(); 1789 rfh1->OnSwappedOut();
1786 1790
1787 // rfh1 should be swapped out. 1791 // rfh1 should be swapped out.
1788 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1792 EXPECT_FALSE(rfh_deleted_observer.deleted());
(...skipping 18 matching lines...) Expand all
1807 controller().LoadURL( 1811 controller().LoadURL(
1808 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1812 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1809 { 1813 {
1810 pending_rfh = contents()->GetFrameTree()->root()->render_manager() 1814 pending_rfh = contents()->GetFrameTree()->root()->render_manager()
1811 ->pending_frame_host(); 1815 ->pending_frame_host();
1812 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); 1816 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh);
1813 1817
1814 // Cancel the navigation by simulating a declined beforeunload dialog. 1818 // Cancel the navigation by simulating a declined beforeunload dialog.
1815 contents()->GetMainFrame()->OnMessageReceived( 1819 contents()->GetMainFrame()->OnMessageReceived(
1816 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1820 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1817 EXPECT_FALSE(contents()->cross_navigation_pending()); 1821 EXPECT_FALSE(contents()->CrossNavigationPending());
1818 1822
1819 // Since the pending RFH is the only one for the new SiteInstance, it should 1823 // Since the pending RFH is the only one for the new SiteInstance, it should
1820 // be deleted. 1824 // be deleted.
1821 EXPECT_TRUE(rfh_deleted_observer.deleted()); 1825 EXPECT_TRUE(rfh_deleted_observer.deleted());
1822 } 1826 }
1823 1827
1824 // Start another cross-site navigation. 1828 // Start another cross-site navigation.
1825 controller().LoadURL( 1829 controller().LoadURL(
1826 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1830 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1827 { 1831 {
1828 pending_rfh = contents()->GetFrameTree()->root()->render_manager() 1832 pending_rfh = contents()->GetFrameTree()->root()->render_manager()
1829 ->pending_frame_host(); 1833 ->pending_frame_host();
1830 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); 1834 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh);
1831 1835
1832 // Increment the number of active frames in the new SiteInstance, which will 1836 // Increment the number of active frames in the new SiteInstance, which will
1833 // cause the pending RFH to be swapped out instead of deleted. 1837 // cause the pending RFH to be swapped out instead of deleted.
1834 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 1838 pending_rfh->GetSiteInstance()->increment_active_frame_count();
1835 1839
1836 contents()->GetMainFrame()->OnMessageReceived( 1840 contents()->GetMainFrame()->OnMessageReceived(
1837 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1841 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1838 EXPECT_FALSE(contents()->cross_navigation_pending()); 1842 EXPECT_FALSE(contents()->CrossNavigationPending());
1839 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1843 EXPECT_FALSE(rfh_deleted_observer.deleted());
1840 } 1844 }
1841 } 1845 }
1842 1846
1843 // Test that a pending RenderFrameHost in a non-root frame tree node is properly 1847 // Test that a pending RenderFrameHost in a non-root frame tree node is properly
1844 // deleted when the node is detached. Motivated by http://crbug.com/441357 and 1848 // deleted when the node is detached. Motivated by http://crbug.com/441357 and
1845 // http://crbug.com/444955. 1849 // http://crbug.com/444955.
1846 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { 1850 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) {
1847 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1851 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1848 switches::kSitePerProcess); 1852 switches::kSitePerProcess);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); 1903 EXPECT_EQ(host2, GetPendingFrameHost(iframe2));
1900 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( 1904 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive(
1901 GetPendingFrameHost(iframe1)->rfh_state())); 1905 GetPendingFrameHost(iframe1)->rfh_state()));
1902 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( 1906 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive(
1903 GetPendingFrameHost(iframe2)->rfh_state())); 1907 GetPendingFrameHost(iframe2)->rfh_state()));
1904 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); 1908 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2));
1905 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), 1909 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(),
1906 GetPendingFrameHost(iframe2)->GetSiteInstance()); 1910 GetPendingFrameHost(iframe2)->GetSiteInstance());
1907 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); 1911 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1));
1908 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); 1912 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2));
1909 EXPECT_FALSE(contents()->cross_navigation_pending()) 1913 EXPECT_FALSE(contents()->CrossNavigationPending());
1910 << "There should be no top-level pending navigation.";
1911 1914
1912 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); 1915 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1));
1913 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); 1916 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2));
1914 EXPECT_FALSE(delete_watcher1.deleted()); 1917 EXPECT_FALSE(delete_watcher1.deleted());
1915 EXPECT_FALSE(delete_watcher2.deleted()); 1918 EXPECT_FALSE(delete_watcher2.deleted());
1916 1919
1917 // Keep the SiteInstance alive for testing. 1920 // Keep the SiteInstance alive for testing.
1918 scoped_refptr<SiteInstanceImpl> site_instance = 1921 scoped_refptr<SiteInstanceImpl> site_instance =
1919 GetPendingFrameHost(iframe1)->GetSiteInstance(); 1922 GetPendingFrameHost(iframe1)->GetSiteInstance();
1920 EXPECT_TRUE(site_instance->HasSite()); 1923 EXPECT_TRUE(site_instance->HasSite());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); 2021 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
2019 contents2->NavigateAndCommit(kUrl3); 2022 contents2->NavigateAndCommit(kUrl3);
2020 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); 2023 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive());
2021 EXPECT_NE(nullptr, 2024 EXPECT_NE(nullptr,
2022 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); 2025 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
2023 EXPECT_EQ(nullptr, 2026 EXPECT_EQ(nullptr,
2024 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); 2027 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
2025 } 2028 }
2026 2029
2027 } // namespace content 2030 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698