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/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 29 matching lines...) Expand all Loading... | |
| 40 EnableBrowserSideNavigation(); | 40 EnableBrowserSideNavigation(); |
| 41 RenderViewHostImplTestHarness::SetUp(); | 41 RenderViewHostImplTestHarness::SetUp(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TestNavigationURLLoader* GetLoaderForNavigationRequest( | 44 TestNavigationURLLoader* GetLoaderForNavigationRequest( |
| 45 NavigationRequest* request) const { | 45 NavigationRequest* request) const { |
| 46 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 46 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void RequestNavigation(FrameTreeNode* node, const GURL& url) { | 49 void RequestNavigation(FrameTreeNode* node, const GURL& url) { |
| 50 RequestNavigationWithParameters(node, url, Referrer(), | 50 NavigationEntryImpl* entry = |
| 51 ui::PAGE_TRANSITION_LINK, | 51 NavigationEntryImpl::FromNavigationEntry( |
| 52 NavigationController::CreateNavigationEntry( | |
| 53 url, | |
| 54 Referrer(), | |
| 55 ui::PAGE_TRANSITION_LINK, | |
| 56 false, | |
| 57 std::string(), | |
| 58 controller().GetBrowserContext())); | |
| 59 NavigationControllerImpl& navigation_controller_impl = | |
| 60 static_cast<NavigationControllerImpl&>(controller()); | |
| 61 navigation_controller_impl.SetPendingEntry(entry); | |
| 62 | |
| 63 RequestNavigationWithParameters(entry, node, url, | |
| 52 NavigationController::NO_RELOAD); | 64 NavigationController::NO_RELOAD); |
| 53 } | 65 } |
| 54 | 66 |
| 55 void RequestNavigationWithParameters( | 67 void RequestReloadNavigation( |
| 56 FrameTreeNode* node, | 68 FrameTreeNode* node, |
| 57 const GURL& url, | 69 const GURL& url, |
| 58 const Referrer& referrer, | |
| 59 ui::PageTransition transition_type, | |
| 60 NavigationController::ReloadType reload_type) { | 70 NavigationController::ReloadType reload_type) { |
| 61 scoped_ptr<NavigationEntryImpl> entry( | 71 NavigationControllerImpl& navigation_controller_impl = |
| 62 NavigationEntryImpl::FromNavigationEntry( | 72 static_cast<NavigationControllerImpl&>(controller()); |
| 63 NavigationController::CreateNavigationEntry( | 73 navigation_controller_impl.SetPendingEntryAndIndexForTesting( |
| 64 url, | 74 navigation_controller_impl.GetLastCommittedEntryIndex()); |
| 65 referrer, | 75 NavigationEntryImpl* entry = |
| 66 transition_type, | 76 navigation_controller_impl.GetPendingEntry(); |
| 67 false, | 77 |
| 68 std::string(), | 78 RequestNavigationWithParameters(entry, node, url, reload_type); |
| 69 controller().GetBrowserContext()))); | 79 } |
| 80 | |
| 81 void RequestNavigationWithParameters( | |
| 82 NavigationEntryImpl* entry, | |
| 83 FrameTreeNode* node, | |
| 84 const GURL& url, | |
| 85 NavigationController::ReloadType reload_type) { | |
| 70 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( | 86 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( |
|
Charlie Reis
2015/03/17 22:20:22
The goal of this change is to make sure that |entr
Avi (use Gerrit)
2015/03/17 23:28:16
Done.
| |
| 71 node, *entry, reload_type, base::TimeTicks::Now()); | 87 node, *entry, reload_type, base::TimeTicks::Now()); |
| 72 } | 88 } |
| 73 | 89 |
| 74 NavigationRequest* GetNavigationRequestForFrameTreeNode( | 90 NavigationRequest* GetNavigationRequestForFrameTreeNode( |
| 75 FrameTreeNode* frame_tree_node) { | 91 FrameTreeNode* frame_tree_node) { |
| 76 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) | 92 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) |
| 77 ->GetNavigationRequestForNodeForTesting(frame_tree_node); | 93 ->GetNavigationRequestForNodeForTesting(frame_tree_node); |
| 78 } | 94 } |
| 79 | 95 |
| 80 TestRenderFrameHost* GetSpeculativeRenderFrameHost(FrameTreeNode* node) { | 96 TestRenderFrameHost* GetSpeculativeRenderFrameHost(FrameTreeNode* node) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 193 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 178 | 194 |
| 179 // Have the current RenderFrameHost commit the navigation. | 195 // Have the current RenderFrameHost commit the navigation. |
| 180 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 196 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 181 GetLoaderForNavigationRequest(request) | 197 GetLoaderForNavigationRequest(request) |
| 182 ->CallOnResponseStarted(response, MakeEmptyStream()); | 198 ->CallOnResponseStarted(response, MakeEmptyStream()); |
| 183 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); | 199 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| 184 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); | 200 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); |
| 185 | 201 |
| 186 // Commit the navigation. | 202 // Commit the navigation. |
| 187 main_test_rfh()->SendNavigate(0, kUrl2); | 203 main_test_rfh()->SendNavigate(1, kUrl2); |
| 188 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); | 204 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); |
| 189 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl2), | 205 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl2), |
| 190 main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 206 main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| 191 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); | 207 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); |
| 192 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 208 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
| 193 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 209 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 194 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 210 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| 195 } | 211 } |
| 196 | 212 |
| 197 // PlzNavigate: Test a complete renderer-initiated navigation that should be | 213 // PlzNavigate: Test a complete renderer-initiated navigation that should be |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 222 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 238 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 223 | 239 |
| 224 // Have the current RenderFrameHost commit the navigation. | 240 // Have the current RenderFrameHost commit the navigation. |
| 225 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 241 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 226 GetLoaderForNavigationRequest(request) | 242 GetLoaderForNavigationRequest(request) |
| 227 ->CallOnResponseStarted(response, MakeEmptyStream()); | 243 ->CallOnResponseStarted(response, MakeEmptyStream()); |
| 228 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); | 244 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| 229 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); | 245 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); |
| 230 | 246 |
| 231 // Commit the navigation. | 247 // Commit the navigation. |
| 232 main_test_rfh()->SendNavigate(0, kUrl2); | 248 main_test_rfh()->SendNavigate(1, kUrl2); |
| 233 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); | 249 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); |
| 234 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); | 250 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); |
| 235 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 251 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
| 236 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 252 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 237 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 253 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| 238 | 254 |
| 239 // The SiteInstance did not change. | 255 // The SiteInstance did not change. |
| 240 EXPECT_EQ(site_instance_id_1, main_test_rfh()->GetSiteInstance()->GetId()); | 256 EXPECT_EQ(site_instance_id_1, main_test_rfh()->GetSiteInstance()->GetId()); |
| 241 } | 257 } |
| 242 | 258 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 // Confirm that the speculative RenderFrameHost was destroyed. | 622 // Confirm that the speculative RenderFrameHost was destroyed. |
| 607 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 623 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 608 | 624 |
| 609 // Have the RenderFrameHost commit the navigation. | 625 // Have the RenderFrameHost commit the navigation. |
| 610 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 626 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 611 GetLoaderForNavigationRequest(request2) | 627 GetLoaderForNavigationRequest(request2) |
| 612 ->CallOnResponseStarted(response, MakeEmptyStream()); | 628 ->CallOnResponseStarted(response, MakeEmptyStream()); |
| 613 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); | 629 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| 614 | 630 |
| 615 // Commit the navigation. | 631 // Commit the navigation. |
| 616 main_test_rfh()->SendNavigate(0, kUrl2); | 632 main_test_rfh()->SendNavigate(1, kUrl2); |
| 617 | 633 |
| 618 // Confirm that the commit corresponds to the new request. | 634 // Confirm that the commit corresponds to the new request. |
| 619 ASSERT_TRUE(main_test_rfh()); | 635 ASSERT_TRUE(main_test_rfh()); |
| 620 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); | 636 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); |
| 621 } | 637 } |
| 622 | 638 |
| 623 // PlzNavigate: Test that a renderer-initiated user-initiated navigation is NOT | 639 // PlzNavigate: Test that a renderer-initiated user-initiated navigation is NOT |
| 624 // canceled if a renderer-initiated non-user-initiated request is issued in the | 640 // canceled if a renderer-initiated non-user-initiated request is issued in the |
| 625 // meantime. | 641 // meantime. |
| 626 TEST_F(NavigatorTestWithBrowserSideNavigation, | 642 TEST_F(NavigatorTestWithBrowserSideNavigation, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 654 EXPECT_TRUE(request2->begin_params().has_user_gesture); | 670 EXPECT_TRUE(request2->begin_params().has_user_gesture); |
| 655 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 671 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 656 | 672 |
| 657 // Have the RenderFrameHost commit the navigation. | 673 // Have the RenderFrameHost commit the navigation. |
| 658 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 674 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 659 GetLoaderForNavigationRequest(request2) | 675 GetLoaderForNavigationRequest(request2) |
| 660 ->CallOnResponseStarted(response, MakeEmptyStream()); | 676 ->CallOnResponseStarted(response, MakeEmptyStream()); |
| 661 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); | 677 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| 662 | 678 |
| 663 // Commit the navigation. | 679 // Commit the navigation. |
| 664 main_test_rfh()->SendNavigate(0, kUrl1); | 680 main_test_rfh()->SendNavigate(1, kUrl1); |
| 665 EXPECT_EQ(kUrl1, contents()->GetLastCommittedURL()); | 681 EXPECT_EQ(kUrl1, contents()->GetLastCommittedURL()); |
| 666 } | 682 } |
| 667 | 683 |
| 668 // PlzNavigate: Test that a browser-initiated navigation is NOT canceled if a | 684 // PlzNavigate: Test that a browser-initiated navigation is NOT canceled if a |
| 669 // renderer-initiated non-user-initiated request is issued in the meantime. | 685 // renderer-initiated non-user-initiated request is issued in the meantime. |
| 670 TEST_F(NavigatorTestWithBrowserSideNavigation, | 686 TEST_F(NavigatorTestWithBrowserSideNavigation, |
| 671 RendererNonUserInitiatedNavigationDoesntCancelBrowserInitiated) { | 687 RendererNonUserInitiatedNavigationDoesntCancelBrowserInitiated) { |
| 672 const GURL kUrl0("http://www.wikipedia.org/"); | 688 const GURL kUrl0("http://www.wikipedia.org/"); |
| 673 const GURL kUrl1("http://www.chromium.org/"); | 689 const GURL kUrl1("http://www.chromium.org/"); |
| 674 const GURL kUrl2("http://www.google.com/"); | 690 const GURL kUrl2("http://www.google.com/"); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 // Confirm that the first loader got destroyed. | 766 // Confirm that the first loader got destroyed. |
| 751 EXPECT_FALSE(loader1); | 767 EXPECT_FALSE(loader1); |
| 752 | 768 |
| 753 // Have the RenderFrameHost commit the navigation. | 769 // Have the RenderFrameHost commit the navigation. |
| 754 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 770 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 755 GetLoaderForNavigationRequest(request2) | 771 GetLoaderForNavigationRequest(request2) |
| 756 ->CallOnResponseStarted(response, MakeEmptyStream()); | 772 ->CallOnResponseStarted(response, MakeEmptyStream()); |
| 757 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); | 773 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| 758 | 774 |
| 759 // Commit the navigation. | 775 // Commit the navigation. |
| 760 main_test_rfh()->SendNavigate(0, kUrl2); | 776 main_test_rfh()->SendNavigate(1, kUrl2); |
| 761 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); | 777 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); |
| 762 | 778 |
| 763 // The SiteInstance did not change. | 779 // The SiteInstance did not change. |
| 764 EXPECT_EQ(site_instance_id_0, main_test_rfh()->GetSiteInstance()->GetId()); | 780 EXPECT_EQ(site_instance_id_0, main_test_rfh()->GetSiteInstance()->GetId()); |
| 765 } | 781 } |
| 766 | 782 |
| 767 // PlzNavigate: Test that a reload navigation is properly signaled to the | 783 // PlzNavigate: Test that a reload navigation is properly signaled to the |
| 768 // RenderFrame when the navigation can commit. A speculative RenderFrameHost | 784 // RenderFrame when the navigation can commit. A speculative RenderFrameHost |
| 769 // should not be created at any step. | 785 // should not be created at any step. |
| 770 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { | 786 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { |
| 771 const GURL kUrl("http://www.google.com/"); | 787 const GURL kUrl("http://www.google.com/"); |
| 772 contents()->NavigateAndCommit(kUrl); | 788 contents()->NavigateAndCommit(kUrl); |
| 773 | 789 |
| 774 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 790 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 775 RequestNavigationWithParameters(node, kUrl, Referrer(), | 791 RequestReloadNavigation(node, kUrl, NavigationController::RELOAD); |
| 776 ui::PAGE_TRANSITION_LINK, | |
| 777 NavigationController::RELOAD); | |
| 778 // A NavigationRequest should have been generated. | 792 // A NavigationRequest should have been generated. |
| 779 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 793 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| 780 ASSERT_TRUE(main_request != NULL); | 794 ASSERT_TRUE(main_request != NULL); |
| 781 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, | 795 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, |
| 782 main_request->common_params().navigation_type); | 796 main_request->common_params().navigation_type); |
| 783 main_test_rfh()->PrepareForCommit(); | 797 main_test_rfh()->PrepareForCommit(); |
| 784 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 798 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 785 | 799 |
| 786 main_test_rfh()->SendNavigate(0, kUrl); | 800 main_test_rfh()->SendNavigate(0, kUrl); |
| 787 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 801 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 788 | 802 |
| 789 // Now do a shift+reload. | 803 // Now do a shift+reload. |
| 790 RequestNavigationWithParameters(node, kUrl, Referrer(), | 804 RequestReloadNavigation( |
| 791 ui::PAGE_TRANSITION_LINK, | 805 node, kUrl, NavigationController::RELOAD_IGNORING_CACHE); |
| 792 NavigationController::RELOAD_IGNORING_CACHE); | |
| 793 // A NavigationRequest should have been generated. | 806 // A NavigationRequest should have been generated. |
| 794 main_request = GetNavigationRequestForFrameTreeNode(node); | 807 main_request = GetNavigationRequestForFrameTreeNode(node); |
| 795 ASSERT_TRUE(main_request != NULL); | 808 ASSERT_TRUE(main_request != NULL); |
| 796 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, | 809 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, |
| 797 main_request->common_params().navigation_type); | 810 main_request->common_params().navigation_type); |
| 798 main_test_rfh()->PrepareForCommit(); | 811 main_test_rfh()->PrepareForCommit(); |
| 799 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 812 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 800 } | 813 } |
| 801 | 814 |
| 802 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when | 815 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 main_rfh->SendRendererInitiatedNavigationRequest(kUrl2, true); | 1015 main_rfh->SendRendererInitiatedNavigationRequest(kUrl2, true); |
| 1003 navigation_request = GetNavigationRequestForFrameTreeNode(node); | 1016 navigation_request = GetNavigationRequestForFrameTreeNode(node); |
| 1004 ASSERT_TRUE(navigation_request); | 1017 ASSERT_TRUE(navigation_request); |
| 1005 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, | 1018 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, |
| 1006 navigation_request->state()); | 1019 navigation_request->state()); |
| 1007 EXPECT_FALSE(navigation_request->loader_for_testing()); | 1020 EXPECT_FALSE(navigation_request->loader_for_testing()); |
| 1008 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 1021 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 1009 } | 1022 } |
| 1010 | 1023 |
| 1011 } // namespace content | 1024 } // namespace content |
| OLD | NEW |