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