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

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

Issue 7719011: Move some files from sync/engine to internal_api (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Refresh the diff and remove unintended change Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.cc ('k') | chrome/browser/sync/glue/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/scoped_callback_factory.h" 8 #include "base/memory/scoped_callback_factory.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "base/test/test_timeouts.h" 11 #include "base/test/test_timeouts.h"
12 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" 12 #include "chrome/browser/sync/engine/mock_model_safe_workers.h"
13 #include "chrome/browser/sync/engine/configure_reason.h"
14 #include "chrome/browser/sync/engine/sync_scheduler.h" 13 #include "chrome/browser/sync/engine/sync_scheduler.h"
15 #include "chrome/browser/sync/engine/syncer.h" 14 #include "chrome/browser/sync/engine/syncer.h"
16 #include "chrome/browser/sync/sessions/test_util.h" 15 #include "chrome/browser/sync/sessions/test_util.h"
17 #include "chrome/test/sync/engine/mock_connection_manager.h" 16 #include "chrome/test/sync/engine/mock_connection_manager.h"
18 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 17 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
21 20
22 using base::TimeDelta; 21 using base::TimeDelta;
23 using base::TimeTicks; 22 using base::TimeTicks;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 model_types[syncable::BOOKMARKS] = true; 281 model_types[syncable::BOOKMARKS] = true;
283 282
284 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 283 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
285 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 284 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
286 WithArg<0>(RecordSyncShare(&records)))); 285 WithArg<0>(RecordSyncShare(&records))));
287 286
288 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 287 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
289 RunLoop(); 288 RunLoop();
290 289
291 scheduler()->ScheduleConfig( 290 scheduler()->ScheduleConfig(
292 model_types, sync_api::CONFIGURE_REASON_RECONFIGURATION); 291 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
293 RunLoop(); 292 RunLoop();
294 293
295 ASSERT_EQ(1U, records.snapshots.size()); 294 ASSERT_EQ(1U, records.snapshots.size());
296 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, 295 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types,
297 records.snapshots[0]->source.types)); 296 records.snapshots[0]->source.types));
298 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 297 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
299 records.snapshots[0]->source.updates_source); 298 records.snapshots[0]->source.updates_source);
300 } 299 }
301 300
302 // Simulate a failure and make sure the config request is retried. 301 // Simulate a failure and make sure the config request is retried.
303 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 302 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
304 UseMockDelayProvider(); 303 UseMockDelayProvider();
305 EXPECT_CALL(*delay(), GetDelay(_)) 304 EXPECT_CALL(*delay(), GetDelay(_))
306 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 305 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
307 SyncShareRecords records; 306 SyncShareRecords records;
308 syncable::ModelTypeBitSet model_types; 307 syncable::ModelTypeBitSet model_types;
309 model_types[syncable::BOOKMARKS] = true; 308 model_types[syncable::BOOKMARKS] = true;
310 309
311 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 310 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
312 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 311 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
313 WithArg<0>(RecordSyncShare(&records)))) 312 WithArg<0>(RecordSyncShare(&records))))
314 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 313 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
315 WithArg<0>(RecordSyncShare(&records)))); 314 WithArg<0>(RecordSyncShare(&records))));
316 315
317 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 316 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
318 RunLoop(); 317 RunLoop();
319 318
320 ASSERT_EQ(0U, records.snapshots.size()); 319 ASSERT_EQ(0U, records.snapshots.size());
321 scheduler()->ScheduleConfig( 320 scheduler()->ScheduleConfig(
322 model_types, sync_api::CONFIGURE_REASON_RECONFIGURATION); 321 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
323 RunLoop(); 322 RunLoop();
324 323
325 ASSERT_EQ(1U, records.snapshots.size()); 324 ASSERT_EQ(1U, records.snapshots.size());
326 RunLoop(); 325 RunLoop();
327 326
328 ASSERT_EQ(2U, records.snapshots.size()); 327 ASSERT_EQ(2U, records.snapshots.size());
329 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, 328 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types,
330 records.snapshots[1]->source.types)); 329 records.snapshots[1]->source.types));
331 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, 330 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
332 records.snapshots[1]->source.updates_source); 331 records.snapshots[1]->source.updates_source);
(...skipping 16 matching lines...) Expand all
349 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 348 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
350 WithArg<0>(RecordSyncShare(&records)))) 349 WithArg<0>(RecordSyncShare(&records))))
351 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 350 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
352 WithArg<0>(RecordSyncShare(&records)))); 351 WithArg<0>(RecordSyncShare(&records))));
353 352
354 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 353 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
355 RunLoop(); 354 RunLoop();
356 355
357 ASSERT_EQ(0U, records.snapshots.size()); 356 ASSERT_EQ(0U, records.snapshots.size());
358 scheduler()->ScheduleConfig( 357 scheduler()->ScheduleConfig(
359 model_types1, sync_api::CONFIGURE_REASON_RECONFIGURATION); 358 model_types1, GetUpdatesCallerInfo::RECONFIGURATION);
360 RunLoop(); 359 RunLoop();
361 360
362 ASSERT_EQ(1U, records.snapshots.size()); 361 ASSERT_EQ(1U, records.snapshots.size());
363 scheduler()->ScheduleConfig( 362 scheduler()->ScheduleConfig(
364 model_types2, sync_api::CONFIGURE_REASON_RECONFIGURATION); 363 model_types2, GetUpdatesCallerInfo::RECONFIGURATION);
365 RunLoop(); 364 RunLoop();
366 365
367 ASSERT_EQ(2U, records.snapshots.size()); 366 ASSERT_EQ(2U, records.snapshots.size());
368 RunLoop(); 367 RunLoop();
369 368
370 ASSERT_EQ(3U, records.snapshots.size()); 369 ASSERT_EQ(3U, records.snapshots.size());
371 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types2, 370 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types2,
372 records.snapshots[2]->source.types)); 371 records.snapshots[2]->source.types));
373 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 372 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
374 records.snapshots[2]->source.updates_source); 373 records.snapshots[2]->source.updates_source);
(...skipping 17 matching lines...) Expand all
392 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 391 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
393 WithArg<0>(RecordSyncShare(&records)))) 392 WithArg<0>(RecordSyncShare(&records))))
394 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 393 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
395 WithArg<0>(RecordSyncShare(&records)))); 394 WithArg<0>(RecordSyncShare(&records))));
396 395
397 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 396 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
398 RunLoop(); 397 RunLoop();
399 398
400 ASSERT_EQ(0U, records.snapshots.size()); 399 ASSERT_EQ(0U, records.snapshots.size());
401 scheduler()->ScheduleConfig( 400 scheduler()->ScheduleConfig(
402 model_types, sync_api::CONFIGURE_REASON_RECONFIGURATION); 401 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
403 RunLoop(); 402 RunLoop();
404 403
405 ASSERT_EQ(1U, records.snapshots.size()); 404 ASSERT_EQ(1U, records.snapshots.size());
406 scheduler()->ScheduleNudge( 405 scheduler()->ScheduleNudge(
407 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 406 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
408 RunLoop(); 407 RunLoop();
409 408
410 ASSERT_EQ(2U, records.snapshots.size()); 409 ASSERT_EQ(2U, records.snapshots.size());
411 RunLoop(); 410 RunLoop();
412 411
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 RunLoop(); 690 RunLoop();
692 691
693 scheduler()->ScheduleNudge( 692 scheduler()->ScheduleNudge(
694 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 693 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
695 PumpLoop(); 694 PumpLoop();
696 695
697 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 696 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
698 RunLoop(); 697 RunLoop();
699 698
700 scheduler()->ScheduleConfig( 699 scheduler()->ScheduleConfig(
701 types, sync_api::CONFIGURE_REASON_RECONFIGURATION); 700 types, GetUpdatesCallerInfo::RECONFIGURATION);
702 PumpLoop(); 701 PumpLoop();
703 } 702 }
704 703
705 TEST_F(SyncSchedulerTest, ThrottlingExpires) { 704 TEST_F(SyncSchedulerTest, ThrottlingExpires) {
706 SyncShareRecords records; 705 SyncShareRecords records;
707 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 706 TimeDelta poll(TimeDelta::FromMilliseconds(15));
708 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 707 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
709 TimeDelta throttle2(TimeDelta::FromMinutes(10)); 708 TimeDelta throttle2(TimeDelta::FromMinutes(10));
710 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 709 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
711 710
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 nudge_types[syncable::AUTOFILL] = true; 743 nudge_types[syncable::AUTOFILL] = true;
745 scheduler()->ScheduleNudge( 744 scheduler()->ScheduleNudge(
746 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 745 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
747 scheduler()->ScheduleNudge( 746 scheduler()->ScheduleNudge(
748 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 747 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
749 748
750 syncable::ModelTypeBitSet config_types; 749 syncable::ModelTypeBitSet config_types;
751 config_types[syncable::BOOKMARKS] = true; 750 config_types[syncable::BOOKMARKS] = true;
752 751
753 scheduler()->ScheduleConfig( 752 scheduler()->ScheduleConfig(
754 config_types, sync_api::CONFIGURE_REASON_RECONFIGURATION); 753 config_types, GetUpdatesCallerInfo::RECONFIGURATION);
755 RunLoop(); 754 RunLoop();
756 755
757 ASSERT_EQ(1U, records.snapshots.size()); 756 ASSERT_EQ(1U, records.snapshots.size());
758 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(config_types, 757 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(config_types,
759 records.snapshots[0]->source.types)); 758 records.snapshots[0]->source.types));
760 } 759 }
761 760
762 // Test that exponential backoff is properly triggered. 761 // Test that exponential backoff is properly triggered.
763 TEST_F(SyncSchedulerTest, BackoffTriggers) { 762 TEST_F(SyncSchedulerTest, BackoffTriggers) {
764 UseMockDelayProvider(); 763 UseMockDelayProvider();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 845 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
847 r.snapshots[2]->source.updates_source); 846 r.snapshots[2]->source.updates_source);
848 847
849 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); 848 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0);
850 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 849 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
851 850
852 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 851 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
853 RunLoop(); 852 RunLoop();
854 853
855 scheduler()->ScheduleConfig( 854 scheduler()->ScheduleConfig(
856 types, sync_api::CONFIGURE_REASON_RECONFIGURATION); 855 types, GetUpdatesCallerInfo::RECONFIGURATION);
857 PumpLoop(); 856 PumpLoop();
858 857
859 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 858 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
860 RunLoop(); 859 RunLoop();
861 860
862 scheduler()->ScheduleNudge( 861 scheduler()->ScheduleNudge(
863 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 862 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
864 scheduler()->ScheduleNudge( 863 scheduler()->ScheduleNudge(
865 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 864 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
866 PumpLoop(); 865 PumpLoop();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 987
989 scheduler()->Stop(); 988 scheduler()->Stop();
990 Mock::VerifyAndClearExpectations(syncer()); 989 Mock::VerifyAndClearExpectations(syncer());
991 990
992 // Configuration. 991 // Configuration.
993 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); 992 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES));
994 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 993 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
995 RunLoop(); 994 RunLoop();
996 995
997 scheduler()->ScheduleConfig( 996 scheduler()->ScheduleConfig(
998 ModelTypeBitSet(), sync_api::CONFIGURE_REASON_RECONFIGURATION); 997 ModelTypeBitSet(), GetUpdatesCallerInfo::RECONFIGURATION);
999 PumpLoop(); 998 PumpLoop();
1000 PumpLoop(); 999 PumpLoop();
1001 1000
1002 scheduler()->Stop(); 1001 scheduler()->Stop();
1003 Mock::VerifyAndClearExpectations(syncer()); 1002 Mock::VerifyAndClearExpectations(syncer());
1004 1003
1005 // Cleanup disabled types. 1004 // Cleanup disabled types.
1006 EXPECT_CALL(*syncer(), 1005 EXPECT_CALL(*syncer(),
1007 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)); 1006 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES));
1008 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1007 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 PumpLoop(); 1069 PumpLoop();
1071 // Pump again to run job. 1070 // Pump again to run job.
1072 PumpLoop(); 1071 PumpLoop();
1073 1072
1074 scheduler()->Stop(); 1073 scheduler()->Stop();
1075 1074
1076 EXPECT_TRUE(expected == context()->previous_session_routing_info()); 1075 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1077 } 1076 }
1078 1077
1079 } // namespace browser_sync 1078 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.cc ('k') | chrome/browser/sync/glue/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698