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

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

Issue 1055203002: Fix the RenderFrameProxyHost mop-up logic in RenderFrameHostManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self-review cleanup. 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)) {
399 return manager->speculative_render_frame_host_.get(); 399 return manager->speculative_render_frame_host_.get();
400 } 400 }
401 return manager->pending_frame_host(); 401 return manager->pending_frame_host();
402 } 402 }
403 403
404 void CrashFrame(TestRenderFrameHost* frame) {
405 // TODO(nick): Standardize how we simulate crashes in content unittests. The
406 // test method |set_render_view_created| should probably be eliminated
407 // altogether, and maybe there should be a CrashProcess() method on
408 // MockRenderProcessHost.
409 ASSERT_TRUE(frame->IsRenderFrameLive());
410 frame->OnMessageReceived(FrameHostMsg_RenderProcessGone(
411 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
412 RenderProcessHost::RendererClosedDetails details(
413 base::TERMINATION_STATUS_PROCESS_CRASHED, 0);
414 NotificationService::current()->Notify(
415 NOTIFICATION_RENDERER_PROCESS_CLOSED,
416 Source<RenderProcessHost>(frame->GetProcess()),
417 Details<RenderProcessHost::RendererClosedDetails>(&details));
418 frame->GetRenderViewHost()->set_render_view_created(false);
419 ASSERT_FALSE(frame->IsRenderFrameLive());
420 }
421
404 private: 422 private:
405 RenderFrameHostManagerTestWebUIControllerFactory factory_; 423 RenderFrameHostManagerTestWebUIControllerFactory factory_;
406 }; 424 };
407 425
408 // Tests that when you navigate from a chrome:// url to another page, and 426 // Tests that when you navigate from a chrome:// url to another page, and
409 // then do that same thing in another tab, that the two resulting pages have 427 // then do that same thing in another tab, that the two resulting pages have
410 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 428 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
411 // a regression test for bug 9364. 429 // a regression test for bug 9364.
412 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { 430 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
413 set_should_create_webui(true); 431 set_should_create_webui(true);
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 contents()->GetController().GoBack(); 1404 contents()->GetController().GoBack();
1387 contents()->GetMainFrame()->PrepareForCommit(); 1405 contents()->GetMainFrame()->PrepareForCommit();
1388 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1406 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1389 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1407 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL());
1390 1408
1391 // Disown the opener from rfh2. 1409 // Disown the opener from rfh2.
1392 rfh2->DidDisownOpener(); 1410 rfh2->DidDisownOpener();
1393 EXPECT_FALSE(contents()->HasOpener()); 1411 EXPECT_FALSE(contents()->HasOpener());
1394 } 1412 }
1395 1413
1396 // Test that we clean up swapped out RenderViewHosts when a process hosting 1414 // Test that we clean up swapped out RenderFrameHosts when a process hosting
Charlie Reis 2015/04/03 19:55:09 The test itself still seems to be about swapped ou
ncarter (slow) 2015/04/03 22:03:33 Keen observation. I restored the comments and test
1397 // those associated RenderViews crashes. http://crbug.com/258993 1415 // those associated RenderFrame crashes. http://crbug.com/258993
Charlie Reis 2015/04/03 19:55:09 nit: RenderFrames
ncarter (slow) 2015/04/03 22:03:33 Done.
1398 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { 1416 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRFHOnProcessCrash) {
1399 const GURL kUrl1("http://www.google.com/"); 1417 const GURL kUrl1("http://www.google.com/");
1400 const GURL kUrl2("http://www.chromium.org/"); 1418 const GURL kUrl2("http://www.chromium.org/");
1401 1419
1402 // Navigate to an initial URL. 1420 // Navigate to an initial URL.
1403 contents()->NavigateAndCommit(kUrl1); 1421 contents()->NavigateAndCommit(kUrl1);
1404 TestRenderViewHost* rvh1 = test_rvh(); 1422 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
1405 1423
1406 // Create a new tab as an opener for the main tab. 1424 // Create a new tab as an opener for the main tab.
1407 scoped_ptr<TestWebContents> opener1( 1425 scoped_ptr<TestWebContents> opener1(
1408 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); 1426 TestWebContents::Create(browser_context(), rfh1->GetSiteInstance()));
1409 RenderFrameHostManager* opener1_manager = 1427 RenderFrameHostManager* opener1_manager =
1410 opener1->GetRenderManagerForTesting(); 1428 opener1->GetRenderManagerForTesting();
1411 contents()->SetOpener(opener1.get()); 1429 contents()->SetOpener(opener1.get());
1412 1430
1413 // Make sure the new opener RVH is considered live. 1431 // Make sure the new opener RVH is considered live.
1414 opener1_manager->current_host()->CreateRenderView( 1432 opener1_manager->current_host()->CreateRenderView(
1415 base::string16(), -1, MSG_ROUTING_NONE, -1, false); 1433 base::string16(), -1, MSG_ROUTING_NONE, -1, false);
1416 EXPECT_TRUE(opener1_manager->current_host()->IsRenderViewLive()); 1434 EXPECT_TRUE(opener1_manager->current_host()->IsRenderViewLive());
1417 EXPECT_TRUE(opener1_manager->current_frame_host()->IsRenderFrameLive()); 1435 EXPECT_TRUE(opener1_manager->current_frame_host()->IsRenderFrameLive());
1418 1436
1419 // Use a cross-process navigation in the opener to swap out the old RVH. 1437 // Use a cross-process navigation in the opener to swap out the old RVH.
1420 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( 1438 EXPECT_FALSE(
1421 rvh1->GetSiteInstance())); 1439 opener1_manager->GetSwappedOutRenderViewHost(rfh1->GetSiteInstance()));
1422 opener1->NavigateAndCommit(kUrl2); 1440 opener1->NavigateAndCommit(kUrl2);
1423 EXPECT_TRUE(opener1_manager->GetSwappedOutRenderViewHost( 1441 EXPECT_TRUE(
1424 rvh1->GetSiteInstance())); 1442 opener1_manager->GetSwappedOutRenderViewHost(rfh1->GetSiteInstance()));
1425 1443
1426 // Fake a process crash. 1444 // Fake a process crash.
1427 RenderProcessHost::RendererClosedDetails details( 1445 CrashFrame(rfh1);
1428 base::TERMINATION_STATUS_PROCESS_CRASHED,
1429 0);
1430 // TODO(nasko): Investigate whether this test can be made more realistic by
1431 // not faking the notification and just doing the RenderProcessGone. This
1432 // should also get rid of faking |set_render_view_created()| call below.
1433 NotificationService::current()->Notify(
1434 NOTIFICATION_RENDERER_PROCESS_CLOSED,
1435 Source<RenderProcessHost>(rvh1->GetProcess()),
1436 Details<RenderProcessHost::RendererClosedDetails>(&details));
1437 rvh1->set_render_view_created(false);
1438 1446
1439 // Ensure that the RenderFrameProxyHost stays around and the RenderFrameProxy 1447 // Ensure that the RenderFrameProxyHost stays around and the RenderFrameProxy
1440 // is deleted. 1448 // is deleted.
1441 RenderFrameProxyHost* render_frame_proxy_host = 1449 RenderFrameProxyHost* render_frame_proxy_host =
1442 opener1_manager->GetRenderFrameProxyHost(rvh1->GetSiteInstance()); 1450 opener1_manager->GetRenderFrameProxyHost(rfh1->GetSiteInstance());
1443 EXPECT_TRUE(render_frame_proxy_host); 1451 EXPECT_TRUE(render_frame_proxy_host);
1444 EXPECT_FALSE(render_frame_proxy_host->is_render_frame_proxy_live()); 1452 EXPECT_FALSE(render_frame_proxy_host->is_render_frame_proxy_live());
1445 1453
1446 // Expect the swapped out RVH to exist. 1454 // Expect the swapped out RVH to exist.
1447 EXPECT_TRUE(opener1_manager->GetSwappedOutRenderViewHost( 1455 EXPECT_TRUE(
1448 rvh1->GetSiteInstance())); 1456 opener1_manager->GetSwappedOutRenderViewHost(rfh1->GetSiteInstance()));
1449 1457
1450 // Reload the initial tab. This should recreate the opener's swapped out RVH 1458 // Reload the initial tab. This should recreate the opener's swapped out RVH
1451 // in the original SiteInstance. 1459 // in the original SiteInstance.
1452 contents()->GetController().Reload(true); 1460 contents()->GetController().Reload(true);
1453 contents()->GetMainFrame()->PrepareForCommit(); 1461 contents()->GetMainFrame()->PrepareForCommit();
1454 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( 1462 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost(
1455 rvh1->GetSiteInstance())->GetRoutingID(), 1463 rfh1->GetSiteInstance())->GetRoutingID(),
1456 test_rvh()->opener_route_id()); 1464 contents()->GetMainFrame()->GetRenderViewHost()->opener_route_id());
1457 } 1465 }
1458 1466
1459 // Test that RenderViewHosts created for WebUI navigations are properly 1467 // Test that RenderViewHosts created for WebUI navigations are properly
1460 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost 1468 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost
1461 // is in the same process (http://crbug.com/79918). 1469 // is in the same process (http://crbug.com/79918).
1462 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { 1470 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) {
1463 set_should_create_webui(true); 1471 set_should_create_webui(true);
1464 const GURL kSettingsUrl("chrome://chrome/settings"); 1472 const GURL kSettingsUrl("chrome://chrome/settings");
1465 const GURL kPluginUrl("chrome://plugins"); 1473 const GURL kPluginUrl("chrome://plugins");
1466 1474
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 1848
1841 const GURL kUrl1("http://www.google.com/"); 1849 const GURL kUrl1("http://www.google.com/");
1842 const GURL kUrl2("http://webkit.org/"); 1850 const GURL kUrl2("http://webkit.org/");
1843 1851
1844 RenderFrameHostImpl* host = NULL; 1852 RenderFrameHostImpl* host = NULL;
1845 1853
1846 contents()->NavigateAndCommit(kUrl1); 1854 contents()->NavigateAndCommit(kUrl1);
1847 contents()->GetMainFrame()->OnCreateChildFrame( 1855 contents()->GetMainFrame()->OnCreateChildFrame(
1848 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), 1856 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(),
1849 std::string("frame_name"), SandboxFlags::NONE); 1857 std::string("frame_name"), SandboxFlags::NONE);
1858 RenderFrameHostManager* root_manager =
1859 contents()->GetFrameTree()->root()->render_manager();
1850 RenderFrameHostManager* manager = 1860 RenderFrameHostManager* manager =
1851 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); 1861 contents()->GetFrameTree()->root()->child_at(0)->render_manager();
1852 1862
1853 // 1) The first navigation. -------------------------- 1863 // 1) The first navigation. --------------------------
1854 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 1864 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1855 Referrer(), base::string16() /* title */, 1865 Referrer(), base::string16() /* title */,
1856 ui::PAGE_TRANSITION_TYPED, 1866 ui::PAGE_TRANSITION_TYPED,
1857 false /* is_renderer_init */); 1867 false /* is_renderer_init */);
1858 host = GetFrameHostForNavigation(manager, entry1); 1868 host = GetFrameHostForNavigation(manager, entry1);
1859 1869
(...skipping 12 matching lines...) Expand all
1872 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 1882 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1873 Referrer(kUrl1, blink::WebReferrerPolicyDefault), 1883 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
1874 base::string16() /* title */, 1884 base::string16() /* title */,
1875 ui::PAGE_TRANSITION_LINK, 1885 ui::PAGE_TRANSITION_LINK,
1876 false /* is_renderer_init */); 1886 false /* is_renderer_init */);
1877 host = GetFrameHostForNavigation(manager, entry2); 1887 host = GetFrameHostForNavigation(manager, entry2);
1878 1888
1879 // A new RenderFrameHost should be created. 1889 // A new RenderFrameHost should be created.
1880 EXPECT_TRUE(GetPendingFrameHost(manager)); 1890 EXPECT_TRUE(GetPendingFrameHost(manager));
1881 ASSERT_EQ(host, GetPendingFrameHost(manager)); 1891 ASSERT_EQ(host, GetPendingFrameHost(manager));
1892 ASSERT_TRUE(RenderFrameHostImpl::IsRFHStateActive(
1893 GetPendingFrameHost(manager)->rfh_state()));
1882 ASSERT_NE(manager->current_frame_host(), GetPendingFrameHost(manager)); 1894 ASSERT_NE(manager->current_frame_host(), GetPendingFrameHost(manager));
1883 EXPECT_FALSE(contents()->cross_navigation_pending()) 1895 EXPECT_FALSE(contents()->cross_navigation_pending())
1884 << "There should be no top-level pending navigation."; 1896 << "There should be no top-level pending navigation.";
1885 1897
1886 RenderFrameHostDeletedObserver delete_watcher(GetPendingFrameHost(manager)); 1898 RenderFrameHostDeletedObserver delete_watcher(GetPendingFrameHost(manager));
1887 EXPECT_FALSE(delete_watcher.deleted()); 1899 EXPECT_FALSE(delete_watcher.deleted());
1888 1900
1889 // Extend the lifetime of the child frame's SiteInstance, pretending 1901 // Extend the lifetime of the child frame's SiteInstance, pretending
1890 // that there is another reference to it. 1902 // that there is another reference to it.
1891 scoped_refptr<SiteInstanceImpl> site_instance = 1903 scoped_refptr<SiteInstanceImpl> site_instance =
1892 GetPendingFrameHost(manager)->GetSiteInstance(); 1904 GetPendingFrameHost(manager)->GetSiteInstance();
1893 EXPECT_TRUE(site_instance->HasSite()); 1905 EXPECT_TRUE(site_instance->HasSite());
1894 EXPECT_NE(site_instance, contents()->GetSiteInstance()); 1906 EXPECT_NE(site_instance, contents()->GetSiteInstance());
1895 EXPECT_EQ(1U, site_instance->active_frame_count()); 1907 EXPECT_EQ(1U, site_instance->active_frame_count());
1896 site_instance->increment_active_frame_count(); 1908 EXPECT_NE(nullptr,
1897 EXPECT_EQ(2U, site_instance->active_frame_count()); 1909 root_manager->GetRenderFrameProxyHost(site_instance.get()));
1898 1910
1899 // Now detach the child FrameTreeNode. This should kill the pending host. 1911 // Now detach the child FrameTreeNode. This should kill the pending host.
1900 manager->current_frame_host()->OnMessageReceived( 1912 manager->current_frame_host()->OnMessageReceived(
1901 FrameHostMsg_Detach(manager->current_frame_host()->GetRoutingID())); 1913 FrameHostMsg_Detach(manager->current_frame_host()->GetRoutingID()));
1902 1914
1903 EXPECT_TRUE(delete_watcher.deleted()); 1915 EXPECT_TRUE(delete_watcher.deleted());
1904 1916
1905 EXPECT_EQ(1U, site_instance->active_frame_count()); 1917 EXPECT_EQ(0U, site_instance->active_frame_count());
1906 site_instance->decrement_active_frame_count();
1907 1918
1908 #if 0 1919 EXPECT_TRUE(site_instance->HasOneRef())
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
1911 // cleaned up after detach. http://crbug.com/444955.
1912 ASSERT_TRUE(site_instance->HasOneRef())
1913 << "This SiteInstance should be destroyable now."; 1920 << "This SiteInstance should be destroyable now.";
1914 #endif 1921
1922 EXPECT_EQ(nullptr,
1923 root_manager->GetRenderFrameProxyHost(site_instance.get()));
1924 }
1925
1926 // Two tabs in the same process crash. The first tab is reloaded, and the second
1927 // tab navigates away without reloading. The second tab's navigation shouldn't
1928 // mess with the first tab's content.
Charlie Reis 2015/04/03 19:55:09 Can you add https://crbug.com/473714 to the commen
ncarter (slow) 2015/04/03 22:03:33 Done.
1929 TEST_F(RenderFrameHostManagerTest, TwoTabsCrashOneReloadsOneLeaves) {
1930 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1931 switches::kSitePerProcess);
1932
1933 const GURL kUrl1("http://www.google.com/");
1934 const GURL kUrl2("http://webkit.org/");
1935 const GURL kUrl3("http://whatwg.org/");
1936
1937 // |contents1| and |contents2| navigate to the same page and then crash.
1938 TestWebContents* contents1 = contents();
1939 scoped_ptr<TestWebContents> contents2(
1940 TestWebContents::Create(browser_context(), contents1->GetSiteInstance()));
1941 contents1->NavigateAndCommit(kUrl1);
1942 contents2->NavigateAndCommit(kUrl1);
1943 CrashFrame(contents1->GetMainFrame());
1944 CrashFrame(contents2->GetMainFrame());
1945
1946 ASSERT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance());
1947
1948 // Reload |contents1|.
1949 contents1->NavigateAndCommit(kUrl1);
1950 ASSERT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive());
1951 ASSERT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
1952 ASSERT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance());
1953
1954 // |contents1| creates an out of process iframe.
1955 contents1->GetMainFrame()->OnCreateChildFrame(
1956 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(),
1957 std::string("frame_name"), SandboxFlags::NONE);
1958 RenderFrameHostManager* iframe =
1959 contents()->GetFrameTree()->root()->child_at(0)->render_manager();
1960 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2,
1961 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
1962 base::string16() /* title */,
1963 ui::PAGE_TRANSITION_LINK,
1964 false /* is_renderer_init */);
1965 RenderFrameHostImpl* cross_site = GetFrameHostForNavigation(iframe, entry);
1966 iframe->DidNavigateFrame(cross_site, true);
1967
1968 // A proxy to the iframe should now exist in the site instance of the main
Charlie Reis 2015/04/03 19:55:09 s/site instance/SiteInstance/
ncarter (slow) 2015/04/03 22:03:33 Done.
1969 // frames.
1970 ASSERT_NE(cross_site->GetSiteInstance(), contents1->GetSiteInstance());
1971 ASSERT_NE(nullptr,
1972 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
1973 ASSERT_NE(nullptr,
1974 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
1975
1976 // Navigate |contents2| away from the sad tab (and thus away from the
1977 // SiteInstance of |contents1|). This should not destroy the proxies needed by
1978 // |contents1| -- that was http://crbug.com/473714.
1979 ASSERT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
1980 contents2->NavigateAndCommit(kUrl3);
1981 ASSERT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive());
1982 ASSERT_NE(nullptr,
1983 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
1984 ASSERT_EQ(nullptr,
1985 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
1915 } 1986 }
1916 1987
1917 } // namespace content 1988 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698