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

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

Issue 379143002: PlzNavigate: implement RequestNavigation in the no live renderer case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's comments Created 6 years, 5 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/files/file_path.h" 6 #include "base/files/file_path.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h"
7 #include "content/browser/frame_host/cross_site_transferring_request.h" 9 #include "content/browser/frame_host/cross_site_transferring_request.h"
10 #include "content/browser/frame_host/navigation_commit_info.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 11 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 12 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/frame_host/navigation_request.h" 13 #include "content/browser/frame_host/navigation_request.h"
11 #include "content/browser/frame_host/navigator.h" 14 #include "content/browser/frame_host/navigator.h"
15 #include "content/browser/frame_host/navigator_impl.h"
12 #include "content/browser/frame_host/render_frame_host_manager.h" 16 #include "content/browser/frame_host/render_frame_host_manager.h"
13 #include "content/browser/site_instance_impl.h" 17 #include "content/browser/site_instance_impl.h"
14 #include "content/browser/webui/web_ui_controller_factory_registry.h" 18 #include "content/browser/webui/web_ui_controller_factory_registry.h"
15 #include "content/common/view_messages.h" 19 #include "content/common/view_messages.h"
16 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
19 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_widget_host_iterator.h" 25 #include "content/public/browser/render_widget_host_iterator.h"
22 #include "content/public/browser/web_contents_delegate.h" 26 #include "content/public/browser/web_contents_delegate.h"
23 #include "content/public/browser/web_contents_observer.h" 27 #include "content/public/browser/web_contents_observer.h"
24 #include "content/public/browser/web_ui_controller.h" 28 #include "content/public/browser/web_ui_controller.h"
25 #include "content/public/common/bindings_policy.h" 29 #include "content/public/common/bindings_policy.h"
30 #include "content/public/common/content_switches.h"
26 #include "content/public/common/javascript_message_type.h" 31 #include "content/public/common/javascript_message_type.h"
27 #include "content/public/common/page_transition_types.h" 32 #include "content/public/common/page_transition_types.h"
28 #include "content/public/common/url_constants.h" 33 #include "content/public/common/url_constants.h"
29 #include "content/public/common/url_utils.h" 34 #include "content/public/common/url_utils.h"
30 #include "content/public/test/mock_render_process_host.h" 35 #include "content/public/test/mock_render_process_host.h"
31 #include "content/public/test/test_notification_tracker.h" 36 #include "content/public/test/test_notification_tracker.h"
32 #include "content/test/test_content_browser_client.h" 37 #include "content/test/test_content_browser_client.h"
33 #include "content/test/test_content_client.h" 38 #include "content/test/test_content_client.h"
34 #include "content/test/test_render_view_host.h" 39 #include "content/test/test_render_view_host.h"
35 #include "content/test/test_web_contents.h" 40 #include "content/test/test_web_contents.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // BeforeUnload finishes. 361 // BeforeUnload finishes.
357 ntp_rvh->SendBeforeUnloadACK(true); 362 ntp_rvh->SendBeforeUnloadACK(true);
358 363
359 dest_rvh->SendNavigate(101, kDestUrl); 364 dest_rvh->SendNavigate(101, kDestUrl);
360 ntp_rvh->OnSwappedOut(false); 365 ntp_rvh->OnSwappedOut(false);
361 366
362 EXPECT_TRUE(ntp_rvh->IsSwappedOut()); 367 EXPECT_TRUE(ntp_rvh->IsSwappedOut());
363 return ntp_rvh; 368 return ntp_rvh;
364 } 369 }
365 370
366 NavigationRequest* NavigationRequestForRenderFrameManager( 371 NavigationRequest* GetNavigationRequestForRenderFrameManager(
367 RenderFrameHostManager* manager) const { 372 RenderFrameHostManager* manager) const {
368 return manager->navigation_request_for_testing(); 373 return manager->navigation_request_for_testing();
369 } 374 }
370 375
376 RenderFrameHostImpl* GetSpeculativeRenderFrameHostForRenderFrameManager(
377 RenderFrameHostManager* manager) {
378 return manager->speculative_render_frame_host_.get();
379 }
380
381 void EnableBrowserSideNavigation() {
382 CommandLine::ForCurrentProcess()->AppendSwitch(
383 switches::kEnableBrowserSideNavigation);
384 }
371 private: 385 private:
372 RenderFrameHostManagerTestWebUIControllerFactory factory_; 386 RenderFrameHostManagerTestWebUIControllerFactory factory_;
373 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; 387 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_;
374 }; 388 };
375 389
376 // Tests that when you navigate from a chrome:// url to another page, and 390 // Tests that when you navigate from a chrome:// url to another page, and
377 // then do that same thing in another tab, that the two resulting pages have 391 // then do that same thing in another tab, that the two resulting pages have
378 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 392 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
379 // a regression test for bug 9364. 393 // a regression test for bug 9364.
380 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { 394 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 } 1864 }
1851 } 1865 }
1852 1866
1853 // Browser-side navigation: Test that a proper NavigationRequest is created by 1867 // Browser-side navigation: Test that a proper NavigationRequest is created by
1854 // BeginNavigation. 1868 // BeginNavigation.
1855 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { 1869 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
1856 const GURL kUrl1("http://www.google.com/"); 1870 const GURL kUrl1("http://www.google.com/");
1857 const GURL kUrl2("http://www.chromium.org/"); 1871 const GURL kUrl2("http://www.chromium.org/");
1858 const GURL kUrl3("http://www.gmail.com/"); 1872 const GURL kUrl3("http://www.gmail.com/");
1859 1873
1874 // TODO(clamy): we should be enabling browser side navigations here
1875 // eventually.
1860 // Navigate to the first page. 1876 // Navigate to the first page.
1861 contents()->NavigateAndCommit(kUrl1); 1877 contents()->NavigateAndCommit(kUrl1);
1862 TestRenderViewHost* rvh1 = test_rvh(); 1878 TestRenderViewHost* rvh1 = test_rvh();
1863 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); 1879 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state());
1864 1880
1881 EnableBrowserSideNavigation();
1865 // Add a subframe. 1882 // Add a subframe.
1866 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 1883 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
1867 contents()->GetFrameTree()->AddFrame( 1884 contents()->GetFrameTree()->AddFrame(
1868 contents()->GetFrameTree()->root(), 14, "Child")); 1885 contents()->GetFrameTree()->root(), 14, "Child"));
1869 1886
1870 // Simulate a BeginNavigation IPC on the subframe. 1887 // Simulate a BeginNavigation IPC on the subframe.
1888 subframe_rfh->frame_tree_node()->navigator()->GetController()->LoadURL(
1889 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string());
1871 subframe_rfh->SendBeginNavigationWithURL(kUrl2); 1890 subframe_rfh->SendBeginNavigationWithURL(kUrl2);
1872 NavigationRequest* subframe_request = 1891 NavigationRequest* subframe_request =
1873 NavigationRequestForRenderFrameManager( 1892 GetNavigationRequestForRenderFrameManager(
1874 subframe_rfh->frame_tree_node()->render_manager()); 1893 subframe_rfh->frame_tree_node()->render_manager());
1875 ASSERT_TRUE(subframe_request); 1894 ASSERT_TRUE(subframe_request);
1876 EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url); 1895 EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url);
1877 // First party for cookies url should be that of the main frame. 1896 // First party for cookies url should be that of the main frame.
1878 EXPECT_EQ( 1897 EXPECT_EQ(
1879 kUrl1, subframe_request->info_for_testing().first_party_for_cookies); 1898 kUrl1, subframe_request->info_for_testing().first_party_for_cookies);
1880 EXPECT_FALSE(subframe_request->info_for_testing().is_main_frame); 1899 EXPECT_FALSE(subframe_request->info_for_testing().is_main_frame);
1881 EXPECT_TRUE(subframe_request->info_for_testing().parent_is_main_frame); 1900 EXPECT_TRUE(subframe_request->info_for_testing().parent_is_main_frame);
1882 1901
1883 // Simulate a BeginNavigation IPC on the main frame. 1902 // Simulate a BeginNavigation IPC on the main frame.
1903 contents()->GetController().LoadURL(
1904 kUrl3, Referrer(), PAGE_TRANSITION_LINK, std::string());
1884 main_test_rfh()->SendBeginNavigationWithURL(kUrl3); 1905 main_test_rfh()->SendBeginNavigationWithURL(kUrl3);
1885 NavigationRequest* main_request = 1906 NavigationRequest* main_request =
1886 NavigationRequestForRenderFrameManager( 1907 GetNavigationRequestForRenderFrameManager(
1887 main_test_rfh()->frame_tree_node()->render_manager()); 1908 main_test_rfh()->frame_tree_node()->render_manager());
1888 ASSERT_TRUE(main_request); 1909 ASSERT_TRUE(main_request);
1889 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); 1910 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url);
1890 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); 1911 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies);
1891 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); 1912 EXPECT_TRUE(main_request->info_for_testing().is_main_frame);
1892 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); 1913 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame);
1893 } 1914 }
1894 1915
1916 // Browser side navigation: Test that RequestNavigation creates a
1917 // NavigationRequest and that the RenderFrameHost is initialized to handle the
1918 // request when it commits. Also ensures that the RenderFrameHost is not
1919 // modified when the navigation commits.
1920 TEST_F(RenderFrameHostManagerTest,
1921 BrowserSideNavigationRequestNavigationNoLiveRenderer) {
1922 const GURL kUrl("http://www.google.com/");
1923
1924 EnableBrowserSideNavigation();
1925 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
1926 contents()->GetController().LoadURL(
1927 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
1928 NavigationRequest* main_request =
1929 GetNavigationRequestForRenderFrameManager(
1930 main_test_rfh()->frame_tree_node()->render_manager());
1931 // A NavigationRequest should have been generated.
1932 EXPECT_TRUE(main_request != NULL);
1933 // The RFH should have been initialized to handle the navigation when it
1934 // commits.
1935 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
1936 RenderFrameHostImpl* rfh = main_test_rfh();
1937
1938 // Now commit the same url.
1939 NavigationCommitInfo commit_info;
1940 commit_info.navigation_url = kUrl;
1941 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation(
1942 commit_info);
1943 main_request = GetNavigationRequestForRenderFrameManager(
1944 main_test_rfh()->frame_tree_node()->render_manager());
1945
1946 // The main rfh should not have been changed and we should not have a
1947 // navigation request anymore.
1948 EXPECT_EQ(rfh, main_test_rfh());
1949 EXPECT_TRUE(main_request == NULL);
1950 }
1951
1952 // Browser-side navigation: Test that a speculative renderer is spawned when
1953 // navigating to a different site instance than the one of the main render frame
1954 // host. Test that it is used if the navigation commits with a url pertaining to
1955 // the same site instance.
1956 TEST_F(RenderFrameHostManagerTest,
1957 BrowserSideNavigationSpeculativeRendererSameURL) {
1958 const GURL kUrl1("http://www.chromium.org/");
1959 const GURL kUrl2("http://www.google.com/");
1960 const GURL kUrl3("http://docs.google.com/");
1961
1962 // TODO(clamy): we should be enabling browser side navigations here
1963 // eventually.
1964 // Navigate to the first page.
1965 contents()->NavigateAndCommit(kUrl1);
1966 TestRenderViewHost* rvh1 = test_rvh();
1967 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state());
1968
1969 EnableBrowserSideNavigation();
1970 // Navigate to a different site.
1971 contents()->GetController().LoadURL(
1972 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string());
1973 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1974 NavigationRequest* main_request =
1975 GetNavigationRequestForRenderFrameManager(
1976 main_test_rfh()->frame_tree_node()->render_manager());
1977 ASSERT_TRUE(main_request);
1978 RenderFrameHostImpl* speculative_rfh =
1979 GetSpeculativeRenderFrameHostForRenderFrameManager(
1980 main_test_rfh()->frame_tree_node()->render_manager());
1981 EXPECT_TRUE(speculative_rfh != NULL);
1982 EXPECT_NE(main_test_rfh(), speculative_rfh);
1983
1984 // Commit the same url.
nasko 2014/07/24 09:55:47 nit: It is no longer the same url :).
clamy 2014/07/24 11:38:05 Done.
1985 NavigationCommitInfo commit_info;
1986 commit_info.navigation_url = kUrl3;
1987 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation(
1988 commit_info);
1989 main_request = GetNavigationRequestForRenderFrameManager(
1990 main_test_rfh()->frame_tree_node()->render_manager());
1991 EXPECT_EQ(main_test_rfh(), speculative_rfh);
1992 EXPECT_TRUE(main_request == NULL);
1993 }
1994
1995 // Browser-side navigation: Test that a speculative renderer is spawned when
1996 // navigating to a different site instance than the one of the main render frame
1997 // host. Test that it is discarded if the navigation commits with a different
1998 // url.
1999 TEST_F(RenderFrameHostManagerTest,
2000 BrowserSideNavigationSpeculativeRendererDifferentURL) {
2001 const GURL kUrl1("http://www.google.com/");
2002 const GURL kUrl2("http://www.chromium.org/");
2003 const GURL kUrl3("http://www.gmail.com/");
2004
2005 // TODO(clamy): we should be enabling browser side navigations here
2006 // eventually.
2007 // Navigate to the first page.
2008 contents()->NavigateAndCommit(kUrl1);
2009 TestRenderViewHost* rvh1 = test_rvh();
2010 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state());
2011
2012 EnableBrowserSideNavigation();
2013 // Navigate to a different site.
2014 contents()->GetController().LoadURL(
2015 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string());
2016 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
2017 NavigationRequest* main_request =
2018 GetNavigationRequestForRenderFrameManager(
2019 main_test_rfh()->frame_tree_node()->render_manager());
2020 ASSERT_TRUE(main_request);
2021 RenderFrameHostImpl* speculative_rfh =
2022 GetSpeculativeRenderFrameHostForRenderFrameManager(
2023 main_test_rfh()->frame_tree_node()->render_manager());
2024 RenderFrameHostImpl* current_rfh = main_test_rfh();
2025 EXPECT_TRUE(speculative_rfh != NULL);
2026 EXPECT_NE(main_test_rfh(), speculative_rfh);
2027
2028 // Commit a different url.
2029 NavigationCommitInfo commit_info;
2030 commit_info.navigation_url = kUrl3;
2031 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation(
2032 commit_info);
2033 main_request = GetNavigationRequestForRenderFrameManager(
2034 main_test_rfh()->frame_tree_node()->render_manager());
2035 speculative_rfh = GetSpeculativeRenderFrameHostForRenderFrameManager(
2036 main_test_rfh()->frame_tree_node()->render_manager());
2037 EXPECT_NE(main_test_rfh(), speculative_rfh);
2038 EXPECT_NE(main_test_rfh(), current_rfh);
2039 EXPECT_TRUE(main_request == NULL);
2040 EXPECT_TRUE(speculative_rfh == NULL);
2041 }
2042
2043 // Browser-side navigation: Test that a speculative renderer is spawned when
2044 // navigating to a different site instance than the one of the main render frame
2045 // host. Test that it is discarded and the old render frame host is used if the
2046 // navigation commits with the url from the previous render frame host.
2047 TEST_F(RenderFrameHostManagerTest,
2048 BrowserSideNavigationSpeculativeRendererOldURL) {
2049 const GURL kUrl1("http://www.google.com/");
2050 const GURL kUrl2("http://www.chromium.org/");
2051
2052 // TODO(clamy): we should be enabling browser side navigations here
2053 // eventually.
2054 // Navigate to the first page.
2055 contents()->NavigateAndCommit(kUrl1);
2056 TestRenderViewHost* rvh1 = test_rvh();
2057 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state());
2058
2059 EnableBrowserSideNavigation();
2060 // Navigate to a different site.
2061 contents()->GetController().LoadURL(
2062 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string());
2063 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
2064 NavigationRequest* main_request =
2065 GetNavigationRequestForRenderFrameManager(
2066 main_test_rfh()->frame_tree_node()->render_manager());
2067 ASSERT_TRUE(main_request);
2068 RenderFrameHostImpl* speculative_rfh =
2069 GetSpeculativeRenderFrameHostForRenderFrameManager(
2070 main_test_rfh()->frame_tree_node()->render_manager());
2071 RenderFrameHostImpl* current_rfh = main_test_rfh();
2072 EXPECT_TRUE(speculative_rfh != NULL);
2073 EXPECT_NE(main_test_rfh(), speculative_rfh);
2074
2075 // Commit a different url.
2076 NavigationCommitInfo commit_info;
2077 commit_info.navigation_url = kUrl1;
2078 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation(
2079 commit_info);
2080 main_request = GetNavigationRequestForRenderFrameManager(
2081 main_test_rfh()->frame_tree_node()->render_manager());
2082 speculative_rfh = GetSpeculativeRenderFrameHostForRenderFrameManager(
2083 main_test_rfh()->frame_tree_node()->render_manager());
2084 EXPECT_NE(main_test_rfh(), speculative_rfh);
2085 EXPECT_EQ(main_test_rfh(), current_rfh);
2086 EXPECT_TRUE(main_request == NULL);
2087 EXPECT_TRUE(speculative_rfh == NULL);
2088 }
2089
1895 } // namespace content 2090 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698