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

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

Issue 11474036: Remove initial_sync_ended bits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Avoid spurious changes Created 8 years 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "sync/protocol/extension_specifics.pb.h" 53 #include "sync/protocol/extension_specifics.pb.h"
54 #include "sync/protocol/password_specifics.pb.h" 54 #include "sync/protocol/password_specifics.pb.h"
55 #include "sync/protocol/preference_specifics.pb.h" 55 #include "sync/protocol/preference_specifics.pb.h"
56 #include "sync/protocol/proto_value_conversions.h" 56 #include "sync/protocol/proto_value_conversions.h"
57 #include "sync/protocol/sync.pb.h" 57 #include "sync/protocol/sync.pb.h"
58 #include "sync/sessions/sync_session.h" 58 #include "sync/sessions/sync_session.h"
59 #include "sync/syncable/directory.h" 59 #include "sync/syncable/directory.h"
60 #include "sync/syncable/entry.h" 60 #include "sync/syncable/entry.h"
61 #include "sync/syncable/mutable_entry.h" 61 #include "sync/syncable/mutable_entry.h"
62 #include "sync/syncable/nigori_util.h" 62 #include "sync/syncable/nigori_util.h"
63 #include "sync/syncable/read_transaction.h"
63 #include "sync/syncable/syncable_id.h" 64 #include "sync/syncable/syncable_id.h"
64 #include "sync/syncable/write_transaction.h" 65 #include "sync/syncable/write_transaction.h"
65 #include "sync/test/callback_counter.h" 66 #include "sync/test/callback_counter.h"
66 #include "sync/test/engine/fake_sync_scheduler.h" 67 #include "sync/test/engine/fake_sync_scheduler.h"
67 #include "sync/test/fake_encryptor.h" 68 #include "sync/test/fake_encryptor.h"
68 #include "sync/test/fake_extensions_activity_monitor.h" 69 #include "sync/test/fake_extensions_activity_monitor.h"
69 #include "sync/util/cryptographer.h" 70 #include "sync/util/cryptographer.h"
70 #include "sync/util/extensions_activity_monitor.h" 71 #include "sync/util/extensions_activity_monitor.h"
71 #include "sync/util/test_unrecoverable_error_handler.h" 72 #include "sync/util/test_unrecoverable_error_handler.h"
72 #include "sync/util/time.h" 73 #include "sync/util/time.h"
73 #include "testing/gmock/include/gmock/gmock.h" 74 #include "testing/gmock/include/gmock/gmock.h"
74 #include "testing/gtest/include/gtest/gtest.h" 75 #include "testing/gtest/include/gtest/gtest.h"
75 76
76 using base::ExpectDictStringValue; 77 using base::ExpectDictStringValue;
77 using testing::_; 78 using testing::_;
78 using testing::DoAll; 79 using testing::DoAll;
79 using testing::InSequence; 80 using testing::InSequence;
80 using testing::Return; 81 using testing::Return;
81 using testing::SaveArg; 82 using testing::SaveArg;
82 using testing::StrictMock; 83 using testing::StrictMock;
83 84
84 namespace syncer { 85 namespace syncer {
85 86
86 using sessions::SyncSessionSnapshot; 87 using sessions::SyncSessionSnapshot;
88 using syncable::GET_BY_HANDLE;
87 using syncable::IS_DEL; 89 using syncable::IS_DEL;
88 using syncable::IS_UNSYNCED; 90 using syncable::IS_UNSYNCED;
89 using syncable::kEncryptedString;
90 using syncable::NON_UNIQUE_NAME; 91 using syncable::NON_UNIQUE_NAME;
91 using syncable::SPECIFICS; 92 using syncable::SPECIFICS;
93 using syncable::kEncryptedString;
92 94
93 namespace { 95 namespace {
94 96
95 const char kTestChromeVersion[] = "test chrome version"; 97 const char kTestChromeVersion[] = "test chrome version";
96 98
97 void ExpectInt64Value(int64 expected_value, 99 void ExpectInt64Value(int64 expected_value,
98 const DictionaryValue& value, const std::string& key) { 100 const DictionaryValue& value, const std::string& key) {
99 std::string int64_str; 101 std::string int64_str;
100 EXPECT_TRUE(value.GetString(key, &int64_str)); 102 EXPECT_TRUE(value.GetString(key, &int64_str));
101 int64 val = 0; 103 int64 val = 0;
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 int64 model_version, 883 int64 model_version,
882 const BaseTransaction* trans, 884 const BaseTransaction* trans,
883 const ImmutableChangeRecordList& changes) OVERRIDE {} 885 const ImmutableChangeRecordList& changes) OVERRIDE {}
884 886
885 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {} 887 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {}
886 888
887 // Helper methods. 889 // Helper methods.
888 bool SetUpEncryption(NigoriStatus nigori_status, 890 bool SetUpEncryption(NigoriStatus nigori_status,
889 EncryptionStatus encryption_status) { 891 EncryptionStatus encryption_status) {
890 UserShare* share = sync_manager_.GetUserShare(); 892 UserShare* share = sync_manager_.GetUserShare();
891 share->directory->set_initial_sync_ended_for_type(NIGORI, true);
892 893
893 // We need to create the nigori node as if it were an applied server update. 894 // We need to create the nigori node as if it were an applied server update.
894 int64 nigori_id = GetIdForDataType(NIGORI); 895 int64 nigori_id = GetIdForDataType(NIGORI);
895 if (nigori_id == kInvalidId) 896 if (nigori_id == kInvalidId)
896 return false; 897 return false;
897 898
898 // Set the nigori cryptographer information. 899 // Set the nigori cryptographer information.
899 if (encryption_status == FULL_ENCRYPTION) 900 if (encryption_status == FULL_ENCRYPTION)
900 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 901 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
901 902
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 sync_pb::DataTypeProgressMarker marker; 1006 sync_pb::DataTypeProgressMarker marker;
1006 marker.set_token("token"); 1007 marker.set_token("token");
1007 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); 1008 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
1008 sync_manager_.directory()->SetDownloadProgress(type, marker); 1009 sync_manager_.directory()->SetDownloadProgress(type, marker);
1009 } else { 1010 } else {
1010 sync_pb::DataTypeProgressMarker marker; 1011 sync_pb::DataTypeProgressMarker marker;
1011 sync_manager_.directory()->SetDownloadProgress(type, marker); 1012 sync_manager_.directory()->SetDownloadProgress(type, marker);
1012 } 1013 }
1013 } 1014 }
1014 1015
1015 void SetInitialSyncEndedForType(ModelType type, bool value) {
1016 sync_manager_.directory()->set_initial_sync_ended_for_type(type, value);
1017 }
1018
1019 InternalComponentsFactory::Switches GetSwitches() const { 1016 InternalComponentsFactory::Switches GetSwitches() const {
1020 return switches_; 1017 return switches_;
1021 } 1018 }
1022 1019
1023 private: 1020 private:
1024 // Needed by |sync_manager_|. 1021 // Needed by |sync_manager_|.
1025 MessageLoop message_loop_; 1022 MessageLoop message_loop_;
1026 // Needed by |sync_manager_|. 1023 // Needed by |sync_manager_|.
1027 base::ScopedTempDir temp_dir_; 1024 base::ScopedTempDir temp_dir_;
1028 // Sync Id's for the roots of the enabled datatypes. 1025 // Sync Id's for the roots of the enabled datatypes.
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 2845
2849 ConfigurationParams params; 2846 ConfigurationParams params;
2850 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); 2847 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE));
2851 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). 2848 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)).
2852 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2849 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2853 2850
2854 // Set data for all types. 2851 // Set data for all types.
2855 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 2852 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
2856 iter.Inc()) { 2853 iter.Inc()) {
2857 SetProgressMarkerForType(iter.Get(), true); 2854 SetProgressMarkerForType(iter.Get(), true);
2858 SetInitialSyncEndedForType(iter.Get(), true);
2859 } 2855 }
2860 2856
2861 CallbackCounter ready_task_counter, retry_task_counter; 2857 CallbackCounter ready_task_counter, retry_task_counter;
2862 sync_manager_.ConfigureSyncer( 2858 sync_manager_.ConfigureSyncer(
2863 reason, 2859 reason,
2864 types_to_download, 2860 types_to_download,
2865 new_routing_info, 2861 new_routing_info,
2866 base::Bind(&CallbackCounter::Callback, 2862 base::Bind(&CallbackCounter::Callback,
2867 base::Unretained(&ready_task_counter)), 2863 base::Unretained(&ready_task_counter)),
2868 base::Bind(&CallbackCounter::Callback, 2864 base::Bind(&CallbackCounter::Callback,
2869 base::Unretained(&retry_task_counter))); 2865 base::Unretained(&retry_task_counter)));
2870 EXPECT_EQ(0, ready_task_counter.times_called()); 2866 EXPECT_EQ(0, ready_task_counter.times_called());
2871 EXPECT_EQ(0, retry_task_counter.times_called()); 2867 EXPECT_EQ(0, retry_task_counter.times_called());
2872 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2868 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2873 params.source); 2869 params.source);
2874 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2870 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2875 EXPECT_EQ(new_routing_info, params.routing_info); 2871 EXPECT_EQ(new_routing_info, params.routing_info);
2876 2872
2877 // Verify all the disabled types were purged.
Nicolas Zea 2012/12/10 22:50:38 Doesn't this still apply?
rlarocque 2012/12/11 01:44:48 Yes it does. Fixed.
2878 EXPECT_TRUE(sync_manager_.InitialSyncEndedTypes().Equals( 2873 EXPECT_TRUE(sync_manager_.InitialSyncEndedTypes().Equals(
2879 enabled_types)); 2874 enabled_types));
2880 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken( 2875 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken(
2881 ModelTypeSet::All()).Equals(disabled_types)); 2876 ModelTypeSet::All()).Equals(disabled_types));
2882 } 2877 }
2883 2878
2884 // Test that on a reconfiguration (configuration where the session context 2879 // Test that on a reconfiguration (configuration where the session context
2885 // already has routing info), only those recently disabled types are purged. 2880 // already has routing info), only those recently disabled types are purged.
2886 TEST_F(SyncManagerTestWithMockScheduler, ReConfiguration) { 2881 TEST_F(SyncManagerTestWithMockScheduler, ReConfiguration) {
2887 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2882 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
(...skipping 11 matching lines...) Expand all
2899 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); 2894 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE));
2900 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). 2895 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)).
2901 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2896 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2902 2897
2903 // Set data for all types except those recently disabled (so we can verify 2898 // Set data for all types except those recently disabled (so we can verify
2904 // only those recently disabled are purged) . 2899 // only those recently disabled are purged) .
2905 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 2900 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
2906 iter.Inc()) { 2901 iter.Inc()) {
2907 if (!disabled_types.Has(iter.Get())) { 2902 if (!disabled_types.Has(iter.Get())) {
2908 SetProgressMarkerForType(iter.Get(), true); 2903 SetProgressMarkerForType(iter.Get(), true);
2909 SetInitialSyncEndedForType(iter.Get(), true);
2910 } else { 2904 } else {
2911 SetProgressMarkerForType(iter.Get(), false); 2905 SetProgressMarkerForType(iter.Get(), false);
2912 SetInitialSyncEndedForType(iter.Get(), false);
2913 } 2906 }
2914 } 2907 }
2915 2908
2916 // Set the context to have the old routing info. 2909 // Set the context to have the old routing info.
2917 session_context()->set_routing_info(old_routing_info); 2910 session_context()->set_routing_info(old_routing_info);
2918 2911
2919 CallbackCounter ready_task_counter, retry_task_counter; 2912 CallbackCounter ready_task_counter, retry_task_counter;
2920 sync_manager_.ConfigureSyncer( 2913 sync_manager_.ConfigureSyncer(
2921 reason, 2914 reason,
2922 types_to_download, 2915 types_to_download,
2923 new_routing_info, 2916 new_routing_info,
2924 base::Bind(&CallbackCounter::Callback, 2917 base::Bind(&CallbackCounter::Callback,
2925 base::Unretained(&ready_task_counter)), 2918 base::Unretained(&ready_task_counter)),
2926 base::Bind(&CallbackCounter::Callback, 2919 base::Bind(&CallbackCounter::Callback,
2927 base::Unretained(&retry_task_counter))); 2920 base::Unretained(&retry_task_counter)));
2928 EXPECT_EQ(0, ready_task_counter.times_called()); 2921 EXPECT_EQ(0, ready_task_counter.times_called());
2929 EXPECT_EQ(0, retry_task_counter.times_called()); 2922 EXPECT_EQ(0, retry_task_counter.times_called());
2930 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2923 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2931 params.source); 2924 params.source);
2932 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2925 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2933 EXPECT_EQ(new_routing_info, params.routing_info); 2926 EXPECT_EQ(new_routing_info, params.routing_info);
2934 2927
2935 // Verify only the recently disabled types were purged. 2928 // Verify only the recently disabled types were purged.
2936 EXPECT_TRUE(sync_manager_.InitialSyncEndedTypes().Equals(
Nicolas Zea 2012/12/10 22:50:38 I guess we don't actually create roots for these t
rlarocque 2012/12/11 01:44:48 More or less, yes. The test harness creates root
2937 Difference(ModelTypeSet::All(), disabled_types)));
2938 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken( 2929 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken(
2939 ModelTypeSet::All()).Equals(disabled_types)); 2930 ModelTypeSet::All()).Equals(disabled_types));
2940 } 2931 }
2941 2932
2942 // Test that the retry callback is invoked on configuration failure. 2933 // Test that the retry callback is invoked on configuration failure.
2943 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) { 2934 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) {
2944 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2935 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2945 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); 2936 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
2946 ModelSafeRoutingInfo new_routing_info; 2937 ModelSafeRoutingInfo new_routing_info;
2947 GetModelSafeRoutingInfo(&new_routing_info); 2938 GetModelSafeRoutingInfo(&new_routing_info);
(...skipping 13 matching lines...) Expand all
2961 base::Bind(&CallbackCounter::Callback, 2952 base::Bind(&CallbackCounter::Callback,
2962 base::Unretained(&retry_task_counter))); 2953 base::Unretained(&retry_task_counter)));
2963 EXPECT_EQ(0, ready_task_counter.times_called()); 2954 EXPECT_EQ(0, ready_task_counter.times_called());
2964 EXPECT_EQ(1, retry_task_counter.times_called()); 2955 EXPECT_EQ(1, retry_task_counter.times_called());
2965 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2956 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2966 params.source); 2957 params.source);
2967 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2958 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2968 EXPECT_EQ(new_routing_info, params.routing_info); 2959 EXPECT_EQ(new_routing_info, params.routing_info);
2969 } 2960 }
2970 2961
2971 // Test that PurgePartiallySyncedTypes purges only those types that don't 2962 // Test that PurgePartiallySyncedTypes purges only those types that have not
2972 // have empty progress marker and don't have initial sync ended set. 2963 // fully completed their initial download and apply.
2973 TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) { 2964 TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) {
2965 ModelSafeRoutingInfo routing_info;
2966 GetModelSafeRoutingInfo(&routing_info);
2967 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
2968
2974 UserShare* share = sync_manager_.GetUserShare(); 2969 UserShare* share = sync_manager_.GetUserShare();
2975 2970
2976 // Set Nigori and Bookmarks to be partial types. 2971 // The test harness automatically initializes all types in the routing info.
2977 sync_pb::DataTypeProgressMarker nigori_marker; 2972 // Check that autofill is not among them.
2978 nigori_marker.set_data_type_id( 2973 ASSERT_FALSE(enabled_types.Has(AUTOFILL));
2979 GetSpecificsFieldNumberFromModelType(NIGORI));
2980 nigori_marker.set_token("token");
2981 sync_pb::DataTypeProgressMarker bookmark_marker;
2982 bookmark_marker.set_data_type_id(
2983 GetSpecificsFieldNumberFromModelType(BOOKMARKS));
2984 bookmark_marker.set_token("token");
2985 share->directory->SetDownloadProgress(NIGORI, nigori_marker);
2986 share->directory->SetDownloadProgress(BOOKMARKS, bookmark_marker);
2987 2974
2988 // Set Preferences to be a full type. 2975 // Further ensure that the test harness did not create its root node.
2989 sync_pb::DataTypeProgressMarker pref_marker; 2976 {
2990 pref_marker.set_data_type_id( 2977 syncable::ReadTransaction trans(FROM_HERE, share->directory.get());
2978 syncable::Entry autofill_root_node(&trans, syncable::GET_BY_SERVER_TAG,
2979 ModelTypeToRootTag(AUTOFILL));
2980 ASSERT_FALSE(autofill_root_node.good());
2981 }
2982
2983 // One more redundant check.
2984 ASSERT_FALSE(sync_manager_.InitialSyncEndedTypes().Has(AUTOFILL));
2985
2986 // Give autofill a progress marker.
2987 sync_pb::DataTypeProgressMarker autofill_marker;
2988 autofill_marker.set_data_type_id(
2989 GetSpecificsFieldNumberFromModelType(AUTOFILL));
2990 autofill_marker.set_token("token");
2991 share->directory->SetDownloadProgress(AUTOFILL, autofill_marker);
2992
2993 int autofill_meta;
2994 {
2995 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST,
2996 share->directory.get());
2997 // Also add a pending autofill update from the server.
Nicolas Zea 2012/12/10 22:50:38 Can you use the test entry factory for this?
rlarocque 2012/12/11 01:44:48 That would be the first use of TestEntryFactory fr
2998 sync_pb::EntitySpecifics specifics;
2999 AddDefaultFieldValue(AUTOFILL, &specifics);
3000 syncable::Id node_id = syncable::Id::CreateFromServerId("xyz");
3001 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
3002 node_id);
3003 EXPECT_TRUE(entry.good());
3004 // Make it look like sort of like a pending creation from the server.
3005 // The SERVER_PARENT_ID and UNIQUE_CLIENT_TAG aren't quite right, but
3006 // it's good enough for our purposes.
3007 entry.Put(syncable::SERVER_VERSION, 1);
3008 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
3009 entry.Put(syncable::SERVER_IS_DIR, false);
3010 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId());
3011 entry.Put(syncable::SERVER_SPECIFICS, specifics);
3012 entry.Put(syncable::NON_UNIQUE_NAME, "xyz");
3013
3014 autofill_meta = entry.Get(syncable::META_HANDLE);
3015 }
3016
3017 // Preferences is an enabled type. Check that the harness initialized it.
3018 ASSERT_TRUE(enabled_types.Has(PREFERENCES));
3019 ASSERT_TRUE(sync_manager_.InitialSyncEndedTypes().Has(PREFERENCES));
3020
3021 // Give preferencse a progress marker.
3022 sync_pb::DataTypeProgressMarker prefs_marker;
3023 prefs_marker.set_data_type_id(
2991 GetSpecificsFieldNumberFromModelType(PREFERENCES)); 3024 GetSpecificsFieldNumberFromModelType(PREFERENCES));
2992 pref_marker.set_token("token"); 3025 prefs_marker.set_token("token");
2993 share->directory->SetDownloadProgress(PREFERENCES, pref_marker); 3026 share->directory->SetDownloadProgress(PREFERENCES, prefs_marker);
2994 share->directory->set_initial_sync_ended_for_type(PREFERENCES, true);
2995 3027
2996 ModelTypeSet partial_types = 3028 // Add a fully synced preferences node under the root.
2997 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); 3029 std::string pref_client_tag = "prefABC";
2998 EXPECT_FALSE(partial_types.Has(NIGORI)); 3030 std::string pref_hashed_tag = "hashXYZ";
2999 EXPECT_FALSE(partial_types.Has(BOOKMARKS)); 3031 sync_pb::EntitySpecifics pref_specifics;
3000 EXPECT_FALSE(partial_types.Has(PREFERENCES)); 3032 AddDefaultFieldValue(PREFERENCES, &pref_specifics);
3033 int pref_meta = MakeServerNode(
3034 share, PREFERENCES, pref_client_tag, pref_hashed_tag, pref_specifics);
3001 3035
3036 // And now, the purge.
3002 EXPECT_TRUE(sync_manager_.PurgePartiallySyncedTypes()); 3037 EXPECT_TRUE(sync_manager_.PurgePartiallySyncedTypes());
3003 3038
3004 // Ensure only bookmarks and nigori lost their progress marker. Preferences 3039 // Ensure that autofill lost its progress marker, but preferences did not.
3005 // should still have it. 3040 ModelTypeSet empty_tokens =
3006 partial_types =
3007 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); 3041 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All());
3008 EXPECT_TRUE(partial_types.Has(NIGORI)); 3042 EXPECT_TRUE(empty_tokens.Has(AUTOFILL));
3009 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); 3043 EXPECT_FALSE(empty_tokens.Has(PREFERENCES));
3010 EXPECT_FALSE(partial_types.Has(PREFERENCES)); 3044
3045 // Ensure that autofill lots its node, but preferences did not.
3046 {
3047 syncable::ReadTransaction trans(FROM_HERE, share->directory.get());
3048 syncable::Entry autofill_node(&trans, GET_BY_HANDLE, autofill_meta);
3049 syncable::Entry pref_node(&trans, GET_BY_HANDLE, pref_meta);
3050 EXPECT_FALSE(autofill_node.good());
3051 EXPECT_TRUE(pref_node.good());
3052 }
3011 } 3053 }
3012 3054
3013 // Test CleanupDisabledTypes properly purges all disabled types as specified 3055 // Test CleanupDisabledTypes properly purges all disabled types as specified
3014 // by the previous and current enabled params. Enabled partial types should not 3056 // by the previous and current enabled params. Enabled partial types should not
Nicolas Zea 2012/12/10 22:50:38 nit: Last sentence no longer applies.
rlarocque 2012/12/11 01:44:48 Done.
3015 // be purged. 3057 // be purged.
3016 // Fails on Windows: crbug.com/139726 3058 // Fails on Windows: crbug.com/139726
3017 #if defined(OS_WIN) 3059 #if defined(OS_WIN)
3018 #define MAYBE_PurgeDisabledTypes DISABLED_PurgeDisabledTypes 3060 #define MAYBE_PurgeDisabledTypes DISABLED_PurgeDisabledTypes
3019 #else 3061 #else
3020 #define MAYBE_PurgeDisabledTypes PurgeDisabledTypes 3062 #define MAYBE_PurgeDisabledTypes PurgeDisabledTypes
3021 #endif 3063 #endif
3022 TEST_F(SyncManagerTest, MAYBE_PurgeDisabledTypes) { 3064 TEST_F(SyncManagerTest, MAYBE_PurgeDisabledTypes) {
3023 ModelSafeRoutingInfo routing_info; 3065 ModelSafeRoutingInfo routing_info;
3024 GetModelSafeRoutingInfo(&routing_info); 3066 GetModelSafeRoutingInfo(&routing_info);
3025 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 3067 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
3026 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); 3068 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
3027 ModelTypeSet partial_enabled_types(PASSWORDS);
3028 3069
3029 // Set data for all non-partial types. 3070 // The harness should have initialized the enabled_types for us.
3071 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3072
3073 // Set progress markers for all types.
3030 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 3074 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
3031 iter.Inc()) { 3075 iter.Inc()) {
3032 SetProgressMarkerForType(iter.Get(), true); 3076 SetProgressMarkerForType(iter.Get(), true);
3033 if (!partial_enabled_types.Has(iter.Get()))
3034 SetInitialSyncEndedForType(iter.Get(), true);
3035 } 3077 }
3036 3078
3037 // Verify all the enabled types remain after cleanup, and all the disabled 3079 // Verify all the enabled types remain after cleanup, and all the disabled
3038 // types were purged. 3080 // types were purged.
3039 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), enabled_types); 3081 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), enabled_types);
3040 EXPECT_TRUE(enabled_types.Equals( 3082 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3041 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
3042 EXPECT_TRUE(disabled_types.Equals( 3083 EXPECT_TRUE(disabled_types.Equals(
3043 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3084 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3044 3085
3045 // Disable some more types. 3086 // Disable some more types.
3046 disabled_types.Put(BOOKMARKS); 3087 disabled_types.Put(BOOKMARKS);
3047 disabled_types.Put(PREFERENCES); 3088 disabled_types.Put(PREFERENCES);
3048 ModelTypeSet new_enabled_types = 3089 ModelTypeSet new_enabled_types =
3049 Difference(ModelTypeSet::All(), disabled_types); 3090 Difference(ModelTypeSet::All(), disabled_types);
3050 3091
3051 // Verify only the non-disabled types remain after cleanup. 3092 // Verify only the non-disabled types remain after cleanup.
3052 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 3093 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
3053 EXPECT_TRUE(new_enabled_types.Equals( 3094 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3054 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
3055 EXPECT_TRUE(disabled_types.Equals( 3095 EXPECT_TRUE(disabled_types.Equals(
3056 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3096 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3057 } 3097 }
3058 3098
3059 } // namespace 3099 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698