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

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: Re-applying previous changes over. 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 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/macros.h" 5 #include "base/macros.h"
6 #include "base/time/time.h" 6 #include "base/time/time.h"
7 #include "content/browser/frame_host/navigation_controller_impl.h" 7 #include "content/browser/frame_host/navigation_controller_impl.h"
8 #include "content/browser/frame_host/navigation_entry_impl.h" 8 #include "content/browser/frame_host/navigation_entry_impl.h"
9 #include "content/browser/frame_host/navigation_request.h" 9 #include "content/browser/frame_host/navigation_request.h"
10 #include "content/browser/frame_host/navigation_request_info.h" 10 #include "content/browser/frame_host/navigation_request_info.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 FrameTreeNode* frame_tree_node) { 78 FrameTreeNode* frame_tree_node) {
79 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) 79 return static_cast<NavigatorImpl*>(frame_tree_node->navigator())
80 ->GetNavigationRequestForNodeForTesting(frame_tree_node); 80 ->GetNavigationRequestForNodeForTesting(frame_tree_node);
81 } 81 }
82 }; 82 };
83 83
84 // PlzNavigate: Test that a proper NavigationRequest is created by 84 // PlzNavigate: Test that a proper NavigationRequest is created by
85 // BeginNavigation. 85 // BeginNavigation.
86 // Note that all PlzNavigate methods on the browser side require the use of the 86 // Note that all PlzNavigate methods on the browser side require the use of the
87 // flag kEnableBrowserSideNavigation. 87 // flag kEnableBrowserSideNavigation.
88 // TODO(carlosk): Will fix this ASAP but it currently crashes with my latest
89 // changes from speculative renderer creation.
88 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { 90 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
clamy 2014/11/25 16:50:57 Is it still failing?
carlosk 2014/11/28 13:08:17 Now it's not anymore so that TODO is gone.
89 const GURL kUrl1("http://www.google.com/"); 91 const GURL kUrl1("http://www.google.com/");
90 const GURL kUrl2("http://www.chromium.org/"); 92 const GURL kUrl2("http://www.chromium.org/");
91 const GURL kUrl3("http://www.gmail.com/"); 93 const GURL kUrl3("http://www.gmail.com/");
92 94
93 contents()->NavigateAndCommit(kUrl1); 95 contents()->NavigateAndCommit(kUrl1);
94 96
95 // Add a subframe. 97 // Add a subframe.
96 FrameTreeNode* root = contents()->GetFrameTree()->root(); 98 FrameTreeNode* root = contents()->GetFrameTree()->root();
97 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 99 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
98 contents()->GetFrameTree()->AddFrame( 100 contents()->GetFrameTree()->AddFrame(
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 223
222 // Navigate to a different site. 224 // Navigate to a different site.
223 SendRequestNavigation(node, kUrl2); 225 SendRequestNavigation(node, kUrl2);
224 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 226 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
225 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 227 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
226 ASSERT_TRUE(main_request); 228 ASSERT_TRUE(main_request);
227 229
228 scoped_refptr<ResourceResponse> response(new ResourceResponse); 230 scoped_refptr<ResourceResponse> response(new ResourceResponse);
229 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 231 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
230 response, MakeEmptyStream()); 232 response, MakeEmptyStream());
231 RenderFrameHostImpl* pending_rfh = 233 RenderFrameHostImpl* final_rfh = main_test_rfh();
232 node->render_manager()->pending_frame_host(); 234 ASSERT_TRUE(final_rfh);
233 ASSERT_TRUE(pending_rfh); 235 EXPECT_NE(final_rfh, rfh);
234 EXPECT_NE(pending_rfh, rfh); 236 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
235 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 237 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
236 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
237 } 238 }
238 239
239 // PlzNavigate: Test that redirects are followed. 240 // PlzNavigate: Test that redirects are followed.
240 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { 241 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
241 const GURL kUrl1("http://www.chromium.org/"); 242 const GURL kUrl1("http://www.chromium.org/");
242 const GURL kUrl2("http://www.google.com/"); 243 const GURL kUrl2("http://www.google.com/");
243 244
244 contents()->NavigateAndCommit(kUrl1); 245 contents()->NavigateAndCommit(kUrl1);
245 RenderFrameHostImpl* rfh = main_test_rfh(); 246 RenderFrameHostImpl* rfh = main_test_rfh();
246 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); 247 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
(...skipping 15 matching lines...) Expand all
262 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( 263 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
263 redirect_info, response); 264 redirect_info, response);
264 265
265 // The redirect should have been followed. 266 // The redirect should have been followed.
266 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); 267 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count());
267 268
268 // Then it commits. 269 // Then it commits.
269 response = new ResourceResponse; 270 response = new ResourceResponse;
270 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 271 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
271 response, MakeEmptyStream()); 272 response, MakeEmptyStream());
272 RenderFrameHostImpl* pending_rfh = 273 RenderFrameHostImpl* final_rfh = main_test_rfh();
273 node->render_manager()->pending_frame_host(); 274 ASSERT_TRUE(final_rfh);
274 ASSERT_TRUE(pending_rfh); 275 EXPECT_NE(final_rfh, rfh);
275 EXPECT_NE(pending_rfh, rfh); 276 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
276 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 277 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
277 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
278 } 278 }
279 279
280 // PlzNavigate: Test that a navigation is cancelled if another request has been 280 // PlzNavigate: Test that a navigation is canceled if another request has been
281 // issued in the meantime. 281 // issued in the meantime.
282 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { 282 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) {
283 const GURL kUrl0("http://www.wikipedia.org/"); 283 const GURL kUrl0("http://www.wikipedia.org/");
284 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); 284 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0);
285 const GURL kUrl1("http://www.chromium.org/"); 285 const GURL kUrl1("http://www.chromium.org/");
286 const GURL kUrl2("http://www.google.com/"); 286 const GURL kUrl2("http://www.google.com/");
287 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); 287 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
288 288
289 // Initialization. 289 // Initialization.
290 contents()->NavigateAndCommit(kUrl0); 290 contents()->NavigateAndCommit(kUrl0);
(...skipping 17 matching lines...) Expand all
308 ASSERT_TRUE(request2); 308 ASSERT_TRUE(request2);
309 EXPECT_EQ(kUrl2, request2->common_params().url); 309 EXPECT_EQ(kUrl2, request2->common_params().url);
310 310
311 // Confirm that the first loader got destroyed. 311 // Confirm that the first loader got destroyed.
312 EXPECT_FALSE(loader1); 312 EXPECT_FALSE(loader1);
313 313
314 // Confirm that the commit corresponds to the new request. 314 // Confirm that the commit corresponds to the new request.
315 scoped_refptr<ResourceResponse> response(new ResourceResponse); 315 scoped_refptr<ResourceResponse> response(new ResourceResponse);
316 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( 316 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
317 response, MakeEmptyStream()); 317 response, MakeEmptyStream());
318 RenderFrameHostImpl* pending_rfh = 318 RenderFrameHostImpl* final_rfh = main_test_rfh();
319 node->render_manager()->pending_frame_host(); 319 ASSERT_TRUE(final_rfh);
320 ASSERT_TRUE(pending_rfh); 320 EXPECT_EQ(kUrl2_site, final_rfh->GetSiteInstance()->GetSiteURL());
321 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL());
322 } 321 }
323 322
324 // PlzNavigate: Test that a reload navigation is properly signaled to the 323 // PlzNavigate: Test that a reload navigation is properly signaled to the
325 // renderer when the navigation can commit. 324 // renderer when the navigation can commit.
326 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { 325 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
327 const GURL kUrl("http://www.google.com/"); 326 const GURL kUrl("http://www.google.com/");
328 contents()->NavigateAndCommit(kUrl); 327 contents()->NavigateAndCommit(kUrl);
329 328
330 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 329 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
331 SendRequestNavigationWithParameters( 330 SendRequestNavigationWithParameters(
(...skipping 15 matching lines...) Expand all
347 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 346 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
348 NavigationController::RELOAD_IGNORING_CACHE); 347 NavigationController::RELOAD_IGNORING_CACHE);
349 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 348 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
350 // A NavigationRequest should have been generated. 349 // A NavigationRequest should have been generated.
351 main_request = GetNavigationRequestForFrameTreeNode(node); 350 main_request = GetNavigationRequestForFrameTreeNode(node);
352 ASSERT_TRUE(main_request != NULL); 351 ASSERT_TRUE(main_request != NULL);
353 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 352 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
354 main_request->common_params().navigation_type); 353 main_request->common_params().navigation_type);
355 } 354 }
356 355
356 // PlzNavigate: Confirms that a speculative renderer process is used when
nasko 2014/11/25 00:19:10 nit: s/renderer process/renderer/ or s/renderer pr
carlosk 2014/11/28 13:08:17 Done.
357 // navigation when navigating from one site to the other
clamy 2014/11/25 16:50:57 Remove "when navigation"
carlosk 2014/11/28 13:08:17 Done.
358 TEST_F(NavigatorTestWithBrowserSideNavigation,
359 SpeculativeRendererWorksBaseCase) {
360 // Navigates to an initial site.
clamy 2014/11/25 16:50:57 nit: Navigate (no s).
carlosk 2014/11/28 13:08:17 Done.
361 const GURL kUrlInit("http://wikipedia.org/");
362 contents()->NavigateAndCommit(kUrlInit);
363 TestRenderFrameHost* mrfh = main_test_rfh();
364 FrameTreeNode* node = mrfh->frame_tree_node();
365 RenderFrameHostManager* rfhm = node->render_manager();
366 RenderFrameHost* srfh = rfhm->speculative_render_frame_host();
367 ASSERT_FALSE(srfh);
368
369 // Begins navigating to another site.
nasko 2014/11/25 00:19:10 nit: Begin (no s).
carlosk 2014/11/28 13:08:17 Done.
370 const GURL kUrl("http://google.com/");
371 SendRequestNavigation(node, kUrl);
372 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
373 srfh = rfhm->speculative_render_frame_host();
374 ASSERT_TRUE(srfh);
375 EXPECT_NE(srfh, mrfh);
376 EXPECT_TRUE(srfh->GetProcess()->HasConnection());
377
378 // Commits.
nasko 2014/11/25 00:19:10 nit: Commit (no s).
carlosk 2014/11/28 13:08:17 Done.
379 scoped_refptr<ResourceResponse> response(new ResourceResponse);
380 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
381 GetLoaderForNavigationRequest(main_request)
382 ->CallOnResponseStarted(response, MakeEmptyStream());
383 EXPECT_EQ(srfh, main_test_rfh());
384 EXPECT_FALSE(rfhm->speculative_render_frame_host());
385
386 // And just for completeness invokes OnDidCommitProvisionalLoad which
clamy 2014/11/25 16:50:57 nit: invoke (no s).
carlosk 2014/11/28 13:08:17 Done.
387 // shouldn't change anything in RFHM.
388 FrameHostMsg_DidCommitProvisionalLoad_Params params;
389 params.page_id = 1;
390 params.url = kUrl;
391 params.was_within_same_page = false;
392 params.is_post = false;
393 params.post_id = -1;
394 params.page_state = PageState::CreateForTesting(kUrl, false, 0, 0);
395 main_test_rfh()->SendNavigateWithParams(&params);
396 EXPECT_EQ(srfh, main_test_rfh());
397 EXPECT_FALSE(rfhm->speculative_render_frame_host());
398 }
399
357 } // namespace content 400 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698