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/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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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* NavigationRequestForRenderFrameManager( |
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* SpeculativeRenderFrameHostForRenderFrameManager( | |
nasko
2014/07/23 14:15:46
nit: this and the method above are returning thing
clamy
2014/07/23 14:56:10
Done.
| |
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 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1849 } | 1863 } |
1850 } | 1864 } |
1851 | 1865 |
1852 // Browser-side navigation: Test that a proper NavigationRequest is created by | 1866 // Browser-side navigation: Test that a proper NavigationRequest is created by |
1853 // BeginNavigation. | 1867 // BeginNavigation. |
1854 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { | 1868 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { |
1855 const GURL kUrl1("http://www.google.com/"); | 1869 const GURL kUrl1("http://www.google.com/"); |
1856 const GURL kUrl2("http://www.chromium.org/"); | 1870 const GURL kUrl2("http://www.chromium.org/"); |
1857 const GURL kUrl3("http://www.gmail.com/"); | 1871 const GURL kUrl3("http://www.gmail.com/"); |
1858 | 1872 |
1873 // TODO(clamy): we should be enabling browser side navigations here | |
1874 // eventually. | |
nasko
2014/07/23 14:15:46
Why can't we do it now?
clamy
2014/07/23 14:56:10
Because we don't have a proper commit of the navig
nasko
2014/07/24 09:55:47
Ok
| |
1859 // Navigate to the first page. | 1875 // Navigate to the first page. |
1860 contents()->NavigateAndCommit(kUrl1); | 1876 contents()->NavigateAndCommit(kUrl1); |
1861 TestRenderViewHost* rvh1 = test_rvh(); | 1877 TestRenderViewHost* rvh1 = test_rvh(); |
1862 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | 1878 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); |
1863 | 1879 |
1880 EnableBrowserSideNavigation(); | |
1864 // Add a subframe. | 1881 // Add a subframe. |
1865 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 1882 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
1866 contents()->GetFrameTree()->AddFrame( | 1883 contents()->GetFrameTree()->AddFrame( |
1867 contents()->GetFrameTree()->root(), 14, "Child")); | 1884 contents()->GetFrameTree()->root(), 14, "Child")); |
1868 | 1885 |
1869 // Simulate a BeginNavigation IPC on the subframe. | 1886 // Simulate a BeginNavigation IPC on the subframe. |
1887 subframe_rfh->frame_tree_node()->navigator()->GetController()->LoadURL( | |
1888 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1870 subframe_rfh->SendBeginNavigationWithURL(kUrl2); | 1889 subframe_rfh->SendBeginNavigationWithURL(kUrl2); |
1871 NavigationRequest* subframe_request = | 1890 NavigationRequest* subframe_request = |
1872 NavigationRequestForRenderFrameManager( | 1891 NavigationRequestForRenderFrameManager( |
1873 subframe_rfh->frame_tree_node()->render_manager()); | 1892 subframe_rfh->frame_tree_node()->render_manager()); |
1874 ASSERT_TRUE(subframe_request); | 1893 ASSERT_TRUE(subframe_request); |
1875 EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url); | 1894 EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url); |
1876 // First party for cookies url should be that of the main frame. | 1895 // First party for cookies url should be that of the main frame. |
1877 EXPECT_EQ( | 1896 EXPECT_EQ( |
1878 kUrl1, subframe_request->info_for_testing().first_party_for_cookies); | 1897 kUrl1, subframe_request->info_for_testing().first_party_for_cookies); |
1879 EXPECT_FALSE(subframe_request->info_for_testing().is_main_frame); | 1898 EXPECT_FALSE(subframe_request->info_for_testing().is_main_frame); |
1880 EXPECT_TRUE(subframe_request->info_for_testing().parent_is_main_frame); | 1899 EXPECT_TRUE(subframe_request->info_for_testing().parent_is_main_frame); |
1881 | 1900 |
1882 // Simulate a BeginNavigation IPC on the main frame. | 1901 // Simulate a BeginNavigation IPC on the main frame. |
1902 contents()->GetController().LoadURL( | |
1903 kUrl3, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1883 main_test_rfh()->SendBeginNavigationWithURL(kUrl3); | 1904 main_test_rfh()->SendBeginNavigationWithURL(kUrl3); |
1884 NavigationRequest* main_request = | 1905 NavigationRequest* main_request = |
1885 NavigationRequestForRenderFrameManager( | 1906 NavigationRequestForRenderFrameManager( |
1886 main_test_rfh()->frame_tree_node()->render_manager()); | 1907 main_test_rfh()->frame_tree_node()->render_manager()); |
1887 ASSERT_TRUE(main_request); | 1908 ASSERT_TRUE(main_request); |
1888 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); | 1909 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); |
1889 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); | 1910 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); |
1890 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); | 1911 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); |
1891 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); | 1912 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); |
1892 } | 1913 } |
1893 | 1914 |
1915 // Browser side navigation: Test that RequestNavigation creates a | |
1916 // NavigationRequest and that the RenderFrameHost is initialized to handle the | |
1917 // request when it commits. Also ensures that the RenderFrameHost is not | |
1918 // modified when the navigation commits. | |
1919 TEST_F(RenderFrameHostManagerTest, | |
1920 BrowserSideNavigationRequestNavigationNoLiveRenderer) { | |
1921 const GURL kUrl("http://www.google.com/"); | |
1922 | |
1923 EnableBrowserSideNavigation(); | |
1924 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | |
1925 contents()->GetController().LoadURL( | |
1926 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1927 NavigationRequest* main_request = | |
1928 NavigationRequestForRenderFrameManager( | |
1929 main_test_rfh()->frame_tree_node()->render_manager()); | |
1930 // A NavigationRequest should have been generated. | |
1931 EXPECT_TRUE(main_request != NULL); | |
1932 // The RFH should have been initialized to handle the navigation when it | |
1933 // commits. | |
1934 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | |
1935 RenderFrameHostImpl* rfh = main_test_rfh(); | |
1936 | |
1937 // Now commit the same url. | |
1938 NavigationCommitInfo commit_info; | |
1939 commit_info.navigation_url = kUrl; | |
1940 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation( | |
1941 commit_info); | |
1942 main_request =NavigationRequestForRenderFrameManager( | |
nasko
2014/07/23 14:15:46
nit: space after =
clamy
2014/07/23 14:56:10
Done.
| |
1943 main_test_rfh()->frame_tree_node()->render_manager()); | |
1944 | |
1945 // The main rfh should not have been changed and we should not have a | |
1946 // navigation request anymore. | |
1947 EXPECT_EQ(rfh, main_test_rfh()); | |
1948 EXPECT_TRUE(main_request == NULL); | |
1949 } | |
1950 | |
1951 // Browser-side navigation: Test that a speculative renderer is spawned when | |
1952 // navigating to a different site instance than the one of the main render frame | |
1953 // host. Test that it is used if the navigation commits with the same url. | |
nasko
2014/07/23 14:15:46
It should be reused if we commit in the same SiteI
clamy
2014/07/23 14:56:10
I now test that it works as long as we commit a ur
| |
1954 TEST_F(RenderFrameHostManagerTest, | |
1955 BrowserSideNavigationSpeculativeRendererSameURL) { | |
1956 const GURL kUrl1("http://www.google.com/"); | |
1957 const GURL kUrl2("http://www.chromium.org/"); | |
1958 | |
1959 // TODO(clamy): we should be enabling browser side navigations here | |
1960 // eventually. | |
1961 // Navigate to the first page. | |
1962 contents()->NavigateAndCommit(kUrl1); | |
1963 TestRenderViewHost* rvh1 = test_rvh(); | |
1964 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | |
1965 | |
1966 EnableBrowserSideNavigation(); | |
1967 // Navigate to a different site. | |
1968 contents()->GetController().LoadURL( | |
1969 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1970 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | |
1971 NavigationRequest* main_request = | |
1972 NavigationRequestForRenderFrameManager( | |
1973 main_test_rfh()->frame_tree_node()->render_manager()); | |
1974 ASSERT_TRUE(main_request); | |
1975 RenderFrameHostImpl* speculative_rfh = | |
1976 SpeculativeRenderFrameHostForRenderFrameManager( | |
1977 main_test_rfh()->frame_tree_node()->render_manager()); | |
1978 EXPECT_TRUE(speculative_rfh != NULL); | |
1979 EXPECT_NE(main_test_rfh(), speculative_rfh); | |
1980 | |
1981 // Commit the same url. | |
1982 NavigationCommitInfo commit_info; | |
1983 commit_info.navigation_url = kUrl2; | |
1984 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation( | |
1985 commit_info); | |
1986 main_request = NavigationRequestForRenderFrameManager( | |
1987 main_test_rfh()->frame_tree_node()->render_manager()); | |
1988 EXPECT_EQ(main_test_rfh(), speculative_rfh); | |
1989 EXPECT_TRUE(main_request == NULL); | |
1990 } | |
1991 | |
1992 // Browser-side navigation: Test that a speculative renderer is spawned when | |
1993 // navigating to a different site instance than the one of the main render frame | |
1994 // host. Test that it is discarded if the navigation commits with a different | |
1995 // url. | |
1996 TEST_F(RenderFrameHostManagerTest, | |
1997 BrowserSideNavigationSpeculativeRendererDifferentURL) { | |
1998 const GURL kUrl1("http://www.google.com/"); | |
1999 const GURL kUrl2("http://www.chromium.org/"); | |
2000 const GURL kUrl3("http://www.gmail.com/"); | |
2001 | |
2002 // TODO(clamy): we should be enabling browser side navigations here | |
2003 // eventually. | |
2004 // Navigate to the first page. | |
2005 contents()->NavigateAndCommit(kUrl1); | |
2006 TestRenderViewHost* rvh1 = test_rvh(); | |
2007 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | |
2008 | |
2009 EnableBrowserSideNavigation(); | |
2010 // Navigate to a different site. | |
2011 contents()->GetController().LoadURL( | |
2012 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
2013 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | |
2014 NavigationRequest* main_request = | |
2015 NavigationRequestForRenderFrameManager( | |
2016 main_test_rfh()->frame_tree_node()->render_manager()); | |
2017 ASSERT_TRUE(main_request); | |
2018 RenderFrameHostImpl* speculative_rfh = | |
2019 SpeculativeRenderFrameHostForRenderFrameManager( | |
2020 main_test_rfh()->frame_tree_node()->render_manager()); | |
2021 RenderFrameHostImpl* current_rfh = main_test_rfh(); | |
2022 EXPECT_TRUE(speculative_rfh != NULL); | |
2023 EXPECT_NE(main_test_rfh(), speculative_rfh); | |
2024 | |
2025 // Commit a different url. | |
2026 NavigationCommitInfo commit_info; | |
2027 commit_info.navigation_url = kUrl3; | |
2028 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation( | |
2029 commit_info); | |
2030 main_request = NavigationRequestForRenderFrameManager( | |
2031 main_test_rfh()->frame_tree_node()->render_manager()); | |
2032 EXPECT_NE(main_test_rfh(), speculative_rfh); | |
2033 EXPECT_NE(main_test_rfh(), current_rfh); | |
2034 EXPECT_TRUE(main_request == NULL); | |
nasko
2014/07/23 14:15:46
Let's also assert that there is no longer speculat
clamy
2014/07/23 14:56:10
Done.
| |
2035 } | |
2036 | |
2037 // Browser-side navigation: Test that a speculative renderer is spawned when | |
2038 // navigating to a different site instance than the one of the main render frame | |
2039 // host. Test that it is discarded and the old render frame host is used if the | |
2040 // navigation commits with the url from the previous render frame host. | |
2041 TEST_F(RenderFrameHostManagerTest, | |
2042 BrowserSideNavigationSpeculativeRendererOldURL) { | |
2043 const GURL kUrl1("http://www.google.com/"); | |
2044 const GURL kUrl2("http://www.chromium.org/"); | |
2045 | |
2046 // TODO(clamy): we should be enabling browser side navigations here | |
2047 // eventually. | |
2048 // Navigate to the first page. | |
2049 contents()->NavigateAndCommit(kUrl1); | |
2050 TestRenderViewHost* rvh1 = test_rvh(); | |
2051 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | |
2052 | |
2053 EnableBrowserSideNavigation(); | |
2054 // Navigate to a different site. | |
2055 contents()->GetController().LoadURL( | |
2056 kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
2057 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | |
2058 NavigationRequest* main_request = | |
2059 NavigationRequestForRenderFrameManager( | |
2060 main_test_rfh()->frame_tree_node()->render_manager()); | |
2061 ASSERT_TRUE(main_request); | |
2062 RenderFrameHostImpl* speculative_rfh = | |
2063 SpeculativeRenderFrameHostForRenderFrameManager( | |
2064 main_test_rfh()->frame_tree_node()->render_manager()); | |
2065 RenderFrameHostImpl* current_rfh = main_test_rfh(); | |
2066 EXPECT_TRUE(speculative_rfh != NULL); | |
2067 EXPECT_NE(main_test_rfh(), speculative_rfh); | |
2068 | |
2069 // Commit a different url. | |
2070 NavigationCommitInfo commit_info; | |
2071 commit_info.navigation_url = kUrl1; | |
2072 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation( | |
2073 commit_info); | |
2074 main_request = NavigationRequestForRenderFrameManager( | |
2075 main_test_rfh()->frame_tree_node()->render_manager()); | |
2076 EXPECT_NE(main_test_rfh(), speculative_rfh); | |
2077 EXPECT_EQ(main_test_rfh(), current_rfh); | |
2078 EXPECT_TRUE(main_request == NULL); | |
nasko
2014/07/23 14:15:46
Same as above, it is not testing that the speculat
clamy
2014/07/23 14:56:10
Done.
| |
2079 } | |
2080 | |
1894 } // namespace content | 2081 } // namespace content |
OLD | NEW |