| 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 14 matching lines...) Expand all Loading... |
| 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() {} | 33 virtual ~TestTickClock() {} |
| 34 | 34 |
| 35 virtual base::TimeTicks NowTicks() OVERRIDE { | 35 virtual base::TimeTicks NowTicks() override { |
| 36 return *ticks_now_; | 36 return *ticks_now_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 base::TimeTicks* ticks_now_; | 40 base::TimeTicks* ticks_now_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 class NetworkTimeTrackerTest : public testing::Test { | 45 class NetworkTimeTrackerTest : public testing::Test { |
| 46 public: | 46 public: |
| 47 virtual ~NetworkTimeTrackerTest() {} | 47 virtual ~NetworkTimeTrackerTest() {} |
| 48 | 48 |
| 49 virtual void SetUp() OVERRIDE { | 49 virtual void SetUp() override { |
| 50 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); | 50 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); |
| 51 | 51 |
| 52 now_ = base::Time::NowFromSystemTime(); | 52 now_ = base::Time::NowFromSystemTime(); |
| 53 network_time_tracker_.reset(new NetworkTimeTracker( | 53 network_time_tracker_.reset(new NetworkTimeTracker( |
| 54 scoped_ptr<base::TickClock>(new TestTickClock(&ticks_now_)), | 54 scoped_ptr<base::TickClock>(new TestTickClock(&ticks_now_)), |
| 55 &pref_service_)); | 55 &pref_service_)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 base::Time Now() const { | 58 base::Time Now() const { |
| 59 return now_ + (ticks_now_ - base::TimeTicks()); | 59 return now_ + (ticks_now_ - base::TimeTicks()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 AddToTicksNow(kPseudoSleepTime2); | 154 AddToTicksNow(kPseudoSleepTime2); |
| 155 UpdateNetworkTime( | 155 UpdateNetworkTime( |
| 156 old_now, | 156 old_now, |
| 157 base::TimeDelta::FromMilliseconds(kResolution2), | 157 base::TimeDelta::FromMilliseconds(kResolution2), |
| 158 base::TimeDelta::FromMilliseconds(kLatency2), | 158 base::TimeDelta::FromMilliseconds(kLatency2), |
| 159 old_ticks); | 159 old_ticks); |
| 160 EXPECT_TRUE(ValidateExpectedTime()); | 160 EXPECT_TRUE(ValidateExpectedTime()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace network_time | 163 } // namespace network_time |
| OLD | NEW |