| 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_registration_handle.h" |
| 15 #include "content/browser/background_sync/background_sync_status.h" | 16 #include "content/browser/background_sync/background_sync_status.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 |
| (...skipping 95 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 const 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<BackgroundSyncRegistrationHandle> 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<BackgroundSyncRegistrationHandle>> |
| 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(BackgroundSyncRegistrationHandle* 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 BackgroundSyncRegistrationHandle* 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<BackgroundSyncRegistrationHandle> callback_registration_; |
| 518 std::vector<BackgroundSyncRegistration> callback_registrations_; | 525 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> |
| 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) { | |
| 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<BackgroundSyncRegistrationHandle> 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->handle_id(), |
| 562 EXPECT_FALSE(callback_registration_.Equals(first_registration)); | 563 callback_registration_->handle_id()); |
| 564 EXPECT_FALSE(first_registration->options()->Equals( |
| 565 *callback_registration_->options())); |
| 563 } | 566 } |
| 564 | 567 |
| 565 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { | 568 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { |
| 566 // Registrations with the same tags but different periodicities should not | 569 // Registrations with the same tags but different periodicities should not |
| 567 // collide. | 570 // collide. |
| 568 sync_options_1_.tag = ""; | 571 sync_options_1_.tag = ""; |
| 569 sync_options_2_.tag = ""; | 572 sync_options_2_.tag = ""; |
| 570 sync_options_1_.periodicity = SYNC_PERIODIC; | 573 sync_options_1_.periodicity = SYNC_PERIODIC; |
| 571 sync_options_2_.periodicity = SYNC_ONE_SHOT; | 574 sync_options_2_.periodicity = SYNC_ONE_SHOT; |
| 572 EXPECT_TRUE(Register(sync_options_1_)); | 575 EXPECT_TRUE(Register(sync_options_1_)); |
| 573 EXPECT_TRUE(Register(sync_options_2_)); | 576 EXPECT_TRUE(Register(sync_options_2_)); |
| 574 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 577 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 575 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); | 578 EXPECT_EQ(SYNC_PERIODIC, callback_registration_->options()->periodicity); |
| 576 EXPECT_TRUE(GetRegistration(sync_options_2_)); | 579 EXPECT_TRUE(GetRegistration(sync_options_2_)); |
| 577 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); | 580 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity); |
| 578 } | 581 } |
| 579 | 582 |
| 580 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { | 583 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { |
| 581 test_background_sync_manager_->set_corrupt_backend(true); | 584 test_background_sync_manager_->set_corrupt_backend(true); |
| 582 EXPECT_FALSE(Register(sync_options_1_)); | 585 EXPECT_FALSE(Register(sync_options_1_)); |
| 583 test_background_sync_manager_->set_corrupt_backend(false); | 586 test_background_sync_manager_->set_corrupt_backend(false); |
| 584 EXPECT_FALSE(Register(sync_options_1_)); | 587 EXPECT_FALSE(Register(sync_options_1_)); |
| 585 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 588 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 586 } | 589 } |
| 587 | 590 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 607 EXPECT_FALSE(Register(sync_options_2_)); | 610 EXPECT_FALSE(Register(sync_options_2_)); |
| 608 // Registration should have discovered the bad backend and disabled the | 611 // Registration should have discovered the bad backend and disabled the |
| 609 // BackgroundSyncManager. | 612 // BackgroundSyncManager. |
| 610 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 613 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 611 test_background_sync_manager_->set_corrupt_backend(false); | 614 test_background_sync_manager_->set_corrupt_backend(false); |
| 612 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 615 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 613 } | 616 } |
| 614 | 617 |
| 615 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { | 618 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { |
| 616 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); | 619 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); |
| 617 EXPECT_EQ(0u, callback_registrations_.size()); | 620 EXPECT_EQ(0u, callback_registrations_->size()); |
| 618 } | 621 } |
| 619 | 622 |
| 620 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { | 623 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { |
| 621 EXPECT_TRUE(Register(sync_options_1_)); | 624 EXPECT_TRUE(Register(sync_options_1_)); |
| 622 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); | 625 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); |
| 623 | 626 |
| 624 EXPECT_EQ(1u, callback_registrations_.size()); | 627 EXPECT_EQ(1u, callback_registrations_->size()); |
| 625 sync_options_1_.Equals(*callback_registrations_[0].options()); | 628 sync_options_1_.Equals(*(*callback_registrations_)[0]->options()); |
| 626 } | 629 } |
| 627 | 630 |
| 628 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { | 631 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { |
| 629 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); | 632 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); |
| 630 | 633 |
| 631 EXPECT_TRUE(Register(sync_options_1_)); | 634 EXPECT_TRUE(Register(sync_options_1_)); |
| 632 EXPECT_TRUE(Register(sync_options_2_)); | 635 EXPECT_TRUE(Register(sync_options_2_)); |
| 633 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); | 636 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); |
| 634 | 637 |
| 635 EXPECT_EQ(2u, callback_registrations_.size()); | 638 EXPECT_EQ(2u, callback_registrations_->size()); |
| 636 sync_options_1_.Equals(*callback_registrations_[0].options()); | 639 sync_options_1_.Equals(*(*callback_registrations_)[0]->options()); |
| 637 sync_options_2_.Equals(*callback_registrations_[1].options()); | 640 sync_options_2_.Equals(*(*callback_registrations_)[1]->options()); |
| 638 } | 641 } |
| 639 | 642 |
| 640 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { | 643 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { |
| 641 sync_options_1_.periodicity = SYNC_ONE_SHOT; | 644 sync_options_1_.periodicity = SYNC_ONE_SHOT; |
| 642 sync_options_2_.periodicity = SYNC_PERIODIC; | 645 sync_options_2_.periodicity = SYNC_PERIODIC; |
| 643 EXPECT_TRUE(Register(sync_options_1_)); | 646 EXPECT_TRUE(Register(sync_options_1_)); |
| 644 EXPECT_TRUE(Register(sync_options_2_)); | 647 EXPECT_TRUE(Register(sync_options_2_)); |
| 645 | 648 |
| 646 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); | 649 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); |
| 647 EXPECT_EQ(1u, callback_registrations_.size()); | 650 EXPECT_EQ(1u, callback_registrations_->size()); |
| 648 sync_options_1_.Equals(*callback_registrations_[0].options()); | 651 sync_options_1_.Equals(*(*callback_registrations_)[0]->options()); |
| 649 | 652 |
| 650 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); | 653 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); |
| 651 EXPECT_EQ(1u, callback_registrations_.size()); | 654 EXPECT_EQ(1u, callback_registrations_->size()); |
| 652 sync_options_2_.Equals(*callback_registrations_[0].options()); | 655 sync_options_2_.Equals(*(*callback_registrations_)[0]->options()); |
| 653 } | 656 } |
| 654 | 657 |
| 655 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { | 658 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { |
| 656 EXPECT_TRUE(Register(sync_options_1_)); | 659 EXPECT_TRUE(Register(sync_options_1_)); |
| 657 test_background_sync_manager_->set_corrupt_backend(true); | 660 test_background_sync_manager_->set_corrupt_backend(true); |
| 658 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); | 661 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); |
| 659 EXPECT_FALSE(Register(sync_options_2_)); | 662 EXPECT_FALSE(Register(sync_options_2_)); |
| 660 // Registration should have discovered the bad backend and disabled the | 663 // Registration should have discovered the bad backend and disabled the |
| 661 // BackgroundSyncManager. | 664 // BackgroundSyncManager. |
| 662 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); | 665 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); |
| 663 test_background_sync_manager_->set_corrupt_backend(false); | 666 test_background_sync_manager_->set_corrupt_backend(false); |
| 664 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); | 667 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); |
| 665 } | 668 } |
| 666 | 669 |
| 667 TEST_F(BackgroundSyncManagerTest, Unregister) { | 670 TEST_F(BackgroundSyncManagerTest, Unregister) { |
| 668 EXPECT_TRUE(Register(sync_options_1_)); | 671 EXPECT_TRUE(Register(sync_options_1_)); |
| 669 EXPECT_TRUE(Unregister(callback_registration_)); | 672 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 670 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 673 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 671 } | 674 } |
| 672 | 675 |
| 673 TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) { | |
| 674 EXPECT_TRUE(Register(sync_options_1_)); | |
| 675 callback_registration_.set_id(callback_registration_.id() + 1); | |
| 676 EXPECT_FALSE(Unregister(callback_registration_)); | |
| 677 } | |
| 678 | |
| 679 TEST_F(BackgroundSyncManagerTest, Reregister) { | 676 TEST_F(BackgroundSyncManagerTest, Reregister) { |
| 680 EXPECT_TRUE(Register(sync_options_1_)); | 677 EXPECT_TRUE(Register(sync_options_1_)); |
| 681 EXPECT_TRUE(Unregister(callback_registration_)); | 678 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 682 EXPECT_TRUE(Register(sync_options_1_)); | 679 EXPECT_TRUE(Register(sync_options_1_)); |
| 683 } | 680 } |
| 684 | 681 |
| 685 TEST_F(BackgroundSyncManagerTest, UnregisterNonExisting) { | |
| 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) { | 682 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) { |
| 693 EXPECT_TRUE(Register(sync_options_1_)); | 683 EXPECT_TRUE(Register(sync_options_1_)); |
| 694 EXPECT_TRUE(Register(sync_options_2_)); | 684 EXPECT_TRUE(Register(sync_options_2_)); |
| 695 EXPECT_TRUE(Unregister(callback_registration_)); | 685 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 696 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 686 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 697 EXPECT_TRUE(Register(sync_options_2_)); | 687 EXPECT_TRUE(Register(sync_options_2_)); |
| 698 } | 688 } |
| 699 | 689 |
| 700 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { | 690 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { |
| 701 sync_options_1_.min_period += 1; | 691 sync_options_1_.min_period += 1; |
| 702 EXPECT_TRUE(Register(sync_options_1_)); | 692 EXPECT_TRUE(Register(sync_options_1_)); |
| 703 EXPECT_TRUE(Register(sync_options_2_)); | 693 EXPECT_TRUE(Register(sync_options_2_)); |
| 704 test_background_sync_manager_->set_corrupt_backend(true); | 694 test_background_sync_manager_->set_corrupt_backend(true); |
| 705 EXPECT_FALSE(Unregister(callback_registration_)); | 695 EXPECT_FALSE(Unregister(callback_registration_.get())); |
| 706 // Unregister should have discovered the bad backend and disabled the | 696 // Unregister should have discovered the bad backend and disabled the |
| 707 // BackgroundSyncManager. | 697 // BackgroundSyncManager. |
| 708 test_background_sync_manager_->set_corrupt_backend(false); | 698 test_background_sync_manager_->set_corrupt_backend(false); |
| 709 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 699 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 710 EXPECT_FALSE(GetRegistration(sync_options_2_)); | 700 EXPECT_FALSE(GetRegistration(sync_options_2_)); |
| 711 } | 701 } |
| 712 | 702 |
| 713 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { | 703 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { |
| 714 EXPECT_TRUE(Register(sync_options_1_)); | 704 EXPECT_TRUE(Register(sync_options_1_)); |
| 715 BackgroundSyncRegistration registered_sync = callback_registration_; | 705 scoped_ptr<BackgroundSyncRegistrationHandle> registered_sync = |
| 706 callback_registration_.Pass(); |
| 716 BackgroundSyncRegistration::RegistrationId cur_id = | 707 BackgroundSyncRegistration::RegistrationId cur_id = |
| 717 callback_registration_.id(); | 708 registered_sync->handle_id(); |
| 718 | 709 |
| 719 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 710 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 720 EXPECT_TRUE(Register(sync_options_2_)); | 711 EXPECT_TRUE(Register(sync_options_2_)); |
| 721 EXPECT_LT(cur_id, callback_registration_.id()); | 712 EXPECT_LT(cur_id, callback_registration_->handle_id()); |
| 722 cur_id = callback_registration_.id(); | 713 cur_id = callback_registration_->handle_id(); |
| 723 | 714 |
| 724 EXPECT_TRUE(Unregister(registered_sync)); | 715 EXPECT_TRUE(Unregister(registered_sync.get())); |
| 725 EXPECT_TRUE(Register(sync_options_1_)); | 716 EXPECT_TRUE(Register(sync_options_1_)); |
| 726 EXPECT_LT(cur_id, callback_registration_.id()); | 717 EXPECT_LT(cur_id, callback_registration_->handle_id()); |
| 727 } | 718 } |
| 728 | 719 |
| 729 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { | 720 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { |
| 730 EXPECT_TRUE(Register(sync_options_1_)); | 721 EXPECT_TRUE(Register(sync_options_1_)); |
| 731 | 722 |
| 732 SetupBackgroundSyncManager(); | 723 SetupBackgroundSyncManager(); |
| 733 | 724 |
| 734 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 725 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 735 EXPECT_FALSE(GetRegistration(sync_options_2_)); | 726 EXPECT_FALSE(GetRegistration(sync_options_2_)); |
| 736 } | 727 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 | 759 |
| 769 EXPECT_FALSE(Register(sync_options_1_)); | 760 EXPECT_FALSE(Register(sync_options_1_)); |
| 770 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 761 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 771 } | 762 } |
| 772 | 763 |
| 773 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { | 764 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { |
| 774 // Schedule Init and all of the operations on a delayed backend. Verify that | 765 // Schedule Init and all of the operations on a delayed backend. Verify that |
| 775 // the operations complete sequentially. | 766 // the operations complete sequentially. |
| 776 SetupDelayedBackgroundSyncManager(); | 767 SetupDelayedBackgroundSyncManager(); |
| 777 | 768 |
| 778 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId; | |
| 779 | |
| 780 bool register_called = false; | 769 bool register_called = false; |
| 781 bool unregister_called = false; | |
| 782 bool get_registration_called = false; | 770 bool get_registration_called = false; |
| 783 test_background_sync_manager_->Register( | 771 test_background_sync_manager_->Register( |
| 784 sw_registration_id_1_, sync_options_1_, | 772 sw_registration_id_1_, sync_options_1_, |
| 785 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 773 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 786 base::Unretained(this), ®ister_called)); | 774 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( | 775 test_background_sync_manager_->GetRegistration( |
| 793 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, | 776 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, |
| 794 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 777 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 795 base::Unretained(this), &get_registration_called)); | 778 base::Unretained(this), &get_registration_called)); |
| 796 | 779 |
| 797 base::RunLoop().RunUntilIdle(); | 780 base::RunLoop().RunUntilIdle(); |
| 798 // Init should be blocked while loading from the backend. | 781 // Init should be blocked while loading from the backend. |
| 799 EXPECT_FALSE(register_called); | 782 EXPECT_FALSE(register_called); |
| 800 EXPECT_FALSE(unregister_called); | |
| 801 EXPECT_FALSE(get_registration_called); | 783 EXPECT_FALSE(get_registration_called); |
| 802 | 784 |
| 803 test_background_sync_manager_->Continue(); | 785 test_background_sync_manager_->Continue(); |
| 804 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
| 805 // Register should be blocked while storing to the backend. | 787 // Register should be blocked while storing to the backend. |
| 806 EXPECT_FALSE(register_called); | 788 EXPECT_FALSE(register_called); |
| 807 EXPECT_FALSE(unregister_called); | |
| 808 EXPECT_FALSE(get_registration_called); | 789 EXPECT_FALSE(get_registration_called); |
| 809 | 790 |
| 810 test_background_sync_manager_->Continue(); | 791 test_background_sync_manager_->Continue(); |
| 811 base::RunLoop().RunUntilIdle(); | 792 base::RunLoop().RunUntilIdle(); |
| 812 EXPECT_TRUE(register_called); | 793 EXPECT_TRUE(register_called); |
| 813 EXPECT_EQ(kExpectedInitialId, callback_registration_.id()); | |
| 814 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); | 794 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); |
| 815 // Unregister should be blocked while storing to the backend. | 795 // 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); | 796 EXPECT_TRUE(get_registration_called); |
| 826 } | 797 } |
| 827 | 798 |
| 828 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { | 799 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { |
| 829 EXPECT_TRUE(Register(sync_options_1_)); | 800 EXPECT_TRUE(Register(sync_options_1_)); |
| 830 UnregisterServiceWorker(sw_registration_id_1_); | 801 UnregisterServiceWorker(sw_registration_id_1_); |
| 831 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 802 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 832 } | 803 } |
| 833 | 804 |
| 834 TEST_F(BackgroundSyncManagerTest, | 805 TEST_F(BackgroundSyncManagerTest, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 options.power_state = POWER_STATE_AUTO; | 933 options.power_state = POWER_STATE_AUTO; |
| 963 | 934 |
| 964 // Store the registration. | 935 // Store the registration. |
| 965 EXPECT_TRUE(Register(options)); | 936 EXPECT_TRUE(Register(options)); |
| 966 | 937 |
| 967 // Simulate restarting the sync manager, forcing the next read to come from | 938 // Simulate restarting the sync manager, forcing the next read to come from |
| 968 // disk. | 939 // disk. |
| 969 SetupBackgroundSyncManager(); | 940 SetupBackgroundSyncManager(); |
| 970 | 941 |
| 971 EXPECT_TRUE(GetRegistration(options)); | 942 EXPECT_TRUE(GetRegistration(options)); |
| 972 EXPECT_TRUE(options.Equals(*callback_registration_.options())); | 943 EXPECT_TRUE(options.Equals(*callback_registration_->options())); |
| 973 } | 944 } |
| 974 | 945 |
| 975 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { | 946 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { |
| 976 sync_options_1_.tag = "a"; | 947 sync_options_1_.tag = "a"; |
| 977 EXPECT_TRUE(Register(sync_options_1_)); | 948 EXPECT_TRUE(Register(sync_options_1_)); |
| 978 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 949 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 979 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_.options())); | 950 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_->options())); |
| 980 EXPECT_TRUE(Unregister(callback_registration_)); | 951 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 981 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 952 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 982 } | 953 } |
| 983 | 954 |
| 984 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { | 955 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { |
| 985 // Registrations with the same tags but different periodicities should not | 956 // Registrations with the same tags but different periodicities should not |
| 986 // collide. | 957 // collide. |
| 987 sync_options_1_.tag = ""; | 958 sync_options_1_.tag = ""; |
| 988 sync_options_2_.tag = ""; | 959 sync_options_2_.tag = ""; |
| 989 sync_options_1_.periodicity = SYNC_PERIODIC; | 960 sync_options_1_.periodicity = SYNC_PERIODIC; |
| 990 sync_options_2_.periodicity = SYNC_ONE_SHOT; | 961 sync_options_2_.periodicity = SYNC_ONE_SHOT; |
| 991 | 962 |
| 992 EXPECT_TRUE(Register(sync_options_1_)); | 963 EXPECT_TRUE(Register(sync_options_1_)); |
| 993 EXPECT_TRUE(Register(sync_options_2_)); | 964 EXPECT_TRUE(Register(sync_options_2_)); |
| 994 | 965 |
| 995 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 966 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 996 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); | 967 EXPECT_EQ(SYNC_PERIODIC, callback_registration_->options()->periodicity); |
| 997 EXPECT_TRUE(GetRegistration(sync_options_2_)); | 968 EXPECT_TRUE(GetRegistration(sync_options_2_)); |
| 998 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); | 969 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity); |
| 999 | 970 |
| 1000 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 971 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 1001 EXPECT_TRUE(Unregister(callback_registration_)); | 972 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 1002 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 973 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1003 EXPECT_TRUE(GetRegistration(sync_options_2_)); | 974 EXPECT_TRUE(GetRegistration(sync_options_2_)); |
| 1004 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); | 975 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity); |
| 1005 | 976 |
| 1006 EXPECT_TRUE(Unregister(callback_registration_)); | 977 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 1007 EXPECT_FALSE(GetRegistration(sync_options_2_)); | 978 EXPECT_FALSE(GetRegistration(sync_options_2_)); |
| 1008 } | 979 } |
| 1009 | 980 |
| 1010 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { | 981 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { |
| 1011 InitSyncEventTest(); | 982 InitSyncEventTest(); |
| 1012 | 983 |
| 1013 EXPECT_TRUE(Register(sync_options_1_)); | 984 EXPECT_TRUE(Register(sync_options_1_)); |
| 1014 EXPECT_EQ(1, sync_events_called_); | 985 EXPECT_EQ(1, sync_events_called_); |
| 1015 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 986 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1016 } | 987 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 1090 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 1120 } | 1091 } |
| 1121 | 1092 |
| 1122 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { | 1093 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { |
| 1123 InitFailedSyncEventTest(); | 1094 InitFailedSyncEventTest(); |
| 1124 | 1095 |
| 1125 // The initial sync event fails. | 1096 // The initial sync event fails. |
| 1126 EXPECT_TRUE(Register(sync_options_1_)); | 1097 EXPECT_TRUE(Register(sync_options_1_)); |
| 1127 EXPECT_EQ(1, sync_events_called_); | 1098 EXPECT_EQ(1, sync_events_called_); |
| 1128 EXPECT_TRUE(GetRegistration(sync_options_1_)); | 1099 EXPECT_TRUE(GetRegistration(sync_options_1_)); |
| 1129 BackgroundSyncRegistration first_registration = callback_registration_; | |
| 1130 | 1100 |
| 1131 InitSyncEventTest(); | 1101 InitSyncEventTest(); |
| 1132 | 1102 |
| 1133 // Reregistering should cause the sync event to fire again, this time | 1103 // Reregistering should cause the sync event to fire again, this time |
| 1134 // succeeding. | 1104 // succeeding. |
| 1135 EXPECT_TRUE(Register(sync_options_1_)); | 1105 EXPECT_TRUE(Register(sync_options_1_)); |
| 1136 EXPECT_EQ(first_registration.id(), callback_registration_.id()); | |
| 1137 EXPECT_EQ(2, sync_events_called_); | 1106 EXPECT_EQ(2, sync_events_called_); |
| 1138 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1107 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1139 } | 1108 } |
| 1140 | 1109 |
| 1141 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { | 1110 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { |
| 1142 InitDelayedSyncEventTest(); | 1111 InitDelayedSyncEventTest(); |
| 1143 | 1112 |
| 1144 RegisterAndVerifySyncEventDelayed(sync_options_1_); | 1113 RegisterAndVerifySyncEventDelayed(sync_options_1_); |
| 1145 | 1114 |
| 1146 // Finish firing the event and verify that the registration is removed. | 1115 // 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(); | 1169 base::RunLoop().RunUntilIdle(); |
| 1201 EXPECT_EQ(1, sync_events_called_); | 1170 EXPECT_EQ(1, sync_events_called_); |
| 1202 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1171 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1203 } | 1172 } |
| 1204 | 1173 |
| 1205 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { | 1174 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { |
| 1206 InitDelayedSyncEventTest(); | 1175 InitDelayedSyncEventTest(); |
| 1207 | 1176 |
| 1208 RegisterAndVerifySyncEventDelayed(sync_options_1_); | 1177 RegisterAndVerifySyncEventDelayed(sync_options_1_); |
| 1209 | 1178 |
| 1210 EXPECT_TRUE(Unregister(callback_registration_)); | 1179 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 1211 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1180 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1212 | 1181 |
| 1213 sync_fired_callback_.Run(SERVICE_WORKER_OK); | 1182 sync_fired_callback_.Run(SERVICE_WORKER_OK); |
| 1214 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1183 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1215 } | 1184 } |
| 1216 | 1185 |
| 1217 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { | 1186 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { |
| 1218 InitDelayedSyncEventTest(); | 1187 InitDelayedSyncEventTest(); |
| 1219 | 1188 |
| 1220 RegisterAndVerifySyncEventDelayed(sync_options_1_); | 1189 RegisterAndVerifySyncEventDelayed(sync_options_1_); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 | 1234 |
| 1266 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { | 1235 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { |
| 1267 EXPECT_TRUE(Register(sync_options_1_)); | 1236 EXPECT_TRUE(Register(sync_options_1_)); |
| 1268 RemoveWindowClients(); | 1237 RemoveWindowClients(); |
| 1269 EXPECT_FALSE(Register(sync_options_1_)); | 1238 EXPECT_FALSE(Register(sync_options_1_)); |
| 1270 } | 1239 } |
| 1271 | 1240 |
| 1272 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { | 1241 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { |
| 1273 EXPECT_TRUE(Register(sync_options_1_)); | 1242 EXPECT_TRUE(Register(sync_options_1_)); |
| 1274 RemoveWindowClients(); | 1243 RemoveWindowClients(); |
| 1275 EXPECT_TRUE(Unregister(callback_registration_)); | 1244 EXPECT_TRUE(Unregister(callback_registration_.get())); |
| 1276 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1245 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1277 } | 1246 } |
| 1278 | 1247 |
| 1279 } // namespace content | 1248 } // namespace content |
| OLD | NEW |