Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 GURL(), | 35 GURL(), |
| 36 0, | 36 0, |
| 37 nullptr, | 37 nullptr, |
| 38 base::Callback<void(bool)>()), | 38 base::Callback<void(bool)>()), |
| 39 profile_(profile), | 39 profile_(profile), |
| 40 captive_portal_checked_(false), | 40 captive_portal_checked_(false), |
| 41 suggested_url_exists_(false), | 41 suggested_url_exists_(false), |
| 42 suggested_url_checked_(false), | 42 suggested_url_checked_(false), |
| 43 ssl_interstitial_shown_(false), | 43 ssl_interstitial_shown_(false), |
| 44 captive_portal_interstitial_shown_(false), | 44 captive_portal_interstitial_shown_(false), |
| 45 common_name_mismatch_redirect_(false) {} | 45 common_name_mismatch_redirect_(false), |
| 46 is_overridable_(true) {} | |
| 46 | 47 |
| 47 ~TestSSLErrorHandler() override { | 48 ~TestSSLErrorHandler() override { |
| 48 } | 49 } |
| 49 | 50 |
| 50 using SSLErrorHandler::StartHandlingError; | 51 using SSLErrorHandler::StartHandlingError; |
| 51 | 52 |
| 52 void SendCaptivePortalNotification( | 53 void SendCaptivePortalNotification( |
| 53 captive_portal::CaptivePortalResult result) { | 54 captive_portal::CaptivePortalResult result) { |
| 54 CaptivePortalService::Results results; | 55 CaptivePortalService::Results results; |
| 55 results.previous_result = captive_portal::RESULT_INTERNET_CONNECTED; | 56 results.previous_result = captive_portal::RESULT_INTERNET_CONNECTED; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 *suggested_url = GURL("www.example.com"); | 94 *suggested_url = GURL("www.example.com"); |
| 94 return true; | 95 return true; |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool suggested_url_checked() const { return suggested_url_checked_; } | 98 bool suggested_url_checked() const { return suggested_url_checked_; } |
| 98 | 99 |
| 99 bool common_name_mismatch_redirect() const { | 100 bool common_name_mismatch_redirect() const { |
| 100 return common_name_mismatch_redirect_; | 101 return common_name_mismatch_redirect_; |
| 101 } | 102 } |
| 102 | 103 |
| 104 void SetOverridable(bool is_overridable) { is_overridable_ = is_overridable; } | |
|
meacer
2015/08/20 23:15:22
lower case for simple setters (set_overridable_err
Bhanu Dev
2015/08/21 00:52:16
Done.
| |
| 105 | |
| 103 void Reset() { | 106 void Reset() { |
| 104 captive_portal_checked_ = false; | 107 captive_portal_checked_ = false; |
| 105 suggested_url_exists_ = false; | 108 suggested_url_exists_ = false; |
| 106 suggested_url_checked_ = false; | 109 suggested_url_checked_ = false; |
| 107 ssl_interstitial_shown_ = false; | 110 ssl_interstitial_shown_ = false; |
| 108 captive_portal_interstitial_shown_ = false; | 111 captive_portal_interstitial_shown_ = false; |
| 109 common_name_mismatch_redirect_ = false; | 112 common_name_mismatch_redirect_ = false; |
| 113 is_overridable_ = true; | |
|
meacer
2015/08/20 23:15:22
This method should only clear the counters. Each t
Bhanu Dev
2015/08/21 00:52:16
Done.
| |
| 110 } | 114 } |
| 111 | 115 |
| 112 private: | 116 private: |
| 113 void CheckForCaptivePortal() override { | 117 void CheckForCaptivePortal() override { |
| 114 captive_portal_checked_ = true; | 118 captive_portal_checked_ = true; |
| 115 } | 119 } |
| 116 | 120 |
| 117 void ShowSSLInterstitial() override { ssl_interstitial_shown_ = true; } | 121 void ShowSSLInterstitial() override { ssl_interstitial_shown_ = true; } |
| 118 | 122 |
| 119 void ShowCaptivePortalInterstitial(const GURL& landing_url) override { | 123 void ShowCaptivePortalInterstitial(const GURL& landing_url) override { |
| 120 captive_portal_interstitial_shown_ = true; | 124 captive_portal_interstitial_shown_ = true; |
| 121 } | 125 } |
| 122 | 126 |
| 123 void CheckSuggestedUrl(const GURL& suggested_url) override { | 127 void CheckSuggestedUrl(const GURL& suggested_url) override { |
| 124 suggested_url_checked_ = true; | 128 suggested_url_checked_ = true; |
| 125 } | 129 } |
| 126 | 130 |
| 127 void NavigateToSuggestedURL(const GURL& suggested_url) override { | 131 void NavigateToSuggestedURL(const GURL& suggested_url) override { |
| 128 common_name_mismatch_redirect_ = true; | 132 common_name_mismatch_redirect_ = true; |
| 129 } | 133 } |
| 130 | 134 |
| 135 bool IsOverridable() override { return is_overridable_; } | |
| 136 | |
| 131 Profile* profile_; | 137 Profile* profile_; |
| 132 bool captive_portal_checked_; | 138 bool captive_portal_checked_; |
| 133 bool suggested_url_exists_; | 139 bool suggested_url_exists_; |
| 134 bool suggested_url_checked_; | 140 bool suggested_url_checked_; |
| 135 bool ssl_interstitial_shown_; | 141 bool ssl_interstitial_shown_; |
| 136 bool captive_portal_interstitial_shown_; | 142 bool captive_portal_interstitial_shown_; |
| 137 bool common_name_mismatch_redirect_; | 143 bool common_name_mismatch_redirect_; |
| 144 bool is_overridable_; | |
|
meacer
2015/08/20 23:15:22
nit: Rename to is_overridable_error_
Bhanu Dev
2015/08/21 00:52:16
Done.
| |
| 138 | 145 |
| 139 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler); | 146 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler); |
| 140 }; | 147 }; |
| 141 | 148 |
| 142 class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness { | 149 class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness { |
| 143 public: | 150 public: |
| 144 SSLErrorHandlerTest() | 151 SSLErrorHandlerTest() |
| 145 : field_trial_list_(NULL) { | 152 : field_trial_list_(NULL) { |
| 146 } | 153 } |
| 147 | 154 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 | 268 |
| 262 EXPECT_TRUE(error_handler()->IsTimerRunning()); | 269 EXPECT_TRUE(error_handler()->IsTimerRunning()); |
| 263 EXPECT_TRUE(error_handler()->suggested_url_checked()); | 270 EXPECT_TRUE(error_handler()->suggested_url_checked()); |
| 264 EXPECT_FALSE(error_handler()->captive_portal_checked()); | 271 EXPECT_FALSE(error_handler()->captive_portal_checked()); |
| 265 base::RunLoop().RunUntilIdle(); | 272 base::RunLoop().RunUntilIdle(); |
| 266 | 273 |
| 267 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 274 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
| 268 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 275 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
| 269 } | 276 } |
| 270 | 277 |
| 278 TEST_F(SSLErrorHandlerTest, ShouldNotCheckSuggestedUrlOnNonOverridableError) { | |
|
meacer
2015/08/20 23:15:22
nit: Change the test name to ShouldNotHandleNameMi
Bhanu Dev
2015/08/21 00:52:16
Done.
| |
| 279 error_handler()->SetSuggestedUrlExists(true); | |
| 280 error_handler()->SetOverridable(false); | |
| 281 error_handler()->StartHandlingError(); | |
| 282 | |
| 283 EXPECT_FALSE(error_handler()->suggested_url_checked()); | |
| 284 EXPECT_TRUE(error_handler()->captive_portal_checked()); | |
| 285 EXPECT_TRUE(error_handler()->IsTimerRunning()); | |
| 286 base::RunLoop().RunUntilIdle(); | |
| 287 | |
| 288 EXPECT_FALSE(error_handler()->IsTimerRunning()); | |
| 289 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | |
| 290 } | |
| 291 | |
| 271 #else // #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 292 #else // #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 272 | 293 |
| 273 TEST_F(SSLErrorHandlerTest, | 294 TEST_F(SSLErrorHandlerTest, |
| 274 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) { | 295 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) { |
| 275 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 296 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
| 276 error_handler()->SetSuggestedUrlExists(false); | 297 error_handler()->SetSuggestedUrlExists(false); |
| 277 error_handler()->StartHandlingError(); | 298 error_handler()->StartHandlingError(); |
| 278 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 299 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
| 279 EXPECT_FALSE(error_handler()->captive_portal_checked()); | 300 EXPECT_FALSE(error_handler()->captive_portal_checked()); |
| 280 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 301 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 // Fake an Invalid Suggested URL Check result. | 353 // Fake an Invalid Suggested URL Check result. |
| 333 error_handler()->SendSuggestedUrlCheckResult( | 354 error_handler()->SendSuggestedUrlCheckResult( |
| 334 CommonNameMismatchHandler::SuggestedUrlCheckResult:: | 355 CommonNameMismatchHandler::SuggestedUrlCheckResult:: |
| 335 SUGGESTED_URL_NOT_AVAILABLE, | 356 SUGGESTED_URL_NOT_AVAILABLE, |
| 336 GURL()); | 357 GURL()); |
| 337 | 358 |
| 338 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 359 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
| 339 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 360 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
| 340 EXPECT_FALSE(error_handler()->common_name_mismatch_redirect()); | 361 EXPECT_FALSE(error_handler()->common_name_mismatch_redirect()); |
| 341 } | 362 } |
| OLD | NEW |