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

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

Issue 2502343003: Moved //components/proximity_auth/cryptauth to //components/cryptauth. (Closed)
Patch Set: Fixed proto #includes. Created 4 years, 1 month 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
« no previous file with comments | « components/cryptauth/sync_scheduler_impl.cc ('k') | components/proximity_auth/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/memory/ptr_util.h"
11 #include "base/timer/mock_timer.h" 11 #include "base/timer/mock_timer.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace proximity_auth { 14 namespace cryptauth {
15 15
16 using Strategy = SyncScheduler::Strategy; 16 using Strategy = SyncScheduler::Strategy;
17 using SyncState = SyncScheduler::SyncState; 17 using SyncState = SyncScheduler::SyncState;
18 18
19 namespace { 19 namespace {
20 20
21 // Constants configuring the the scheduler. 21 // Constants configuring the the scheduler.
22 const int kElapsedTimeDays = 40; 22 const int kElapsedTimeDays = 40;
23 const int kRefreshPeriodDays = 30; 23 const int kRefreshPeriodDays = 30;
24 const int kRecoveryPeriodSeconds = 10; 24 const int kRecoveryPeriodSeconds = 10;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 67
68 // A timer instance for testing. Owned by the parent scheduler. 68 // A timer instance for testing. Owned by the parent scheduler.
69 base::MockTimer* mock_timer_; 69 base::MockTimer* mock_timer_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(TestSyncSchedulerImpl); 71 DISALLOW_COPY_AND_ASSIGN(TestSyncSchedulerImpl);
72 }; 72 };
73 73
74 } // namespace 74 } // namespace
75 75
76 class ProximityAuthSyncSchedulerImplTest : public testing::Test, 76 class CryptAuthSyncSchedulerImplTest : public testing::Test,
77 public SyncSchedulerImpl::Delegate { 77 public SyncSchedulerImpl::Delegate {
78 protected: 78 protected:
79 ProximityAuthSyncSchedulerImplTest() 79 CryptAuthSyncSchedulerImplTest()
80 : refresh_period_(base::TimeDelta::FromDays(kRefreshPeriodDays)), 80 : refresh_period_(base::TimeDelta::FromDays(kRefreshPeriodDays)),
81 base_recovery_period_( 81 base_recovery_period_(
82 base::TimeDelta::FromSeconds(kRecoveryPeriodSeconds)), 82 base::TimeDelta::FromSeconds(kRecoveryPeriodSeconds)),
83 zero_elapsed_time_(base::TimeDelta::FromSeconds(0)), 83 zero_elapsed_time_(base::TimeDelta::FromSeconds(0)),
84 scheduler_(new TestSyncSchedulerImpl(this, 84 scheduler_(new TestSyncSchedulerImpl(this,
85 refresh_period_, 85 refresh_period_,
86 base_recovery_period_, 86 base_recovery_period_,
87 0)) {} 87 0)) {}
88 88
89 ~ProximityAuthSyncSchedulerImplTest() override {} 89 ~CryptAuthSyncSchedulerImplTest() override {}
90 90
91 void OnSyncRequested( 91 void OnSyncRequested(
92 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override { 92 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) override {
93 sync_request_ = std::move(sync_request); 93 sync_request_ = std::move(sync_request);
94 } 94 }
95 95
96 base::MockTimer* timer() { return scheduler_->timer(); } 96 base::MockTimer* timer() { return scheduler_->timer(); }
97 97
98 // The time deltas used to configure |scheduler_|. 98 // The time deltas used to configure |scheduler_|.
99 base::TimeDelta refresh_period_; 99 base::TimeDelta refresh_period_;
100 base::TimeDelta base_recovery_period_; 100 base::TimeDelta base_recovery_period_;
101 base::TimeDelta zero_elapsed_time_; 101 base::TimeDelta zero_elapsed_time_;
102 102
103 // The scheduler instance under test. 103 // The scheduler instance under test.
104 std::unique_ptr<TestSyncSchedulerImpl> scheduler_; 104 std::unique_ptr<TestSyncSchedulerImpl> scheduler_;
105 105
106 std::unique_ptr<SyncScheduler::SyncRequest> sync_request_; 106 std::unique_ptr<SyncScheduler::SyncRequest> sync_request_;
107 107
108 DISALLOW_COPY_AND_ASSIGN(ProximityAuthSyncSchedulerImplTest); 108 DISALLOW_COPY_AND_ASSIGN(CryptAuthSyncSchedulerImplTest);
109 }; 109 };
110 110
111 TEST_F(ProximityAuthSyncSchedulerImplTest, ForceSyncSuccess) { 111 TEST_F(CryptAuthSyncSchedulerImplTest, ForceSyncSuccess) {
112 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 112 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
113 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 113 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
114 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState()); 114 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
115 115
116 scheduler_->ForceSync(); 116 scheduler_->ForceSync();
117 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState()); 117 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState());
118 EXPECT_TRUE(sync_request_); 118 EXPECT_TRUE(sync_request_);
119 sync_request_->OnDidComplete(true); 119 sync_request_->OnDidComplete(true);
120 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 120 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
121 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState()); 121 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
122 } 122 }
123 123
124 TEST_F(ProximityAuthSyncSchedulerImplTest, ForceSyncFailure) { 124 TEST_F(CryptAuthSyncSchedulerImplTest, ForceSyncFailure) {
125 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 125 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
126 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 126 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
127 127
128 scheduler_->ForceSync(); 128 scheduler_->ForceSync();
129 EXPECT_TRUE(sync_request_); 129 EXPECT_TRUE(sync_request_);
130 sync_request_->OnDidComplete(false); 130 sync_request_->OnDidComplete(false);
131 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 131 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
132 } 132 }
133 133
134 TEST_F(ProximityAuthSyncSchedulerImplTest, PeriodicRefreshSuccess) { 134 TEST_F(CryptAuthSyncSchedulerImplTest, PeriodicRefreshSuccess) {
135 EXPECT_EQ(SyncState::NOT_STARTED, scheduler_->GetSyncState()); 135 EXPECT_EQ(SyncState::NOT_STARTED, scheduler_->GetSyncState());
136 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 136 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
137 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 137 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
138 138
139 EXPECT_EQ(refresh_period_, timer()->GetCurrentDelay()); 139 EXPECT_EQ(refresh_period_, timer()->GetCurrentDelay());
140 timer()->Fire(); 140 timer()->Fire();
141 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState()); 141 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState());
142 ASSERT_TRUE(sync_request_.get()); 142 ASSERT_TRUE(sync_request_.get());
143 143
144 sync_request_->OnDidComplete(true); 144 sync_request_->OnDidComplete(true);
145 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState()); 145 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
146 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 146 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
147 } 147 }
148 148
149 TEST_F(ProximityAuthSyncSchedulerImplTest, PeriodicRefreshFailure) { 149 TEST_F(CryptAuthSyncSchedulerImplTest, PeriodicRefreshFailure) {
150 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 150 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
151 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 151 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
152 timer()->Fire(); 152 timer()->Fire();
153 sync_request_->OnDidComplete(false); 153 sync_request_->OnDidComplete(false);
154 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 154 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
155 } 155 }
156 156
157 TEST_F(ProximityAuthSyncSchedulerImplTest, AggressiveRecoverySuccess) { 157 TEST_F(CryptAuthSyncSchedulerImplTest, AggressiveRecoverySuccess) {
158 scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY); 158 scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY);
159 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 159 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
160 160
161 EXPECT_EQ(base_recovery_period_, timer()->GetCurrentDelay()); 161 EXPECT_EQ(base_recovery_period_, timer()->GetCurrentDelay());
162 timer()->Fire(); 162 timer()->Fire();
163 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState()); 163 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState());
164 ASSERT_TRUE(sync_request_.get()); 164 ASSERT_TRUE(sync_request_.get());
165 165
166 sync_request_->OnDidComplete(true); 166 sync_request_->OnDidComplete(true);
167 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState()); 167 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
168 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 168 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
169 } 169 }
170 170
171 TEST_F(ProximityAuthSyncSchedulerImplTest, AggressiveRecoveryFailure) { 171 TEST_F(CryptAuthSyncSchedulerImplTest, AggressiveRecoveryFailure) {
172 scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY); 172 scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY);
173 173
174 timer()->Fire(); 174 timer()->Fire();
175 sync_request_->OnDidComplete(false); 175 sync_request_->OnDidComplete(false);
176 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 176 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
177 } 177 }
178 178
179 TEST_F(ProximityAuthSyncSchedulerImplTest, AggressiveRecoveryBackOff) { 179 TEST_F(CryptAuthSyncSchedulerImplTest, AggressiveRecoveryBackOff) {
180 scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY); 180 scheduler_->Start(zero_elapsed_time_, Strategy::AGGRESSIVE_RECOVERY);
181 base::TimeDelta last_recovery_period = base::TimeDelta::FromSeconds(0); 181 base::TimeDelta last_recovery_period = base::TimeDelta::FromSeconds(0);
182 182
183 for (int i = 0; i < 20; ++i) { 183 for (int i = 0; i < 20; ++i) {
184 timer()->Fire(); 184 timer()->Fire();
185 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState()); 185 EXPECT_EQ(SyncState::SYNC_IN_PROGRESS, scheduler_->GetSyncState());
186 sync_request_->OnDidComplete(false); 186 sync_request_->OnDidComplete(false);
187 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 187 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
188 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState()); 188 EXPECT_EQ(SyncState::WAITING_FOR_REFRESH, scheduler_->GetSyncState());
189 189
190 base::TimeDelta recovery_period = scheduler_->GetTimeToNextSync(); 190 base::TimeDelta recovery_period = scheduler_->GetTimeToNextSync();
191 EXPECT_LE(last_recovery_period, recovery_period); 191 EXPECT_LE(last_recovery_period, recovery_period);
192 last_recovery_period = recovery_period; 192 last_recovery_period = recovery_period;
193 } 193 }
194 194
195 // Backoffs should rapidly converge to the normal refresh period. 195 // Backoffs should rapidly converge to the normal refresh period.
196 EXPECT_EQ(refresh_period_, last_recovery_period); 196 EXPECT_EQ(refresh_period_, last_recovery_period);
197 } 197 }
198 198
199 TEST_F(ProximityAuthSyncSchedulerImplTest, RefreshFailureRecoverySuccess) { 199 TEST_F(CryptAuthSyncSchedulerImplTest, RefreshFailureRecoverySuccess) {
200 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 200 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
201 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 201 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
202 202
203 timer()->Fire(); 203 timer()->Fire();
204 sync_request_->OnDidComplete(false); 204 sync_request_->OnDidComplete(false);
205 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 205 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
206 206
207 timer()->Fire(); 207 timer()->Fire();
208 sync_request_->OnDidComplete(true); 208 sync_request_->OnDidComplete(true);
209 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 209 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
210 } 210 }
211 211
212 TEST_F(ProximityAuthSyncSchedulerImplTest, SyncImmediatelyForPeriodicRefresh) { 212 TEST_F(CryptAuthSyncSchedulerImplTest, SyncImmediatelyForPeriodicRefresh) {
213 scheduler_->Start(base::TimeDelta::FromDays(kElapsedTimeDays), 213 scheduler_->Start(base::TimeDelta::FromDays(kElapsedTimeDays),
214 Strategy::PERIODIC_REFRESH); 214 Strategy::PERIODIC_REFRESH);
215 EXPECT_TRUE(scheduler_->GetTimeToNextSync().is_zero()); 215 EXPECT_TRUE(scheduler_->GetTimeToNextSync().is_zero());
216 EXPECT_TRUE(timer()->GetCurrentDelay().is_zero()); 216 EXPECT_TRUE(timer()->GetCurrentDelay().is_zero());
217 timer()->Fire(); 217 timer()->Fire();
218 EXPECT_TRUE(sync_request_); 218 EXPECT_TRUE(sync_request_);
219 219
220 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy()); 220 EXPECT_EQ(Strategy::PERIODIC_REFRESH, scheduler_->GetStrategy());
221 } 221 }
222 222
223 TEST_F(ProximityAuthSyncSchedulerImplTest, 223 TEST_F(CryptAuthSyncSchedulerImplTest,
224 SyncImmediatelyForAggressiveRecovery) { 224 SyncImmediatelyForAggressiveRecovery) {
225 scheduler_->Start(base::TimeDelta::FromDays(kElapsedTimeDays), 225 scheduler_->Start(base::TimeDelta::FromDays(kElapsedTimeDays),
226 Strategy::AGGRESSIVE_RECOVERY); 226 Strategy::AGGRESSIVE_RECOVERY);
227 EXPECT_TRUE(scheduler_->GetTimeToNextSync().is_zero()); 227 EXPECT_TRUE(scheduler_->GetTimeToNextSync().is_zero());
228 EXPECT_TRUE(timer()->GetCurrentDelay().is_zero()); 228 EXPECT_TRUE(timer()->GetCurrentDelay().is_zero());
229 timer()->Fire(); 229 timer()->Fire();
230 EXPECT_TRUE(sync_request_); 230 EXPECT_TRUE(sync_request_);
231 231
232 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy()); 232 EXPECT_EQ(Strategy::AGGRESSIVE_RECOVERY, scheduler_->GetStrategy());
233 } 233 }
234 234
235 TEST_F(ProximityAuthSyncSchedulerImplTest, InitialSyncShorterByElapsedTime) { 235 TEST_F(CryptAuthSyncSchedulerImplTest, InitialSyncShorterByElapsedTime) {
236 base::TimeDelta elapsed_time = base::TimeDelta::FromDays(2); 236 base::TimeDelta elapsed_time = base::TimeDelta::FromDays(2);
237 scheduler_->Start(elapsed_time, Strategy::PERIODIC_REFRESH); 237 scheduler_->Start(elapsed_time, Strategy::PERIODIC_REFRESH);
238 EXPECT_EQ(refresh_period_ - elapsed_time, scheduler_->GetTimeToNextSync()); 238 EXPECT_EQ(refresh_period_ - elapsed_time, scheduler_->GetTimeToNextSync());
239 timer()->Fire(); 239 timer()->Fire();
240 EXPECT_TRUE(sync_request_); 240 EXPECT_TRUE(sync_request_);
241 } 241 }
242 242
243 TEST_F(ProximityAuthSyncSchedulerImplTest, PeriodicRefreshJitter) { 243 TEST_F(CryptAuthSyncSchedulerImplTest, PeriodicRefreshJitter) {
244 scheduler_.reset(new TestSyncSchedulerImpl( 244 scheduler_.reset(new TestSyncSchedulerImpl(
245 this, refresh_period_, base_recovery_period_, kMaxJitterPercentage)); 245 this, refresh_period_, base_recovery_period_, kMaxJitterPercentage));
246 246
247 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 247 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
248 248
249 base::TimeDelta cumulative_jitter = base::TimeDelta::FromSeconds(0); 249 base::TimeDelta cumulative_jitter = base::TimeDelta::FromSeconds(0);
250 for (int i = 0; i < 10; ++i) { 250 for (int i = 0; i < 10; ++i) {
251 base::TimeDelta next_sync_delta = scheduler_->GetTimeToNextSync(); 251 base::TimeDelta next_sync_delta = scheduler_->GetTimeToNextSync();
252 cumulative_jitter += (next_sync_delta - refresh_period_).magnitude(); 252 cumulative_jitter += (next_sync_delta - refresh_period_).magnitude();
253 EXPECT_TRUE(IsTimeDeltaWithinJitter(refresh_period_, next_sync_delta, 253 EXPECT_TRUE(IsTimeDeltaWithinJitter(refresh_period_, next_sync_delta,
254 kMaxJitterPercentage)); 254 kMaxJitterPercentage));
255 timer()->Fire(); 255 timer()->Fire();
256 sync_request_->OnDidComplete(true); 256 sync_request_->OnDidComplete(true);
257 } 257 }
258 258
259 // The probablility that all periods are randomly equal to |refresh_period_| 259 // The probablility that all periods are randomly equal to |refresh_period_|
260 // is so low that we would expect the heat death of the universe before this 260 // is so low that we would expect the heat death of the universe before this
261 // test flakes. 261 // test flakes.
262 EXPECT_FALSE(cumulative_jitter.is_zero()); 262 EXPECT_FALSE(cumulative_jitter.is_zero());
263 } 263 }
264 264
265 TEST_F(ProximityAuthSyncSchedulerImplTest, JitteredTimeDeltaIsNonNegative) { 265 TEST_F(CryptAuthSyncSchedulerImplTest, JitteredTimeDeltaIsNonNegative) {
266 base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0); 266 base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0);
267 double max_jitter_ratio = 1; 267 double max_jitter_ratio = 1;
268 scheduler_.reset(new TestSyncSchedulerImpl(this, zero_delta, zero_delta, 268 scheduler_.reset(new TestSyncSchedulerImpl(this, zero_delta, zero_delta,
269 max_jitter_ratio)); 269 max_jitter_ratio));
270 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH); 270 scheduler_->Start(zero_elapsed_time_, Strategy::PERIODIC_REFRESH);
271 271
272 for (int i = 0; i < 10; ++i) { 272 for (int i = 0; i < 10; ++i) {
273 base::TimeDelta next_sync_delta = scheduler_->GetTimeToNextSync(); 273 base::TimeDelta next_sync_delta = scheduler_->GetTimeToNextSync();
274 EXPECT_GE(zero_delta, next_sync_delta); 274 EXPECT_GE(zero_delta, next_sync_delta);
275 EXPECT_TRUE( 275 EXPECT_TRUE(
276 IsTimeDeltaWithinJitter(zero_delta, next_sync_delta, max_jitter_ratio)); 276 IsTimeDeltaWithinJitter(zero_delta, next_sync_delta, max_jitter_ratio));
277 timer()->Fire(); 277 timer()->Fire();
278 sync_request_->OnDidComplete(true); 278 sync_request_->OnDidComplete(true);
279 } 279 }
280 } 280 }
281 281
282 TEST_F(ProximityAuthSyncSchedulerImplTest, StartWithNegativeElapsedTime) { 282 TEST_F(CryptAuthSyncSchedulerImplTest, StartWithNegativeElapsedTime) {
283 // This could happen in rare cases where the system clock changes. 283 // This could happen in rare cases where the system clock changes.
284 scheduler_->Start(base::TimeDelta::FromDays(-1000), 284 scheduler_->Start(base::TimeDelta::FromDays(-1000),
285 Strategy::PERIODIC_REFRESH); 285 Strategy::PERIODIC_REFRESH);
286 286
287 base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0); 287 base::TimeDelta zero_delta = base::TimeDelta::FromSeconds(0);
288 EXPECT_EQ(zero_delta, scheduler_->GetTimeToNextSync()); 288 EXPECT_EQ(zero_delta, scheduler_->GetTimeToNextSync());
289 EXPECT_EQ(zero_delta, timer()->GetCurrentDelay()); 289 EXPECT_EQ(zero_delta, timer()->GetCurrentDelay());
290 } 290 }
291 291
292 } // namespace proximity_auth 292 } // namespace cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/sync_scheduler_impl.cc ('k') | components/proximity_auth/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698