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

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

Issue 1772143002: Use network time for bad clock interstitial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: estark review 1 Created 4 years, 9 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
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/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/time/default_clock.h"
10 #include "base/time/default_tick_clock.h"
11 #include "components/network_time/network_time_tracker.h"
12 #include "components/prefs/testing_pref_service.h"
9 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
10 #include "net/base/test_data_directory.h" 14 #include "net/base/test_data_directory.h"
11 #include "net/cert/x509_cert_types.h" 15 #include "net/cert/x509_cert_types.h"
12 #include "net/cert/x509_certificate.h" 16 #include "net/cert/x509_certificate.h"
13 #include "net/test/cert_test_util.h" 17 #include "net/test/cert_test_util.h"
14 #include "net/test/test_certificate_data.h" 18 #include "net/test/test_certificate_data.h"
15 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 20 #include "url/gurl.h"
17 21
18 class SSLErrorClassificationTest : public testing::Test {}; 22 class SSLErrorClassificationTest : public testing::Test {};
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 175
172 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("", "abcd")); 176 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("", "abcd"));
173 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("abcd", "")); 177 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("abcd", ""));
174 178
175 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("xxx", "xxxxxxx")); 179 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("xxx", "xxxxxxx"));
176 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("xxxxxxx", "xxx")); 180 EXPECT_EQ(4u, ssl_errors::GetLevenshteinDistance("xxxxxxx", "xxx"));
177 181
178 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("yyy", "xxxxxxx")); 182 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("yyy", "xxxxxxx"));
179 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("xxxxxxx", "yyy")); 183 EXPECT_EQ(7u, ssl_errors::GetLevenshteinDistance("xxxxxxx", "yyy"));
180 } 184 }
185
186 TEST_F(SSLErrorClassificationTest, GetClockState) {
187 // This test aims to obtain all possible return values of
188 // |GetClockState|.
189 TestingPrefServiceSimple pref_service;
190 network_time::NetworkTimeTracker::RegisterPrefs(pref_service.registry());
191 network_time::NetworkTimeTracker network_time_tracker(
192 make_scoped_ptr(new base::DefaultClock()),
193 make_scoped_ptr(new base::DefaultTickClock()),
194 &pref_service);
195 EXPECT_EQ(
196 ssl_errors::ClockState::UNKNOWN,
197 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
198
199 ssl_errors::SetBuildTimeForTesting(
200 base::Time::Now() - base::TimeDelta::FromDays(367));
201 EXPECT_EQ(
202 ssl_errors::ClockState::BUILD_FUTURE,
203 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
204
205 ssl_errors::SetBuildTimeForTesting(
206 base::Time::Now() + base::TimeDelta::FromDays(3));
207 EXPECT_EQ(
208 ssl_errors::ClockState::BUILD_PAST,
209 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
210
211 // Intentionally leave the build time alone. It should be ignored
212 // in favor of network time.
213 network_time_tracker.UpdateNetworkTime(
214 base::Time::Now() + base::TimeDelta::FromHours(1),
215 base::TimeDelta::FromSeconds(1), // resolution
216 base::TimeDelta::FromMilliseconds(250), // latency
217 base::TimeTicks::Now()); // posting time
218 EXPECT_EQ(
219 ssl_errors::ClockState::NETWORK_PAST,
220 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
221
222 network_time_tracker.UpdateNetworkTime(
223 base::Time::Now() - base::TimeDelta::FromHours(1),
224 base::TimeDelta::FromSeconds(1), // resolution
225 base::TimeDelta::FromMilliseconds(250), // latency
226 base::TimeTicks::Now()); // posting time
227 EXPECT_EQ(
228 ssl_errors::ClockState::NETWORK_FUTURE,
229 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
230
231 network_time_tracker.UpdateNetworkTime(
232 base::Time::Now(),
233 base::TimeDelta::FromSeconds(1), // resolution
234 base::TimeDelta::FromMilliseconds(250), // latency
235 base::TimeTicks::Now()); // posting time
236 EXPECT_EQ(
237 ssl_errors::ClockState::NETWORK_OK,
238 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
239
240 // Now clear the network time. The build time should reassert
241 // itself.
242 network_time_tracker.UpdateNetworkTime(
243 base::Time(),
244 base::TimeDelta::FromSeconds(1), // resolution
245 base::TimeDelta::FromMilliseconds(250), // latency
246 base::TimeTicks::Now()); // posting time
247 ssl_errors::SetBuildTimeForTesting(
248 base::Time::Now() + base::TimeDelta::FromDays(3));
249 EXPECT_EQ(
250 ssl_errors::ClockState::BUILD_PAST,
251 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
252
253 // Now set the build time to something reasonable. We should be
254 // back to the know-nothing state.
255 ssl_errors::SetBuildTimeForTesting(base::Time::Now());
256 EXPECT_EQ(
257 ssl_errors::ClockState::UNKNOWN,
258 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
259 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698