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_before_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 Loading... | |
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 void EnableBrowserSideNavigation() { | |
377 CommandLine::ForCurrentProcess()->AppendSwitch( | |
378 switches::kEnableBrowserSideNavigation); | |
379 } | |
371 private: | 380 private: |
372 RenderFrameHostManagerTestWebUIControllerFactory factory_; | 381 RenderFrameHostManagerTestWebUIControllerFactory factory_; |
373 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; | 382 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; |
374 }; | 383 }; |
375 | 384 |
376 // Tests that when you navigate from a chrome:// url to another page, and | 385 // 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 | 386 // then do that same thing in another tab, that the two resulting pages have |
378 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 387 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
379 // a regression test for bug 9364. | 388 // a regression test for bug 9364. |
380 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 389 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1843 static_cast<SiteInstanceImpl*>( | 1852 static_cast<SiteInstanceImpl*>( |
1844 pending_rfh->GetSiteInstance())->increment_active_view_count(); | 1853 pending_rfh->GetSiteInstance())->increment_active_view_count(); |
1845 | 1854 |
1846 main_test_rfh()->OnMessageReceived( | 1855 main_test_rfh()->OnMessageReceived( |
1847 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1856 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1848 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1857 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1849 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1858 EXPECT_FALSE(rvh_deleted_observer.deleted()); |
1850 } | 1859 } |
1851 } | 1860 } |
1852 | 1861 |
1853 // Browser-side navigation: Test that a proper NavigationRequest is created by | 1862 // PlzNavigate: Test that a proper NavigationRequest is created by |
1854 // BeginNavigation. | 1863 // BeginNavigation. |
1855 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { | 1864 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { |
1856 const GURL kUrl1("http://www.google.com/"); | 1865 const GURL kUrl1("http://www.google.com/"); |
1857 const GURL kUrl2("http://www.chromium.org/"); | 1866 const GURL kUrl2("http://www.chromium.org/"); |
1858 const GURL kUrl3("http://www.gmail.com/"); | 1867 const GURL kUrl3("http://www.gmail.com/"); |
1859 | 1868 |
1869 // TODO(clamy): we should be enabling browser side navigations here | |
1870 // when CommitNavigation is properly implemented. | |
1860 // Navigate to the first page. | 1871 // Navigate to the first page. |
1861 contents()->NavigateAndCommit(kUrl1); | 1872 contents()->NavigateAndCommit(kUrl1); |
1862 TestRenderViewHost* rvh1 = test_rvh(); | 1873 TestRenderViewHost* rvh1 = test_rvh(); |
1863 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | 1874 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); |
1864 | 1875 |
1876 EnableBrowserSideNavigation(); | |
1865 // Add a subframe. | 1877 // Add a subframe. |
1866 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 1878 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
1867 contents()->GetFrameTree()->AddFrame( | 1879 contents()->GetFrameTree()->AddFrame( |
1868 contents()->GetFrameTree()->root(), 14, "Child")); | 1880 contents()->GetFrameTree()->root(), 14, "Child")); |
1869 | 1881 |
1870 // Simulate a BeginNavigation IPC on the subframe. | 1882 // Simulate a BeginNavigation IPC on the subframe. |
1871 subframe_rfh->SendBeginNavigationWithURL(kUrl2); | 1883 subframe_rfh->SendBeginNavigationWithURL(kUrl2); |
1872 NavigationRequest* subframe_request = | 1884 NavigationRequest* subframe_request = |
1873 NavigationRequestForRenderFrameManager( | 1885 GetNavigationRequestForRenderFrameManager( |
1874 subframe_rfh->frame_tree_node()->render_manager()); | 1886 subframe_rfh->frame_tree_node()->render_manager()); |
1875 ASSERT_TRUE(subframe_request); | 1887 ASSERT_TRUE(subframe_request); |
1876 EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url); | 1888 EXPECT_EQ(kUrl2, subframe_request->info_for_testing().navigation_params.url); |
1877 // First party for cookies url should be that of the main frame. | 1889 // First party for cookies url should be that of the main frame. |
1878 EXPECT_EQ( | 1890 EXPECT_EQ( |
1879 kUrl1, subframe_request->info_for_testing().first_party_for_cookies); | 1891 kUrl1, subframe_request->info_for_testing().first_party_for_cookies); |
1880 EXPECT_FALSE(subframe_request->info_for_testing().is_main_frame); | 1892 EXPECT_FALSE(subframe_request->info_for_testing().is_main_frame); |
1881 EXPECT_TRUE(subframe_request->info_for_testing().parent_is_main_frame); | 1893 EXPECT_TRUE(subframe_request->info_for_testing().parent_is_main_frame); |
1882 | 1894 |
1883 // Simulate a BeginNavigation IPC on the main frame. | 1895 // Simulate a BeginNavigation IPC on the main frame. |
1884 main_test_rfh()->SendBeginNavigationWithURL(kUrl3); | 1896 main_test_rfh()->SendBeginNavigationWithURL(kUrl3); |
1885 NavigationRequest* main_request = | 1897 NavigationRequest* main_request = |
1886 NavigationRequestForRenderFrameManager( | 1898 GetNavigationRequestForRenderFrameManager( |
1887 main_test_rfh()->frame_tree_node()->render_manager()); | 1899 main_test_rfh()->frame_tree_node()->render_manager()); |
1888 ASSERT_TRUE(main_request); | 1900 ASSERT_TRUE(main_request); |
1889 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); | 1901 EXPECT_EQ(kUrl3, main_request->info_for_testing().navigation_params.url); |
1890 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); | 1902 EXPECT_EQ(kUrl3, main_request->info_for_testing().first_party_for_cookies); |
1891 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); | 1903 EXPECT_TRUE(main_request->info_for_testing().is_main_frame); |
1892 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); | 1904 EXPECT_FALSE(main_request->info_for_testing().parent_is_main_frame); |
1893 } | 1905 } |
1894 | 1906 |
1907 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | |
1908 // RenderFrameHost is not modified when the navigation commits. | |
1909 TEST_F(RenderFrameHostManagerTest, | |
1910 BrowserSideNavigationRequestNavigationNoLiveRenderer) { | |
1911 const GURL kUrl("http://www.google.com/"); | |
1912 | |
1913 EnableBrowserSideNavigation(); | |
1914 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | |
1915 contents()->GetController().LoadURL( | |
1916 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1917 NavigationRequest* main_request = | |
1918 GetNavigationRequestForRenderFrameManager( | |
1919 main_test_rfh()->frame_tree_node()->render_manager()); | |
nasko
2014/08/13 00:08:00
nit: two more spaces for indent
clamy
2014/08/13 13:27:24
Done.
| |
1920 // A NavigationRequest should have been generated. | |
1921 EXPECT_TRUE(main_request != NULL); | |
1922 RenderFrameHostImpl* rfh = main_test_rfh(); | |
1923 | |
1924 // Now commit the same url. | |
1925 NavigationBeforeCommitInfo commit_info; | |
1926 commit_info.navigation_url = kUrl; | |
1927 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation( | |
1928 commit_info); | |
1929 main_request = GetNavigationRequestForRenderFrameManager( | |
1930 main_test_rfh()->frame_tree_node()->render_manager()); | |
nasko
2014/08/13 00:08:00
nit: main_test_rfh()->frame_tree_node()->render_ma
clamy
2014/08/13 13:27:24
Done.
| |
1931 | |
1932 // The main rfh should not have been changed and we should not have a | |
nasko
2014/08/13 00:08:00
nit: capitalize rfh
clamy
2014/08/13 13:27:24
Done.
| |
1933 // navigation request anymore. | |
1934 EXPECT_EQ(rfh, main_test_rfh()); | |
1935 EXPECT_TRUE(main_request == NULL); | |
1936 } | |
1937 | |
1938 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | |
1939 // site navigation. | |
1940 TEST_F(RenderFrameHostManagerTest, | |
1941 BrowserSideNavigationCrossSiteNavigation) { | |
1942 const GURL kUrl1("http://www.chromium.org/"); | |
1943 const GURL kUrl2("http://www.google.com/"); | |
1944 | |
1945 // TODO(clamy): we should be enabling browser side navigations here | |
1946 // when CommitNavigation is properly implemented. | |
1947 // Navigate to the first page. | |
1948 contents()->NavigateAndCommit(kUrl1); | |
1949 TestRenderViewHost* rvh1 = test_rvh(); | |
1950 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | |
1951 RenderFrameHostImpl* rfh = main_test_rfh(); | |
1952 | |
1953 EnableBrowserSideNavigation(); | |
1954 // Navigate to a different site. | |
1955 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | |
1956 NavigationRequest* main_request = | |
1957 GetNavigationRequestForRenderFrameManager( | |
1958 main_test_rfh()->frame_tree_node()->render_manager()); | |
1959 ASSERT_TRUE(main_request); | |
1960 | |
1961 NavigationBeforeCommitInfo commit_info; | |
1962 commit_info.navigation_url = kUrl2; | |
1963 main_test_rfh()->frame_tree_node()->render_manager()->CommitNavigation( | |
1964 commit_info); | |
1965 main_request = GetNavigationRequestForRenderFrameManager( | |
1966 main_test_rfh()->frame_tree_node()->render_manager()); | |
1967 EXPECT_NE(main_test_rfh(), rfh); | |
1968 EXPECT_TRUE(main_request == NULL); | |
1969 } | |
1970 | |
1895 } // namespace content | 1971 } // namespace content |
OLD | NEW |