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

Side by Side Diff: components/proximity_auth/cryptauth/sync_scheduler_impl_unittest.cc

Issue 1912433002: Convert //components/proximity_auth from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/proximity_auth/cryptauth/sync_scheduler_impl.h" 5 #include "components/proximity_auth/cryptauth/sync_scheduler_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/timer/mock_timer.h" 11 #include "base/timer/mock_timer.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace proximity_auth { 14 namespace proximity_auth {
14 15
15 using Strategy = SyncScheduler::Strategy; 16 using Strategy = SyncScheduler::Strategy;
16 using SyncState = SyncScheduler::SyncState; 17 using SyncState = SyncScheduler::SyncState;
17 18
18 namespace { 19 namespace {
19 20
(...skipping 30 matching lines...) Expand all
50 refresh_period, 51 refresh_period,
51 recovery_period, 52 recovery_period,
52 max_jitter_ratio, 53 max_jitter_ratio,
53 kTestSchedulerName) {} 54 kTestSchedulerName) {}
54 55
55 ~TestSyncSchedulerImpl() override {} 56 ~TestSyncSchedulerImpl() override {}
56 57
57 base::MockTimer* timer() { return mock_timer_; } 58 base::MockTimer* timer() { return mock_timer_; }
58 59
59 private: 60 private:
60 scoped_ptr<base::Timer> CreateTimer() override { 61 std::unique_ptr<base::Timer> CreateTimer() override {
61 bool retain_user_task = false; 62 bool retain_user_task = false;
62 bool is_repeating = false; 63 bool is_repeating = false;
63 mock_timer_ = new base::MockTimer(retain_user_task, is_repeating); 64 mock_timer_ = new base::MockTimer(retain_user_task, is_repeating);
64 return make_scoped_ptr(mock_timer_); 65 return base::WrapUnique(mock_timer_);
65 } 66 }
66 67
67 // A timer instance for testing. Owned by the parent scheduler. 68 // A timer instance for testing. Owned by the parent scheduler.
68 base::MockTimer* mock_timer_; 69 base::MockTimer* mock_timer_;
69 70
70 DISALLOW_COPY_AND_ASSIGN(TestSyncSchedulerImpl); 71 DISALLOW_COPY_AND_ASSIGN(TestSyncSchedulerImpl);
71 }; 72 };
72 73
73 } // namespace 74 } // namespace
74 75
75 class ProximityAuthSyncSchedulerImplTest : public testing::Test, 76 class ProximityAuthSyncSchedulerImplTest : public testing::Test,
76 public SyncSchedulerImpl::Delegate { 77 public SyncSchedulerImpl::Delegate {
77 protected: 78 protected:
78 ProximityAuthSyncSchedulerImplTest() 79 ProximityAuthSyncSchedulerImplTest()
79 : refresh_period_(base::TimeDelta::FromDays(kRefreshPeriodDays)), 80 : refresh_period_(base::TimeDelta::FromDays(kRefreshPeriodDays)),
80 base_recovery_period_( 81 base_recovery_period_(
81 base::TimeDelta::FromSeconds(kRecoveryPeriodSeconds)), 82 base::TimeDelta::FromSeconds(kRecoveryPeriodSeconds)),
82 zero_elapsed_time_(base::TimeDelta::FromSeconds(0)), 83 zero_elapsed_time_(base::TimeDelta::FromSeconds(0)),
83 scheduler_(new TestSyncSchedulerImpl(this, 84 scheduler_(new TestSyncSchedulerImpl(this,
84 refresh_period_, 85 refresh_period_,
85 base_recovery_period_, 86 base_recovery_period_,
86 0)) {} 87 0)) {}
87 88
88 ~ProximityAuthSyncSchedulerImplTest() override {} 89 ~ProximityAuthSyncSchedulerImplTest() override {}
89 90
90 void OnSyncRequested( 91 void OnSyncRequested(
91 scoped_ptr<SyncScheduler::SyncRequest> sync_request) override { 92 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override {
92 sync_request_ = std::move(sync_request); 93 sync_request_ = std::move(sync_request);
93 } 94 }
94 95
95 base::MockTimer* timer() { return scheduler_->timer(); } 96 base::MockTimer* timer() { return scheduler_->timer(); }
96 97
97 // The time deltas used to configure |scheduler_|. 98 // The time deltas used to configure |scheduler_|.
98 base::TimeDelta refresh_period_; 99 base::TimeDelta refresh_period_;
99 base::TimeDelta base_recovery_period_; 100 base::TimeDelta base_recovery_period_;
100 base::TimeDelta zero_elapsed_time_; 101 base::TimeDelta zero_elapsed_time_;
101 102
102 // The scheduler instance under test. 103 // The scheduler instance under test.
103 scoped_ptr<TestSyncSchedulerImpl> scheduler_; 104 std::unique_ptr<TestSyncSchedulerImpl> scheduler_;
104 105
105 scoped_ptr<SyncScheduler::SyncRequest> sync_request_; 106 std::unique_ptr<SyncScheduler::SyncRequest> sync_request_;
106 107
107 DISALLOW_COPY_AND_ASSIGN(ProximityAuthSyncSchedulerImplTest); 108 DISALLOW_COPY_AND_ASSIGN(ProximityAuthSyncSchedulerImplTest);
108 }; 109 };
109 110
110 TEST_F(ProximityAuthSyncSchedulerImplTest, ForceSyncSuccess) { 111 TEST_F(ProximityAuthSyncSchedulerImplTest, ForceSyncSuccess) {
111 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 112 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
112 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 113 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
113 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState()); 114 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
114 115
115 scheduler_->ForceSync(); 116 scheduler_->ForceSync();
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // This could happen in rare cases where the system clock changes. 283 // This could happen in rare cases where the system clock changes.
283 scheduler_->Start(base::TimeDelta::FromDays(-1000), 284 scheduler_->Start(base::TimeDelta::FromDays(-1000),
284 Strategy::PERIODIC_REFRESH); 285 Strategy::PERIODIC_REFRESH);
285 286
286 base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0); 287 base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0);
287 EXPECT_EQ(zero_delta, scheduler_->GetTimeToNextSync()); 288 EXPECT_EQ(zero_delta, scheduler_->GetTimeToNextSync());
288 EXPECT_EQ(zero_delta, timer()->GetCurrentDelay()); 289 EXPECT_EQ(zero_delta, timer()->GetCurrentDelay());
289 } 290 }
290 291
291 } // namespace proximity_auth 292 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698