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

Side by Side Diff: components/ssl_errors/error_classification_unittest.cc

Issue 2447183002: Refactor network_time_test_utils (Closed)
Patch Set: another BUILD.gn fix Created 4 years, 1 month 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 | « components/network_time/network_time_tracker_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/ssl_errors/error_classification.h" 5 #include "components/ssl_errors/error_classification.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 21 matching lines...) Expand all
32 const char kNetworkTimeHistogram[] = "interstitial.ssl.clockstate.network3"; 32 const char kNetworkTimeHistogram[] = "interstitial.ssl.clockstate.network3";
33 33
34 static std::unique_ptr<net::test_server::HttpResponse> 34 static std::unique_ptr<net::test_server::HttpResponse>
35 NetworkErrorResponseHandler(const net::test_server::HttpRequest& request) { 35 NetworkErrorResponseHandler(const net::test_server::HttpRequest& request) {
36 return std::unique_ptr<net::test_server::HttpResponse>( 36 return std::unique_ptr<net::test_server::HttpResponse>(
37 new net::test_server::RawHttpResponse("", "")); 37 new net::test_server::RawHttpResponse("", ""));
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 class SSLErrorClassificationTest : public network_time::FieldTrialTest { 42 class SSLErrorClassificationTest : public ::testing::Test {
43 public: 43 public:
44 SSLErrorClassificationTest() : network_time::FieldTrialTest() {} 44 SSLErrorClassificationTest()
45 : field_trial_test_(new network_time::FieldTrialTest()) {}
46 network_time::FieldTrialTest* field_trial_test() {
47 return field_trial_test_.get();
48 }
49
50 private:
51 std::unique_ptr<network_time::FieldTrialTest> field_trial_test_;
45 }; 52 };
46 53
47 TEST_F(SSLErrorClassificationTest, TestNameMismatch) { 54 TEST_F(SSLErrorClassificationTest, TestNameMismatch) {
48 scoped_refptr<net::X509Certificate> google_cert( 55 scoped_refptr<net::X509Certificate> google_cert(
49 net::X509Certificate::CreateFromBytes( 56 net::X509Certificate::CreateFromBytes(
50 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 57 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
51 ASSERT_TRUE(google_cert.get()); 58 ASSERT_TRUE(google_cert.get());
52 std::vector<std::string> dns_names_google; 59 std::vector<std::string> dns_names_google;
53 google_cert->GetDNSNames(&dns_names_google); 60 google_cert->GetDNSNames(&dns_names_google);
54 ASSERT_EQ(1u, dns_names_google.size()); // ["www.google.com"] 61 ASSERT_EQ(1u, dns_names_google.size()); // ["www.google.com"]
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Do this to be sure that |is_null| returns false. 349 // Do this to be sure that |is_null| returns false.
343 clock->Advance(base::TimeDelta::FromDays(111)); 350 clock->Advance(base::TimeDelta::FromDays(111));
344 tick_clock->Advance(base::TimeDelta::FromDays(222)); 351 tick_clock->Advance(base::TimeDelta::FromDays(222));
345 352
346 base::MessageLoop loop; 353 base::MessageLoop loop;
347 network_time::NetworkTimeTracker network_time_tracker( 354 network_time::NetworkTimeTracker network_time_tracker(
348 std::unique_ptr<base::Clock>(clock), 355 std::unique_ptr<base::Clock>(clock),
349 std::unique_ptr<base::TickClock>(tick_clock), &pref_service, 356 std::unique_ptr<base::TickClock>(tick_clock), &pref_service,
350 new net::TestURLRequestContextGetter(io_thread.task_runner())); 357 new net::TestURLRequestContextGetter(io_thread.task_runner()));
351 network_time_tracker.SetTimeServerURLForTesting(test_server.GetURL("/")); 358 network_time_tracker.SetTimeServerURLForTesting(test_server.GetURL("/"));
352 SetNetworkQueriesWithVariationsService(true, 0.0); 359 field_trial_test()->SetNetworkQueriesWithVariationsService(
360 true, 0.0, network_time::FieldTrialTest::ENABLE_FETCHES_ON_DEMAND);
353 361
354 // No sync attempt. 362 // No sync attempt.
355 EXPECT_EQ( 363 EXPECT_EQ(
356 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN, 364 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN,
357 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); 365 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
358 histograms.ExpectTotalCount(kNetworkTimeHistogram, 1); 366 histograms.ExpectTotalCount(kNetworkTimeHistogram, 1);
359 histograms.ExpectBucketCount( 367 histograms.ExpectBucketCount(
360 kNetworkTimeHistogram, 368 kNetworkTimeHistogram,
361 ssl_errors::NETWORK_CLOCK_STATE_UNKNOWN_NO_SYNC_ATTEMPT, 1); 369 ssl_errors::NETWORK_CLOCK_STATE_UNKNOWN_NO_SYNC_ATTEMPT, 1);
362 370
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 clock->Advance(base::TimeDelta::FromDays(1)); 442 clock->Advance(base::TimeDelta::FromDays(1));
435 // GetClockState() will fall back to the build time heuristic. 443 // GetClockState() will fall back to the build time heuristic.
436 ssl_errors::GetClockState(clock->Now(), &network_time_tracker); 444 ssl_errors::GetClockState(clock->Now(), &network_time_tracker);
437 histograms.ExpectTotalCount(kNetworkTimeHistogram, 8); 445 histograms.ExpectTotalCount(kNetworkTimeHistogram, 8);
438 histograms.ExpectBucketCount( 446 histograms.ExpectBucketCount(
439 kNetworkTimeHistogram, ssl_errors::NETWORK_CLOCK_STATE_UNKNOWN_SYNC_LOST, 447 kNetworkTimeHistogram, ssl_errors::NETWORK_CLOCK_STATE_UNKNOWN_SYNC_LOST,
440 1); 448 1);
441 449
442 io_thread.Stop(); 450 io_thread.Stop();
443 } 451 }
OLDNEW
« no previous file with comments | « components/network_time/network_time_tracker_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698