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