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/macros.h" | 8 #include "base/macros.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" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/captive_portal/captive_portal_service.h" | 12 #include "chrome/browser/captive_portal/captive_portal_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | 14 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
| 15 #include "chrome/common/features.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "components/captive_portal/captive_portal_testing_utils.h" | 18 #include "components/captive_portal/captive_portal_testing_utils.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "net/cert/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
21 #include "net/ssl/ssl_info.h" | 22 #include "net/ssl/ssl_info.h" |
22 #include "net/test/cert_test_util.h" | 23 #include "net/test/cert_test_util.h" |
23 #include "net/test/test_certificate_data.h" | 24 #include "net/test/test_certificate_data.h" |
24 #include "net/test/test_data_directory.h" | 25 #include "net/test/test_data_directory.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 157 } |
157 | 158 |
158 SSLErrorHandlerForTest* error_handler() { return error_handler_.get(); } | 159 SSLErrorHandlerForTest* error_handler() { return error_handler_.get(); } |
159 | 160 |
160 private: | 161 private: |
161 net::SSLInfo ssl_info_; | 162 net::SSLInfo ssl_info_; |
162 std::unique_ptr<SSLErrorHandlerForTest> error_handler_; | 163 std::unique_ptr<SSLErrorHandlerForTest> error_handler_; |
163 base::FieldTrialList field_trial_list_; | 164 base::FieldTrialList field_trial_list_; |
164 }; | 165 }; |
165 | 166 |
166 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 167 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
167 | 168 |
168 TEST_F(SSLErrorHandlerTest, | 169 TEST_F(SSLErrorHandlerTest, |
169 ShouldShowSSLInterstitialOnTimerExpired) { | 170 ShouldShowSSLInterstitialOnTimerExpired) { |
170 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 171 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
171 error_handler()->StartHandlingError(); | 172 error_handler()->StartHandlingError(); |
172 | 173 |
173 EXPECT_TRUE(error_handler()->IsTimerRunning()); | 174 EXPECT_TRUE(error_handler()->IsTimerRunning()); |
174 EXPECT_TRUE(error_handler()->captive_portal_checked()); | 175 EXPECT_TRUE(error_handler()->captive_portal_checked()); |
175 EXPECT_FALSE(error_handler()->ssl_interstitial_shown()); | 176 EXPECT_FALSE(error_handler()->ssl_interstitial_shown()); |
176 EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown()); | 177 EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 262 |
262 EXPECT_FALSE(error_handler()->suggested_url_checked()); | 263 EXPECT_FALSE(error_handler()->suggested_url_checked()); |
263 EXPECT_TRUE(error_handler()->captive_portal_checked()); | 264 EXPECT_TRUE(error_handler()->captive_portal_checked()); |
264 EXPECT_TRUE(error_handler()->IsTimerRunning()); | 265 EXPECT_TRUE(error_handler()->IsTimerRunning()); |
265 base::RunLoop().RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
266 | 267 |
267 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 268 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
268 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 269 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
269 } | 270 } |
270 | 271 |
271 #else // #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 272 #else // #if !BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
272 | 273 |
273 TEST_F(SSLErrorHandlerTest, | 274 TEST_F(SSLErrorHandlerTest, |
274 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) { | 275 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) { |
275 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 276 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
276 error_handler()->StartHandlingError(); | 277 error_handler()->StartHandlingError(); |
277 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 278 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
278 EXPECT_FALSE(error_handler()->captive_portal_checked()); | 279 EXPECT_FALSE(error_handler()->captive_portal_checked()); |
279 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 280 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
280 EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown()); | 281 EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown()); |
281 } | 282 } |
282 | 283 |
283 #endif // defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 284 #endif // BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
284 | 285 |
285 TEST_F(SSLErrorHandlerTest, | 286 TEST_F(SSLErrorHandlerTest, |
286 ShouldShowSSLInterstitialOnTimerExpiredWhenSuggestedUrlExists) { | 287 ShouldShowSSLInterstitialOnTimerExpiredWhenSuggestedUrlExists) { |
287 error_handler()->set_suggested_url_exists(); | 288 error_handler()->set_suggested_url_exists(); |
288 error_handler()->StartHandlingError(); | 289 error_handler()->StartHandlingError(); |
289 | 290 |
290 EXPECT_TRUE(error_handler()->IsTimerRunning()); | 291 EXPECT_TRUE(error_handler()->IsTimerRunning()); |
291 EXPECT_TRUE(error_handler()->suggested_url_checked()); | 292 EXPECT_TRUE(error_handler()->suggested_url_checked()); |
292 EXPECT_FALSE(error_handler()->ssl_interstitial_shown()); | 293 EXPECT_FALSE(error_handler()->ssl_interstitial_shown()); |
293 EXPECT_FALSE(error_handler()->redirected_to_suggested_url()); | 294 EXPECT_FALSE(error_handler()->redirected_to_suggested_url()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // Fake an Invalid Suggested URL Check result. | 332 // Fake an Invalid Suggested URL Check result. |
332 error_handler()->SendSuggestedUrlCheckResult( | 333 error_handler()->SendSuggestedUrlCheckResult( |
333 CommonNameMismatchHandler::SuggestedUrlCheckResult:: | 334 CommonNameMismatchHandler::SuggestedUrlCheckResult:: |
334 SUGGESTED_URL_NOT_AVAILABLE, | 335 SUGGESTED_URL_NOT_AVAILABLE, |
335 GURL()); | 336 GURL()); |
336 | 337 |
337 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 338 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
338 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 339 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
339 EXPECT_FALSE(error_handler()->redirected_to_suggested_url()); | 340 EXPECT_FALSE(error_handler()->redirected_to_suggested_url()); |
340 } | 341 } |
OLD | NEW |