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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/guid.h" | 6 #include "base/guid.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 164 |
165 private: | 165 private: |
166 scoped_ptr<StreamRegistry> stream_registry_; | 166 scoped_ptr<StreamRegistry> stream_registry_; |
167 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_; | 167 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_; |
168 }; | 168 }; |
169 | 169 |
170 // PlzNavigate: Test that a proper NavigationRequest is created by | 170 // PlzNavigate: Test that a proper NavigationRequest is created by |
171 // BeginNavigation. | 171 // BeginNavigation. |
172 // Note that all PlzNavigate methods on the browser side require the use of the | 172 // Note that all PlzNavigate methods on the browser side require the use of the |
173 // flag kEnableBrowserSideNavigation. | 173 // flag kEnableBrowserSideNavigation. |
174 // TODO(carlosk): Will fix this ASAP but it currently crashes with my latest | |
175 // changes from speculative renderer creation. | |
174 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { | 176 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { |
175 const GURL kUrl1("http://www.google.com/"); | 177 const GURL kUrl1("http://www.google.com/"); |
176 const GURL kUrl2("http://www.chromium.org/"); | 178 const GURL kUrl2("http://www.chromium.org/"); |
177 const GURL kUrl3("http://www.gmail.com/"); | 179 const GURL kUrl3("http://www.gmail.com/"); |
178 | 180 |
179 contents()->NavigateAndCommit(kUrl1); | 181 contents()->NavigateAndCommit(kUrl1); |
180 | 182 |
181 EnableBrowserSideNavigation(); | 183 EnableBrowserSideNavigation(); |
182 | 184 |
183 // Add a subframe. | 185 // Add a subframe. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( | 296 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
295 response, MakeEmptyStream()); | 297 response, MakeEmptyStream()); |
296 | 298 |
297 // There should be no pending RenderFrameHost; the navigation was aborted. | 299 // There should be no pending RenderFrameHost; the navigation was aborted. |
298 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 300 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
299 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 301 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
300 } | 302 } |
301 | 303 |
302 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | 304 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross |
303 // site navigation. | 305 // site navigation. |
306 // TODO(carlosk): Will fix this ASAP but it currently fails because it relies on | |
307 // the pending_* members of RFHM which are not necessarily used by PlzNavigate. | |
clamy
2014/11/19 15:03:29
In the new version, we should just check that the
carlosk
2014/11/19 17:24:28
Acknowledged.
carlosk
2014/11/21 14:36:33
I did that and fixed all but one of the failing te
nasko
2014/11/25 00:19:10
Subframes will never navigate cross-process withou
carlosk
2014/11/28 13:08:17
Done.
| |
304 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { | 308 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { |
305 const GURL kUrl1("http://www.chromium.org/"); | 309 const GURL kUrl1("http://www.chromium.org/"); |
306 const GURL kUrl2("http://www.google.com/"); | 310 const GURL kUrl2("http://www.google.com/"); |
307 | 311 |
308 contents()->NavigateAndCommit(kUrl1); | 312 contents()->NavigateAndCommit(kUrl1); |
309 RenderFrameHostImpl* rfh = main_test_rfh(); | 313 RenderFrameHostImpl* rfh = main_test_rfh(); |
310 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); | 314 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
311 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 315 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
312 | 316 |
313 EnableBrowserSideNavigation(); | 317 EnableBrowserSideNavigation(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 RenderFrameHostImpl* pending_rfh = | 371 RenderFrameHostImpl* pending_rfh = |
368 node->render_manager()->pending_frame_host(); | 372 node->render_manager()->pending_frame_host(); |
369 ASSERT_TRUE(pending_rfh); | 373 ASSERT_TRUE(pending_rfh); |
370 EXPECT_NE(pending_rfh, rfh); | 374 EXPECT_NE(pending_rfh, rfh); |
371 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); | 375 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); |
372 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); | 376 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); |
373 } | 377 } |
374 | 378 |
375 // PlzNavigate: Test that a navigation is cancelled if another request has been | 379 // PlzNavigate: Test that a navigation is cancelled if another request has been |
376 // issued in the meantime. | 380 // issued in the meantime. |
381 // TODO(carlosk): Will fix this ASAP but it currently fails because it relies on | |
382 // the pending_* members of RFHM which are not necessarily used by PlzNavigate. | |
377 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) { | 383 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) { |
378 const GURL kUrl0("http://www.wikipedia.org/"); | 384 const GURL kUrl0("http://www.wikipedia.org/"); |
379 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); | 385 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); |
380 const GURL kUrl1("http://www.chromium.org/"); | 386 const GURL kUrl1("http://www.chromium.org/"); |
381 const GURL kUrl2("http://www.google.com/"); | 387 const GURL kUrl2("http://www.google.com/"); |
382 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); | 388 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); |
383 | 389 |
384 // Initialization. | 390 // Initialization. |
385 contents()->NavigateAndCommit(kUrl0); | 391 contents()->NavigateAndCommit(kUrl0); |
386 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 392 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, | 476 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, |
471 NavigationController::RELOAD_IGNORING_CACHE); | 477 NavigationController::RELOAD_IGNORING_CACHE); |
472 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | 478 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
473 // A NavigationRequest should have been generated. | 479 // A NavigationRequest should have been generated. |
474 main_request = GetNavigationRequestForFrameTreeNode(node); | 480 main_request = GetNavigationRequestForFrameTreeNode(node); |
475 ASSERT_TRUE(main_request != NULL); | 481 ASSERT_TRUE(main_request != NULL); |
476 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, | 482 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, |
477 main_request->common_params().navigation_type); | 483 main_request->common_params().navigation_type); |
478 } | 484 } |
479 | 485 |
486 // PlzNavigate: Confirms that a speculative renderer process is used when | |
487 // navigation is committed to the same SiteInstance as the one for the initial | |
488 // URL. | |
489 // TODO(carlosk): move this test to render_frame_host_manager_unittest.cc once | |
490 // the proper test fixtures are made available (TestNavigationURLLoader). | |
491 TEST_F(NavigatorTest, BrowserSideNavigationSpeculativeRendererWorksSimple) { | |
492 const GURL kUrlInit("http://wikipedia.org/"); | |
493 contents()->NavigateAndCommit(kUrlInit); | |
494 | |
495 EnableBrowserSideNavigation(); | |
496 TestRenderFrameHost* mrfh = main_test_rfh(); | |
497 FrameTreeNode* node = mrfh->frame_tree_node(); | |
498 RenderFrameHostManager* rfhm = node->render_manager(); | |
499 TestRenderFrameHost* srfh = | |
500 static_cast<TestRenderFrameHost*>(rfhm->speculative_render_frame_host()); | |
nasko
2014/11/19 01:00:23
Why do you need to static cast? You aren't calling
carlosk
2014/11/19 17:24:28
I added the cast when I was figuring out how to in
carlosk
2014/11/21 14:36:33
Done.
| |
501 ASSERT_FALSE(srfh); | |
502 | |
503 const GURL kUrlNav("http://google.com/"); | |
504 SendRequestNavigation(node, kUrlNav); | |
505 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrlNav); | |
506 srfh = | |
507 static_cast<TestRenderFrameHost*>(rfhm->speculative_render_frame_host()); | |
508 ASSERT_TRUE(srfh); | |
509 EXPECT_NE(srfh, mrfh); | |
510 EXPECT_TRUE(srfh->GetProcess()->HasConnection()); | |
511 | |
512 const GURL kUrlFinal("http://www.google.com/about/"); | |
513 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | |
514 CommonNavigationParams& common_params = main_request->common_params(); | |
515 common_params.url = kUrlFinal; | |
516 common_params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | |
nasko
2014/11/19 01:00:23
In order for client redirect to occur, you need to
clamy
2014/11/19 15:03:29
Unless you are specifically testing a client redir
carlosk
2014/11/19 17:24:28
In this case I was guesstimating that to maintain
nasko
2014/11/19 19:01:29
Why are you even faking it? If you want to test th
carlosk
2014/11/21 14:36:33
Agreed and done. I made this test to test the actu
| |
517 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
518 GetLoaderForNavigationRequest(main_request) | |
519 ->CallOnResponseStarted(response, MakeEmptyStream()); | |
520 EXPECT_EQ(srfh, main_test_rfh()); | |
521 EXPECT_FALSE(rfhm->speculative_render_frame_host()); | |
522 | |
523 // And just for completeness invokes OnDidCommitProvisionalLoad which | |
524 // shouldn't change anything in RFHM. | |
525 FrameHostMsg_DidCommitProvisionalLoad_Params params; | |
526 params.page_id = 1; | |
527 params.url = kUrlFinal; | |
528 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | |
529 params.was_within_same_page = false; | |
530 params.is_post = false; | |
531 params.post_id = -1; | |
532 params.page_state = PageState::CreateForTesting(kUrlFinal, false, 0, 0); | |
533 main_test_rfh()->SendNavigateWithParams(¶ms); | |
534 EXPECT_EQ(srfh, main_test_rfh()); | |
535 EXPECT_FALSE(rfhm->speculative_render_frame_host()); | |
536 } | |
537 | |
480 } // namespace content | 538 } // namespace content |
OLD | NEW |