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

Side by Side 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: Addressed last round of CR comments. Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/macros.h" 6 #include "base/macros.h"
6 #include "base/time/time.h" 7 #include "base/time/time.h"
7 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
8 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
9 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
10 #include "content/browser/frame_host/navigation_request_info.h" 11 #include "content/browser/frame_host/navigation_request_info.h"
11 #include "content/browser/frame_host/navigator.h" 12 #include "content/browser/frame_host/navigator.h"
12 #include "content/browser/frame_host/navigator_impl.h" 13 #include "content/browser/frame_host/navigator_impl.h"
13 #include "content/browser/frame_host/render_frame_host_manager.h" 14 #include "content/browser/frame_host/render_frame_host_manager.h"
14 #include "content/browser/site_instance_impl.h" 15 #include "content/browser/site_instance_impl.h"
15 #include "content/browser/streams/stream.h" 16 #include "content/browser/streams/stream.h"
16 #include "content/common/navigation_params.h" 17 #include "content/common/navigation_params.h"
17 #include "content/public/browser/stream_handle.h" 18 #include "content/public/browser/stream_handle.h"
19 #include "content/public/common/content_switches.h"
18 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
19 #include "content/public/common/url_utils.h" 21 #include "content/public/common/url_utils.h"
22 #include "content/public/test/mock_render_process_host.h"
20 #include "content/test/browser_side_navigation_test_utils.h" 23 #include "content/test/browser_side_navigation_test_utils.h"
21 #include "content/test/test_navigation_url_loader.h" 24 #include "content/test/test_navigation_url_loader.h"
22 #include "content/test/test_render_frame_host.h" 25 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_web_contents.h" 26 #include "content/test/test_web_contents.h"
24 #include "net/base/load_flags.h" 27 #include "net/base/load_flags.h"
25 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
26 #include "net/url_request/redirect_info.h" 29 #include "net/url_request/redirect_info.h"
27 #include "ui/base/page_transition_types.h" 30 #include "ui/base/page_transition_types.h"
28 #include "url/url_constants.h" 31 #include "url/url_constants.h"
29 32
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 controller().GetBrowserContext()))); 69 controller().GetBrowserContext())));
67 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( 70 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation(
68 node, *entry, reload_type, base::TimeTicks::Now()); 71 node, *entry, reload_type, base::TimeTicks::Now());
69 } 72 }
70 73
71 NavigationRequest* GetNavigationRequestForFrameTreeNode( 74 NavigationRequest* GetNavigationRequestForFrameTreeNode(
72 FrameTreeNode* frame_tree_node) { 75 FrameTreeNode* frame_tree_node) {
73 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) 76 return static_cast<NavigatorImpl*>(frame_tree_node->navigator())
74 ->GetNavigationRequestForNodeForTesting(frame_tree_node); 77 ->GetNavigationRequestForNodeForTesting(frame_tree_node);
75 } 78 }
79
80 TestRenderFrameHost* GetSpeculativeRenderFrameHost(FrameTreeNode* node) {
81 return static_cast<TestRenderFrameHost*>(
82 node->render_manager()->speculative_render_frame_host_.get());
83 }
84
85 // Checks if this RenderFrameHost sent a single FrameMsg_CommitNavigation
86 // since the last clearing of the sink.
87 // Note: user must call ClearMessages on the sink before the commit happens.
88 bool DidRenderFrameHostCommit(RenderFrameHostImpl* rfh) {
89 MockRenderProcessHost* rph =
90 static_cast<MockRenderProcessHost*>(rfh->GetProcess());
clamy 2014/12/30 16:57:45 You can just call process() instead (from RenderVi
carlosk 2014/12/31 13:39:18 I can't. For this check to work I need the mock pr
clamy 2014/12/31 14:07:09 Acknowledged.
91 const FrameMsg_CommitNavigation* commitMessage =
92 static_cast<const FrameMsg_CommitNavigation*>(
93 rph->sink().GetUniqueMessageMatching(
94 FrameMsg_CommitNavigation::ID));
95 return commitMessage && rfh->GetRoutingID() == commitMessage->routing_id();
96 }
76 }; 97 };
77 98
99 // PlzNavigate: Test final state after a complete navigation (to avoid repeating
clamy 2014/12/30 16:57:45 nit: "(to avoid repeating these checks)" may be un
carlosk 2014/12/31 13:39:18 I'd prefer to leave that note to indicate to futur
clamy 2014/12/31 14:07:09 Acknowledged.
100 // these checks).
101 TEST_F(NavigatorTestWithBrowserSideNavigation, NavigationFinishedState) {
102 const GURL kUrl("http://chromium.org/");
103 contents()->NavigateAndCommit(kUrl);
104 ASSERT_TRUE(main_test_rfh());
105 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
106 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
107 main_test_rfh()->GetSiteInstance()->GetSiteURL());
clamy 2014/12/30 16:57:45 nit: add an extra-line here.
carlosk 2014/12/31 13:39:18 Done.
108 // After a navigation is finished no speculative RenderFrameHost should
109 // exist.
110 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
111 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
clamy 2014/12/30 16:57:45 nit: add an extra line here.
carlosk 2014/12/31 13:39:19 Done.
112 // With PlzNavigate enabled a pending RenderFrameHost should never exist.
113 EXPECT_FALSE(node->render_manager()->pending_frame_host());
114 }
115
78 // PlzNavigate: Test that a proper NavigationRequest is created by 116 // PlzNavigate: Test that a proper NavigationRequest is created by
79 // BeginNavigation. 117 // BeginNavigation.
80 // Note that all PlzNavigate methods on the browser side require the use of the 118 // Note that all PlzNavigate methods on the browser side require the use of the
81 // flag kEnableBrowserSideNavigation. 119 // flag kEnableBrowserSideNavigation.
82 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { 120 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
83 const GURL kUrl1("http://www.google.com/"); 121 const GURL kUrl1("http://www.google.com/");
84 const GURL kUrl2("http://www.chromium.org/"); 122 const GURL kUrl2("http://www.chromium.org/");
85 const GURL kUrl3("http://www.gmail.com/"); 123 const GURL kUrl3("http://www.gmail.com/");
86 124
87 contents()->NavigateAndCommit(kUrl1); 125 contents()->NavigateAndCommit(kUrl1);
126 FrameTreeNode* root_node = contents()->GetFrameTree()->root();
clamy 2014/12/30 16:57:45 nit: this line does not need to be moved.
carlosk 2014/12/31 13:39:18 Done.
127 RenderFrameHostManager* root_rfhm = root_node->render_manager();
88 128
89 // Add a subframe. 129 // Add a subframe.
90 FrameTreeNode* root = contents()->GetFrameTree()->root(); 130 TestRenderFrameHost* subframe_rfh =
91 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 131 static_cast<TestRenderFrameHost*>(contents()->GetFrameTree()->AddFrame(
92 contents()->GetFrameTree()->AddFrame( 132 root_node, root_node->current_frame_host()->GetProcess()->GetID(), 14,
93 root, root->current_frame_host()->GetProcess()->GetID(), 14,
94 "Child")); 133 "Child"));
95 EXPECT_TRUE(subframe_rfh); 134 ASSERT_TRUE(subframe_rfh);
96 135
97 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 136 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
98 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); 137 EXPECT_NE(root_rfhm, subframe_node->render_manager());
clamy 2014/12/30 16:57:45 This is unnecessary (you are testing FrameTree fun
carlosk 2014/12/31 13:39:19 Done.
138
139 SendRequestNavigation(subframe_node, kUrl2);
99 // There is no previous renderer in the subframe, so BeginNavigation is 140 // There is no previous renderer in the subframe, so BeginNavigation is
100 // handled already. 141 // handled already.
101 NavigationRequest* subframe_request = 142 NavigationRequest* subframe_request =
102 GetNavigationRequestForFrameTreeNode(subframe_node); 143 GetNavigationRequestForFrameTreeNode(subframe_node);
103 TestNavigationURLLoader* subframe_loader = 144 TestNavigationURLLoader* subframe_loader =
104 GetLoaderForNavigationRequest(subframe_request); 145 GetLoaderForNavigationRequest(subframe_request);
105 ASSERT_TRUE(subframe_request); 146 ASSERT_TRUE(subframe_request);
106 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 147 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
107 EXPECT_EQ(kUrl2, subframe_loader->common_params().url); 148 EXPECT_EQ(kUrl2, subframe_loader->common_params().url);
108 // First party for cookies url should be that of the main frame. 149 // First party for cookies url should be that of the main frame.
109 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); 150 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
110 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); 151 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
111 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); 152 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
153 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
112 154
113 SendRequestNavigation(root, kUrl3); 155 // Subframe navigations should not create a speculative RenderFrameHost.
156 // (unless site-per-process is enabled).
157 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
158 switches::kSitePerProcess)) {
159 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
160 } else {
161 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
162 }
163
164 SendRequestNavigation(root_node, kUrl3);
114 // Simulate a BeginNavigation IPC on the main frame. 165 // Simulate a BeginNavigation IPC on the main frame.
115 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); 166 main_test_rfh()->SendBeginNavigationWithURL(kUrl3);
116 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(root); 167 NavigationRequest* main_request =
168 GetNavigationRequestForFrameTreeNode(root_node);
117 TestNavigationURLLoader* main_loader = 169 TestNavigationURLLoader* main_loader =
118 GetLoaderForNavigationRequest(main_request); 170 GetLoaderForNavigationRequest(main_request);
119 ASSERT_TRUE(main_request); 171 ASSERT_TRUE(main_request);
120 EXPECT_EQ(kUrl3, main_request->common_params().url); 172 EXPECT_EQ(kUrl3, main_request->common_params().url);
121 EXPECT_EQ(kUrl3, main_loader->common_params().url); 173 EXPECT_EQ(kUrl3, main_loader->common_params().url);
122 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 174 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
123 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 175 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
124 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 176 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
177
178 // Main frame navigations to different sites should use a speculative
179 // RenderFrameHost.
180 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
181 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
clamy 2014/12/30 16:57:46 nit: maybe you should precise that this check is d
carlosk 2014/12/31 13:39:18 Done.
182 switches::kSitePerProcess)) {
183 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
184 } else {
185 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
186 }
125 } 187 }
126 188
127 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that 189 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
128 // RenderFrameHost is not modified when the navigation commits. 190 // RenderFrameHost is not modified when the navigation commits.
129 TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) { 191 TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) {
130 const GURL kUrl("http://www.google.com/"); 192 const GURL kUrl("http://www.google.com/");
131 193
132 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 194 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
133 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 195 RenderFrameHostImpl* rfh = main_test_rfh();
196 FrameTreeNode* node = rfh->frame_tree_node();
134 SendRequestNavigation(node, kUrl); 197 SendRequestNavigation(node, kUrl);
198
199 // A NavigationRequest should have been generated.
135 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 200 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
136 // A NavigationRequest should have been generated.
137 EXPECT_TRUE(main_request != NULL); 201 EXPECT_TRUE(main_request != NULL);
138 RenderFrameHostImpl* rfh = main_test_rfh(); 202
203 // As we're re-using the current RenderFrameHost, no speculative one should be
204 // created.
205 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
139 206
140 // Now return the response without any redirects. This will cause the 207 // Now return the response without any redirects. This will cause the
141 // navigation to commit at the same URL. 208 // navigation to commit at the same URL.
142 scoped_refptr<ResourceResponse> response(new ResourceResponse); 209 scoped_refptr<ResourceResponse> response(new ResourceResponse);
143 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 210 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
144 response, MakeEmptyStream()); 211 response, MakeEmptyStream());
145 main_request = GetNavigationRequestForFrameTreeNode(node); 212 main_request = GetNavigationRequestForFrameTreeNode(node);
146 213
147 // The main RFH should not have been changed, and the renderer should have 214 // The main RFH should not have been changed, and the renderer should have
148 // been initialized. 215 // been initialized.
149 EXPECT_EQ(rfh, main_test_rfh()); 216 EXPECT_EQ(rfh, main_test_rfh());
150 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); 217 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
151 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 218 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
152 } 219 }
153 220
154 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the 221 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels
155 // navigation. 222 // the navigation.
156 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { 223 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
157 const GURL kUrl1("http://www.chromium.org/"); 224 const GURL kUrl1("http://www.chromium.org/");
158 const GURL kUrl2("http://www.google.com/"); 225 const GURL kUrl2("http://www.google.com/");
159 226
160 // Load a URL. 227 // Load a URL.
161 contents()->NavigateAndCommit(kUrl1); 228 contents()->NavigateAndCommit(kUrl1);
162 RenderFrameHostImpl* rfh = main_test_rfh();
163 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
164 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 229 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
165 230
166 // Navigate to a different site. 231 // Navigate to a different site.
167 SendRequestNavigation(node, kUrl2); 232 contents()->GetController().LoadURL(kUrl2, Referrer(),
233 ui::PAGE_TRANSITION_LINK, std::string());
168 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 234 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
235
169 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 236 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
170 ASSERT_TRUE(main_request); 237 ASSERT_TRUE(main_request);
171 238
239 // Navigations to a different site do create a speculative RenderFrameHost.
240 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
241
172 // Commit an HTTP 204 response. 242 // Commit an HTTP 204 response.
173 scoped_refptr<ResourceResponse> response(new ResourceResponse); 243 scoped_refptr<ResourceResponse> response(new ResourceResponse);
174 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; 244 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0";
175 response->head.headers = new net::HttpResponseHeaders( 245 response->head.headers = new net::HttpResponseHeaders(
176 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); 246 std::string(kNoContentHeaders, arraysize(kNoContentHeaders)));
177 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 247 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
178 response, MakeEmptyStream()); 248 response, MakeEmptyStream());
179 249
180 // There should be no pending RenderFrameHost; the navigation was aborted. 250 // There should be no pending nor speculative RenderFrameHost; the navigation
251 // was aborted.
181 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 252 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
182 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 253 EXPECT_FALSE(node->render_manager()->pending_frame_host());
254 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
183 255
184 // Now, repeat the test with 205 Reset Content. 256 // Now, repeat the test with 205 Reset Content.
185 257
186 // Navigate to a different site again. 258 // Navigate to a different site again.
187 SendRequestNavigation(node, kUrl2); 259 contents()->GetController().LoadURL(kUrl2, Referrer(),
260 ui::PAGE_TRANSITION_LINK, std::string());
188 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 261 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
262
189 main_request = GetNavigationRequestForFrameTreeNode(node); 263 main_request = GetNavigationRequestForFrameTreeNode(node);
190 ASSERT_TRUE(main_request); 264 ASSERT_TRUE(main_request);
265 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
191 266
192 // Commit an HTTP 205 response. 267 // Commit an HTTP 205 response.
193 response = new ResourceResponse; 268 response = new ResourceResponse;
194 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; 269 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0";
195 response->head.headers = new net::HttpResponseHeaders( 270 response->head.headers = new net::HttpResponseHeaders(
196 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); 271 std::string(kResetContentHeaders, arraysize(kResetContentHeaders)));
197 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 272 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
198 response, MakeEmptyStream()); 273 response, MakeEmptyStream());
199 274
200 // There should be no pending RenderFrameHost; the navigation was aborted. 275 // There should be no pending nor speculative RenderFrameHost; the navigation
276 // was aborted.
201 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 277 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
202 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 278 EXPECT_FALSE(node->render_manager()->pending_frame_host());
279 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
203 } 280 }
204 281
205 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross 282 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
206 // site navigation. 283 // site navigation.
207 TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) { 284 TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) {
208 const GURL kUrl1("http://www.chromium.org/"); 285 const GURL kUrl1("http://www.chromium.org/");
209 const GURL kUrl2("http://www.google.com/"); 286 const GURL kUrl2("http://www.google.com/");
210 287
211 contents()->NavigateAndCommit(kUrl1); 288 contents()->NavigateAndCommit(kUrl1);
212 RenderFrameHostImpl* rfh = main_test_rfh(); 289 process()->sink().ClearMessages();
213 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); 290 RenderFrameHostImpl* initial_rfh = main_test_rfh();
214 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 291 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
215 292
216 // Navigate to a different site. 293 // Navigate to a different site.
217 SendRequestNavigation(node, kUrl2); 294 contents()->GetController().LoadURL(kUrl2, Referrer(),
295 ui::PAGE_TRANSITION_LINK, std::string());
218 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 296 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
219 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 297 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
220 ASSERT_TRUE(main_request); 298 ASSERT_TRUE(main_request);
299 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
221 300
222 scoped_refptr<ResourceResponse> response(new ResourceResponse); 301 scoped_refptr<ResourceResponse> response(new ResourceResponse);
223 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 302 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
224 response, MakeEmptyStream()); 303 response, MakeEmptyStream());
225 RenderFrameHostImpl* pending_rfh = 304 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
226 node->render_manager()->pending_frame_host(); 305 ASSERT_TRUE(speculative_rfh);
227 ASSERT_TRUE(pending_rfh); 306 ASSERT_TRUE(DidRenderFrameHostCommit(speculative_rfh));
clamy 2014/12/30 16:57:45 I would use an EXPECT_TRUE here.
carlosk 2014/12/31 13:39:18 Done. This reminded me to add that similar commit
228 EXPECT_NE(pending_rfh, rfh); 307
229 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 308 speculative_rfh->SendNavigate(0, kUrl2);
230 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); 309
310 RenderFrameHostImpl* final_rfh = main_test_rfh();
311 ASSERT_TRUE(final_rfh);
312 EXPECT_NE(initial_rfh, final_rfh);
313 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
314 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
315 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
231 } 316 }
232 317
233 // PlzNavigate: Test that redirects are followed. 318 // PlzNavigate: Test that redirects are followed and the speculative renderer
319 // logic behaves as expected.
234 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { 320 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
235 const GURL kUrl1("http://www.chromium.org/"); 321 const GURL kUrl1("http://www.chromium.org/");
236 const GURL kUrl2("http://www.google.com/"); 322 const GURL kUrl2("http://www.google.com/");
237 323
238 contents()->NavigateAndCommit(kUrl1); 324 contents()->NavigateAndCommit(kUrl1);
239 RenderFrameHostImpl* rfh = main_test_rfh(); 325 RenderFrameHostImpl* rfh = main_test_rfh();
240 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
241 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 326 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
242 327
243 // Navigate to a URL on the same site. 328 // Navigate to a URL on the same site.
244 SendRequestNavigation(node, kUrl1); 329 contents()->GetController().LoadURL(kUrl1, Referrer(),
330 ui::PAGE_TRANSITION_LINK, std::string());
245 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 331 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
246 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 332 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
247 ASSERT_TRUE(main_request); 333 ASSERT_TRUE(main_request);
334 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
248 335
249 // It then redirects to another site. 336 // It then redirects to another site.
250 net::RedirectInfo redirect_info; 337 net::RedirectInfo redirect_info;
251 redirect_info.status_code = 302; 338 redirect_info.status_code = 302;
252 redirect_info.new_method = "GET"; 339 redirect_info.new_method = "GET";
253 redirect_info.new_url = kUrl2; 340 redirect_info.new_url = kUrl2;
254 redirect_info.new_first_party_for_cookies = kUrl2; 341 redirect_info.new_first_party_for_cookies = kUrl2;
255 scoped_refptr<ResourceResponse> response(new ResourceResponse); 342 scoped_refptr<ResourceResponse> response(new ResourceResponse);
256 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( 343 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
257 redirect_info, response); 344 redirect_info, response);
258 345
259 // The redirect should have been followed. 346 // The redirect should have been followed.
260 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); 347 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count());
348 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
261 349
262 // Then it commits. 350 // Then it commits.
263 response = new ResourceResponse; 351 response = new ResourceResponse;
264 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 352 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
265 response, MakeEmptyStream()); 353 response, MakeEmptyStream());
266 RenderFrameHostImpl* pending_rfh = 354 TestRenderFrameHost* last_speculative_rfh =
clamy 2014/12/30 16:57:45 nit: why is it called last_speculative_rfh if no o
carlosk 2014/12/31 13:39:19 Because this will not be the case for much longer.
clamy 2014/12/31 14:07:09 nit: Then could it be called final_speculative_rfh
carlosk 2014/12/31 15:39:51 Done.
267 node->render_manager()->pending_frame_host(); 355 GetSpeculativeRenderFrameHost(node);
268 ASSERT_TRUE(pending_rfh); 356 EXPECT_TRUE(last_speculative_rfh);
269 EXPECT_NE(pending_rfh, rfh); 357
270 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 358 // And commits provisional load.
271 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); 359 contents()->CommitPendingNavigation();
clamy 2014/12/30 16:57:46 Could you use TestRenderFrameHost::SendNavigate he
carlosk 2014/12/31 13:39:18 Done here and for the following cases. And now mor
clamy 2014/12/31 14:07:09 Yes the value should not be modified by redirects
carlosk 2014/12/31 15:39:51 Acknowledged.
360 RenderFrameHostImpl* final_rfh = main_test_rfh();
361 ASSERT_TRUE(final_rfh);
362 EXPECT_NE(rfh, final_rfh);
363 EXPECT_EQ(last_speculative_rfh, final_rfh);
364 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
365 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
366 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
272 } 367 }
273 368
274 // PlzNavigate: Test that a navigation is cancelled if another request has been 369 // PlzNavigate: Test that a navigation is canceled if another request has been
275 // issued in the meantime. 370 // issued in the meantime. Also confirms that the speculative renderer is
371 // correctly updated in the process.
276 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { 372 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
277 const GURL kUrl0("http://www.wikipedia.org/"); 373 const GURL kUrl0("http://www.wikipedia.org/");
278 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0);
279 const GURL kUrl1("http://www.chromium.org/"); 374 const GURL kUrl1("http://www.chromium.org/");
375 const GURL kUrl1_site = SiteInstance::GetSiteForURL(browser_context(), kUrl1);
280 const GURL kUrl2("http://www.google.com/"); 376 const GURL kUrl2("http://www.google.com/");
281 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); 377 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
282 378
283 // Initialization. 379 // Initialization.
284 contents()->NavigateAndCommit(kUrl0); 380 contents()->NavigateAndCommit(kUrl0);
285 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 381 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
286 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
287 382
288 // Request navigation to the 1st URL. 383 // Request navigation to the 1st URL.
289 SendRequestNavigation(node, kUrl1); 384 contents()->GetController().LoadURL(kUrl1, Referrer(),
385 ui::PAGE_TRANSITION_LINK, std::string());
290 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 386 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
291 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); 387 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
292 ASSERT_TRUE(request1); 388 ASSERT_TRUE(request1);
293 EXPECT_EQ(kUrl1, request1->common_params().url); 389 EXPECT_EQ(kUrl1, request1->common_params().url);
294 base::WeakPtr<TestNavigationURLLoader> loader1 = 390 base::WeakPtr<TestNavigationURLLoader> loader1 =
295 GetLoaderForNavigationRequest(request1)->AsWeakPtr(); 391 GetLoaderForNavigationRequest(request1)->AsWeakPtr();
296 392
393 // Confirm a speculative RFH was created.
394 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
395 ASSERT_TRUE(speculative_rfh);
396 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId();
397 EXPECT_EQ(kUrl1_site, speculative_rfh->GetSiteInstance()->GetSiteURL());
398
297 // Request navigation to the 2nd URL; the NavigationRequest must have been 399 // Request navigation to the 2nd URL; the NavigationRequest must have been
298 // replaced by a new one with a different URL. 400 // replaced by a new one with a different URL.
299 SendRequestNavigation(node, kUrl2); 401 contents()->GetController().LoadURL(kUrl2, Referrer(),
402 ui::PAGE_TRANSITION_LINK, std::string());
300 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 403 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
301 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); 404 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
302 ASSERT_TRUE(request2); 405 ASSERT_TRUE(request2);
303 EXPECT_EQ(kUrl2, request2->common_params().url); 406 EXPECT_EQ(kUrl2, request2->common_params().url);
304 407
305 // Confirm that the first loader got destroyed. 408 // Confirm that the first loader got destroyed.
306 EXPECT_FALSE(loader1); 409 EXPECT_FALSE(loader1);
307 410
308 // Confirm that the commit corresponds to the new request. 411 // Confirm that a new speculative RFH was created.
412 speculative_rfh = GetSpeculativeRenderFrameHost(node);
413 ASSERT_TRUE(speculative_rfh);
414 int32 site_instance_id_2 = speculative_rfh->GetSiteInstance()->GetId();
415 EXPECT_NE(site_instance_id_1, site_instance_id_2);
416
417 // Commit.
309 scoped_refptr<ResourceResponse> response(new ResourceResponse); 418 scoped_refptr<ResourceResponse> response(new ResourceResponse);
310 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( 419 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
311 response, MakeEmptyStream()); 420 response, MakeEmptyStream());
312 RenderFrameHostImpl* pending_rfh = 421
313 node->render_manager()->pending_frame_host(); 422 // And commit provisional load.
314 ASSERT_TRUE(pending_rfh); 423 contents()->CommitPendingNavigation();
clamy 2014/12/30 16:57:45 Same as above, please use SendNavigate here.
carlosk 2014/12/31 13:39:18 Done.
315 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); 424
425 // Confirm that the commit corresponds to the new request.
426 ASSERT_TRUE(main_test_rfh());
427 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
428
429 // Confirm that the committed RFH is the new speculative one.
430 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId());
316 } 431 }
317 432
318 // PlzNavigate: Test that a reload navigation is properly signaled to the 433 // PlzNavigate: Test that a reload navigation is properly signaled to the
319 // renderer when the navigation can commit. 434 // renderer when the navigation can commit. Speculative renderers should not be
435 // created at any step.
320 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { 436 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
321 const GURL kUrl("http://www.google.com/"); 437 const GURL kUrl("http://www.google.com/");
322 contents()->NavigateAndCommit(kUrl); 438 contents()->NavigateAndCommit(kUrl);
323 439
324 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 440 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
325 SendRequestNavigationWithParameters( 441 SendRequestNavigationWithParameters(
326 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 442 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
327 NavigationController::RELOAD); 443 NavigationController::RELOAD);
328 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 444 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
329 // A NavigationRequest should have been generated. 445 // A NavigationRequest should have been generated.
330 NavigationRequest* main_request = 446 NavigationRequest* main_request =
331 GetNavigationRequestForFrameTreeNode(node); 447 GetNavigationRequestForFrameTreeNode(node);
332 ASSERT_TRUE(main_request != NULL); 448 ASSERT_TRUE(main_request != NULL);
333 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, 449 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD,
334 main_request->common_params().navigation_type); 450 main_request->common_params().navigation_type);
335 int page_id = contents()->GetMaxPageIDForSiteInstance( 451 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
336 main_test_rfh()->GetSiteInstance()) + 1; 452
337 main_test_rfh()->SendNavigate(page_id, kUrl); 453 main_test_rfh()->SendNavigate(0, kUrl);
454 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
338 455
339 // Now do a shift+reload. 456 // Now do a shift+reload.
340 SendRequestNavigationWithParameters( 457 SendRequestNavigationWithParameters(
341 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 458 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
342 NavigationController::RELOAD_IGNORING_CACHE); 459 NavigationController::RELOAD_IGNORING_CACHE);
343 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 460 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
344 // A NavigationRequest should have been generated. 461 // A NavigationRequest should have been generated.
345 main_request = GetNavigationRequestForFrameTreeNode(node); 462 main_request = GetNavigationRequestForFrameTreeNode(node);
346 ASSERT_TRUE(main_request != NULL); 463 ASSERT_TRUE(main_request != NULL);
347 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 464 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
348 main_request->common_params().navigation_type); 465 main_request->common_params().navigation_type);
466 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
467 }
468
469 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when
470 // navigating from one site to the another.
471 TEST_F(NavigatorTestWithBrowserSideNavigation,
472 SpeculativeRendererWorksBaseCase) {
473 // Navigate to an initial site.
474 const GURL kUrlInit("http://wikipedia.org/");
475 contents()->NavigateAndCommit(kUrlInit);
476 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
477
478 // Begin navigating to another site.
479 const GURL kUrl("http://google.com/");
480 contents()->GetController().LoadURL(kUrl, Referrer(),
481 ui::PAGE_TRANSITION_LINK, std::string());
482 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
483 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
484 ASSERT_TRUE(speculative_rfh);
485 EXPECT_NE(speculative_rfh, main_test_rfh());
486 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
487 speculative_rfh->GetSiteInstance()->GetSiteURL());
488 EXPECT_FALSE(node->render_manager()->pending_frame_host());
489 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
490
491 // Ask Navigator to commit the navigation by simulating a call to
492 // OnResponseStarted.
493 scoped_refptr<ResourceResponse> response(new ResourceResponse);
494 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
495 ->CallOnResponseStarted(response, MakeEmptyStream());
496 speculative_rfh = GetSpeculativeRenderFrameHost(node);
497 ASSERT_TRUE(speculative_rfh);
498 EXPECT_EQ(site_instance_id, speculative_rfh->GetSiteInstance()->GetId());
499 EXPECT_FALSE(node->render_manager()->pending_frame_host());
500
501 // Invoke OnDidCommitProvisionalLoad.
502 contents()->CommitPendingNavigation();
clamy 2014/12/30 16:57:45 Same as above, please use SendNavigate.
carlosk 2014/12/31 13:39:19 Done.
503 EXPECT_EQ(site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
504 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
505 EXPECT_FALSE(node->render_manager()->pending_frame_host());
506 }
507
508 // PlzNavigate: Confirm that a speculative RenderFrameHost is thrown away when
509 // the final URL's site differs from the initial one due to redirects.
510 TEST_F(NavigatorTestWithBrowserSideNavigation,
511 SpeculativeRendererDiscardedAfterRedirectToAnotherSite) {
512 // Navigate to an initial site.
513 const GURL kUrlInit("http://wikipedia.org/");
514 contents()->NavigateAndCommit(kUrlInit);
515 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
516 int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId();
517
518 // Begin navigating to another site.
519 const GURL kUrl("http://google.com/");
520 contents()->GetController().LoadURL(kUrl, Referrer(),
521 ui::PAGE_TRANSITION_LINK, std::string());
522 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
523 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
524 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
525 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
526 ASSERT_TRUE(speculative_rfh);
527 EXPECT_NE(speculative_rfh, main_test_rfh());
528 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
529 speculative_rfh->GetSiteInstance()->GetSiteURL());
530
531 // It then redirects to yet another site.
532 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
533 ASSERT_TRUE(main_request);
534 const GURL kUrlRedirect("https://www.google.com/");
535 net::RedirectInfo redirect_info;
536 redirect_info.status_code = 302;
537 redirect_info.new_method = "GET";
538 redirect_info.new_url = kUrlRedirect;
539 redirect_info.new_first_party_for_cookies = kUrlRedirect;
540 scoped_refptr<ResourceResponse> response(new ResourceResponse);
541 GetLoaderForNavigationRequest(main_request)
542 ->CallOnRequestRedirected(redirect_info, response);
543 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
544 speculative_rfh = GetSpeculativeRenderFrameHost(node);
545 ASSERT_TRUE(speculative_rfh);
546
547 // TODO(carlosk): once the speculative RenderFrameHost updates with redirects
548 // this next check will be changed to verify that it actually happens.
549 EXPECT_EQ(site_instance_id, speculative_rfh->GetSiteInstance()->GetId());
550
551 // Commit the navigation with Navigator by simulating the call to
552 // OnResponseStarted.
553 response = new ResourceResponse;
554 GetLoaderForNavigationRequest(main_request)
555 ->CallOnResponseStarted(response, MakeEmptyStream());
556 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
557
558 // Once commit happens the speculative RenderFrameHost is already updated to
559 // match the known final SiteInstance.
560 speculative_rfh = GetSpeculativeRenderFrameHost(node);
561 ASSERT_TRUE(speculative_rfh);
562 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlRedirect),
563 speculative_rfh->GetSiteInstance()->GetSiteURL());
564 int32 redirect_site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
565
566 // Invoke OnDidCommitProvisionalLoad.
567 contents()->CommitPendingNavigation();
clamy 2014/12/30 16:57:46 Please us SendNavigate here.
carlosk 2014/12/31 13:39:18 Done.
568
569 // And finally on commit-provisional-load the already created RenderFrameHost
570 // is made active.
clamy 2014/12/30 16:57:45 Maybe rephrase this as Finally, when the navigatio
carlosk 2014/12/31 13:39:18 This doesn't sound very accurate either as the RFH
clamy 2014/12/31 14:07:09 It depends on how you define commit. Currently, it
carlosk 2014/12/31 15:39:51 Done.
571 EXPECT_EQ(redirect_site_instance_id,
572 main_test_rfh()->GetSiteInstance()->GetId());
573 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
574 }
575
576 // PlzNavigate: Verify that a previously swapped-out RenderFrameHost is
clamy 2014/12/30 16:57:45 nit: s/swapped-out/swapped out
carlosk 2014/12/31 13:39:19 Done.
577 // correctly reused when spawning a speculative RenderFrameHost in a navigation
578 // using the same SiteInstance.
579 TEST_F(NavigatorTestWithBrowserSideNavigation,
580 SpeculativeRendererReuseSwappedOutRFH) {
581 // Navigate to an initial site.
582 const GURL kUrl1("http://wikipedia.org/");
583 contents()->NavigateAndCommit(kUrl1);
584 RenderFrameHostImpl* rfh1 = main_test_rfh();
585 FrameTreeNode* node = rfh1->frame_tree_node();
586 RenderFrameHostManager* rfhm = node->render_manager();
587
588 // Increment active frame count to cause the RenderFrameHost to be swapped out
589 // (instead of immediately destroyed).
590 rfh1->GetSiteInstance()->increment_active_frame_count();
591
592 // Navigate to another site to swap-out the initial RenderFrameHost.
593 const GURL kUrl2("http://chromium.org/");
594 contents()->NavigateAndCommit(kUrl2);
595 ASSERT_NE(rfh1, main_test_rfh());
596 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
597 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
598 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1));
599
600 // Now go back to the initial site so the swapped-out RenderFrameHost should
601 // be reused.
602 contents()->GetController().LoadURL(kUrl1, Referrer(),
603 ui::PAGE_TRANSITION_LINK, std::string());
604 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
605 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
606 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT,
607 GetSpeculativeRenderFrameHost(node)->rfh_state());
608
609 scoped_refptr<ResourceResponse> response(new ResourceResponse);
610 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
611 ->CallOnResponseStarted(response, MakeEmptyStream());
612 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
613 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT,
614 GetSpeculativeRenderFrameHost(node)->rfh_state());
615
616 contents()->CommitPendingNavigation();
clamy 2014/12/30 16:57:45 Please use SendNavigate.
carlosk 2014/12/31 13:39:18 Done.
617 EXPECT_EQ(rfh1, main_test_rfh());
618 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
619 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
349 } 620 }
350 621
351 } // namespace content 622 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698