| OLD | NEW |
| 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/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/time/default_clock.h" | 10 #include "base/time/default_clock.h" |
| 11 #include "base/time/default_tick_clock.h" | 11 #include "base/time/default_tick_clock.h" |
| 12 #include "components/network_time/network_time_tracker.h" | 12 #include "components/network_time/network_time_tracker.h" |
| 13 #include "components/prefs/testing_pref_service.h" | 13 #include "components/prefs/testing_pref_service.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/test_data_directory.h" | 15 #include "net/base/test_data_directory.h" |
| 16 #include "net/cert/x509_cert_types.h" | 16 #include "net/cert/x509_cert_types.h" |
| 17 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
| 18 #include "net/test/cert_test_util.h" | 18 #include "net/test/cert_test_util.h" |
| 19 #include "net/test/test_certificate_data.h" | 19 #include "net/test/test_certificate_data.h" |
| 20 #include "net/url_request/url_request_test_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 class SSLErrorClassificationTest : public testing::Test {}; | 24 class SSLErrorClassificationTest : public testing::Test {}; |
| 24 | 25 |
| 25 TEST_F(SSLErrorClassificationTest, TestNameMismatch) { | 26 TEST_F(SSLErrorClassificationTest, TestNameMismatch) { |
| 26 scoped_refptr<net::X509Certificate> google_cert( | 27 scoped_refptr<net::X509Certificate> google_cert( |
| 27 net::X509Certificate::CreateFromBytes( | 28 net::X509Certificate::CreateFromBytes( |
| 28 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 29 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
| 29 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), google_cert.get()); | 30 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), google_cert.get()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 183 |
| 183 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("yyy", "xxxxxxx")); | 184 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("yyy", "xxxxxxx")); |
| 184 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("xxxxxxx", "yyy")); | 185 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("xxxxxxx", "yyy")); |
| 185 } | 186 } |
| 186 | 187 |
| 187 TEST_F(SSLErrorClassificationTest, GetClockState) { | 188 TEST_F(SSLErrorClassificationTest, GetClockState) { |
| 188 // This test aims to obtain all possible return values of | 189 // This test aims to obtain all possible return values of |
| 189 // |GetClockState|. | 190 // |GetClockState|. |
| 190 TestingPrefServiceSimple pref_service; | 191 TestingPrefServiceSimple pref_service; |
| 191 network_time::NetworkTimeTracker::RegisterPrefs(pref_service.registry()); | 192 network_time::NetworkTimeTracker::RegisterPrefs(pref_service.registry()); |
| 193 base::MessageLoop loop; |
| 192 network_time::NetworkTimeTracker network_time_tracker( | 194 network_time::NetworkTimeTracker network_time_tracker( |
| 193 base::WrapUnique(new base::DefaultClock()), | 195 base::WrapUnique(new base::DefaultClock()), |
| 194 base::WrapUnique(new base::DefaultTickClock()), &pref_service); | 196 base::WrapUnique(new base::DefaultTickClock()), &pref_service, |
| 197 new net::TestURLRequestContextGetter( |
| 198 base::ThreadTaskRunnerHandle::Get())); |
| 199 |
| 195 EXPECT_EQ( | 200 EXPECT_EQ( |
| 196 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN, | 201 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN, |
| 197 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); | 202 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); |
| 198 | 203 |
| 199 ssl_errors::SetBuildTimeForTesting(base::Time::Now() - | 204 ssl_errors::SetBuildTimeForTesting(base::Time::Now() - |
| 200 base::TimeDelta::FromDays(367)); | 205 base::TimeDelta::FromDays(367)); |
| 201 EXPECT_EQ( | 206 EXPECT_EQ( |
| 202 ssl_errors::ClockState::CLOCK_STATE_FUTURE, | 207 ssl_errors::ClockState::CLOCK_STATE_FUTURE, |
| 203 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); | 208 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); |
| 204 | 209 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 ssl_errors::ClockState::CLOCK_STATE_PAST, | 255 ssl_errors::ClockState::CLOCK_STATE_PAST, |
| 251 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); | 256 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); |
| 252 | 257 |
| 253 // Now set the build time to something reasonable. We should be | 258 // Now set the build time to something reasonable. We should be |
| 254 // back to the know-nothing state. | 259 // back to the know-nothing state. |
| 255 ssl_errors::SetBuildTimeForTesting(base::Time::Now()); | 260 ssl_errors::SetBuildTimeForTesting(base::Time::Now()); |
| 256 EXPECT_EQ( | 261 EXPECT_EQ( |
| 257 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN, | 262 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN, |
| 258 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); | 263 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker)); |
| 259 } | 264 } |
| OLD | NEW |