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

Side by Side Diff: components/network_time/network_time_tracker_unittest.cc

Issue 1918083002: Convert //components/[f-n]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: … Created 4 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
OLDNEW
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 <memory>
8
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
9 #include "base/test/simple_test_tick_clock.h" 11 #include "base/test/simple_test_tick_clock.h"
10 #include "components/network_time/network_time_pref_names.h" 12 #include "components/network_time/network_time_pref_names.h"
11 #include "components/prefs/testing_pref_service.h" 13 #include "components/prefs/testing_pref_service.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 namespace network_time { 16 namespace network_time {
15 17
16 class NetworkTimeTrackerTest : public testing::Test { 18 class NetworkTimeTrackerTest : public testing::Test {
17 public: 19 public:
18 ~NetworkTimeTrackerTest() override {} 20 ~NetworkTimeTrackerTest() override {}
19 21
20 void SetUp() override { 22 void SetUp() override {
21 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); 23 NetworkTimeTracker::RegisterPrefs(pref_service_.registry());
22 24
23 clock_ = new base::SimpleTestClock(); 25 clock_ = new base::SimpleTestClock();
24 tick_clock_ = new base::SimpleTestTickClock(); 26 tick_clock_ = new base::SimpleTestTickClock();
25 // Do this to be sure that |is_null| returns false. 27 // Do this to be sure that |is_null| returns false.
26 clock_->Advance(base::TimeDelta::FromDays(111)); 28 clock_->Advance(base::TimeDelta::FromDays(111));
27 tick_clock_->Advance(base::TimeDelta::FromDays(222)); 29 tick_clock_->Advance(base::TimeDelta::FromDays(222));
28 30
29 tracker_.reset(new NetworkTimeTracker( 31 tracker_.reset(new NetworkTimeTracker(
30 scoped_ptr<base::Clock>(clock_), 32 std::unique_ptr<base::Clock>(clock_),
31 scoped_ptr<base::TickClock>(tick_clock_), 33 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_));
32 &pref_service_));
33 34
34 // Can not be smaller than 15, it's the NowFromSystemTime() resolution. 35 // Can not be smaller than 15, it's the NowFromSystemTime() resolution.
35 resolution_ = base::TimeDelta::FromMilliseconds(17); 36 resolution_ = base::TimeDelta::FromMilliseconds(17);
36 latency_ = base::TimeDelta::FromMilliseconds(50); 37 latency_ = base::TimeDelta::FromMilliseconds(50);
37 adjustment_ = 7 * base::TimeDelta::FromMilliseconds(kTicksResolutionMs); 38 adjustment_ = 7 * base::TimeDelta::FromMilliseconds(kTicksResolutionMs);
38 } 39 }
39 40
40 // Replaces |tracker_| with a new object, while preserving the 41 // Replaces |tracker_| with a new object, while preserving the
41 // testing clocks. 42 // testing clocks.
42 void Reset() { 43 void Reset() {
43 base::SimpleTestClock* new_clock = new base::SimpleTestClock(); 44 base::SimpleTestClock* new_clock = new base::SimpleTestClock();
44 new_clock->SetNow(clock_->Now()); 45 new_clock->SetNow(clock_->Now());
45 base::SimpleTestTickClock* new_tick_clock = new base::SimpleTestTickClock(); 46 base::SimpleTestTickClock* new_tick_clock = new base::SimpleTestTickClock();
46 new_tick_clock->SetNowTicks(tick_clock_->NowTicks()); 47 new_tick_clock->SetNowTicks(tick_clock_->NowTicks());
47 clock_ = new_clock; 48 clock_ = new_clock;
48 tick_clock_= new_tick_clock; 49 tick_clock_= new_tick_clock;
49 tracker_.reset(new NetworkTimeTracker( 50 tracker_.reset(new NetworkTimeTracker(
50 scoped_ptr<base::Clock>(clock_), 51 std::unique_ptr<base::Clock>(clock_),
51 scoped_ptr<base::TickClock>(tick_clock_), 52 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_));
52 &pref_service_));
53 } 53 }
54 54
55 // Updates the notifier's time with the specified parameters. 55 // Updates the notifier's time with the specified parameters.
56 void UpdateNetworkTime(const base::Time& network_time, 56 void UpdateNetworkTime(const base::Time& network_time,
57 const base::TimeDelta& resolution, 57 const base::TimeDelta& resolution,
58 const base::TimeDelta& latency, 58 const base::TimeDelta& latency,
59 const base::TimeTicks& post_time) { 59 const base::TimeTicks& post_time) {
60 tracker_->UpdateNetworkTime( 60 tracker_->UpdateNetworkTime(
61 network_time, resolution, latency, post_time); 61 network_time, resolution, latency, post_time);
62 } 62 }
63 63
64 // Advances both the system clock and the tick clock. This should be used for 64 // Advances both the system clock and the tick clock. This should be used for
65 // the normal passage of time, i.e. when neither clock is doing anything odd. 65 // the normal passage of time, i.e. when neither clock is doing anything odd.
66 void AdvanceBoth(const base::TimeDelta& delta) { 66 void AdvanceBoth(const base::TimeDelta& delta) {
67 tick_clock_->Advance(delta); 67 tick_clock_->Advance(delta);
68 clock_->Advance(delta); 68 clock_->Advance(delta);
69 } 69 }
70 70
71 protected: 71 protected:
72 base::TimeDelta resolution_; 72 base::TimeDelta resolution_;
73 base::TimeDelta latency_; 73 base::TimeDelta latency_;
74 base::TimeDelta adjustment_; 74 base::TimeDelta adjustment_;
75 base::SimpleTestClock* clock_; 75 base::SimpleTestClock* clock_;
76 base::SimpleTestTickClock* tick_clock_; 76 base::SimpleTestTickClock* tick_clock_;
77 TestingPrefServiceSimple pref_service_; 77 TestingPrefServiceSimple pref_service_;
78 scoped_ptr<NetworkTimeTracker> tracker_; 78 std::unique_ptr<NetworkTimeTracker> tracker_;
79 }; 79 };
80 80
81 TEST_F(NetworkTimeTrackerTest, Uninitialized) { 81 TEST_F(NetworkTimeTrackerTest, Uninitialized) {
82 base::Time network_time; 82 base::Time network_time;
83 base::TimeDelta uncertainty; 83 base::TimeDelta uncertainty;
84 EXPECT_FALSE(tracker_->GetNetworkTime(&network_time, &uncertainty)); 84 EXPECT_FALSE(tracker_->GetNetworkTime(&network_time, &uncertainty));
85 } 85 }
86 86
87 TEST_F(NetworkTimeTrackerTest, LongPostingDelay) { 87 TEST_F(NetworkTimeTrackerTest, LongPostingDelay) {
88 // The request arrives at the server, which records the time. Advance the 88 // The request arrives at the server, which records the time. Advance the
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 tick_clock_->NowTicks()); 285 tick_clock_->NowTicks());
286 286
287 base::Time out_network_time; 287 base::Time out_network_time;
288 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL)); 288 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL));
289 clock_->Advance(base::TimeDelta::FromDays(1)); 289 clock_->Advance(base::TimeDelta::FromDays(1));
290 Reset(); 290 Reset();
291 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 291 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL));
292 } 292 }
293 293
294 } // namespace network_time 294 } // namespace network_time
OLDNEW
« no previous file with comments | « components/network_time/network_time_tracker.cc ('k') | components/ntp_snippets/ntp_snippets_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698