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

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

Issue 2161073002: Adds RequestContextType information to the NavigationHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed clamy@'s and nasko@'s comments. Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 #include "content/browser/web_contents/web_contents_impl.h" 6 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/public/browser/web_contents.h" 7 #include "content/public/browser/web_contents.h"
8 #include "content/public/browser/web_contents_observer.h" 8 #include "content/public/browser/web_contents_observer.h"
9 #include "content/public/common/request_context_type.h"
9 #include "content/public/test/browser_test_utils.h" 10 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h" 11 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h" 12 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/public/test/test_navigation_observer.h" 13 #include "content/public/test/test_navigation_observer.h"
13 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
14 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
15 #include "content/test/content_browser_test_utils_internal.h" 16 #include "content/test/content_browser_test_utils_internal.h"
16 #include "net/dns/mock_host_resolver.h" 17 #include "net/dns/mock_host_resolver.h"
17 #include "ui/base/page_transition_types.h" 18 #include "ui/base/page_transition_types.h"
18 #include "url/url_constants.h" 19 #include "url/url_constants.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 will_start_result_(will_start_result), 140 will_start_result_(will_start_result),
140 will_redirect_result_(will_redirect_result), 141 will_redirect_result_(will_redirect_result),
141 will_process_result_(will_process_result), 142 will_process_result_(will_process_result),
142 did_call_will_start_(did_call_will_start), 143 did_call_will_start_(did_call_will_start),
143 did_call_will_redirect_(did_call_will_redirect), 144 did_call_will_redirect_(did_call_will_redirect),
144 did_call_will_process_(did_call_will_process) {} 145 did_call_will_process_(did_call_will_process) {}
145 ~TestNavigationThrottle() override {} 146 ~TestNavigationThrottle() override {}
146 147
147 void Resume() { navigation_handle()->Resume(); } 148 void Resume() { navigation_handle()->Resume(); }
148 149
150 RequestContextType request_context_type() { return request_context_type_; }
151
149 private: 152 private:
150 // NavigationThrottle implementation. 153 // NavigationThrottle implementation.
151 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { 154 NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
155 NavigationHandleImpl* navigation_handle_impl =
156 static_cast<NavigationHandleImpl*>(navigation_handle());
157 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED,
158 navigation_handle_impl->GetFetchRequestContextType());
159 request_context_type_ =
160 navigation_handle_impl->GetFetchRequestContextType();
161
152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_); 162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_);
153 return will_start_result_; 163 return will_start_result_;
154 } 164 }
155 165
156 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { 166 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override {
167 NavigationHandleImpl* navigation_handle_impl =
168 static_cast<NavigationHandleImpl*>(navigation_handle());
169 CHECK_EQ(request_context_type_,
170 navigation_handle_impl->GetFetchRequestContextType());
171
157 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 172 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
158 did_call_will_redirect_); 173 did_call_will_redirect_);
159 return will_redirect_result_; 174 return will_redirect_result_;
160 } 175 }
161 176
162 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override { 177 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override {
178 NavigationHandleImpl* navigation_handle_impl =
179 static_cast<NavigationHandleImpl*>(navigation_handle());
180 CHECK_EQ(request_context_type_,
181 navigation_handle_impl->GetFetchRequestContextType());
182
163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 183 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
164 did_call_will_process_); 184 did_call_will_process_);
165 return will_process_result_; 185 return will_process_result_;
166 } 186 }
167 187
168 NavigationThrottle::ThrottleCheckResult will_start_result_; 188 NavigationThrottle::ThrottleCheckResult will_start_result_;
169 NavigationThrottle::ThrottleCheckResult will_redirect_result_; 189 NavigationThrottle::ThrottleCheckResult will_redirect_result_;
170 NavigationThrottle::ThrottleCheckResult will_process_result_; 190 NavigationThrottle::ThrottleCheckResult will_process_result_;
171 base::Closure did_call_will_start_; 191 base::Closure did_call_will_start_;
172 base::Closure did_call_will_redirect_; 192 base::Closure did_call_will_redirect_;
173 base::Closure did_call_will_process_; 193 base::Closure did_call_will_process_;
194 RequestContextType request_context_type_;
174 }; 195 };
175 196
176 // Install a TestNavigationThrottle on all following requests and allows waiting 197 // Install a TestNavigationThrottle on all following requests and allows waiting
177 // for various NavigationThrottle related events. Waiting works only for the 198 // for various NavigationThrottle related events. Waiting works only for the
178 // immediately next navigation. New instances are needed to wait for further 199 // immediately next navigation. New instances are needed to wait for further
179 // navigations. 200 // navigations.
180 class TestNavigationThrottleInstaller : public WebContentsObserver { 201 class TestNavigationThrottleInstaller : public WebContentsObserver {
181 public: 202 public:
182 TestNavigationThrottleInstaller( 203 TestNavigationThrottleInstaller(
183 WebContents* web_contents, 204 WebContents* web_contents,
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // Wait for the end of the navigation. 668 // Wait for the end of the navigation.
648 navigation_observer.Wait(); 669 navigation_observer.Wait();
649 670
650 EXPECT_TRUE(observer.has_committed()); 671 EXPECT_TRUE(observer.has_committed());
651 EXPECT_TRUE(observer.was_redirected()); 672 EXPECT_TRUE(observer.was_redirected());
652 EXPECT_FALSE(observer.is_error()); 673 EXPECT_FALSE(observer.is_error());
653 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), 674 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(),
654 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); 675 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html")));
655 } 676 }
656 677
678 // Checks that the RequestContextType value is properly set.
679 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
680 VerifyRequestContextTypeForFrameTree) {
681 GURL main_url(embedded_test_server()->GetURL(
682 "a.com", "/cross_site_iframe_factory.html?a(b(c))"));
683 GURL b_url(embedded_test_server()->GetURL(
684 "b.com", "/cross_site_iframe_factory.html?b(c())"));
685 GURL c_url(embedded_test_server()->GetURL(
686 "c.com", "/cross_site_iframe_factory.html?c()"));
687
688 TestNavigationThrottleInstaller installer(
689 shell()->web_contents(), NavigationThrottle::PROCEED,
690 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
691 TestNavigationManager main_manager(shell()->web_contents(), main_url);
692 TestNavigationManager b_manager(shell()->web_contents(), b_url);
693 TestNavigationManager c_manager(shell()->web_contents(), c_url);
694 NavigationStartUrlRecorder url_recorder(shell()->web_contents());
695 TestNavigationThrottle* previous_throttle = nullptr;
696
697 // Starts and verifies the main frame navigation.
698 shell()->LoadURL(main_url);
699 main_manager.WaitForWillStartRequest();
700 // The throttle should not be null.
701 EXPECT_NE(previous_throttle, installer.navigation_throttle());
702 // Checks the only URL recorded so far is the one expected for the main frame.
703 EXPECT_EQ(main_url, url_recorder.urls().back());
704 EXPECT_EQ(1ul, url_recorder.urls().size());
705 // Checks the main frame RequestContextType.
706 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
707 installer.navigation_throttle()->request_context_type());
708 // For each navigations the throttle should be a different instance.
709 previous_throttle = installer.navigation_throttle();
710
711 // Ditto for frame b navigation.
712 main_manager.WaitForNavigationFinished();
713 b_manager.WaitForWillStartRequest();
714 EXPECT_NE(previous_throttle, installer.navigation_throttle());
715 EXPECT_EQ(b_url, url_recorder.urls().back());
716 EXPECT_EQ(2ul, url_recorder.urls().size());
717 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
718 installer.navigation_throttle()->request_context_type());
719 previous_throttle = installer.navigation_throttle();
720
721 // Ditto for frame c navigation.
722 b_manager.WaitForNavigationFinished();
723 c_manager.WaitForWillStartRequest();
724 EXPECT_NE(previous_throttle, installer.navigation_throttle());
725 EXPECT_EQ(c_url, url_recorder.urls().back());
726 EXPECT_EQ(3ul, url_recorder.urls().size());
727 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
728 installer.navigation_throttle()->request_context_type());
729
730 // Lets the final navigation finish so that we conclude running the
731 // RequestContextType checks that happen in TestNavigationThrottle.
732 c_manager.WaitForNavigationFinished();
733 // Confirms the last navigation did finish.
734 EXPECT_FALSE(installer.navigation_throttle());
735 }
736
737 // Checks that the RequestContextType value is properly set for an hyper-link.
738 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
739 VerifyHyperlinkRequestContextType) {
740 GURL link_url(embedded_test_server()->GetURL("/title2.html"));
741 GURL document_url(embedded_test_server()->GetURL("/simple_links.html"));
742
743 TestNavigationThrottleInstaller installer(
744 shell()->web_contents(), NavigationThrottle::PROCEED,
745 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
746 TestNavigationManager document_manager(shell()->web_contents(), document_url);
747 TestNavigationManager link_manager(shell()->web_contents(), link_url);
748 NavigationStartUrlRecorder url_recorder(shell()->web_contents());
749 TestNavigationThrottle* previous_throttle = nullptr;
750
751 // Starts and checks the main frame navigation.
clamy 2016/07/22 13:51:31 I don't think this part adds much. Let's just navi
carlosk 2016/07/22 16:00:30 Done. I was in doubt about this and went with the
752 shell()->LoadURL(document_url);
753 document_manager.WaitForWillStartRequest();
754 EXPECT_NE(previous_throttle, installer.navigation_throttle());
755 EXPECT_EQ(document_url, url_recorder.urls().back());
756 EXPECT_EQ(1ul, url_recorder.urls().size());
757 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
758 installer.navigation_throttle()->request_context_type());
759 previous_throttle = installer.navigation_throttle();
760
761 // Starts the navigation from a link click and then check it.
762 document_manager.WaitForNavigationFinished();
763 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
764 bool success = false;
765 EXPECT_TRUE(ExecuteScriptAndExtractBool(
766 shell(), "window.domAutomationController.send(clickSameSiteLink());",
767 &success));
768 EXPECT_TRUE(success);
769 link_manager.WaitForWillStartRequest();
770 EXPECT_NE(previous_throttle, installer.navigation_throttle());
771 EXPECT_EQ(link_url, url_recorder.urls().back());
772 EXPECT_EQ(2ul, url_recorder.urls().size());
773 EXPECT_EQ(REQUEST_CONTEXT_TYPE_HYPERLINK,
774 installer.navigation_throttle()->request_context_type());
775
776 // Finishes the last navigation.
777 link_manager.WaitForNavigationFinished();
778 EXPECT_FALSE(installer.navigation_throttle());
779 }
780
781 // Checks that the RequestContextType value is properly set for an form (POST).
782 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
783 VerifyFormRequestContextType) {
784 GURL document_url(
785 embedded_test_server()->GetURL("/session_history/form.html"));
786 GURL post_url(embedded_test_server()->GetURL("/echotitle"));
787
788 TestNavigationThrottleInstaller installer(
789 shell()->web_contents(), NavigationThrottle::PROCEED,
790 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
791 TestNavigationManager document_manager(shell()->web_contents(), document_url);
792 TestNavigationManager post_manager(shell()->web_contents(), post_url);
793 NavigationStartUrlRecorder url_recorder(shell()->web_contents());
794 TestNavigationThrottle* previous_throttle = nullptr;
795
796 // Starts and checks the main frame navigation.
clamy 2016/07/22 13:51:31 Same as the test above, I'd rather we focus on che
carlosk 2016/07/22 16:00:29 Done.
797 shell()->LoadURL(document_url);
798 document_manager.WaitForWillStartRequest();
799 EXPECT_NE(previous_throttle, installer.navigation_throttle());
800 EXPECT_EQ(document_url, url_recorder.urls().back());
801 EXPECT_EQ(1ul, url_recorder.urls().size());
802 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
803 installer.navigation_throttle()->request_context_type());
804 previous_throttle = installer.navigation_throttle();
805
806 // Executes the form POST navigation and then check it.
807 document_manager.WaitForNavigationFinished();
808 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
809 GURL submit_url("javascript:submitForm('isubmit')");
810 shell()->LoadURL(submit_url);
811 post_manager.WaitForWillStartRequest();
812 EXPECT_NE(previous_throttle, installer.navigation_throttle());
813 EXPECT_EQ(post_url, url_recorder.urls().back());
814 EXPECT_EQ(2ul, url_recorder.urls().size());
815 EXPECT_EQ(REQUEST_CONTEXT_TYPE_FORM,
816 installer.navigation_throttle()->request_context_type());
817
818 // Finishes the last navigation.
819 post_manager.WaitForNavigationFinished();
820 EXPECT_FALSE(installer.navigation_throttle());
821 }
822
657 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded 823 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded
658 // URL from the very beginning of the navigation. 824 // URL from the very beginning of the navigation.
659 class NavigationHandleImplHttpsUpgradeBrowserTest 825 class NavigationHandleImplHttpsUpgradeBrowserTest
660 : public NavigationHandleImplBrowserTest { 826 : public NavigationHandleImplBrowserTest {
661 public: 827 public:
662 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, 828 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url,
663 const GURL& iframe_secure_url) { 829 const GURL& iframe_secure_url) {
664 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); 830 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme));
665 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme)); 831 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme));
666 832
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, 877 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest,
712 StartUrlIsHttpsUpgradedCrossSite) { 878 StartUrlIsHttpsUpgradedCrossSite) {
713 GURL start_url( 879 GURL start_url(
714 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); 880 embedded_test_server()->GetURL("/https_upgrade_cross_site.html"));
715 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); 881 GURL cross_site_iframe_secure_url("https://other.com/title1.html");
716 882
717 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); 883 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url);
718 } 884 }
719 885
720 } // namespace content 886 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698