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

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

Powered by Google App Engine
This is Rietveld 408576698