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 "base/memory/weak_ptr.h" | |
| 5 #include "content/browser/frame_host/navigation_handle_impl.h" | 6 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 6 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
| 7 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 8 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
| 9 #include "content/public/common/request_context_type.h" | 10 #include "content/public/common/request_context_type.h" |
| 10 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 11 #include "content/public/test/content_browser_test.h" | 12 #include "content/public/test/content_browser_test.h" |
| 12 #include "content/public/test/content_browser_test_utils.h" | 13 #include "content/public/test/content_browser_test_utils.h" |
| 13 #include "content/public/test/test_navigation_observer.h" | 14 #include "content/public/test/test_navigation_observer.h" |
| 14 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 NavigationThrottle::ThrottleCheckResult will_start_result, | 200 NavigationThrottle::ThrottleCheckResult will_start_result, |
| 200 NavigationThrottle::ThrottleCheckResult will_redirect_result, | 201 NavigationThrottle::ThrottleCheckResult will_redirect_result, |
| 201 NavigationThrottle::ThrottleCheckResult will_process_result) | 202 NavigationThrottle::ThrottleCheckResult will_process_result) |
| 202 : WebContentsObserver(web_contents), | 203 : WebContentsObserver(web_contents), |
| 203 will_start_result_(will_start_result), | 204 will_start_result_(will_start_result), |
| 204 will_redirect_result_(will_redirect_result), | 205 will_redirect_result_(will_redirect_result), |
| 205 will_process_result_(will_process_result), | 206 will_process_result_(will_process_result), |
| 206 will_start_called_(0), | 207 will_start_called_(0), |
| 207 will_redirect_called_(0), | 208 will_redirect_called_(0), |
| 208 will_process_called_(0), | 209 will_process_called_(0), |
| 209 navigation_throttle_(nullptr) {} | 210 navigation_throttle_(nullptr), |
| 210 ~TestNavigationThrottleInstaller() override{}; | 211 weak_factory_(this) {} |
| 212 ~TestNavigationThrottleInstaller() override {} | |
| 211 | 213 |
| 212 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } | 214 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } |
| 213 | 215 |
| 214 void WaitForThrottleWillStart() { | 216 void WaitForThrottleWillStart() { |
| 215 if (will_start_called_) | 217 if (will_start_called_) |
| 216 return; | 218 return; |
| 217 will_start_loop_runner_ = new MessageLoopRunner(); | 219 will_start_loop_runner_ = new MessageLoopRunner(); |
| 218 will_start_loop_runner_->Run(); | 220 will_start_loop_runner_->Run(); |
| 219 will_start_loop_runner_ = nullptr; | 221 will_start_loop_runner_ = nullptr; |
| 220 } | 222 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 237 | 239 |
| 238 int will_start_called() { return will_start_called_; } | 240 int will_start_called() { return will_start_called_; } |
| 239 int will_redirect_called() { return will_redirect_called_; } | 241 int will_redirect_called() { return will_redirect_called_; } |
| 240 int will_process_called() { return will_process_called_; } | 242 int will_process_called() { return will_process_called_; } |
| 241 | 243 |
| 242 private: | 244 private: |
| 243 void DidStartNavigation(NavigationHandle* handle) override { | 245 void DidStartNavigation(NavigationHandle* handle) override { |
| 244 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( | 246 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( |
| 245 handle, will_start_result_, will_redirect_result_, will_process_result_, | 247 handle, will_start_result_, will_redirect_result_, will_process_result_, |
| 246 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, | 248 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, |
| 247 base::Unretained(this)), | 249 weak_factory_.GetWeakPtr()), |
| 248 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, | 250 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, |
| 249 base::Unretained(this)), | 251 weak_factory_.GetWeakPtr()), |
| 250 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, | 252 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, |
| 251 base::Unretained(this)))); | 253 weak_factory_.GetWeakPtr()))); |
| 252 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); | 254 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); |
| 253 handle->RegisterThrottleForTesting(std::move(throttle)); | 255 handle->RegisterThrottleForTesting(std::move(throttle)); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void DidFinishNavigation(NavigationHandle* handle) override { | 258 void DidFinishNavigation(NavigationHandle* handle) override { |
| 257 if (!navigation_throttle_) | 259 if (!navigation_throttle_) |
| 258 return; | 260 return; |
| 259 | 261 |
| 260 if (handle == navigation_throttle_->navigation_handle()) | 262 if (handle == navigation_throttle_->navigation_handle()) |
| 261 navigation_throttle_ = nullptr; | 263 navigation_throttle_ = nullptr; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 282 NavigationThrottle::ThrottleCheckResult will_start_result_; | 284 NavigationThrottle::ThrottleCheckResult will_start_result_; |
| 283 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 285 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
| 284 NavigationThrottle::ThrottleCheckResult will_process_result_; | 286 NavigationThrottle::ThrottleCheckResult will_process_result_; |
| 285 int will_start_called_; | 287 int will_start_called_; |
| 286 int will_redirect_called_; | 288 int will_redirect_called_; |
| 287 int will_process_called_; | 289 int will_process_called_; |
| 288 TestNavigationThrottle* navigation_throttle_; | 290 TestNavigationThrottle* navigation_throttle_; |
| 289 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; | 291 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; |
| 290 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; | 292 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; |
| 291 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; | 293 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; |
| 294 | |
| 295 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_; | |
|
nasko
2017/01/20 22:54:45
Can you add a comment as to why this weak factory
Alexander Semashko
2017/01/23 19:45:39
Done.
| |
| 292 }; | 296 }; |
| 293 | 297 |
| 294 // Records all navigation start URLs from the WebContents. | 298 // Records all navigation start URLs from the WebContents. |
| 295 class NavigationStartUrlRecorder : public WebContentsObserver { | 299 class NavigationStartUrlRecorder : public WebContentsObserver { |
| 296 public: | 300 public: |
| 297 NavigationStartUrlRecorder(WebContents* web_contents) | 301 NavigationStartUrlRecorder(WebContents* web_contents) |
| 298 : WebContentsObserver(web_contents) {} | 302 : WebContentsObserver(web_contents) {} |
| 299 | 303 |
| 300 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 304 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
| 301 urls_.push_back(navigation_handle->GetURL()); | 305 urls_.push_back(navigation_handle->GetURL()); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, | 902 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, |
| 899 StartUrlIsHttpsUpgradedCrossSite) { | 903 StartUrlIsHttpsUpgradedCrossSite) { |
| 900 GURL start_url( | 904 GURL start_url( |
| 901 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); | 905 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); |
| 902 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); | 906 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); |
| 903 | 907 |
| 904 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); | 908 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); |
| 905 } | 909 } |
| 906 | 910 |
| 907 } // namespace content | 911 } // namespace content |
| OLD | NEW |