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

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: Rebase. Created 4 years, 4 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->GetRequestContextType());
159 request_context_type_ = navigation_handle_impl->GetRequestContextType();
160
152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_); 161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_);
153 return will_start_result_; 162 return will_start_result_;
154 } 163 }
155 164
156 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { 165 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override {
166 NavigationHandleImpl* navigation_handle_impl =
167 static_cast<NavigationHandleImpl*>(navigation_handle());
168 CHECK_EQ(request_context_type_,
169 navigation_handle_impl->GetRequestContextType());
170
157 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 171 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
158 did_call_will_redirect_); 172 did_call_will_redirect_);
159 return will_redirect_result_; 173 return will_redirect_result_;
160 } 174 }
161 175
162 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override { 176 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override {
177 NavigationHandleImpl* navigation_handle_impl =
178 static_cast<NavigationHandleImpl*>(navigation_handle());
179 CHECK_EQ(request_context_type_,
180 navigation_handle_impl->GetRequestContextType());
181
163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 182 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
164 did_call_will_process_); 183 did_call_will_process_);
165 return will_process_result_; 184 return will_process_result_;
166 } 185 }
167 186
168 NavigationThrottle::ThrottleCheckResult will_start_result_; 187 NavigationThrottle::ThrottleCheckResult will_start_result_;
169 NavigationThrottle::ThrottleCheckResult will_redirect_result_; 188 NavigationThrottle::ThrottleCheckResult will_redirect_result_;
170 NavigationThrottle::ThrottleCheckResult will_process_result_; 189 NavigationThrottle::ThrottleCheckResult will_process_result_;
171 base::Closure did_call_will_start_; 190 base::Closure did_call_will_start_;
172 base::Closure did_call_will_redirect_; 191 base::Closure did_call_will_redirect_;
173 base::Closure did_call_will_process_; 192 base::Closure did_call_will_process_;
193 RequestContextType request_context_type_;
174 }; 194 };
175 195
176 // Install a TestNavigationThrottle on all following requests and allows waiting 196 // Install a TestNavigationThrottle on all following requests and allows waiting
177 // for various NavigationThrottle related events. Waiting works only for the 197 // for various NavigationThrottle related events. Waiting works only for the
178 // immediately next navigation. New instances are needed to wait for further 198 // immediately next navigation. New instances are needed to wait for further
179 // navigations. 199 // navigations.
180 class TestNavigationThrottleInstaller : public WebContentsObserver { 200 class TestNavigationThrottleInstaller : public WebContentsObserver {
181 public: 201 public:
182 TestNavigationThrottleInstaller( 202 TestNavigationThrottleInstaller(
183 WebContents* web_contents, 203 WebContents* web_contents,
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // Wait for the end of the navigation. 667 // Wait for the end of the navigation.
648 navigation_observer.Wait(); 668 navigation_observer.Wait();
649 669
650 EXPECT_TRUE(observer.has_committed()); 670 EXPECT_TRUE(observer.has_committed());
651 EXPECT_TRUE(observer.was_redirected()); 671 EXPECT_TRUE(observer.was_redirected());
652 EXPECT_FALSE(observer.is_error()); 672 EXPECT_FALSE(observer.is_error());
653 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), 673 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(),
654 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); 674 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html")));
655 } 675 }
656 676
677 // Checks that the RequestContextType value is properly set.
678 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
679 VerifyRequestContextTypeForFrameTree) {
680 GURL main_url(embedded_test_server()->GetURL(
681 "a.com", "/cross_site_iframe_factory.html?a(b(c))"));
682 GURL b_url(embedded_test_server()->GetURL(
683 "b.com", "/cross_site_iframe_factory.html?b(c())"));
684 GURL c_url(embedded_test_server()->GetURL(
685 "c.com", "/cross_site_iframe_factory.html?c()"));
686
687 TestNavigationThrottleInstaller installer(
688 shell()->web_contents(), NavigationThrottle::PROCEED,
689 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
690 TestNavigationManager main_manager(shell()->web_contents(), main_url);
691 TestNavigationManager b_manager(shell()->web_contents(), b_url);
692 TestNavigationManager c_manager(shell()->web_contents(), c_url);
693 NavigationStartUrlRecorder url_recorder(shell()->web_contents());
694 TestNavigationThrottle* previous_throttle = nullptr;
695
696 // Starts and verifies the main frame navigation.
697 shell()->LoadURL(main_url);
698 main_manager.WaitForWillStartRequest();
699 // The throttle should not be null.
700 EXPECT_NE(previous_throttle, installer.navigation_throttle());
701 // Checks the only URL recorded so far is the one expected for the main frame.
702 EXPECT_EQ(main_url, url_recorder.urls().back());
703 EXPECT_EQ(1ul, url_recorder.urls().size());
704 // Checks the main frame RequestContextType.
705 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
706 installer.navigation_throttle()->request_context_type());
707 // For each navigations the throttle should be a different instance.
708 previous_throttle = installer.navigation_throttle();
709
710 // Ditto for frame b navigation.
711 main_manager.WaitForNavigationFinished();
712 b_manager.WaitForWillStartRequest();
713 EXPECT_NE(previous_throttle, installer.navigation_throttle());
714 EXPECT_EQ(b_url, url_recorder.urls().back());
715 EXPECT_EQ(2ul, url_recorder.urls().size());
716 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
717 installer.navigation_throttle()->request_context_type());
718 previous_throttle = installer.navigation_throttle();
719
720 // Ditto for frame c navigation.
721 b_manager.WaitForNavigationFinished();
722 c_manager.WaitForWillStartRequest();
723 EXPECT_NE(previous_throttle, installer.navigation_throttle());
724 EXPECT_EQ(c_url, url_recorder.urls().back());
725 EXPECT_EQ(3ul, url_recorder.urls().size());
726 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
727 installer.navigation_throttle()->request_context_type());
728
729 // Lets the final navigation finish so that we conclude running the
730 // RequestContextType checks that happen in TestNavigationThrottle.
731 c_manager.WaitForNavigationFinished();
732 // Confirms the last navigation did finish.
733 EXPECT_FALSE(installer.navigation_throttle());
734 }
735
736 // Checks that the RequestContextType value is properly set for an hyper-link.
737 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
738 VerifyHyperlinkRequestContextType) {
739 GURL link_url(embedded_test_server()->GetURL("/title2.html"));
740 GURL document_url(embedded_test_server()->GetURL("/simple_links.html"));
741
742 TestNavigationThrottleInstaller installer(
743 shell()->web_contents(), NavigationThrottle::PROCEED,
744 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
745 TestNavigationManager link_manager(shell()->web_contents(), link_url);
746 NavigationStartUrlRecorder url_recorder(shell()->web_contents());
747
748 // Navigate to a page with a link.
749 EXPECT_TRUE(NavigateToURL(shell(), document_url));
750 EXPECT_EQ(document_url, url_recorder.urls().back());
751 EXPECT_EQ(1ul, url_recorder.urls().size());
752
753 // Starts the navigation from a link click and then check it.
754 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
755 bool success = false;
756 EXPECT_TRUE(ExecuteScriptAndExtractBool(
757 shell(), "window.domAutomationController.send(clickSameSiteLink());",
758 &success));
759 EXPECT_TRUE(success);
760 link_manager.WaitForWillStartRequest();
761 EXPECT_EQ(link_url, url_recorder.urls().back());
762 EXPECT_EQ(2ul, url_recorder.urls().size());
763 EXPECT_EQ(REQUEST_CONTEXT_TYPE_HYPERLINK,
764 installer.navigation_throttle()->request_context_type());
765
766 // Finishes the last navigation.
767 link_manager.WaitForNavigationFinished();
768 EXPECT_FALSE(installer.navigation_throttle());
769 }
770
771 // Checks that the RequestContextType value is properly set for an form (POST).
772 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
773 VerifyFormRequestContextType) {
774 GURL document_url(
775 embedded_test_server()->GetURL("/session_history/form.html"));
776 GURL post_url(embedded_test_server()->GetURL("/echotitle"));
777
778 TestNavigationThrottleInstaller installer(
779 shell()->web_contents(), NavigationThrottle::PROCEED,
780 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
781 TestNavigationManager post_manager(shell()->web_contents(), post_url);
782 NavigationStartUrlRecorder url_recorder(shell()->web_contents());
783
784 // Navigate to a page with a form.
785 EXPECT_TRUE(NavigateToURL(shell(), document_url));
786 EXPECT_EQ(document_url, url_recorder.urls().back());
787 EXPECT_EQ(1ul, url_recorder.urls().size());
788
789 // Executes the form POST navigation and then check it.
790 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
791 GURL submit_url("javascript:submitForm('isubmit')");
792 shell()->LoadURL(submit_url);
793 post_manager.WaitForWillStartRequest();
794 EXPECT_EQ(post_url, url_recorder.urls().back());
795 EXPECT_EQ(2ul, url_recorder.urls().size());
796 EXPECT_EQ(REQUEST_CONTEXT_TYPE_FORM,
797 installer.navigation_throttle()->request_context_type());
798
799 // Finishes the last navigation.
800 post_manager.WaitForNavigationFinished();
801 EXPECT_FALSE(installer.navigation_throttle());
802 }
803
657 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded 804 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded
658 // URL from the very beginning of the navigation. 805 // URL from the very beginning of the navigation.
659 class NavigationHandleImplHttpsUpgradeBrowserTest 806 class NavigationHandleImplHttpsUpgradeBrowserTest
660 : public NavigationHandleImplBrowserTest { 807 : public NavigationHandleImplBrowserTest {
661 public: 808 public:
662 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, 809 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url,
663 const GURL& iframe_secure_url) { 810 const GURL& iframe_secure_url) {
664 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); 811 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme));
665 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme)); 812 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme));
666 813
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, 858 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest,
712 StartUrlIsHttpsUpgradedCrossSite) { 859 StartUrlIsHttpsUpgradedCrossSite) {
713 GURL start_url( 860 GURL start_url(
714 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); 861 embedded_test_server()->GetURL("/https_upgrade_cross_site.html"));
715 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); 862 GURL cross_site_iframe_secure_url("https://other.com/title1.html");
716 863
717 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); 864 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url);
718 } 865 }
719 866
720 } // namespace content 867 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698