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

Side by Side Diff: sync/engine/sync_scheduler_unittest.cc

Issue 10455012: [Sync] Add support for performing a GetKey on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fred's comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 workers_.begin(); it != workers_.end(); ++it) { 113 workers_.begin(); it != workers_.end(); ++it) {
114 workers.push_back(it->get()); 114 workers.push_back(it->get());
115 } 115 }
116 116
117 connection_.reset(new MockConnectionManager(directory())); 117 connection_.reset(new MockConnectionManager(directory()));
118 connection_->SetServerReachable(); 118 connection_->SetServerReachable();
119 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); 119 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL));
120 context_.reset(new SyncSessionContext( 120 context_.reset(new SyncSessionContext(
121 connection_.get(), directory(), workers, 121 connection_.get(), directory(), workers,
122 &extensions_activity_monitor_, throttled_data_type_tracker_.get(), 122 &extensions_activity_monitor_, throttled_data_type_tracker_.get(),
123 std::vector<SyncEngineEventListener*>(), NULL, NULL)); 123 std::vector<SyncEngineEventListener*>(), NULL, NULL,
124 true /* enable keystore encryption */));
124 context_->set_routing_info(routing_info); 125 context_->set_routing_info(routing_info);
125 context_->set_notifications_enabled(true); 126 context_->set_notifications_enabled(true);
126 context_->set_account_name("Test"); 127 context_->set_account_name("Test");
127 scheduler_.reset( 128 scheduler_.reset(
128 new SyncSchedulerImpl("TestSyncScheduler", context(), syncer_)); 129 new SyncSchedulerImpl("TestSyncScheduler", context(), syncer_));
129 } 130 }
130 131
131 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } 132 SyncSchedulerImpl* scheduler() { return scheduler_.get(); }
132 MockSyncer* syncer() { return syncer_; } 133 MockSyncer* syncer() { return syncer_; }
133 MockDelayProvider* delay() { return delay_; } 134 MockDelayProvider* delay() { return delay_; }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
306 WithArg<0>(RecordSyncShare(&records)))); 307 WithArg<0>(RecordSyncShare(&records))));
307 308
308 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 309 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
309 310
310 CallbackCounter counter; 311 CallbackCounter counter;
311 ConfigurationParams params( 312 ConfigurationParams params(
312 GetUpdatesCallerInfo::RECONFIGURATION, 313 GetUpdatesCallerInfo::RECONFIGURATION,
313 model_types, 314 model_types,
314 TypesToRoutingInfo(model_types), 315 TypesToRoutingInfo(model_types),
315 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
316 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 316 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
317 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 317 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
318 ASSERT_EQ(1, counter.times_called()); 318 ASSERT_EQ(1, counter.times_called());
319 319
320 ASSERT_EQ(1U, records.snapshots.size()); 320 ASSERT_EQ(1U, records.snapshots.size());
321 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 321 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
322 records.snapshots[0].source().types)); 322 records.snapshots[0].source().types));
323 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 323 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
324 records.snapshots[0].source().updates_source); 324 records.snapshots[0].source().updates_source);
325 } 325 }
(...skipping 13 matching lines...) Expand all
339 WithArg<0>(RecordSyncShare(&records)))); 339 WithArg<0>(RecordSyncShare(&records))));
340 340
341 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 341 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
342 342
343 ASSERT_EQ(0U, records.snapshots.size()); 343 ASSERT_EQ(0U, records.snapshots.size());
344 CallbackCounter counter; 344 CallbackCounter counter;
345 ConfigurationParams params( 345 ConfigurationParams params(
346 GetUpdatesCallerInfo::RECONFIGURATION, 346 GetUpdatesCallerInfo::RECONFIGURATION,
347 model_types, 347 model_types,
348 TypesToRoutingInfo(model_types), 348 TypesToRoutingInfo(model_types),
349 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
350 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 349 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
351 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 350 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
352 ASSERT_EQ(0, counter.times_called()); 351 ASSERT_EQ(0, counter.times_called());
353 352
354 ASSERT_EQ(1U, records.snapshots.size()); 353 ASSERT_EQ(1U, records.snapshots.size());
355 RunLoop(); 354 RunLoop();
356 355
357 ASSERT_EQ(2U, records.snapshots.size()); 356 ASSERT_EQ(2U, records.snapshots.size());
358 ASSERT_EQ(1, counter.times_called()); 357 ASSERT_EQ(1, counter.times_called());
359 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 358 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
(...skipping 22 matching lines...) Expand all
382 WithArg<0>(RecordSyncShare(&records)))); 381 WithArg<0>(RecordSyncShare(&records))));
383 382
384 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 383 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
385 384
386 ASSERT_EQ(0U, records.snapshots.size()); 385 ASSERT_EQ(0U, records.snapshots.size());
387 CallbackCounter counter; 386 CallbackCounter counter;
388 ConfigurationParams params( 387 ConfigurationParams params(
389 GetUpdatesCallerInfo::RECONFIGURATION, 388 GetUpdatesCallerInfo::RECONFIGURATION,
390 model_types, 389 model_types,
391 TypesToRoutingInfo(model_types), 390 TypesToRoutingInfo(model_types),
392 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
393 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 391 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
394 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 392 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
395 ASSERT_EQ(0, counter.times_called()); 393 ASSERT_EQ(0, counter.times_called());
396 ASSERT_EQ(1U, records.snapshots.size()); 394 ASSERT_EQ(1U, records.snapshots.size());
397 395
398 scheduler()->ScheduleNudgeAsync( 396 scheduler()->ScheduleNudgeAsync(
399 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 397 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
400 RunLoop(); 398 RunLoop();
401 ASSERT_EQ(2U, records.snapshots.size()); 399 ASSERT_EQ(2U, records.snapshots.size());
402 ASSERT_EQ(0, counter.times_called()); 400 ASSERT_EQ(0, counter.times_called());
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 721 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
724 PumpLoop(); 722 PumpLoop();
725 723
726 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 724 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
727 725
728 CallbackCounter counter; 726 CallbackCounter counter;
729 ConfigurationParams params( 727 ConfigurationParams params(
730 GetUpdatesCallerInfo::RECONFIGURATION, 728 GetUpdatesCallerInfo::RECONFIGURATION,
731 types, 729 types,
732 TypesToRoutingInfo(types), 730 TypesToRoutingInfo(types),
733 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
734 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 731 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
735 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 732 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
736 ASSERT_EQ(0, counter.times_called()); 733 ASSERT_EQ(0, counter.times_called());
737 } 734 }
738 735
739 TEST_F(SyncSchedulerTest, ThrottlingExpires) { 736 TEST_F(SyncSchedulerTest, ThrottlingExpires) {
740 SyncShareRecords records; 737 SyncShareRecords records;
741 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 738 TimeDelta poll(TimeDelta::FromMilliseconds(15));
742 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 739 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
743 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 740 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 scheduler()->ScheduleNudgeAsync( 774 scheduler()->ScheduleNudgeAsync(
778 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 775 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
779 776
780 const ModelTypeSet config_types(BOOKMARKS); 777 const ModelTypeSet config_types(BOOKMARKS);
781 778
782 CallbackCounter counter; 779 CallbackCounter counter;
783 ConfigurationParams params( 780 ConfigurationParams params(
784 GetUpdatesCallerInfo::RECONFIGURATION, 781 GetUpdatesCallerInfo::RECONFIGURATION,
785 config_types, 782 config_types,
786 TypesToRoutingInfo(config_types), 783 TypesToRoutingInfo(config_types),
787 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
788 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 784 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
789 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 785 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
790 ASSERT_EQ(1, counter.times_called()); 786 ASSERT_EQ(1, counter.times_called());
791 787
792 ASSERT_EQ(1U, records.snapshots.size()); 788 ASSERT_EQ(1U, records.snapshots.size());
793 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, 789 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types,
794 records.snapshots[0].source().types)); 790 records.snapshots[0].source().types));
795 } 791 }
796 792
797 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { 793 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 // Expect this will leave the scheduler in backoff. 837 // Expect this will leave the scheduler in backoff.
842 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { 838 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
843 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 839 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
844 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) 840 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed))
845 .WillRepeatedly(DoAll( 841 .WillRepeatedly(DoAll(
846 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 842 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
847 QuitLoopNowAction())); 843 QuitLoopNowAction()));
848 EXPECT_TRUE(RunAndGetBackoff()); 844 EXPECT_TRUE(RunAndGetBackoff());
849 } 845 }
850 846
847 // Have the syncer fail to get the encryption key yet succeed in downloading
848 // updates. Expect this will leave the scheduler in backoff.
849 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
850 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
851 .WillOnce(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed))
852 .WillRepeatedly(DoAll(
853 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
854 QuitLoopNowAction()));
855 EXPECT_TRUE(RunAndGetBackoff());
856 }
857
851 // Test that no polls or extraneous nudges occur when in backoff. 858 // Test that no polls or extraneous nudges occur when in backoff.
852 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 859 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
853 SyncShareRecords r; 860 SyncShareRecords r;
854 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 861 TimeDelta poll(TimeDelta::FromMilliseconds(5));
855 const ModelTypeSet types(BOOKMARKS); 862 const ModelTypeSet types(BOOKMARKS);
856 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 863 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
857 UseMockDelayProvider(); 864 UseMockDelayProvider();
858 865
859 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 866 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
860 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 867 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 899
893 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 900 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
894 901
895 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 902 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
896 903
897 CallbackCounter counter; 904 CallbackCounter counter;
898 ConfigurationParams params( 905 ConfigurationParams params(
899 GetUpdatesCallerInfo::RECONFIGURATION, 906 GetUpdatesCallerInfo::RECONFIGURATION,
900 types, 907 types,
901 TypesToRoutingInfo(types), 908 TypesToRoutingInfo(types),
902 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
903 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 909 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
904 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 910 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
905 ASSERT_EQ(0, counter.times_called()); 911 ASSERT_EQ(0, counter.times_called());
906 912
907 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 913 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
908 914
909 scheduler()->ScheduleNudgeAsync( 915 scheduler()->ScheduleNudgeAsync(
910 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 916 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
911 scheduler()->ScheduleNudgeAsync( 917 scheduler()->ScheduleNudgeAsync(
912 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 918 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1073 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1068 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1074 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1069 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1075 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1070 1076
1071 ModelTypeSet model_types(BOOKMARKS); 1077 ModelTypeSet model_types(BOOKMARKS);
1072 CallbackCounter counter; 1078 CallbackCounter counter;
1073 ConfigurationParams params( 1079 ConfigurationParams params(
1074 GetUpdatesCallerInfo::RECONFIGURATION, 1080 GetUpdatesCallerInfo::RECONFIGURATION,
1075 model_types, 1081 model_types,
1076 TypesToRoutingInfo(model_types), 1082 TypesToRoutingInfo(model_types),
1077 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
1078 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1083 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1079 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 1084 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
1080 ASSERT_EQ(1, counter.times_called()); 1085 ASSERT_EQ(1, counter.times_called());
1081 // Runs directly so no need to pump the loop. 1086 // Runs directly so no need to pump the loop.
1082 StopSyncScheduler(); 1087 StopSyncScheduler();
1083 Mock::VerifyAndClearExpectations(syncer()); 1088 Mock::VerifyAndClearExpectations(syncer());
1084 1089
1085 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1090 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1086 1091
1087 // Poll. 1092 // Poll.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 // Should save the nudge for until after the server is reachable. 1126 // Should save the nudge for until after the server is reachable.
1122 MessageLoop::current()->RunAllPending(); 1127 MessageLoop::current()->RunAllPending();
1123 1128
1124 connection()->SetServerReachable(); 1129 connection()->SetServerReachable();
1125 connection()->UpdateConnectionStatus(); 1130 connection()->UpdateConnectionStatus();
1126 scheduler()->OnConnectionStatusChange(); 1131 scheduler()->OnConnectionStatusChange();
1127 MessageLoop::current()->RunAllPending(); 1132 MessageLoop::current()->RunAllPending();
1128 } 1133 }
1129 1134
1130 } // namespace syncer 1135 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698