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

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

Issue 1763123002: [BackgroundSync] Remove BackgroundSyncRegistrationHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS7 Created 4 years, 9 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 <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/test/mock_entropy_provider.h" 17 #include "base/test/mock_entropy_provider.h"
18 #include "base/test/simple_test_clock.h" 18 #include "base/test/simple_test_clock.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "content/browser/background_sync/background_sync_network_observer.h" 20 #include "content/browser/background_sync/background_sync_network_observer.h"
21 #include "content/browser/background_sync/background_sync_registration_handle.h"
22 #include "content/browser/background_sync/background_sync_status.h" 21 #include "content/browser/background_sync/background_sync_status.h"
23 #include "content/browser/browser_thread_impl.h" 22 #include "content/browser/browser_thread_impl.h"
24 #include "content/browser/service_worker/embedded_worker_test_helper.h" 23 #include "content/browser/service_worker/embedded_worker_test_helper.h"
25 #include "content/browser/service_worker/service_worker_context_core.h" 24 #include "content/browser/service_worker/service_worker_context_core.h"
26 #include "content/browser/service_worker/service_worker_context_wrapper.h" 25 #include "content/browser/service_worker/service_worker_context_wrapper.h"
27 #include "content/browser/service_worker/service_worker_storage.h" 26 #include "content/browser/service_worker/service_worker_storage.h"
28 #include "content/browser/storage_partition_impl.h" 27 #include "content/browser/storage_partition_impl.h"
29 #include "content/public/browser/background_sync_parameters.h" 28 #include "content/public/browser/background_sync_parameters.h"
30 #include "content/public/test/background_sync_test_util.h" 29 #include "content/public/test/background_sync_test_util.h"
31 #include "content/public/test/test_browser_context.h" 30 #include "content/public/test/test_browser_context.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 continuation_ = 192 continuation_ =
194 base::Bind(&TestBackgroundSyncManager::GetDataFromBackendContinue, 193 base::Bind(&TestBackgroundSyncManager::GetDataFromBackendContinue,
195 base::Unretained(this), key, callback); 194 base::Unretained(this), key, callback);
196 if (delay_backend_) 195 if (delay_backend_)
197 return; 196 return;
198 197
199 Continue(); 198 Continue();
200 } 199 }
201 200
202 void DispatchSyncEvent( 201 void DispatchSyncEvent(
203 BackgroundSyncRegistrationHandle::HandleId handle_id, 202 const std::string& tag,
204 const scoped_refptr<ServiceWorkerVersion>& active_version, 203 const scoped_refptr<ServiceWorkerVersion>& active_version,
205 BackgroundSyncEventLastChance last_chance, 204 BackgroundSyncEventLastChance last_chance,
206 const ServiceWorkerVersion::StatusCallback& callback) override { 205 const ServiceWorkerVersion::StatusCallback& callback) override {
207 ASSERT_FALSE(dispatch_sync_callback_.is_null()); 206 ASSERT_FALSE(dispatch_sync_callback_.is_null());
208 last_chance_ = last_chance; 207 last_chance_ = last_chance;
209 dispatch_sync_callback_.Run(active_version, callback); 208 dispatch_sync_callback_.Run(active_version, callback);
210 } 209 }
211 210
212 void ScheduleDelayedTask(const base::Closure& callback, 211 void ScheduleDelayedTask(const base::Closure& callback,
213 base::TimeDelta delay) override { 212 base::TimeDelta delay) override {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 test_background_sync_manager_->GetNetworkObserverForTesting(); 312 test_background_sync_manager_->GetNetworkObserverForTesting();
314 network_observer->NotifyManagerIfNetworkChangedForTesting( 313 network_observer->NotifyManagerIfNetworkChangedForTesting(
315 connection_type); 314 connection_type);
316 base::RunLoop().RunUntilIdle(); 315 base::RunLoop().RunUntilIdle();
317 } 316 }
318 } 317 }
319 318
320 void StatusAndRegistrationCallback( 319 void StatusAndRegistrationCallback(
321 bool* was_called, 320 bool* was_called,
322 BackgroundSyncStatus status, 321 BackgroundSyncStatus status,
323 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle) { 322 scoped_ptr<BackgroundSyncRegistration> registration) {
324 *was_called = true; 323 *was_called = true;
325 callback_status_ = status; 324 callback_status_ = status;
326 callback_registration_handle_ = std::move(registration_handle); 325 callback_registration_ = std::move(registration);
327 } 326 }
328 327
329 void StatusAndRegistrationsCallback( 328 void StatusAndRegistrationsCallback(
330 bool* was_called, 329 bool* was_called,
331 BackgroundSyncStatus status, 330 BackgroundSyncStatus status,
332 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> 331 scoped_ptr<ScopedVector<BackgroundSyncRegistration>> registrations) {
333 registration_handles) {
334 *was_called = true; 332 *was_called = true;
335 callback_status_ = status; 333 callback_status_ = status;
336 callback_registration_handles_ = std::move(registration_handles); 334 callback_registrations_ = std::move(registrations);
337 } 335 }
338 336
339 void StatusCallback(bool* was_called, BackgroundSyncStatus status) { 337 void StatusCallback(bool* was_called, BackgroundSyncStatus status) {
340 *was_called = true; 338 *was_called = true;
341 callback_status_ = status; 339 callback_status_ = status;
342 } 340 }
343 341
344 protected: 342 protected:
345 void CreateBackgroundSyncManager() { 343 void CreateBackgroundSyncManager() {
346 ClearRegistrationHandles();
347
348 test_background_sync_manager_ = 344 test_background_sync_manager_ =
349 new TestBackgroundSyncManager(helper_->context_wrapper()); 345 new TestBackgroundSyncManager(helper_->context_wrapper());
350 background_sync_manager_.reset(test_background_sync_manager_); 346 background_sync_manager_.reset(test_background_sync_manager_);
351 347
352 test_clock_ = new base::SimpleTestClock(); 348 test_clock_ = new base::SimpleTestClock();
353 background_sync_manager_->set_clock(make_scoped_ptr(test_clock_)); 349 background_sync_manager_->set_clock(make_scoped_ptr(test_clock_));
354 350
355 // Many tests do not expect the sync event to fire immediately after 351 // Many tests do not expect the sync event to fire immediately after
356 // register (and cleanup up the sync registrations). Tests can control when 352 // register (and cleanup up the sync registrations). Tests can control when
357 // the sync event fires by manipulating the network state as needed. 353 // the sync event fires by manipulating the network state as needed.
358 // NOTE: The setup of the network connection must happen after the 354 // NOTE: The setup of the network connection must happen after the
359 // BackgroundSyncManager has been created. 355 // BackgroundSyncManager has been created.
360 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE); 356 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE);
361 } 357 }
362 358
363 void InitBackgroundSyncManager() { 359 void InitBackgroundSyncManager() {
364 test_background_sync_manager_->DoInit(); 360 test_background_sync_manager_->DoInit();
365 base::RunLoop().RunUntilIdle(); 361 base::RunLoop().RunUntilIdle();
366 } 362 }
367 363
368 // Clear the registrations so that the BackgroundSyncManager can release them.
369 void ClearRegistrationHandles() {
370 callback_registration_handle_.reset();
371 callback_registration_handles_.reset();
372 }
373
374 void SetupBackgroundSyncManager() { 364 void SetupBackgroundSyncManager() {
375 CreateBackgroundSyncManager(); 365 CreateBackgroundSyncManager();
376 InitBackgroundSyncManager(); 366 InitBackgroundSyncManager();
377 } 367 }
378 368
379 void SetupCorruptBackgroundSyncManager() { 369 void SetupCorruptBackgroundSyncManager() {
380 CreateBackgroundSyncManager(); 370 CreateBackgroundSyncManager();
381 test_background_sync_manager_->set_corrupt_backend(true); 371 test_background_sync_manager_->set_corrupt_backend(true);
382 InitBackgroundSyncManager(); 372 InitBackgroundSyncManager();
383 } 373 }
384 374
385 void SetupDelayedBackgroundSyncManager() { 375 void SetupDelayedBackgroundSyncManager() {
386 CreateBackgroundSyncManager(); 376 CreateBackgroundSyncManager();
387 test_background_sync_manager_->set_delay_backend(true); 377 test_background_sync_manager_->set_delay_backend(true);
388 InitBackgroundSyncManager(); 378 InitBackgroundSyncManager();
389 } 379 }
390 380
391 void DeleteBackgroundSyncManager() { 381 void DeleteBackgroundSyncManager() {
392 ClearRegistrationHandles();
393 background_sync_manager_.reset(); 382 background_sync_manager_.reset();
394 test_background_sync_manager_ = nullptr; 383 test_background_sync_manager_ = nullptr;
395 test_clock_ = nullptr; 384 test_clock_ = nullptr;
396 } 385 }
397 386
398 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { 387 bool Register(const BackgroundSyncRegistrationOptions& sync_options) {
399 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); 388 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options);
400 } 389 }
401 390
402 bool RegisterWithServiceWorkerId( 391 bool RegisterWithServiceWorkerId(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 const BackgroundSyncRegistrationOptions& registration_options) { 425 const BackgroundSyncRegistrationOptions& registration_options) {
437 bool was_called = false; 426 bool was_called = false;
438 background_sync_manager_->GetRegistrations( 427 background_sync_manager_->GetRegistrations(
439 sw_registration_id, 428 sw_registration_id,
440 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback, 429 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback,
441 base::Unretained(this), &was_called)); 430 base::Unretained(this), &was_called));
442 base::RunLoop().RunUntilIdle(); 431 base::RunLoop().RunUntilIdle();
443 EXPECT_TRUE(was_called); 432 EXPECT_TRUE(was_called);
444 433
445 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { 434 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
446 for (auto iter = callback_registration_handles_->begin(); 435 for (auto iter = callback_registrations_->begin();
447 iter < callback_registration_handles_->end(); ++iter) { 436 iter < callback_registrations_->end(); ++iter) {
448 if ((*iter)->options()->tag == registration_options.tag) { 437 if ((*iter)->options()->tag == registration_options.tag) {
449 // Transfer the matching registration handle out of the vector into 438 // Transfer the matching registration out of the vector into
450 // callback_registration_handle_ for testing. 439 // callback_registration_ for testing.
451 callback_registration_handle_.reset(*iter); 440 callback_registration_.reset(*iter);
452 callback_registration_handles_->weak_erase(iter); 441 callback_registrations_->weak_erase(iter);
453 return true; 442 return true;
454 } 443 }
455 } 444 }
456 } 445 }
457 return false; 446 return false;
458 } 447 }
459 448
460 bool GetRegistrations() { 449 bool GetRegistrations() {
461 return GetRegistrationsWithServiceWorkerId(sw_registration_id_1_); 450 return GetRegistrationsWithServiceWorkerId(sw_registration_id_1_);
462 } 451 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 int64_t sw_registration_id_1_; 546 int64_t sw_registration_id_1_;
558 int64_t sw_registration_id_2_; 547 int64_t sw_registration_id_2_;
559 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; 548 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_;
560 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; 549 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_;
561 550
562 BackgroundSyncRegistrationOptions sync_options_1_; 551 BackgroundSyncRegistrationOptions sync_options_1_;
563 BackgroundSyncRegistrationOptions sync_options_2_; 552 BackgroundSyncRegistrationOptions sync_options_2_;
564 553
565 // Callback values. 554 // Callback values.
566 BackgroundSyncStatus callback_status_ = BACKGROUND_SYNC_STATUS_OK; 555 BackgroundSyncStatus callback_status_ = BACKGROUND_SYNC_STATUS_OK;
567 scoped_ptr<BackgroundSyncRegistrationHandle> callback_registration_handle_; 556 scoped_ptr<BackgroundSyncRegistration> callback_registration_;
568 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> 557 scoped_ptr<ScopedVector<BackgroundSyncRegistration>> callback_registrations_;
569 callback_registration_handles_;
570 ServiceWorkerStatusCode callback_sw_status_code_ = SERVICE_WORKER_OK; 558 ServiceWorkerStatusCode callback_sw_status_code_ = SERVICE_WORKER_OK;
571 int sync_events_called_ = 0; 559 int sync_events_called_ = 0;
572 ServiceWorkerVersion::StatusCallback sync_fired_callback_; 560 ServiceWorkerVersion::StatusCallback sync_fired_callback_;
573 }; 561 };
574 562
575 TEST_F(BackgroundSyncManagerTest, Register) { 563 TEST_F(BackgroundSyncManagerTest, Register) {
576 EXPECT_TRUE(Register(sync_options_1_)); 564 EXPECT_TRUE(Register(sync_options_1_));
577 } 565 }
578 566
579 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { 567 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
580 EXPECT_TRUE(Register(sync_options_1_)); 568 EXPECT_TRUE(Register(sync_options_1_));
581 EXPECT_STREQ(sync_options_1_.tag.c_str(), 569 EXPECT_STREQ(sync_options_1_.tag.c_str(),
582 callback_registration_handle_->options()->tag.c_str()); 570 callback_registration_->options()->tag.c_str());
583 EXPECT_TRUE(callback_registration_handle_->IsValid()); 571 EXPECT_TRUE(callback_registration_->IsValid());
584 } 572 }
585 573
586 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { 574 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {
587 sw_registration_1_ = nullptr; 575 sw_registration_1_ = nullptr;
588 EXPECT_FALSE(Register(sync_options_1_)); 576 EXPECT_FALSE(Register(sync_options_1_));
589 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 577 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
590 } 578 }
591 579
592 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { 580 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
593 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); 581 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
594 EXPECT_FALSE(Register(sync_options_1_)); 582 EXPECT_FALSE(Register(sync_options_1_));
595 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 583 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
596 } 584 }
597 585
598 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { 586 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
599 test_background_sync_manager_->set_corrupt_backend(true); 587 test_background_sync_manager_->set_corrupt_backend(true);
600 EXPECT_FALSE(Register(sync_options_1_)); 588 EXPECT_FALSE(Register(sync_options_1_));
601 test_background_sync_manager_->set_corrupt_backend(false); 589 test_background_sync_manager_->set_corrupt_backend(false);
602 EXPECT_FALSE(Register(sync_options_1_)); 590 EXPECT_FALSE(Register(sync_options_1_));
603 EXPECT_FALSE(GetRegistration(sync_options_1_)); 591 EXPECT_FALSE(GetRegistration(sync_options_1_));
604 } 592 }
605 593
606 TEST_F(BackgroundSyncManagerTest, DuplicateRegistrationHandle) {
607 EXPECT_TRUE(Register(sync_options_1_));
608 EXPECT_TRUE(
609 sync_options_1_.Equals(*callback_registration_handle_->options()));
610
611 scoped_ptr<BackgroundSyncRegistrationHandle> dup_handle =
612 background_sync_manager_->DuplicateRegistrationHandle(
613 callback_registration_handle_->handle_id());
614
615 EXPECT_TRUE(sync_options_1_.Equals(*dup_handle->options()));
616 EXPECT_NE(callback_registration_handle_->handle_id(),
617 dup_handle->handle_id());
618 }
619
620 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { 594 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {
621 EXPECT_TRUE(Register(sync_options_1_)); 595 EXPECT_TRUE(Register(sync_options_1_));
622 EXPECT_TRUE(Register(sync_options_2_)); 596 EXPECT_TRUE(Register(sync_options_2_));
623 } 597 }
624 598
625 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { 599 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) {
626 EXPECT_FALSE(GetRegistration(sync_options_1_)); 600 EXPECT_FALSE(GetRegistration(sync_options_1_));
627 } 601 }
628 602
629 TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) { 603 TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) {
630 EXPECT_TRUE(Register(sync_options_1_)); 604 EXPECT_TRUE(Register(sync_options_1_));
631 EXPECT_TRUE(GetRegistration(sync_options_1_)); 605 EXPECT_TRUE(GetRegistration(sync_options_1_));
632 EXPECT_FALSE(GetRegistration(sync_options_2_)); 606 EXPECT_FALSE(GetRegistration(sync_options_2_));
633 } 607 }
634 608
635 TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) { 609 TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) {
636 EXPECT_TRUE(Register(sync_options_1_)); 610 EXPECT_TRUE(Register(sync_options_1_));
637 test_background_sync_manager_->set_corrupt_backend(true); 611 test_background_sync_manager_->set_corrupt_backend(true);
638 EXPECT_TRUE(GetRegistration(sync_options_1_)); 612 EXPECT_TRUE(GetRegistration(sync_options_1_));
639 EXPECT_FALSE(Register(sync_options_2_)); 613 EXPECT_FALSE(Register(sync_options_2_));
640 // Registration should have discovered the bad backend and disabled the 614 // Registration should have discovered the bad backend and disabled the
641 // BackgroundSyncManager. 615 // BackgroundSyncManager.
642 EXPECT_FALSE(GetRegistration(sync_options_1_)); 616 EXPECT_FALSE(GetRegistration(sync_options_1_));
643 test_background_sync_manager_->set_corrupt_backend(false); 617 test_background_sync_manager_->set_corrupt_backend(false);
644 EXPECT_FALSE(GetRegistration(sync_options_1_)); 618 EXPECT_FALSE(GetRegistration(sync_options_1_));
645 } 619 }
646 620
647 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { 621 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) {
648 EXPECT_TRUE(GetRegistrations()); 622 EXPECT_TRUE(GetRegistrations());
649 EXPECT_EQ(0u, callback_registration_handles_->size()); 623 EXPECT_EQ(0u, callback_registrations_->size());
650 } 624 }
651 625
652 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { 626 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {
653 EXPECT_TRUE(Register(sync_options_1_)); 627 EXPECT_TRUE(Register(sync_options_1_));
654 EXPECT_TRUE(GetRegistrations()); 628 EXPECT_TRUE(GetRegistrations());
655 629
656 EXPECT_EQ(1u, callback_registration_handles_->size()); 630 EXPECT_EQ(1u, callback_registrations_->size());
657 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options()); 631 sync_options_1_.Equals(*(*callback_registrations_)[0]->options());
658 } 632 }
659 633
660 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { 634 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
661 EXPECT_TRUE(Register(sync_options_1_)); 635 EXPECT_TRUE(Register(sync_options_1_));
662 EXPECT_TRUE(Register(sync_options_2_)); 636 EXPECT_TRUE(Register(sync_options_2_));
663 EXPECT_TRUE(GetRegistrations()); 637 EXPECT_TRUE(GetRegistrations());
664 638
665 EXPECT_EQ(2u, callback_registration_handles_->size()); 639 EXPECT_EQ(2u, callback_registrations_->size());
666 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options()); 640 sync_options_1_.Equals(*(*callback_registrations_)[0]->options());
667 sync_options_2_.Equals(*(*callback_registration_handles_)[1]->options()); 641 sync_options_2_.Equals(*(*callback_registrations_)[1]->options());
668 } 642 }
669 643
670 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { 644 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {
671 EXPECT_TRUE(Register(sync_options_1_)); 645 EXPECT_TRUE(Register(sync_options_1_));
672 test_background_sync_manager_->set_corrupt_backend(true); 646 test_background_sync_manager_->set_corrupt_backend(true);
673 EXPECT_TRUE(GetRegistrations()); 647 EXPECT_TRUE(GetRegistrations());
674 EXPECT_FALSE(Register(sync_options_2_)); 648 EXPECT_FALSE(Register(sync_options_2_));
675 // Registration should have discovered the bad backend and disabled the 649 // Registration should have discovered the bad backend and disabled the
676 // BackgroundSyncManager. 650 // BackgroundSyncManager.
677 EXPECT_FALSE(GetRegistrations()); 651 EXPECT_FALSE(GetRegistrations());
(...skipping 18 matching lines...) Expand all
696 sync_options_1_.tag = std::string(MaxTagLength(), 'a'); 670 sync_options_1_.tag = std::string(MaxTagLength(), 'a');
697 EXPECT_TRUE(Register(sync_options_1_)); 671 EXPECT_TRUE(Register(sync_options_1_));
698 672
699 sync_options_2_.tag = std::string(MaxTagLength() + 1, 'b'); 673 sync_options_2_.tag = std::string(MaxTagLength() + 1, 'b');
700 EXPECT_FALSE(Register(sync_options_2_)); 674 EXPECT_FALSE(Register(sync_options_2_));
701 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback_status_); 675 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback_status_);
702 } 676 }
703 677
704 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { 678 TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
705 EXPECT_TRUE(Register(sync_options_1_)); 679 EXPECT_TRUE(Register(sync_options_1_));
706 scoped_ptr<BackgroundSyncRegistrationHandle> registered_handle =
707 std::move(callback_registration_handle_);
708 BackgroundSyncRegistration::RegistrationId cur_id = 680 BackgroundSyncRegistration::RegistrationId cur_id =
709 registered_handle->handle_id(); 681 callback_registration_->id();
710 682
711 EXPECT_TRUE(GetRegistration(sync_options_1_)); 683 EXPECT_TRUE(GetRegistration(sync_options_1_));
712 EXPECT_TRUE(Register(sync_options_2_)); 684 EXPECT_TRUE(Register(sync_options_2_));
713 EXPECT_LT(cur_id, callback_registration_handle_->handle_id()); 685 EXPECT_LT(cur_id, callback_registration_->id());
714 } 686 }
715 687
716 TEST_F(BackgroundSyncManagerTest, RebootRecovery) { 688 TEST_F(BackgroundSyncManagerTest, RebootRecovery) {
717 EXPECT_TRUE(Register(sync_options_1_)); 689 EXPECT_TRUE(Register(sync_options_1_));
718 690
719 SetupBackgroundSyncManager(); 691 SetupBackgroundSyncManager();
720 692
721 EXPECT_TRUE(GetRegistration(sync_options_1_)); 693 EXPECT_TRUE(GetRegistration(sync_options_1_));
722 EXPECT_FALSE(GetRegistration(sync_options_2_)); 694 EXPECT_FALSE(GetRegistration(sync_options_2_));
723 } 695 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 options.network_state = NETWORK_STATE_AVOID_CELLULAR; 872 options.network_state = NETWORK_STATE_AVOID_CELLULAR;
901 873
902 // Store the registration. 874 // Store the registration.
903 EXPECT_TRUE(Register(options)); 875 EXPECT_TRUE(Register(options));
904 876
905 // Simulate restarting the sync manager, forcing the next read to come from 877 // Simulate restarting the sync manager, forcing the next read to come from
906 // disk. 878 // disk.
907 SetupBackgroundSyncManager(); 879 SetupBackgroundSyncManager();
908 880
909 EXPECT_TRUE(GetRegistration(options)); 881 EXPECT_TRUE(GetRegistration(options));
910 EXPECT_TRUE(options.Equals(*callback_registration_handle_->options())); 882 EXPECT_TRUE(options.Equals(*callback_registration_->options()));
911 } 883 }
912 884
913 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { 885 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {
914 sync_options_1_.tag = ""; 886 sync_options_1_.tag = "";
915 EXPECT_TRUE(Register(sync_options_1_)); 887 EXPECT_TRUE(Register(sync_options_1_));
916 EXPECT_TRUE(GetRegistration(sync_options_1_)); 888 EXPECT_TRUE(GetRegistration(sync_options_1_));
917 EXPECT_TRUE( 889 EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_->options()));
918 sync_options_1_.Equals(*callback_registration_handle_->options()));
919 } 890 }
920 891
921 TEST_F(BackgroundSyncManagerTest, FiresOnRegistration) { 892 TEST_F(BackgroundSyncManagerTest, FiresOnRegistration) {
922 InitSyncEventTest(); 893 InitSyncEventTest();
923 894
924 EXPECT_TRUE(Register(sync_options_1_)); 895 EXPECT_TRUE(Register(sync_options_1_));
925 EXPECT_EQ(1, sync_events_called_); 896 EXPECT_EQ(1, sync_events_called_);
926 EXPECT_FALSE(GetRegistration(sync_options_1_)); 897 EXPECT_FALSE(GetRegistration(sync_options_1_));
927 } 898 }
928 899
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 // Run it again. 1428 // Run it again.
1458 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1429 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1459 test_background_sync_manager_->delayed_task().Run(); 1430 test_background_sync_manager_->delayed_task().Run();
1460 base::RunLoop().RunUntilIdle(); 1431 base::RunLoop().RunUntilIdle();
1461 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1432 EXPECT_FALSE(GetRegistration(sync_options_1_));
1462 EXPECT_EQ(BackgroundSyncEventLastChance::IS_LAST_CHANCE, 1433 EXPECT_EQ(BackgroundSyncEventLastChance::IS_LAST_CHANCE,
1463 test_background_sync_manager_->last_chance()); 1434 test_background_sync_manager_->last_chance());
1464 } 1435 }
1465 1436
1466 } // namespace content 1437 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698