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

Unified Diff: content/browser/frame_host/navigator_impl_unittest.cc

Issue 701953006: PlzNavigate: Speculatively spawns a renderer process for navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-applied full CL changes, addressed comments, rebased, added tests and fixes. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/navigator_impl_unittest.cc
diff --git a/content/browser/frame_host/navigator_impl_unittest.cc b/content/browser/frame_host/navigator_impl_unittest.cc
index 96afc97d3479fbf69b0575ba16bdf879d1bfb3eb..8588097ee22e77dd75b2a85601a93d70e610e0b2 100644
--- a/content/browser/frame_host/navigator_impl_unittest.cc
+++ b/content/browser/frame_host/navigator_impl_unittest.cc
@@ -79,6 +79,10 @@ class NavigatorTestWithBrowserSideNavigation
return static_cast<NavigatorImpl*>(frame_tree_node->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node);
}
+
+ RenderFrameHost* GetSpeculativeRenderFrameHost(RenderFrameHostManager* rfhm) {
+ return rfhm->speculative_render_frame_host();
+ }
};
// PlzNavigate: Test that a proper NavigationRequest is created by
@@ -115,7 +119,6 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
-
carlosk 2014/11/28 13:08:17 I already re-added this line locally (and this is
SendRequestNavigation(root, kUrl3);
// Simulate a BeginNavigation IPC on the main frame.
contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3);
@@ -228,12 +231,11 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) {
scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
response, MakeEmptyStream());
- RenderFrameHostImpl* pending_rfh =
- node->render_manager()->pending_frame_host();
- ASSERT_TRUE(pending_rfh);
- EXPECT_NE(pending_rfh, rfh);
- EXPECT_TRUE(pending_rfh->IsRenderFrameLive());
- EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
+ RenderFrameHostImpl* final_rfh = main_test_rfh();
+ ASSERT_TRUE(final_rfh);
+ EXPECT_NE(final_rfh, rfh);
+ EXPECT_TRUE(final_rfh->IsRenderFrameLive());
+ EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
}
// PlzNavigate: Test that redirects are followed.
@@ -245,12 +247,14 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
RenderFrameHostImpl* rfh = main_test_rfh();
EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
// Navigate to a URL on the same site.
SendRequestNavigation(node, kUrl1);
main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(main_request);
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
// It then redirects to another site.
net::RedirectInfo redirect_info;
@@ -258,26 +262,27 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
redirect_info.new_method = "GET";
redirect_info.new_url = kUrl2;
redirect_info.new_first_party_for_cookies = kUrl2;
- scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
redirect_info, response);
// The redirect should have been followed.
EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
// Then it commits.
response = new ResourceResponse;
GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
response, MakeEmptyStream());
- RenderFrameHostImpl* pending_rfh =
- node->render_manager()->pending_frame_host();
- ASSERT_TRUE(pending_rfh);
- EXPECT_NE(pending_rfh, rfh);
- EXPECT_TRUE(pending_rfh->IsRenderFrameLive());
- EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
+ RenderFrameHostImpl* final_rfh = main_test_rfh();
+ ASSERT_TRUE(final_rfh);
+ EXPECT_NE(final_rfh, rfh);
+ EXPECT_TRUE(final_rfh->IsRenderFrameLive());
+ EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
}
-// PlzNavigate: Test that a navigation is cancelled if another request has been
+// PlzNavigate: Test that a navigation is canceled if another request has been
// issued in the meantime.
TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
const GURL kUrl0("http://www.wikipedia.org/");
@@ -289,6 +294,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
// Initialization.
contents()->NavigateAndCommit(kUrl0);
FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
// Request navigation to the 1st URL.
@@ -300,6 +306,10 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
base::WeakPtr<TestNavigationURLLoader> loader1 =
GetLoaderForNavigationRequest(request1)->AsWeakPtr();
+ // Confirms a speculative RFH was created
+ RenderFrameHost* first_srfh = GetSpeculativeRenderFrameHost(rfhm);
+ EXPECT_TRUE(first_srfh);
+
// Request navigation to the 2nd URL; the NavigationRequest must have been
// replaced by a new one with a different URL.
SendRequestNavigation(node, kUrl2);
@@ -311,14 +321,21 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
// Confirm that the first loader got destroyed.
EXPECT_FALSE(loader1);
+ // Confirms that a new speculative RFH was created
+ RenderFrameHost* second_srfh = GetSpeculativeRenderFrameHost(rfhm);
+ EXPECT_TRUE(second_srfh);
+ EXPECT_NE(first_srfh, second_srfh);
+
// Confirm that the commit corresponds to the new request.
scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
response, MakeEmptyStream());
- RenderFrameHostImpl* pending_rfh =
- node->render_manager()->pending_frame_host();
- ASSERT_TRUE(pending_rfh);
- EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL());
+ RenderFrameHostImpl* final_rfh = main_test_rfh();
+ ASSERT_TRUE(final_rfh);
+ EXPECT_EQ(kUrl2_site, final_rfh->GetSiteInstance()->GetSiteURL());
+
+ // Confirms that the committed RFH is the new speculative one
+ EXPECT_EQ(second_srfh, final_rfh);
}
// PlzNavigate: Test that a reload navigation is properly signaled to the
@@ -354,4 +371,92 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
main_request->common_params().navigation_type);
}
+// PlzNavigate: Confirms that a speculative RenderFrameHost is used when
+// navigating from one site to the another.
+TEST_F(NavigatorTestWithBrowserSideNavigation,
+ SpeculativeRendererWorksBaseCase) {
+ // Navigate to an initial site.
+ const GURL kUrlInit("http://wikipedia.org/");
+ contents()->NavigateAndCommit(kUrlInit);
+ TestRenderFrameHost* mrfh = main_test_rfh();
+ FrameTreeNode* node = mrfh->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
+ RenderFrameHost* srfh = GetSpeculativeRenderFrameHost(rfhm);
+ ASSERT_FALSE(srfh);
+
+ // Begin navigating to another site.
+ const GURL kUrl("http://google.com/");
+ SendRequestNavigation(node, kUrl);
+ contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
+ srfh = GetSpeculativeRenderFrameHost(rfhm);
+ ASSERT_TRUE(srfh);
+ EXPECT_NE(srfh, mrfh);
+ EXPECT_TRUE(srfh->GetProcess()->HasConnection());
+
+ // Commit.
+ scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
+ GetLoaderForNavigationRequest(main_request)
+ ->CallOnResponseStarted(response, MakeEmptyStream());
+ EXPECT_EQ(srfh, main_test_rfh());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+
+ // And just for completeness invoke OnDidCommitProvisionalLoad which
+ // shouldn't change anything in RFHM.
+ FrameHostMsg_DidCommitProvisionalLoad_Params params;
+ params.page_id = 1;
+ params.url = kUrl;
+ params.was_within_same_page = false;
+ params.is_post = false;
+ params.post_id = -1;
+ params.page_state = PageState::CreateForTesting(kUrl, false, 0, 0);
+ main_test_rfh()->SendNavigateWithParams(&params);
+ EXPECT_EQ(srfh, main_test_rfh());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+}
+
+// PlzNavigate: Confirms that a speculative RenderFrameHost is thrown away when
+// the final URL's site differ from the initial one due to redirects.
+TEST_F(NavigatorTestWithBrowserSideNavigation,
+ SpeculativeRendererDiscardedAfterRedirectToAnotherSite) {
+ // Navigate to an initial site.
+ const GURL kUrlInit("http://wikipedia.org/");
+ contents()->NavigateAndCommit(kUrlInit);
+ TestRenderFrameHost* mrfh = main_test_rfh();
+ FrameTreeNode* node = mrfh->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
+ RenderFrameHost* srfh = GetSpeculativeRenderFrameHost(rfhm);
+ ASSERT_FALSE(srfh);
+
+ // Begin navigating to another site.
+ const GURL kUrl("http://google.com/");
+ SendRequestNavigation(node, kUrl);
+ contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
+ srfh = GetSpeculativeRenderFrameHost(rfhm);
+ ASSERT_TRUE(srfh);
+ EXPECT_NE(srfh, mrfh);
+ EXPECT_TRUE(srfh->GetProcess()->HasConnection());
+
+ // It then redirects to another site.
+ NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
+ ASSERT_TRUE(main_request);
+ const GURL kUrlRedirect("https://www.google.com/");
+ net::RedirectInfo redirect_info;
+ redirect_info.status_code = 302;
+ redirect_info.new_method = "GET";
+ redirect_info.new_url = kUrlRedirect;
+ redirect_info.new_first_party_for_cookies = kUrlRedirect;
+ scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
+ redirect_info, response);
+ EXPECT_EQ(srfh, GetSpeculativeRenderFrameHost(rfhm));
+
+ // Commit.
+ response = new ResourceResponse;
+ GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
+ response, MakeEmptyStream());
+ EXPECT_NE(srfh, main_test_rfh());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+}
+
} // namespace content
« no previous file with comments | « content/browser/frame_host/navigator_impl.cc ('k') | content/browser/frame_host/render_frame_host_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698