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

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: Move GetEncryptionKey logic into GetUpdates Created 8 years, 5 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(), routing_info, workers, 121 connection_.get(), directory(), routing_info, 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_notifications_enabled(true); 125 context_->set_notifications_enabled(true);
125 context_->set_account_name("Test"); 126 context_->set_account_name("Test");
126 scheduler_.reset( 127 scheduler_.reset(
127 new SyncScheduler("TestSyncScheduler", context(), syncer_)); 128 new SyncScheduler("TestSyncScheduler", context(), syncer_));
128 } 129 }
129 130
130 SyncScheduler* scheduler() { return scheduler_.get(); } 131 SyncScheduler* scheduler() { return scheduler_.get(); }
131 MockSyncer* syncer() { return syncer_; } 132 MockSyncer* syncer() { return syncer_; }
132 MockDelayProvider* delay() { return delay_; } 133 MockDelayProvider* delay() { return delay_; }
133 MockConnectionManager* connection() { return connection_.get(); } 134 MockConnectionManager* connection() { return connection_.get(); }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 305 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
305 WithArg<0>(RecordSyncShare(&records)))); 306 WithArg<0>(RecordSyncShare(&records))));
306 307
307 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 308 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
308 309
309 CallbackCounter counter; 310 CallbackCounter counter;
310 ConfigurationParams params( 311 ConfigurationParams params(
311 GetUpdatesCallerInfo::RECONFIGURATION, 312 GetUpdatesCallerInfo::RECONFIGURATION,
312 model_types, 313 model_types,
313 TypesToRoutingInfo(model_types), 314 TypesToRoutingInfo(model_types),
314 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
315 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 315 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
316 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 316 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
317 ASSERT_EQ(1, counter.times_called()); 317 ASSERT_EQ(1, counter.times_called());
318 318
319 ASSERT_EQ(1U, records.snapshots.size()); 319 ASSERT_EQ(1U, records.snapshots.size());
320 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 320 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
321 records.snapshots[0].source().types)); 321 records.snapshots[0].source().types));
322 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 322 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
323 records.snapshots[0].source().updates_source); 323 records.snapshots[0].source().updates_source);
324 } 324 }
(...skipping 13 matching lines...) Expand all
338 WithArg<0>(RecordSyncShare(&records)))); 338 WithArg<0>(RecordSyncShare(&records))));
339 339
340 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 340 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
341 341
342 ASSERT_EQ(0U, records.snapshots.size()); 342 ASSERT_EQ(0U, records.snapshots.size());
343 CallbackCounter counter; 343 CallbackCounter counter;
344 ConfigurationParams params( 344 ConfigurationParams params(
345 GetUpdatesCallerInfo::RECONFIGURATION, 345 GetUpdatesCallerInfo::RECONFIGURATION,
346 model_types, 346 model_types,
347 TypesToRoutingInfo(model_types), 347 TypesToRoutingInfo(model_types),
348 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
349 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 348 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
350 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 349 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
351 ASSERT_EQ(0, counter.times_called()); 350 ASSERT_EQ(0, counter.times_called());
352 351
353 ASSERT_EQ(1U, records.snapshots.size()); 352 ASSERT_EQ(1U, records.snapshots.size());
354 RunLoop(); 353 RunLoop();
355 354
356 ASSERT_EQ(2U, records.snapshots.size()); 355 ASSERT_EQ(2U, records.snapshots.size());
357 ASSERT_EQ(1, counter.times_called()); 356 ASSERT_EQ(1, counter.times_called());
358 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 357 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
(...skipping 22 matching lines...) Expand all
381 WithArg<0>(RecordSyncShare(&records)))); 380 WithArg<0>(RecordSyncShare(&records))));
382 381
383 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 382 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
384 383
385 ASSERT_EQ(0U, records.snapshots.size()); 384 ASSERT_EQ(0U, records.snapshots.size());
386 CallbackCounter counter; 385 CallbackCounter counter;
387 ConfigurationParams params( 386 ConfigurationParams params(
388 GetUpdatesCallerInfo::RECONFIGURATION, 387 GetUpdatesCallerInfo::RECONFIGURATION,
389 model_types, 388 model_types,
390 TypesToRoutingInfo(model_types), 389 TypesToRoutingInfo(model_types),
391 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
392 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 390 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
393 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 391 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
394 ASSERT_EQ(0, counter.times_called()); 392 ASSERT_EQ(0, counter.times_called());
395 ASSERT_EQ(1U, records.snapshots.size()); 393 ASSERT_EQ(1U, records.snapshots.size());
396 394
397 scheduler()->ScheduleNudgeAsync( 395 scheduler()->ScheduleNudgeAsync(
398 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 396 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
399 RunLoop(); 397 RunLoop();
400 ASSERT_EQ(2U, records.snapshots.size()); 398 ASSERT_EQ(2U, records.snapshots.size());
401 ASSERT_EQ(0, counter.times_called()); 399 ASSERT_EQ(0, counter.times_called());
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 725 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
728 PumpLoop(); 726 PumpLoop();
729 727
730 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 728 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
731 729
732 CallbackCounter counter; 730 CallbackCounter counter;
733 ConfigurationParams params( 731 ConfigurationParams params(
734 GetUpdatesCallerInfo::RECONFIGURATION, 732 GetUpdatesCallerInfo::RECONFIGURATION,
735 types, 733 types,
736 TypesToRoutingInfo(types), 734 TypesToRoutingInfo(types),
737 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
738 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 735 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
739 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 736 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
740 ASSERT_EQ(0, counter.times_called()); 737 ASSERT_EQ(0, counter.times_called());
741 } 738 }
742 739
743 TEST_F(SyncSchedulerTest, ThrottlingExpires) { 740 TEST_F(SyncSchedulerTest, ThrottlingExpires) {
744 SyncShareRecords records; 741 SyncShareRecords records;
745 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 742 TimeDelta poll(TimeDelta::FromMilliseconds(15));
746 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 743 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
747 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 744 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 scheduler()->ScheduleNudgeAsync( 778 scheduler()->ScheduleNudgeAsync(
782 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 779 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
783 780
784 const ModelTypeSet config_types(syncer::BOOKMARKS); 781 const ModelTypeSet config_types(syncer::BOOKMARKS);
785 782
786 CallbackCounter counter; 783 CallbackCounter counter;
787 ConfigurationParams params( 784 ConfigurationParams params(
788 GetUpdatesCallerInfo::RECONFIGURATION, 785 GetUpdatesCallerInfo::RECONFIGURATION,
789 config_types, 786 config_types,
790 TypesToRoutingInfo(config_types), 787 TypesToRoutingInfo(config_types),
791 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
792 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 788 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
793 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 789 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
794 ASSERT_EQ(1, counter.times_called()); 790 ASSERT_EQ(1, counter.times_called());
795 791
796 ASSERT_EQ(1U, records.snapshots.size()); 792 ASSERT_EQ(1U, records.snapshots.size());
797 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, 793 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types,
798 records.snapshots[0].source().types)); 794 records.snapshots[0].source().types));
799 } 795 }
800 796
801 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { 797 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 // Expect this will leave the scheduler in backoff. 841 // Expect this will leave the scheduler in backoff.
846 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { 842 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
847 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 843 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
848 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) 844 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed))
849 .WillRepeatedly(DoAll( 845 .WillRepeatedly(DoAll(
850 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 846 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
851 QuitLoopNowAction())); 847 QuitLoopNowAction()));
852 EXPECT_TRUE(RunAndGetBackoff()); 848 EXPECT_TRUE(RunAndGetBackoff());
853 } 849 }
854 850
851 // Have the syncer fail to get the encryption key yet succeed in downloading
852 // updates. Expect this will leave the scheduler in backoff.
853 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
854 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
855 .WillOnce(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed))
856 .WillRepeatedly(DoAll(
857 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
858 QuitLoopNowAction()));
859 EXPECT_TRUE(RunAndGetBackoff());
860 }
861
855 // Test that no polls or extraneous nudges occur when in backoff. 862 // Test that no polls or extraneous nudges occur when in backoff.
856 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 863 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
857 SyncShareRecords r; 864 SyncShareRecords r;
858 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 865 TimeDelta poll(TimeDelta::FromMilliseconds(5));
859 const ModelTypeSet types(syncer::BOOKMARKS); 866 const ModelTypeSet types(syncer::BOOKMARKS);
860 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 867 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
861 UseMockDelayProvider(); 868 UseMockDelayProvider();
862 869
863 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 870 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
864 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 871 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 903
897 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 904 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
898 905
899 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 906 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
900 907
901 CallbackCounter counter; 908 CallbackCounter counter;
902 ConfigurationParams params( 909 ConfigurationParams params(
903 GetUpdatesCallerInfo::RECONFIGURATION, 910 GetUpdatesCallerInfo::RECONFIGURATION,
904 types, 911 types,
905 TypesToRoutingInfo(types), 912 TypesToRoutingInfo(types),
906 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
907 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 913 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
908 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 914 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
909 ASSERT_EQ(0, counter.times_called()); 915 ASSERT_EQ(0, counter.times_called());
910 916
911 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 917 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
912 918
913 scheduler()->ScheduleNudgeAsync( 919 scheduler()->ScheduleNudgeAsync(
914 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 920 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
915 scheduler()->ScheduleNudgeAsync( 921 scheduler()->ScheduleNudgeAsync(
916 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 922 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1075 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1070 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1076 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1071 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1077 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1072 1078
1073 syncer::ModelTypeSet model_types(syncer::BOOKMARKS); 1079 syncer::ModelTypeSet model_types(syncer::BOOKMARKS);
1074 CallbackCounter counter; 1080 CallbackCounter counter;
1075 ConfigurationParams params( 1081 ConfigurationParams params(
1076 GetUpdatesCallerInfo::RECONFIGURATION, 1082 GetUpdatesCallerInfo::RECONFIGURATION,
1077 model_types, 1083 model_types,
1078 TypesToRoutingInfo(model_types), 1084 TypesToRoutingInfo(model_types),
1079 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
1080 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1085 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1081 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 1086 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
1082 ASSERT_EQ(1, counter.times_called()); 1087 ASSERT_EQ(1, counter.times_called());
1083 // Runs directly so no need to pump the loop. 1088 // Runs directly so no need to pump the loop.
1084 StopSyncScheduler(); 1089 StopSyncScheduler();
1085 Mock::VerifyAndClearExpectations(syncer()); 1090 Mock::VerifyAndClearExpectations(syncer());
1086 1091
1087 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1092 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1088 1093
1089 // Poll. 1094 // Poll.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 // Should save the nudge for until after the server is reachable. 1128 // Should save the nudge for until after the server is reachable.
1124 MessageLoop::current()->RunAllPending(); 1129 MessageLoop::current()->RunAllPending();
1125 1130
1126 connection()->SetServerReachable(); 1131 connection()->SetServerReachable();
1127 connection()->UpdateConnectionStatus(); 1132 connection()->UpdateConnectionStatus();
1128 scheduler()->OnConnectionStatusChange(); 1133 scheduler()->OnConnectionStatusChange();
1129 MessageLoop::current()->RunAllPending(); 1134 MessageLoop::current()->RunAllPending();
1130 } 1135 }
1131 1136
1132 } // namespace browser_sync 1137 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698