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

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

Powered by Google App Engine
This is Rietveld 408576698