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

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: Rebase and changes from CR comments. Created 6 years 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 2258b258559dae276adc48b300c29e3e03836a22..f3f684199d7e4295c40b08444928d56147d4cb4d 100644
--- a/content/browser/frame_host/navigator_impl_unittest.cc
+++ b/content/browser/frame_host/navigator_impl_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "content/browser/frame_host/navigation_controller_impl.h"
@@ -15,6 +16,7 @@
#include "content/browser/streams/stream.h"
#include "content/common/navigation_params.h"
#include "content/public/browser/stream_handle.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "content/test/browser_side_navigation_test_utils.h"
@@ -73,8 +75,41 @@ class NavigatorTestWithBrowserSideNavigation
return static_cast<NavigatorImpl*>(frame_tree_node->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node);
}
+
+ RenderFrameHost* GetSpeculativeRenderFrameHost(RenderFrameHostManager* rfhm) {
+ return rfhm->speculative_render_frame_host_.get();
+ }
+
+ FrameHostMsg_DidCommitProvisionalLoad_Params BuildSimpleDCPLParams(GURL url) {
clamy 2014/12/16 15:22:48 This is actually a rewrite of some of the helper f
carlosk 2014/12/19 04:27:14 Done.
+ FrameHostMsg_DidCommitProvisionalLoad_Params params;
+ params.page_id = 1;
+ params.url = url;
+ params.was_within_same_page = false;
+ params.is_post = false;
+ params.post_id = -1;
+ params.page_state = PageState::CreateForTesting(url, false, 0, 0);
+ return params;
+ }
};
+// PlzNavigate: Test final state after a complete navigation (to avoid repeating
+// this these checks).
clamy 2014/12/16 15:22:48 Remove the extra this.
carlosk 2014/12/19 04:27:14 Done.
+TEST_F(NavigatorTestWithBrowserSideNavigation, NavigationFinishedState) {
+ const GURL kUrl("http://chromium.org/");
+ contents()->NavigateAndCommit(kUrl);
+ ASSERT_TRUE(main_test_rfh());
+ RenderFrameHostManager* rfhm =
+ main_test_rfh()->frame_tree_node()->render_manager();
+ EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
+ EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
+ main_test_rfh()->GetSiteInstance()->GetSiteURL());
+ // After a navigation is finished no speculative RenderFrameHost should
+ // exist.
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+ // With PlzNavigate enabled a pending RenderFrameHost should never exist.
+ EXPECT_FALSE(rfhm->pending_frame_host());
+}
+
// PlzNavigate: Test that a proper NavigationRequest is created by
// BeginNavigation.
// Note that all PlzNavigate methods on the browser side require the use of the
@@ -85,9 +120,10 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
const GURL kUrl3("http://www.gmail.com/");
contents()->NavigateAndCommit(kUrl1);
+ FrameTreeNode* root = contents()->GetFrameTree()->root();
+ RenderFrameHostManager* root_rfhm = root->render_manager();
// Add a subframe.
- FrameTreeNode* root = contents()->GetFrameTree()->root();
TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
contents()->GetFrameTree()->AddFrame(
root, root->current_frame_host()->GetProcess()->GetID(), 14,
@@ -95,6 +131,9 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
EXPECT_TRUE(subframe_rfh);
FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
+ RenderFrameHostManager* subframe_rfhm = subframe_node->render_manager();
+ EXPECT_NE(root_rfhm, subframe_rfhm);
+
SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2);
// There is no previous renderer in the subframe, so BeginNavigation is
// handled already.
@@ -110,6 +149,16 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
+ // Subframe navigations should not create a speculative RenderFrameHost.
+ // (unless site-per-process is enabled).
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_rfhm));
nasko 2014/12/18 00:22:39 nit: Move this check before the comment as it does
carlosk 2014/12/19 04:27:14 Done.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kSitePerProcess)) {
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_rfhm));
+ } else {
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_rfhm));
+ }
+
SendRequestNavigation(root, kUrl3);
// Simulate a BeginNavigation IPC on the main frame.
contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3);
@@ -122,6 +171,16 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
EXPECT_TRUE(main_loader->request_info()->is_main_frame);
EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
+
+ // Main frame navigations to different sites should use a speculative
+ // RenderFrameHost.
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_rfhm));
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kSitePerProcess)) {
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_rfhm));
+ } else {
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_rfhm));
+ }
}
// PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
@@ -130,12 +189,18 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) {
const GURL kUrl("http://www.google.com/");
EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
- FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RenderFrameHostImpl* rfh = main_test_rfh();
+ FrameTreeNode* node = rfh->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
SendRequestNavigation(node, kUrl);
- NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
+
// A NavigationRequest should have been generated.
+ NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
EXPECT_TRUE(main_request != NULL);
- RenderFrameHostImpl* rfh = main_test_rfh();
+
+ // As we're re-using the current RenderFrameHost, no speculative one should be
+ // created.
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
// Now return the response without any redirects. This will cause the
// navigation to commit at the same URL.
@@ -151,17 +216,16 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) {
EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
}
-// PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the
-// navigation.
+// PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels
+// the navigation.
TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
const GURL kUrl1("http://www.chromium.org/");
const GURL kUrl2("http://www.google.com/");
// Load a URL.
contents()->NavigateAndCommit(kUrl1);
- 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 different site.
SendRequestNavigation(node, kUrl2);
@@ -169,6 +233,9 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(main_request);
+ // Navigations to a different site do create a speculative RenderFrameHost.
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+
// Commit an HTTP 204 response.
scoped_refptr<ResourceResponse> response(new ResourceResponse);
const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0";
@@ -177,9 +244,11 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
response, MakeEmptyStream());
- // There should be no pending RenderFrameHost; the navigation was aborted.
+ // There should be no pending nor speculative RenderFrameHost; the navigation
+ // was aborted.
EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
- EXPECT_FALSE(node->render_manager()->pending_frame_host());
+ EXPECT_FALSE(rfhm->pending_frame_host());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
// Now, repeat the test with 205 Reset Content.
@@ -188,6 +257,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
main_request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(main_request);
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
// Commit an HTTP 205 response.
response = new ResourceResponse;
@@ -197,9 +267,11 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
response, MakeEmptyStream());
- // There should be no pending RenderFrameHost; the navigation was aborted.
+ // There should be no pending nor speculative RenderFrameHost; the navigation
+ // was aborted.
EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
- EXPECT_FALSE(node->render_manager()->pending_frame_host());
+ EXPECT_FALSE(rfhm->pending_frame_host());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
}
// PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
@@ -210,41 +282,49 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) {
contents()->NavigateAndCommit(kUrl1);
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 different site.
SendRequestNavigation(node, kUrl2);
main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(main_request);
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
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());
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+
+ FrameHostMsg_DidCommitProvisionalLoad_Params params =
+ BuildSimpleDCPLParams(kUrl2);
+ main_test_rfh()->SendNavigateWithParams(&params);
clamy 2014/12/16 15:22:48 Switch to using TestRenderFrameHost::SendNavigate
carlosk 2014/12/19 04:27:14 Done.
clamy 2014/12/19 13:35:57 I really meant to use that precise function and no
carlosk 2014/12/29 16:40:16 OK. What was bugging me about that approach was th
+ RenderFrameHostImpl* final_rfh = main_test_rfh();
+ ASSERT_TRUE(final_rfh);
+ EXPECT_NE(rfh, final_rfh);
+ EXPECT_TRUE(final_rfh->IsRenderFrameLive());
+ EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
}
-// PlzNavigate: Test that redirects are followed.
+// PlzNavigate: Test that redirects are followed and the speculative renderer
+// logic behaves as expected.
TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
const GURL kUrl1("http://www.chromium.org/");
const GURL kUrl2("http://www.google.com/");
contents()->NavigateAndCommit(kUrl1);
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;
@@ -252,38 +332,48 @@ 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());
+ RenderFrameHost* final_srfh = GetSpeculativeRenderFrameHost(rfhm);
+ EXPECT_TRUE(final_srfh);
+
+ // And commits provisional load.
+ FrameHostMsg_DidCommitProvisionalLoad_Params params =
+ BuildSimpleDCPLParams(kUrl2);
+ main_test_rfh()->SendNavigateWithParams(&params);
+ RenderFrameHostImpl* final_rfh = main_test_rfh();
+ ASSERT_TRUE(final_rfh);
+ EXPECT_NE(rfh, final_rfh);
+ EXPECT_EQ(final_srfh, final_rfh);
clamy 2014/12/16 15:22:48 nit: could you rename one of those parameters? fin
carlosk 2014/12/19 04:27:14 Done.
+ 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
-// issued in the meantime.
+// PlzNavigate: Test that a navigation is canceled if another request has been
+// issued in the meantime. Also confirms that the speculative renderer is
+// correctly updated in the process.
TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
const GURL kUrl0("http://www.wikipedia.org/");
- const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0);
const GURL kUrl1("http://www.chromium.org/");
+ const GURL kUrl1_site = SiteInstance::GetSiteForURL(browser_context(), kUrl1);
const GURL kUrl2("http://www.google.com/");
const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
// Initialization.
contents()->NavigateAndCommit(kUrl0);
FrameTreeNode* node = main_test_rfh()->frame_tree_node();
- EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
+ RenderFrameHostManager* rfhm = node->render_manager();
// Request navigation to the 1st URL.
SendRequestNavigation(node, kUrl1);
@@ -294,6 +384,14 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
base::WeakPtr<TestNavigationURLLoader> loader1 =
GetLoaderForNavigationRequest(request1)->AsWeakPtr();
+ // Confirm a speculative RFH was created.
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+ int32 site_instance_id_1 =
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId();
+ EXPECT_EQ(
+ kUrl1_site,
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetSiteURL());
+
// Request navigation to the 2nd URL; the NavigationRequest must have been
// replaced by a new one with a different URL.
SendRequestNavigation(node, kUrl2);
@@ -305,23 +403,39 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
// Confirm that the first loader got destroyed.
EXPECT_FALSE(loader1);
- // Confirm that the commit corresponds to the new request.
+ // Confirm that a new speculative RFH was created.
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+ int32 site_instance_id_2 =
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId();
+ EXPECT_NE(site_instance_id_1, site_instance_id_2);
+
+ // Commit.
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());
+
+ // And commit provisional load.
+ FrameHostMsg_DidCommitProvisionalLoad_Params params =
+ BuildSimpleDCPLParams(kUrl2);
+ main_test_rfh()->SendNavigateWithParams(&params);
+
+ // Confirm that the commit corresponds to the new request.
+ ASSERT_TRUE(main_test_rfh());
+ EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
+
+ // Confirm that the committed RFH is the new speculative one.
+ EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId());
}
// PlzNavigate: Test that a reload navigation is properly signaled to the
-// renderer when the navigation can commit.
+// renderer when the navigation can commit. Speculative renderers should not be
+// created at any step.
TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
const GURL kUrl("http://www.google.com/");
contents()->NavigateAndCommit(kUrl);
FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
SendRequestNavigationWithParameters(
node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
NavigationController::RELOAD);
@@ -332,9 +446,12 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
ASSERT_TRUE(main_request != NULL);
EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD,
main_request->common_params().navigation_type);
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+
int page_id = contents()->GetMaxPageIDForSiteInstance(
main_test_rfh()->GetSiteInstance()) + 1;
main_test_rfh()->SendNavigate(page_id, kUrl);
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
// Now do a shift+reload.
SendRequestNavigationWithParameters(
@@ -346,6 +463,151 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
ASSERT_TRUE(main_request != NULL);
EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
main_request->common_params().navigation_type);
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+}
+
+// PlzNavigate: Confirm 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);
+ FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
+
+ // Begin navigating to another site.
+ const GURL kUrl("http://google.com/");
+ SendRequestNavigation(node, kUrl);
+ contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+ EXPECT_NE(GetSpeculativeRenderFrameHost(rfhm), main_test_rfh());
+ EXPECT_EQ(
+ SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetSiteURL());
+ EXPECT_FALSE(rfhm->pending_frame_host());
+ int32 site_instance_id =
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId();
+
+ // Ask Navigator to commit the navigation by simulating a call to
+ // OnResponseStarted.
+ scoped_refptr<ResourceResponse> response(new ResourceResponse);
+ GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
+ ->CallOnResponseStarted(response, MakeEmptyStream());
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+ EXPECT_EQ(site_instance_id,
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId());
+ EXPECT_FALSE(rfhm->pending_frame_host());
+
+ // Invoke OnDidCommitProvisionalLoad.
+ FrameHostMsg_DidCommitProvisionalLoad_Params params =
+ BuildSimpleDCPLParams(kUrl);
+ main_test_rfh()->SendNavigateWithParams(&params);
+ EXPECT_EQ(site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+ EXPECT_FALSE(rfhm->pending_frame_host());
+}
+
+// PlzNavigate: Confirm that a speculative RenderFrameHost is thrown away when
+// the final URL's site differs 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);
+ FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RenderFrameHostManager* rfhm = node->render_manager();
+ int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId();
+
+ // Begin navigating to another site.
+ const GURL kUrl("http://google.com/");
+ SendRequestNavigation(node, kUrl);
+ contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
+ int32 site_instance_id =
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId();
+ EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+ EXPECT_NE(GetSpeculativeRenderFrameHost(rfhm), main_test_rfh());
+ EXPECT_EQ(
+ SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetSiteURL());
+
+ // It then redirects to yet 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(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+
+ // TODO(carlosk): once the speculative RenderFrameHost updates with redirects
+ // this next check will be changed to verify that it actually happens.
+ EXPECT_EQ(site_instance_id,
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId());
+
+ // Commit the navigation with Navigator by simulating the call to
+ // OnResponseStarted.
+ response = new ResourceResponse;
+ GetLoaderForNavigationRequest(main_request)
+ ->CallOnResponseStarted(response, MakeEmptyStream());
+ EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
+
+ // Once commit happens the speculative RenderFrameHost is already updated to
+ // match the known final SiteInstance.
+ ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm));
+ EXPECT_EQ(
+ SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlRedirect),
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetSiteURL());
+ int32 redirect_site_instance_id =
+ GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId();
+
+ // Invoke OnDidCommitProvisionalLoad.
+ FrameHostMsg_DidCommitProvisionalLoad_Params params =
+ BuildSimpleDCPLParams(kUrl);
+ main_test_rfh()->SendNavigateWithParams(&params);
+
+ // And finally on commit-provisional-load the already created RenderFrameHost
+ // is made active.
+ EXPECT_EQ(redirect_site_instance_id,
+ main_test_rfh()->GetSiteInstance()->GetId());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm));
+}
+
+// PlzNavigate: Verify that a previously swapped-out RenderFrameHost is
+// correctly reused when spawning a speculative RenderFrameHost in a navigation
+// using the same SiteInstance.
+TEST_F(NavigatorTestWithBrowserSideNavigation,
+ SpeculativeRendererReuseSwappedOutRFH) {
+ // Navigate to an initial site.
+ const GURL kUrl1("http://wikipedia.org/");
+ contents()->NavigateAndCommit(kUrl1);
+ RenderFrameHostImpl* rfh1 = main_test_rfh();
+ RenderFrameHostManager* rfhm = rfh1->frame_tree_node()->render_manager();
+
+ // Increment active frame count to cause the RenderFrameHost to be swapped out
+ // (instead of immediately destroyed).
+ rfh1->GetSiteInstance()->increment_active_frame_count();
+
+ // Then to another to swap-out the initial RenderFrameHost.
clamy 2014/12/16 15:22:48 s/Then to another/Navigate to another site
carlosk 2014/12/19 04:27:14 Done.
+ const GURL kUrl2("http://chromium.org/");
+ contents()->NavigateAndCommit(kUrl2);
+ ASSERT_NE(rfh1, main_test_rfh());
+ EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
+ EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
+ EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1));
+
+ // Now goes back to the initial site.
clamy 2014/12/16 15:22:48 s/goes/go I would add a comment along the lines o
carlosk 2014/12/19 04:27:14 Done.
+ contents()->NavigateAndCommit(kUrl1);
clamy 2014/12/16 15:22:48 I think you could actually split the NavigateAndCo
carlosk 2014/12/19 04:27:14 Done.
+ EXPECT_EQ(rfh1, main_test_rfh());
+ EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
+ EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698