OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/network_time/network_time_tracker.h" | 5 #include "components/network_time/network_time_tracker.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 const int64 kResolution1 = 17; | 23 const int64 kResolution1 = 17; |
24 const int64 kResolution2 = 177; | 24 const int64 kResolution2 = 177; |
25 | 25 |
26 const int64 kPseudoSleepTime1 = 500000001; | 26 const int64 kPseudoSleepTime1 = 500000001; |
27 const int64 kPseudoSleepTime2 = 1888; | 27 const int64 kPseudoSleepTime2 = 1888; |
28 | 28 |
29 // A custom tick clock that will return an arbitrary time. | 29 // A custom tick clock that will return an arbitrary time. |
30 class TestTickClock : public base::TickClock { | 30 class TestTickClock : public base::TickClock { |
31 public: | 31 public: |
32 explicit TestTickClock(base::TimeTicks* ticks_now) : ticks_now_(ticks_now) {} | 32 explicit TestTickClock(base::TimeTicks* ticks_now) : ticks_now_(ticks_now) {} |
33 virtual ~TestTickClock() {} | |
34 | 33 |
35 virtual base::TimeTicks NowTicks() override { | 34 virtual base::TimeTicks NowTicks() override { |
36 return *ticks_now_; | 35 return *ticks_now_; |
37 } | 36 } |
38 | 37 |
39 private: | 38 private: |
| 39 virtual ~TestTickClock() {} |
| 40 |
40 base::TimeTicks* ticks_now_; | 41 base::TimeTicks* ticks_now_; |
41 }; | 42 }; |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 class NetworkTimeTrackerTest : public testing::Test { | 46 class NetworkTimeTrackerTest : public testing::Test { |
46 public: | 47 public: |
47 virtual ~NetworkTimeTrackerTest() {} | 48 virtual ~NetworkTimeTrackerTest() {} |
48 | 49 |
49 virtual void SetUp() override { | 50 virtual void SetUp() override { |
50 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); | 51 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); |
51 | 52 |
52 now_ = base::Time::NowFromSystemTime(); | 53 now_ = base::Time::NowFromSystemTime(); |
53 network_time_tracker_.reset(new NetworkTimeTracker( | 54 network_time_tracker_.reset(new NetworkTimeTracker( |
54 scoped_ptr<base::TickClock>(new TestTickClock(&ticks_now_)), | 55 scoped_refptr<base::TickClock>(new TestTickClock(&ticks_now_)), |
55 &pref_service_)); | 56 &pref_service_)); |
56 } | 57 } |
57 | 58 |
58 base::Time Now() const { | 59 base::Time Now() const { |
59 return now_ + (ticks_now_ - base::TimeTicks()); | 60 return now_ + (ticks_now_ - base::TimeTicks()); |
60 } | 61 } |
61 | 62 |
62 base::TimeTicks TicksNow() const { | 63 base::TimeTicks TicksNow() const { |
63 return ticks_now_; | 64 return ticks_now_; |
64 } | 65 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 AddToTicksNow(kPseudoSleepTime2); | 155 AddToTicksNow(kPseudoSleepTime2); |
155 UpdateNetworkTime( | 156 UpdateNetworkTime( |
156 old_now, | 157 old_now, |
157 base::TimeDelta::FromMilliseconds(kResolution2), | 158 base::TimeDelta::FromMilliseconds(kResolution2), |
158 base::TimeDelta::FromMilliseconds(kLatency2), | 159 base::TimeDelta::FromMilliseconds(kLatency2), |
159 old_ticks); | 160 old_ticks); |
160 EXPECT_TRUE(ValidateExpectedTime()); | 161 EXPECT_TRUE(ValidateExpectedTime()); |
161 } | 162 } |
162 | 163 |
163 } // namespace network_time | 164 } // namespace network_time |
OLD | NEW |