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/request_context_type.h" | 10 #include "content/public/common/request_context_type.h" |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 shell()->web_contents(), NavigationThrottle::PROCEED, | 1060 shell()->web_contents(), NavigationThrottle::PROCEED, |
1061 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 1061 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
1062 NavigationHandleObserver observer(shell()->web_contents(), url); | 1062 NavigationHandleObserver observer(shell()->web_contents(), url); |
1063 EXPECT_TRUE(NavigateToURL(shell(), url)); | 1063 EXPECT_TRUE(NavigateToURL(shell(), url)); |
1064 EXPECT_EQ(1, installer.will_start_called()); | 1064 EXPECT_EQ(1, installer.will_start_called()); |
1065 EXPECT_EQ(1, installer.will_process_called()); | 1065 EXPECT_EQ(1, installer.will_process_called()); |
1066 EXPECT_FALSE(observer.is_same_page()); | 1066 EXPECT_FALSE(observer.is_same_page()); |
1067 } | 1067 } |
1068 } | 1068 } |
1069 | 1069 |
| 1070 // Record and list the navigations that are started and finished. |
| 1071 class NavigationLogger : public WebContentsObserver { |
| 1072 public: |
| 1073 NavigationLogger(WebContents* web_contents) |
| 1074 : WebContentsObserver(web_contents) {} |
| 1075 |
| 1076 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
| 1077 started_navigation_urls_.push_back(navigation_handle->GetURL()); |
| 1078 } |
| 1079 |
| 1080 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| 1081 finished_navigation_urls_.push_back(navigation_handle->GetURL()); |
| 1082 } |
| 1083 |
| 1084 const std::vector<GURL>& GetStartedNavigationURLS() { |
| 1085 return started_navigation_urls_; |
| 1086 } |
| 1087 const std::vector<GURL>& GetFinishedNavigationURLS() { |
| 1088 return finished_navigation_urls_; |
| 1089 } |
| 1090 |
| 1091 private: |
| 1092 std::vector<GURL> started_navigation_urls_; |
| 1093 std::vector<GURL> finished_navigation_urls_; |
| 1094 }; |
| 1095 |
| 1096 // There was a bug without PlzNavigate that happened when a navigation was |
| 1097 // blocked after a redirect. Blink didn't know about the redirect and tried |
| 1098 // to commit an error page to the post-redirect URL. The result was that the |
| 1099 // NavigationHandle was not found on the browser-side and a new NavigationHandle |
| 1100 // created for committing the error page. This test makes sure that only one |
| 1101 // NavigationHandle is used for committing the error page. |
| 1102 // See crbug.com/695421 |
| 1103 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, BlockedOnRedirect) { |
| 1104 const GURL kUrl = embedded_test_server()->GetURL("/title1.html"); |
| 1105 const GURL kRedirectingUrl = |
| 1106 embedded_test_server()->GetURL("/server-redirect?" + kUrl.spec()); |
| 1107 |
| 1108 // Set up a NavigationThrottle that will block the navigation in |
| 1109 // WillRedirectRequest. |
| 1110 TestNavigationThrottleInstaller installer( |
| 1111 shell()->web_contents(), NavigationThrottle::PROCEED, |
| 1112 NavigationThrottle::BLOCK_REQUEST, NavigationThrottle::PROCEED); |
| 1113 NavigationHandleObserver observer(shell()->web_contents(), kRedirectingUrl); |
| 1114 NavigationLogger logger(shell()->web_contents()); |
| 1115 |
| 1116 // Try to navigate to the url. The navigation should be canceled and the |
| 1117 // NavigationHandle should have the right error code. |
| 1118 EXPECT_FALSE(NavigateToURL(shell(), kRedirectingUrl)); |
| 1119 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); |
| 1120 |
| 1121 // Only one navigation is expected to happen. |
| 1122 std::vector<GURL> started_navigation = {kRedirectingUrl}; |
| 1123 EXPECT_EQ(started_navigation, logger.GetStartedNavigationURLS()); |
| 1124 |
| 1125 std::vector<GURL> finished_navigation = {kUrl}; |
| 1126 EXPECT_EQ(finished_navigation, logger.GetFinishedNavigationURLS()); |
| 1127 } |
| 1128 |
1070 } // namespace content | 1129 } // namespace content |
OLD | NEW |