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

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: pass "gn check out/Default" 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
« no previous file with comments | « components/ssl_errors/error_classification.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | 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/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()), &pref_service);
194 EXPECT_EQ(
195 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN,
196 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
197
198 ssl_errors::SetBuildTimeForTesting(base::Time::Now() -
199 base::TimeDelta::FromDays(367));
200 EXPECT_EQ(
201 ssl_errors::ClockState::CLOCK_STATE_FUTURE,
202 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
203
204 ssl_errors::SetBuildTimeForTesting(base::Time::Now() +
205 base::TimeDelta::FromDays(3));
206 EXPECT_EQ(
207 ssl_errors::ClockState::CLOCK_STATE_PAST,
208 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
209
210 // Intentionally leave the build time alone. It should be ignored
211 // in favor of network time.
212 network_time_tracker.UpdateNetworkTime(
213 base::Time::Now() + base::TimeDelta::FromHours(1),
214 base::TimeDelta::FromSeconds(1), // resolution
215 base::TimeDelta::FromMilliseconds(250), // latency
216 base::TimeTicks::Now()); // posting time
217 EXPECT_EQ(
218 ssl_errors::ClockState::CLOCK_STATE_PAST,
219 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
220
221 network_time_tracker.UpdateNetworkTime(
222 base::Time::Now() - base::TimeDelta::FromHours(1),
223 base::TimeDelta::FromSeconds(1), // resolution
224 base::TimeDelta::FromMilliseconds(250), // latency
225 base::TimeTicks::Now()); // posting time
226 EXPECT_EQ(
227 ssl_errors::ClockState::CLOCK_STATE_FUTURE,
228 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
229
230 network_time_tracker.UpdateNetworkTime(
231 base::Time::Now(),
232 base::TimeDelta::FromSeconds(1), // resolution
233 base::TimeDelta::FromMilliseconds(250), // latency
234 base::TimeTicks::Now()); // posting time
235 EXPECT_EQ(
236 ssl_errors::ClockState::CLOCK_STATE_OK,
237 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
238
239 // Now clear the network time. The build time should reassert
240 // itself.
241 network_time_tracker.UpdateNetworkTime(
242 base::Time(),
243 base::TimeDelta::FromSeconds(1), // resolution
244 base::TimeDelta::FromMilliseconds(250), // latency
245 base::TimeTicks::Now()); // posting time
246 ssl_errors::SetBuildTimeForTesting(base::Time::Now() +
247 base::TimeDelta::FromDays(3));
248 EXPECT_EQ(
249 ssl_errors::ClockState::CLOCK_STATE_PAST,
250 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
251
252 // Now set the build time to something reasonable. We should be
253 // back to the know-nothing state.
254 ssl_errors::SetBuildTimeForTesting(base::Time::Now());
255 EXPECT_EQ(
256 ssl_errors::ClockState::CLOCK_STATE_UNKNOWN,
257 ssl_errors::GetClockState(base::Time::Now(), &network_time_tracker));
258 }
OLDNEW
« no previous file with comments | « components/ssl_errors/error_classification.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698