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

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: Removed test Created 5 years, 3 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,
(...skipping 14 matching lines...) Expand all
388 bool was_called = false; 396 bool was_called = false;
389 background_sync_manager_->Register( 397 background_sync_manager_->Register(
390 sw_registration_id, options, false /* requested_from_service_worker */, 398 sw_registration_id, options, false /* requested_from_service_worker */,
391 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 399 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
392 base::Unretained(this), &was_called)); 400 base::Unretained(this), &was_called));
393 base::RunLoop().RunUntilIdle(); 401 base::RunLoop().RunUntilIdle();
394 EXPECT_TRUE(was_called); 402 EXPECT_TRUE(was_called);
395 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 403 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
396 } 404 }
397 405
398 bool Unregister(const BackgroundSyncRegistration& sync_registration) { 406 bool Unregister(BackgroundSyncRegistrationHandle* registration_handle) {
399 return UnregisterWithServiceWorkerId(sw_registration_id_1_, 407 return UnregisterWithServiceWorkerId(sw_registration_id_1_,
400 sync_registration); 408 registration_handle);
401 } 409 }
402 410
403 bool UnregisterWithServiceWorkerId( 411 bool UnregisterWithServiceWorkerId(
404 int64 sw_registration_id, 412 int64 sw_registration_id,
405 const BackgroundSyncRegistration& sync_registration) { 413 BackgroundSyncRegistrationHandle* registration_handle) {
406 bool was_called = false; 414 bool was_called = false;
407 background_sync_manager_->Unregister( 415 registration_handle->Unregister(
408 sw_registration_id, sync_registration.options()->tag, 416 sw_registration_id,
409 sync_registration.options()->periodicity, sync_registration.id(),
410 base::Bind(&BackgroundSyncManagerTest::StatusCallback, 417 base::Bind(&BackgroundSyncManagerTest::StatusCallback,
411 base::Unretained(this), &was_called)); 418 base::Unretained(this), &was_called));
412 base::RunLoop().RunUntilIdle(); 419 base::RunLoop().RunUntilIdle();
413 EXPECT_TRUE(was_called); 420 EXPECT_TRUE(was_called);
414 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 421 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
415 } 422 }
416 423
417 bool GetRegistration(const BackgroundSyncRegistrationOptions& sync_options) { 424 bool GetRegistration(
425 const BackgroundSyncRegistrationOptions& registration_options) {
418 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 426 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
419 sync_options); 427 registration_options);
420 } 428 }
421 429
422 bool GetRegistrationWithServiceWorkerId( 430 bool GetRegistrationWithServiceWorkerId(
423 int64 sw_registration_id, 431 int64 sw_registration_id,
424 const BackgroundSyncRegistrationOptions& sync_options) { 432 const BackgroundSyncRegistrationOptions& registration_options) {
425 bool was_called = false; 433 bool was_called = false;
426 background_sync_manager_->GetRegistration( 434 background_sync_manager_->GetRegistration(
427 sw_registration_id, sync_options.tag, sync_options.periodicity, 435 sw_registration_id, registration_options.tag,
436 registration_options.periodicity,
428 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 437 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
429 base::Unretained(this), &was_called)); 438 base::Unretained(this), &was_called));
430 base::RunLoop().RunUntilIdle(); 439 base::RunLoop().RunUntilIdle();
431 EXPECT_TRUE(was_called); 440 EXPECT_TRUE(was_called);
432 441
433 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { 442 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
434 EXPECT_STREQ(sync_options.tag.c_str(), 443 EXPECT_STREQ(registration_options.tag.c_str(),
435 callback_registration_.options()->tag.c_str()); 444 callback_registration_handle_->options()->tag.c_str());
436 } 445 }
437 446
438 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 447 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
439 } 448 }
440 449
441 bool GetRegistrations(SyncPeriodicity periodicity) { 450 bool GetRegistrations(SyncPeriodicity periodicity) {
442 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 451 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
443 periodicity); 452 periodicity);
444 } 453 }
445 454
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 int64 sw_registration_id_1_; 529 int64 sw_registration_id_1_;
521 int64 sw_registration_id_2_; 530 int64 sw_registration_id_2_;
522 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; 531 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_;
523 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; 532 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_;
524 533
525 BackgroundSyncRegistrationOptions sync_options_1_; 534 BackgroundSyncRegistrationOptions sync_options_1_;
526 BackgroundSyncRegistrationOptions sync_options_2_; 535 BackgroundSyncRegistrationOptions sync_options_2_;
527 536
528 // Callback values. 537 // Callback values.
529 BackgroundSyncStatus callback_status_; 538 BackgroundSyncStatus callback_status_;
530 BackgroundSyncRegistration callback_registration_; 539 scoped_ptr<BackgroundSyncRegistrationHandle> callback_registration_handle_;
531 std::vector<BackgroundSyncRegistration> callback_registrations_; 540 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>
541 callback_registration_handles_;
532 ServiceWorkerStatusCode callback_sw_status_code_; 542 ServiceWorkerStatusCode callback_sw_status_code_;
533 int sync_events_called_; 543 int sync_events_called_;
534 ServiceWorkerVersion::StatusCallback sync_fired_callback_; 544 ServiceWorkerVersion::StatusCallback sync_fired_callback_;
535 }; 545 };
536 546
537 TEST_F(BackgroundSyncManagerTest, Register) { 547 TEST_F(BackgroundSyncManagerTest, Register) {
538 EXPECT_TRUE(Register(sync_options_1_)); 548 EXPECT_TRUE(Register(sync_options_1_));
539 } 549 }
540 550
541 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { 551 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
542 EXPECT_TRUE(Register(sync_options_1_)); 552 EXPECT_TRUE(Register(sync_options_1_));
543 EXPECT_STREQ(sync_options_1_.tag.c_str(), 553 EXPECT_STREQ(sync_options_1_.tag.c_str(),
544 callback_registration_.options()->tag.c_str()); 554 callback_registration_handle_->options()->tag.c_str());
545 EXPECT_TRUE(callback_registration_.IsValid()); 555 EXPECT_TRUE(callback_registration_handle_->IsValid());
546 } 556 }
547 557
548 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { 558 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {
549 sw_registration_1_ = nullptr; 559 sw_registration_1_ = nullptr;
550 EXPECT_FALSE(Register(sync_options_1_)); 560 EXPECT_FALSE(Register(sync_options_1_));
551 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 561 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
552 } 562 }
553 563
554 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { 564 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
555 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); 565 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
556 EXPECT_FALSE(Register(sync_options_1_)); 566 EXPECT_FALSE(Register(sync_options_1_));
557 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 567 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
558 } 568 }
559 569
560 TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) {
561 EXPECT_TRUE(Register(sync_options_1_));
562 BackgroundSyncRegistration first_registration = callback_registration_;
563 EXPECT_TRUE(Register(sync_options_1_));
564 EXPECT_TRUE(callback_registration_.Equals(first_registration));
565 EXPECT_EQ(first_registration.id(), callback_registration_.id());
566 }
567
568 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) { 570 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) {
569 EXPECT_TRUE(Register(sync_options_1_)); 571 EXPECT_TRUE(Register(sync_options_1_));
570 BackgroundSyncRegistration first_registration = callback_registration_; 572 scoped_ptr<BackgroundSyncRegistrationHandle> first_registration_handle =
573 callback_registration_handle_.Pass();
571 574
572 sync_options_1_.min_period = 100; 575 sync_options_1_.min_period = 100;
573 EXPECT_TRUE(Register(sync_options_1_)); 576 EXPECT_TRUE(Register(sync_options_1_));
574 EXPECT_LT(first_registration.id(), callback_registration_.id()); 577 EXPECT_LT(first_registration_handle->handle_id(),
575 EXPECT_FALSE(callback_registration_.Equals(first_registration)); 578 callback_registration_handle_->handle_id());
579 EXPECT_FALSE(first_registration_handle->options()->Equals(
580 *callback_registration_handle_->options()));
576 } 581 }
577 582
578 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) { 583 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) {
579 // Registrations with the same tags but different periodicities should not 584 // Registrations with the same tags but different periodicities should not
580 // collide. 585 // collide.
581 sync_options_1_.tag = ""; 586 sync_options_1_.tag = "";
582 sync_options_2_.tag = ""; 587 sync_options_2_.tag = "";
583 sync_options_1_.periodicity = SYNC_PERIODIC; 588 sync_options_1_.periodicity = SYNC_PERIODIC;
584 sync_options_2_.periodicity = SYNC_ONE_SHOT; 589 sync_options_2_.periodicity = SYNC_ONE_SHOT;
585 EXPECT_TRUE(Register(sync_options_1_)); 590 EXPECT_TRUE(Register(sync_options_1_));
586 EXPECT_TRUE(Register(sync_options_2_)); 591 EXPECT_TRUE(Register(sync_options_2_));
587 EXPECT_TRUE(GetRegistration(sync_options_1_)); 592 EXPECT_TRUE(GetRegistration(sync_options_1_));
588 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); 593 EXPECT_EQ(SYNC_PERIODIC,
594 callback_registration_handle_->options()->periodicity);
589 EXPECT_TRUE(GetRegistration(sync_options_2_)); 595 EXPECT_TRUE(GetRegistration(sync_options_2_));
590 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 596 EXPECT_EQ(SYNC_ONE_SHOT,
597 callback_registration_handle_->options()->periodicity);
591 } 598 }
592 599
593 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { 600 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
594 test_background_sync_manager_->set_corrupt_backend(true); 601 test_background_sync_manager_->set_corrupt_backend(true);
595 EXPECT_FALSE(Register(sync_options_1_)); 602 EXPECT_FALSE(Register(sync_options_1_));
596 test_background_sync_manager_->set_corrupt_backend(false); 603 test_background_sync_manager_->set_corrupt_backend(false);
597 EXPECT_FALSE(Register(sync_options_1_)); 604 EXPECT_FALSE(Register(sync_options_1_));
598 EXPECT_FALSE(GetRegistration(sync_options_1_)); 605 EXPECT_FALSE(GetRegistration(sync_options_1_));
599 } 606 }
600 607
608 TEST_F(BackgroundSyncManagerTest, DuplicateRegistrationHandle) {
609 EXPECT_TRUE(Register(sync_options_1_));
610 EXPECT_TRUE(
611 sync_options_1_.Equals(*callback_registration_handle_->options()));
612
613 scoped_ptr<BackgroundSyncRegistrationHandle> dup_handle =
614 background_sync_manager_->DuplicateRegistrationHandle(
615 callback_registration_handle_->handle_id());
616
617 EXPECT_TRUE(sync_options_1_.Equals(*dup_handle->options()));
618 EXPECT_NE(callback_registration_handle_->handle_id(),
619 dup_handle->handle_id());
620 }
621
601 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { 622 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {
602 EXPECT_TRUE(Register(sync_options_1_)); 623 EXPECT_TRUE(Register(sync_options_1_));
603 EXPECT_TRUE(Register(sync_options_2_)); 624 EXPECT_TRUE(Register(sync_options_2_));
604 } 625 }
605 626
606 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { 627 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) {
607 EXPECT_FALSE(GetRegistration(sync_options_1_)); 628 EXPECT_FALSE(GetRegistration(sync_options_1_));
608 } 629 }
609 630
610 TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) { 631 TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) {
611 EXPECT_TRUE(Register(sync_options_1_)); 632 EXPECT_TRUE(Register(sync_options_1_));
612 EXPECT_TRUE(GetRegistration(sync_options_1_)); 633 EXPECT_TRUE(GetRegistration(sync_options_1_));
613 EXPECT_FALSE(GetRegistration(sync_options_2_)); 634 EXPECT_FALSE(GetRegistration(sync_options_2_));
614 } 635 }
615 636
616 TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) { 637 TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) {
617 EXPECT_TRUE(Register(sync_options_1_)); 638 EXPECT_TRUE(Register(sync_options_1_));
618 test_background_sync_manager_->set_corrupt_backend(true); 639 test_background_sync_manager_->set_corrupt_backend(true);
619 EXPECT_TRUE(GetRegistration(sync_options_1_)); 640 EXPECT_TRUE(GetRegistration(sync_options_1_));
620 EXPECT_FALSE(Register(sync_options_2_)); 641 EXPECT_FALSE(Register(sync_options_2_));
621 // Registration should have discovered the bad backend and disabled the 642 // Registration should have discovered the bad backend and disabled the
622 // BackgroundSyncManager. 643 // BackgroundSyncManager.
623 EXPECT_FALSE(GetRegistration(sync_options_1_)); 644 EXPECT_FALSE(GetRegistration(sync_options_1_));
624 test_background_sync_manager_->set_corrupt_backend(false); 645 test_background_sync_manager_->set_corrupt_backend(false);
625 EXPECT_FALSE(GetRegistration(sync_options_1_)); 646 EXPECT_FALSE(GetRegistration(sync_options_1_));
626 } 647 }
627 648
628 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { 649 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) {
629 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 650 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
630 EXPECT_EQ(0u, callback_registrations_.size()); 651 EXPECT_EQ(0u, callback_registration_handles_->size());
631 } 652 }
632 653
633 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { 654 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {
634 EXPECT_TRUE(Register(sync_options_1_)); 655 EXPECT_TRUE(Register(sync_options_1_));
635 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 656 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
636 657
637 EXPECT_EQ(1u, callback_registrations_.size()); 658 EXPECT_EQ(1u, callback_registration_handles_->size());
638 sync_options_1_.Equals(*callback_registrations_[0].options()); 659 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
639 } 660 }
640 661
641 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { 662 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
642 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity); 663 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity);
643 664
644 EXPECT_TRUE(Register(sync_options_1_)); 665 EXPECT_TRUE(Register(sync_options_1_));
645 EXPECT_TRUE(Register(sync_options_2_)); 666 EXPECT_TRUE(Register(sync_options_2_));
646 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 667 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
647 668
648 EXPECT_EQ(2u, callback_registrations_.size()); 669 EXPECT_EQ(2u, callback_registration_handles_->size());
649 sync_options_1_.Equals(*callback_registrations_[0].options()); 670 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
650 sync_options_2_.Equals(*callback_registrations_[1].options()); 671 sync_options_2_.Equals(*(*callback_registration_handles_)[1]->options());
651 } 672 }
652 673
653 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) { 674 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) {
654 sync_options_1_.periodicity = SYNC_ONE_SHOT; 675 sync_options_1_.periodicity = SYNC_ONE_SHOT;
655 sync_options_2_.periodicity = SYNC_PERIODIC; 676 sync_options_2_.periodicity = SYNC_PERIODIC;
656 EXPECT_TRUE(Register(sync_options_1_)); 677 EXPECT_TRUE(Register(sync_options_1_));
657 EXPECT_TRUE(Register(sync_options_2_)); 678 EXPECT_TRUE(Register(sync_options_2_));
658 679
659 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 680 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
660 EXPECT_EQ(1u, callback_registrations_.size()); 681 EXPECT_EQ(1u, callback_registration_handles_->size());
661 sync_options_1_.Equals(*callback_registrations_[0].options()); 682 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
662 683
663 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC)); 684 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC));
664 EXPECT_EQ(1u, callback_registrations_.size()); 685 EXPECT_EQ(1u, callback_registration_handles_->size());
665 sync_options_2_.Equals(*callback_registrations_[0].options()); 686 sync_options_2_.Equals(*(*callback_registration_handles_)[0]->options());
666 } 687 }
667 688
668 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { 689 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {
669 EXPECT_TRUE(Register(sync_options_1_)); 690 EXPECT_TRUE(Register(sync_options_1_));
670 test_background_sync_manager_->set_corrupt_backend(true); 691 test_background_sync_manager_->set_corrupt_backend(true);
671 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 692 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
672 EXPECT_FALSE(Register(sync_options_2_)); 693 EXPECT_FALSE(Register(sync_options_2_));
673 // Registration should have discovered the bad backend and disabled the 694 // Registration should have discovered the bad backend and disabled the
674 // BackgroundSyncManager. 695 // BackgroundSyncManager.
675 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 696 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity));
676 test_background_sync_manager_->set_corrupt_backend(false); 697 test_background_sync_manager_->set_corrupt_backend(false);
677 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 698 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity));
678 } 699 }
679 700
680 TEST_F(BackgroundSyncManagerTest, Unregister) { 701 TEST_F(BackgroundSyncManagerTest, Unregister) {
681 EXPECT_TRUE(Register(sync_options_1_)); 702 EXPECT_TRUE(Register(sync_options_1_));
682 EXPECT_TRUE(Unregister(callback_registration_)); 703 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
683 EXPECT_FALSE(GetRegistration(sync_options_1_)); 704 EXPECT_FALSE(GetRegistration(sync_options_1_));
684 } 705 }
685 706
686 TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) {
687 EXPECT_TRUE(Register(sync_options_1_));
688 callback_registration_.set_id(callback_registration_.id() + 1);
689 EXPECT_FALSE(Unregister(callback_registration_));
690 }
691
692 TEST_F(BackgroundSyncManagerTest, Reregister) { 707 TEST_F(BackgroundSyncManagerTest, Reregister) {
693 EXPECT_TRUE(Register(sync_options_1_)); 708 EXPECT_TRUE(Register(sync_options_1_));
694 EXPECT_TRUE(Unregister(callback_registration_)); 709 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
695 EXPECT_TRUE(Register(sync_options_1_)); 710 EXPECT_TRUE(Register(sync_options_1_));
696 } 711 }
697 712
698 TEST_F(BackgroundSyncManagerTest, UnregisterNonExisting) {
699 BackgroundSyncRegistration nonexistant_registration;
700 nonexistant_registration.set_id(1);
701 EXPECT_FALSE(Unregister(nonexistant_registration));
702 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback_status_);
703 }
704
705 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) { 713 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) {
706 EXPECT_TRUE(Register(sync_options_1_)); 714 EXPECT_TRUE(Register(sync_options_1_));
707 EXPECT_TRUE(Register(sync_options_2_)); 715 EXPECT_TRUE(Register(sync_options_2_));
708 EXPECT_TRUE(Unregister(callback_registration_)); 716 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
709 EXPECT_TRUE(GetRegistration(sync_options_1_)); 717 EXPECT_TRUE(GetRegistration(sync_options_1_));
710 EXPECT_TRUE(Register(sync_options_2_)); 718 EXPECT_TRUE(Register(sync_options_2_));
711 } 719 }
712 720
713 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { 721 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) {
714 sync_options_1_.min_period += 1; 722 sync_options_1_.min_period += 1;
715 EXPECT_TRUE(Register(sync_options_1_)); 723 EXPECT_TRUE(Register(sync_options_1_));
716 EXPECT_TRUE(Register(sync_options_2_)); 724 EXPECT_TRUE(Register(sync_options_2_));
717 test_background_sync_manager_->set_corrupt_backend(true); 725 test_background_sync_manager_->set_corrupt_backend(true);
718 EXPECT_FALSE(Unregister(callback_registration_)); 726 EXPECT_FALSE(Unregister(callback_registration_handle_.get()));
719 // Unregister should have discovered the bad backend and disabled the 727 // Unregister should have discovered the bad backend and disabled the
720 // BackgroundSyncManager. 728 // BackgroundSyncManager.
721 test_background_sync_manager_->set_corrupt_backend(false); 729 test_background_sync_manager_->set_corrupt_backend(false);
722 EXPECT_FALSE(GetRegistration(sync_options_1_)); 730 EXPECT_FALSE(GetRegistration(sync_options_1_));
723 EXPECT_FALSE(GetRegistration(sync_options_2_)); 731 EXPECT_FALSE(GetRegistration(sync_options_2_));
724 } 732 }
725 733
726 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { 734 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
727 EXPECT_TRUE(Register(sync_options_1_)); 735 EXPECT_TRUE(Register(sync_options_1_));
728 BackgroundSyncRegistration registered_sync = callback_registration_; 736 scoped_ptr<BackgroundSyncRegistrationHandle> registered_handle =
737 callback_registration_handle_.Pass();
729 BackgroundSyncRegistration::RegistrationId cur_id = 738 BackgroundSyncRegistration::RegistrationId cur_id =
730 callback_registration_.id(); 739 registered_handle->handle_id();
731 740
732 EXPECT_TRUE(GetRegistration(sync_options_1_)); 741 EXPECT_TRUE(GetRegistration(sync_options_1_));
733 EXPECT_TRUE(Register(sync_options_2_)); 742 EXPECT_TRUE(Register(sync_options_2_));
734 EXPECT_LT(cur_id, callback_registration_.id()); 743 EXPECT_LT(cur_id, callback_registration_handle_->handle_id());
735 cur_id = callback_registration_.id(); 744 cur_id = callback_registration_handle_->handle_id();
736 745
737 EXPECT_TRUE(Unregister(registered_sync)); 746 EXPECT_TRUE(Unregister(registered_handle.get()));
738 EXPECT_TRUE(Register(sync_options_1_)); 747 EXPECT_TRUE(Register(sync_options_1_));
739 EXPECT_LT(cur_id, callback_registration_.id()); 748 EXPECT_LT(cur_id, callback_registration_handle_->handle_id());
740 } 749 }
741 750
742 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { 751 TEST_F(BackgroundSyncManagerTest, RebootRecovery) {
743 EXPECT_TRUE(Register(sync_options_1_)); 752 EXPECT_TRUE(Register(sync_options_1_));
744 753
745 SetupBackgroundSyncManager(); 754 SetupBackgroundSyncManager();
746 755
747 EXPECT_TRUE(GetRegistration(sync_options_1_)); 756 EXPECT_TRUE(GetRegistration(sync_options_1_));
748 EXPECT_FALSE(GetRegistration(sync_options_2_)); 757 EXPECT_FALSE(GetRegistration(sync_options_2_));
749 } 758 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 790
782 EXPECT_FALSE(Register(sync_options_1_)); 791 EXPECT_FALSE(Register(sync_options_1_));
783 EXPECT_FALSE(GetRegistration(sync_options_1_)); 792 EXPECT_FALSE(GetRegistration(sync_options_1_));
784 } 793 }
785 794
786 TEST_F(BackgroundSyncManagerTest, SequentialOperations) { 795 TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
787 // Schedule Init and all of the operations on a delayed backend. Verify that 796 // Schedule Init and all of the operations on a delayed backend. Verify that
788 // the operations complete sequentially. 797 // the operations complete sequentially.
789 SetupDelayedBackgroundSyncManager(); 798 SetupDelayedBackgroundSyncManager();
790 799
791 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId;
792
793 bool register_called = false; 800 bool register_called = false;
794 bool unregister_called = false;
795 bool get_registration_called = false; 801 bool get_registration_called = false;
796 test_background_sync_manager_->Register( 802 test_background_sync_manager_->Register(
797 sw_registration_id_1_, sync_options_1_, 803 sw_registration_id_1_, sync_options_1_,
798 true /* requested_from_service_worker */, 804 true /* requested_from_service_worker */,
799 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 805 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
800 base::Unretained(this), &register_called)); 806 base::Unretained(this), &register_called));
801 test_background_sync_manager_->Unregister(
802 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity,
803 kExpectedInitialId,
804 base::Bind(&BackgroundSyncManagerTest::StatusCallback,
805 base::Unretained(this), &unregister_called));
806 test_background_sync_manager_->GetRegistration( 807 test_background_sync_manager_->GetRegistration(
807 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, 808 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity,
808 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 809 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
809 base::Unretained(this), &get_registration_called)); 810 base::Unretained(this), &get_registration_called));
810 811
811 base::RunLoop().RunUntilIdle(); 812 base::RunLoop().RunUntilIdle();
812 // Init should be blocked while loading from the backend. 813 // Init should be blocked while loading from the backend.
813 EXPECT_FALSE(register_called); 814 EXPECT_FALSE(register_called);
814 EXPECT_FALSE(unregister_called);
815 EXPECT_FALSE(get_registration_called); 815 EXPECT_FALSE(get_registration_called);
816 816
817 test_background_sync_manager_->Continue(); 817 test_background_sync_manager_->Continue();
818 base::RunLoop().RunUntilIdle(); 818 base::RunLoop().RunUntilIdle();
819 // Register should be blocked while storing to the backend. 819 // Register should be blocked while storing to the backend.
820 EXPECT_FALSE(register_called); 820 EXPECT_FALSE(register_called);
821 EXPECT_FALSE(unregister_called);
822 EXPECT_FALSE(get_registration_called); 821 EXPECT_FALSE(get_registration_called);
823 822
824 test_background_sync_manager_->Continue(); 823 test_background_sync_manager_->Continue();
825 base::RunLoop().RunUntilIdle(); 824 base::RunLoop().RunUntilIdle();
826 EXPECT_TRUE(register_called); 825 EXPECT_TRUE(register_called);
827 EXPECT_EQ(kExpectedInitialId, callback_registration_.id());
828 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_); 826 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_);
829 // Unregister should be blocked while storing to the backend. 827 // GetRegistration should run immediately as it doesn't write to disk.
830 EXPECT_FALSE(unregister_called);
831 EXPECT_FALSE(get_registration_called);
832
833 test_background_sync_manager_->Continue();
834 base::RunLoop().RunUntilIdle();
835 // Unregister should be done and since GetRegistration doesn't require the
836 // backend it should be done too.
837 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback_status_);
838 EXPECT_TRUE(unregister_called);
839 EXPECT_TRUE(get_registration_called); 828 EXPECT_TRUE(get_registration_called);
840 } 829 }
841 830
842 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { 831 TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) {
843 EXPECT_TRUE(Register(sync_options_1_)); 832 EXPECT_TRUE(Register(sync_options_1_));
844 UnregisterServiceWorker(sw_registration_id_1_); 833 UnregisterServiceWorker(sw_registration_id_1_);
845 EXPECT_FALSE(GetRegistration(sync_options_1_)); 834 EXPECT_FALSE(GetRegistration(sync_options_1_));
846 } 835 }
847 836
848 TEST_F(BackgroundSyncManagerTest, 837 TEST_F(BackgroundSyncManagerTest,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 options.power_state = POWER_STATE_AUTO; 966 options.power_state = POWER_STATE_AUTO;
978 967
979 // Store the registration. 968 // Store the registration.
980 EXPECT_TRUE(Register(options)); 969 EXPECT_TRUE(Register(options));
981 970
982 // Simulate restarting the sync manager, forcing the next read to come from 971 // Simulate restarting the sync manager, forcing the next read to come from
983 // disk. 972 // disk.
984 SetupBackgroundSyncManager(); 973 SetupBackgroundSyncManager();
985 974
986 EXPECT_TRUE(GetRegistration(options)); 975 EXPECT_TRUE(GetRegistration(options));
987 EXPECT_TRUE(options.Equals(*callback_registration_.options())); 976 EXPECT_TRUE(options.Equals(*callback_registration_handle_->options()));
988 } 977 }
989 978
990 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { 979 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {
991 sync_options_1_.tag = "a"; 980 sync_options_1_.tag = "a";
992 EXPECT_TRUE(Register(sync_options_1_)); 981 EXPECT_TRUE(Register(sync_options_1_));
993 EXPECT_TRUE(GetRegistration(sync_options_1_)); 982 EXPECT_TRUE(GetRegistration(sync_options_1_));
994 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_.options())); 983 EXPECT_TRUE(
995 EXPECT_TRUE(Unregister(callback_registration_)); 984 sync_options_1_.Equals(*callback_registration_handle_->options()));
985 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
996 EXPECT_FALSE(GetRegistration(sync_options_1_)); 986 EXPECT_FALSE(GetRegistration(sync_options_1_));
997 } 987 }
998 988
999 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) { 989 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) {
1000 // Registrations with the same tags but different periodicities should not 990 // Registrations with the same tags but different periodicities should not
1001 // collide. 991 // collide.
1002 sync_options_1_.tag = ""; 992 sync_options_1_.tag = "";
1003 sync_options_2_.tag = ""; 993 sync_options_2_.tag = "";
1004 sync_options_1_.periodicity = SYNC_PERIODIC; 994 sync_options_1_.periodicity = SYNC_PERIODIC;
1005 sync_options_2_.periodicity = SYNC_ONE_SHOT; 995 sync_options_2_.periodicity = SYNC_ONE_SHOT;
1006 996
1007 EXPECT_TRUE(Register(sync_options_1_)); 997 EXPECT_TRUE(Register(sync_options_1_));
1008 EXPECT_TRUE(Register(sync_options_2_)); 998 EXPECT_TRUE(Register(sync_options_2_));
1009 999
1010 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1000 EXPECT_TRUE(GetRegistration(sync_options_1_));
1011 EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity); 1001 EXPECT_EQ(SYNC_PERIODIC,
1002 callback_registration_handle_->options()->periodicity);
1012 EXPECT_TRUE(GetRegistration(sync_options_2_)); 1003 EXPECT_TRUE(GetRegistration(sync_options_2_));
1013 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 1004 EXPECT_EQ(SYNC_ONE_SHOT,
1005 callback_registration_handle_->options()->periodicity);
1014 1006
1015 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1007 EXPECT_TRUE(GetRegistration(sync_options_1_));
1016 EXPECT_TRUE(Unregister(callback_registration_)); 1008 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1017 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1009 EXPECT_FALSE(GetRegistration(sync_options_1_));
1018 EXPECT_TRUE(GetRegistration(sync_options_2_)); 1010 EXPECT_TRUE(GetRegistration(sync_options_2_));
1019 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity); 1011 EXPECT_EQ(SYNC_ONE_SHOT,
1012 callback_registration_handle_->options()->periodicity);
1020 1013
1021 EXPECT_TRUE(Unregister(callback_registration_)); 1014 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1022 EXPECT_FALSE(GetRegistration(sync_options_2_)); 1015 EXPECT_FALSE(GetRegistration(sync_options_2_));
1023 } 1016 }
1024 1017
1025 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { 1018 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) {
1026 InitSyncEventTest(); 1019 InitSyncEventTest();
1027 1020
1028 EXPECT_TRUE(Register(sync_options_1_)); 1021 EXPECT_TRUE(Register(sync_options_1_));
1029 EXPECT_EQ(1, sync_events_called_); 1022 EXPECT_EQ(1, sync_events_called_);
1030 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1023 EXPECT_FALSE(GetRegistration(sync_options_1_));
1031 } 1024 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1127 EXPECT_TRUE(GetRegistration(sync_options_1_));
1135 } 1128 }
1136 1129
1137 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) { 1130 TEST_F(BackgroundSyncManagerTest, FailedOneShotReregisteredAndFires) {
1138 InitFailedSyncEventTest(); 1131 InitFailedSyncEventTest();
1139 1132
1140 // The initial sync event fails. 1133 // The initial sync event fails.
1141 EXPECT_TRUE(Register(sync_options_1_)); 1134 EXPECT_TRUE(Register(sync_options_1_));
1142 EXPECT_EQ(1, sync_events_called_); 1135 EXPECT_EQ(1, sync_events_called_);
1143 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1136 EXPECT_TRUE(GetRegistration(sync_options_1_));
1144 BackgroundSyncRegistration first_registration = callback_registration_;
1145 1137
1146 InitSyncEventTest(); 1138 InitSyncEventTest();
1147 1139
1148 // Reregistering should cause the sync event to fire again, this time 1140 // Reregistering should cause the sync event to fire again, this time
1149 // succeeding. 1141 // succeeding.
1150 EXPECT_TRUE(Register(sync_options_1_)); 1142 EXPECT_TRUE(Register(sync_options_1_));
1151 EXPECT_EQ(first_registration.id(), callback_registration_.id());
1152 EXPECT_EQ(2, sync_events_called_); 1143 EXPECT_EQ(2, sync_events_called_);
1153 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1144 EXPECT_FALSE(GetRegistration(sync_options_1_));
1154 } 1145 }
1155 1146
1156 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) { 1147 TEST_F(BackgroundSyncManagerTest, DelayOneShotMidSync) {
1157 InitDelayedSyncEventTest(); 1148 InitDelayedSyncEventTest();
1158 1149
1159 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1150 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1160 1151
1161 // Finish firing the event and verify that the registration is removed. 1152 // Finish firing the event and verify that the registration is removed.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 base::RunLoop().RunUntilIdle(); 1206 base::RunLoop().RunUntilIdle();
1216 EXPECT_EQ(1, sync_events_called_); 1207 EXPECT_EQ(1, sync_events_called_);
1217 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1208 EXPECT_FALSE(GetRegistration(sync_options_1_));
1218 } 1209 }
1219 1210
1220 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) { 1211 TEST_F(BackgroundSyncManagerTest, UnregisterOneShotMidSync) {
1221 InitDelayedSyncEventTest(); 1212 InitDelayedSyncEventTest();
1222 1213
1223 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1214 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1224 1215
1225 EXPECT_TRUE(Unregister(callback_registration_)); 1216 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1226 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1217 EXPECT_FALSE(GetRegistration(sync_options_1_));
1227 1218
1228 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1219 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1229 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1220 EXPECT_FALSE(GetRegistration(sync_options_1_));
1230 } 1221 }
1231 1222
1232 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) { 1223 TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) {
1233 InitDelayedSyncEventTest(); 1224 InitDelayedSyncEventTest();
1234 1225
1235 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1226 RegisterAndVerifySyncEventDelayed(sync_options_1_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1277
1287 TEST_F(BackgroundSyncManagerTest, RegisterSucceedsFromUncontrolledWindow) { 1278 TEST_F(BackgroundSyncManagerTest, RegisterSucceedsFromUncontrolledWindow) {
1288 RemoveWindowClients(); 1279 RemoveWindowClients();
1289 EXPECT_TRUE(RegisterFromDocumentWithServiceWorkerId(sw_registration_id_1_, 1280 EXPECT_TRUE(RegisterFromDocumentWithServiceWorkerId(sw_registration_id_1_,
1290 sync_options_1_)); 1281 sync_options_1_));
1291 } 1282 }
1292 1283
1293 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { 1284 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) {
1294 EXPECT_TRUE(Register(sync_options_1_)); 1285 EXPECT_TRUE(Register(sync_options_1_));
1295 RemoveWindowClients(); 1286 RemoveWindowClients();
1296 EXPECT_TRUE(Unregister(callback_registration_)); 1287 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1297 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1288 EXPECT_FALSE(GetRegistration(sync_options_1_));
1298 } 1289 }
1299 1290
1300 } // namespace content 1291 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698