OLD | NEW |
---|---|
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 "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
11 #include "base/power_monitor/power_monitor_source.h" | 11 #include "base/power_monitor/power_monitor_source.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "content/browser/background_sync/background_sync_status.h" | 15 #include "content/browser/background_sync/background_sync_status.h" |
16 #include "content/browser/background_sync/client_background_sync_registration.h" | |
16 #include "content/browser/browser_thread_impl.h" | 17 #include "content/browser/browser_thread_impl.h" |
17 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 18 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
18 #include "content/browser/service_worker/service_worker_context_core.h" | 19 #include "content/browser/service_worker/service_worker_context_core.h" |
19 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 20 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
20 #include "content/browser/service_worker/service_worker_storage.h" | 21 #include "content/browser/service_worker/service_worker_storage.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 namespace content { | 26 namespace content { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 121 } |
121 | 122 |
122 void GetDataFromBackendContinue( | 123 void GetDataFromBackendContinue( |
123 const std::string& key, | 124 const std::string& key, |
124 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& | 125 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
125 callback) { | 126 callback) { |
126 BackgroundSyncManager::GetDataFromBackend(key, callback); | 127 BackgroundSyncManager::GetDataFromBackend(key, callback); |
127 } | 128 } |
128 | 129 |
129 void Continue() { | 130 void Continue() { |
131 ASSERT_FALSE(continuation_.is_null()); | |
130 continuation_.Run(); | 132 continuation_.Run(); |
131 continuation_.Reset(); | 133 continuation_.Reset(); |
132 } | 134 } |
133 | 135 |
134 void set_corrupt_backend(bool corrupt_backend) { | 136 void set_corrupt_backend(bool corrupt_backend) { |
135 corrupt_backend_ = corrupt_backend; | 137 corrupt_backend_ = corrupt_backend; |
136 } | 138 } |
137 void set_delay_backend(bool delay_backend) { delay_backend_ = delay_backend; } | 139 void set_delay_backend(bool delay_backend) { delay_backend_ = delay_backend; } |
138 void set_one_shot_callback(const OneShotCallback& callback) { | 140 void set_one_shot_callback(const OneShotCallback& callback) { |
139 one_shot_callback_ = callback; | 141 one_shot_callback_ = callback; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 continuation_ = | 179 continuation_ = |
178 base::Bind(&TestBackgroundSyncManager::GetDataFromBackendContinue, | 180 base::Bind(&TestBackgroundSyncManager::GetDataFromBackendContinue, |
179 base::Unretained(this), key, callback); | 181 base::Unretained(this), key, callback); |
180 if (delay_backend_) | 182 if (delay_backend_) |
181 return; | 183 return; |
182 | 184 |
183 Continue(); | 185 Continue(); |
184 } | 186 } |
185 | 187 |
186 void FireOneShotSync( | 188 void FireOneShotSync( |
187 const BackgroundSyncRegistration& registration, | 189 BackgroundSyncManager::RefCountedRegistration* registration, |
188 const scoped_refptr<ServiceWorkerVersion>& active_version, | 190 const scoped_refptr<ServiceWorkerVersion>& active_version, |
189 const ServiceWorkerVersion::StatusCallback& callback) override { | 191 const ServiceWorkerVersion::StatusCallback& callback) override { |
190 if (one_shot_callback_.is_null()) { | 192 ASSERT_FALSE(one_shot_callback_.is_null()); |
191 BackgroundSyncManager::FireOneShotSync(registration, active_version, | 193 one_shot_callback_.Run(active_version, callback); |
192 callback); | |
193 } else { | |
194 one_shot_callback_.Run(active_version, callback); | |
195 } | |
196 } | 194 } |
197 | 195 |
198 private: | 196 private: |
199 bool corrupt_backend_ = false; | 197 bool corrupt_backend_ = false; |
200 bool delay_backend_ = false; | 198 bool delay_backend_ = false; |
201 base::Closure continuation_; | 199 base::Closure continuation_; |
202 OneShotCallback one_shot_callback_; | 200 OneShotCallback one_shot_callback_; |
203 }; | 201 }; |
204 | 202 |
205 class BackgroundSyncManagerTest : public testing::Test { | 203 class BackgroundSyncManagerTest : public testing::Test { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 } | 296 } |
299 | 297 |
300 void SetOnBatteryPower(bool on_battery_power) { | 298 void SetOnBatteryPower(bool on_battery_power) { |
301 power_monitor_source_->GeneratePowerStateEvent(on_battery_power); | 299 power_monitor_source_->GeneratePowerStateEvent(on_battery_power); |
302 base::RunLoop().RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
303 } | 301 } |
304 | 302 |
305 void StatusAndRegistrationCallback( | 303 void StatusAndRegistrationCallback( |
306 bool* was_called, | 304 bool* was_called, |
307 BackgroundSyncStatus status, | 305 BackgroundSyncStatus status, |
308 const BackgroundSyncRegistration& registration) { | 306 scoped_ptr<ClientBackgroundSyncRegistration> registration) { |
309 *was_called = true; | 307 *was_called = true; |
310 callback_status_ = status; | 308 callback_status_ = status; |
311 callback_registration_ = registration; | 309 callback_registration_ = registration.Pass(); |
312 } | 310 } |
313 | 311 |
314 void StatusAndRegistrationsCallback( | 312 void StatusAndRegistrationsCallback( |
315 bool* was_called, | 313 bool* was_called, |
316 BackgroundSyncStatus status, | 314 BackgroundSyncStatus status, |
317 const std::vector<BackgroundSyncRegistration>& registrations) { | 315 scoped_ptr<ScopedVector<ClientBackgroundSyncRegistration>> |
316 registrations) { | |
318 *was_called = true; | 317 *was_called = true; |
319 callback_status_ = status; | 318 callback_status_ = status; |
320 callback_registrations_ = registrations; | 319 callback_registrations_ = registrations.Pass(); |
321 } | 320 } |
322 | 321 |
323 void StatusCallback(bool* was_called, BackgroundSyncStatus status) { | 322 void StatusCallback(bool* was_called, BackgroundSyncStatus status) { |
324 *was_called = true; | 323 *was_called = true; |
325 callback_status_ = status; | 324 callback_status_ = status; |
326 } | 325 } |
327 | 326 |
328 protected: | 327 protected: |
329 void CreateBackgroundSyncManager() { | 328 void CreateBackgroundSyncManager() { |
329 ClearRegistrations(); | |
330 | |
330 test_background_sync_manager_ = | 331 test_background_sync_manager_ = |
331 new TestBackgroundSyncManager(helper_->context_wrapper()); | 332 new TestBackgroundSyncManager(helper_->context_wrapper()); |
332 background_sync_manager_.reset(test_background_sync_manager_); | 333 background_sync_manager_.reset(test_background_sync_manager_); |
333 } | 334 } |
334 | 335 |
335 void InitBackgroundSyncManager() { | 336 void InitBackgroundSyncManager() { |
336 test_background_sync_manager_->DoInit(); | 337 test_background_sync_manager_->DoInit(); |
337 | 338 |
338 // Many tests do not expect the sync event to fire immediately after | 339 // Many tests do not expect the sync event to fire immediately after |
339 // register (and cleanup up the sync registrations). Tests can control when | 340 // register (and cleanup up the sync registrations). Tests can control when |
340 // the sync event fires by manipulating the network state as needed. | 341 // the sync event fires by manipulating the network state as needed. |
341 // NOTE: The setup of the network connection must happen after the | 342 // NOTE: The setup of the network connection must happen after the |
342 // BackgroundSyncManager has been setup. | 343 // BackgroundSyncManager has been setup. |
343 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE); | 344 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE); |
344 } | 345 } |
345 | 346 |
347 // Clear the registrations so that the BackgroundSyncManager can release them. | |
348 void ClearRegistrations() { | |
349 callback_registration_.reset(); | |
350 callback_registrations_.reset(); | |
351 } | |
352 | |
346 void SetupBackgroundSyncManager() { | 353 void SetupBackgroundSyncManager() { |
347 CreateBackgroundSyncManager(); | 354 CreateBackgroundSyncManager(); |
348 InitBackgroundSyncManager(); | 355 InitBackgroundSyncManager(); |
349 } | 356 } |
350 | 357 |
351 void SetupCorruptBackgroundSyncManager() { | 358 void SetupCorruptBackgroundSyncManager() { |
352 CreateBackgroundSyncManager(); | 359 CreateBackgroundSyncManager(); |
353 test_background_sync_manager_->set_corrupt_backend(true); | 360 test_background_sync_manager_->set_corrupt_backend(true); |
354 InitBackgroundSyncManager(); | 361 InitBackgroundSyncManager(); |
355 } | 362 } |
356 | 363 |
357 void SetupDelayedBackgroundSyncManager() { | 364 void SetupDelayedBackgroundSyncManager() { |
358 CreateBackgroundSyncManager(); | 365 CreateBackgroundSyncManager(); |
359 test_background_sync_manager_->set_delay_backend(true); | 366 test_background_sync_manager_->set_delay_backend(true); |
360 InitBackgroundSyncManager(); | 367 InitBackgroundSyncManager(); |
361 } | 368 } |
362 | 369 |
363 void DeleteBackgroundSyncManager() { | 370 void DeleteBackgroundSyncManager() { |
371 ClearRegistrations(); | |
364 background_sync_manager_.reset(); | 372 background_sync_manager_.reset(); |
365 test_background_sync_manager_ = nullptr; | 373 test_background_sync_manager_ = nullptr; |
366 } | 374 } |
367 | 375 |
368 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { | 376 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { |
369 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); | 377 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); |
370 } | 378 } |
371 | 379 |
372 bool RegisterWithServiceWorkerId( | 380 bool RegisterWithServiceWorkerId( |
373 int64 sw_registration_id, | 381 int64 sw_registration_id, |
374 const BackgroundSyncRegistrationOptions& options) { | 382 const BackgroundSyncRegistrationOptions& options) { |
375 bool was_called = false; | 383 bool was_called = false; |
376 background_sync_manager_->Register( | 384 background_sync_manager_->Register( |
377 sw_registration_id, options, | 385 sw_registration_id, options, |
378 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 386 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
379 base::Unretained(this), &was_called)); | 387 base::Unretained(this), &was_called)); |
380 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
381 EXPECT_TRUE(was_called); | 389 EXPECT_TRUE(was_called); |
382 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; | 390 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; |
383 } | 391 } |
384 | 392 |
385 bool Unregister(const BackgroundSyncRegistration& sync_registration) { | 393 bool Unregister(ClientBackgroundSyncRegistration* sync_registration) { |
386 return UnregisterWithServiceWorkerId(sw_registration_id_1_, | 394 return UnregisterWithServiceWorkerId(sw_registration_id_1_, |
387 sync_registration); | 395 sync_registration); |
388 } | 396 } |
389 | 397 |
390 bool UnregisterWithServiceWorkerId( | 398 bool UnregisterWithServiceWorkerId( |
391 int64 sw_registration_id, | 399 int64 sw_registration_id, |
392 const BackgroundSyncRegistration& sync_registration) { | 400 ClientBackgroundSyncRegistration* sync_registration) { |
393 bool was_called = false; | 401 bool was_called = false; |
394 background_sync_manager_->Unregister( | 402 sync_registration->Unregister( |
395 sw_registration_id, sync_registration.options()->tag, | 403 sw_registration_id, |
396 sync_registration.options()->periodicity, sync_registration.id(), | |
397 base::Bind(&BackgroundSyncManagerTest::StatusCallback, | 404 base::Bind(&BackgroundSyncManagerTest::StatusCallback, |
398 base::Unretained(this), &was_called)); | 405 base::Unretained(this), &was_called)); |
399 base::RunLoop().RunUntilIdle(); | 406 base::RunLoop().RunUntilIdle(); |
400 EXPECT_TRUE(was_called); | 407 EXPECT_TRUE(was_called); |
401 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; | 408 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; |
402 } | 409 } |
403 | 410 |
404 bool GetRegistration(const BackgroundSyncRegistrationOptions& sync_options) { | 411 bool GetRegistration(const BackgroundSyncRegistrationOptions& sync_options) { |
405 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, | 412 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, |
406 sync_options); | 413 sync_options); |
407 } | 414 } |
408 | 415 |
409 bool GetRegistrationWithServiceWorkerId( | 416 bool GetRegistrationWithServiceWorkerId( |
410 int64 sw_registration_id, | 417 int64 sw_registration_id, |
411 const BackgroundSyncRegistrationOptions& sync_options) { | 418 const BackgroundSyncRegistrationOptions& sync_options) { |
412 bool was_called = false; | 419 bool was_called = false; |
413 background_sync_manager_->GetRegistration( | 420 background_sync_manager_->GetRegistration( |
414 sw_registration_id, sync_options.tag, sync_options.periodicity, | 421 sw_registration_id, sync_options.tag, sync_options.periodicity, |
415 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 422 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
416 base::Unretained(this), &was_called)); | 423 base::Unretained(this), &was_called)); |
417 base::RunLoop().RunUntilIdle(); | 424 base::RunLoop().RunUntilIdle(); |
418 EXPECT_TRUE(was_called); | 425 EXPECT_TRUE(was_called); |
419 | 426 |
420 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { | 427 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { |
421 EXPECT_STREQ(sync_options.tag.c_str(), | 428 EXPECT_STREQ(sync_options.tag.c_str(), |
422 callback_registration_.options()->tag.c_str()); | 429 callback_registration_->options()->tag.c_str()); |
423 } | 430 } |
424 | 431 |
425 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; | 432 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; |
426 } | 433 } |
427 | 434 |
428 bool GetRegistrations(SyncPeriodicity periodicity) { | 435 bool GetRegistrations(SyncPeriodicity periodicity) { |
429 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, | 436 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, |
430 periodicity); | 437 periodicity); |
431 } | 438 } |
432 | 439 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 int64 sw_registration_id_1_; | 514 int64 sw_registration_id_1_; |
508 int64 sw_registration_id_2_; | 515 int64 sw_registration_id_2_; |
509 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; | 516 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; |
510 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; | 517 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; |
511 | 518 |
512 BackgroundSyncRegistrationOptions sync_options_1_; | 519 BackgroundSyncRegistrationOptions sync_options_1_; |
513 BackgroundSyncRegistrationOptions sync_options_2_; | 520 BackgroundSyncRegistrationOptions sync_options_2_; |
514 | 521 |
515 // Callback values. | 522 // Callback values. |
516 BackgroundSyncStatus callback_status_; | 523 BackgroundSyncStatus callback_status_; |
517 BackgroundSyncRegistration callback_registration_; | 524 scoped_ptr<ClientBackgroundSyncRegistration> callback_registration_; |
518 std::vector<BackgroundSyncRegistration> callback_registrations_; | 525 scoped_ptr<ScopedVector<ClientBackgroundSyncRegistration>> |
526 callback_registrations_; | |
519 ServiceWorkerStatusCode callback_sw_status_code_; | 527 ServiceWorkerStatusCode callback_sw_status_code_; |
520 int sync_events_called_; | 528 int sync_events_called_; |
521 ServiceWorkerVersion::StatusCallback sync_fired_callback_; | 529 ServiceWorkerVersion::StatusCallback sync_fired_callback_; |
522 }; | 530 }; |
523 | 531 |
524 TEST_F(BackgroundSyncManagerTest, Register) { | 532 TEST_F(BackgroundSyncManagerTest, Register) { |
525 EXPECT_TRUE(Register(sync_options_1_)); | 533 EXPECT_TRUE(Register(sync_options_1_)); |
526 } | 534 } |
527 | 535 |
528 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { | 536 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { |
529 EXPECT_TRUE(Register(sync_options_1_)); | 537 EXPECT_TRUE(Register(sync_options_1_)); |
530 EXPECT_STREQ(sync_options_1_.tag.c_str(), | 538 EXPECT_STREQ(sync_options_1_.tag.c_str(), |
531 callback_registration_.options()->tag.c_str()); | 539 callback_registration_->options()->tag.c_str()); |
532 EXPECT_TRUE(callback_registration_.IsValid()); | 540 EXPECT_TRUE(callback_registration_->IsValid()); |
533 } | 541 } |
534 | 542 |
535 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { | 543 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { |
536 sw_registration_1_ = nullptr; | 544 sw_registration_1_ = nullptr; |
537 EXPECT_FALSE(Register(sync_options_1_)); | 545 EXPECT_FALSE(Register(sync_options_1_)); |
538 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); | 546 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); |
539 } | 547 } |
540 | 548 |
541 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { | 549 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { |
542 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); | 550 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); |
543 EXPECT_FALSE(Register(sync_options_1_)); | 551 EXPECT_FALSE(Register(sync_options_1_)); |
544 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); | 552 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); |
545 } | 553 } |
546 | 554 |
547 TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) { | |
iclelland
2015/08/14 14:44:18
Is this test no longer valid? Do we not care that
jkarlin
2015/08/17 17:14:49
No longer valid. It used to be the same regitratio
| |
548 EXPECT_TRUE(Register(sync_options_1_)); | |
549 BackgroundSyncRegistration first_registration = callback_registration_; | |
550 EXPECT_TRUE(Register(sync_options_1_)); | |
551 EXPECT_TRUE(callback_registration_.Equals(first_registration)); | |
552 EXPECT_EQ(first_registration.id(), callback_registration_.id()); | |
553 } | |
554 | |
555 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) { | 555 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) { |
556 EXPECT_TRUE(Register(sync_options_1_)); | 556 EXPECT_TRUE(Register(sync_options_1_)); |
557 BackgroundSyncRegistration first_registration = callback_registration_; | 557 scoped_ptr<ClientBackgroundSyncRegistration> first_registration = |
558 callback_registration_.Pass(); | |
558 | 559 |
559 sync_options_1_.min_period = 100; | 560 sync_options_1_.min_period = 100; |
560 EXPECT_TRUE(Register(sync_options_1_)); | 561 EXPECT_TRUE(Register(sync_options_1_)); |
561 EXPECT_LT(first_registration.id(), callback_registration_.id()); | 562 EXPECT_LT(first_registration->id(), callback_registration_->id()); |
562 EXPECT_FALSE(callback_registration_.Equals(first_registration)); | 563 EXPECT_FALSE(callback_registration_->Equals(*first_registration)); |
563 } | 564 } |
564 | 565 |
565 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { | 566 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { |
566 // Registrations with the same tags but different periodicities should not | 567 // Registrations with the same tags but different periodicities should not |
567 // collide. | 568 // collide. |
568 sync_options_1_.tag = ""; | 569 sync_options_1_.tag = ""; |
569 sync_options_2_.tag = ""; | 570 sync_options_2_.tag = ""; |
570 sync_options_1_.periodicity = SYNC_PERIODIC; | 571 sync_options_1_.periodicity = SYNC_PERIODIC; |
571 sync_options_2_.periodicity = SYNC_ONE_SHOT; | 572 sync_options_2_.periodicity = SYNC_ONE_SHOT; |
572 EXPECT_TRUE(Register(sync_options_1_)); | 573 EXPECT_TRUE(Register(sync_options_1_)); |
573 EXPECT_TRUE(Register(sync_options_2_)); | 574 EXPECT_TRUE(Register(sync_options_2_)); |
574 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 575 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
575 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); | 576 EXPECT_EQ(SYNC_PERIODIC, callback_registration_->options()->periodicity); |
576 EXPECT_TRUE(GetRegistration(sync_options_2_)); | 577 EXPECT_TRUE(GetRegistration(sync_options_2_)); |
577 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); | 578 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity); |
578 } | 579 } |
579 | 580 |
580 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { | 581 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { |
581 test_background_sync_manager_->set_corrupt_backend(true); | 582 test_background_sync_manager_->set_corrupt_backend(true); |
582 EXPECT_FALSE(Register(sync_options_1_)); | 583 EXPECT_FALSE(Register(sync_options_1_)); |
583 test_background_sync_manager_->set_corrupt_backend(false); | 584 test_background_sync_manager_->set_corrupt_backend(false); |
584 EXPECT_FALSE(Register(sync_options_1_)); | 585 EXPECT_FALSE(Register(sync_options_1_)); |
585 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 586 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
586 } | 587 } |
587 | 588 |
(...skipping 19 matching lines...) Expand all Loading... | |
607 EXPECT_FALSE(Register(sync_options_2_)); | 608 EXPECT_FALSE(Register(sync_options_2_)); |
608 // Registration should have discovered the bad backend and disabled the | 609 // Registration should have discovered the bad backend and disabled the |
609 // BackgroundSyncManager. | 610 // BackgroundSyncManager. |
610 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 611 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
611 test_background_sync_manager_->set_corrupt_backend(false); | 612 test_background_sync_manager_->set_corrupt_backend(false); |
612 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 613 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
613 } | 614 } |
614 | 615 |
615 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { | 616 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { |
616 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); | 617 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); |
617 EXPECT_EQ(0u, callback_registrations_.size()); | 618 EXPECT_EQ(0u, callback_registrations_->size()); |
618 } | 619 } |
619 | 620 |
620 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { | 621 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { |
621 EXPECT_TRUE(Register(sync_options_1_)); | 622 EXPECT_TRUE(Register(sync_options_1_)); |
622 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); | 623 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); |
623 | 624 |
624 EXPECT_EQ(1u, callback_registrations_.size()); | 625 EXPECT_EQ(1u, callback_registrations_->size()); |
625 sync_options_1_.Equals(*callback_registrations_[0].options()); | 626 sync_options_1_.Equals(*(*callback_registrations_)[0]->options()); |
626 } | 627 } |
627 | 628 |
628 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { | 629 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { |
629 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); | 630 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); |
630 | 631 |
631 EXPECT_TRUE(Register(sync_options_1_)); | 632 EXPECT_TRUE(Register(sync_options_1_)); |
632 EXPECT_TRUE(Register(sync_options_2_)); | 633 EXPECT_TRUE(Register(sync_options_2_)); |
633 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); | 634 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); |
634 | 635 |
635 EXPECT_EQ(2u, callback_registrations_.size()); | 636 EXPECT_EQ(2u, callback_registrations_->size()); |
636 sync_options_1_.Equals(*callback_registrations_[0].options()); | 637 sync_options_1_.Equals(*(*callback_registrations_)[0]->options()); |
637 sync_options_2_.Equals(*callback_registrations_[1].options()); | 638 sync_options_2_.Equals(*(*callback_registrations_)[1]->options()); |
638 } | 639 } |
639 | 640 |
640 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { | 641 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { |
641 sync_options_1_.periodicity = SYNC_ONE_SHOT; | 642 sync_options_1_.periodicity = SYNC_ONE_SHOT; |
642 sync_options_2_.periodicity = SYNC_PERIODIC; | 643 sync_options_2_.periodicity = SYNC_PERIODIC; |
643 EXPECT_TRUE(Register(sync_options_1_)); | 644 EXPECT_TRUE(Register(sync_options_1_)); |
644 EXPECT_TRUE(Register(sync_options_2_)); | 645 EXPECT_TRUE(Register(sync_options_2_)); |
645 | 646 |
646 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); | 647 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); |
647 EXPECT_EQ(1u, callback_registrations_.size()); | 648 EXPECT_EQ(1u, callback_registrations_->size()); |
648 sync_options_1_.Equals(*callback_registrations_[0].options()); | 649 sync_options_1_.Equals(*(*callback_registrations_)[0]->options()); |
649 | 650 |
650 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); | 651 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); |
651 EXPECT_EQ(1u, callback_registrations_.size()); | 652 EXPECT_EQ(1u, callback_registrations_->size()); |
652 sync_options_2_.Equals(*callback_registrations_[0].options()); | 653 sync_options_2_.Equals(*(*callback_registrations_)[0]->options()); |
653 } | 654 } |
654 | 655 |
655 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { | 656 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { |
656 EXPECT_TRUE(Register(sync_options_1_)); | 657 EXPECT_TRUE(Register(sync_options_1_)); |
657 test_background_sync_manager_->set_corrupt_backend(true); | 658 test_background_sync_manager_->set_corrupt_backend(true); |
658 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); | 659 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); |
659 EXPECT_FALSE(Register(sync_options_2_)); | 660 EXPECT_FALSE(Register(sync_options_2_)); |
660 // Registration should have discovered the bad backend and disabled the | 661 // Registration should have discovered the bad backend and disabled the |
661 // BackgroundSyncManager. | 662 // BackgroundSyncManager. |
662 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); | 663 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); |
663 test_background_sync_manager_->set_corrupt_backend(false); | 664 test_background_sync_manager_->set_corrupt_backend(false); |
664 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); | 665 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); |
665 } | 666 } |
666 | 667 |
667 TEST_F(BackgroundSyncManagerTest, Unregister) { | 668 TEST_F(BackgroundSyncManagerTest, Unregister) { |
668 EXPECT_TRUE(Register(sync_options_1_)); | 669 EXPECT_TRUE(Register(sync_options_1_)); |
669 EXPECT_TRUE(Unregister(callback_registration_)); | 670 EXPECT_TRUE(Unregister(callback_registration_.get())); |
670 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 671 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
671 } | 672 } |
672 | 673 |
673 TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) { | 674 TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) { |
674 EXPECT_TRUE(Register(sync_options_1_)); | 675 EXPECT_TRUE(Register(sync_options_1_)); |
675 callback_registration_.set_id(callback_registration_.id() + 1); | 676 callback_registration_->set_id(callback_registration_->id() + 1); |
676 EXPECT_FALSE(Unregister(callback_registration_)); | 677 EXPECT_FALSE(Unregister(callback_registration_.get())); |
678 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback_status_); | |
679 | |
680 // Set the id back so that it's released before closing down | |
681 callback_registration_->set_id(callback_registration_->id() - 1); | |
677 } | 682 } |
678 | 683 |
679 TEST_F(BackgroundSyncManagerTest, Reregister) { | 684 TEST_F(BackgroundSyncManagerTest, Reregister) { |
680 EXPECT_TRUE(Register(sync_options_1_)); | 685 EXPECT_TRUE(Register(sync_options_1_)); |
681 EXPECT_TRUE(Unregister(callback_registration_)); | 686 EXPECT_TRUE(Unregister(callback_registration_.get())); |
682 EXPECT_TRUE(Register(sync_options_1_)); | 687 EXPECT_TRUE(Register(sync_options_1_)); |
683 } | 688 } |
684 | 689 |
685 TEST_F(BackgroundSyncManagerTest, UnregisterNonExisting) { | |
iclelland
2015/08/14 14:44:18
There's still code in UnregisterImpl that does thi
jkarlin
2015/08/17 17:14:49
Thanks for pointing this out. The BackgroundSyncMa
| |
686 BackgroundSyncRegistration nonexistant_registration; | |
687 nonexistant_registration.set_id(1); | |
688 EXPECT_FALSE(Unregister(nonexistant_registration)); | |
689 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback_status_); | |
690 } | |
691 | |
692 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) { | 690 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) { |
693 EXPECT_TRUE(Register(sync_options_1_)); | 691 EXPECT_TRUE(Register(sync_options_1_)); |
694 EXPECT_TRUE(Register(sync_options_2_)); | 692 EXPECT_TRUE(Register(sync_options_2_)); |
695 EXPECT_TRUE(Unregister(callback_registration_)); | 693 EXPECT_TRUE(Unregister(callback_registration_.get())); |
696 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 694 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
697 EXPECT_TRUE(Register(sync_options_2_)); | 695 EXPECT_TRUE(Register(sync_options_2_)); |
698 } | 696 } |
699 | 697 |
700 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { | 698 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { |
701 sync_options_1_.min_period += 1; | 699 sync_options_1_.min_period += 1; |
702 EXPECT_TRUE(Register(sync_options_1_)); | 700 EXPECT_TRUE(Register(sync_options_1_)); |
703 EXPECT_TRUE(Register(sync_options_2_)); | 701 EXPECT_TRUE(Register(sync_options_2_)); |
704 test_background_sync_manager_->set_corrupt_backend(true); | 702 test_background_sync_manager_->set_corrupt_backend(true); |
705 EXPECT_FALSE(Unregister(callback_registration_)); | 703 EXPECT_FALSE(Unregister(callback_registration_.get())); |
706 // Unregister should have discovered the bad backend and disabled the | 704 // Unregister should have discovered the bad backend and disabled the |
707 // BackgroundSyncManager. | 705 // BackgroundSyncManager. |
708 test_background_sync_manager_->set_corrupt_backend(false); | 706 test_background_sync_manager_->set_corrupt_backend(false); |
709 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 707 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
710 EXPECT_FALSE(GetRegistration(sync_options_2_)); | 708 EXPECT_FALSE(GetRegistration(sync_options_2_)); |
711 } | 709 } |
712 | 710 |
713 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { | 711 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { |
714 EXPECT_TRUE(Register(sync_options_1_)); | 712 EXPECT_TRUE(Register(sync_options_1_)); |
715 BackgroundSyncRegistration registered_sync = callback_registration_; | 713 scoped_ptr<ClientBackgroundSyncRegistration> registered_sync = |
716 BackgroundSyncRegistration::RegistrationId cur_id = | 714 callback_registration_.Pass(); |
717 callback_registration_.id(); | 715 BackgroundSyncRegistration::RegistrationId cur_id = registered_sync->id(); |
718 | 716 |
719 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 717 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
720 EXPECT_TRUE(Register(sync_options_2_)); | 718 EXPECT_TRUE(Register(sync_options_2_)); |
721 EXPECT_LT(cur_id, callback_registration_.id()); | 719 EXPECT_LT(cur_id, callback_registration_->id()); |
722 cur_id = callback_registration_.id(); | 720 cur_id = callback_registration_->id(); |
723 | 721 |
724 EXPECT_TRUE(Unregister(registered_sync)); | 722 EXPECT_TRUE(Unregister(registered_sync.get())); |
725 EXPECT_TRUE(Register(sync_options_1_)); | 723 EXPECT_TRUE(Register(sync_options_1_)); |
726 EXPECT_LT(cur_id, callback_registration_.id()); | 724 EXPECT_LT(cur_id, callback_registration_->id()); |
727 } | 725 } |
728 | 726 |
729 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { | 727 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { |
730 EXPECT_TRUE(Register(sync_options_1_)); | 728 EXPECT_TRUE(Register(sync_options_1_)); |
731 | 729 |
732 SetupBackgroundSyncManager(); | 730 SetupBackgroundSyncManager(); |
733 | 731 |
734 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 732 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
735 EXPECT_FALSE(GetRegistration(sync_options_2_)); | 733 EXPECT_FALSE(GetRegistration(sync_options_2_)); |
736 } | 734 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 | 766 |
769 EXPECT_FALSE(Register(sync_options_1_)); | 767 EXPECT_FALSE(Register(sync_options_1_)); |
770 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 768 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
771 } | 769 } |
772 | 770 |
773 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { | 771 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { |
774 // Schedule Init and all of the operations on a delayed backend. Verify that | 772 // Schedule Init and all of the operations on a delayed backend. Verify that |
775 // the operations complete sequentially. | 773 // the operations complete sequentially. |
776 SetupDelayedBackgroundSyncManager(); | 774 SetupDelayedBackgroundSyncManager(); |
777 | 775 |
778 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId; | |
779 | |
780 bool register_called = false; | 776 bool register_called = false; |
781 bool unregister_called = false; | |
782 bool get_registration_called = false; | 777 bool get_registration_called = false; |
783 test_background_sync_manager_->Register( | 778 test_background_sync_manager_->Register( |
784 sw_registration_id_1_, sync_options_1_, | 779 sw_registration_id_1_, sync_options_1_, |
785 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 780 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
786 base::Unretained(this), ®ister_called)); | 781 base::Unretained(this), ®ister_called)); |
787 test_background_sync_manager_->Unregister( | |
788 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, | |
789 kExpectedInitialId, | |
790 base::Bind(&BackgroundSyncManagerTest::StatusCallback, | |
791 base::Unretained(this), &unregister_called)); | |
792 test_background_sync_manager_->GetRegistration( | 782 test_background_sync_manager_->GetRegistration( |
793 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, | 783 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, |
794 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 784 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
795 base::Unretained(this), &get_registration_called)); | 785 base::Unretained(this), &get_registration_called)); |
796 | 786 |
797 base::RunLoop().RunUntilIdle(); | 787 base::RunLoop().RunUntilIdle(); |
798 // Init should be blocked while loading from the backend. | 788 // Init should be blocked while loading from the backend. |
799 EXPECT_FALSE(register_called); | 789 EXPECT_FALSE(register_called); |
800 EXPECT_FALSE(unregister_called); | |
801 EXPECT_FALSE(get_registration_called); | 790 EXPECT_FALSE(get_registration_called); |
802 | 791 |
803 test_background_sync_manager_->Continue(); | 792 test_background_sync_manager_->Continue(); |
804 base::RunLoop().RunUntilIdle(); | 793 base::RunLoop().RunUntilIdle(); |
805 // Register should be blocked while storing to the backend. | 794 // Register should be blocked while storing to the backend. |
806 EXPECT_FALSE(register_called); | 795 EXPECT_FALSE(register_called); |
807 EXPECT_FALSE(unregister_called); | |
808 EXPECT_FALSE(get_registration_called); | 796 EXPECT_FALSE(get_registration_called); |
809 | 797 |
810 test_background_sync_manager_->Continue(); | 798 test_background_sync_manager_->Continue(); |
811 base::RunLoop().RunUntilIdle(); | 799 base::RunLoop().RunUntilIdle(); |
812 EXPECT_TRUE(register_called); | 800 EXPECT_TRUE(register_called); |
813 EXPECT_EQ(kExpectedInitialId, callback_registration_.id()); | |
814 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); | 801 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); |
815 // Unregister should be blocked while storing to the backend. | 802 // GetRegistration should run immediately as it doesn't write to disk. |
816 EXPECT_FALSE(unregister_called); | |
817 EXPECT_FALSE(get_registration_called); | |
818 | |
819 test_background_sync_manager_->Continue(); | |
820 base::RunLoop().RunUntilIdle(); | |
821 // Unregister should be done and since GetRegistration doesn't require the | |
822 // backend it should be done too. | |
823 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback_status_); | |
824 EXPECT_TRUE(unregister_called); | |
825 EXPECT_TRUE(get_registration_called); | 803 EXPECT_TRUE(get_registration_called); |
826 } | 804 } |
827 | 805 |
828 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { | 806 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { |
829 EXPECT_TRUE(Register(sync_options_1_)); | 807 EXPECT_TRUE(Register(sync_options_1_)); |
830 UnregisterServiceWorker(sw_registration_id_1_); | 808 UnregisterServiceWorker(sw_registration_id_1_); |
831 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 809 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
832 } | 810 } |
833 | 811 |
834 TEST_F(BackgroundSyncManagerTest, | 812 TEST_F(BackgroundSyncManagerTest, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 options.power_state = POWER_STATE_AUTO; | 940 options.power_state = POWER_STATE_AUTO; |
963 | 941 |
964 // Store the registration. | 942 // Store the registration. |
965 EXPECT_TRUE(Register(options)); | 943 EXPECT_TRUE(Register(options)); |
966 | 944 |
967 // Simulate restarting the sync manager, forcing the next read to come from | 945 // Simulate restarting the sync manager, forcing the next read to come from |
968 // disk. | 946 // disk. |
969 SetupBackgroundSyncManager(); | 947 SetupBackgroundSyncManager(); |
970 | 948 |
971 EXPECT_TRUE(GetRegistration(options)); | 949 EXPECT_TRUE(GetRegistration(options)); |
972 EXPECT_TRUE(options.Equals(*callback_registration_.options())); | 950 EXPECT_TRUE(options.Equals(*callback_registration_->options())); |
973 } | 951 } |
974 | 952 |
975 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { | 953 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { |
976 sync_options_1_.tag = "a"; | 954 sync_options_1_.tag = "a"; |
977 EXPECT_TRUE(Register(sync_options_1_)); | 955 EXPECT_TRUE(Register(sync_options_1_)); |
978 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 956 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
979 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_.options())); | 957 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_->options())); |
980 EXPECT_TRUE(Unregister(callback_registration_)); | 958 EXPECT_TRUE(Unregister(callback_registration_.get())); |
981 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 959 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
982 } | 960 } |
983 | 961 |
984 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { | 962 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { |
985 // Registrations with the same tags but different periodicities should not | 963 // Registrations with the same tags but different periodicities should not |
986 // collide. | 964 // collide. |
987 sync_options_1_.tag = ""; | 965 sync_options_1_.tag = ""; |
988 sync_options_2_.tag = ""; | 966 sync_options_2_.tag = ""; |
989 sync_options_1_.periodicity = SYNC_PERIODIC; | 967 sync_options_1_.periodicity = SYNC_PERIODIC; |
990 sync_options_2_.periodicity = SYNC_ONE_SHOT; | 968 sync_options_2_.periodicity = SYNC_ONE_SHOT; |
991 | 969 |
992 EXPECT_TRUE(Register(sync_options_1_)); | 970 EXPECT_TRUE(Register(sync_options_1_)); |
993 EXPECT_TRUE(Register(sync_options_2_)); | 971 EXPECT_TRUE(Register(sync_options_2_)); |
994 | 972 |
995 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 973 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
996 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); | 974 EXPECT_EQ(SYNC_PERIODIC, callback_registration_->options()->periodicity); |
997 EXPECT_TRUE(GetRegistration(sync_options_2_)); | 975 EXPECT_TRUE(GetRegistration(sync_options_2_)); |
998 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); | 976 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity); |
999 | 977 |
1000 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 978 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
1001 EXPECT_TRUE(Unregister(callback_registration_)); | 979 EXPECT_TRUE(Unregister(callback_registration_.get())); |
1002 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 980 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1003 EXPECT_TRUE(GetRegistration(sync_options_2_)); | 981 EXPECT_TRUE(GetRegistration(sync_options_2_)); |
1004 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); | 982 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity); |
1005 | 983 |
1006 EXPECT_TRUE(Unregister(callback_registration_)); | 984 EXPECT_TRUE(Unregister(callback_registration_.get())); |
1007 EXPECT_FALSE(GetRegistration(sync_options_2_)); | 985 EXPECT_FALSE(GetRegistration(sync_options_2_)); |
1008 } | 986 } |
1009 | 987 |
1010 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { | 988 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { |
1011 InitSyncEventTest(); | 989 InitSyncEventTest(); |
1012 | 990 |
1013 EXPECT_TRUE(Register(sync_options_1_)); | 991 EXPECT_TRUE(Register(sync_options_1_)); |
1014 EXPECT_EQ(1, sync_events_called_); | 992 EXPECT_EQ(1, sync_events_called_); |
1015 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 993 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1016 } | 994 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 1097 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
1120 } | 1098 } |
1121 | 1099 |
1122 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { | 1100 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { |
1123 InitFailedSyncEventTest(); | 1101 InitFailedSyncEventTest(); |
1124 | 1102 |
1125 // The initial sync event fails. | 1103 // The initial sync event fails. |
1126 EXPECT_TRUE(Register(sync_options_1_)); | 1104 EXPECT_TRUE(Register(sync_options_1_)); |
1127 EXPECT_EQ(1, sync_events_called_); | 1105 EXPECT_EQ(1, sync_events_called_); |
1128 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 1106 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
1129 BackgroundSyncRegistration first_registration = callback_registration_; | |
1130 | 1107 |
1131 InitSyncEventTest(); | 1108 InitSyncEventTest(); |
1132 | 1109 |
1133 // Reregistering should cause the sync event to fire again, this time | 1110 // Reregistering should cause the sync event to fire again, this time |
1134 // succeeding. | 1111 // succeeding. |
1135 EXPECT_TRUE(Register(sync_options_1_)); | 1112 EXPECT_TRUE(Register(sync_options_1_)); |
1136 EXPECT_EQ(first_registration.id(), callback_registration_.id()); | |
1137 EXPECT_EQ(2, sync_events_called_); | 1113 EXPECT_EQ(2, sync_events_called_); |
1138 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1114 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1139 } | 1115 } |
1140 | 1116 |
1141 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { | 1117 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { |
1142 InitDelayedSyncEventTest(); | 1118 InitDelayedSyncEventTest(); |
1143 | 1119 |
1144 RegisterAndVerifySyncEventDelayed(sync_options_1_); | 1120 RegisterAndVerifySyncEventDelayed(sync_options_1_); |
1145 | 1121 |
1146 // Finish firing the event and verify that the registration is removed. | 1122 // Finish firing the event and verify that the registration is removed. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1200 base::RunLoop().RunUntilIdle(); | 1176 base::RunLoop().RunUntilIdle(); |
1201 EXPECT_EQ(1, sync_events_called_); | 1177 EXPECT_EQ(1, sync_events_called_); |
1202 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1178 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1203 } | 1179 } |
1204 | 1180 |
1205 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { | 1181 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { |
1206 InitDelayedSyncEventTest(); | 1182 InitDelayedSyncEventTest(); |
1207 | 1183 |
1208 RegisterAndVerifySyncEventDelayed(sync_options_1_); | 1184 RegisterAndVerifySyncEventDelayed(sync_options_1_); |
1209 | 1185 |
1210 EXPECT_TRUE(Unregister(callback_registration_)); | 1186 EXPECT_TRUE(Unregister(callback_registration_.get())); |
1211 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1187 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1212 | 1188 |
1213 sync_fired_callback_.Run(SERVICE_WORKER_OK); | 1189 sync_fired_callback_.Run(SERVICE_WORKER_OK); |
1214 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1190 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1215 } | 1191 } |
1216 | 1192 |
1217 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { | 1193 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { |
1218 InitDelayedSyncEventTest(); | 1194 InitDelayedSyncEventTest(); |
1219 | 1195 |
1220 RegisterAndVerifySyncEventDelayed(sync_options_1_); | 1196 RegisterAndVerifySyncEventDelayed(sync_options_1_); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1265 | 1241 |
1266 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { | 1242 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { |
1267 EXPECT_TRUE(Register(sync_options_1_)); | 1243 EXPECT_TRUE(Register(sync_options_1_)); |
1268 RemoveWindowClients(); | 1244 RemoveWindowClients(); |
1269 EXPECT_FALSE(Register(sync_options_1_)); | 1245 EXPECT_FALSE(Register(sync_options_1_)); |
1270 } | 1246 } |
1271 | 1247 |
1272 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { | 1248 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { |
1273 EXPECT_TRUE(Register(sync_options_1_)); | 1249 EXPECT_TRUE(Register(sync_options_1_)); |
1274 RemoveWindowClients(); | 1250 RemoveWindowClients(); |
1275 EXPECT_TRUE(Unregister(callback_registration_)); | 1251 EXPECT_TRUE(Unregister(callback_registration_.get())); |
1276 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1252 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1277 } | 1253 } |
1278 | 1254 |
1279 } // namespace content | 1255 } // namespace content |
OLD | NEW |