Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Side by Side Diff: chrome/browser/ssl/ssl_error_handler_unittest.cc

Issue 2610183004: Wrap SSL error handler configuration with a lazy instance (Closed)
Patch Set: Add ForTesting to config setter methods Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ssl/ssl_error_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandlerForTest); 161 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandlerForTest);
162 }; 162 };
163 163
164 class SSLErrorHandlerNameMismatchTest : public ChromeRenderViewHostTestHarness { 164 class SSLErrorHandlerNameMismatchTest : public ChromeRenderViewHostTestHarness {
165 public: 165 public:
166 SSLErrorHandlerNameMismatchTest() : field_trial_list_(nullptr) {} 166 SSLErrorHandlerNameMismatchTest() : field_trial_list_(nullptr) {}
167 167
168 void SetUp() override { 168 void SetUp() override {
169 ChromeRenderViewHostTestHarness::SetUp(); 169 ChromeRenderViewHostTestHarness::SetUp();
170 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); 170 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta());
171 ssl_info_.cert = 171 ssl_info_.cert =
172 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 172 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
173 ssl_info_.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; 173 ssl_info_.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
174 error_handler_.reset( 174 error_handler_.reset(
175 new SSLErrorHandlerForTest(profile(), web_contents(), ssl_info_)); 175 new SSLErrorHandlerForTest(profile(), web_contents(), ssl_info_));
176 // Enable finch experiment for captive portal interstitials. 176 // Enable finch experiment for captive portal interstitials.
177 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 177 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
178 "CaptivePortalInterstitial", "Enabled")); 178 "CaptivePortalInterstitial", "Enabled"));
179 // Enable finch experiment for SSL common name mismatch handling. 179 // Enable finch experiment for SSL common name mismatch handling.
180 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 180 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 std::unique_ptr<base::Clock>(clock_), 218 std::unique_ptr<base::Clock>(clock_),
219 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_, 219 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_,
220 new net::TestURLRequestContextGetter( 220 new net::TestURLRequestContextGetter(
221 content::BrowserThread::GetTaskRunnerForThread( 221 content::BrowserThread::GetTaskRunnerForThread(
222 content::BrowserThread::IO)))); 222 content::BrowserThread::IO))));
223 223
224 // Do this to be sure that |is_null| returns false. 224 // Do this to be sure that |is_null| returns false.
225 clock_->Advance(base::TimeDelta::FromDays(111)); 225 clock_->Advance(base::TimeDelta::FromDays(111));
226 tick_clock_->Advance(base::TimeDelta::FromDays(222)); 226 tick_clock_->Advance(base::TimeDelta::FromDays(222));
227 227
228 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); 228 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta());
229 ssl_info_.cert = 229 ssl_info_.cert =
230 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 230 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
231 ssl_info_.cert_status = net::CERT_STATUS_DATE_INVALID; 231 ssl_info_.cert_status = net::CERT_STATUS_DATE_INVALID;
232 error_handler_.reset( 232 error_handler_.reset(
233 new SSLErrorHandlerForTest(profile(), web_contents(), ssl_info_)); 233 new SSLErrorHandlerForTest(profile(), web_contents(), ssl_info_));
234 error_handler_->SetNetworkTimeTrackerForTest(tracker_.get()); 234 error_handler_->SetNetworkTimeTrackerForTesting(tracker_.get());
235 235
236 // Fix flakiness in case system time is off and triggers a bad clock 236 // Fix flakiness in case system time is off and triggers a bad clock
237 // interstitial. https://crbug.com/666821#c50 237 // interstitial. https://crbug.com/666821#c50
238 ssl_errors::SetBuildTimeForTesting(base::Time::Now()); 238 ssl_errors::SetBuildTimeForTesting(base::Time::Now());
239 } 239 }
240 240
241 void TearDown() override { 241 void TearDown() override {
242 if (error_handler()) { 242 if (error_handler()) {
243 EXPECT_FALSE(error_handler()->IsTimerRunning()); 243 EXPECT_FALSE(error_handler()->IsTimerRunning());
244 error_handler_.reset(nullptr); 244 error_handler_.reset(nullptr);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 449
450 EXPECT_FALSE(error_handler()->IsTimerRunning()); 450 EXPECT_FALSE(error_handler()->IsTimerRunning());
451 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); 451 EXPECT_TRUE(error_handler()->ssl_interstitial_shown());
452 EXPECT_FALSE(error_handler()->redirected_to_suggested_url()); 452 EXPECT_FALSE(error_handler()->redirected_to_suggested_url());
453 } 453 }
454 454
455 TEST_F(SSLErrorHandlerDateInvalidTest, TimeQueryStarted) { 455 TEST_F(SSLErrorHandlerDateInvalidTest, TimeQueryStarted) {
456 base::HistogramTester histograms; 456 base::HistogramTester histograms;
457 base::Time network_time; 457 base::Time network_time;
458 base::TimeDelta uncertainty; 458 base::TimeDelta uncertainty;
459 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); 459 SSLErrorHandler::SetInterstitialDelayForTesting(
460 base::TimeDelta::FromHours(1));
460 EXPECT_EQ(network_time::NetworkTimeTracker::NETWORK_TIME_NO_SYNC_ATTEMPT, 461 EXPECT_EQ(network_time::NetworkTimeTracker::NETWORK_TIME_NO_SYNC_ATTEMPT,
461 tracker()->GetNetworkTime(&network_time, &uncertainty)); 462 tracker()->GetNetworkTime(&network_time, &uncertainty));
462 463
463 // Enable network time queries and handle the error. A bad clock interstitial 464 // Enable network time queries and handle the error. A bad clock interstitial
464 // should be shown. 465 // should be shown.
465 test_server()->RegisterRequestHandler( 466 test_server()->RegisterRequestHandler(
466 base::Bind(&network_time::GoodTimeResponseHandler)); 467 base::Bind(&network_time::GoodTimeResponseHandler));
467 EXPECT_TRUE(test_server()->Start()); 468 EXPECT_TRUE(test_server()->Start());
468 tracker()->SetTimeServerURLForTesting(test_server()->GetURL("/")); 469 tracker()->SetTimeServerURLForTesting(test_server()->GetURL("/"));
469 field_trial_test()->SetNetworkQueriesWithVariationsService( 470 field_trial_test()->SetNetworkQueriesWithVariationsService(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // Check that the histogram for the delay was recorded. 542 // Check that the histogram for the delay was recorded.
542 histograms.ExpectTotalCount(kCertDateErrorHistogram, 1); 543 histograms.ExpectTotalCount(kCertDateErrorHistogram, 1);
543 544
544 // Clear the error handler to test that, when the request completes, 545 // Clear the error handler to test that, when the request completes,
545 // it doesn't try to call a callback on a deleted SSLErrorHandler. 546 // it doesn't try to call a callback on a deleted SSLErrorHandler.
546 ClearErrorHandler(); 547 ClearErrorHandler();
547 548
548 // Shut down the server to cancel the pending request. 549 // Shut down the server to cancel the pending request.
549 ASSERT_TRUE(test_server()->ShutdownAndWaitUntilComplete()); 550 ASSERT_TRUE(test_server()->ShutdownAndWaitUntilComplete());
550 } 551 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_error_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698