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

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: Address comments from PS12 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_status.h" 15 #include "content/browser/background_sync/background_sync_status.h"
16 #include "content/browser/background_sync/client_background_sync_registration.h"
16 #include "content/browser/browser_thread_impl.h" 17 #include "content/browser/browser_thread_impl.h"
17 #include "content/browser/service_worker/embedded_worker_test_helper.h" 18 #include "content/browser/service_worker/embedded_worker_test_helper.h"
18 #include "content/browser/service_worker/service_worker_context_core.h" 19 #include "content/browser/service_worker/service_worker_context_core.h"
19 #include "content/browser/service_worker/service_worker_context_wrapper.h" 20 #include "content/browser/service_worker/service_worker_context_wrapper.h"
20 #include "content/browser/service_worker/service_worker_storage.h" 21 #include "content/browser/service_worker/service_worker_storage.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "net/base/network_change_notifier.h" 23 #include "net/base/network_change_notifier.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace content { 26 namespace content {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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
298 } 296 }
299 297
300 void SetOnBatteryPower(bool on_battery_power) { 298 void SetOnBatteryPower(bool on_battery_power) {
301 power_monitor_source_->GeneratePowerStateEvent(on_battery_power); 299 power_monitor_source_->GeneratePowerStateEvent(on_battery_power);
302 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
303 } 301 }
304 302
305 void StatusAndRegistrationCallback( 303 void StatusAndRegistrationCallback(
306 bool* was_called, 304 bool* was_called,
307 BackgroundSyncStatus status, 305 BackgroundSyncStatus status,
308 const BackgroundSyncRegistration& registration) { 306 scoped_ptr<ClientBackgroundSyncRegistration> registration) {
309 *was_called = true; 307 *was_called = true;
310 callback_status_ = status; 308 callback_status_ = status;
311 callback_registration_ = registration; 309 callback_registration_ = registration.Pass();
312 } 310 }
313 311
314 void StatusAndRegistrationsCallback( 312 void StatusAndRegistrationsCallback(
315 bool* was_called, 313 bool* was_called,
316 BackgroundSyncStatus status, 314 BackgroundSyncStatus status,
317 const std::vector<BackgroundSyncRegistration>& registrations) { 315 scoped_ptr<ScopedVector<ClientBackgroundSyncRegistration>>
316 registrations) {
318 *was_called = true; 317 *was_called = true;
319 callback_status_ = status; 318 callback_status_ = status;
320 callback_registrations_ = registrations; 319 callback_registrations_ = registrations.Pass();
321 } 320 }
322 321
323 void StatusCallback(bool* was_called, BackgroundSyncStatus status) { 322 void StatusCallback(bool* was_called, BackgroundSyncStatus status) {
324 *was_called = true; 323 *was_called = true;
325 callback_status_ = status; 324 callback_status_ = status;
326 } 325 }
327 326
328 protected: 327 protected:
329 void CreateBackgroundSyncManager() { 328 void CreateBackgroundSyncManager() {
329 ClearRegistrations();
330
330 test_background_sync_manager_ = 331 test_background_sync_manager_ =
331 new TestBackgroundSyncManager(helper_->context_wrapper()); 332 new TestBackgroundSyncManager(helper_->context_wrapper());
332 background_sync_manager_.reset(test_background_sync_manager_); 333 background_sync_manager_.reset(test_background_sync_manager_);
333 } 334 }
334 335
335 void InitBackgroundSyncManager() { 336 void InitBackgroundSyncManager() {
336 test_background_sync_manager_->DoInit(); 337 test_background_sync_manager_->DoInit();
337 338
338 // Many tests do not expect the sync event to fire immediately after 339 // Many tests do not expect the sync event to fire immediately after
339 // register (and cleanup up the sync registrations). Tests can control when 340 // register (and cleanup up the sync registrations). Tests can control when
340 // the sync event fires by manipulating the network state as needed. 341 // the sync event fires by manipulating the network state as needed.
341 // NOTE: The setup of the network connection must happen after the 342 // NOTE: The setup of the network connection must happen after the
342 // BackgroundSyncManager has been setup. 343 // BackgroundSyncManager has been setup.
343 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE); 344 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE);
344 } 345 }
345 346
347 // Clear the registrations so that the BackgroundSyncManager can release them.
348 void ClearRegistrations() {
349 callback_registration_.reset();
350 callback_registrations_.reset();
351 }
352
346 void SetupBackgroundSyncManager() { 353 void SetupBackgroundSyncManager() {
347 CreateBackgroundSyncManager(); 354 CreateBackgroundSyncManager();
348 InitBackgroundSyncManager(); 355 InitBackgroundSyncManager();
349 } 356 }
350 357
351 void SetupCorruptBackgroundSyncManager() { 358 void SetupCorruptBackgroundSyncManager() {
352 CreateBackgroundSyncManager(); 359 CreateBackgroundSyncManager();
353 test_background_sync_manager_->set_corrupt_backend(true); 360 test_background_sync_manager_->set_corrupt_backend(true);
354 InitBackgroundSyncManager(); 361 InitBackgroundSyncManager();
355 } 362 }
356 363
357 void SetupDelayedBackgroundSyncManager() { 364 void SetupDelayedBackgroundSyncManager() {
358 CreateBackgroundSyncManager(); 365 CreateBackgroundSyncManager();
359 test_background_sync_manager_->set_delay_backend(true); 366 test_background_sync_manager_->set_delay_backend(true);
360 InitBackgroundSyncManager(); 367 InitBackgroundSyncManager();
361 } 368 }
362 369
363 void DeleteBackgroundSyncManager() { 370 void DeleteBackgroundSyncManager() {
371 ClearRegistrations();
364 background_sync_manager_.reset(); 372 background_sync_manager_.reset();
365 test_background_sync_manager_ = nullptr; 373 test_background_sync_manager_ = nullptr;
366 } 374 }
367 375
368 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { 376 bool Register(const BackgroundSyncRegistrationOptions& sync_options) {
369 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); 377 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options);
370 } 378 }
371 379
372 bool RegisterWithServiceWorkerId( 380 bool RegisterWithServiceWorkerId(
373 int64 sw_registration_id, 381 int64 sw_registration_id,
374 const BackgroundSyncRegistrationOptions& options) { 382 const BackgroundSyncRegistrationOptions& options) {
375 bool was_called = false; 383 bool was_called = false;
376 background_sync_manager_->Register( 384 background_sync_manager_->Register(
377 sw_registration_id, options, 385 sw_registration_id, options,
378 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 386 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
379 base::Unretained(this), &was_called)); 387 base::Unretained(this), &was_called));
380 base::RunLoop().RunUntilIdle(); 388 base::RunLoop().RunUntilIdle();
381 EXPECT_TRUE(was_called); 389 EXPECT_TRUE(was_called);
382 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 390 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
383 } 391 }
384 392
385 bool Unregister(const BackgroundSyncRegistration& sync_registration) { 393 bool Unregister(ClientBackgroundSyncRegistration* sync_registration) {
386 return UnregisterWithServiceWorkerId(sw_registration_id_1_, 394 return UnregisterWithServiceWorkerId(sw_registration_id_1_,
387 sync_registration); 395 sync_registration);
388 } 396 }
389 397
390 bool UnregisterWithServiceWorkerId( 398 bool UnregisterWithServiceWorkerId(
391 int64 sw_registration_id, 399 int64 sw_registration_id,
392 const BackgroundSyncRegistration& sync_registration) { 400 ClientBackgroundSyncRegistration* sync_registration) {
393 bool was_called = false; 401 bool was_called = false;
394 background_sync_manager_->Unregister( 402 sync_registration->Unregister(
395 sw_registration_id, sync_registration.options()->tag, 403 sw_registration_id,
396 sync_registration.options()->periodicity, sync_registration.id(),
397 base::Bind(&BackgroundSyncManagerTest::StatusCallback, 404 base::Bind(&BackgroundSyncManagerTest::StatusCallback,
398 base::Unretained(this), &was_called)); 405 base::Unretained(this), &was_called));
399 base::RunLoop().RunUntilIdle(); 406 base::RunLoop().RunUntilIdle();
400 EXPECT_TRUE(was_called); 407 EXPECT_TRUE(was_called);
401 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 408 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
402 } 409 }
403 410
404 bool GetRegistration(const BackgroundSyncRegistrationOptions& sync_options) { 411 bool GetRegistration(const BackgroundSyncRegistrationOptions& sync_options) {
405 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 412 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
406 sync_options); 413 sync_options);
407 } 414 }
408 415
409 bool GetRegistrationWithServiceWorkerId( 416 bool GetRegistrationWithServiceWorkerId(
410 int64 sw_registration_id, 417 int64 sw_registration_id,
411 const BackgroundSyncRegistrationOptions& sync_options) { 418 const BackgroundSyncRegistrationOptions& sync_options) {
412 bool was_called = false; 419 bool was_called = false;
413 background_sync_manager_->GetRegistration( 420 background_sync_manager_->GetRegistration(
414 sw_registration_id, sync_options.tag, sync_options.periodicity, 421 sw_registration_id, sync_options.tag, sync_options.periodicity,
415 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 422 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
416 base::Unretained(this), &was_called)); 423 base::Unretained(this), &was_called));
417 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
418 EXPECT_TRUE(was_called); 425 EXPECT_TRUE(was_called);
419 426
420 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { 427 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
421 EXPECT_STREQ(sync_options.tag.c_str(), 428 EXPECT_STREQ(sync_options.tag.c_str(),
422 callback_registration_.options()->tag.c_str()); 429 callback_registration_->options()->tag.c_str());
423 } 430 }
424 431
425 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 432 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
426 } 433 }
427 434
428 bool GetRegistrations(SyncPeriodicity periodicity) { 435 bool GetRegistrations(SyncPeriodicity periodicity) {
429 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 436 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
430 periodicity); 437 periodicity);
431 } 438 }
432 439
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 int64 sw_registration_id_1_; 514 int64 sw_registration_id_1_;
508 int64 sw_registration_id_2_; 515 int64 sw_registration_id_2_;
509 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; 516 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_;
510 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; 517 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_;
511 518
512 BackgroundSyncRegistrationOptions sync_options_1_; 519 BackgroundSyncRegistrationOptions sync_options_1_;
513 BackgroundSyncRegistrationOptions sync_options_2_; 520 BackgroundSyncRegistrationOptions sync_options_2_;
514 521
515 // Callback values. 522 // Callback values.
516 BackgroundSyncStatus callback_status_; 523 BackgroundSyncStatus callback_status_;
517 BackgroundSyncRegistration callback_registration_; 524 scoped_ptr<ClientBackgroundSyncRegistration> callback_registration_;
518 std::vector<BackgroundSyncRegistration> callback_registrations_; 525 scoped_ptr<ScopedVector<ClientBackgroundSyncRegistration>>
526 callback_registrations_;
519 ServiceWorkerStatusCode callback_sw_status_code_; 527 ServiceWorkerStatusCode callback_sw_status_code_;
520 int sync_events_called_; 528 int sync_events_called_;
521 ServiceWorkerVersion::StatusCallback sync_fired_callback_; 529 ServiceWorkerVersion::StatusCallback sync_fired_callback_;
522 }; 530 };
523 531
524 TEST_F(BackgroundSyncManagerTest, Register) { 532 TEST_F(BackgroundSyncManagerTest, Register) {
525 EXPECT_TRUE(Register(sync_options_1_)); 533 EXPECT_TRUE(Register(sync_options_1_));
526 } 534 }
527 535
528 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { 536 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
529 EXPECT_TRUE(Register(sync_options_1_)); 537 EXPECT_TRUE(Register(sync_options_1_));
530 EXPECT_STREQ(sync_options_1_.tag.c_str(), 538 EXPECT_STREQ(sync_options_1_.tag.c_str(),
531 callback_registration_.options()->tag.c_str()); 539 callback_registration_->options()->tag.c_str());
532 EXPECT_TRUE(callback_registration_.IsValid()); 540 EXPECT_TRUE(callback_registration_->IsValid());
533 } 541 }
534 542
535 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { 543 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {
536 sw_registration_1_ = nullptr; 544 sw_registration_1_ = nullptr;
537 EXPECT_FALSE(Register(sync_options_1_)); 545 EXPECT_FALSE(Register(sync_options_1_));
538 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 546 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
539 } 547 }
540 548
541 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { 549 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
542 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); 550 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
543 EXPECT_FALSE(Register(sync_options_1_)); 551 EXPECT_FALSE(Register(sync_options_1_));
544 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 552 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
545 } 553 }
546 554
547 TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) {
548 EXPECT_TRUE(Register(sync_options_1_));
549 BackgroundSyncRegistration first_registration = callback_registration_;
550 EXPECT_TRUE(Register(sync_options_1_));
551 EXPECT_TRUE(callback_registration_.Equals(first_registration));
552 EXPECT_EQ(first_registration.id(), callback_registration_.id());
553 }
554
555 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) { 555 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) {
556 EXPECT_TRUE(Register(sync_options_1_)); 556 EXPECT_TRUE(Register(sync_options_1_));
557 BackgroundSyncRegistration first_registration = callback_registration_; 557 scoped_ptr<ClientBackgroundSyncRegistration> first_registration =
558 callback_registration_.Pass();
558 559
559 sync_options_1_.min_period = 100; 560 sync_options_1_.min_period = 100;
560 EXPECT_TRUE(Register(sync_options_1_)); 561 EXPECT_TRUE(Register(sync_options_1_));
561 EXPECT_LT(first_registration.id(), callback_registration_.id()); 562 EXPECT_LT(first_registration->id(), callback_registration_->id());
562 EXPECT_FALSE(callback_registration_.Equals(first_registration)); 563 EXPECT_FALSE(callback_registration_->Equals(*first_registration));
563 } 564 }
564 565
565 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { 566 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) {
566 // Registrations with the same tags but different periodicities should not 567 // Registrations with the same tags but different periodicities should not
567 // collide. 568 // collide.
568 sync_options_1_.tag = ""; 569 sync_options_1_.tag = "";
569 sync_options_2_.tag = ""; 570 sync_options_2_.tag = "";
570 sync_options_1_.periodicity = SYNC_PERIODIC; 571 sync_options_1_.periodicity = SYNC_PERIODIC;
571 sync_options_2_.periodicity = SYNC_ONE_SHOT; 572 sync_options_2_.periodicity = SYNC_ONE_SHOT;
572 EXPECT_TRUE(Register(sync_options_1_)); 573 EXPECT_TRUE(Register(sync_options_1_));
573 EXPECT_TRUE(Register(sync_options_2_)); 574 EXPECT_TRUE(Register(sync_options_2_));
574 EXPECT_TRUE(GetRegistration(sync_options_1_)); 575 EXPECT_TRUE(GetRegistration(sync_options_1_));
575 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); 576 EXPECT_EQ(SYNC_PERIODIC, callback_registration_->options()->periodicity);
576 EXPECT_TRUE(GetRegistration(sync_options_2_)); 577 EXPECT_TRUE(GetRegistration(sync_options_2_));
577 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 578 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity);
578 } 579 }
579 580
580 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { 581 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
581 test_background_sync_manager_->set_corrupt_backend(true); 582 test_background_sync_manager_->set_corrupt_backend(true);
582 EXPECT_FALSE(Register(sync_options_1_)); 583 EXPECT_FALSE(Register(sync_options_1_));
583 test_background_sync_manager_->set_corrupt_backend(false); 584 test_background_sync_manager_->set_corrupt_backend(false);
584 EXPECT_FALSE(Register(sync_options_1_)); 585 EXPECT_FALSE(Register(sync_options_1_));
585 EXPECT_FALSE(GetRegistration(sync_options_1_)); 586 EXPECT_FALSE(GetRegistration(sync_options_1_));
586 } 587 }
587 588
(...skipping 19 matching lines...) Expand all
607 EXPECT_FALSE(Register(sync_options_2_)); 608 EXPECT_FALSE(Register(sync_options_2_));
608 // Registration should have discovered the bad backend and disabled the 609 // Registration should have discovered the bad backend and disabled the
609 // BackgroundSyncManager. 610 // BackgroundSyncManager.
610 EXPECT_FALSE(GetRegistration(sync_options_1_)); 611 EXPECT_FALSE(GetRegistration(sync_options_1_));
611 test_background_sync_manager_->set_corrupt_backend(false); 612 test_background_sync_manager_->set_corrupt_backend(false);
612 EXPECT_FALSE(GetRegistration(sync_options_1_)); 613 EXPECT_FALSE(GetRegistration(sync_options_1_));
613 } 614 }
614 615
615 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { 616 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) {
616 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 617 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
617 EXPECT_EQ(0u, callback_registrations_.size()); 618 EXPECT_EQ(0u, callback_registrations_->size());
618 } 619 }
619 620
620 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { 621 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {
621 EXPECT_TRUE(Register(sync_options_1_)); 622 EXPECT_TRUE(Register(sync_options_1_));
622 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 623 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
623 624
624 EXPECT_EQ(1u, callback_registrations_.size()); 625 EXPECT_EQ(1u, callback_registrations_->size());
625 sync_options_1_.Equals(*callback_registrations_[0].options()); 626 sync_options_1_.Equals(*(*callback_registrations_)[0]->options());
626 } 627 }
627 628
628 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { 629 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
629 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); 630 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity);
630 631
631 EXPECT_TRUE(Register(sync_options_1_)); 632 EXPECT_TRUE(Register(sync_options_1_));
632 EXPECT_TRUE(Register(sync_options_2_)); 633 EXPECT_TRUE(Register(sync_options_2_));
633 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 634 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
634 635
635 EXPECT_EQ(2u, callback_registrations_.size()); 636 EXPECT_EQ(2u, callback_registrations_->size());
636 sync_options_1_.Equals(*callback_registrations_[0].options()); 637 sync_options_1_.Equals(*(*callback_registrations_)[0]->options());
637 sync_options_2_.Equals(*callback_registrations_[1].options()); 638 sync_options_2_.Equals(*(*callback_registrations_)[1]->options());
638 } 639 }
639 640
640 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { 641 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) {
641 sync_options_1_.periodicity = SYNC_ONE_SHOT; 642 sync_options_1_.periodicity = SYNC_ONE_SHOT;
642 sync_options_2_.periodicity = SYNC_PERIODIC; 643 sync_options_2_.periodicity = SYNC_PERIODIC;
643 EXPECT_TRUE(Register(sync_options_1_)); 644 EXPECT_TRUE(Register(sync_options_1_));
644 EXPECT_TRUE(Register(sync_options_2_)); 645 EXPECT_TRUE(Register(sync_options_2_));
645 646
646 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 647 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
647 EXPECT_EQ(1u, callback_registrations_.size()); 648 EXPECT_EQ(1u, callback_registrations_->size());
648 sync_options_1_.Equals(*callback_registrations_[0].options()); 649 sync_options_1_.Equals(*(*callback_registrations_)[0]->options());
649 650
650 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); 651 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC));
651 EXPECT_EQ(1u, callback_registrations_.size()); 652 EXPECT_EQ(1u, callback_registrations_->size());
652 sync_options_2_.Equals(*callback_registrations_[0].options()); 653 sync_options_2_.Equals(*(*callback_registrations_)[0]->options());
653 } 654 }
654 655
655 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { 656 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {
656 EXPECT_TRUE(Register(sync_options_1_)); 657 EXPECT_TRUE(Register(sync_options_1_));
657 test_background_sync_manager_->set_corrupt_backend(true); 658 test_background_sync_manager_->set_corrupt_backend(true);
658 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 659 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
659 EXPECT_FALSE(Register(sync_options_2_)); 660 EXPECT_FALSE(Register(sync_options_2_));
660 // Registration should have discovered the bad backend and disabled the 661 // Registration should have discovered the bad backend and disabled the
661 // BackgroundSyncManager. 662 // BackgroundSyncManager.
662 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 663 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity));
663 test_background_sync_manager_->set_corrupt_backend(false); 664 test_background_sync_manager_->set_corrupt_backend(false);
664 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 665 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity));
665 } 666 }
666 667
667 TEST_F(BackgroundSyncManagerTest, Unregister) { 668 TEST_F(BackgroundSyncManagerTest, Unregister) {
668 EXPECT_TRUE(Register(sync_options_1_)); 669 EXPECT_TRUE(Register(sync_options_1_));
669 EXPECT_TRUE(Unregister(callback_registration_)); 670 EXPECT_TRUE(Unregister(callback_registration_.get()));
670 EXPECT_FALSE(GetRegistration(sync_options_1_)); 671 EXPECT_FALSE(GetRegistration(sync_options_1_));
671 } 672 }
672 673
673 TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) {
674 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) { 674 TEST_F(BackgroundSyncManagerTest, Reregister) {
680 EXPECT_TRUE(Register(sync_options_1_)); 675 EXPECT_TRUE(Register(sync_options_1_));
681 EXPECT_TRUE(Unregister(callback_registration_)); 676 EXPECT_TRUE(Unregister(callback_registration_.get()));
682 EXPECT_TRUE(Register(sync_options_1_)); 677 EXPECT_TRUE(Register(sync_options_1_));
683 } 678 }
684 679
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) { 680 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) {
693 EXPECT_TRUE(Register(sync_options_1_)); 681 EXPECT_TRUE(Register(sync_options_1_));
694 EXPECT_TRUE(Register(sync_options_2_)); 682 EXPECT_TRUE(Register(sync_options_2_));
695 EXPECT_TRUE(Unregister(callback_registration_)); 683 EXPECT_TRUE(Unregister(callback_registration_.get()));
696 EXPECT_TRUE(GetRegistration(sync_options_1_)); 684 EXPECT_TRUE(GetRegistration(sync_options_1_));
697 EXPECT_TRUE(Register(sync_options_2_)); 685 EXPECT_TRUE(Register(sync_options_2_));
698 } 686 }
699 687
700 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { 688 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) {
701 sync_options_1_.min_period += 1; 689 sync_options_1_.min_period += 1;
702 EXPECT_TRUE(Register(sync_options_1_)); 690 EXPECT_TRUE(Register(sync_options_1_));
703 EXPECT_TRUE(Register(sync_options_2_)); 691 EXPECT_TRUE(Register(sync_options_2_));
704 test_background_sync_manager_->set_corrupt_backend(true); 692 test_background_sync_manager_->set_corrupt_backend(true);
705 EXPECT_FALSE(Unregister(callback_registration_)); 693 EXPECT_FALSE(Unregister(callback_registration_.get()));
706 // Unregister should have discovered the bad backend and disabled the 694 // Unregister should have discovered the bad backend and disabled the
707 // BackgroundSyncManager. 695 // BackgroundSyncManager.
708 test_background_sync_manager_->set_corrupt_backend(false); 696 test_background_sync_manager_->set_corrupt_backend(false);
709 EXPECT_FALSE(GetRegistration(sync_options_1_)); 697 EXPECT_FALSE(GetRegistration(sync_options_1_));
710 EXPECT_FALSE(GetRegistration(sync_options_2_)); 698 EXPECT_FALSE(GetRegistration(sync_options_2_));
711 } 699 }
712 700
713 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { 701 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
714 EXPECT_TRUE(Register(sync_options_1_)); 702 EXPECT_TRUE(Register(sync_options_1_));
715 BackgroundSyncRegistration registered_sync = callback_registration_; 703 scoped_ptr<ClientBackgroundSyncRegistration> registered_sync =
716 BackgroundSyncRegistration::RegistrationId cur_id = 704 callback_registration_.Pass();
717 callback_registration_.id(); 705 BackgroundSyncRegistration::RegistrationId cur_id = registered_sync->id();
718 706
719 EXPECT_TRUE(GetRegistration(sync_options_1_)); 707 EXPECT_TRUE(GetRegistration(sync_options_1_));
720 EXPECT_TRUE(Register(sync_options_2_)); 708 EXPECT_TRUE(Register(sync_options_2_));
721 EXPECT_LT(cur_id, callback_registration_.id()); 709 EXPECT_LT(cur_id, callback_registration_->id());
722 cur_id = callback_registration_.id(); 710 cur_id = callback_registration_->id();
723 711
724 EXPECT_TRUE(Unregister(registered_sync)); 712 EXPECT_TRUE(Unregister(registered_sync.get()));
725 EXPECT_TRUE(Register(sync_options_1_)); 713 EXPECT_TRUE(Register(sync_options_1_));
726 EXPECT_LT(cur_id, callback_registration_.id()); 714 EXPECT_LT(cur_id, callback_registration_->id());
727 } 715 }
728 716
729 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { 717 TEST_F(BackgroundSyncManagerTest, RebootRecovery) {
730 EXPECT_TRUE(Register(sync_options_1_)); 718 EXPECT_TRUE(Register(sync_options_1_));
731 719
732 SetupBackgroundSyncManager(); 720 SetupBackgroundSyncManager();
733 721
734 EXPECT_TRUE(GetRegistration(sync_options_1_)); 722 EXPECT_TRUE(GetRegistration(sync_options_1_));
735 EXPECT_FALSE(GetRegistration(sync_options_2_)); 723 EXPECT_FALSE(GetRegistration(sync_options_2_));
736 } 724 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 756
769 EXPECT_FALSE(Register(sync_options_1_)); 757 EXPECT_FALSE(Register(sync_options_1_));
770 EXPECT_FALSE(GetRegistration(sync_options_1_)); 758 EXPECT_FALSE(GetRegistration(sync_options_1_));
771 } 759 }
772 760
773 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { 761 TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
774 // Schedule Init and all of the operations on a delayed backend. Verify that 762 // Schedule Init and all of the operations on a delayed backend. Verify that
775 // the operations complete sequentially. 763 // the operations complete sequentially.
776 SetupDelayedBackgroundSyncManager(); 764 SetupDelayedBackgroundSyncManager();
777 765
778 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId;
779
780 bool register_called = false; 766 bool register_called = false;
781 bool unregister_called = false;
782 bool get_registration_called = false; 767 bool get_registration_called = false;
783 test_background_sync_manager_->Register( 768 test_background_sync_manager_->Register(
784 sw_registration_id_1_, sync_options_1_, 769 sw_registration_id_1_, sync_options_1_,
785 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 770 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
786 base::Unretained(this), &register_called)); 771 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( 772 test_background_sync_manager_->GetRegistration(
793 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, 773 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity,
794 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 774 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
795 base::Unretained(this), &get_registration_called)); 775 base::Unretained(this), &get_registration_called));
796 776
797 base::RunLoop().RunUntilIdle(); 777 base::RunLoop().RunUntilIdle();
798 // Init should be blocked while loading from the backend. 778 // Init should be blocked while loading from the backend.
799 EXPECT_FALSE(register_called); 779 EXPECT_FALSE(register_called);
800 EXPECT_FALSE(unregister_called);
801 EXPECT_FALSE(get_registration_called); 780 EXPECT_FALSE(get_registration_called);
802 781
803 test_background_sync_manager_->Continue(); 782 test_background_sync_manager_->Continue();
804 base::RunLoop().RunUntilIdle(); 783 base::RunLoop().RunUntilIdle();
805 // Register should be blocked while storing to the backend. 784 // Register should be blocked while storing to the backend.
806 EXPECT_FALSE(register_called); 785 EXPECT_FALSE(register_called);
807 EXPECT_FALSE(unregister_called);
808 EXPECT_FALSE(get_registration_called); 786 EXPECT_FALSE(get_registration_called);
809 787
810 test_background_sync_manager_->Continue(); 788 test_background_sync_manager_->Continue();
811 base::RunLoop().RunUntilIdle(); 789 base::RunLoop().RunUntilIdle();
812 EXPECT_TRUE(register_called); 790 EXPECT_TRUE(register_called);
813 EXPECT_EQ(kExpectedInitialId, callback_registration_.id());
814 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); 791 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_);
815 // Unregister should be blocked while storing to the backend. 792 // 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); 793 EXPECT_TRUE(get_registration_called);
826 } 794 }
827 795
828 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { 796 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) {
829 EXPECT_TRUE(Register(sync_options_1_)); 797 EXPECT_TRUE(Register(sync_options_1_));
830 UnregisterServiceWorker(sw_registration_id_1_); 798 UnregisterServiceWorker(sw_registration_id_1_);
831 EXPECT_FALSE(GetRegistration(sync_options_1_)); 799 EXPECT_FALSE(GetRegistration(sync_options_1_));
832 } 800 }
833 801
834 TEST_F(BackgroundSyncManagerTest, 802 TEST_F(BackgroundSyncManagerTest,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 options.power_state = POWER_STATE_AUTO; 930 options.power_state = POWER_STATE_AUTO;
963 931
964 // Store the registration. 932 // Store the registration.
965 EXPECT_TRUE(Register(options)); 933 EXPECT_TRUE(Register(options));
966 934
967 // Simulate restarting the sync manager, forcing the next read to come from 935 // Simulate restarting the sync manager, forcing the next read to come from
968 // disk. 936 // disk.
969 SetupBackgroundSyncManager(); 937 SetupBackgroundSyncManager();
970 938
971 EXPECT_TRUE(GetRegistration(options)); 939 EXPECT_TRUE(GetRegistration(options));
972 EXPECT_TRUE(options.Equals(*callback_registration_.options())); 940 EXPECT_TRUE(options.Equals(*callback_registration_->options()));
973 } 941 }
974 942
975 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { 943 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {
976 sync_options_1_.tag = "a"; 944 sync_options_1_.tag = "a";
977 EXPECT_TRUE(Register(sync_options_1_)); 945 EXPECT_TRUE(Register(sync_options_1_));
978 EXPECT_TRUE(GetRegistration(sync_options_1_)); 946 EXPECT_TRUE(GetRegistration(sync_options_1_));
979 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_.options())); 947 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_->options()));
980 EXPECT_TRUE(Unregister(callback_registration_)); 948 EXPECT_TRUE(Unregister(callback_registration_.get()));
981 EXPECT_FALSE(GetRegistration(sync_options_1_)); 949 EXPECT_FALSE(GetRegistration(sync_options_1_));
982 } 950 }
983 951
984 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { 952 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) {
985 // Registrations with the same tags but different periodicities should not 953 // Registrations with the same tags but different periodicities should not
986 // collide. 954 // collide.
987 sync_options_1_.tag = ""; 955 sync_options_1_.tag = "";
988 sync_options_2_.tag = ""; 956 sync_options_2_.tag = "";
989 sync_options_1_.periodicity = SYNC_PERIODIC; 957 sync_options_1_.periodicity = SYNC_PERIODIC;
990 sync_options_2_.periodicity = SYNC_ONE_SHOT; 958 sync_options_2_.periodicity = SYNC_ONE_SHOT;
991 959
992 EXPECT_TRUE(Register(sync_options_1_)); 960 EXPECT_TRUE(Register(sync_options_1_));
993 EXPECT_TRUE(Register(sync_options_2_)); 961 EXPECT_TRUE(Register(sync_options_2_));
994 962
995 EXPECT_TRUE(GetRegistration(sync_options_1_)); 963 EXPECT_TRUE(GetRegistration(sync_options_1_));
996 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); 964 EXPECT_EQ(SYNC_PERIODIC, callback_registration_->options()->periodicity);
997 EXPECT_TRUE(GetRegistration(sync_options_2_)); 965 EXPECT_TRUE(GetRegistration(sync_options_2_));
998 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 966 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity);
999 967
1000 EXPECT_TRUE(GetRegistration(sync_options_1_)); 968 EXPECT_TRUE(GetRegistration(sync_options_1_));
1001 EXPECT_TRUE(Unregister(callback_registration_)); 969 EXPECT_TRUE(Unregister(callback_registration_.get()));
1002 EXPECT_FALSE(GetRegistration(sync_options_1_)); 970 EXPECT_FALSE(GetRegistration(sync_options_1_));
1003 EXPECT_TRUE(GetRegistration(sync_options_2_)); 971 EXPECT_TRUE(GetRegistration(sync_options_2_));
1004 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 972 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_->options()->periodicity);
1005 973
1006 EXPECT_TRUE(Unregister(callback_registration_)); 974 EXPECT_TRUE(Unregister(callback_registration_.get()));
1007 EXPECT_FALSE(GetRegistration(sync_options_2_)); 975 EXPECT_FALSE(GetRegistration(sync_options_2_));
1008 } 976 }
1009 977
1010 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { 978 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) {
1011 InitSyncEventTest(); 979 InitSyncEventTest();
1012 980
1013 EXPECT_TRUE(Register(sync_options_1_)); 981 EXPECT_TRUE(Register(sync_options_1_));
1014 EXPECT_EQ(1, sync_events_called_); 982 EXPECT_EQ(1, sync_events_called_);
1015 EXPECT_FALSE(GetRegistration(sync_options_1_)); 983 EXPECT_FALSE(GetRegistration(sync_options_1_));
1016 } 984 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1087 EXPECT_TRUE(GetRegistration(sync_options_1_));
1120 } 1088 }
1121 1089
1122 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { 1090 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) {
1123 InitFailedSyncEventTest(); 1091 InitFailedSyncEventTest();
1124 1092
1125 // The initial sync event fails. 1093 // The initial sync event fails.
1126 EXPECT_TRUE(Register(sync_options_1_)); 1094 EXPECT_TRUE(Register(sync_options_1_));
1127 EXPECT_EQ(1, sync_events_called_); 1095 EXPECT_EQ(1, sync_events_called_);
1128 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1096 EXPECT_TRUE(GetRegistration(sync_options_1_));
1129 BackgroundSyncRegistration first_registration = callback_registration_;
1130 1097
1131 InitSyncEventTest(); 1098 InitSyncEventTest();
1132 1099
1133 // Reregistering should cause the sync event to fire again, this time 1100 // Reregistering should cause the sync event to fire again, this time
1134 // succeeding. 1101 // succeeding.
1135 EXPECT_TRUE(Register(sync_options_1_)); 1102 EXPECT_TRUE(Register(sync_options_1_));
1136 EXPECT_EQ(first_registration.id(), callback_registration_.id());
1137 EXPECT_EQ(2, sync_events_called_); 1103 EXPECT_EQ(2, sync_events_called_);
1138 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1104 EXPECT_FALSE(GetRegistration(sync_options_1_));
1139 } 1105 }
1140 1106
1141 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { 1107 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) {
1142 InitDelayedSyncEventTest(); 1108 InitDelayedSyncEventTest();
1143 1109
1144 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1110 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1145 1111
1146 // Finish firing the event and verify that the registration is removed. 1112 // 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(); 1166 base::RunLoop().RunUntilIdle();
1201 EXPECT_EQ(1, sync_events_called_); 1167 EXPECT_EQ(1, sync_events_called_);
1202 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1168 EXPECT_FALSE(GetRegistration(sync_options_1_));
1203 } 1169 }
1204 1170
1205 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { 1171 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) {
1206 InitDelayedSyncEventTest(); 1172 InitDelayedSyncEventTest();
1207 1173
1208 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1174 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1209 1175
1210 EXPECT_TRUE(Unregister(callback_registration_)); 1176 EXPECT_TRUE(Unregister(callback_registration_.get()));
1211 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1177 EXPECT_FALSE(GetRegistration(sync_options_1_));
1212 1178
1213 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1179 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1214 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1180 EXPECT_FALSE(GetRegistration(sync_options_1_));
1215 } 1181 }
1216 1182
1217 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { 1183 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) {
1218 InitDelayedSyncEventTest(); 1184 InitDelayedSyncEventTest();
1219 1185
1220 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1186 RegisterAndVerifySyncEventDelayed(sync_options_1_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 1231
1266 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { 1232 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) {
1267 EXPECT_TRUE(Register(sync_options_1_)); 1233 EXPECT_TRUE(Register(sync_options_1_));
1268 RemoveWindowClients(); 1234 RemoveWindowClients();
1269 EXPECT_FALSE(Register(sync_options_1_)); 1235 EXPECT_FALSE(Register(sync_options_1_));
1270 } 1236 }
1271 1237
1272 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { 1238 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) {
1273 EXPECT_TRUE(Register(sync_options_1_)); 1239 EXPECT_TRUE(Register(sync_options_1_));
1274 RemoveWindowClients(); 1240 RemoveWindowClients();
1275 EXPECT_TRUE(Unregister(callback_registration_)); 1241 EXPECT_TRUE(Unregister(callback_registration_.get()));
1276 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1242 EXPECT_FALSE(GetRegistration(sync_options_1_));
1277 } 1243 }
1278 1244
1279 } // namespace content 1245 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698