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 return manager->GetFrameHostForNavigation(*navigation_request, true); |
389 } | 389 } |
390 return manager->Navigate(entry); | 390 return manager->Navigate(entry); |
391 } | 391 } |
392 | 392 |
393 // Returns the pending RenderFrameHost. | 393 // Returns the pending RenderFrameHost. |
394 // PlzNavigate: returns the speculative RenderFrameHost. | 394 // PlzNavigate: returns the speculative RenderFrameHost. |
395 RenderFrameHostImpl* GetPendingFrameHost( | 395 RenderFrameHostImpl* GetPendingFrameHost( |
396 RenderFrameHostManager* manager) { | 396 RenderFrameHostManager* manager) { |
397 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 397 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
398 switches::kEnableBrowserSideNavigation)) { | 398 switches::kEnableBrowserSideNavigation)) { |
(...skipping 27 matching lines...) Expand all Loading... |
426 scoped_ptr<TestWebContents> contents2( | 426 scoped_ptr<TestWebContents> contents2( |
427 TestWebContents::Create(browser_context(), NULL)); | 427 TestWebContents::Create(browser_context(), NULL)); |
428 | 428 |
429 // Load the two URLs in the second tab. Note that the first navigation creates | 429 // Load the two URLs in the second tab. Note that the first navigation creates |
430 // a RFH that's not pending (since there is no cross-site transition), so | 430 // a RFH that's not pending (since there is no cross-site transition), so |
431 // we use the committed one. | 431 // we use the committed one. |
432 contents2->GetController().LoadURL( | 432 contents2->GetController().LoadURL( |
433 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 433 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
434 contents2->GetMainFrame()->PrepareForCommit(); | 434 contents2->GetMainFrame()->PrepareForCommit(); |
435 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 435 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
436 EXPECT_FALSE(contents2->cross_navigation_pending()); | 436 EXPECT_FALSE(contents2->CrossNavigationPending()); |
437 ntp_rfh2->SendNavigate(100, kChromeUrl); | 437 ntp_rfh2->SendNavigate(100, kChromeUrl); |
438 | 438 |
439 // The second one is the opposite, creating a cross-site transition and | 439 // The second one is the opposite, creating a cross-site transition and |
440 // requiring a beforeunload ack. | 440 // requiring a beforeunload ack. |
441 contents2->GetController().LoadURL( | 441 contents2->GetController().LoadURL( |
442 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 442 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
443 contents2->GetMainFrame()->PrepareForCommit(); | 443 contents2->GetMainFrame()->PrepareForCommit(); |
444 EXPECT_TRUE(contents2->cross_navigation_pending()); | 444 EXPECT_TRUE(contents2->CrossNavigationPending()); |
445 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 445 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
446 ASSERT_TRUE(dest_rfh2); | 446 ASSERT_TRUE(dest_rfh2); |
447 | 447 |
448 dest_rfh2->SendNavigate(101, kDestUrl); | 448 dest_rfh2->SendNavigate(101, kDestUrl); |
449 | 449 |
450 // The two RFH's should be different in every way. | 450 // The two RFH's should be different in every way. |
451 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 451 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
452 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 452 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
453 dest_rfh2->GetSiteInstance()); | 453 dest_rfh2->GetSiteInstance()); |
454 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 454 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1515 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1516 | 1516 |
1517 RenderFrameHostImpl* host = NULL; | 1517 RenderFrameHostImpl* host = NULL; |
1518 | 1518 |
1519 // 1) The first navigation. -------------------------- | 1519 // 1) The first navigation. -------------------------- |
1520 const GURL kUrl1("http://www.google.com/"); | 1520 const GURL kUrl1("http://www.google.com/"); |
1521 NavigationEntryImpl entry1( | 1521 NavigationEntryImpl entry1( |
1522 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 1522 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
1523 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1523 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
1524 false /* is_renderer_init */); | 1524 false /* is_renderer_init */); |
1525 host = manager->Navigate(entry1); | 1525 host = GetFrameHostForNavigation(manager, entry1); |
1526 | 1526 |
1527 // The RenderFrameHost created in Init will be reused. | 1527 // The RenderFrameHost created in Init will be reused. |
1528 EXPECT_TRUE(host == manager->current_frame_host()); | 1528 EXPECT_TRUE(host == manager->current_frame_host()); |
1529 EXPECT_FALSE(manager->pending_frame_host()); | 1529 EXPECT_FALSE(manager->pending_frame_host()); |
1530 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); | 1530 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); |
1531 | 1531 |
1532 // Commit. | 1532 // Commit. |
1533 manager->DidNavigateFrame(host, true); | 1533 manager->DidNavigateFrame(host, true); |
1534 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1534 // Commit to SiteInstance should be delayed until RenderFrame commit. |
1535 EXPECT_EQ(host, manager->current_frame_host()); | 1535 EXPECT_EQ(host, manager->current_frame_host()); |
1536 ASSERT_TRUE(host); | 1536 ASSERT_TRUE(host); |
1537 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1537 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
1538 | 1538 |
1539 // 2) Navigate to a different domain. ------------------------- | 1539 // 2) Navigate to a different domain. ------------------------- |
1540 // Guests stay in the same process on navigation. | 1540 // Guests stay in the same process on navigation. |
1541 const GURL kUrl2("http://www.chromium.org"); | 1541 const GURL kUrl2("http://www.chromium.org"); |
1542 NavigationEntryImpl entry2( | 1542 NavigationEntryImpl entry2( |
1543 NULL /* instance */, -1 /* page_id */, kUrl2, | 1543 NULL /* instance */, -1 /* page_id */, kUrl2, |
1544 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1544 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
1545 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 1545 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
1546 true /* is_renderer_init */); | 1546 true /* is_renderer_init */); |
1547 host = manager->Navigate(entry2); | 1547 host = GetFrameHostForNavigation(manager, entry2); |
1548 | 1548 |
1549 // The RenderFrameHost created in Init will be reused. | 1549 // The RenderFrameHost created in Init will be reused. |
1550 EXPECT_EQ(host, manager->current_frame_host()); | 1550 EXPECT_EQ(host, manager->current_frame_host()); |
1551 EXPECT_FALSE(manager->pending_frame_host()); | 1551 EXPECT_FALSE(manager->pending_frame_host()); |
1552 | 1552 |
1553 // Commit. | 1553 // Commit. |
1554 manager->DidNavigateFrame(host, true); | 1554 manager->DidNavigateFrame(host, true); |
1555 EXPECT_EQ(host, manager->current_frame_host()); | 1555 EXPECT_EQ(host, manager->current_frame_host()); |
1556 ASSERT_TRUE(host); | 1556 ASSERT_TRUE(host); |
1557 EXPECT_EQ(host->GetSiteInstance(), instance); | 1557 EXPECT_EQ(host->GetSiteInstance(), instance); |
(...skipping 14 matching lines...) Expand all Loading... |
1572 Source<WebContents>(web_contents.get())); | 1572 Source<WebContents>(web_contents.get())); |
1573 | 1573 |
1574 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1574 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1575 | 1575 |
1576 // 1) The first navigation. -------------------------- | 1576 // 1) The first navigation. -------------------------- |
1577 const GURL kUrl1("http://www.google.com/"); | 1577 const GURL kUrl1("http://www.google.com/"); |
1578 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1578 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
1579 Referrer(), base::string16() /* title */, | 1579 Referrer(), base::string16() /* title */, |
1580 ui::PAGE_TRANSITION_TYPED, | 1580 ui::PAGE_TRANSITION_TYPED, |
1581 false /* is_renderer_init */); | 1581 false /* is_renderer_init */); |
1582 RenderFrameHostImpl* host = manager->Navigate(entry1); | 1582 RenderFrameHostImpl* host = GetFrameHostForNavigation(manager, entry1); |
1583 | 1583 |
1584 // The RenderFrameHost created in Init will be reused. | 1584 // The RenderFrameHost created in Init will be reused. |
1585 EXPECT_EQ(host, manager->current_frame_host()); | 1585 EXPECT_EQ(host, manager->current_frame_host()); |
1586 EXPECT_FALSE(manager->pending_frame_host()); | 1586 EXPECT_FALSE(GetPendingFrameHost(manager)); |
1587 | 1587 |
1588 // We should observe a notification. | 1588 // We should observe a notification. |
1589 EXPECT_TRUE( | 1589 EXPECT_TRUE( |
1590 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 1590 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
1591 notifications.Reset(); | 1591 notifications.Reset(); |
1592 | 1592 |
1593 // Commit. | 1593 // Commit. |
1594 manager->DidNavigateFrame(host, true); | 1594 manager->DidNavigateFrame(host, true); |
1595 | 1595 |
1596 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1596 // Commit to SiteInstance should be delayed until RenderFrame commits. |
1597 EXPECT_EQ(host, manager->current_frame_host()); | 1597 EXPECT_EQ(host, manager->current_frame_host()); |
1598 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 1598 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
1599 host->GetSiteInstance()->SetSite(kUrl1); | 1599 host->GetSiteInstance()->SetSite(kUrl1); |
1600 | 1600 |
1601 // 2) Cross-site navigate to next site. ------------------------- | 1601 // 2) Cross-site navigate to next site. ------------------------- |
1602 const GURL kUrl2("http://www.example.com"); | 1602 const GURL kUrl2("http://www.example.com"); |
1603 NavigationEntryImpl entry2( | 1603 NavigationEntryImpl entry2( |
1604 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | 1604 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), |
1605 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1605 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
1606 false /* is_renderer_init */); | 1606 false /* is_renderer_init */); |
1607 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | 1607 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(manager, entry2); |
1608 | 1608 |
1609 // A new RenderFrameHost should be created. | 1609 // A new RenderFrameHost should be created. |
1610 ASSERT_EQ(host2, manager->pending_frame_host()); | 1610 ASSERT_EQ(host2, GetPendingFrameHost(manager)); |
1611 EXPECT_NE(host2, host); | 1611 EXPECT_NE(host2, host); |
1612 | 1612 |
1613 EXPECT_EQ(host, manager->current_frame_host()); | 1613 EXPECT_EQ(host, manager->current_frame_host()); |
1614 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | 1614 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); |
1615 EXPECT_EQ(host2, manager->pending_frame_host()); | 1615 EXPECT_EQ(host2, GetPendingFrameHost(manager)); |
1616 | 1616 |
1617 // 3) Close the tab. ------------------------- | 1617 // 3) Close the tab. ------------------------- |
1618 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1618 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
1619 Source<RenderWidgetHost>(host2->render_view_host())); | 1619 Source<RenderWidgetHost>(host2->render_view_host())); |
1620 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); | 1620 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); |
1621 | 1621 |
1622 EXPECT_TRUE( | 1622 EXPECT_TRUE( |
1623 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); | 1623 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); |
1624 EXPECT_FALSE(manager->pending_frame_host()); | 1624 EXPECT_FALSE(GetPendingFrameHost(manager)); |
1625 EXPECT_EQ(host, manager->current_frame_host()); | 1625 EXPECT_EQ(host, manager->current_frame_host()); |
1626 } | 1626 } |
1627 | 1627 |
1628 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { | 1628 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { |
1629 const GURL kUrl1("http://www.google.com/"); | 1629 const GURL kUrl1("http://www.google.com/"); |
1630 const GURL kUrl2("http://www.chromium.org/"); | 1630 const GURL kUrl2("http://www.chromium.org/"); |
1631 | 1631 |
1632 CloseWebContentsDelegate close_delegate; | 1632 CloseWebContentsDelegate close_delegate; |
1633 contents()->SetDelegate(&close_delegate); | 1633 contents()->SetDelegate(&close_delegate); |
1634 | 1634 |
1635 // Navigate to the first page. | 1635 // Navigate to the first page. |
1636 contents()->NavigateAndCommit(kUrl1); | 1636 contents()->NavigateAndCommit(kUrl1); |
1637 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1637 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1638 | 1638 |
1639 // Start to close the tab, but assume it's unresponsive. | 1639 // Start to close the tab, but assume it's unresponsive. |
1640 rfh1->render_view_host()->ClosePage(); | 1640 rfh1->render_view_host()->ClosePage(); |
1641 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1641 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
1642 | 1642 |
1643 // Start a navigation to a new site. | 1643 // Start a navigation to a new site. |
1644 controller().LoadURL( | 1644 controller().LoadURL( |
1645 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1645 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1646 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1646 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1647 switches::kEnableBrowserSideNavigation)) { | 1647 switches::kEnableBrowserSideNavigation)) { |
1648 rfh1->PrepareForCommit(); | 1648 rfh1->PrepareForCommit(); |
1649 } | 1649 } |
1650 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1650 EXPECT_TRUE(contents()->CrossNavigationPending()); |
1651 | 1651 |
1652 // Simulate the unresponsiveness timer. The tab should close. | 1652 // Simulate the unresponsiveness timer. The tab should close. |
1653 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1653 contents()->RendererUnresponsive(rfh1->render_view_host()); |
1654 EXPECT_TRUE(close_delegate.is_closed()); | 1654 EXPECT_TRUE(close_delegate.is_closed()); |
1655 } | 1655 } |
1656 | 1656 |
1657 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1657 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
1658 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1658 // received. (SwapOut and the corresponding ACK always occur after commit.) |
1659 // Also tests that an early SwapOutACK is properly ignored. | 1659 // Also tests that an early SwapOutACK is properly ignored. |
1660 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1660 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
1661 const GURL kUrl1("http://www.google.com/"); | 1661 const GURL kUrl1("http://www.google.com/"); |
1662 const GURL kUrl2("http://www.chromium.org/"); | 1662 const GURL kUrl2("http://www.chromium.org/"); |
1663 | 1663 |
1664 // Navigate to the first page. | 1664 // Navigate to the first page. |
1665 contents()->NavigateAndCommit(kUrl1); | 1665 contents()->NavigateAndCommit(kUrl1); |
1666 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1666 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1667 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1667 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1668 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1668 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1669 | 1669 |
1670 // Navigate to new site, simulating onbeforeunload approval. | 1670 // Navigate to new site, simulating onbeforeunload approval. |
1671 controller().LoadURL( | 1671 controller().LoadURL( |
1672 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1672 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1673 contents()->GetMainFrame()->PrepareForCommit(); | 1673 contents()->GetMainFrame()->PrepareForCommit(); |
1674 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1674 EXPECT_TRUE(contents()->CrossNavigationPending()); |
1675 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1675 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1676 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1676 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1677 | 1677 |
1678 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1678 // Simulate the swap out ack, unexpectedly early (before commit). It should |
1679 // have no effect. | 1679 // have no effect. |
1680 rfh1->OnSwappedOut(); | 1680 rfh1->OnSwappedOut(); |
1681 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1681 EXPECT_TRUE(contents()->CrossNavigationPending()); |
1682 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1682 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1683 | 1683 |
1684 // The new page commits. | 1684 // The new page commits. |
1685 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1685 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1686 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1686 EXPECT_FALSE(contents()->CrossNavigationPending()); |
1687 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1687 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1688 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1688 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1689 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1689 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1690 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1690 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1691 EXPECT_TRUE( | 1691 EXPECT_TRUE( |
1692 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); | 1692 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); |
1693 | 1693 |
1694 // Simulate the swap out ack. | 1694 // Simulate the swap out ack. |
1695 rfh1->OnSwappedOut(); | 1695 rfh1->OnSwappedOut(); |
1696 | 1696 |
(...skipping 15 matching lines...) Expand all Loading... |
1712 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1712 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1713 | 1713 |
1714 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1714 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1715 // not deleted on swap out. | 1715 // not deleted on swap out. |
1716 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1716 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1717 | 1717 |
1718 // Navigate to new site, simulating onbeforeunload approval. | 1718 // Navigate to new site, simulating onbeforeunload approval. |
1719 controller().LoadURL( | 1719 controller().LoadURL( |
1720 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1720 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1721 contents()->GetMainFrame()->PrepareForCommit(); | 1721 contents()->GetMainFrame()->PrepareForCommit(); |
1722 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1722 EXPECT_TRUE(contents()->CrossNavigationPending()); |
1723 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1723 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1724 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1724 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1725 | 1725 |
1726 // The new page commits. | 1726 // The new page commits. |
1727 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1727 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1728 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1728 EXPECT_FALSE(contents()->CrossNavigationPending()); |
1729 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1729 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1730 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1730 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1731 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1731 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1732 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1732 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1733 | 1733 |
1734 // Simulate the swap out ack. | 1734 // Simulate the swap out ack. |
1735 rfh1->OnSwappedOut(); | 1735 rfh1->OnSwappedOut(); |
1736 | 1736 |
1737 // rfh1 should be swapped out. | 1737 // rfh1 should be swapped out. |
1738 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1738 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
(...skipping 16 matching lines...) Expand all Loading... |
1755 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1755 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1756 | 1756 |
1757 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1757 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1758 // not deleted on swap out. | 1758 // not deleted on swap out. |
1759 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1759 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1760 | 1760 |
1761 // Navigate to new site, simulating onbeforeunload approval. | 1761 // Navigate to new site, simulating onbeforeunload approval. |
1762 controller().LoadURL( | 1762 controller().LoadURL( |
1763 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1763 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1764 rfh1->PrepareForCommit(); | 1764 rfh1->PrepareForCommit(); |
1765 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1765 EXPECT_TRUE(contents()->CrossNavigationPending()); |
1766 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1766 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1767 | 1767 |
1768 // The new page commits. | 1768 // The new page commits. |
1769 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1769 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
1770 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1770 EXPECT_FALSE(contents()->CrossNavigationPending()); |
1771 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1771 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1772 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1772 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1773 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1773 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1774 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1774 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1775 | 1775 |
1776 // Simulate the swap out ack. | 1776 // Simulate the swap out ack. |
1777 rfh1->OnSwappedOut(); | 1777 rfh1->OnSwappedOut(); |
1778 | 1778 |
1779 // rfh1 should be swapped out. | 1779 // rfh1 should be swapped out. |
1780 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1780 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
(...skipping 18 matching lines...) Expand all Loading... |
1799 controller().LoadURL( | 1799 controller().LoadURL( |
1800 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1800 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1801 { | 1801 { |
1802 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1802 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1803 ->pending_frame_host(); | 1803 ->pending_frame_host(); |
1804 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1804 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
1805 | 1805 |
1806 // Cancel the navigation by simulating a declined beforeunload dialog. | 1806 // Cancel the navigation by simulating a declined beforeunload dialog. |
1807 contents()->GetMainFrame()->OnMessageReceived( | 1807 contents()->GetMainFrame()->OnMessageReceived( |
1808 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1808 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1809 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1809 EXPECT_FALSE(contents()->CrossNavigationPending()); |
1810 | 1810 |
1811 // Since the pending RFH is the only one for the new SiteInstance, it should | 1811 // Since the pending RFH is the only one for the new SiteInstance, it should |
1812 // be deleted. | 1812 // be deleted. |
1813 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1813 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
1814 } | 1814 } |
1815 | 1815 |
1816 // Start another cross-site navigation. | 1816 // Start another cross-site navigation. |
1817 controller().LoadURL( | 1817 controller().LoadURL( |
1818 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1818 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
1819 { | 1819 { |
1820 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1820 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
1821 ->pending_frame_host(); | 1821 ->pending_frame_host(); |
1822 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1822 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
1823 | 1823 |
1824 // Increment the number of active frames in the new SiteInstance, which will | 1824 // Increment the number of active frames in the new SiteInstance, which will |
1825 // cause the pending RFH to be swapped out instead of deleted. | 1825 // cause the pending RFH to be swapped out instead of deleted. |
1826 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1826 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
1827 | 1827 |
1828 contents()->GetMainFrame()->OnMessageReceived( | 1828 contents()->GetMainFrame()->OnMessageReceived( |
1829 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1829 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1830 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1830 EXPECT_FALSE(contents()->CrossNavigationPending()); |
1831 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1831 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
1832 } | 1832 } |
1833 } | 1833 } |
1834 | 1834 |
1835 // Test that a pending RenderFrameHost in a non-root frame tree node is properly | 1835 // Test that a pending RenderFrameHost in a non-root frame tree node is properly |
1836 // deleted when the node is detached. Motivated by http://crbug.com/441357 | 1836 // deleted when the node is detached. Motivated by http://crbug.com/441357 |
1837 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { | 1837 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { |
1838 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1838 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1839 switches::kSitePerProcess); | 1839 switches::kSitePerProcess); |
1840 | 1840 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1873 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
1874 base::string16() /* title */, | 1874 base::string16() /* title */, |
1875 ui::PAGE_TRANSITION_LINK, | 1875 ui::PAGE_TRANSITION_LINK, |
1876 false /* is_renderer_init */); | 1876 false /* is_renderer_init */); |
1877 host = GetFrameHostForNavigation(manager, entry2); | 1877 host = GetFrameHostForNavigation(manager, entry2); |
1878 | 1878 |
1879 // A new RenderFrameHost should be created. | 1879 // A new RenderFrameHost should be created. |
1880 EXPECT_TRUE(GetPendingFrameHost(manager)); | 1880 EXPECT_TRUE(GetPendingFrameHost(manager)); |
1881 ASSERT_EQ(host, GetPendingFrameHost(manager)); | 1881 ASSERT_EQ(host, GetPendingFrameHost(manager)); |
1882 ASSERT_NE(manager->current_frame_host(), GetPendingFrameHost(manager)); | 1882 ASSERT_NE(manager->current_frame_host(), GetPendingFrameHost(manager)); |
1883 EXPECT_FALSE(contents()->cross_navigation_pending()) | 1883 EXPECT_FALSE(contents()->CrossNavigationPending()) |
1884 << "There should be no top-level pending navigation."; | 1884 << "There should be no top-level pending navigation."; |
1885 | 1885 |
1886 RenderFrameHostDeletedObserver delete_watcher(GetPendingFrameHost(manager)); | 1886 RenderFrameHostDeletedObserver delete_watcher(GetPendingFrameHost(manager)); |
1887 EXPECT_FALSE(delete_watcher.deleted()); | 1887 EXPECT_FALSE(delete_watcher.deleted()); |
1888 | 1888 |
1889 // Extend the lifetime of the child frame's SiteInstance, pretending | 1889 // Extend the lifetime of the child frame's SiteInstance, pretending |
1890 // that there is another reference to it. | 1890 // that there is another reference to it. |
1891 scoped_refptr<SiteInstanceImpl> site_instance = | 1891 scoped_refptr<SiteInstanceImpl> site_instance = |
1892 GetPendingFrameHost(manager)->GetSiteInstance(); | 1892 GetPendingFrameHost(manager)->GetSiteInstance(); |
1893 EXPECT_TRUE(site_instance->HasSite()); | 1893 EXPECT_TRUE(site_instance->HasSite()); |
(...skipping 14 matching lines...) Expand all Loading... |
1908 #if 0 | 1908 #if 0 |
1909 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. | 1909 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. |
1910 // Enable this assert below once the proxies to the subframe are correctly | 1910 // Enable this assert below once the proxies to the subframe are correctly |
1911 // cleaned up after detach. http://crbug.com/444955. | 1911 // cleaned up after detach. http://crbug.com/444955. |
1912 ASSERT_TRUE(site_instance->HasOneRef()) | 1912 ASSERT_TRUE(site_instance->HasOneRef()) |
1913 << "This SiteInstance should be destroyable now."; | 1913 << "This SiteInstance should be destroyable now."; |
1914 #endif | 1914 #endif |
1915 } | 1915 } |
1916 | 1916 |
1917 } // namespace content | 1917 } // namespace content |
OLD | NEW |