Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 fetch_request_context_type() { | |
| 151 return fetch_request_context_type_; | |
| 152 } | |
| 153 | |
| 149 private: | 154 private: |
| 150 // NavigationThrottle implementation. | 155 // NavigationThrottle implementation. |
| 151 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { | 156 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
| 157 NavigationHandleImpl* navigation_handle_impl = | |
| 158 static_cast<NavigationHandleImpl*>(navigation_handle()); | |
| 159 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, | |
|
nasko
2016/07/21 22:04:35
Why would it be unspecified? At the start of the r
carlosk
2016/07/22 12:51:26
The only thing we know here is that it should have
| |
| 160 navigation_handle_impl->fetch_request_context_type()); | |
| 161 fetch_request_context_type_ = | |
| 162 navigation_handle_impl->fetch_request_context_type(); | |
| 163 | |
| 152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_); | 164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_); |
| 153 return will_start_result_; | 165 return will_start_result_; |
| 154 } | 166 } |
| 155 | 167 |
| 156 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { | 168 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { |
| 169 NavigationHandleImpl* navigation_handle_impl = | |
| 170 static_cast<NavigationHandleImpl*>(navigation_handle()); | |
| 171 CHECK_EQ(fetch_request_context_type_, | |
| 172 navigation_handle_impl->fetch_request_context_type()); | |
| 173 | |
| 157 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 174 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 158 did_call_will_redirect_); | 175 did_call_will_redirect_); |
| 159 return will_redirect_result_; | 176 return will_redirect_result_; |
| 160 } | 177 } |
| 161 | 178 |
| 162 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override { | 179 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override { |
| 180 NavigationHandleImpl* navigation_handle_impl = | |
| 181 static_cast<NavigationHandleImpl*>(navigation_handle()); | |
| 182 CHECK_EQ(fetch_request_context_type_, | |
| 183 navigation_handle_impl->fetch_request_context_type()); | |
| 184 | |
| 163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 164 did_call_will_process_); | 186 did_call_will_process_); |
| 165 return will_process_result_; | 187 return will_process_result_; |
| 166 } | 188 } |
| 167 | 189 |
| 168 NavigationThrottle::ThrottleCheckResult will_start_result_; | 190 NavigationThrottle::ThrottleCheckResult will_start_result_; |
| 169 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 191 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
| 170 NavigationThrottle::ThrottleCheckResult will_process_result_; | 192 NavigationThrottle::ThrottleCheckResult will_process_result_; |
| 171 base::Closure did_call_will_start_; | 193 base::Closure did_call_will_start_; |
| 172 base::Closure did_call_will_redirect_; | 194 base::Closure did_call_will_redirect_; |
| 173 base::Closure did_call_will_process_; | 195 base::Closure did_call_will_process_; |
| 196 RequestContextType fetch_request_context_type_; | |
| 174 }; | 197 }; |
| 175 | 198 |
| 176 // Install a TestNavigationThrottle on all following requests and allows waiting | 199 // Install a TestNavigationThrottle on all following requests and allows waiting |
| 177 // for various NavigationThrottle related events. Waiting works only for the | 200 // for various NavigationThrottle related events. Waiting works only for the |
| 178 // immediately next navigation. New instances are needed to wait for further | 201 // immediately next navigation. New instances are needed to wait for further |
| 179 // navigations. | 202 // navigations. |
| 180 class TestNavigationThrottleInstaller : public WebContentsObserver { | 203 class TestNavigationThrottleInstaller : public WebContentsObserver { |
| 181 public: | 204 public: |
| 182 TestNavigationThrottleInstaller( | 205 TestNavigationThrottleInstaller( |
| 183 WebContents* web_contents, | 206 WebContents* web_contents, |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 // Wait for the end of the navigation. | 670 // Wait for the end of the navigation. |
| 648 navigation_observer.Wait(); | 671 navigation_observer.Wait(); |
| 649 | 672 |
| 650 EXPECT_TRUE(observer.has_committed()); | 673 EXPECT_TRUE(observer.has_committed()); |
| 651 EXPECT_TRUE(observer.was_redirected()); | 674 EXPECT_TRUE(observer.was_redirected()); |
| 652 EXPECT_FALSE(observer.is_error()); | 675 EXPECT_FALSE(observer.is_error()); |
| 653 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), | 676 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), |
| 654 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); | 677 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
| 655 } | 678 } |
| 656 | 679 |
| 680 // Checks that the RequestContextType value is properly set. | |
| 681 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, | |
| 682 VerifyRequestContextType) { | |
| 683 GURL main_url(embedded_test_server()->GetURL( | |
| 684 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); | |
|
clamy
2016/07/21 11:30:21
I'm not sure I see the point of testing frame c he
nasko
2016/07/21 22:04:35
Actually, testing a frame that is not direct child
carlosk
2016/07/22 12:51:26
Oh well... I had removed the testing of the extra
clamy
2016/07/22 13:51:31
I think it's normal that a navigation to an image
carlosk
2016/07/22 16:00:29
Acknowledged.
| |
| 685 GURL b_url(embedded_test_server()->GetURL( | |
| 686 "b.com", "/cross_site_iframe_factory.html?b(c())")); | |
| 687 GURL c_url(embedded_test_server()->GetURL( | |
| 688 "c.com", "/cross_site_iframe_factory.html?c()")); | |
| 689 | |
| 690 TestNavigationThrottleInstaller installer( | |
| 691 shell()->web_contents(), NavigationThrottle::PROCEED, | |
| 692 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | |
| 693 TestNavigationManager main_manager(shell()->web_contents(), main_url); | |
| 694 TestNavigationManager b_manager(shell()->web_contents(), b_url); | |
| 695 TestNavigationManager c_manager(shell()->web_contents(), c_url); | |
| 696 NavigationStartUrlRecorder url_recorder(shell()->web_contents()); | |
| 697 TestNavigationThrottle* last_throttle = nullptr; | |
| 698 | |
| 699 // Waits until the end of the main frame navigation. | |
| 700 shell()->LoadURL(main_url); | |
| 701 main_manager.WaitForWillStartRequest(); | |
| 702 // Checks the navigation is the one expected for the main frame. | |
| 703 EXPECT_NE(last_throttle, installer.navigation_throttle()); | |
| 704 EXPECT_EQ(main_url, url_recorder.urls().back()); | |
| 705 EXPECT_EQ(1ul, url_recorder.urls().size()); | |
| 706 // Checks the main frame RequestContextType. | |
| 707 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | |
| 708 installer.navigation_throttle()->fetch_request_context_type()); | |
| 709 last_throttle = installer.navigation_throttle(); | |
| 710 | |
| 711 // Ditto for frame b. | |
| 712 main_manager.WaitForNavigationFinished(); | |
| 713 b_manager.WaitForWillStartRequest(); | |
| 714 EXPECT_NE(last_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()->fetch_request_context_type()); | |
| 719 last_throttle = installer.navigation_throttle(); | |
| 720 | |
| 721 // Ditto for frame c. | |
| 722 b_manager.WaitForNavigationFinished(); | |
| 723 c_manager.WaitForWillStartRequest(); | |
| 724 EXPECT_NE(last_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()->fetch_request_context_type()); | |
| 729 last_throttle = installer.navigation_throttle(); | |
| 730 | |
| 731 // Lets the final navigation finish so that we conclude running the checks | |
| 732 // that happen in TestNavigationThrottle. | |
| 733 c_manager.WaitForNavigationFinished(); | |
| 734 } | |
| 735 | |
| 657 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded | 736 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded |
| 658 // URL from the very beginning of the navigation. | 737 // URL from the very beginning of the navigation. |
| 659 class NavigationHandleImplHttpsUpgradeBrowserTest | 738 class NavigationHandleImplHttpsUpgradeBrowserTest |
| 660 : public NavigationHandleImplBrowserTest { | 739 : public NavigationHandleImplBrowserTest { |
| 661 public: | 740 public: |
| 662 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, | 741 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, |
| 663 const GURL& iframe_secure_url) { | 742 const GURL& iframe_secure_url) { |
| 664 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); | 743 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); |
| 665 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme)); | 744 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme)); |
| 666 | 745 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, | 790 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, |
| 712 StartUrlIsHttpsUpgradedCrossSite) { | 791 StartUrlIsHttpsUpgradedCrossSite) { |
| 713 GURL start_url( | 792 GURL start_url( |
| 714 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); | 793 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); |
| 715 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); | 794 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); |
| 716 | 795 |
| 717 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); | 796 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); |
| 718 } | 797 } |
| 719 | 798 |
| 720 } // namespace content | 799 } // namespace content |
| OLD | NEW |