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

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

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments from PS17 Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/background_sync/background_sync_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include "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
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
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 BackgroundSyncRegistrationHandle::HandleId handle_id,
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
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_handle) {
309 *was_called = true; 307 *was_called = true;
310 callback_status_ = status; 308 callback_status_ = status;
311 callback_registration_ = registration; 309 callback_registration_handle_ = registration_handle.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 registration_handles) {
318 *was_called = true; 317 *was_called = true;
319 callback_status_ = status; 318 callback_status_ = status;
320 callback_registrations_ = registrations; 319 callback_registration_handles_ = registration_handles.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 ClearRegistrationHandles();
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 ClearRegistrationHandles() {
349 callback_registration_handle_.reset();
350 callback_registration_handles_.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 ClearRegistrationHandles();
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* registration_handle) {
386 return UnregisterWithServiceWorkerId(sw_registration_id_1_, 394 return UnregisterWithServiceWorkerId(sw_registration_id_1_,
387 sync_registration); 395 registration_handle);
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* registration_handle) {
393 bool was_called = false; 401 bool was_called = false;
394 background_sync_manager_->Unregister( 402 registration_handle->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(
412 const BackgroundSyncRegistrationOptions& registration_options) {
405 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 413 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
406 sync_options); 414 registration_options);
407 } 415 }
408 416
409 bool GetRegistrationWithServiceWorkerId( 417 bool GetRegistrationWithServiceWorkerId(
410 int64 sw_registration_id, 418 int64 sw_registration_id,
411 const BackgroundSyncRegistrationOptions& sync_options) { 419 const BackgroundSyncRegistrationOptions& registration_options) {
412 bool was_called = false; 420 bool was_called = false;
413 background_sync_manager_->GetRegistration( 421 background_sync_manager_->GetRegistration(
414 sw_registration_id, sync_options.tag, sync_options.periodicity, 422 sw_registration_id, registration_options.tag,
423 registration_options.periodicity,
415 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 424 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
416 base::Unretained(this), &was_called)); 425 base::Unretained(this), &was_called));
417 base::RunLoop().RunUntilIdle(); 426 base::RunLoop().RunUntilIdle();
418 EXPECT_TRUE(was_called); 427 EXPECT_TRUE(was_called);
419 428
420 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { 429 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
421 EXPECT_STREQ(sync_options.tag.c_str(), 430 EXPECT_STREQ(registration_options.tag.c_str(),
422 callback_registration_.options()->tag.c_str()); 431 callback_registration_handle_->options()->tag.c_str());
423 } 432 }
424 433
425 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 434 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
426 } 435 }
427 436
428 bool GetRegistrations(SyncPeriodicity periodicity) { 437 bool GetRegistrations(SyncPeriodicity periodicity) {
429 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 438 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
430 periodicity); 439 periodicity);
431 } 440 }
432 441
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 int64 sw_registration_id_1_; 516 int64 sw_registration_id_1_;
508 int64 sw_registration_id_2_; 517 int64 sw_registration_id_2_;
509 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; 518 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_;
510 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; 519 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_;
511 520
512 BackgroundSyncRegistrationOptions sync_options_1_; 521 BackgroundSyncRegistrationOptions sync_options_1_;
513 BackgroundSyncRegistrationOptions sync_options_2_; 522 BackgroundSyncRegistrationOptions sync_options_2_;
514 523
515 // Callback values. 524 // Callback values.
516 BackgroundSyncStatus callback_status_; 525 BackgroundSyncStatus callback_status_;
517 BackgroundSyncRegistration callback_registration_; 526 scoped_ptr<BackgroundSyncRegistrationHandle> callback_registration_handle_;
518 std::vector<BackgroundSyncRegistration> callback_registrations_; 527 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>
528 callback_registration_handles_;
519 ServiceWorkerStatusCode callback_sw_status_code_; 529 ServiceWorkerStatusCode callback_sw_status_code_;
520 int sync_events_called_; 530 int sync_events_called_;
521 ServiceWorkerVersion::StatusCallback sync_fired_callback_; 531 ServiceWorkerVersion::StatusCallback sync_fired_callback_;
522 }; 532 };
523 533
524 TEST_F(BackgroundSyncManagerTest, Register) { 534 TEST_F(BackgroundSyncManagerTest, Register) {
525 EXPECT_TRUE(Register(sync_options_1_)); 535 EXPECT_TRUE(Register(sync_options_1_));
526 } 536 }
527 537
528 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { 538 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
529 EXPECT_TRUE(Register(sync_options_1_)); 539 EXPECT_TRUE(Register(sync_options_1_));
530 EXPECT_STREQ(sync_options_1_.tag.c_str(), 540 EXPECT_STREQ(sync_options_1_.tag.c_str(),
531 callback_registration_.options()->tag.c_str()); 541 callback_registration_handle_->options()->tag.c_str());
532 EXPECT_TRUE(callback_registration_.IsValid()); 542 EXPECT_TRUE(callback_registration_handle_->IsValid());
533 } 543 }
534 544
535 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { 545 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {
536 sw_registration_1_ = nullptr; 546 sw_registration_1_ = nullptr;
537 EXPECT_FALSE(Register(sync_options_1_)); 547 EXPECT_FALSE(Register(sync_options_1_));
538 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 548 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
539 } 549 }
540 550
541 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { 551 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
542 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); 552 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
543 EXPECT_FALSE(Register(sync_options_1_)); 553 EXPECT_FALSE(Register(sync_options_1_));
544 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 554 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
545 } 555 }
546 556
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) { 557 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) {
556 EXPECT_TRUE(Register(sync_options_1_)); 558 EXPECT_TRUE(Register(sync_options_1_));
557 BackgroundSyncRegistration first_registration = callback_registration_; 559 scoped_ptr<BackgroundSyncRegistrationHandle> first_registration_handle =
560 callback_registration_handle_.Pass();
558 561
559 sync_options_1_.min_period = 100; 562 sync_options_1_.min_period = 100;
560 EXPECT_TRUE(Register(sync_options_1_)); 563 EXPECT_TRUE(Register(sync_options_1_));
561 EXPECT_LT(first_registration.id(), callback_registration_.id()); 564 EXPECT_LT(first_registration_handle->handle_id(),
562 EXPECT_FALSE(callback_registration_.Equals(first_registration)); 565 callback_registration_handle_->handle_id());
566 EXPECT_FALSE(first_registration_handle->options()->Equals(
567 *callback_registration_handle_->options()));
563 } 568 }
564 569
565 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { 570 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) {
566 // Registrations with the same tags but different periodicities should not 571 // Registrations with the same tags but different periodicities should not
567 // collide. 572 // collide.
568 sync_options_1_.tag = ""; 573 sync_options_1_.tag = "";
569 sync_options_2_.tag = ""; 574 sync_options_2_.tag = "";
570 sync_options_1_.periodicity = SYNC_PERIODIC; 575 sync_options_1_.periodicity = SYNC_PERIODIC;
571 sync_options_2_.periodicity = SYNC_ONE_SHOT; 576 sync_options_2_.periodicity = SYNC_ONE_SHOT;
572 EXPECT_TRUE(Register(sync_options_1_)); 577 EXPECT_TRUE(Register(sync_options_1_));
573 EXPECT_TRUE(Register(sync_options_2_)); 578 EXPECT_TRUE(Register(sync_options_2_));
574 EXPECT_TRUE(GetRegistration(sync_options_1_)); 579 EXPECT_TRUE(GetRegistration(sync_options_1_));
575 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); 580 EXPECT_EQ(SYNC_PERIODIC,
581 callback_registration_handle_->options()->periodicity);
576 EXPECT_TRUE(GetRegistration(sync_options_2_)); 582 EXPECT_TRUE(GetRegistration(sync_options_2_));
577 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 583 EXPECT_EQ(SYNC_ONE_SHOT,
584 callback_registration_handle_->options()->periodicity);
578 } 585 }
579 586
580 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { 587 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
581 test_background_sync_manager_->set_corrupt_backend(true); 588 test_background_sync_manager_->set_corrupt_backend(true);
582 EXPECT_FALSE(Register(sync_options_1_)); 589 EXPECT_FALSE(Register(sync_options_1_));
583 test_background_sync_manager_->set_corrupt_backend(false); 590 test_background_sync_manager_->set_corrupt_backend(false);
584 EXPECT_FALSE(Register(sync_options_1_)); 591 EXPECT_FALSE(Register(sync_options_1_));
585 EXPECT_FALSE(GetRegistration(sync_options_1_)); 592 EXPECT_FALSE(GetRegistration(sync_options_1_));
586 } 593 }
587 594
595 TEST_F(BackgroundSyncManagerTest, DuplicateRegistrationHandle) {
596 EXPECT_TRUE(Register(sync_options_1_));
597 EXPECT_TRUE(
598 sync_options_1_.Equals(*callback_registration_handle_->options()));
599
600 scoped_ptr<BackgroundSyncRegistrationHandle> dup_handle =
601 background_sync_manager_->DuplicateRegistrationHandle(
602 sw_registration_id_1_, callback_registration_handle_->handle_id());
603
604 EXPECT_TRUE(sync_options_1_.Equals(*dup_handle->options()));
605 EXPECT_NE(callback_registration_handle_->handle_id(),
606 dup_handle->handle_id());
607 }
608
588 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { 609 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {
589 EXPECT_TRUE(Register(sync_options_1_)); 610 EXPECT_TRUE(Register(sync_options_1_));
590 EXPECT_TRUE(Register(sync_options_2_)); 611 EXPECT_TRUE(Register(sync_options_2_));
591 } 612 }
592 613
593 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { 614 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) {
594 EXPECT_FALSE(GetRegistration(sync_options_1_)); 615 EXPECT_FALSE(GetRegistration(sync_options_1_));
595 } 616 }
596 617
597 TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) { 618 TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) {
598 EXPECT_TRUE(Register(sync_options_1_)); 619 EXPECT_TRUE(Register(sync_options_1_));
599 EXPECT_TRUE(GetRegistration(sync_options_1_)); 620 EXPECT_TRUE(GetRegistration(sync_options_1_));
600 EXPECT_FALSE(GetRegistration(sync_options_2_)); 621 EXPECT_FALSE(GetRegistration(sync_options_2_));
601 } 622 }
602 623
603 TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) { 624 TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) {
604 EXPECT_TRUE(Register(sync_options_1_)); 625 EXPECT_TRUE(Register(sync_options_1_));
605 test_background_sync_manager_->set_corrupt_backend(true); 626 test_background_sync_manager_->set_corrupt_backend(true);
606 EXPECT_TRUE(GetRegistration(sync_options_1_)); 627 EXPECT_TRUE(GetRegistration(sync_options_1_));
607 EXPECT_FALSE(Register(sync_options_2_)); 628 EXPECT_FALSE(Register(sync_options_2_));
608 // Registration should have discovered the bad backend and disabled the 629 // Registration should have discovered the bad backend and disabled the
609 // BackgroundSyncManager. 630 // BackgroundSyncManager.
610 EXPECT_FALSE(GetRegistration(sync_options_1_)); 631 EXPECT_FALSE(GetRegistration(sync_options_1_));
611 test_background_sync_manager_->set_corrupt_backend(false); 632 test_background_sync_manager_->set_corrupt_backend(false);
612 EXPECT_FALSE(GetRegistration(sync_options_1_)); 633 EXPECT_FALSE(GetRegistration(sync_options_1_));
613 } 634 }
614 635
615 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { 636 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) {
616 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 637 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
617 EXPECT_EQ(0u, callback_registrations_.size()); 638 EXPECT_EQ(0u, callback_registration_handles_->size());
618 } 639 }
619 640
620 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { 641 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {
621 EXPECT_TRUE(Register(sync_options_1_)); 642 EXPECT_TRUE(Register(sync_options_1_));
622 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 643 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
623 644
624 EXPECT_EQ(1u, callback_registrations_.size()); 645 EXPECT_EQ(1u, callback_registration_handles_->size());
625 sync_options_1_.Equals(*callback_registrations_[0].options()); 646 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
626 } 647 }
627 648
628 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { 649 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
629 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); 650 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity);
630 651
631 EXPECT_TRUE(Register(sync_options_1_)); 652 EXPECT_TRUE(Register(sync_options_1_));
632 EXPECT_TRUE(Register(sync_options_2_)); 653 EXPECT_TRUE(Register(sync_options_2_));
633 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 654 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
634 655
635 EXPECT_EQ(2u, callback_registrations_.size()); 656 EXPECT_EQ(2u, callback_registration_handles_->size());
636 sync_options_1_.Equals(*callback_registrations_[0].options()); 657 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
637 sync_options_2_.Equals(*callback_registrations_[1].options()); 658 sync_options_2_.Equals(*(*callback_registration_handles_)[1]->options());
638 } 659 }
639 660
640 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { 661 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) {
641 sync_options_1_.periodicity = SYNC_ONE_SHOT; 662 sync_options_1_.periodicity = SYNC_ONE_SHOT;
642 sync_options_2_.periodicity = SYNC_PERIODIC; 663 sync_options_2_.periodicity = SYNC_PERIODIC;
643 EXPECT_TRUE(Register(sync_options_1_)); 664 EXPECT_TRUE(Register(sync_options_1_));
644 EXPECT_TRUE(Register(sync_options_2_)); 665 EXPECT_TRUE(Register(sync_options_2_));
645 666
646 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 667 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
647 EXPECT_EQ(1u, callback_registrations_.size()); 668 EXPECT_EQ(1u, callback_registration_handles_->size());
648 sync_options_1_.Equals(*callback_registrations_[0].options()); 669 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
649 670
650 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); 671 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC));
651 EXPECT_EQ(1u, callback_registrations_.size()); 672 EXPECT_EQ(1u, callback_registration_handles_->size());
652 sync_options_2_.Equals(*callback_registrations_[0].options()); 673 sync_options_2_.Equals(*(*callback_registration_handles_)[0]->options());
653 } 674 }
654 675
655 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { 676 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {
656 EXPECT_TRUE(Register(sync_options_1_)); 677 EXPECT_TRUE(Register(sync_options_1_));
657 test_background_sync_manager_->set_corrupt_backend(true); 678 test_background_sync_manager_->set_corrupt_backend(true);
658 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 679 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
659 EXPECT_FALSE(Register(sync_options_2_)); 680 EXPECT_FALSE(Register(sync_options_2_));
660 // Registration should have discovered the bad backend and disabled the 681 // Registration should have discovered the bad backend and disabled the
661 // BackgroundSyncManager. 682 // BackgroundSyncManager.
662 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 683 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity));
663 test_background_sync_manager_->set_corrupt_backend(false); 684 test_background_sync_manager_->set_corrupt_backend(false);
664 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 685 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity));
665 } 686 }
666 687
667 TEST_F(BackgroundSyncManagerTest, Unregister) { 688 TEST_F(BackgroundSyncManagerTest, Unregister) {
668 EXPECT_TRUE(Register(sync_options_1_)); 689 EXPECT_TRUE(Register(sync_options_1_));
669 EXPECT_TRUE(Unregister(callback_registration_)); 690 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
670 EXPECT_FALSE(GetRegistration(sync_options_1_)); 691 EXPECT_FALSE(GetRegistration(sync_options_1_));
671 } 692 }
672 693
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) { 694 TEST_F(BackgroundSyncManagerTest, Reregister) {
680 EXPECT_TRUE(Register(sync_options_1_)); 695 EXPECT_TRUE(Register(sync_options_1_));
681 EXPECT_TRUE(Unregister(callback_registration_)); 696 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
682 EXPECT_TRUE(Register(sync_options_1_)); 697 EXPECT_TRUE(Register(sync_options_1_));
683 } 698 }
684 699
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) { 700 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) {
693 EXPECT_TRUE(Register(sync_options_1_)); 701 EXPECT_TRUE(Register(sync_options_1_));
694 EXPECT_TRUE(Register(sync_options_2_)); 702 EXPECT_TRUE(Register(sync_options_2_));
695 EXPECT_TRUE(Unregister(callback_registration_)); 703 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
696 EXPECT_TRUE(GetRegistration(sync_options_1_)); 704 EXPECT_TRUE(GetRegistration(sync_options_1_));
697 EXPECT_TRUE(Register(sync_options_2_)); 705 EXPECT_TRUE(Register(sync_options_2_));
698 } 706 }
699 707
700 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { 708 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) {
701 sync_options_1_.min_period += 1; 709 sync_options_1_.min_period += 1;
702 EXPECT_TRUE(Register(sync_options_1_)); 710 EXPECT_TRUE(Register(sync_options_1_));
703 EXPECT_TRUE(Register(sync_options_2_)); 711 EXPECT_TRUE(Register(sync_options_2_));
704 test_background_sync_manager_->set_corrupt_backend(true); 712 test_background_sync_manager_->set_corrupt_backend(true);
705 EXPECT_FALSE(Unregister(callback_registration_)); 713 EXPECT_FALSE(Unregister(callback_registration_handle_.get()));
706 // Unregister should have discovered the bad backend and disabled the 714 // Unregister should have discovered the bad backend and disabled the
707 // BackgroundSyncManager. 715 // BackgroundSyncManager.
708 test_background_sync_manager_->set_corrupt_backend(false); 716 test_background_sync_manager_->set_corrupt_backend(false);
709 EXPECT_FALSE(GetRegistration(sync_options_1_)); 717 EXPECT_FALSE(GetRegistration(sync_options_1_));
710 EXPECT_FALSE(GetRegistration(sync_options_2_)); 718 EXPECT_FALSE(GetRegistration(sync_options_2_));
711 } 719 }
712 720
713 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { 721 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
714 EXPECT_TRUE(Register(sync_options_1_)); 722 EXPECT_TRUE(Register(sync_options_1_));
715 BackgroundSyncRegistration registered_sync = callback_registration_; 723 scoped_ptr<BackgroundSyncRegistrationHandle> registered_handle =
724 callback_registration_handle_.Pass();
716 BackgroundSyncRegistration::RegistrationId cur_id = 725 BackgroundSyncRegistration::RegistrationId cur_id =
717 callback_registration_.id(); 726 registered_handle->handle_id();
718 727
719 EXPECT_TRUE(GetRegistration(sync_options_1_)); 728 EXPECT_TRUE(GetRegistration(sync_options_1_));
720 EXPECT_TRUE(Register(sync_options_2_)); 729 EXPECT_TRUE(Register(sync_options_2_));
721 EXPECT_LT(cur_id, callback_registration_.id()); 730 EXPECT_LT(cur_id, callback_registration_handle_->handle_id());
722 cur_id = callback_registration_.id(); 731 cur_id = callback_registration_handle_->handle_id();
723 732
724 EXPECT_TRUE(Unregister(registered_sync)); 733 EXPECT_TRUE(Unregister(registered_handle.get()));
725 EXPECT_TRUE(Register(sync_options_1_)); 734 EXPECT_TRUE(Register(sync_options_1_));
726 EXPECT_LT(cur_id, callback_registration_.id()); 735 EXPECT_LT(cur_id, callback_registration_handle_->handle_id());
727 } 736 }
728 737
729 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { 738 TEST_F(BackgroundSyncManagerTest, RebootRecovery) {
730 EXPECT_TRUE(Register(sync_options_1_)); 739 EXPECT_TRUE(Register(sync_options_1_));
731 740
732 SetupBackgroundSyncManager(); 741 SetupBackgroundSyncManager();
733 742
734 EXPECT_TRUE(GetRegistration(sync_options_1_)); 743 EXPECT_TRUE(GetRegistration(sync_options_1_));
735 EXPECT_FALSE(GetRegistration(sync_options_2_)); 744 EXPECT_FALSE(GetRegistration(sync_options_2_));
736 } 745 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 777
769 EXPECT_FALSE(Register(sync_options_1_)); 778 EXPECT_FALSE(Register(sync_options_1_));
770 EXPECT_FALSE(GetRegistration(sync_options_1_)); 779 EXPECT_FALSE(GetRegistration(sync_options_1_));
771 } 780 }
772 781
773 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { 782 TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
774 // Schedule Init and all of the operations on a delayed backend. Verify that 783 // Schedule Init and all of the operations on a delayed backend. Verify that
775 // the operations complete sequentially. 784 // the operations complete sequentially.
776 SetupDelayedBackgroundSyncManager(); 785 SetupDelayedBackgroundSyncManager();
777 786
778 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId;
779
780 bool register_called = false; 787 bool register_called = false;
781 bool unregister_called = false;
782 bool get_registration_called = false; 788 bool get_registration_called = false;
783 test_background_sync_manager_->Register( 789 test_background_sync_manager_->Register(
784 sw_registration_id_1_, sync_options_1_, 790 sw_registration_id_1_, sync_options_1_,
785 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 791 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
786 base::Unretained(this), &register_called)); 792 base::Unretained(this), &register_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( 793 test_background_sync_manager_->GetRegistration(
793 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, 794 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity,
794 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 795 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
795 base::Unretained(this), &get_registration_called)); 796 base::Unretained(this), &get_registration_called));
796 797
797 base::RunLoop().RunUntilIdle(); 798 base::RunLoop().RunUntilIdle();
798 // Init should be blocked while loading from the backend. 799 // Init should be blocked while loading from the backend.
799 EXPECT_FALSE(register_called); 800 EXPECT_FALSE(register_called);
800 EXPECT_FALSE(unregister_called);
801 EXPECT_FALSE(get_registration_called); 801 EXPECT_FALSE(get_registration_called);
802 802
803 test_background_sync_manager_->Continue(); 803 test_background_sync_manager_->Continue();
804 base::RunLoop().RunUntilIdle(); 804 base::RunLoop().RunUntilIdle();
805 // Register should be blocked while storing to the backend. 805 // Register should be blocked while storing to the backend.
806 EXPECT_FALSE(register_called); 806 EXPECT_FALSE(register_called);
807 EXPECT_FALSE(unregister_called);
808 EXPECT_FALSE(get_registration_called); 807 EXPECT_FALSE(get_registration_called);
809 808
810 test_background_sync_manager_->Continue(); 809 test_background_sync_manager_->Continue();
811 base::RunLoop().RunUntilIdle(); 810 base::RunLoop().RunUntilIdle();
812 EXPECT_TRUE(register_called); 811 EXPECT_TRUE(register_called);
813 EXPECT_EQ(kExpectedInitialId, callback_registration_.id());
814 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); 812 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_);
815 // Unregister should be blocked while storing to the backend. 813 // 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); 814 EXPECT_TRUE(get_registration_called);
826 } 815 }
827 816
828 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { 817 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) {
829 EXPECT_TRUE(Register(sync_options_1_)); 818 EXPECT_TRUE(Register(sync_options_1_));
830 UnregisterServiceWorker(sw_registration_id_1_); 819 UnregisterServiceWorker(sw_registration_id_1_);
831 EXPECT_FALSE(GetRegistration(sync_options_1_)); 820 EXPECT_FALSE(GetRegistration(sync_options_1_));
832 } 821 }
833 822
834 TEST_F(BackgroundSyncManagerTest, 823 TEST_F(BackgroundSyncManagerTest,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 options.power_state = POWER_STATE_AUTO; 951 options.power_state = POWER_STATE_AUTO;
963 952
964 // Store the registration. 953 // Store the registration.
965 EXPECT_TRUE(Register(options)); 954 EXPECT_TRUE(Register(options));
966 955
967 // Simulate restarting the sync manager, forcing the next read to come from 956 // Simulate restarting the sync manager, forcing the next read to come from
968 // disk. 957 // disk.
969 SetupBackgroundSyncManager(); 958 SetupBackgroundSyncManager();
970 959
971 EXPECT_TRUE(GetRegistration(options)); 960 EXPECT_TRUE(GetRegistration(options));
972 EXPECT_TRUE(options.Equals(*callback_registration_.options())); 961 EXPECT_TRUE(options.Equals(*callback_registration_handle_->options()));
973 } 962 }
974 963
975 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { 964 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {
976 sync_options_1_.tag = "a"; 965 sync_options_1_.tag = "a";
977 EXPECT_TRUE(Register(sync_options_1_)); 966 EXPECT_TRUE(Register(sync_options_1_));
978 EXPECT_TRUE(GetRegistration(sync_options_1_)); 967 EXPECT_TRUE(GetRegistration(sync_options_1_));
979 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_.options())); 968 EXPECT_TRUE(
980 EXPECT_TRUE(Unregister(callback_registration_)); 969 sync_options_1_.Equals(*callback_registration_handle_->options()));
970 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
981 EXPECT_FALSE(GetRegistration(sync_options_1_)); 971 EXPECT_FALSE(GetRegistration(sync_options_1_));
982 } 972 }
983 973
984 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { 974 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) {
985 // Registrations with the same tags but different periodicities should not 975 // Registrations with the same tags but different periodicities should not
986 // collide. 976 // collide.
987 sync_options_1_.tag = ""; 977 sync_options_1_.tag = "";
988 sync_options_2_.tag = ""; 978 sync_options_2_.tag = "";
989 sync_options_1_.periodicity = SYNC_PERIODIC; 979 sync_options_1_.periodicity = SYNC_PERIODIC;
990 sync_options_2_.periodicity = SYNC_ONE_SHOT; 980 sync_options_2_.periodicity = SYNC_ONE_SHOT;
991 981
992 EXPECT_TRUE(Register(sync_options_1_)); 982 EXPECT_TRUE(Register(sync_options_1_));
993 EXPECT_TRUE(Register(sync_options_2_)); 983 EXPECT_TRUE(Register(sync_options_2_));
994 984
995 EXPECT_TRUE(GetRegistration(sync_options_1_)); 985 EXPECT_TRUE(GetRegistration(sync_options_1_));
996 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); 986 EXPECT_EQ(SYNC_PERIODIC,
987 callback_registration_handle_->options()->periodicity);
997 EXPECT_TRUE(GetRegistration(sync_options_2_)); 988 EXPECT_TRUE(GetRegistration(sync_options_2_));
998 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 989 EXPECT_EQ(SYNC_ONE_SHOT,
990 callback_registration_handle_->options()->periodicity);
999 991
1000 EXPECT_TRUE(GetRegistration(sync_options_1_)); 992 EXPECT_TRUE(GetRegistration(sync_options_1_));
1001 EXPECT_TRUE(Unregister(callback_registration_)); 993 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1002 EXPECT_FALSE(GetRegistration(sync_options_1_)); 994 EXPECT_FALSE(GetRegistration(sync_options_1_));
1003 EXPECT_TRUE(GetRegistration(sync_options_2_)); 995 EXPECT_TRUE(GetRegistration(sync_options_2_));
1004 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 996 EXPECT_EQ(SYNC_ONE_SHOT,
997 callback_registration_handle_->options()->periodicity);
1005 998
1006 EXPECT_TRUE(Unregister(callback_registration_)); 999 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1007 EXPECT_FALSE(GetRegistration(sync_options_2_)); 1000 EXPECT_FALSE(GetRegistration(sync_options_2_));
1008 } 1001 }
1009 1002
1010 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { 1003 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) {
1011 InitSyncEventTest(); 1004 InitSyncEventTest();
1012 1005
1013 EXPECT_TRUE(Register(sync_options_1_)); 1006 EXPECT_TRUE(Register(sync_options_1_));
1014 EXPECT_EQ(1, sync_events_called_); 1007 EXPECT_EQ(1, sync_events_called_);
1015 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1008 EXPECT_FALSE(GetRegistration(sync_options_1_));
1016 } 1009 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1112 EXPECT_TRUE(GetRegistration(sync_options_1_));
1120 } 1113 }
1121 1114
1122 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { 1115 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) {
1123 InitFailedSyncEventTest(); 1116 InitFailedSyncEventTest();
1124 1117
1125 // The initial sync event fails. 1118 // The initial sync event fails.
1126 EXPECT_TRUE(Register(sync_options_1_)); 1119 EXPECT_TRUE(Register(sync_options_1_));
1127 EXPECT_EQ(1, sync_events_called_); 1120 EXPECT_EQ(1, sync_events_called_);
1128 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1121 EXPECT_TRUE(GetRegistration(sync_options_1_));
1129 BackgroundSyncRegistration first_registration = callback_registration_;
1130 1122
1131 InitSyncEventTest(); 1123 InitSyncEventTest();
1132 1124
1133 // Reregistering should cause the sync event to fire again, this time 1125 // Reregistering should cause the sync event to fire again, this time
1134 // succeeding. 1126 // succeeding.
1135 EXPECT_TRUE(Register(sync_options_1_)); 1127 EXPECT_TRUE(Register(sync_options_1_));
1136 EXPECT_EQ(first_registration.id(), callback_registration_.id());
1137 EXPECT_EQ(2, sync_events_called_); 1128 EXPECT_EQ(2, sync_events_called_);
1138 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1129 EXPECT_FALSE(GetRegistration(sync_options_1_));
1139 } 1130 }
1140 1131
1141 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { 1132 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) {
1142 InitDelayedSyncEventTest(); 1133 InitDelayedSyncEventTest();
1143 1134
1144 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1135 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1145 1136
1146 // Finish firing the event and verify that the registration is removed. 1137 // Finish firing the event and verify that the registration is removed.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 base::RunLoop().RunUntilIdle(); 1191 base::RunLoop().RunUntilIdle();
1201 EXPECT_EQ(1, sync_events_called_); 1192 EXPECT_EQ(1, sync_events_called_);
1202 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1193 EXPECT_FALSE(GetRegistration(sync_options_1_));
1203 } 1194 }
1204 1195
1205 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { 1196 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) {
1206 InitDelayedSyncEventTest(); 1197 InitDelayedSyncEventTest();
1207 1198
1208 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1199 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1209 1200
1210 EXPECT_TRUE(Unregister(callback_registration_)); 1201 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1211 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1202 EXPECT_FALSE(GetRegistration(sync_options_1_));
1212 1203
1213 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1204 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1214 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1205 EXPECT_FALSE(GetRegistration(sync_options_1_));
1215 } 1206 }
1216 1207
1217 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { 1208 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) {
1218 InitDelayedSyncEventTest(); 1209 InitDelayedSyncEventTest();
1219 1210
1220 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1211 RegisterAndVerifySyncEventDelayed(sync_options_1_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 1256
1266 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { 1257 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) {
1267 EXPECT_TRUE(Register(sync_options_1_)); 1258 EXPECT_TRUE(Register(sync_options_1_));
1268 RemoveWindowClients(); 1259 RemoveWindowClients();
1269 EXPECT_FALSE(Register(sync_options_1_)); 1260 EXPECT_FALSE(Register(sync_options_1_));
1270 } 1261 }
1271 1262
1272 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { 1263 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) {
1273 EXPECT_TRUE(Register(sync_options_1_)); 1264 EXPECT_TRUE(Register(sync_options_1_));
1274 RemoveWindowClients(); 1265 RemoveWindowClients();
1275 EXPECT_TRUE(Unregister(callback_registration_)); 1266 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1276 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1267 EXPECT_FALSE(GetRegistration(sync_options_1_));
1277 } 1268 }
1278 1269
1279 } // namespace content 1270 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698