| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // committed immediately (since it is a new tab). Therefore the main frame | 340 // committed immediately (since it is a new tab). Therefore the main frame |
| 341 // is replaced without a pending frame being created, and we don't get the | 341 // is replaced without a pending frame being created, and we don't get the |
| 342 // right values for the RFH to navigate: we try to use the old one that has | 342 // right values for the RFH to navigate: we try to use the old one that has |
| 343 // been deleted in the meantime. | 343 // been deleted in the meantime. |
| 344 contents()->GetMainFrame()->PrepareForCommit(); | 344 contents()->GetMainFrame()->PrepareForCommit(); |
| 345 | 345 |
| 346 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); | 346 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); |
| 347 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() | 347 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() |
| 348 ? contents()->GetPendingMainFrame() | 348 ? contents()->GetPendingMainFrame() |
| 349 : old_rfh; | 349 : old_rfh; |
| 350 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); | 350 EXPECT_TRUE(old_rfh->is_active()); |
| 351 | 351 |
| 352 // Commit the navigation with a new page ID. | 352 // Commit the navigation with a new page ID. |
| 353 int32_t max_page_id = | 353 int32_t max_page_id = |
| 354 contents()->GetMaxPageIDForSiteInstance(active_rfh->GetSiteInstance()); | 354 contents()->GetMaxPageIDForSiteInstance(active_rfh->GetSiteInstance()); |
| 355 | 355 |
| 356 // Use an observer to avoid accessing a deleted renderer later on when the | 356 // Use an observer to avoid accessing a deleted renderer later on when the |
| 357 // state is being checked. | 357 // state is being checked. |
| 358 RenderFrameDeletedObserver rfh_observer(old_rfh); | 358 RenderFrameDeletedObserver rfh_observer(old_rfh); |
| 359 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); | 359 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); |
| 360 active_rfh->SendNavigate(max_page_id + 1, entry_id, true, url); | 360 active_rfh->SendNavigate(max_page_id + 1, entry_id, true, url); |
| 361 | 361 |
| 362 // Make sure that we start to run the unload handler at the time of commit. | 362 // Make sure that we start to run the unload handler at the time of commit. |
| 363 if (old_rfh != active_rfh && !rfh_observer.deleted()) { | 363 if (old_rfh != active_rfh && !rfh_observer.deleted()) { |
| 364 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, | 364 EXPECT_FALSE(old_rfh->is_active()); |
| 365 old_rfh->rfh_state()); | |
| 366 } | 365 } |
| 367 | 366 |
| 368 // Simulate the swap out ACK coming from the pending renderer. This should | 367 // Simulate the swap out ACK coming from the pending renderer. This should |
| 369 // either shut down the old RFH or leave it in a swapped out state. | 368 // either shut down the old RFH or leave it in a swapped out state. |
| 370 if (old_rfh != active_rfh) { | 369 if (old_rfh != active_rfh) { |
| 371 old_rfh->OnSwappedOut(); | 370 old_rfh->OnSwappedOut(); |
| 372 EXPECT_TRUE(rfh_observer.deleted()); | 371 EXPECT_TRUE(rfh_observer.deleted()); |
| 373 } | 372 } |
| 374 EXPECT_EQ(active_rfh, contents()->GetMainFrame()); | 373 EXPECT_EQ(active_rfh, contents()->GetMainFrame()); |
| 375 EXPECT_EQ(NULL, contents()->GetPendingMainFrame()); | 374 EXPECT_EQ(NULL, contents()->GetPendingMainFrame()); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); | 651 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); |
| 653 | 652 |
| 654 // Navigate to a cross-site URL and commit the new page. | 653 // Navigate to a cross-site URL and commit the new page. |
| 655 controller().LoadURL( | 654 controller().LoadURL( |
| 656 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 655 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 657 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 656 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 658 contents()->GetMainFrame()->PrepareForCommit(); | 657 contents()->GetMainFrame()->PrepareForCommit(); |
| 659 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 658 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 660 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kDestUrl, | 659 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kDestUrl, |
| 661 ui::PAGE_TRANSITION_TYPED); | 660 ui::PAGE_TRANSITION_TYPED); |
| 662 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 661 EXPECT_FALSE(rfh1->is_active()); |
| 663 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 662 EXPECT_TRUE(rfh2->is_active()); |
| 664 | 663 |
| 665 // The new RVH should be able to update its favicons. | 664 // The new RVH should be able to update its favicons. |
| 666 { | 665 { |
| 667 PluginFaviconMessageObserver observer(contents()); | 666 PluginFaviconMessageObserver observer(contents()); |
| 668 EXPECT_TRUE(rfh2->GetRenderViewHost()->GetWidget()->OnMessageReceived( | 667 EXPECT_TRUE(rfh2->GetRenderViewHost()->GetWidget()->OnMessageReceived( |
| 669 ViewHostMsg_UpdateFaviconURL(rfh2->GetRenderViewHost()->GetRoutingID(), | 668 ViewHostMsg_UpdateFaviconURL(rfh2->GetRenderViewHost()->GetRoutingID(), |
| 670 icons))); | 669 icons))); |
| 671 EXPECT_TRUE(observer.favicon_received()); | 670 EXPECT_TRUE(observer.favicon_received()); |
| 672 } | 671 } |
| 673 | 672 |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 contents()->GetController().GoBack(); | 1274 contents()->GetController().GoBack(); |
| 1276 EXPECT_TRUE(rfh2->is_waiting_for_beforeunload_ack()); | 1275 EXPECT_TRUE(rfh2->is_waiting_for_beforeunload_ack()); |
| 1277 contents()->GetMainFrame()->PrepareForCommit(); | 1276 contents()->GetMainFrame()->PrepareForCommit(); |
| 1278 EXPECT_FALSE(rfh2->is_waiting_for_beforeunload_ack()); | 1277 EXPECT_FALSE(rfh2->is_waiting_for_beforeunload_ack()); |
| 1279 | 1278 |
| 1280 // The back navigation commits. | 1279 // The back navigation commits. |
| 1281 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1280 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
| 1282 contents()->GetPendingMainFrame()->SendNavigate( | 1281 contents()->GetPendingMainFrame()->SendNavigate( |
| 1283 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL()); | 1282 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL()); |
| 1284 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); | 1283 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
| 1285 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); | 1284 EXPECT_FALSE(rfh2->is_active()); |
| 1286 | 1285 |
| 1287 // We should be able to navigate forward. | 1286 // We should be able to navigate forward. |
| 1288 contents()->GetController().GoForward(); | 1287 contents()->GetController().GoForward(); |
| 1289 contents()->GetMainFrame()->PrepareForCommit(); | 1288 contents()->GetMainFrame()->PrepareForCommit(); |
| 1290 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1289 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
| 1291 contents()->GetPendingMainFrame()->SendNavigate( | 1290 contents()->GetPendingMainFrame()->SendNavigate( |
| 1292 entry2->GetPageID(), entry2->GetUniqueID(), false, entry2->GetURL()); | 1291 entry2->GetPageID(), entry2->GetUniqueID(), false, entry2->GetURL()); |
| 1293 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); | 1292 EXPECT_TRUE(main_test_rfh()->is_active()); |
| 1294 } | 1293 } |
| 1295 | 1294 |
| 1296 // Test that we create swapped out RFHs for the opener chain when navigating an | 1295 // Test that we create swapped out RFHs for the opener chain when navigating an |
| 1297 // opened tab cross-process. This allows us to support certain cross-process | 1296 // opened tab cross-process. This allows us to support certain cross-process |
| 1298 // JavaScript calls (http://crbug.com/99202). | 1297 // JavaScript calls (http://crbug.com/99202). |
| 1299 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRFHs) { | 1298 TEST_F(RenderFrameHostManagerTest, CreateSwappedOutOpenerRFHs) { |
| 1300 const GURL kUrl1("http://www.google.com/"); | 1299 const GURL kUrl1("http://www.google.com/"); |
| 1301 const GURL kUrl2("http://www.chromium.org/"); | 1300 const GURL kUrl2("http://www.chromium.org/"); |
| 1302 const GURL kChromeUrl("chrome://foo"); | 1301 const GURL kChromeUrl("chrome://foo"); |
| 1303 | 1302 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1755 // received. (SwapOut and the corresponding ACK always occur after commit.) |
| 1757 // Also tests that an early SwapOutACK is properly ignored. | 1756 // Also tests that an early SwapOutACK is properly ignored. |
| 1758 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1757 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
| 1759 const GURL kUrl1("http://www.google.com/"); | 1758 const GURL kUrl1("http://www.google.com/"); |
| 1760 const GURL kUrl2("http://www.chromium.org/"); | 1759 const GURL kUrl2("http://www.chromium.org/"); |
| 1761 | 1760 |
| 1762 // Navigate to the first page. | 1761 // Navigate to the first page. |
| 1763 contents()->NavigateAndCommit(kUrl1); | 1762 contents()->NavigateAndCommit(kUrl1); |
| 1764 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1763 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1765 RenderFrameDeletedObserver rfh_deleted_observer(rfh1); | 1764 RenderFrameDeletedObserver rfh_deleted_observer(rfh1); |
| 1766 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1765 EXPECT_TRUE(rfh1->is_active()); |
| 1767 | 1766 |
| 1768 // Navigate to new site, simulating onbeforeunload approval. | 1767 // Navigate to new site, simulating onbeforeunload approval. |
| 1769 controller().LoadURL( | 1768 controller().LoadURL( |
| 1770 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1769 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1771 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 1770 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 1772 contents()->GetMainFrame()->PrepareForCommit(); | 1771 contents()->GetMainFrame()->PrepareForCommit(); |
| 1773 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 1772 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1774 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1773 EXPECT_TRUE(rfh1->is_active()); |
| 1775 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1774 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1776 | 1775 |
| 1777 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1776 // Simulate the swap out ack, unexpectedly early (before commit). It should |
| 1778 // have no effect. | 1777 // have no effect. |
| 1779 rfh1->OnSwappedOut(); | 1778 rfh1->OnSwappedOut(); |
| 1780 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 1779 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1781 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1780 EXPECT_TRUE(rfh1->is_active()); |
| 1782 | 1781 |
| 1783 // The new page commits. | 1782 // The new page commits. |
| 1784 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, | 1783 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
| 1785 ui::PAGE_TRANSITION_TYPED); | 1784 ui::PAGE_TRANSITION_TYPED); |
| 1786 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1785 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1787 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1786 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1788 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1787 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1789 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1788 EXPECT_TRUE(rfh2->is_active()); |
| 1790 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1789 EXPECT_FALSE(rfh1->is_active()); |
| 1791 | 1790 |
| 1792 // Simulate the swap out ack. | 1791 // Simulate the swap out ack. |
| 1793 rfh1->OnSwappedOut(); | 1792 rfh1->OnSwappedOut(); |
| 1794 | 1793 |
| 1795 // rfh1 should have been deleted. | 1794 // rfh1 should have been deleted. |
| 1796 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1795 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1797 rfh1 = NULL; | 1796 rfh1 = NULL; |
| 1798 } | 1797 } |
| 1799 | 1798 |
| 1800 // Tests that the RenderFrameHost is properly swapped out when the SwapOut ACK | 1799 // Tests that the RenderFrameHost is properly swapped out when the SwapOut ACK |
| 1801 // is received. (SwapOut and the corresponding ACK always occur after commit.) | 1800 // is received. (SwapOut and the corresponding ACK always occur after commit.) |
| 1802 TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) { | 1801 TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) { |
| 1803 const GURL kUrl1("http://www.google.com/"); | 1802 const GURL kUrl1("http://www.google.com/"); |
| 1804 const GURL kUrl2("http://www.chromium.org/"); | 1803 const GURL kUrl2("http://www.chromium.org/"); |
| 1805 | 1804 |
| 1806 // Navigate to the first page. | 1805 // Navigate to the first page. |
| 1807 contents()->NavigateAndCommit(kUrl1); | 1806 contents()->NavigateAndCommit(kUrl1); |
| 1808 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1807 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1809 RenderFrameDeletedObserver rfh_deleted_observer(rfh1); | 1808 RenderFrameDeletedObserver rfh_deleted_observer(rfh1); |
| 1810 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1809 EXPECT_TRUE(rfh1->is_active()); |
| 1811 | 1810 |
| 1812 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1811 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1813 // not deleted on swap out. | 1812 // not deleted on swap out. |
| 1814 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); | 1813 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); |
| 1815 | 1814 |
| 1816 // Navigate to new site, simulating onbeforeunload approval. | 1815 // Navigate to new site, simulating onbeforeunload approval. |
| 1817 controller().LoadURL( | 1816 controller().LoadURL( |
| 1818 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1817 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1819 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 1818 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 1820 contents()->GetMainFrame()->PrepareForCommit(); | 1819 contents()->GetMainFrame()->PrepareForCommit(); |
| 1821 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 1820 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1822 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1821 EXPECT_TRUE(rfh1->is_active()); |
| 1823 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1822 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1824 | 1823 |
| 1825 // The new page commits. | 1824 // The new page commits. |
| 1826 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, | 1825 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
| 1827 ui::PAGE_TRANSITION_TYPED); | 1826 ui::PAGE_TRANSITION_TYPED); |
| 1828 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1827 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1829 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1828 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1830 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1829 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1831 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1830 EXPECT_FALSE(rfh1->is_active()); |
| 1832 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1831 EXPECT_TRUE(rfh2->is_active()); |
| 1833 | 1832 |
| 1834 // Simulate the swap out ack. | 1833 // Simulate the swap out ack. |
| 1835 rfh1->OnSwappedOut(); | 1834 rfh1->OnSwappedOut(); |
| 1836 | 1835 |
| 1837 // rfh1 should be deleted. | 1836 // rfh1 should be deleted. |
| 1838 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1837 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1839 } | 1838 } |
| 1840 | 1839 |
| 1841 // Test that the RenderViewHost is properly swapped out if a navigation in the | 1840 // Test that the RenderViewHost is properly swapped out if a navigation in the |
| 1842 // new renderer commits before sending the SwapOut message to the old renderer. | 1841 // new renderer commits before sending the SwapOut message to the old renderer. |
| 1843 // This simulates a cross-site navigation to a synchronously committing URL | 1842 // This simulates a cross-site navigation to a synchronously committing URL |
| 1844 // (e.g., a data URL) and ensures it works properly. | 1843 // (e.g., a data URL) and ensures it works properly. |
| 1845 TEST_F(RenderFrameHostManagerTest, | 1844 TEST_F(RenderFrameHostManagerTest, |
| 1846 CommitNewNavigationBeforeSendingSwapOut) { | 1845 CommitNewNavigationBeforeSendingSwapOut) { |
| 1847 const GURL kUrl1("http://www.google.com/"); | 1846 const GURL kUrl1("http://www.google.com/"); |
| 1848 const GURL kUrl2("http://www.chromium.org/"); | 1847 const GURL kUrl2("http://www.chromium.org/"); |
| 1849 | 1848 |
| 1850 // Navigate to the first page. | 1849 // Navigate to the first page. |
| 1851 contents()->NavigateAndCommit(kUrl1); | 1850 contents()->NavigateAndCommit(kUrl1); |
| 1852 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1851 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1853 RenderFrameDeletedObserver rfh_deleted_observer(rfh1); | 1852 RenderFrameDeletedObserver rfh_deleted_observer(rfh1); |
| 1854 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1853 EXPECT_TRUE(rfh1->is_active()); |
| 1855 | 1854 |
| 1856 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1855 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1857 // not deleted on swap out. | 1856 // not deleted on swap out. |
| 1858 scoped_refptr<SiteInstanceImpl> site_instance = rfh1->GetSiteInstance(); | 1857 scoped_refptr<SiteInstanceImpl> site_instance = rfh1->GetSiteInstance(); |
| 1859 site_instance->IncrementActiveFrameCount(); | 1858 site_instance->IncrementActiveFrameCount(); |
| 1860 | 1859 |
| 1861 // Navigate to new site, simulating onbeforeunload approval. | 1860 // Navigate to new site, simulating onbeforeunload approval. |
| 1862 controller().LoadURL( | 1861 controller().LoadURL( |
| 1863 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1862 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1864 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 1863 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 1865 rfh1->PrepareForCommit(); | 1864 rfh1->PrepareForCommit(); |
| 1866 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 1865 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1867 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1866 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1868 | 1867 |
| 1869 // The new page commits. | 1868 // The new page commits. |
| 1870 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, | 1869 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
| 1871 ui::PAGE_TRANSITION_TYPED); | 1870 ui::PAGE_TRANSITION_TYPED); |
| 1872 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1871 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1873 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1872 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1874 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1873 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1875 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1874 EXPECT_FALSE(rfh1->is_active()); |
| 1876 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1875 EXPECT_TRUE(rfh2->is_active()); |
| 1877 | 1876 |
| 1878 // Simulate the swap out ack. | 1877 // Simulate the swap out ack. |
| 1879 rfh1->OnSwappedOut(); | 1878 rfh1->OnSwappedOut(); |
| 1880 | 1879 |
| 1881 // rfh1 should be deleted. | 1880 // rfh1 should be deleted. |
| 1882 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1881 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1883 EXPECT_TRUE(contents()->GetFrameTree()->root()->render_manager() | 1882 EXPECT_TRUE(contents()->GetFrameTree()->root()->render_manager() |
| 1884 ->GetRenderFrameProxyHost(site_instance.get())); | 1883 ->GetRenderFrameProxyHost(site_instance.get())); |
| 1885 } | 1884 } |
| 1886 | 1885 |
| 1887 // Test that a RenderFrameHost is properly deleted when a cross-site navigation | 1886 // Test that a RenderFrameHost is properly deleted when a cross-site navigation |
| 1888 // is cancelled. | 1887 // is cancelled. |
| 1889 TEST_F(RenderFrameHostManagerTest, | 1888 TEST_F(RenderFrameHostManagerTest, |
| 1890 CancelPendingProperlyDeletesOrSwaps) { | 1889 CancelPendingProperlyDeletesOrSwaps) { |
| 1891 const GURL kUrl1("http://www.google.com/"); | 1890 const GURL kUrl1("http://www.google.com/"); |
| 1892 const GURL kUrl2("http://www.chromium.org/"); | 1891 const GURL kUrl2("http://www.chromium.org/"); |
| 1893 RenderFrameHostImpl* pending_rfh = NULL; | 1892 RenderFrameHostImpl* pending_rfh = NULL; |
| 1894 base::TimeTicks now = base::TimeTicks::Now(); | 1893 base::TimeTicks now = base::TimeTicks::Now(); |
| 1895 | 1894 |
| 1896 // Navigate to the first page. | 1895 // Navigate to the first page. |
| 1897 contents()->NavigateAndCommit(kUrl1); | 1896 contents()->NavigateAndCommit(kUrl1); |
| 1898 TestRenderFrameHost* rfh1 = main_test_rfh(); | 1897 TestRenderFrameHost* rfh1 = main_test_rfh(); |
| 1899 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1898 EXPECT_TRUE(rfh1->is_active()); |
| 1900 | 1899 |
| 1901 // Navigate to a new site, starting a cross-site navigation. | 1900 // Navigate to a new site, starting a cross-site navigation. |
| 1902 controller().LoadURL( | 1901 controller().LoadURL( |
| 1903 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1902 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1904 { | 1903 { |
| 1905 pending_rfh = contents()->GetPendingMainFrame(); | 1904 pending_rfh = contents()->GetPendingMainFrame(); |
| 1906 RenderFrameDeletedObserver rfh_deleted_observer(pending_rfh); | 1905 RenderFrameDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1907 | 1906 |
| 1908 // Cancel the navigation by simulating a declined beforeunload dialog. | 1907 // Cancel the navigation by simulating a declined beforeunload dialog. |
| 1909 contents()->GetMainFrame()->OnMessageReceived( | 1908 contents()->GetMainFrame()->OnMessageReceived( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 ui::PAGE_TRANSITION_LINK, | 1995 ui::PAGE_TRANSITION_LINK, |
| 1997 false /* is_renderer_init */); | 1996 false /* is_renderer_init */); |
| 1998 host1 = NavigateToEntry(iframe1, entryB); | 1997 host1 = NavigateToEntry(iframe1, entryB); |
| 1999 RenderFrameHostImpl* host2 = NavigateToEntry(iframe2, entryB); | 1998 RenderFrameHostImpl* host2 = NavigateToEntry(iframe2, entryB); |
| 2000 | 1999 |
| 2001 // A new, pending RenderFrameHost should be created in each FrameTreeNode. | 2000 // A new, pending RenderFrameHost should be created in each FrameTreeNode. |
| 2002 EXPECT_TRUE(GetPendingFrameHost(iframe1)); | 2001 EXPECT_TRUE(GetPendingFrameHost(iframe1)); |
| 2003 EXPECT_TRUE(GetPendingFrameHost(iframe2)); | 2002 EXPECT_TRUE(GetPendingFrameHost(iframe2)); |
| 2004 EXPECT_EQ(host1, GetPendingFrameHost(iframe1)); | 2003 EXPECT_EQ(host1, GetPendingFrameHost(iframe1)); |
| 2005 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); | 2004 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); |
| 2006 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 2005 EXPECT_TRUE(GetPendingFrameHost(iframe1)->is_active()); |
| 2007 GetPendingFrameHost(iframe1)->rfh_state())); | 2006 EXPECT_TRUE(GetPendingFrameHost(iframe2)->is_active()); |
| 2008 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | |
| 2009 GetPendingFrameHost(iframe2)->rfh_state())); | |
| 2010 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); | 2007 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); |
| 2011 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), | 2008 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), |
| 2012 GetPendingFrameHost(iframe2)->GetSiteInstance()); | 2009 GetPendingFrameHost(iframe2)->GetSiteInstance()); |
| 2013 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); | 2010 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); |
| 2014 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); | 2011 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); |
| 2015 EXPECT_FALSE(contents()->CrossProcessNavigationPending()) | 2012 EXPECT_FALSE(contents()->CrossProcessNavigationPending()) |
| 2016 << "There should be no top-level pending navigation."; | 2013 << "There should be no top-level pending navigation."; |
| 2017 | 2014 |
| 2018 RenderFrameDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); | 2015 RenderFrameDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); |
| 2019 RenderFrameDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); | 2016 RenderFrameDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3102 commit_params.should_enforce_strict_mixed_content_checking = false; | 3099 commit_params.should_enforce_strict_mixed_content_checking = false; |
| 3103 child_host->SendNavigateWithParams(&commit_params); | 3100 child_host->SendNavigateWithParams(&commit_params); |
| 3104 EXPECT_NO_FATAL_FAILURE(CheckMixedContentIPC( | 3101 EXPECT_NO_FATAL_FAILURE(CheckMixedContentIPC( |
| 3105 main_test_rfh(), false, proxy_to_parent->GetRoutingID())); | 3102 main_test_rfh(), false, proxy_to_parent->GetRoutingID())); |
| 3106 EXPECT_FALSE(root->child_at(0) | 3103 EXPECT_FALSE(root->child_at(0) |
| 3107 ->current_replication_state() | 3104 ->current_replication_state() |
| 3108 .should_enforce_strict_mixed_content_checking); | 3105 .should_enforce_strict_mixed_content_checking); |
| 3109 } | 3106 } |
| 3110 | 3107 |
| 3111 } // namespace content | 3108 } // namespace content |
| OLD | NEW |