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

Side by Side Diff: chrome/browser/network_time/network_time_tracker_unittest.cc

Issue 291333009: network_time: Remove NetworkTimeService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/network_time/network_time_tracker.h" 5 #include "chrome/browser/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/time/tick_clock.h" 11 #include "base/time/tick_clock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 // These are all in milliseconds. 16 // These are all in milliseconds.
16 const int64 kLatency1 = 50; 17 const int64 kLatency1 = 50;
17 const int64 kLatency2 = 500; 18 const int64 kLatency2 = 500;
18 19
19 // Can not be smaller than 15, it's the NowFromSystemTime() resolution. 20 // Can not be smaller than 15, it's the NowFromSystemTime() resolution.
(...skipping 17 matching lines...) Expand all
37 base::TimeTicks* ticks_now_; 38 base::TimeTicks* ticks_now_;
38 }; 39 };
39 40
40 } // namespace 41 } // namespace
41 42
42 class NetworkTimeTrackerTest : public testing::Test { 43 class NetworkTimeTrackerTest : public testing::Test {
43 public: 44 public:
44 NetworkTimeTrackerTest() 45 NetworkTimeTrackerTest()
45 : now_(base::Time::NowFromSystemTime()), 46 : now_(base::Time::NowFromSystemTime()),
46 network_time_tracker_(new NetworkTimeTracker( 47 network_time_tracker_(new NetworkTimeTracker(
47 scoped_ptr<base::TickClock>(new TestTickClock(&ticks_now_)))) {} 48 scoped_ptr<base::TickClock>(new TestTickClock(&ticks_now_)),
49 &pref_service_)) {}
48 virtual ~NetworkTimeTrackerTest() {} 50 virtual ~NetworkTimeTrackerTest() {}
49 51
50 base::Time Now() const { 52 base::Time Now() const {
51 return now_ + (ticks_now_ - base::TimeTicks()); 53 return now_ + (ticks_now_ - base::TimeTicks());
52 } 54 }
53 55
54 base::TimeTicks TicksNow() const { 56 base::TimeTicks TicksNow() const {
55 return ticks_now_; 57 return ticks_now_;
56 } 58 }
57 59
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 NetworkTimeTracker* network_time_tracker() { 93 NetworkTimeTracker* network_time_tracker() {
92 return network_time_tracker_.get(); 94 return network_time_tracker_.get();
93 } 95 }
94 96
95 private: 97 private:
96 // Used in building the current time that TestTickClock reports. See Now() 98 // Used in building the current time that TestTickClock reports. See Now()
97 // for details. 99 // for details.
98 base::Time now_; 100 base::Time now_;
99 base::TimeTicks ticks_now_; 101 base::TimeTicks ticks_now_;
100 102
103 TestingPrefServiceSimple pref_service_;
104
101 // The network time tracker being tested. 105 // The network time tracker being tested.
102 scoped_ptr<NetworkTimeTracker> network_time_tracker_; 106 scoped_ptr<NetworkTimeTracker> network_time_tracker_;
103 }; 107 };
104 108
105 // Should not return a value before UpdateNetworkTime gets called. 109 // Should not return a value before UpdateNetworkTime gets called.
106 TEST_F(NetworkTimeTrackerTest, Uninitialized) { 110 TEST_F(NetworkTimeTrackerTest, Uninitialized) {
107 base::Time network_time; 111 base::Time network_time;
108 base::TimeDelta uncertainty; 112 base::TimeDelta uncertainty;
109 EXPECT_FALSE(network_time_tracker()->GetNetworkTime(base::TimeTicks(), 113 EXPECT_FALSE(network_time_tracker()->GetNetworkTime(base::TimeTicks(),
110 &network_time, 114 &network_time,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 base::Time old_now = Now(); 146 base::Time old_now = Now();
143 base::TimeTicks old_ticks = TicksNow(); 147 base::TimeTicks old_ticks = TicksNow();
144 AddToTicksNow(kPseudoSleepTime2); 148 AddToTicksNow(kPseudoSleepTime2);
145 UpdateNetworkTime( 149 UpdateNetworkTime(
146 old_now, 150 old_now,
147 base::TimeDelta::FromMilliseconds(kResolution2), 151 base::TimeDelta::FromMilliseconds(kResolution2),
148 base::TimeDelta::FromMilliseconds(kLatency2), 152 base::TimeDelta::FromMilliseconds(kLatency2),
149 old_ticks); 153 old_ticks);
150 EXPECT_TRUE(ValidateExpectedTime()); 154 EXPECT_TRUE(ValidateExpectedTime());
151 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698