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

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

Issue 11958029: [Sync] Add support for proxy types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 7 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 } 2797 }
2798 2798
2799 private: 2799 private:
2800 MockSyncScheduler* scheduler_; 2800 MockSyncScheduler* scheduler_;
2801 sessions::SyncSessionContext* session_context_; 2801 sessions::SyncSessionContext* session_context_;
2802 }; 2802 };
2803 2803
2804 // Test that the configuration params are properly created and sent to 2804 // Test that the configuration params are properly created and sent to
2805 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes 2805 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes
2806 // should be purged. 2806 // should be purged.
2807 // Fails on Windows: crbug.com/139726 2807 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) {
2808 #if defined(OS_WIN)
2809 #define MAYBE_BasicConfiguration DISABLED_BasicConfiguration
2810 #else
2811 #define MAYBE_BasicConfiguration BasicConfiguration
2812 #endif
2813 TEST_F(SyncManagerTestWithMockScheduler, MAYBE_BasicConfiguration) {
2814 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2808 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2815 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); 2809 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
2816 ModelSafeRoutingInfo new_routing_info; 2810 ModelSafeRoutingInfo new_routing_info;
2817 GetModelSafeRoutingInfo(&new_routing_info); 2811 GetModelSafeRoutingInfo(&new_routing_info);
2818 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); 2812 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info);
2819 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); 2813 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
2820 2814
2821 ConfigurationParams params; 2815 ConfigurationParams params;
2822 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); 2816 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE));
2823 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). 2817 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)).
2824 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2818 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2825 2819
2826 // Set data for all types. 2820 // Set data for all types.
2827 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 2821 ModelTypeSet real_types = ModelTypeSet::All();
2822 real_types.RemoveAll(VirtualTypes());
2823 for (ModelTypeSet::Iterator iter = real_types.First(); iter.Good();
2828 iter.Inc()) { 2824 iter.Inc()) {
2829 SetProgressMarkerForType(iter.Get(), true); 2825 SetProgressMarkerForType(iter.Get(), true);
2830 } 2826 }
2831 2827
2832 CallbackCounter ready_task_counter, retry_task_counter; 2828 CallbackCounter ready_task_counter, retry_task_counter;
2833 sync_manager_.ConfigureSyncer( 2829 sync_manager_.ConfigureSyncer(
2834 reason, 2830 reason,
2835 types_to_download, 2831 types_to_download,
2836 ModelTypeSet(), 2832 ModelTypeSet(),
2837 new_routing_info, 2833 new_routing_info,
(...skipping 29 matching lines...) Expand all
2867 new_routing_info.erase(SESSIONS); 2863 new_routing_info.erase(SESSIONS);
2868 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); 2864 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info);
2869 2865
2870 ConfigurationParams params; 2866 ConfigurationParams params;
2871 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); 2867 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE));
2872 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). 2868 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)).
2873 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2869 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2874 2870
2875 // Set data for all types except those recently disabled (so we can verify 2871 // Set data for all types except those recently disabled (so we can verify
2876 // only those recently disabled are purged) . 2872 // only those recently disabled are purged) .
2877 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 2873 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
tim (not reviewing) 2013/02/05 02:41:58 Random thought, another option to this and to crea
Nicolas Zea 2013/02/07 01:18:48 I went ahea and added a ProtocolTypes() method in
2878 iter.Inc()) { 2874 iter.Inc()) {
2875 if (VirtualTypes().Has(iter.Get()))
2876 continue;
2879 if (!disabled_types.Has(iter.Get())) { 2877 if (!disabled_types.Has(iter.Get())) {
2880 SetProgressMarkerForType(iter.Get(), true); 2878 SetProgressMarkerForType(iter.Get(), true);
2881 } else { 2879 } else {
2882 SetProgressMarkerForType(iter.Get(), false); 2880 SetProgressMarkerForType(iter.Get(), false);
2883 } 2881 }
2884 } 2882 }
2885 2883
2886 // Set the context to have the old routing info. 2884 // Set the context to have the old routing info.
2887 session_context()->set_routing_info(old_routing_info); 2885 session_context()->set_routing_info(old_routing_info);
2888 2886
2889 CallbackCounter ready_task_counter, retry_task_counter; 2887 CallbackCounter ready_task_counter, retry_task_counter;
2890 sync_manager_.ConfigureSyncer( 2888 sync_manager_.ConfigureSyncer(
2891 reason, 2889 reason,
2892 types_to_download, 2890 types_to_download,
2893 ModelTypeSet(), 2891 ModelTypeSet(),
2894 new_routing_info, 2892 new_routing_info,
2895 base::Bind(&CallbackCounter::Callback, 2893 base::Bind(&CallbackCounter::Callback,
2896 base::Unretained(&ready_task_counter)), 2894 base::Unretained(&ready_task_counter)),
2897 base::Bind(&CallbackCounter::Callback, 2895 base::Bind(&CallbackCounter::Callback,
2898 base::Unretained(&retry_task_counter))); 2896 base::Unretained(&retry_task_counter)));
2899 EXPECT_EQ(0, ready_task_counter.times_called()); 2897 EXPECT_EQ(0, ready_task_counter.times_called());
2900 EXPECT_EQ(0, retry_task_counter.times_called()); 2898 EXPECT_EQ(0, retry_task_counter.times_called());
2901 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2899 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2902 params.source); 2900 params.source);
2903 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2901 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2904 EXPECT_EQ(new_routing_info, params.routing_info); 2902 EXPECT_EQ(new_routing_info, params.routing_info);
2905 2903
2906 // Verify only the recently disabled types were purged. 2904 // Verify only the recently disabled types were purged.
2907 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken( 2905 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken(
2908 ModelTypeSet::All()).Equals(disabled_types)); 2906 Difference(ModelTypeSet::All(), VirtualTypes())).Equals(disabled_types));
2909 } 2907 }
2910 2908
2911 // Test that the retry callback is invoked on configuration failure. 2909 // Test that the retry callback is invoked on configuration failure.
2912 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) { 2910 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) {
2913 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2911 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2914 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); 2912 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
2915 ModelSafeRoutingInfo new_routing_info; 2913 ModelSafeRoutingInfo new_routing_info;
2916 GetModelSafeRoutingInfo(&new_routing_info); 2914 GetModelSafeRoutingInfo(&new_routing_info);
2917 2915
2918 ConfigurationParams params; 2916 ConfigurationParams params;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 syncable::ReadTransaction trans(FROM_HERE, share->directory.get()); 3004 syncable::ReadTransaction trans(FROM_HERE, share->directory.get());
3007 syncable::Entry autofill_node(&trans, GET_BY_HANDLE, autofill_meta); 3005 syncable::Entry autofill_node(&trans, GET_BY_HANDLE, autofill_meta);
3008 syncable::Entry pref_node(&trans, GET_BY_HANDLE, pref_meta); 3006 syncable::Entry pref_node(&trans, GET_BY_HANDLE, pref_meta);
3009 EXPECT_FALSE(autofill_node.good()); 3007 EXPECT_FALSE(autofill_node.good());
3010 EXPECT_TRUE(pref_node.good()); 3008 EXPECT_TRUE(pref_node.good());
3011 } 3009 }
3012 } 3010 }
3013 3011
3014 // Test CleanupDisabledTypes properly purges all disabled types as specified 3012 // Test CleanupDisabledTypes properly purges all disabled types as specified
3015 // by the previous and current enabled params. 3013 // by the previous and current enabled params.
3016 // Fails on Windows: crbug.com/139726 3014 TEST_F(SyncManagerTest, PurgeDisabledTypes) {
3017 #if defined(OS_WIN)
3018 #define MAYBE_PurgeDisabledTypes DISABLED_PurgeDisabledTypes
3019 #else
3020 #define MAYBE_PurgeDisabledTypes PurgeDisabledTypes
3021 #endif
3022 TEST_F(SyncManagerTest, MAYBE_PurgeDisabledTypes) {
3023 ModelSafeRoutingInfo routing_info; 3015 ModelSafeRoutingInfo routing_info;
3024 GetModelSafeRoutingInfo(&routing_info); 3016 GetModelSafeRoutingInfo(&routing_info);
3025 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 3017 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
3026 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); 3018 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
3027 3019
3028 // The harness should have initialized the enabled_types for us. 3020 // The harness should have initialized the enabled_types for us.
3029 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); 3021 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3030 3022
3031 // Set progress markers for all types. 3023 // Set progress markers for all types.
3032 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 3024 ModelTypeSet real_types = ModelTypeSet::All();
3025 real_types.RemoveAll(VirtualTypes());
3026 for (ModelTypeSet::Iterator iter = real_types.First(); iter.Good();
3033 iter.Inc()) { 3027 iter.Inc()) {
3034 SetProgressMarkerForType(iter.Get(), true); 3028 SetProgressMarkerForType(iter.Get(), true);
3035 } 3029 }
3036 3030
3037 // Verify all the enabled types remain after cleanup, and all the disabled 3031 // Verify all the enabled types remain after cleanup, and all the disabled
3038 // types were purged. 3032 // types were purged.
3039 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), enabled_types, 3033 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), enabled_types,
3040 ModelTypeSet()); 3034 ModelTypeSet());
3041 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); 3035 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3042 EXPECT_TRUE(disabled_types.Equals( 3036 EXPECT_TRUE(disabled_types.Equals(
3043 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3037 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3044 3038
3045 // Disable some more types. 3039 // Disable some more types.
3046 disabled_types.Put(BOOKMARKS); 3040 disabled_types.Put(BOOKMARKS);
3047 disabled_types.Put(PREFERENCES); 3041 disabled_types.Put(PREFERENCES);
3048 ModelTypeSet new_enabled_types = 3042 ModelTypeSet new_enabled_types =
3049 Difference(ModelTypeSet::All(), disabled_types); 3043 Difference(ModelTypeSet::All(), disabled_types);
3050 3044
3051 // Verify only the non-disabled types remain after cleanup. 3045 // Verify only the non-disabled types remain after cleanup.
3052 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types, 3046 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types,
3053 ModelTypeSet()); 3047 ModelTypeSet());
3054 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); 3048 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3055 EXPECT_TRUE(disabled_types.Equals( 3049 EXPECT_TRUE(disabled_types.Equals(
3056 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3050 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3057 } 3051 }
3058 3052
3059 } // namespace 3053 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698