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

Side by Side Diff: sync/internal_api/syncapi_unittest.cc

Issue 10541079: [Sync] Remove CleanupDisabledTypes command and move purge logic into SyncManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix rebase conflict 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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 return false; 912 return false;
913 entry.Put(IS_UNSYNCED, false); 913 entry.Put(IS_UNSYNCED, false);
914 return true; 914 return true;
915 } 915 }
916 916
917 virtual InternalComponentsFactory* GetFactory() { 917 virtual InternalComponentsFactory* GetFactory() {
918 return new TestInternalComponentsFactory( 918 return new TestInternalComponentsFactory(
919 TestInternalComponentsFactory::IN_MEMORY); 919 TestInternalComponentsFactory::IN_MEMORY);
920 } 920 }
921 921
922 void SetProgressMarkerForType(ModelType type, bool set) {
923 if (set) {
924 sync_pb::DataTypeProgressMarker marker;
925 marker.set_token("token");
926 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
927 sync_manager_.directory()->SetDownloadProgress(type, marker);
928 } else {
929 sync_pb::DataTypeProgressMarker marker;
930 sync_manager_.directory()->SetDownloadProgress(type, marker);
931 }
932 }
933
934 void SetInitialSyncEndedForType(ModelType type, bool value) {
935 sync_manager_.directory()->set_initial_sync_ended_for_type(type, value);
936 }
937
922 private: 938 private:
923 // Needed by |sync_manager_|. 939 // Needed by |sync_manager_|.
924 MessageLoop message_loop_; 940 MessageLoop message_loop_;
925 // Needed by |sync_manager_|. 941 // Needed by |sync_manager_|.
926 ScopedTempDir temp_dir_; 942 ScopedTempDir temp_dir_;
927 // Sync Id's for the roots of the enabled datatypes. 943 // Sync Id's for the roots of the enabled datatypes.
928 std::map<ModelType, int64> type_roots_; 944 std::map<ModelType, int64> type_roots_;
929 FakeExtensionsActivityMonitor extensions_activity_monitor_; 945 FakeExtensionsActivityMonitor extensions_activity_monitor_;
930 StrictMock<SyncNotifierMock>* sync_notifier_mock_; 946 StrictMock<SyncNotifierMock>* sync_notifier_mock_;
931 947
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 public: 2543 public:
2528 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} 2544 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {}
2529 virtual InternalComponentsFactory* GetFactory() OVERRIDE { 2545 virtual InternalComponentsFactory* GetFactory() OVERRIDE {
2530 scheduler_ = new MockSyncScheduler(); 2546 scheduler_ = new MockSyncScheduler();
2531 return new ComponentsFactory(scheduler_); 2547 return new ComponentsFactory(scheduler_);
2532 } 2548 }
2533 MockSyncScheduler* scheduler_; 2549 MockSyncScheduler* scheduler_;
2534 }; 2550 };
2535 2551
2536 // Test that the configuration params are properly created and sent to 2552 // Test that the configuration params are properly created and sent to
2537 // ScheduleConfigure. No callback should be invoked. 2553 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes
2554 // should be purged (but only the types that were just disabled).
tim (not reviewing) 2012/07/26 21:39:45 I don't see a test that covers a case where both p
Nicolas Zea 2012/07/26 23:29:59 The purging of both at startup is actually going a
2538 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { 2555 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) {
2539 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2556 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2540 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); 2557 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
2541 ModelSafeRoutingInfo new_routing_info; 2558 ModelSafeRoutingInfo new_routing_info;
2542 GetModelSafeRoutingInfo(&new_routing_info); 2559 GetModelSafeRoutingInfo(&new_routing_info);
2560 ModelTypeSet disabled_types(THEMES, SESSIONS);
2561 new_routing_info.erase(THEMES);
2562 new_routing_info.erase(SESSIONS);
2543 2563
2544 ConfigurationParams params; 2564 ConfigurationParams params;
2545 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE)); 2565 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE));
2546 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)). 2566 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)).
2547 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2567 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2548 2568
2569 // Set data for all types.
2570 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
2571 iter.Inc()) {
2572 SetProgressMarkerForType(iter.Get(), true);
2573 SetInitialSyncEndedForType(iter.Get(), true);
2574 }
2575
2549 CallbackCounter ready_task_counter, retry_task_counter; 2576 CallbackCounter ready_task_counter, retry_task_counter;
2550 sync_manager_.ConfigureSyncer( 2577 sync_manager_.ConfigureSyncer(
2551 reason, 2578 reason,
2552 types_to_download, 2579 types_to_download,
2553 new_routing_info, 2580 new_routing_info,
2554 base::Bind(&CallbackCounter::Callback, 2581 base::Bind(&CallbackCounter::Callback,
2555 base::Unretained(&ready_task_counter)), 2582 base::Unretained(&ready_task_counter)),
2556 base::Bind(&CallbackCounter::Callback, 2583 base::Bind(&CallbackCounter::Callback,
2557 base::Unretained(&retry_task_counter))); 2584 base::Unretained(&retry_task_counter)));
2558 EXPECT_EQ(0, ready_task_counter.times_called()); 2585 EXPECT_EQ(0, ready_task_counter.times_called());
2559 EXPECT_EQ(0, retry_task_counter.times_called()); 2586 EXPECT_EQ(0, retry_task_counter.times_called());
2560 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2587 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2561 params.source); 2588 params.source);
2562 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2589 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2563 EXPECT_EQ(new_routing_info, params.routing_info); 2590 EXPECT_EQ(new_routing_info, params.routing_info);
2591
2592 // Verify only the disabled types were purged.
2593 EXPECT_TRUE(Intersection(sync_manager_.InitialSyncEndedTypes(),
2594 disabled_types).Empty());
2595 EXPECT_TRUE(disabled_types.Equals(
2596 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2564 } 2597 }
2565 2598
2566 // Test that the retry callback is invoked on configuration failure. 2599 // Test that the retry callback is invoked on configuration failure.
2567 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) { 2600 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) {
2568 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2601 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2569 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); 2602 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
2570 ModelSafeRoutingInfo new_routing_info; 2603 ModelSafeRoutingInfo new_routing_info;
2571 GetModelSafeRoutingInfo(&new_routing_info); 2604 GetModelSafeRoutingInfo(&new_routing_info);
2572 2605
2573 ConfigurationParams params; 2606 ConfigurationParams params;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2627 2660
2628 // Ensure only bookmarks and nigori lost their progress marker. Preferences 2661 // Ensure only bookmarks and nigori lost their progress marker. Preferences
2629 // should still have it. 2662 // should still have it.
2630 partial_types = 2663 partial_types =
2631 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); 2664 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All());
2632 EXPECT_TRUE(partial_types.Has(NIGORI)); 2665 EXPECT_TRUE(partial_types.Has(NIGORI));
2633 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); 2666 EXPECT_TRUE(partial_types.Has(BOOKMARKS));
2634 EXPECT_FALSE(partial_types.Has(PREFERENCES)); 2667 EXPECT_FALSE(partial_types.Has(PREFERENCES));
2635 } 2668 }
2636 2669
2670 // Test CleanipDisabledTypes properly purges all disabled types as specified
2671 // by the previous and current enabled params.
2672 TEST_F(SyncManagerTest, CleanupDisabledTypes) {
2673 ModelSafeRoutingInfo routing_info;
2674 GetModelSafeRoutingInfo(&routing_info);
2675 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
2676 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
2677
2678 // Set data for all types.
2679 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
2680 iter.Inc()) {
2681 SetProgressMarkerForType(iter.Get(), true);
2682 SetInitialSyncEndedForType(iter.Get(), true);
2683 }
2684
2685 // Verify only the enabled types remain after cleanup.
2686 sync_manager_.CleanupDisabledTypes(ModelTypeSet::All(), enabled_types);
2687 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
2688 EXPECT_TRUE(disabled_types.Equals(
2689 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2690
2691 // Disable some more types.
2692 disabled_types.Put(BOOKMARKS);
2693 disabled_types.Put(PREFERENCES);
2694 ModelTypeSet new_enabled_types =
2695 Difference(ModelTypeSet::All(), disabled_types);
2696
2697 // Verify only the non-disabled types remain after cleanup.
2698 sync_manager_.CleanupDisabledTypes(enabled_types, new_enabled_types);
2699 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
2700 EXPECT_TRUE(disabled_types.Equals(
2701 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2702 }
2703
2637 } // namespace 2704 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698