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

Side by Side Diff: content/browser/background_sync/background_sync_manager_unittest.cc

Issue 2954433002: BackgroundSync: Convert to base::BindOnce/OnceCallback/OnceClosure (Closed)
Patch Set: Created 3 years, 6 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 "content/browser/background_sync/background_sync_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 void TearDown() override { 152 void TearDown() override {
153 // Restore the network observer functionality for subsequent tests 153 // Restore the network observer functionality for subsequent tests
154 background_sync_test_util::SetIgnoreNetworkChangeNotifier(false); 154 background_sync_test_util::SetIgnoreNetworkChangeNotifier(false);
155 } 155 }
156 156
157 void RegisterServiceWorkers() { 157 void RegisterServiceWorkers() {
158 bool called_1 = false; 158 bool called_1 = false;
159 bool called_2 = false; 159 bool called_2 = false;
160 helper_->context()->RegisterServiceWorker( 160 helper_->context()->RegisterServiceWorker(
161 GURL(kPattern1), GURL(kScript1), NULL, 161 GURL(kPattern1), GURL(kScript1), NULL,
162 base::Bind(&RegisterServiceWorkerCallback, &called_1, 162 base::AdaptCallbackForRepeating(
163 &sw_registration_id_1_)); 163 base::BindOnce(&RegisterServiceWorkerCallback, &called_1,
164 &sw_registration_id_1_)));
164 165
165 helper_->context()->RegisterServiceWorker( 166 helper_->context()->RegisterServiceWorker(
166 GURL(kPattern2), GURL(kScript2), NULL, 167 GURL(kPattern2), GURL(kScript2), NULL,
167 base::Bind(&RegisterServiceWorkerCallback, &called_2, 168 base::AdaptCallbackForRepeating(
168 &sw_registration_id_2_)); 169 base::BindOnce(&RegisterServiceWorkerCallback, &called_2,
170 &sw_registration_id_2_)));
169 base::RunLoop().RunUntilIdle(); 171 base::RunLoop().RunUntilIdle();
170 EXPECT_TRUE(called_1); 172 EXPECT_TRUE(called_1);
171 EXPECT_TRUE(called_2); 173 EXPECT_TRUE(called_2);
172 174
173 // Hang onto the registrations as they need to be "live" when 175 // Hang onto the registrations as they need to be "live" when
174 // calling BackgroundSyncManager::Register. 176 // calling BackgroundSyncManager::Register.
175 helper_->context_wrapper()->FindReadyRegistrationForId( 177 helper_->context_wrapper()->FindReadyRegistrationForId(
176 sw_registration_id_1_, GURL(kPattern1).GetOrigin(), 178 sw_registration_id_1_, GURL(kPattern1).GetOrigin(),
177 base::Bind(FindServiceWorkerRegistrationCallback, &sw_registration_1_)); 179 base::AdaptCallbackForRepeating(base::BindOnce(
180 FindServiceWorkerRegistrationCallback, &sw_registration_1_)));
178 181
179 helper_->context_wrapper()->FindReadyRegistrationForId( 182 helper_->context_wrapper()->FindReadyRegistrationForId(
180 sw_registration_id_2_, GURL(kPattern1).GetOrigin(), 183 sw_registration_id_2_, GURL(kPattern1).GetOrigin(),
181 base::Bind(FindServiceWorkerRegistrationCallback, &sw_registration_2_)); 184 base::AdaptCallbackForRepeating(base::BindOnce(
185 FindServiceWorkerRegistrationCallback, &sw_registration_2_)));
182 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
183 EXPECT_TRUE(sw_registration_1_); 187 EXPECT_TRUE(sw_registration_1_);
184 EXPECT_TRUE(sw_registration_2_); 188 EXPECT_TRUE(sw_registration_2_);
185 } 189 }
186 190
187 void SetNetwork(net::NetworkChangeNotifier::ConnectionType connection_type) { 191 void SetNetwork(net::NetworkChangeNotifier::ConnectionType connection_type) {
188 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( 192 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
189 connection_type); 193 connection_type);
190 if (test_background_sync_manager_) { 194 if (test_background_sync_manager_) {
191 BackgroundSyncNetworkObserver* network_observer = 195 BackgroundSyncNetworkObserver* network_observer =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { 271 bool Register(const BackgroundSyncRegistrationOptions& sync_options) {
268 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); 272 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options);
269 } 273 }
270 274
271 bool RegisterWithServiceWorkerId( 275 bool RegisterWithServiceWorkerId(
272 int64_t sw_registration_id, 276 int64_t sw_registration_id,
273 const BackgroundSyncRegistrationOptions& options) { 277 const BackgroundSyncRegistrationOptions& options) {
274 bool was_called = false; 278 bool was_called = false;
275 background_sync_manager_->Register( 279 background_sync_manager_->Register(
276 sw_registration_id, options, 280 sw_registration_id, options,
277 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 281 base::BindOnce(
278 base::Unretained(this), &was_called)); 282 &BackgroundSyncManagerTest::StatusAndRegistrationCallback,
283 base::Unretained(this), &was_called));
279 base::RunLoop().RunUntilIdle(); 284 base::RunLoop().RunUntilIdle();
280 EXPECT_TRUE(was_called); 285 EXPECT_TRUE(was_called);
281 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 286 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
282 } 287 }
283 288
284 MockPermissionManager* GetPermissionManager() { 289 MockPermissionManager* GetPermissionManager() {
285 return static_cast<MockPermissionManager*>( 290 return static_cast<MockPermissionManager*>(
286 helper_->browser_context()->GetPermissionManager()); 291 helper_->browser_context()->GetPermissionManager());
287 } 292 }
288 293
289 bool GetRegistration( 294 bool GetRegistration(
290 const BackgroundSyncRegistrationOptions& registration_options) { 295 const BackgroundSyncRegistrationOptions& registration_options) {
291 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 296 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
292 registration_options); 297 registration_options);
293 } 298 }
294 299
295 bool GetRegistrationWithServiceWorkerId( 300 bool GetRegistrationWithServiceWorkerId(
296 int64_t sw_registration_id, 301 int64_t sw_registration_id,
297 const BackgroundSyncRegistrationOptions& registration_options) { 302 const BackgroundSyncRegistrationOptions& registration_options) {
298 bool was_called = false; 303 bool was_called = false;
299 background_sync_manager_->GetRegistrations( 304 background_sync_manager_->GetRegistrations(
300 sw_registration_id, 305 sw_registration_id,
301 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback, 306 base::BindOnce(
302 base::Unretained(this), &was_called)); 307 &BackgroundSyncManagerTest::StatusAndRegistrationsCallback,
308 base::Unretained(this), &was_called));
303 base::RunLoop().RunUntilIdle(); 309 base::RunLoop().RunUntilIdle();
304 EXPECT_TRUE(was_called); 310 EXPECT_TRUE(was_called);
305 311
306 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { 312 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
307 for (auto iter = callback_registrations_.begin(); 313 for (auto iter = callback_registrations_.begin();
308 iter < callback_registrations_.end(); ++iter) { 314 iter < callback_registrations_.end(); ++iter) {
309 if ((*iter)->options()->tag == registration_options.tag) { 315 if ((*iter)->options()->tag == registration_options.tag) {
310 // Transfer the matching registration out of the vector into 316 // Transfer the matching registration out of the vector into
311 // callback_registration_ for testing. 317 // callback_registration_ for testing.
312 callback_registration_ = std::move(*iter); 318 callback_registration_ = std::move(*iter);
313 callback_registrations_.erase(iter); 319 callback_registrations_.erase(iter);
314 return true; 320 return true;
315 } 321 }
316 } 322 }
317 } 323 }
318 return false; 324 return false;
319 } 325 }
320 326
321 bool GetRegistrations() { 327 bool GetRegistrations() {
322 return GetRegistrationsWithServiceWorkerId(sw_registration_id_1_); 328 return GetRegistrationsWithServiceWorkerId(sw_registration_id_1_);
323 } 329 }
324 330
325 bool GetRegistrationsWithServiceWorkerId(int64_t sw_registration_id) { 331 bool GetRegistrationsWithServiceWorkerId(int64_t sw_registration_id) {
326 bool was_called = false; 332 bool was_called = false;
327 background_sync_manager_->GetRegistrations( 333 background_sync_manager_->GetRegistrations(
328 sw_registration_id, 334 sw_registration_id,
329 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback, 335 base::BindOnce(
330 base::Unretained(this), &was_called)); 336 &BackgroundSyncManagerTest::StatusAndRegistrationsCallback,
337 base::Unretained(this), &was_called));
331 base::RunLoop().RunUntilIdle(); 338 base::RunLoop().RunUntilIdle();
332 EXPECT_TRUE(was_called); 339 EXPECT_TRUE(was_called);
333 340
334 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 341 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
335 } 342 }
336 343
337 MockBackgroundSyncController* GetController() { 344 MockBackgroundSyncController* GetController() {
338 return static_cast<MockBackgroundSyncController*>( 345 return static_cast<MockBackgroundSyncController*>(
339 helper_->browser_context()->GetBackgroundSyncController()); 346 helper_->browser_context()->GetBackgroundSyncController());
340 } 347 }
341 348
342 void StorageRegistrationCallback(ServiceWorkerStatusCode result) { 349 void StorageRegistrationCallback(ServiceWorkerStatusCode result) {
343 callback_sw_status_code_ = result; 350 callback_sw_status_code_ = result;
344 } 351 }
345 352
346 void UnregisterServiceWorker(uint64_t sw_registration_id) { 353 void UnregisterServiceWorker(uint64_t sw_registration_id) {
347 bool called = false; 354 bool called = false;
348 helper_->context()->UnregisterServiceWorker( 355 helper_->context()->UnregisterServiceWorker(
349 PatternForSWId(sw_registration_id), 356 PatternForSWId(sw_registration_id),
350 base::Bind(&UnregisterServiceWorkerCallback, &called)); 357 base::AdaptCallbackForRepeating(
358 base::BindOnce(&UnregisterServiceWorkerCallback, &called)));
351 base::RunLoop().RunUntilIdle(); 359 base::RunLoop().RunUntilIdle();
352 EXPECT_TRUE(called); 360 EXPECT_TRUE(called);
353 } 361 }
354 362
355 GURL PatternForSWId(int64_t sw_id) { 363 GURL PatternForSWId(int64_t sw_id) {
356 EXPECT_TRUE(sw_id == sw_registration_id_1_ || 364 EXPECT_TRUE(sw_id == sw_registration_id_1_ ||
357 sw_id == sw_registration_id_2_); 365 sw_id == sw_registration_id_2_);
358 return sw_id == sw_registration_id_1_ ? GURL(kPattern1) : GURL(kPattern2); 366 return sw_id == sw_registration_id_1_ ? GURL(kPattern1) : GURL(kPattern2);
359 } 367 }
360 368
361 void SetupForSyncEvent( 369 void SetupForSyncEvent(
362 const TestBackgroundSyncManager::DispatchSyncCallback& callback) { 370 const TestBackgroundSyncManager::DispatchSyncCallback& callback) {
363 test_background_sync_manager_->set_dispatch_sync_callback(callback); 371 test_background_sync_manager_->set_dispatch_sync_callback(callback);
364 SetNetwork(net::NetworkChangeNotifier::CONNECTION_WIFI); 372 SetNetwork(net::NetworkChangeNotifier::CONNECTION_WIFI);
365 } 373 }
366 374
367 void InitSyncEventTest() { 375 void InitSyncEventTest() {
368 SetupForSyncEvent( 376 SetupForSyncEvent(base::BindRepeating(DispatchSyncSuccessfulCallback,
369 base::Bind(DispatchSyncSuccessfulCallback, &sync_events_called_)); 377 &sync_events_called_));
370 } 378 }
371 379
372 void InitFailedSyncEventTest() { 380 void InitFailedSyncEventTest() {
373 SetupForSyncEvent( 381 SetupForSyncEvent(
374 base::Bind(DispatchSyncFailedCallback, &sync_events_called_)); 382 base::BindRepeating(DispatchSyncFailedCallback, &sync_events_called_));
375 } 383 }
376 384
377 void InitDelayedSyncEventTest() { 385 void InitDelayedSyncEventTest() {
378 SetupForSyncEvent(base::Bind(DispatchSyncDelayedCallback, 386 SetupForSyncEvent(base::BindRepeating(DispatchSyncDelayedCallback,
379 &sync_events_called_, &sync_fired_callback_)); 387 &sync_events_called_,
388 &sync_fired_callback_));
380 } 389 }
381 390
382 void RegisterAndVerifySyncEventDelayed( 391 void RegisterAndVerifySyncEventDelayed(
383 const BackgroundSyncRegistrationOptions& sync_options) { 392 const BackgroundSyncRegistrationOptions& sync_options) {
384 int sync_events_called = sync_events_called_; 393 int sync_events_called = sync_events_called_;
385 EXPECT_TRUE(sync_fired_callback_.is_null()); 394 EXPECT_TRUE(sync_fired_callback_.is_null());
386 395
387 EXPECT_TRUE(Register(sync_options)); 396 EXPECT_TRUE(Register(sync_options));
388 397
389 EXPECT_EQ(sync_events_called + 1, sync_events_called_); 398 EXPECT_EQ(sync_events_called + 1, sync_events_called_);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 635
627 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { 636 TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
628 // Schedule Init and all of the operations on a delayed backend. Verify that 637 // Schedule Init and all of the operations on a delayed backend. Verify that
629 // the operations complete sequentially. 638 // the operations complete sequentially.
630 SetupDelayedBackgroundSyncManager(); 639 SetupDelayedBackgroundSyncManager();
631 640
632 bool register_called = false; 641 bool register_called = false;
633 bool get_registrations_called = false; 642 bool get_registrations_called = false;
634 test_background_sync_manager_->Register( 643 test_background_sync_manager_->Register(
635 sw_registration_id_1_, sync_options_1_, 644 sw_registration_id_1_, sync_options_1_,
636 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 645 base::AdaptCallbackForRepeating(base::BindOnce(
637 base::Unretained(this), &register_called)); 646 &BackgroundSyncManagerTest::StatusAndRegistrationCallback,
647 base::Unretained(this), &register_called)));
638 test_background_sync_manager_->GetRegistrations( 648 test_background_sync_manager_->GetRegistrations(
639 sw_registration_id_1_, 649 sw_registration_id_1_,
640 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback, 650 base::AdaptCallbackForRepeating(base::BindOnce(
641 base::Unretained(this), &get_registrations_called)); 651 &BackgroundSyncManagerTest::StatusAndRegistrationsCallback,
652 base::Unretained(this), &get_registrations_called)));
642 653
643 base::RunLoop().RunUntilIdle(); 654 base::RunLoop().RunUntilIdle();
644 // Init should be blocked while loading from the backend. 655 // Init should be blocked while loading from the backend.
645 EXPECT_FALSE(register_called); 656 EXPECT_FALSE(register_called);
646 EXPECT_FALSE(get_registrations_called); 657 EXPECT_FALSE(get_registrations_called);
647 658
648 test_background_sync_manager_->ResumeBackendOperation(); 659 test_background_sync_manager_->ResumeBackendOperation();
649 base::RunLoop().RunUntilIdle(); 660 base::RunLoop().RunUntilIdle();
650 // Register should be blocked while storing to the backend. 661 // Register should be blocked while storing to the backend.
651 EXPECT_FALSE(register_called); 662 EXPECT_FALSE(register_called);
(...skipping 14 matching lines...) Expand all
666 } 677 }
667 678
668 TEST_F(BackgroundSyncManagerTest, 679 TEST_F(BackgroundSyncManagerTest,
669 UnregisterServiceWorkerDuringSyncRegistration) { 680 UnregisterServiceWorkerDuringSyncRegistration) {
670 EXPECT_TRUE(Register(sync_options_1_)); 681 EXPECT_TRUE(Register(sync_options_1_));
671 682
672 test_background_sync_manager_->set_delay_backend(true); 683 test_background_sync_manager_->set_delay_backend(true);
673 bool callback_called = false; 684 bool callback_called = false;
674 test_background_sync_manager_->Register( 685 test_background_sync_manager_->Register(
675 sw_registration_id_1_, sync_options_2_, 686 sw_registration_id_1_, sync_options_2_,
676 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 687 base::AdaptCallbackForRepeating(base::BindOnce(
677 base::Unretained(this), &callback_called)); 688 &BackgroundSyncManagerTest::StatusAndRegistrationCallback,
689 base::Unretained(this), &callback_called)));
678 690
679 base::RunLoop().RunUntilIdle(); 691 base::RunLoop().RunUntilIdle();
680 EXPECT_FALSE(callback_called); 692 EXPECT_FALSE(callback_called);
681 UnregisterServiceWorker(sw_registration_id_1_); 693 UnregisterServiceWorker(sw_registration_id_1_);
682 694
683 test_background_sync_manager_->ResumeBackendOperation(); 695 test_background_sync_manager_->ResumeBackendOperation();
684 base::RunLoop().RunUntilIdle(); 696 base::RunLoop().RunUntilIdle();
685 EXPECT_TRUE(callback_called); 697 EXPECT_TRUE(callback_called);
686 EXPECT_EQ(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback_status_); 698 EXPECT_EQ(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback_status_);
687 699
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1153 EXPECT_FALSE(GetRegistration(sync_options_1_));
1142 } 1154 }
1143 1155
1144 TEST_F(BackgroundSyncManagerTest, TwoAttempts) { 1156 TEST_F(BackgroundSyncManagerTest, TwoAttempts) {
1145 SetMaxSyncAttemptsAndRestartManager(2); 1157 SetMaxSyncAttemptsAndRestartManager(2);
1146 InitFailedSyncEventTest(); 1158 InitFailedSyncEventTest();
1147 1159
1148 // The first run will fail but it will setup a timer to try again. 1160 // The first run will fail but it will setup a timer to try again.
1149 EXPECT_TRUE(Register(sync_options_1_)); 1161 EXPECT_TRUE(Register(sync_options_1_));
1150 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1162 EXPECT_TRUE(GetRegistration(sync_options_1_));
1151 EXPECT_FALSE(test_background_sync_manager_->delayed_task().is_null()); 1163 EXPECT_TRUE(test_background_sync_manager_->IsDelayedTaskScheduled());
1152 1164
1153 // Make sure the delay is reasonable. 1165 // Make sure the delay is reasonable.
1154 EXPECT_LT(base::TimeDelta::FromMinutes(1), 1166 EXPECT_LT(base::TimeDelta::FromMinutes(1),
1155 test_background_sync_manager_->delayed_task_delta()); 1167 test_background_sync_manager_->delayed_task_delta());
1156 EXPECT_GT(base::TimeDelta::FromHours(1), 1168 EXPECT_GT(base::TimeDelta::FromHours(1),
1157 test_background_sync_manager_->delayed_task_delta()); 1169 test_background_sync_manager_->delayed_task_delta());
1158 1170
1159 // Fire again and this time it should permanently fail. 1171 // Fire again and this time it should permanently fail.
1160 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1172 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1161 test_background_sync_manager_->delayed_task().Run(); 1173 test_background_sync_manager_->RunDelayedTask();
1162 base::RunLoop().RunUntilIdle(); 1174 base::RunLoop().RunUntilIdle();
1163 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1175 EXPECT_FALSE(GetRegistration(sync_options_1_));
1164 } 1176 }
1165 1177
1166 TEST_F(BackgroundSyncManagerTest, ThreeAttempts) { 1178 TEST_F(BackgroundSyncManagerTest, ThreeAttempts) {
1167 SetMaxSyncAttemptsAndRestartManager(3); 1179 SetMaxSyncAttemptsAndRestartManager(3);
1168 InitFailedSyncEventTest(); 1180 InitFailedSyncEventTest();
1169 1181
1170 // The first run will fail but it will setup a timer to try again. 1182 // The first run will fail but it will setup a timer to try again.
1171 EXPECT_TRUE(Register(sync_options_1_)); 1183 EXPECT_TRUE(Register(sync_options_1_));
1172 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1184 EXPECT_TRUE(GetRegistration(sync_options_1_));
1173 EXPECT_FALSE(test_background_sync_manager_->delayed_task().is_null()); 1185 EXPECT_TRUE(test_background_sync_manager_->IsDelayedTaskScheduled());
1174 1186
1175 // The second run will fail but it will setup a timer to try again. 1187 // The second run will fail but it will setup a timer to try again.
1176 base::TimeDelta first_delta = 1188 base::TimeDelta first_delta =
1177 test_background_sync_manager_->delayed_task_delta(); 1189 test_background_sync_manager_->delayed_task_delta();
1178 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1190 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1179 test_background_sync_manager_->delayed_task().Run(); 1191 test_background_sync_manager_->RunDelayedTask();
1180 base::RunLoop().RunUntilIdle(); 1192 base::RunLoop().RunUntilIdle();
1181 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1193 EXPECT_TRUE(GetRegistration(sync_options_1_));
1182 1194
1183 // Verify that the delta grows for each attempt. 1195 // Verify that the delta grows for each attempt.
1184 EXPECT_LT(first_delta, test_background_sync_manager_->delayed_task_delta()); 1196 EXPECT_LT(first_delta, test_background_sync_manager_->delayed_task_delta());
1185 1197
1186 // The third run will permanently fail. 1198 // The third run will permanently fail.
1187 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1199 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1188 test_background_sync_manager_->delayed_task().Run(); 1200 test_background_sync_manager_->RunDelayedTask();
1189 base::RunLoop().RunUntilIdle(); 1201 base::RunLoop().RunUntilIdle();
1190 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1202 EXPECT_FALSE(GetRegistration(sync_options_1_));
1191 } 1203 }
1192 1204
1193 TEST_F(BackgroundSyncManagerTest, WaitsFullDelayTime) { 1205 TEST_F(BackgroundSyncManagerTest, WaitsFullDelayTime) {
1194 SetMaxSyncAttemptsAndRestartManager(2); 1206 SetMaxSyncAttemptsAndRestartManager(2);
1195 InitFailedSyncEventTest(); 1207 InitFailedSyncEventTest();
1196 1208
1197 // The first run will fail but it will setup a timer to try again. 1209 // The first run will fail but it will setup a timer to try again.
1198 EXPECT_TRUE(Register(sync_options_1_)); 1210 EXPECT_TRUE(Register(sync_options_1_));
1199 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1211 EXPECT_TRUE(GetRegistration(sync_options_1_));
1200 EXPECT_FALSE(test_background_sync_manager_->delayed_task().is_null()); 1212 EXPECT_TRUE(test_background_sync_manager_->IsDelayedTaskScheduled());
1201 1213
1202 // Fire again one second before it's ready to retry. Expect it to reschedule 1214 // Fire again one second before it's ready to retry. Expect it to reschedule
1203 // the delay timer for one more second. 1215 // the delay timer for one more second.
1204 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta() - 1216 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta() -
1205 base::TimeDelta::FromSeconds(1)); 1217 base::TimeDelta::FromSeconds(1));
1206 test_background_sync_manager_->delayed_task().Run(); 1218 test_background_sync_manager_->RunDelayedTask();
1207 base::RunLoop().RunUntilIdle(); 1219 base::RunLoop().RunUntilIdle();
1208 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1220 EXPECT_TRUE(GetRegistration(sync_options_1_));
1209 EXPECT_EQ(base::TimeDelta::FromSeconds(1), 1221 EXPECT_EQ(base::TimeDelta::FromSeconds(1),
1210 test_background_sync_manager_->delayed_task_delta()); 1222 test_background_sync_manager_->delayed_task_delta());
1211 1223
1212 // Fire one second later and it should fail permanently. 1224 // Fire one second later and it should fail permanently.
1213 test_clock_->Advance(base::TimeDelta::FromSeconds(1)); 1225 test_clock_->Advance(base::TimeDelta::FromSeconds(1));
1214 test_background_sync_manager_->delayed_task().Run(); 1226 test_background_sync_manager_->RunDelayedTask();
1215 base::RunLoop().RunUntilIdle(); 1227 base::RunLoop().RunUntilIdle();
1216 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1228 EXPECT_FALSE(GetRegistration(sync_options_1_));
1217 } 1229 }
1218 1230
1219 TEST_F(BackgroundSyncManagerTest, RetryOnBrowserRestart) { 1231 TEST_F(BackgroundSyncManagerTest, RetryOnBrowserRestart) {
1220 SetMaxSyncAttemptsAndRestartManager(2); 1232 SetMaxSyncAttemptsAndRestartManager(2);
1221 InitFailedSyncEventTest(); 1233 InitFailedSyncEventTest();
1222 1234
1223 // The first run will fail but it will setup a timer to try again. 1235 // The first run will fail but it will setup a timer to try again.
1224 EXPECT_TRUE(Register(sync_options_1_)); 1236 EXPECT_TRUE(Register(sync_options_1_));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 1285
1274 TEST_F(BackgroundSyncManagerTest, AllTestsEventuallyFire) { 1286 TEST_F(BackgroundSyncManagerTest, AllTestsEventuallyFire) {
1275 SetMaxSyncAttemptsAndRestartManager(3); 1287 SetMaxSyncAttemptsAndRestartManager(3);
1276 InitFailedSyncEventTest(); 1288 InitFailedSyncEventTest();
1277 1289
1278 // The first run will fail but it will setup a timer to try again. 1290 // The first run will fail but it will setup a timer to try again.
1279 EXPECT_TRUE(Register(sync_options_1_)); 1291 EXPECT_TRUE(Register(sync_options_1_));
1280 1292
1281 // Run it a second time. 1293 // Run it a second time.
1282 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1294 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1283 test_background_sync_manager_->delayed_task().Run(); 1295 test_background_sync_manager_->RunDelayedTask();
1284 base::RunLoop().RunUntilIdle(); 1296 base::RunLoop().RunUntilIdle();
1285 1297
1286 base::TimeDelta delay_delta = 1298 base::TimeDelta delay_delta =
1287 test_background_sync_manager_->delayed_task_delta(); 1299 test_background_sync_manager_->delayed_task_delta();
1288 1300
1289 // Create a second registration, which will fail and setup a timer. 1301 // Create a second registration, which will fail and setup a timer.
1290 EXPECT_TRUE(Register(sync_options_2_)); 1302 EXPECT_TRUE(Register(sync_options_2_));
1291 EXPECT_GT(delay_delta, test_background_sync_manager_->delayed_task_delta()); 1303 EXPECT_GT(delay_delta, test_background_sync_manager_->delayed_task_delta());
1292 1304
1293 while (!test_background_sync_manager_->delayed_task().is_null()) { 1305 while (test_background_sync_manager_->IsDelayedTaskScheduled()) {
1294 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1306 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1295 test_background_sync_manager_->delayed_task().Run(); 1307 test_background_sync_manager_->RunDelayedTask();
1296 test_background_sync_manager_->ClearDelayedTask(); 1308 EXPECT_FALSE(test_background_sync_manager_->IsDelayedTaskScheduled());
1297 base::RunLoop().RunUntilIdle(); 1309 base::RunLoop().RunUntilIdle();
1298 } 1310 }
1299 1311
1300 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1312 EXPECT_FALSE(GetRegistration(sync_options_1_));
1301 EXPECT_FALSE(GetRegistration(sync_options_2_)); 1313 EXPECT_FALSE(GetRegistration(sync_options_2_));
1302 } 1314 }
1303 1315
1304 TEST_F(BackgroundSyncManagerTest, LastChance) { 1316 TEST_F(BackgroundSyncManagerTest, LastChance) {
1305 SetMaxSyncAttemptsAndRestartManager(2); 1317 SetMaxSyncAttemptsAndRestartManager(2);
1306 InitFailedSyncEventTest(); 1318 InitFailedSyncEventTest();
1307 1319
1308 EXPECT_TRUE(Register(sync_options_1_)); 1320 EXPECT_TRUE(Register(sync_options_1_));
1309 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_NOT_LAST_CHANCE, 1321 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_NOT_LAST_CHANCE,
1310 test_background_sync_manager_->last_chance()); 1322 test_background_sync_manager_->last_chance());
1311 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1323 EXPECT_TRUE(GetRegistration(sync_options_1_));
1312 1324
1313 // Run it again. 1325 // Run it again.
1314 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1326 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1315 test_background_sync_manager_->delayed_task().Run(); 1327 test_background_sync_manager_->RunDelayedTask();
1316 base::RunLoop().RunUntilIdle(); 1328 base::RunLoop().RunUntilIdle();
1317 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1329 EXPECT_FALSE(GetRegistration(sync_options_1_));
1318 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, 1330 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE,
1319 test_background_sync_manager_->last_chance()); 1331 test_background_sync_manager_->last_chance());
1320 } 1332 }
1321 1333
1322 } // namespace content 1334 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698