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 "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 #include "content/browser/frame_host/navigation_handle_impl.h" | 6 #include "content/browser/frame_host/navigation_handle_impl.h" |
7 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
10 #include "content/public/common/browser_side_navigation_policy.h" | |
10 #include "content/public/common/request_context_type.h" | 11 #include "content/public/common/request_context_type.h" |
11 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
12 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
13 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
14 #include "content/public/test/test_navigation_observer.h" | 15 #include "content/public/test/test_navigation_observer.h" |
15 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
16 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
17 #include "content/test/content_browser_test_utils_internal.h" | 18 #include "content/test/content_browser_test_utils_internal.h" |
18 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
19 #include "ui/base/page_transition_types.h" | 20 #include "ui/base/page_transition_types.h" |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
894 TestNavigationThrottleInstaller installer( | 895 TestNavigationThrottleInstaller installer( |
895 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, | 896 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, |
896 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 897 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
897 NavigationHandleObserver observer(shell()->web_contents(), kUrl); | 898 NavigationHandleObserver observer(shell()->web_contents(), kUrl); |
898 | 899 |
899 // Try to navigate to the url. The navigation should be canceled and the | 900 // Try to navigate to the url. The navigation should be canceled and the |
900 // NavigationHandle should have the right error code. | 901 // NavigationHandle should have the right error code. |
901 EXPECT_FALSE(NavigateToURL(shell(), kUrl)); | 902 EXPECT_FALSE(NavigateToURL(shell(), kUrl)); |
902 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); | 903 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); |
903 } | 904 } |
905 | |
906 { | |
907 // Set up a NavigationThrottle that will block the navigation in | |
908 // WillRedirectRequest. | |
909 TestNavigationThrottleInstaller installer( | |
910 shell()->web_contents(), NavigationThrottle::PROCEED, | |
911 NavigationThrottle::BLOCK_REQUEST, NavigationThrottle::PROCEED); | |
912 NavigationHandleObserver observer(shell()->web_contents(), kRedirectingUrl); | |
913 | |
914 // Try to navigate to the url. The navigation should be canceled and the | |
915 // NavigationHandle should have the right error code. | |
916 EXPECT_FALSE(NavigateToURL(shell(), kRedirectingUrl)); | |
917 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); | |
918 } | |
904 } | 919 } |
905 | 920 |
906 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded | 921 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded |
907 // URL from the very beginning of the navigation. | 922 // URL from the very beginning of the navigation. |
908 class NavigationHandleImplHttpsUpgradeBrowserTest | 923 class NavigationHandleImplHttpsUpgradeBrowserTest |
909 : public NavigationHandleImplBrowserTest { | 924 : public NavigationHandleImplBrowserTest { |
910 public: | 925 public: |
911 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, | 926 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, |
912 const GURL& iframe_secure_url) { | 927 const GURL& iframe_secure_url) { |
913 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); | 928 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 shell()->web_contents(), NavigationThrottle::PROCEED, | 1043 shell()->web_contents(), NavigationThrottle::PROCEED, |
1029 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 1044 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
1030 NavigationHandleObserver observer(shell()->web_contents(), url); | 1045 NavigationHandleObserver observer(shell()->web_contents(), url); |
1031 EXPECT_TRUE(NavigateToURL(shell(), url)); | 1046 EXPECT_TRUE(NavigateToURL(shell(), url)); |
1032 EXPECT_EQ(1, installer.will_start_called()); | 1047 EXPECT_EQ(1, installer.will_start_called()); |
1033 EXPECT_EQ(1, installer.will_process_called()); | 1048 EXPECT_EQ(1, installer.will_process_called()); |
1034 EXPECT_FALSE(observer.is_same_page()); | 1049 EXPECT_FALSE(observer.is_same_page()); |
1035 } | 1050 } |
1036 } | 1051 } |
1037 | 1052 |
1053 // Record and list the navigations that are started and finished. | |
1054 class NavigationLogger : public WebContentsObserver { | |
1055 public: | |
1056 NavigationLogger(WebContents* web_contents) | |
1057 : WebContentsObserver(web_contents) {} | |
1058 | |
1059 void DidStartNavigation(NavigationHandle* navigation_handle) override { | |
1060 started_navigation_urls_.push_back(navigation_handle->GetURL()); | |
1061 } | |
1062 | |
1063 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | |
1064 finished_navigation_urls_.push_back(navigation_handle->GetURL()); | |
1065 } | |
1066 | |
1067 const std::vector<GURL>& started_navigation_urls() const { | |
1068 return started_navigation_urls_; | |
1069 } | |
1070 const std::vector<GURL>& finished_navigation_urls() const { | |
1071 return finished_navigation_urls_; | |
1072 } | |
1073 | |
1074 private: | |
1075 std::vector<GURL> started_navigation_urls_; | |
1076 std::vector<GURL> finished_navigation_urls_; | |
1077 }; | |
1078 | |
1079 // There was a bug without PlzNavigate that happened when a navigation was | |
1080 // blocked after a redirect. Blink didn't know about the redirect and tried | |
1081 // to commit an error page to the post-redirect URL. The result was that the | |
Charlie Reis
2017/03/09 17:39:03
Did you mean pre-redirect URL?
arthursonzogni
2017/03/10 11:55:28
Yes thanks!
| |
1082 // NavigationHandle was not found on the browser-side and a new NavigationHandle | |
1083 // created for committing the error page. This test makes sure that only one | |
1084 // NavigationHandle is used for committing the error page. | |
1085 // See crbug.com/695421 | |
1086 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, BlockedOnRedirect) { | |
1087 const GURL kUrl = embedded_test_server()->GetURL("/title1.html"); | |
1088 const GURL kRedirectingUrl = | |
1089 embedded_test_server()->GetURL("/server-redirect?" + kUrl.spec()); | |
1090 | |
1091 // Set up a NavigationThrottle that will block the navigation in | |
1092 // WillRedirectRequest. | |
1093 TestNavigationThrottleInstaller installer( | |
1094 shell()->web_contents(), NavigationThrottle::PROCEED, | |
1095 NavigationThrottle::BLOCK_REQUEST, NavigationThrottle::PROCEED); | |
1096 NavigationHandleObserver observer(shell()->web_contents(), kRedirectingUrl); | |
1097 NavigationLogger logger(shell()->web_contents()); | |
1098 | |
1099 // Try to navigate to the url. The navigation should be canceled and the | |
1100 // NavigationHandle should have the right error code. | |
1101 EXPECT_FALSE(NavigateToURL(shell(), kRedirectingUrl)); | |
1102 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); | |
1103 | |
1104 // Only one navigation is expected to happen. | |
1105 std::vector<GURL> started_navigation = {kRedirectingUrl}; | |
1106 EXPECT_EQ(started_navigation, logger.started_navigation_urls()); | |
1107 | |
1108 std::vector<GURL> finished_navigation; | |
1109 if (IsBrowserSideNavigationEnabled()) | |
1110 finished_navigation = {kUrl}; | |
1111 else | |
1112 finished_navigation = {kRedirectingUrl}; | |
Charlie Reis
2017/03/09 17:39:03
I'm concerned that we have a difference in behavio
arthursonzogni
2017/03/10 11:55:28
The page is blocked on the post-redirect URL. So t
Charlie Reis
2017/03/13 20:48:02
My argument there was that the pre-redirect URL is
| |
1113 EXPECT_EQ(finished_navigation, logger.finished_navigation_urls()); | |
1114 } | |
1115 | |
1038 } // namespace content | 1116 } // namespace content |
OLD | NEW |