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

Side by Side Diff: chrome/browser/metrics/variations/network_time_tracker_unittest.cc

Issue 12096096: Give access to a network time kept in the variation service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2nd round of CR comments, new file and tests. Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/threading/platform_thread.h"
6 #include "chrome/browser/metrics/variations/network_time_tracker.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 // These are all in milliseconds.
12 const int64 kLatency1 = 50;
13 const int64 kLatency2 = 500;
14
15 // Can not be smaller than 15, it's the NowFromSystemTime() resolution.
16 const int64 kResolution1 = 17;
17 const int64 kResolution2 = 177;
18
19 const int64 kSleepTime1 = 500;
20 const int64 kSleepTime2 = 333;
21
22 void ValidateCurrentTime(const NetworkTimeTracker& network_time_tracker) {
23 base::Time expected_time = base::Time::NowFromSystemTime();
24 base::Time network_time;
25 base::TimeDelta uncertainty;
26 EXPECT_TRUE(network_time_tracker.GetNetworkTime(&network_time,
27 &uncertainty));
28 EXPECT_LE(abs(expected_time.ToInternalValue() -
29 network_time.ToInternalValue()), uncertainty.ToInternalValue());
30 }
31
32 }
Alexei Svitkine (slow) 2013/02/04 21:23:18 Nit: Add "// namespace".
MAD 2013/02/05 01:05:55 Done.
33
34 TEST(NetworkTimeTrackerTest, ProperTimeTracking) {
35 NetworkTimeTracker network_time_tracker;
36
37 // Should not return a value before UpdateNetworkTime gets called.
38 base::Time network_time;
39 base::TimeDelta uncertainty;
40 EXPECT_FALSE(network_time_tracker.GetNetworkTime(&network_time,
41 &uncertainty));
42
43 // Update the time based on NowFromSystemTime and kLatency1.
44 network_time_tracker.UpdateNetworkTime(
45 base::Time::NowFromSystemTime(),
46 base::TimeDelta::FromMilliseconds(kResolution1),
47 base::TimeDelta::FromMilliseconds(kLatency1));
48 ValidateCurrentTime(network_time_tracker);
49
50 // Wait for kSleepTime1 to make sure we keep tracking.
51 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kSleepTime1));
Alexei Svitkine (slow) 2013/02/04 21:23:18 Instead of making the test sleep (which makes the
MAD 2013/02/05 01:05:55 Done.
52 ValidateCurrentTime(network_time_tracker);
53
54 // Update the time with a new NowFromSystemTime value and kLatency2.
55 network_time_tracker.UpdateNetworkTime(
56 base::Time::NowFromSystemTime(),
57 base::TimeDelta::FromMilliseconds(kResolution2),
58 base::TimeDelta::FromMilliseconds(kLatency2));
59
60 // Wait for kSleepTime2 to make sure we keep tracking still.
61 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kSleepTime2));
62 ValidateCurrentTime(network_time_tracker);
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698