Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| (...skipping 1776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1787 // Start another cross-site navigation. | 1787 // Start another cross-site navigation. |
| 1788 controller().LoadURL( | 1788 controller().LoadURL( |
| 1789 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1789 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1790 { | 1790 { |
| 1791 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1791 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1792 ->pending_frame_host(); | 1792 ->pending_frame_host(); |
| 1793 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1793 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1794 | 1794 |
| 1795 // Increment the number of active frames in the new SiteInstance, which will | 1795 // Increment the number of active frames in the new SiteInstance, which will |
| 1796 // cause the pending RFH to be swapped out instead of deleted. | 1796 // cause the pending RFH to be swapped out instead of deleted. |
| 1797 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1797 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1798 | 1798 |
| 1799 contents()->GetMainFrame()->OnMessageReceived( | 1799 contents()->GetMainFrame()->OnMessageReceived( |
| 1800 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1800 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1801 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1801 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 1802 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1802 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 1803 } | 1803 } |
| 1804 } | 1804 } |
| 1805 | 1805 |
| 1806 // Test that a pending RenderFrameHost in a non-root frame tree node is properly | |
| 1807 // deleted when the node is detached. | |
|
nasko
2014/12/11 23:49:54
nit: Add a link to the bug it is testing for.
ncarter (slow)
2014/12/12 20:21:06
Done.
| |
| 1808 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { | |
| 1809 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSitePerProcess); | |
| 1810 | |
| 1811 const GURL kUrl1("http://www.google.com/"); | |
|
nasko
2014/12/11 23:49:54
nit: Google?! Why not chromium.org : )))
ncarter (slow)
2014/12/12 20:21:06
These URLs are just copied from the test above.
| |
| 1812 const GURL kUrl2("http://webkit.org/"); | |
| 1813 | |
| 1814 RenderFrameHostImpl* host = NULL; | |
| 1815 | |
| 1816 contents()->NavigateAndCommit(kUrl1); | |
| 1817 contents()->GetMainFrame()->OnCreateChildFrame( | |
| 1818 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | |
| 1819 std::string("frame_name")); | |
| 1820 RenderFrameHostManager* manager = | |
| 1821 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | |
| 1822 | |
| 1823 // 1) The first navigation. -------------------------- | |
| 1824 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | |
| 1825 Referrer(), base::string16() /* title */, | |
| 1826 ui::PAGE_TRANSITION_TYPED, | |
| 1827 false /* is_renderer_init */); | |
| 1828 host = manager->Navigate(entry1); | |
| 1829 | |
| 1830 // The RenderFrameHost created in Init will be reused. | |
| 1831 EXPECT_TRUE(host == manager->current_frame_host()); | |
| 1832 EXPECT_FALSE(manager->pending_frame_host()); | |
| 1833 | |
| 1834 // Commit. | |
| 1835 manager->DidNavigateFrame(host); | |
| 1836 // Commit to SiteInstance should be delayed until RenderView commit. | |
|
nasko
2014/12/11 23:49:54
RenderFrame instead of RenderView?
ncarter (slow)
2014/12/12 20:21:06
Fixed here (and in the other places in this file,
nasko
2014/12/12 21:54:49
Acknowledged.
| |
| 1837 EXPECT_TRUE(host == manager->current_frame_host()); | |
| 1838 ASSERT_TRUE(host); | |
| 1839 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | |
| 1840 | |
| 1841 // 2) Cross-site navigate to next site. -------------- | |
| 1842 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | |
| 1843 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | |
| 1844 base::string16() /* title */, | |
| 1845 ui::PAGE_TRANSITION_LINK, | |
| 1846 false /* is_renderer_init */); | |
| 1847 host = manager->Navigate(entry2); | |
| 1848 | |
| 1849 // A new RenderFrameHost should be created. | |
| 1850 EXPECT_TRUE(manager->pending_frame_host()); | |
| 1851 ASSERT_EQ(host, manager->pending_frame_host()); | |
| 1852 ASSERT_NE(manager->current_frame_host(), manager->pending_frame_host()); | |
| 1853 EXPECT_FALSE(contents()->cross_navigation_pending()) | |
| 1854 << "There should be no top-level pending navigation."; | |
| 1855 | |
| 1856 RenderFrameHostDeletedObserver delete_watcher(manager->pending_frame_host()); | |
| 1857 EXPECT_FALSE(delete_watcher.deleted()); | |
| 1858 | |
| 1859 // Extend the lifetime of the child frame's SiteInstance, pretending | |
| 1860 // that there is another reference to it. | |
| 1861 scoped_refptr<SiteInstanceImpl> site_instance = | |
| 1862 manager->pending_frame_host()->GetSiteInstance(); | |
| 1863 EXPECT_TRUE(site_instance->HasSite()); | |
| 1864 EXPECT_NE(site_instance, contents()->GetSiteInstance()); | |
| 1865 EXPECT_EQ(1, site_instance->active_frame_count()); | |
| 1866 site_instance->increment_active_frame_count(); | |
| 1867 EXPECT_EQ(2, site_instance->active_frame_count()); | |
| 1868 | |
| 1869 // Now detach the child FrameTreeNode. This should kill the pending host. | |
| 1870 manager->current_frame_host()->OnMessageReceived(FrameHostMsg_Detach(0)); | |
|
nasko
2014/12/11 23:49:54
Let's be more correct - s/0/current_frame_host()->
ncarter (slow)
2014/12/12 20:21:06
Done.
| |
| 1871 | |
| 1872 EXPECT_TRUE(delete_watcher.deleted()); | |
| 1873 | |
| 1874 EXPECT_EQ(1, site_instance->active_frame_count()); | |
| 1875 site_instance->decrement_active_frame_count(); | |
| 1876 | |
| 1877 #if 0 | |
| 1878 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. | |
| 1879 // Enable this assert below once the proxies to the subframe are correctly | |
| 1880 // cleaned up after detach. | |
| 1881 ASSERT_TRUE(site_instance->HasOneRef()) | |
| 1882 << "This SiteInstance should be destroyable now."; | |
| 1883 #endif | |
| 1884 } | |
| 1885 | |
| 1806 } // namespace content | 1886 } // namespace content |
| OLD | NEW |