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

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

Issue 799593004: Don't crash while detaching a pending child frame under --site-per-process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo inline of DiscardUnusedFrame Created 6 years 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 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, 895 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED,
896 false /* is_renderer_init */); 896 false /* is_renderer_init */);
897 host = manager->Navigate(entry1); 897 host = manager->Navigate(entry1);
898 898
899 // The RenderFrameHost created in Init will be reused. 899 // The RenderFrameHost created in Init will be reused.
900 EXPECT_TRUE(host == manager->current_frame_host()); 900 EXPECT_TRUE(host == manager->current_frame_host());
901 EXPECT_FALSE(manager->pending_frame_host()); 901 EXPECT_FALSE(manager->pending_frame_host());
902 902
903 // Commit. 903 // Commit.
904 manager->DidNavigateFrame(host, true); 904 manager->DidNavigateFrame(host, true);
905 // Commit to SiteInstance should be delayed until RenderView commit. 905 // Commit to SiteInstance should be delayed until RenderFrame commit.
906 EXPECT_TRUE(host == manager->current_frame_host()); 906 EXPECT_TRUE(host == manager->current_frame_host());
907 ASSERT_TRUE(host); 907 ASSERT_TRUE(host);
908 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); 908 EXPECT_FALSE(host->GetSiteInstance()->HasSite());
909 host->GetSiteInstance()->SetSite(kUrl1); 909 host->GetSiteInstance()->SetSite(kUrl1);
910 910
911 // 2) Navigate to next site. ------------------------- 911 // 2) Navigate to next site. -------------------------
912 const GURL kUrl2("http://www.google.com/foo"); 912 const GURL kUrl2("http://www.google.com/foo");
913 NavigationEntryImpl entry2( 913 NavigationEntryImpl entry2(
914 NULL /* instance */, -1 /* page_id */, kUrl2, 914 NULL /* instance */, -1 /* page_id */, kUrl2,
915 Referrer(kUrl1, blink::WebReferrerPolicyDefault), 915 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 false /* is_renderer_init */); 1517 false /* is_renderer_init */);
1518 host = manager->Navigate(entry1); 1518 host = manager->Navigate(entry1);
1519 1519
1520 // The RenderFrameHost created in Init will be reused. 1520 // The RenderFrameHost created in Init will be reused.
1521 EXPECT_TRUE(host == manager->current_frame_host()); 1521 EXPECT_TRUE(host == manager->current_frame_host());
1522 EXPECT_FALSE(manager->pending_frame_host()); 1522 EXPECT_FALSE(manager->pending_frame_host());
1523 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); 1523 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance);
1524 1524
1525 // Commit. 1525 // Commit.
1526 manager->DidNavigateFrame(host, true); 1526 manager->DidNavigateFrame(host, true);
1527 // Commit to SiteInstance should be delayed until RenderView commit. 1527 // Commit to SiteInstance should be delayed until RenderFrame commit.
1528 EXPECT_EQ(host, manager->current_frame_host()); 1528 EXPECT_EQ(host, manager->current_frame_host());
1529 ASSERT_TRUE(host); 1529 ASSERT_TRUE(host);
1530 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); 1530 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1531 1531
1532 // 2) Navigate to a different domain. ------------------------- 1532 // 2) Navigate to a different domain. -------------------------
1533 // Guests stay in the same process on navigation. 1533 // Guests stay in the same process on navigation.
1534 const GURL kUrl2("http://www.chromium.org"); 1534 const GURL kUrl2("http://www.chromium.org");
1535 NavigationEntryImpl entry2( 1535 NavigationEntryImpl entry2(
1536 NULL /* instance */, -1 /* page_id */, kUrl2, 1536 NULL /* instance */, -1 /* page_id */, kUrl2,
1537 Referrer(kUrl1, blink::WebReferrerPolicyDefault), 1537 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 // Start another cross-site navigation. 1811 // Start another cross-site navigation.
1812 controller().LoadURL( 1812 controller().LoadURL(
1813 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1813 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1814 { 1814 {
1815 pending_rfh = contents()->GetFrameTree()->root()->render_manager() 1815 pending_rfh = contents()->GetFrameTree()->root()->render_manager()
1816 ->pending_frame_host(); 1816 ->pending_frame_host();
1817 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); 1817 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh);
1818 1818
1819 // Increment the number of active frames in the new SiteInstance, which will 1819 // Increment the number of active frames in the new SiteInstance, which will
1820 // cause the pending RFH to be swapped out instead of deleted. 1820 // cause the pending RFH to be swapped out instead of deleted.
1821 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 1821 pending_rfh->GetSiteInstance()->increment_active_frame_count();
1822 1822
1823 contents()->GetMainFrame()->OnMessageReceived( 1823 contents()->GetMainFrame()->OnMessageReceived(
1824 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1824 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1825 EXPECT_FALSE(contents()->cross_navigation_pending()); 1825 EXPECT_FALSE(contents()->cross_navigation_pending());
1826 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1826 EXPECT_FALSE(rfh_deleted_observer.deleted());
1827 } 1827 }
1828 } 1828 }
1829 1829
1830 // Test that a pending RenderFrameHost in a non-root frame tree node is properly
1831 // deleted when the node is detached. Motivated by http://crbug.com/441357
1832 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) {
1833 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSitePerProcess);
1834
1835 const GURL kUrl1("http://www.google.com/");
1836 const GURL kUrl2("http://webkit.org/");
1837
1838 RenderFrameHostImpl* host = NULL;
1839
1840 contents()->NavigateAndCommit(kUrl1);
1841 contents()->GetMainFrame()->OnCreateChildFrame(
1842 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(),
1843 std::string("frame_name"));
1844 RenderFrameHostManager* manager =
1845 contents()->GetFrameTree()->root()->child_at(0)->render_manager();
1846
1847 // 1) The first navigation. --------------------------
1848 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1849 Referrer(), base::string16() /* title */,
1850 ui::PAGE_TRANSITION_TYPED,
1851 false /* is_renderer_init */);
1852 host = manager->Navigate(entry1);
1853
1854 // The RenderFrameHost created in Init will be reused.
1855 EXPECT_TRUE(host == manager->current_frame_host());
1856 EXPECT_FALSE(manager->pending_frame_host());
1857
1858 // Commit.
1859 manager->DidNavigateFrame(host, true);
1860 // Commit to SiteInstance should be delayed until RenderFrame commit.
1861 EXPECT_TRUE(host == manager->current_frame_host());
1862 ASSERT_TRUE(host);
1863 EXPECT_TRUE(host->GetSiteInstance()->HasSite());
1864
1865 // 2) Cross-site navigate to next site. --------------
1866 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1867 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
1868 base::string16() /* title */,
1869 ui::PAGE_TRANSITION_LINK,
1870 false /* is_renderer_init */);
1871 host = manager->Navigate(entry2);
1872
1873 // A new RenderFrameHost should be created.
1874 EXPECT_TRUE(manager->pending_frame_host());
1875 ASSERT_EQ(host, manager->pending_frame_host());
1876 ASSERT_NE(manager->current_frame_host(), manager->pending_frame_host());
1877 EXPECT_FALSE(contents()->cross_navigation_pending())
1878 << "There should be no top-level pending navigation.";
1879
1880 RenderFrameHostDeletedObserver delete_watcher(manager->pending_frame_host());
1881 EXPECT_FALSE(delete_watcher.deleted());
1882
1883 // Extend the lifetime of the child frame's SiteInstance, pretending
1884 // that there is another reference to it.
1885 scoped_refptr<SiteInstanceImpl> site_instance =
1886 manager->pending_frame_host()->GetSiteInstance();
1887 EXPECT_TRUE(site_instance->HasSite());
1888 EXPECT_NE(site_instance, contents()->GetSiteInstance());
1889 EXPECT_EQ(1, site_instance->active_frame_count());
1890 site_instance->increment_active_frame_count();
1891 EXPECT_EQ(2, site_instance->active_frame_count());
1892
1893 // Now detach the child FrameTreeNode. This should kill the pending host.
1894 manager->current_frame_host()->OnMessageReceived(
1895 FrameHostMsg_Detach(manager->current_frame_host()->GetRoutingID()));
1896
1897 EXPECT_TRUE(delete_watcher.deleted());
1898
1899 EXPECT_EQ(1, site_instance->active_frame_count());
1900 site_instance->decrement_active_frame_count();
1901
1902 #if 0
1903 // TODO(nick): Currently a proxy to the removed frame lingers in the parent.
1904 // Enable this assert below once the proxies to the subframe are correctly
1905 // cleaned up after detach.
1906 ASSERT_TRUE(site_instance->HasOneRef())
1907 << "This SiteInstance should be destroyable now.";
1908 #endif
1909 }
1910
1830 } // namespace content 1911 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698