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

Side by Side Diff: content/browser/frame_host/navigator_impl_unittest.cc

Issue 914223002: PlzNavigate: Updated navigation cancel policy for renderer-initiated requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More testing. Created 5 years, 10 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/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 // PlzNavigate: Test a complete renderer-initiated same-site navigation. 155 // PlzNavigate: Test a complete renderer-initiated same-site navigation.
156 TEST_F(NavigatorTestWithBrowserSideNavigation, 156 TEST_F(NavigatorTestWithBrowserSideNavigation,
157 SimpleRendererInitiatedNavigation) { 157 SimpleRendererInitiatedNavigation) {
158 const GURL kUrl1("http://www.chromium.org/"); 158 const GURL kUrl1("http://www.chromium.org/");
159 const GURL kUrl2("http://www.chromium.org/Home"); 159 const GURL kUrl2("http://www.chromium.org/Home");
160 160
161 contents()->NavigateAndCommit(kUrl1); 161 contents()->NavigateAndCommit(kUrl1);
162 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); 162 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
163 163
164 // Start a renderer-initiated navigation. 164 // Start a renderer-initiated non-user-initiated navigation.
165 process()->sink().ClearMessages(); 165 process()->sink().ClearMessages();
166 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 166 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
167 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 167 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
168 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node); 168 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
169 ASSERT_TRUE(request); 169 ASSERT_TRUE(request);
170 170
171 // The navigation is immediately started as there's no need to wait for 171 // The navigation is immediately started as there's no need to wait for
172 // beforeUnload to be executed. 172 // beforeUnload to be executed.
173 EXPECT_EQ(NavigationRequest::STARTED, request->state()); 173 EXPECT_EQ(NavigationRequest::STARTED, request->state());
174 EXPECT_FALSE(request->begin_params().has_user_gesture);
174 EXPECT_EQ(kUrl2, request->common_params().url); 175 EXPECT_EQ(kUrl2, request->common_params().url);
175 EXPECT_FALSE(request->browser_initiated()); 176 EXPECT_FALSE(request->browser_initiated());
176 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 177 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
177 178
178 // Have the current RenderFrameHost commit the navigation. 179 // Have the current RenderFrameHost commit the navigation.
179 scoped_refptr<ResourceResponse> response(new ResourceResponse); 180 scoped_refptr<ResourceResponse> response(new ResourceResponse);
180 GetLoaderForNavigationRequest(request) 181 GetLoaderForNavigationRequest(request)
181 ->CallOnResponseStarted(response, MakeEmptyStream()); 182 ->CallOnResponseStarted(response, MakeEmptyStream());
182 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); 183 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh()));
183 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); 184 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 const GURL kUrl1("http://www.chromium.org/"); 369 const GURL kUrl1("http://www.chromium.org/");
369 const GURL kUrl2("http://www.google.com/"); 370 const GURL kUrl2("http://www.google.com/");
370 371
371 contents()->NavigateAndCommit(kUrl1); 372 contents()->NavigateAndCommit(kUrl1);
372 RenderFrameHostImpl* initial_rfh = main_test_rfh(); 373 RenderFrameHostImpl* initial_rfh = main_test_rfh();
373 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 374 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
374 375
375 // Navigate to a different site. 376 // Navigate to a different site.
376 process()->sink().ClearMessages(); 377 process()->sink().ClearMessages();
377 RequestNavigation(node, kUrl2); 378 RequestNavigation(node, kUrl2);
378 main_test_rfh()->SendBeforeUnloadACK(true);
379 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 379 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
380 ASSERT_TRUE(main_request); 380 ASSERT_TRUE(main_request);
381 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
382
383 // Receive the beforeUnload ACK.
384 main_test_rfh()->SendBeforeUnloadACK(true);
381 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); 385 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
382 386
383 scoped_refptr<ResourceResponse> response(new ResourceResponse); 387 scoped_refptr<ResourceResponse> response(new ResourceResponse);
384 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 388 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
385 response, MakeEmptyStream()); 389 response, MakeEmptyStream());
386 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 390 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
387 ASSERT_TRUE(speculative_rfh); 391 ASSERT_TRUE(speculative_rfh);
388 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh)); 392 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
389 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 393 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
390 394
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // Request navigation to the 1st URL. 472 // Request navigation to the 1st URL.
469 process()->sink().ClearMessages(); 473 process()->sink().ClearMessages();
470 RequestNavigation(node, kUrl1); 474 RequestNavigation(node, kUrl1);
471 main_test_rfh()->SendBeforeUnloadACK(true); 475 main_test_rfh()->SendBeforeUnloadACK(true);
472 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); 476 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
473 ASSERT_TRUE(request1); 477 ASSERT_TRUE(request1);
474 EXPECT_EQ(kUrl1, request1->common_params().url); 478 EXPECT_EQ(kUrl1, request1->common_params().url);
475 EXPECT_TRUE(request1->browser_initiated()); 479 EXPECT_TRUE(request1->browser_initiated());
476 base::WeakPtr<TestNavigationURLLoader> loader1 = 480 base::WeakPtr<TestNavigationURLLoader> loader1 =
477 GetLoaderForNavigationRequest(request1)->AsWeakPtr(); 481 GetLoaderForNavigationRequest(request1)->AsWeakPtr();
482 EXPECT_TRUE(loader1);
478 483
479 // Confirm a speculative RFH was created. 484 // Confirm a speculative RFH was created.
480 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 485 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
481 ASSERT_TRUE(speculative_rfh); 486 ASSERT_TRUE(speculative_rfh);
482 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId(); 487 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId();
483 EXPECT_EQ(kUrl1_site, speculative_rfh->GetSiteInstance()->GetSiteURL()); 488 EXPECT_EQ(kUrl1_site, speculative_rfh->GetSiteInstance()->GetSiteURL());
484 489
485 // Request navigation to the 2nd URL; the NavigationRequest must have been 490 // Request navigation to the 2nd URL; the NavigationRequest must have been
486 // replaced by a new one with a different URL. 491 // replaced by a new one with a different URL.
487 RequestNavigation(node, kUrl2); 492 RequestNavigation(node, kUrl2);
(...skipping 24 matching lines...) Expand all
512 517
513 // Confirm that the commit corresponds to the new request. 518 // Confirm that the commit corresponds to the new request.
514 ASSERT_TRUE(main_test_rfh()); 519 ASSERT_TRUE(main_test_rfh());
515 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 520 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
516 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); 521 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL());
517 522
518 // Confirm that the committed RFH is the latest speculative one. 523 // Confirm that the committed RFH is the latest speculative one.
519 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId()); 524 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId());
520 } 525 }
521 526
527 // PlzNavigate: Test that a navigation is canceled if another renderer-initiated
528 // user-initiated request has been issued in the meantime.
529 TEST_F(NavigatorTestWithBrowserSideNavigation,
530 RendererUserInitiatedNavigationCancel) {
531 const GURL kUrl0("http://www.wikipedia.org/");
532 const GURL kUrl1("http://www.chromium.org/");
533 const GURL kUrl2("http://www.google.com/");
534
535 // Initialization.
536 contents()->NavigateAndCommit(kUrl0);
537 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
538
539 // Start a browser-initiated navigation to the 1st URL and receive its
540 // beforeUnload ACK.
541 process()->sink().ClearMessages();
542 RequestNavigation(node, kUrl1);
543 main_test_rfh()->SendBeforeUnloadACK(true);
544 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
545 ASSERT_TRUE(request1);
546 EXPECT_EQ(kUrl1, request1->common_params().url);
547 EXPECT_TRUE(request1->browser_initiated());
548 base::WeakPtr<TestNavigationURLLoader> loader1 =
549 GetLoaderForNavigationRequest(request1)->AsWeakPtr();
550 EXPECT_TRUE(loader1);
551
552 // Confirm a speculative RFH was created.
553 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
554 ASSERT_TRUE(speculative_rfh);
555 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId();
556
557 // Now receive a renderer-initiated user-initiated request. It should replace
558 // the current NavigationRequest.
559 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, true);
560 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
561 ASSERT_TRUE(request2);
562 EXPECT_EQ(kUrl2, request2->common_params().url);
563 EXPECT_FALSE(request2->browser_initiated());
564 EXPECT_TRUE(request2->begin_params().has_user_gesture);
565
566 // Confirm that the first loader got destroyed.
567 EXPECT_FALSE(loader1);
568
569 // Confirm that a new speculative RFH was created.
570 speculative_rfh = GetSpeculativeRenderFrameHost(node);
571 ASSERT_TRUE(speculative_rfh);
572 int32 site_instance_id_2 = speculative_rfh->GetSiteInstance()->GetId();
573 EXPECT_NE(site_instance_id_1, site_instance_id_2);
574
575 // Request the RenderFrameHost to commit.
clamy 2015/02/13 14:56:35 nit: I would rephrase that as "Have the RenderFram
carlosk 2015/02/13 15:57:13 Done, here and everywhere else.
576 scoped_refptr<ResourceResponse> response(new ResourceResponse);
577 GetLoaderForNavigationRequest(request2)
578 ->CallOnResponseStarted(response, MakeEmptyStream());
579 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
580 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
581
582 // Commit the navigation.
583 speculative_rfh->SendNavigate(0, kUrl2);
584
585 // Confirm that the commit corresponds to the new request.
586 ASSERT_TRUE(main_test_rfh());
587 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL());
588
589 // Confirm that the committed RFH is the latest speculative one.
clamy 2015/02/13 14:56:35 nit: I would rephrase as "Confirm that the RFH tha
carlosk 2015/02/13 15:57:13 Done, here and everywhere else.
590 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId());
591 }
592
593 // PlzNavigate: Test that a renderer-initiated user-initiated navigation is NOT
594 // canceled if a renderer-initiated non-user-initiated request is issued in the
595 // meantime.
596 TEST_F(NavigatorTestWithBrowserSideNavigation,
597 RendererNonUserInitiatedNavigationDoesntCancelRendererUserInitiated) {
598 const GURL kUrl0("http://www.wikipedia.org/");
599 const GURL kUrl1("http://www.chromium.org/");
600 const GURL kUrl2("http://www.google.com/");
601
602 // Initialization.
603 contents()->NavigateAndCommit(kUrl0);
604 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
605
606 // Start a renderer-initiated user-initiated navigation to the 1st URL.
607 process()->sink().ClearMessages();
608 main_test_rfh()->SendBeginNavigationWithURL(kUrl1, true);
609 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
610 ASSERT_TRUE(request1);
611 EXPECT_EQ(kUrl1, request1->common_params().url);
612 EXPECT_FALSE(request1->browser_initiated());
613 EXPECT_TRUE(request1->begin_params().has_user_gesture);
614 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
615
616 // Now receive a renderer-initiated non-user-initiated request. Nothing should
617 // change.
618 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
619 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
620 ASSERT_TRUE(request2);
621 EXPECT_EQ(request1, request2);
622 EXPECT_EQ(kUrl1, request2->common_params().url);
623 EXPECT_FALSE(request2->browser_initiated());
624 EXPECT_TRUE(request2->begin_params().has_user_gesture);
625 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
626 ASSERT_TRUE(speculative_rfh);
627
628 // Request the RenderFrameHost to commit.
629 scoped_refptr<ResourceResponse> response(new ResourceResponse);
630 GetLoaderForNavigationRequest(request2)
631 ->CallOnResponseStarted(response, MakeEmptyStream());
632 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
633 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
634
635 // Commit the navigation.
636 speculative_rfh->SendNavigate(0, kUrl1);
637 EXPECT_EQ(kUrl1, contents()->GetLastCommittedURL());
638 }
639
640 // PlzNavigate: Test that a browser-initiated navigation is NOT canceled if a
641 // renderer-initiated non-user-initiated request is issued in the meantime.
642 TEST_F(NavigatorTestWithBrowserSideNavigation,
643 RendererNonUserInitiatedNavigationDoesntCancelBrowserInitiated) {
644 const GURL kUrl0("http://www.wikipedia.org/");
645 const GURL kUrl1("http://www.chromium.org/");
646 const GURL kUrl2("http://www.google.com/");
647
648 // Initialization.
649 contents()->NavigateAndCommit(kUrl0);
650 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
651
652 // Start a browser-initiated navigation to the 1st URL.
653 process()->sink().ClearMessages();
654 RequestNavigation(node, kUrl1);
655 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
656 ASSERT_TRUE(request1);
657 EXPECT_EQ(kUrl1, request1->common_params().url);
658 EXPECT_TRUE(request1->browser_initiated());
659 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
660
661 // Now receive a renderer-initiated non-user-initiated request. Nothing should
662 // change.
663 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
664 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
665 ASSERT_TRUE(request2);
666 EXPECT_EQ(request1, request2);
667 EXPECT_EQ(kUrl1, request2->common_params().url);
668 EXPECT_TRUE(request2->browser_initiated());
669 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
670
671 // Now receive the beforeUnload ACK from the still ongoing navigation.
672 main_test_rfh()->SendBeforeUnloadACK(true);
673 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
674 ASSERT_TRUE(speculative_rfh);
675
676 // Request the RenderFrameHost to commit.
677 scoped_refptr<ResourceResponse> response(new ResourceResponse);
678 GetLoaderForNavigationRequest(request2)
679 ->CallOnResponseStarted(response, MakeEmptyStream());
680 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
681 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
682
683 // Commit the navigation.
684 speculative_rfh->SendNavigate(0, kUrl1);
685 EXPECT_EQ(kUrl1, contents()->GetLastCommittedURL());
686 }
687
688 // PlzNavigate: Test that a renderer-initiated non-user-initiated navigation is
689 // canceled if a another similar request is issued in the meantime.
690 TEST_F(NavigatorTestWithBrowserSideNavigation,
691 RendererNonUserInitiatedNavigationCancelSimilarNavigation) {
692 const GURL kUrl0("http://www.wikipedia.org/");
693 const GURL kUrl1("http://www.chromium.org/");
694 const GURL kUrl2("http://www.google.com/");
695
696 // Initialization.
697 contents()->NavigateAndCommit(kUrl0);
698 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
699
700 // Start a renderer-initiated non-user-initiated navigation to the 1st URL.
701 process()->sink().ClearMessages();
702 main_test_rfh()->SendBeginNavigationWithURL(kUrl1, false);
703 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
704 ASSERT_TRUE(request1);
705 EXPECT_EQ(kUrl1, request1->common_params().url);
706 EXPECT_FALSE(request1->browser_initiated());
707 EXPECT_FALSE(request1->begin_params().has_user_gesture);
708 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
709
710 // Now receive a 2nd similar request that should replace the current one.
711 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
712 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
713 EXPECT_EQ(kUrl2, request2->common_params().url);
714 EXPECT_FALSE(request2->browser_initiated());
715 EXPECT_FALSE(request2->begin_params().has_user_gesture);
716 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
717 ASSERT_TRUE(speculative_rfh);
718
719 // Request the RenderFrameHost to commit.
720 scoped_refptr<ResourceResponse> response(new ResourceResponse);
721 GetLoaderForNavigationRequest(request2)
722 ->CallOnResponseStarted(response, MakeEmptyStream());
723 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
724 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
725
726 // Commit the navigation.
727 speculative_rfh->SendNavigate(0, kUrl2);
728 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL());
729 }
730
522 // PlzNavigate: Test that a reload navigation is properly signaled to the 731 // PlzNavigate: Test that a reload navigation is properly signaled to the
523 // RenderFrame when the navigation can commit. A speculative RenderFrameHost 732 // RenderFrame when the navigation can commit. A speculative RenderFrameHost
524 // should not be created at any step. 733 // should not be created at any step.
525 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { 734 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
526 const GURL kUrl("http://www.google.com/"); 735 const GURL kUrl("http://www.google.com/");
527 contents()->NavigateAndCommit(kUrl); 736 contents()->NavigateAndCommit(kUrl);
528 737
529 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 738 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
530 RequestNavigationWithParameters(node, kUrl, Referrer(), 739 RequestNavigationWithParameters(node, kUrl, Referrer(),
531 ui::PAGE_TRANSITION_LINK, 740 ui::PAGE_TRANSITION_LINK,
(...skipping 28 matching lines...) Expand all
560 SpeculativeRendererWorksBaseCase) { 769 SpeculativeRendererWorksBaseCase) {
561 // Navigate to an initial site. 770 // Navigate to an initial site.
562 const GURL kUrlInit("http://wikipedia.org/"); 771 const GURL kUrlInit("http://wikipedia.org/");
563 contents()->NavigateAndCommit(kUrlInit); 772 contents()->NavigateAndCommit(kUrlInit);
564 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 773 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
565 774
566 // Begin navigating to another site. 775 // Begin navigating to another site.
567 const GURL kUrl("http://google.com/"); 776 const GURL kUrl("http://google.com/");
568 process()->sink().ClearMessages(); 777 process()->sink().ClearMessages();
569 RequestNavigation(node, kUrl); 778 RequestNavigation(node, kUrl);
779 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
780
781 // Receive the beforeUnload ACK.
570 main_test_rfh()->SendBeforeUnloadACK(true); 782 main_test_rfh()->SendBeforeUnloadACK(true);
571 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 783 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
572 ASSERT_TRUE(speculative_rfh); 784 ASSERT_TRUE(speculative_rfh);
573 EXPECT_NE(speculative_rfh, main_test_rfh()); 785 EXPECT_NE(speculative_rfh, main_test_rfh());
574 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), 786 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
575 speculative_rfh->GetSiteInstance()->GetSiteURL()); 787 speculative_rfh->GetSiteInstance()->GetSiteURL());
576 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 788 EXPECT_FALSE(node->render_manager()->pending_frame_host());
577 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId(); 789 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
578 790
579 // Ask Navigator to commit the navigation by simulating a call to 791 // Ask Navigator to commit the navigation by simulating a call to
(...skipping 21 matching lines...) Expand all
601 // Navigate to an initial site. 813 // Navigate to an initial site.
602 const GURL kUrlInit("http://wikipedia.org/"); 814 const GURL kUrlInit("http://wikipedia.org/");
603 contents()->NavigateAndCommit(kUrlInit); 815 contents()->NavigateAndCommit(kUrlInit);
604 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 816 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
605 int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId(); 817 int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId();
606 818
607 // Begin navigating to another site. 819 // Begin navigating to another site.
608 const GURL kUrl("http://google.com/"); 820 const GURL kUrl("http://google.com/");
609 process()->sink().ClearMessages(); 821 process()->sink().ClearMessages();
610 RequestNavigation(node, kUrl); 822 RequestNavigation(node, kUrl);
823 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
824
825 // Receive the beforeUnload ACK.
611 main_test_rfh()->SendBeforeUnloadACK(true); 826 main_test_rfh()->SendBeforeUnloadACK(true);
612 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 827 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
613 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId(); 828 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
614 EXPECT_NE(init_site_instance_id, site_instance_id); 829 EXPECT_NE(init_site_instance_id, site_instance_id);
615 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId()); 830 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
616 ASSERT_TRUE(speculative_rfh); 831 ASSERT_TRUE(speculative_rfh);
617 EXPECT_NE(speculative_rfh, main_test_rfh()); 832 EXPECT_NE(speculative_rfh, main_test_rfh());
618 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), 833 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
619 speculative_rfh->GetSiteInstance()->GetSiteURL()); 834 speculative_rfh->GetSiteInstance()->GetSiteURL());
620 835
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); 906 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
692 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1)); 907 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1));
693 908
694 // Now go back to the initial site so that the swapped out RenderFrameHost 909 // Now go back to the initial site so that the swapped out RenderFrameHost
695 // should be reused. 910 // should be reused.
696 process()->sink().ClearMessages(); 911 process()->sink().ClearMessages();
697 static_cast<MockRenderProcessHost*>(rfh1->GetProcess()) 912 static_cast<MockRenderProcessHost*>(rfh1->GetProcess())
698 ->sink() 913 ->sink()
699 .ClearMessages(); 914 .ClearMessages();
700 RequestNavigation(node, kUrl1); 915 RequestNavigation(node, kUrl1);
916 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
917
701 main_test_rfh()->SendBeforeUnloadACK(true); 918 main_test_rfh()->SendBeforeUnloadACK(true);
702 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); 919 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
703 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, 920 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT,
704 GetSpeculativeRenderFrameHost(node)->rfh_state()); 921 GetSpeculativeRenderFrameHost(node)->rfh_state());
705 922
706 scoped_refptr<ResourceResponse> response(new ResourceResponse); 923 scoped_refptr<ResourceResponse> response(new ResourceResponse);
707 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node)) 924 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
708 ->CallOnResponseStarted(response, MakeEmptyStream()); 925 ->CallOnResponseStarted(response, MakeEmptyStream());
709 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); 926 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
710 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, 927 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT,
711 GetSpeculativeRenderFrameHost(node)->rfh_state()); 928 GetSpeculativeRenderFrameHost(node)->rfh_state());
712 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1)); 929 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1));
713 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 930 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
714 931
715 rfh1->SendNavigate(1, kUrl1); 932 rfh1->SendNavigate(1, kUrl1);
716 EXPECT_EQ(rfh1, main_test_rfh()); 933 EXPECT_EQ(rfh1, main_test_rfh());
717 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 934 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
718 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1)); 935 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
719 } 936 }
720 937
721 } // namespace content 938 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698