Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 controller().GetBrowserContext()))); | 72 controller().GetBrowserContext()))); |
| 73 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( | 73 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( |
| 74 node, *entry, reload_type, base::TimeTicks::Now()); | 74 node, *entry, reload_type, base::TimeTicks::Now()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 NavigationRequest* GetNavigationRequestForFrameTreeNode( | 77 NavigationRequest* GetNavigationRequestForFrameTreeNode( |
| 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 | |
| 83 RenderFrameHost* GetSpeculativeRenderFrameHost(RenderFrameHostManager* rfhm) { | |
| 84 return rfhm->speculative_render_frame_host_.get(); | |
| 85 } | |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 // PlzNavigate: Test that a proper NavigationRequest is created by | 88 // PlzNavigate: Test that a proper NavigationRequest is created by |
| 85 // BeginNavigation. | 89 // BeginNavigation. |
| 86 // Note that all PlzNavigate methods on the browser side require the use of the | 90 // Note that all PlzNavigate methods on the browser side require the use of the |
| 87 // flag kEnableBrowserSideNavigation. | 91 // flag kEnableBrowserSideNavigation. |
| 88 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { | 92 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| 89 const GURL kUrl1("http://www.google.com/"); | 93 const GURL kUrl1("http://www.google.com/"); |
| 90 const GURL kUrl2("http://www.chromium.org/"); | 94 const GURL kUrl2("http://www.chromium.org/"); |
| 91 const GURL kUrl3("http://www.gmail.com/"); | 95 const GURL kUrl3("http://www.gmail.com/"); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 220 |
| 217 contents()->NavigateAndCommit(kUrl1); | 221 contents()->NavigateAndCommit(kUrl1); |
| 218 RenderFrameHostImpl* rfh = main_test_rfh(); | 222 RenderFrameHostImpl* rfh = main_test_rfh(); |
| 219 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); | 223 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
| 220 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 224 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 221 | 225 |
| 222 // Navigate to a different site. | 226 // Navigate to a different site. |
| 223 SendRequestNavigation(node, kUrl2); | 227 SendRequestNavigation(node, kUrl2); |
| 224 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 228 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| 225 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 229 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| 226 ASSERT_TRUE(main_request); | 230 ASSERT_TRUE(main_request); |
|
Charlie Reis
2014/12/04 01:11:30
Can we verify that there's no pending RFH here? A
carlosk
2014/12/09 07:55:41
Note: Initially I just added a couple tests and ex
Charlie Reis
2014/12/10 22:37:44
I'd be happy with having speculative RFH checks in
carlosk
2014/12/16 01:53:47
Done.
| |
| 227 | 231 |
| 228 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 232 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 229 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( | 233 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
|
Charlie Reis
2014/12/04 01:11:30
I'm a bit confused by what this means. Before, it
clamy
2014/12/05 17:16:19
The new RFH is only committed after this call (thi
Charlie Reis
2014/12/05 19:06:23
Oh, I get it. CallOnResponseStarted used to creat
carlosk
2014/12/09 07:55:41
I can do the audit but I'd need more details on wh
Charlie Reis
2014/12/10 22:37:44
Canceled or otherwise altered (e.g., committing a
carlosk
2014/12/16 01:53:47
Ack. As discussed let's leave that for when we rem
| |
| 230 response, MakeEmptyStream()); | 234 response, MakeEmptyStream()); |
| 231 RenderFrameHostImpl* pending_rfh = | 235 RenderFrameHostImpl* final_rfh = main_test_rfh(); |
| 232 node->render_manager()->pending_frame_host(); | 236 ASSERT_TRUE(final_rfh); |
| 233 ASSERT_TRUE(pending_rfh); | 237 EXPECT_NE(final_rfh, rfh); |
| 234 EXPECT_NE(pending_rfh, rfh); | 238 EXPECT_TRUE(final_rfh->IsRenderFrameLive()); |
| 235 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); | 239 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive()); |
| 236 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); | |
| 237 } | 240 } |
| 238 | 241 |
| 239 // PlzNavigate: Test that redirects are followed. | 242 // PlzNavigate: Test that redirects are followed and the speculative renderer |
| 243 // logic behaves as expected. | |
| 240 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { | 244 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { |
| 241 const GURL kUrl1("http://www.chromium.org/"); | 245 const GURL kUrl1("http://www.chromium.org/"); |
| 242 const GURL kUrl2("http://www.google.com/"); | 246 const GURL kUrl2("http://www.google.com/"); |
| 243 | 247 |
| 244 contents()->NavigateAndCommit(kUrl1); | 248 contents()->NavigateAndCommit(kUrl1); |
| 245 RenderFrameHostImpl* rfh = main_test_rfh(); | 249 RenderFrameHostImpl* rfh = main_test_rfh(); |
| 246 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); | 250 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
| 247 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 251 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 252 RenderFrameHostManager* rfhm = node->render_manager(); | |
| 248 | 253 |
| 249 // Navigate to a URL on the same site. | 254 // Navigate to a URL on the same site. |
| 250 SendRequestNavigation(node, kUrl1); | 255 SendRequestNavigation(node, kUrl1); |
| 251 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); | 256 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| 252 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 257 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| 253 ASSERT_TRUE(main_request); | 258 ASSERT_TRUE(main_request); |
| 259 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 254 | 260 |
| 255 // It then redirects to another site. | 261 // It then redirects to another site. |
| 256 net::RedirectInfo redirect_info; | 262 net::RedirectInfo redirect_info; |
| 257 redirect_info.status_code = 302; | 263 redirect_info.status_code = 302; |
| 258 redirect_info.new_method = "GET"; | 264 redirect_info.new_method = "GET"; |
| 259 redirect_info.new_url = kUrl2; | 265 redirect_info.new_url = kUrl2; |
| 260 redirect_info.new_first_party_for_cookies = kUrl2; | 266 redirect_info.new_first_party_for_cookies = kUrl2; |
| 261 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 267 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 262 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( | 268 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( |
| 263 redirect_info, response); | 269 redirect_info, response); |
| 264 | 270 |
| 265 // The redirect should have been followed. | 271 // The redirect should have been followed. |
| 266 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); | 272 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); |
| 273 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
|
Charlie Reis
2014/12/04 01:11:30
Why is there no speculative RFH after it redirects
carlosk
2014/12/09 07:55:41
Indeed that is a task for later on. The idea is to
Charlie Reis
2014/12/10 22:37:44
Later is fine. Worth noting that we wouldn't get
carlosk
2014/12/16 01:53:47
So if I understand correctly when server redirects
Charlie Reis
2015/01/12 23:30:51
[Just following up on an old thread. This probabl
carlosk
2015/01/13 15:54:12
Understood. To confirm: the server redirects are "
Charlie Reis
2015/01/13 18:48:21
Invisible to RFHM and the UI thread, correct. The
carlosk
2015/01/14 10:09:46
Acknowledged.
| |
| 267 | 274 |
| 268 // Then it commits. | 275 // Then it commits. |
| 269 response = new ResourceResponse; | 276 response = new ResourceResponse; |
| 270 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( | 277 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
| 271 response, MakeEmptyStream()); | 278 response, MakeEmptyStream()); |
| 272 RenderFrameHostImpl* pending_rfh = | 279 RenderFrameHostImpl* final_rfh = main_test_rfh(); |
| 273 node->render_manager()->pending_frame_host(); | 280 ASSERT_TRUE(final_rfh); |
| 274 ASSERT_TRUE(pending_rfh); | 281 EXPECT_NE(final_rfh, rfh); |
| 275 EXPECT_NE(pending_rfh, rfh); | 282 EXPECT_TRUE(final_rfh->IsRenderFrameLive()); |
| 276 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); | 283 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive()); |
| 277 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); | 284 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); |
| 278 } | 285 } |
| 279 | 286 |
| 280 // PlzNavigate: Test that a navigation is cancelled if another request has been | 287 // PlzNavigate: Test that a navigation is canceled if another request has been |
| 281 // issued in the meantime. | 288 // issued in the meantime. Also confirms that the speculative renderer is |
| 289 // correctly updated in the process. | |
| 282 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { | 290 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { |
| 283 const GURL kUrl0("http://www.wikipedia.org/"); | 291 const GURL kUrl0("http://www.wikipedia.org/"); |
| 284 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); | 292 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); |
| 285 const GURL kUrl1("http://www.chromium.org/"); | 293 const GURL kUrl1("http://www.chromium.org/"); |
| 286 const GURL kUrl2("http://www.google.com/"); | 294 const GURL kUrl2("http://www.google.com/"); |
| 287 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); | 295 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); |
| 288 | 296 |
| 289 // Initialization. | 297 // Initialization. |
| 290 contents()->NavigateAndCommit(kUrl0); | 298 contents()->NavigateAndCommit(kUrl0); |
| 291 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 299 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 300 RenderFrameHostManager* rfhm = node->render_manager(); | |
| 292 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 301 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| 293 | 302 |
| 294 // Request navigation to the 1st URL. | 303 // Request navigation to the 1st URL. |
| 295 SendRequestNavigation(node, kUrl1); | 304 SendRequestNavigation(node, kUrl1); |
| 296 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); | 305 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| 297 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); | 306 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); |
| 298 ASSERT_TRUE(request1); | 307 ASSERT_TRUE(request1); |
| 299 EXPECT_EQ(kUrl1, request1->common_params().url); | 308 EXPECT_EQ(kUrl1, request1->common_params().url); |
| 300 base::WeakPtr<TestNavigationURLLoader> loader1 = | 309 base::WeakPtr<TestNavigationURLLoader> loader1 = |
| 301 GetLoaderForNavigationRequest(request1)->AsWeakPtr(); | 310 GetLoaderForNavigationRequest(request1)->AsWeakPtr(); |
| 302 | 311 |
| 312 // Confirms a speculative RFH was created | |
|
Charlie Reis
2014/12/04 01:11:30
nit: Please end sentences with a period, here and
carlosk
2014/12/09 07:55:41
Done.
| |
| 313 ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 314 int32 first_site_id = | |
|
Charlie Reis
2014/12/04 01:11:30
nit: site_instance_id1 and site_instance_id2 would
carlosk
2014/12/09 07:55:41
Done.
| |
| 315 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId(); | |
|
Charlie Reis
2014/12/04 01:11:30
Let's also verify that GetSiteURL() is kUrl1_site
carlosk
2014/12/09 07:55:41
Done.
| |
| 316 | |
| 303 // Request navigation to the 2nd URL; the NavigationRequest must have been | 317 // Request navigation to the 2nd URL; the NavigationRequest must have been |
| 304 // replaced by a new one with a different URL. | 318 // replaced by a new one with a different URL. |
| 305 SendRequestNavigation(node, kUrl2); | 319 SendRequestNavigation(node, kUrl2); |
| 306 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 320 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| 307 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); | 321 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); |
| 308 ASSERT_TRUE(request2); | 322 ASSERT_TRUE(request2); |
| 309 EXPECT_EQ(kUrl2, request2->common_params().url); | 323 EXPECT_EQ(kUrl2, request2->common_params().url); |
| 310 | 324 |
| 311 // Confirm that the first loader got destroyed. | 325 // Confirm that the first loader got destroyed. |
| 312 EXPECT_FALSE(loader1); | 326 EXPECT_FALSE(loader1); |
| 313 | 327 |
| 328 // Confirms that a new speculative RFH was created | |
| 329 ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 330 int32 second_site_id = | |
| 331 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId(); | |
| 332 EXPECT_NE(first_site_id, second_site_id); | |
| 333 | |
| 314 // Confirm that the commit corresponds to the new request. | 334 // Confirm that the commit corresponds to the new request. |
| 315 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 335 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 316 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( | 336 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( |
| 317 response, MakeEmptyStream()); | 337 response, MakeEmptyStream()); |
| 318 RenderFrameHostImpl* pending_rfh = | 338 ASSERT_TRUE(main_test_rfh()); |
| 319 node->render_manager()->pending_frame_host(); | 339 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| 320 ASSERT_TRUE(pending_rfh); | 340 |
| 321 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); | 341 // Confirms that the committed RFH is the new speculative one |
| 342 EXPECT_EQ(second_site_id, main_test_rfh()->GetSiteInstance()->GetId()); | |
| 322 } | 343 } |
| 323 | 344 |
| 324 // PlzNavigate: Test that a reload navigation is properly signaled to the | 345 // PlzNavigate: Test that a reload navigation is properly signaled to the |
| 325 // renderer when the navigation can commit. | 346 // renderer when the navigation can commit. Speculative renderers should not be |
| 347 // created at any step. | |
| 326 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { | 348 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { |
| 327 const GURL kUrl("http://www.google.com/"); | 349 const GURL kUrl("http://www.google.com/"); |
| 328 contents()->NavigateAndCommit(kUrl); | 350 contents()->NavigateAndCommit(kUrl); |
| 329 | 351 |
| 330 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 352 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 353 RenderFrameHostManager* rfhm = node->render_manager(); | |
| 331 SendRequestNavigationWithParameters( | 354 SendRequestNavigationWithParameters( |
| 332 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, | 355 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, |
| 333 NavigationController::RELOAD); | 356 NavigationController::RELOAD); |
| 334 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | 357 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
| 335 // A NavigationRequest should have been generated. | 358 // A NavigationRequest should have been generated. |
| 336 NavigationRequest* main_request = | 359 NavigationRequest* main_request = |
| 337 GetNavigationRequestForFrameTreeNode(node); | 360 GetNavigationRequestForFrameTreeNode(node); |
| 338 ASSERT_TRUE(main_request != NULL); | 361 ASSERT_TRUE(main_request != NULL); |
| 339 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, | 362 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, |
| 340 main_request->common_params().navigation_type); | 363 main_request->common_params().navigation_type); |
| 364 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 365 | |
| 341 int page_id = contents()->GetMaxPageIDForSiteInstance( | 366 int page_id = contents()->GetMaxPageIDForSiteInstance( |
| 342 main_test_rfh()->GetSiteInstance()) + 1; | 367 main_test_rfh()->GetSiteInstance()) + 1; |
| 343 main_test_rfh()->SendNavigate(page_id, kUrl); | 368 main_test_rfh()->SendNavigate(page_id, kUrl); |
| 369 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 344 | 370 |
| 345 // Now do a shift+reload. | 371 // Now do a shift+reload. |
| 346 SendRequestNavigationWithParameters( | 372 SendRequestNavigationWithParameters( |
| 347 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, | 373 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, |
| 348 NavigationController::RELOAD_IGNORING_CACHE); | 374 NavigationController::RELOAD_IGNORING_CACHE); |
| 349 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | 375 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
| 350 // A NavigationRequest should have been generated. | 376 // A NavigationRequest should have been generated. |
| 351 main_request = GetNavigationRequestForFrameTreeNode(node); | 377 main_request = GetNavigationRequestForFrameTreeNode(node); |
| 352 ASSERT_TRUE(main_request != NULL); | 378 ASSERT_TRUE(main_request != NULL); |
| 353 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, | 379 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, |
| 354 main_request->common_params().navigation_type); | 380 main_request->common_params().navigation_type); |
| 381 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 382 } | |
| 383 | |
| 384 // PlzNavigate: Confirms that a speculative RenderFrameHost is used when | |
| 385 // navigating from one site to the another. | |
| 386 TEST_F(NavigatorTestWithBrowserSideNavigation, | |
| 387 SpeculativeRendererWorksBaseCase) { | |
| 388 // Navigate to an initial site. | |
| 389 const GURL kUrlInit("http://wikipedia.org/"); | |
| 390 contents()->NavigateAndCommit(kUrlInit); | |
| 391 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | |
| 392 RenderFrameHostManager* rfhm = node->render_manager(); | |
| 393 ASSERT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 394 | |
| 395 // Begin navigating to another site. | |
| 396 const GURL kUrl("http://google.com/"); | |
| 397 SendRequestNavigation(node, kUrl); | |
| 398 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | |
| 399 ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 400 EXPECT_NE(GetSpeculativeRenderFrameHost(rfhm), main_test_rfh()); | |
| 401 EXPECT_EQ( | |
| 402 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetSiteURL(), | |
|
Charlie Reis
2014/12/04 01:11:30
nit: Switch argument order. (EXPECT_EQ(expected,
carlosk
2014/12/09 07:55:40
Done.
| |
| 403 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl)); | |
| 404 EXPECT_TRUE( | |
| 405 GetSpeculativeRenderFrameHost(rfhm)->GetProcess()->HasConnection()); | |
|
Charlie Reis
2014/12/04 01:11:30
We're in a unit test (with MockRenderProcessHosts)
clamy
2014/12/05 17:16:19
This could be replaced by a call to RFH::IsRenderF
carlosk
2014/12/09 07:55:41
Acknowledged and done.
| |
| 406 int32 site_id = | |
|
Charlie Reis
2014/12/04 01:11:30
Same nit as above.
carlosk
2014/12/09 07:55:41
Done.
| |
| 407 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId(); | |
| 408 | |
| 409 // Commit. | |
|
Charlie Reis
2014/12/04 01:11:30
I'm still finding it very confusing to call this "
carlosk
2014/12/09 07:55:40
It seemed to me that "commit" was the usually acce
| |
| 410 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
| 411 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node)) | |
| 412 ->CallOnResponseStarted(response, MakeEmptyStream()); | |
| 413 EXPECT_EQ(site_id, main_test_rfh()->GetSiteInstance()->GetId()); | |
| 414 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 415 | |
| 416 // And just for completeness invoke OnDidCommitProvisionalLoad which | |
| 417 // shouldn't change anything in RFHM. | |
| 418 FrameHostMsg_DidCommitProvisionalLoad_Params params; | |
| 419 params.page_id = 1; | |
| 420 params.url = kUrl; | |
| 421 params.was_within_same_page = false; | |
| 422 params.is_post = false; | |
| 423 params.post_id = -1; | |
| 424 params.page_state = PageState::CreateForTesting(kUrl, false, 0, 0); | |
| 425 main_test_rfh()->SendNavigateWithParams(¶ms); | |
| 426 EXPECT_EQ(site_id, main_test_rfh()->GetSiteInstance()->GetId()); | |
| 427 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 428 } | |
| 429 | |
| 430 // PlzNavigate: Confirms that a speculative RenderFrameHost is thrown away when | |
| 431 // the final URL's site differ from the initial one due to redirects. | |
|
Charlie Reis
2014/12/04 01:11:30
nit: differs
carlosk
2014/12/09 07:55:41
Done.
| |
| 432 TEST_F(NavigatorTestWithBrowserSideNavigation, | |
| 433 SpeculativeRendererDiscardedAfterRedirectToAnotherSite) { | |
| 434 // Navigate to an initial site. | |
| 435 const GURL kUrlInit("http://wikipedia.org/"); | |
| 436 contents()->NavigateAndCommit(kUrlInit); | |
| 437 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | |
| 438 RenderFrameHostManager* rfhm = node->render_manager(); | |
| 439 ASSERT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 440 | |
| 441 // Begin navigating to another site. | |
| 442 const GURL kUrl("http://google.com/"); | |
| 443 SendRequestNavigation(node, kUrl); | |
| 444 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | |
| 445 int32 site_id = | |
| 446 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId(); | |
| 447 ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 448 EXPECT_NE(GetSpeculativeRenderFrameHost(rfhm), main_test_rfh()); | |
| 449 EXPECT_TRUE( | |
| 450 GetSpeculativeRenderFrameHost(rfhm)->GetProcess()->HasConnection()); | |
|
Charlie Reis
2014/12/04 01:11:30
Same as above.
carlosk
2014/12/09 07:55:41
Done.
| |
| 451 EXPECT_EQ( | |
| 452 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetSiteURL(), | |
| 453 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl)); | |
| 454 | |
| 455 // It then redirects to yet another site. | |
| 456 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | |
| 457 ASSERT_TRUE(main_request); | |
| 458 const GURL kUrlRedirect("https://www.google.com/"); | |
| 459 net::RedirectInfo redirect_info; | |
| 460 redirect_info.status_code = 302; | |
| 461 redirect_info.new_method = "GET"; | |
| 462 redirect_info.new_url = kUrlRedirect; | |
| 463 redirect_info.new_first_party_for_cookies = kUrlRedirect; | |
| 464 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
| 465 GetLoaderForNavigationRequest(main_request) | |
| 466 ->CallOnRequestRedirected(redirect_info, response); | |
| 467 ASSERT_TRUE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 468 EXPECT_EQ(site_id, | |
|
Charlie Reis
2014/12/04 01:11:30
The test says the redirect is expected to discard
carlosk
2014/12/09 07:55:41
As we're not *yet* monitoring redirects the specul
| |
| 469 GetSpeculativeRenderFrameHost(rfhm)->GetSiteInstance()->GetId()); | |
| 470 | |
| 471 // Commit. | |
|
Charlie Reis
2014/12/04 01:11:30
See comment in previous test.
carlosk
2014/12/09 07:55:41
Done.
| |
| 472 response = new ResourceResponse; | |
| 473 GetLoaderForNavigationRequest(main_request) | |
| 474 ->CallOnResponseStarted(response, MakeEmptyStream()); | |
| 475 EXPECT_NE(site_id, main_test_rfh()->GetSiteInstance()->GetId()); | |
| 476 EXPECT_EQ(main_test_rfh()->GetSiteInstance()->GetSiteURL(), | |
| 477 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlRedirect)); | |
| 478 EXPECT_FALSE(GetSpeculativeRenderFrameHost(rfhm)); | |
| 355 } | 479 } |
| 356 | 480 |
| 357 } // namespace content | 481 } // namespace content |
| OLD | NEW |