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

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

Issue 1614063002: [BackgroundSync Cleanup] Remove periodic sync code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@purge_power
Patch Set: Address comments from PS3 Created 4 years, 11 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"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 base::Closure delayed_task_; 281 base::Closure delayed_task_;
282 base::TimeDelta delayed_task_delta_; 282 base::TimeDelta delayed_task_delta_;
283 }; 283 };
284 284
285 class BackgroundSyncManagerTest : public testing::Test { 285 class BackgroundSyncManagerTest : public testing::Test {
286 public: 286 public:
287 BackgroundSyncManagerTest() 287 BackgroundSyncManagerTest()
288 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 288 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
289 network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { 289 network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) {
290 sync_options_1_.tag = "foo"; 290 sync_options_1_.tag = "foo";
291 sync_options_1_.periodicity = SYNC_ONE_SHOT;
292 sync_options_1_.network_state = NETWORK_STATE_ONLINE; 291 sync_options_1_.network_state = NETWORK_STATE_ONLINE;
293 292
294 sync_options_2_.tag = "bar"; 293 sync_options_2_.tag = "bar";
295 sync_options_2_.periodicity = SYNC_ONE_SHOT;
296 sync_options_2_.network_state = NETWORK_STATE_ONLINE; 294 sync_options_2_.network_state = NETWORK_STATE_ONLINE;
297 } 295 }
298 296
299 void SetUp() override { 297 void SetUp() override {
300 // Don't let the tests be confused by the real-world device connectivity 298 // Don't let the tests be confused by the real-world device connectivity
301 background_sync_test_util::SetIgnoreNetworkChangeNotifier(true); 299 background_sync_test_util::SetIgnoreNetworkChangeNotifier(true);
302 300
303 // TODO(jkarlin): Create a new object with all of the necessary SW calls 301 // TODO(jkarlin): Create a new object with all of the necessary SW calls
304 // so that we can inject test versions instead of bringing up all of this 302 // so that we can inject test versions instead of bringing up all of this
305 // extra SW stuff. 303 // extra SW stuff.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 527 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
530 registration_options); 528 registration_options);
531 } 529 }
532 530
533 bool GetRegistrationWithServiceWorkerId( 531 bool GetRegistrationWithServiceWorkerId(
534 int64_t sw_registration_id, 532 int64_t sw_registration_id,
535 const BackgroundSyncRegistrationOptions& registration_options) { 533 const BackgroundSyncRegistrationOptions& registration_options) {
536 bool was_called = false; 534 bool was_called = false;
537 background_sync_manager_->GetRegistration( 535 background_sync_manager_->GetRegistration(
538 sw_registration_id, registration_options.tag, 536 sw_registration_id, registration_options.tag,
539 registration_options.periodicity,
540 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 537 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
541 base::Unretained(this), &was_called)); 538 base::Unretained(this), &was_called));
542 base::RunLoop().RunUntilIdle(); 539 base::RunLoop().RunUntilIdle();
543 EXPECT_TRUE(was_called); 540 EXPECT_TRUE(was_called);
544 541
545 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) { 542 if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
546 EXPECT_STREQ(registration_options.tag.c_str(), 543 EXPECT_STREQ(registration_options.tag.c_str(),
547 callback_registration_handle_->options()->tag.c_str()); 544 callback_registration_handle_->options()->tag.c_str());
548 } 545 }
549 546
550 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 547 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
551 } 548 }
552 549
553 bool GetRegistrations(SyncPeriodicity periodicity) { 550 bool GetRegistrations() {
554 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, 551 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_);
555 periodicity);
556 } 552 }
557 553
558 bool GetRegistrationWithServiceWorkerId(int64_t sw_registration_id, 554 bool GetRegistrationWithServiceWorkerId(int64_t sw_registration_id) {
559 SyncPeriodicity periodicity) {
560 bool was_called = false; 555 bool was_called = false;
561 background_sync_manager_->GetRegistrations( 556 background_sync_manager_->GetRegistrations(
562 sw_registration_id, periodicity, 557 sw_registration_id,
563 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback, 558 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback,
564 base::Unretained(this), &was_called)); 559 base::Unretained(this), &was_called));
565 base::RunLoop().RunUntilIdle(); 560 base::RunLoop().RunUntilIdle();
566 EXPECT_TRUE(was_called); 561 EXPECT_TRUE(was_called);
567 562
568 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 563 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
569 } 564 }
570 565
571 void StorageRegistrationCallback(ServiceWorkerStatusCode result) { 566 void StorageRegistrationCallback(ServiceWorkerStatusCode result) {
572 callback_sw_status_code_ = result; 567 callback_sw_status_code_ = result;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 EXPECT_FALSE(Register(sync_options_1_)); 677 EXPECT_FALSE(Register(sync_options_1_));
683 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 678 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
684 } 679 }
685 680
686 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { 681 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
687 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); 682 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
688 EXPECT_FALSE(Register(sync_options_1_)); 683 EXPECT_FALSE(Register(sync_options_1_));
689 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_); 684 EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
690 } 685 }
691 686
692 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) {
693 EXPECT_TRUE(Register(sync_options_1_));
694 scoped_ptr<BackgroundSyncRegistrationHandle> first_registration_handle =
695 std::move(callback_registration_handle_);
696
697 sync_options_1_.min_period = 100;
698 EXPECT_TRUE(Register(sync_options_1_));
699 EXPECT_LT(first_registration_handle->handle_id(),
700 callback_registration_handle_->handle_id());
701 EXPECT_FALSE(first_registration_handle->options()->Equals(
702 *callback_registration_handle_->options()));
703 }
704
705 TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) {
706 // Registrations with the same tags but different periodicities should not
707 // collide.
708 sync_options_1_.tag = "";
709 sync_options_2_.tag = "";
710 sync_options_1_.periodicity = SYNC_PERIODIC;
711 sync_options_2_.periodicity = SYNC_ONE_SHOT;
712 EXPECT_TRUE(Register(sync_options_1_));
713 EXPECT_TRUE(Register(sync_options_2_));
714 EXPECT_TRUE(GetRegistration(sync_options_1_));
715 EXPECT_EQ(SYNC_PERIODIC,
716 callback_registration_handle_->options()->periodicity);
717 EXPECT_TRUE(GetRegistration(sync_options_2_));
718 EXPECT_EQ(SYNC_ONE_SHOT,
719 callback_registration_handle_->options()->periodicity);
720 }
721
722 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { 687 TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
723 test_background_sync_manager_->set_corrupt_backend(true); 688 test_background_sync_manager_->set_corrupt_backend(true);
724 EXPECT_FALSE(Register(sync_options_1_)); 689 EXPECT_FALSE(Register(sync_options_1_));
725 test_background_sync_manager_->set_corrupt_backend(false); 690 test_background_sync_manager_->set_corrupt_backend(false);
726 EXPECT_FALSE(Register(sync_options_1_)); 691 EXPECT_FALSE(Register(sync_options_1_));
727 EXPECT_FALSE(GetRegistration(sync_options_1_)); 692 EXPECT_FALSE(GetRegistration(sync_options_1_));
728 } 693 }
729 694
730 TEST_F(BackgroundSyncManagerTest, DuplicateRegistrationHandle) { 695 TEST_F(BackgroundSyncManagerTest, DuplicateRegistrationHandle) {
731 EXPECT_TRUE(Register(sync_options_1_)); 696 EXPECT_TRUE(Register(sync_options_1_));
(...skipping 30 matching lines...) Expand all
762 EXPECT_TRUE(GetRegistration(sync_options_1_)); 727 EXPECT_TRUE(GetRegistration(sync_options_1_));
763 EXPECT_FALSE(Register(sync_options_2_)); 728 EXPECT_FALSE(Register(sync_options_2_));
764 // Registration should have discovered the bad backend and disabled the 729 // Registration should have discovered the bad backend and disabled the
765 // BackgroundSyncManager. 730 // BackgroundSyncManager.
766 EXPECT_FALSE(GetRegistration(sync_options_1_)); 731 EXPECT_FALSE(GetRegistration(sync_options_1_));
767 test_background_sync_manager_->set_corrupt_backend(false); 732 test_background_sync_manager_->set_corrupt_backend(false);
768 EXPECT_FALSE(GetRegistration(sync_options_1_)); 733 EXPECT_FALSE(GetRegistration(sync_options_1_));
769 } 734 }
770 735
771 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) { 736 TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) {
772 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT)); 737 EXPECT_TRUE(GetRegistrations());
773 EXPECT_EQ(0u, callback_registration_handles_->size()); 738 EXPECT_EQ(0u, callback_registration_handles_->size());
774 } 739 }
775 740
776 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) { 741 TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {
777 EXPECT_TRUE(Register(sync_options_1_)); 742 EXPECT_TRUE(Register(sync_options_1_));
778 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 743 EXPECT_TRUE(GetRegistrations());
779 744
780 EXPECT_EQ(1u, callback_registration_handles_->size()); 745 EXPECT_EQ(1u, callback_registration_handles_->size());
781 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options()); 746 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
782 } 747 }
783 748
784 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) { 749 TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
785 EXPECT_EQ(sync_options_1_.periodicity, sync_options_2_.periodicity);
786
787 EXPECT_TRUE(Register(sync_options_1_)); 750 EXPECT_TRUE(Register(sync_options_1_));
788 EXPECT_TRUE(Register(sync_options_2_)); 751 EXPECT_TRUE(Register(sync_options_2_));
789 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 752 EXPECT_TRUE(GetRegistrations());
790 753
791 EXPECT_EQ(2u, callback_registration_handles_->size()); 754 EXPECT_EQ(2u, callback_registration_handles_->size());
792 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options()); 755 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
793 sync_options_2_.Equals(*(*callback_registration_handles_)[1]->options()); 756 sync_options_2_.Equals(*(*callback_registration_handles_)[1]->options());
794 } 757 }
795 758
796 TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) {
797 sync_options_1_.periodicity = SYNC_ONE_SHOT;
798 sync_options_2_.periodicity = SYNC_PERIODIC;
799 EXPECT_TRUE(Register(sync_options_1_));
800 EXPECT_TRUE(Register(sync_options_2_));
801
802 EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
803 EXPECT_EQ(1u, callback_registration_handles_->size());
804 sync_options_1_.Equals(*(*callback_registration_handles_)[0]->options());
805
806 EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC));
807 EXPECT_EQ(1u, callback_registration_handles_->size());
808 sync_options_2_.Equals(*(*callback_registration_handles_)[0]->options());
809 }
810
811 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) { 759 TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {
812 EXPECT_TRUE(Register(sync_options_1_)); 760 EXPECT_TRUE(Register(sync_options_1_));
813 test_background_sync_manager_->set_corrupt_backend(true); 761 test_background_sync_manager_->set_corrupt_backend(true);
814 EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity)); 762 EXPECT_TRUE(GetRegistrations());
815 EXPECT_FALSE(Register(sync_options_2_)); 763 EXPECT_FALSE(Register(sync_options_2_));
816 // Registration should have discovered the bad backend and disabled the 764 // Registration should have discovered the bad backend and disabled the
817 // BackgroundSyncManager. 765 // BackgroundSyncManager.
818 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 766 EXPECT_FALSE(GetRegistrations());
819 test_background_sync_manager_->set_corrupt_backend(false); 767 test_background_sync_manager_->set_corrupt_backend(false);
820 EXPECT_FALSE(GetRegistrations(sync_options_1_.periodicity)); 768 EXPECT_FALSE(GetRegistrations());
821 } 769 }
822 770
823 TEST_F(BackgroundSyncManagerTest, Unregister) { 771 TEST_F(BackgroundSyncManagerTest, Unregister) {
824 EXPECT_TRUE(Register(sync_options_1_)); 772 EXPECT_TRUE(Register(sync_options_1_));
825 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 773 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
826 EXPECT_FALSE(GetRegistration(sync_options_1_)); 774 EXPECT_FALSE(GetRegistration(sync_options_1_));
827 } 775 }
828 776
829 TEST_F(BackgroundSyncManagerTest, Reregister) { 777 TEST_F(BackgroundSyncManagerTest, Reregister) {
830 EXPECT_TRUE(Register(sync_options_1_)); 778 EXPECT_TRUE(Register(sync_options_1_));
831 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 779 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
832 EXPECT_TRUE(Register(sync_options_1_)); 780 EXPECT_TRUE(Register(sync_options_1_));
833 } 781 }
834 782
835 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) { 783 TEST_F(BackgroundSyncManagerTest, UnregisterSecond) {
836 EXPECT_TRUE(Register(sync_options_1_)); 784 EXPECT_TRUE(Register(sync_options_1_));
837 EXPECT_TRUE(Register(sync_options_2_)); 785 EXPECT_TRUE(Register(sync_options_2_));
838 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 786 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
839 EXPECT_TRUE(GetRegistration(sync_options_1_)); 787 EXPECT_TRUE(GetRegistration(sync_options_1_));
840 EXPECT_TRUE(Register(sync_options_2_)); 788 EXPECT_TRUE(Register(sync_options_2_));
841 } 789 }
842 790
843 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { 791 TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) {
844 sync_options_1_.min_period += 1;
845 EXPECT_TRUE(Register(sync_options_1_)); 792 EXPECT_TRUE(Register(sync_options_1_));
846 EXPECT_TRUE(Register(sync_options_2_)); 793 EXPECT_TRUE(Register(sync_options_2_));
847 test_background_sync_manager_->set_corrupt_backend(true); 794 test_background_sync_manager_->set_corrupt_backend(true);
848 EXPECT_FALSE(Unregister(callback_registration_handle_.get())); 795 EXPECT_FALSE(Unregister(callback_registration_handle_.get()));
849 // Unregister should have discovered the bad backend and disabled the 796 // Unregister should have discovered the bad backend and disabled the
850 // BackgroundSyncManager. 797 // BackgroundSyncManager.
851 test_background_sync_manager_->set_corrupt_backend(false); 798 test_background_sync_manager_->set_corrupt_backend(false);
852 EXPECT_FALSE(GetRegistration(sync_options_1_)); 799 EXPECT_FALSE(GetRegistration(sync_options_1_));
853 EXPECT_FALSE(GetRegistration(sync_options_2_)); 800 EXPECT_FALSE(GetRegistration(sync_options_2_));
854 } 801 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 SetupDelayedBackgroundSyncManager(); 877 SetupDelayedBackgroundSyncManager();
931 878
932 bool register_called = false; 879 bool register_called = false;
933 bool get_registration_called = false; 880 bool get_registration_called = false;
934 test_background_sync_manager_->Register( 881 test_background_sync_manager_->Register(
935 sw_registration_id_1_, sync_options_1_, 882 sw_registration_id_1_, sync_options_1_,
936 true /* requested_from_service_worker */, 883 true /* requested_from_service_worker */,
937 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 884 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
938 base::Unretained(this), &register_called)); 885 base::Unretained(this), &register_called));
939 test_background_sync_manager_->GetRegistration( 886 test_background_sync_manager_->GetRegistration(
940 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, 887 sw_registration_id_1_, sync_options_1_.tag,
941 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, 888 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
942 base::Unretained(this), &get_registration_called)); 889 base::Unretained(this), &get_registration_called));
943 890
944 base::RunLoop().RunUntilIdle(); 891 base::RunLoop().RunUntilIdle();
945 // Init should be blocked while loading from the backend. 892 // Init should be blocked while loading from the backend.
946 EXPECT_FALSE(register_called); 893 EXPECT_FALSE(register_called);
947 EXPECT_FALSE(get_registration_called); 894 EXPECT_FALSE(get_registration_called);
948 895
949 test_background_sync_manager_->Continue(); 896 test_background_sync_manager_->Continue();
950 base::RunLoop().RunUntilIdle(); 897 base::RunLoop().RunUntilIdle();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } 988 }
1042 989
1043 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) { 990 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) {
1044 BackgroundSyncRegistration reg_1; 991 BackgroundSyncRegistration reg_1;
1045 BackgroundSyncRegistration reg_2; 992 BackgroundSyncRegistration reg_2;
1046 EXPECT_TRUE(reg_1.Equals(reg_2)); 993 EXPECT_TRUE(reg_1.Equals(reg_2));
1047 reg_2.options()->tag = "bar"; 994 reg_2.options()->tag = "bar";
1048 EXPECT_FALSE(reg_1.Equals(reg_2)); 995 EXPECT_FALSE(reg_1.Equals(reg_2));
1049 } 996 }
1050 997
1051 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsPeriodicity) {
1052 BackgroundSyncRegistration reg_1;
1053 BackgroundSyncRegistration reg_2;
1054 EXPECT_TRUE(reg_1.Equals(reg_2));
1055 reg_1.options()->periodicity = SYNC_PERIODIC;
1056 reg_2.options()->periodicity = SYNC_ONE_SHOT;
1057 EXPECT_FALSE(reg_1.Equals(reg_2));
1058 }
1059
1060 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsMinPeriod) {
1061 BackgroundSyncRegistration reg_1;
1062 BackgroundSyncRegistration reg_2;
1063 EXPECT_TRUE(reg_1.Equals(reg_2));
1064 reg_2.options()->min_period = reg_1.options()->min_period + 1;
1065 EXPECT_FALSE(reg_1.Equals(reg_2));
1066 }
1067
1068 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsNetworkState) { 998 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsNetworkState) {
1069 BackgroundSyncRegistration reg_1; 999 BackgroundSyncRegistration reg_1;
1070 BackgroundSyncRegistration reg_2; 1000 BackgroundSyncRegistration reg_2;
1071 EXPECT_TRUE(reg_1.Equals(reg_2)); 1001 EXPECT_TRUE(reg_1.Equals(reg_2));
1072 reg_1.options()->network_state = NETWORK_STATE_ANY; 1002 reg_1.options()->network_state = NETWORK_STATE_ANY;
1073 reg_2.options()->network_state = NETWORK_STATE_ONLINE; 1003 reg_2.options()->network_state = NETWORK_STATE_ONLINE;
1074 EXPECT_FALSE(reg_1.Equals(reg_2)); 1004 EXPECT_FALSE(reg_1.Equals(reg_2));
1075 } 1005 }
1076 1006
1077 TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) { 1007 TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) {
1008 InitDelayedSyncEventTest();
1078 BackgroundSyncRegistrationOptions options; 1009 BackgroundSyncRegistrationOptions options;
1010
1079 // Set non-default values for each field. 1011 // Set non-default values for each field.
1080 options.tag = "foo"; 1012 options.tag = "foo";
1081 EXPECT_NE(SYNC_PERIODIC, options.periodicity); 1013 EXPECT_NE(NETWORK_STATE_AVOID_CELLULAR, options.network_state);
1082 options.periodicity = SYNC_PERIODIC; 1014 options.network_state = NETWORK_STATE_AVOID_CELLULAR;
1083 options.min_period += 1;
1084 EXPECT_NE(NETWORK_STATE_ANY, options.network_state);
1085 options.network_state = NETWORK_STATE_ANY;
1086 1015
1087 // Store the registration. 1016 // Store the registration.
1088 EXPECT_TRUE(Register(options)); 1017 EXPECT_TRUE(Register(options));
1089 1018
1090 // Simulate restarting the sync manager, forcing the next read to come from 1019 // Simulate restarting the sync manager, forcing the next read to come from
1091 // disk. 1020 // disk.
1092 SetupBackgroundSyncManager(); 1021 SetupBackgroundSyncManager();
1093 1022
1094 EXPECT_TRUE(GetRegistration(options)); 1023 EXPECT_TRUE(GetRegistration(options));
1095 EXPECT_TRUE(options.Equals(*callback_registration_handle_->options())); 1024 EXPECT_TRUE(options.Equals(*callback_registration_handle_->options()));
1096 } 1025 }
1097 1026
1098 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) { 1027 TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {
1099 sync_options_1_.tag = "a"; 1028 sync_options_1_.tag = "a";
1100 EXPECT_TRUE(Register(sync_options_1_)); 1029 EXPECT_TRUE(Register(sync_options_1_));
1101 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1030 EXPECT_TRUE(GetRegistration(sync_options_1_));
1102 EXPECT_TRUE( 1031 EXPECT_TRUE(
1103 sync_options_1_.Equals(*callback_registration_handle_->options())); 1032 sync_options_1_.Equals(*callback_registration_handle_->options()));
1104 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1033 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1105 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1034 EXPECT_FALSE(GetRegistration(sync_options_1_));
1106 } 1035 }
1107 1036
1108 TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) {
1109 // Registrations with the same tags but different periodicities should not
1110 // collide.
1111 sync_options_1_.tag = "";
1112 sync_options_2_.tag = "";
1113 sync_options_1_.periodicity = SYNC_PERIODIC;
1114 sync_options_2_.periodicity = SYNC_ONE_SHOT;
1115
1116 EXPECT_TRUE(Register(sync_options_1_));
1117 EXPECT_TRUE(Register(sync_options_2_));
1118
1119 EXPECT_TRUE(GetRegistration(sync_options_1_));
1120 EXPECT_EQ(SYNC_PERIODIC,
1121 callback_registration_handle_->options()->periodicity);
1122 EXPECT_TRUE(GetRegistration(sync_options_2_));
1123 EXPECT_EQ(SYNC_ONE_SHOT,
1124 callback_registration_handle_->options()->periodicity);
1125
1126 EXPECT_TRUE(GetRegistration(sync_options_1_));
1127 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1128 EXPECT_FALSE(GetRegistration(sync_options_1_));
1129 EXPECT_TRUE(GetRegistration(sync_options_2_));
1130 EXPECT_EQ(SYNC_ONE_SHOT,
1131 callback_registration_handle_->options()->periodicity);
1132
1133 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1134 EXPECT_FALSE(GetRegistration(sync_options_2_));
1135 }
1136
1137 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) { 1037 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnRegistration) {
1138 InitSyncEventTest(); 1038 InitSyncEventTest();
1139 1039
1140 EXPECT_TRUE(Register(sync_options_1_)); 1040 EXPECT_TRUE(Register(sync_options_1_));
1141 EXPECT_EQ(1, sync_events_called_); 1041 EXPECT_EQ(1, sync_events_called_);
1142 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1042 EXPECT_FALSE(GetRegistration(sync_options_1_));
1143 } 1043 }
1144 1044
1145 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterEventSuccess) { 1045 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterEventSuccess) {
1146 InitSyncEventTest(); 1046 InitSyncEventTest();
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 callback_registration_handle_->options()->network_state); 1258 callback_registration_handle_->options()->network_state);
1359 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle = 1259 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle =
1360 std::move(callback_registration_handle_); 1260 std::move(callback_registration_handle_);
1361 1261
1362 // Overwrite the pending registration. 1262 // Overwrite the pending registration.
1363 sync_options_1_.network_state = NETWORK_STATE_ONLINE; 1263 sync_options_1_.network_state = NETWORK_STATE_ONLINE;
1364 EXPECT_TRUE(Register(sync_options_1_)); 1264 EXPECT_TRUE(Register(sync_options_1_));
1365 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1265 EXPECT_TRUE(GetRegistration(sync_options_1_));
1366 EXPECT_EQ(NETWORK_STATE_ONLINE, 1266 EXPECT_EQ(NETWORK_STATE_ONLINE,
1367 callback_registration_handle_->options()->network_state); 1267 callback_registration_handle_->options()->network_state);
1268 EXPECT_LT(original_handle->handle_id(),
1269 callback_registration_handle_->handle_id());
1368 1270
1369 EXPECT_TRUE(NotifyWhenFinished(original_handle.get())); 1271 EXPECT_TRUE(NotifyWhenFinished(original_handle.get()));
1370 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState()); 1272 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1371 EXPECT_EQ(0, sync_events_called_); 1273 EXPECT_EQ(0, sync_events_called_);
1372 } 1274 }
1373 1275
1374 TEST_F(BackgroundSyncManagerTest, OverwriteFiringRegistrationWhichSucceeds) { 1276 TEST_F(BackgroundSyncManagerTest, OverwriteFiringRegistrationWhichSucceeds) {
1375 // An overwritten pending registration should complete with 1277 // An overwritten pending registration should complete with
1376 // BackgroundSyncState::SUCCESS if firing completes successfully. 1278 // BackgroundSyncState::SUCCESS if firing completes successfully.
1377 InitDelayedSyncEventTest(); 1279 InitDelayedSyncEventTest();
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 // Run it again. 1854 // Run it again.
1953 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1855 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1954 test_background_sync_manager_->delayed_task().Run(); 1856 test_background_sync_manager_->delayed_task().Run();
1955 base::RunLoop().RunUntilIdle(); 1857 base::RunLoop().RunUntilIdle();
1956 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1858 EXPECT_FALSE(GetRegistration(sync_options_1_));
1957 EXPECT_EQ(BackgroundSyncEventLastChance::IS_LAST_CHANCE, 1859 EXPECT_EQ(BackgroundSyncEventLastChance::IS_LAST_CHANCE,
1958 test_background_sync_manager_->last_chance()); 1860 test_background_sync_manager_->last_chance());
1959 } 1861 }
1960 1862
1961 } // namespace content 1863 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/background_sync/background_sync_manager.cc ('k') | content/browser/background_sync/background_sync_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698