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

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: Another rebase 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
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/test_entry_factory.cc » ('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) 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 14 matching lines...) Expand all
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "sync/engine/sync_scheduler.h" 26 #include "sync/engine/sync_scheduler.h"
27 #include "sync/internal_api/public/base/model_type_test_util.h" 27 #include "sync/internal_api/public/base/model_type_test_util.h"
28 #include "sync/internal_api/public/change_record.h" 28 #include "sync/internal_api/public/change_record.h"
29 #include "sync/internal_api/public/engine/model_safe_worker.h" 29 #include "sync/internal_api/public/engine/model_safe_worker.h"
30 #include "sync/internal_api/public/engine/polling_constants.h" 30 #include "sync/internal_api/public/engine/polling_constants.h"
31 #include "sync/internal_api/public/http_post_provider_factory.h" 31 #include "sync/internal_api/public/http_post_provider_factory.h"
32 #include "sync/internal_api/public/http_post_provider_interface.h" 32 #include "sync/internal_api/public/http_post_provider_interface.h"
33 #include "sync/internal_api/public/read_node.h" 33 #include "sync/internal_api/public/read_node.h"
34 #include "sync/internal_api/public/read_transaction.h" 34 #include "sync/internal_api/public/read_transaction.h"
35 #include "sync/internal_api/public/test/test_entry_factory.h"
35 #include "sync/internal_api/public/test/test_internal_components_factory.h" 36 #include "sync/internal_api/public/test/test_internal_components_factory.h"
36 #include "sync/internal_api/public/test/test_user_share.h" 37 #include "sync/internal_api/public/test/test_user_share.h"
37 #include "sync/internal_api/public/write_node.h" 38 #include "sync/internal_api/public/write_node.h"
38 #include "sync/internal_api/public/write_transaction.h" 39 #include "sync/internal_api/public/write_transaction.h"
39 #include "sync/internal_api/sync_encryption_handler_impl.h" 40 #include "sync/internal_api/sync_encryption_handler_impl.h"
40 #include "sync/internal_api/sync_manager_impl.h" 41 #include "sync/internal_api/sync_manager_impl.h"
41 #include "sync/internal_api/syncapi_internal.h" 42 #include "sync/internal_api/syncapi_internal.h"
42 #include "sync/js/js_arg_list.h" 43 #include "sync/js/js_arg_list.h"
43 #include "sync/js/js_backend.h" 44 #include "sync/js/js_backend.h"
44 #include "sync/js/js_event_handler.h" 45 #include "sync/js/js_event_handler.h"
45 #include "sync/js/js_reply_handler.h" 46 #include "sync/js/js_reply_handler.h"
46 #include "sync/js/js_test_util.h" 47 #include "sync/js/js_test_util.h"
47 #include "sync/notifier/fake_invalidation_handler.h" 48 #include "sync/notifier/fake_invalidation_handler.h"
48 #include "sync/notifier/fake_invalidator.h" 49 #include "sync/notifier/fake_invalidator.h"
49 #include "sync/notifier/invalidation_handler.h" 50 #include "sync/notifier/invalidation_handler.h"
50 #include "sync/notifier/invalidator.h" 51 #include "sync/notifier/invalidator.h"
51 #include "sync/protocol/bookmark_specifics.pb.h" 52 #include "sync/protocol/bookmark_specifics.pb.h"
52 #include "sync/protocol/encryption.pb.h" 53 #include "sync/protocol/encryption.pb.h"
53 #include "sync/protocol/extension_specifics.pb.h" 54 #include "sync/protocol/extension_specifics.pb.h"
54 #include "sync/protocol/password_specifics.pb.h" 55 #include "sync/protocol/password_specifics.pb.h"
55 #include "sync/protocol/preference_specifics.pb.h" 56 #include "sync/protocol/preference_specifics.pb.h"
56 #include "sync/protocol/proto_value_conversions.h" 57 #include "sync/protocol/proto_value_conversions.h"
57 #include "sync/protocol/sync.pb.h" 58 #include "sync/protocol/sync.pb.h"
58 #include "sync/sessions/sync_session.h" 59 #include "sync/sessions/sync_session.h"
59 #include "sync/syncable/directory.h" 60 #include "sync/syncable/directory.h"
60 #include "sync/syncable/entry.h" 61 #include "sync/syncable/entry.h"
61 #include "sync/syncable/mutable_entry.h" 62 #include "sync/syncable/mutable_entry.h"
62 #include "sync/syncable/nigori_util.h" 63 #include "sync/syncable/nigori_util.h"
64 #include "sync/syncable/read_transaction.h"
63 #include "sync/syncable/syncable_id.h" 65 #include "sync/syncable/syncable_id.h"
64 #include "sync/syncable/write_transaction.h" 66 #include "sync/syncable/write_transaction.h"
65 #include "sync/test/callback_counter.h" 67 #include "sync/test/callback_counter.h"
66 #include "sync/test/engine/fake_sync_scheduler.h" 68 #include "sync/test/engine/fake_sync_scheduler.h"
67 #include "sync/test/fake_encryptor.h" 69 #include "sync/test/fake_encryptor.h"
68 #include "sync/test/fake_extensions_activity_monitor.h" 70 #include "sync/test/fake_extensions_activity_monitor.h"
69 #include "sync/util/cryptographer.h" 71 #include "sync/util/cryptographer.h"
70 #include "sync/util/extensions_activity_monitor.h" 72 #include "sync/util/extensions_activity_monitor.h"
71 #include "sync/util/test_unrecoverable_error_handler.h" 73 #include "sync/util/test_unrecoverable_error_handler.h"
72 #include "sync/util/time.h" 74 #include "sync/util/time.h"
73 #include "testing/gmock/include/gmock/gmock.h" 75 #include "testing/gmock/include/gmock/gmock.h"
74 #include "testing/gtest/include/gtest/gtest.h" 76 #include "testing/gtest/include/gtest/gtest.h"
75 77
76 using base::ExpectDictStringValue; 78 using base::ExpectDictStringValue;
77 using testing::_; 79 using testing::_;
78 using testing::DoAll; 80 using testing::DoAll;
79 using testing::InSequence; 81 using testing::InSequence;
80 using testing::Return; 82 using testing::Return;
81 using testing::SaveArg; 83 using testing::SaveArg;
82 using testing::StrictMock; 84 using testing::StrictMock;
83 85
84 namespace syncer { 86 namespace syncer {
85 87
86 using sessions::SyncSessionSnapshot; 88 using sessions::SyncSessionSnapshot;
89 using syncable::GET_BY_HANDLE;
87 using syncable::IS_DEL; 90 using syncable::IS_DEL;
88 using syncable::IS_UNSYNCED; 91 using syncable::IS_UNSYNCED;
89 using syncable::kEncryptedString;
90 using syncable::NON_UNIQUE_NAME; 92 using syncable::NON_UNIQUE_NAME;
91 using syncable::SPECIFICS; 93 using syncable::SPECIFICS;
94 using syncable::kEncryptedString;
92 95
93 namespace { 96 namespace {
94 97
95 const char kTestChromeVersion[] = "test chrome version"; 98 const char kTestChromeVersion[] = "test chrome version";
96 99
97 void ExpectInt64Value(int64 expected_value, 100 void ExpectInt64Value(int64 expected_value,
98 const DictionaryValue& value, const std::string& key) { 101 const DictionaryValue& value, const std::string& key) {
99 std::string int64_str; 102 std::string int64_str;
100 EXPECT_TRUE(value.GetString(key, &int64_str)); 103 EXPECT_TRUE(value.GetString(key, &int64_str));
101 int64 val = 0; 104 int64 val = 0;
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 int64 model_version, 884 int64 model_version,
882 const BaseTransaction* trans, 885 const BaseTransaction* trans,
883 const ImmutableChangeRecordList& changes) OVERRIDE {} 886 const ImmutableChangeRecordList& changes) OVERRIDE {}
884 887
885 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {} 888 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {}
886 889
887 // Helper methods. 890 // Helper methods.
888 bool SetUpEncryption(NigoriStatus nigori_status, 891 bool SetUpEncryption(NigoriStatus nigori_status,
889 EncryptionStatus encryption_status) { 892 EncryptionStatus encryption_status) {
890 UserShare* share = sync_manager_.GetUserShare(); 893 UserShare* share = sync_manager_.GetUserShare();
891 share->directory->set_initial_sync_ended_for_type(NIGORI, true);
892 894
893 // We need to create the nigori node as if it were an applied server update. 895 // We need to create the nigori node as if it were an applied server update.
894 int64 nigori_id = GetIdForDataType(NIGORI); 896 int64 nigori_id = GetIdForDataType(NIGORI);
895 if (nigori_id == kInvalidId) 897 if (nigori_id == kInvalidId)
896 return false; 898 return false;
897 899
898 // Set the nigori cryptographer information. 900 // Set the nigori cryptographer information.
899 if (encryption_status == FULL_ENCRYPTION) 901 if (encryption_status == FULL_ENCRYPTION)
900 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 902 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
901 903
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 sync_pb::DataTypeProgressMarker marker; 1007 sync_pb::DataTypeProgressMarker marker;
1006 marker.set_token("token"); 1008 marker.set_token("token");
1007 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); 1009 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
1008 sync_manager_.directory()->SetDownloadProgress(type, marker); 1010 sync_manager_.directory()->SetDownloadProgress(type, marker);
1009 } else { 1011 } else {
1010 sync_pb::DataTypeProgressMarker marker; 1012 sync_pb::DataTypeProgressMarker marker;
1011 sync_manager_.directory()->SetDownloadProgress(type, marker); 1013 sync_manager_.directory()->SetDownloadProgress(type, marker);
1012 } 1014 }
1013 } 1015 }
1014 1016
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 { 1017 InternalComponentsFactory::Switches GetSwitches() const {
1020 return switches_; 1018 return switches_;
1021 } 1019 }
1022 1020
1023 private: 1021 private:
1024 // Needed by |sync_manager_|. 1022 // Needed by |sync_manager_|.
1025 MessageLoop message_loop_; 1023 MessageLoop message_loop_;
1026 // Needed by |sync_manager_|. 1024 // Needed by |sync_manager_|.
1027 base::ScopedTempDir temp_dir_; 1025 base::ScopedTempDir temp_dir_;
1028 // Sync Id's for the roots of the enabled datatypes. 1026 // Sync Id's for the roots of the enabled datatypes.
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 2846
2849 ConfigurationParams params; 2847 ConfigurationParams params;
2850 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); 2848 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE));
2851 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). 2849 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)).
2852 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2850 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2853 2851
2854 // Set data for all types. 2852 // Set data for all types.
2855 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 2853 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
2856 iter.Inc()) { 2854 iter.Inc()) {
2857 SetProgressMarkerForType(iter.Get(), true); 2855 SetProgressMarkerForType(iter.Get(), true);
2858 SetInitialSyncEndedForType(iter.Get(), true);
2859 } 2856 }
2860 2857
2861 CallbackCounter ready_task_counter, retry_task_counter; 2858 CallbackCounter ready_task_counter, retry_task_counter;
2862 sync_manager_.ConfigureSyncer( 2859 sync_manager_.ConfigureSyncer(
2863 reason, 2860 reason,
2864 types_to_download, 2861 types_to_download,
2865 new_routing_info, 2862 new_routing_info,
2866 base::Bind(&CallbackCounter::Callback, 2863 base::Bind(&CallbackCounter::Callback,
2867 base::Unretained(&ready_task_counter)), 2864 base::Unretained(&ready_task_counter)),
2868 base::Bind(&CallbackCounter::Callback, 2865 base::Bind(&CallbackCounter::Callback,
(...skipping 30 matching lines...) Expand all
2899 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE)); 2896 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE));
2900 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). 2897 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)).
2901 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2898 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2902 2899
2903 // Set data for all types except those recently disabled (so we can verify 2900 // Set data for all types except those recently disabled (so we can verify
2904 // only those recently disabled are purged) . 2901 // only those recently disabled are purged) .
2905 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 2902 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
2906 iter.Inc()) { 2903 iter.Inc()) {
2907 if (!disabled_types.Has(iter.Get())) { 2904 if (!disabled_types.Has(iter.Get())) {
2908 SetProgressMarkerForType(iter.Get(), true); 2905 SetProgressMarkerForType(iter.Get(), true);
2909 SetInitialSyncEndedForType(iter.Get(), true);
2910 } else { 2906 } else {
2911 SetProgressMarkerForType(iter.Get(), false); 2907 SetProgressMarkerForType(iter.Get(), false);
2912 SetInitialSyncEndedForType(iter.Get(), false);
2913 } 2908 }
2914 } 2909 }
2915 2910
2916 // Set the context to have the old routing info. 2911 // Set the context to have the old routing info.
2917 session_context()->set_routing_info(old_routing_info); 2912 session_context()->set_routing_info(old_routing_info);
2918 2913
2919 CallbackCounter ready_task_counter, retry_task_counter; 2914 CallbackCounter ready_task_counter, retry_task_counter;
2920 sync_manager_.ConfigureSyncer( 2915 sync_manager_.ConfigureSyncer(
2921 reason, 2916 reason,
2922 types_to_download, 2917 types_to_download,
2923 new_routing_info, 2918 new_routing_info,
2924 base::Bind(&CallbackCounter::Callback, 2919 base::Bind(&CallbackCounter::Callback,
2925 base::Unretained(&ready_task_counter)), 2920 base::Unretained(&ready_task_counter)),
2926 base::Bind(&CallbackCounter::Callback, 2921 base::Bind(&CallbackCounter::Callback,
2927 base::Unretained(&retry_task_counter))); 2922 base::Unretained(&retry_task_counter)));
2928 EXPECT_EQ(0, ready_task_counter.times_called()); 2923 EXPECT_EQ(0, ready_task_counter.times_called());
2929 EXPECT_EQ(0, retry_task_counter.times_called()); 2924 EXPECT_EQ(0, retry_task_counter.times_called());
2930 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2925 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2931 params.source); 2926 params.source);
2932 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2927 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2933 EXPECT_EQ(new_routing_info, params.routing_info); 2928 EXPECT_EQ(new_routing_info, params.routing_info);
2934 2929
2935 // Verify only the recently disabled types were purged. 2930 // Verify only the recently disabled types were purged.
2936 EXPECT_TRUE(sync_manager_.InitialSyncEndedTypes().Equals(
2937 Difference(ModelTypeSet::All(), disabled_types)));
2938 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken( 2931 EXPECT_TRUE(sync_manager_.GetTypesWithEmptyProgressMarkerToken(
2939 ModelTypeSet::All()).Equals(disabled_types)); 2932 ModelTypeSet::All()).Equals(disabled_types));
2940 } 2933 }
2941 2934
2942 // Test that the retry callback is invoked on configuration failure. 2935 // Test that the retry callback is invoked on configuration failure.
2943 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) { 2936 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) {
2944 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2937 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2945 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); 2938 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
2946 ModelSafeRoutingInfo new_routing_info; 2939 ModelSafeRoutingInfo new_routing_info;
2947 GetModelSafeRoutingInfo(&new_routing_info); 2940 GetModelSafeRoutingInfo(&new_routing_info);
(...skipping 13 matching lines...) Expand all
2961 base::Bind(&CallbackCounter::Callback, 2954 base::Bind(&CallbackCounter::Callback,
2962 base::Unretained(&retry_task_counter))); 2955 base::Unretained(&retry_task_counter)));
2963 EXPECT_EQ(0, ready_task_counter.times_called()); 2956 EXPECT_EQ(0, ready_task_counter.times_called());
2964 EXPECT_EQ(1, retry_task_counter.times_called()); 2957 EXPECT_EQ(1, retry_task_counter.times_called());
2965 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2958 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2966 params.source); 2959 params.source);
2967 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2960 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2968 EXPECT_EQ(new_routing_info, params.routing_info); 2961 EXPECT_EQ(new_routing_info, params.routing_info);
2969 } 2962 }
2970 2963
2971 // Test that PurgePartiallySyncedTypes purges only those types that don't 2964 // Test that PurgePartiallySyncedTypes purges only those types that have not
2972 // have empty progress marker and don't have initial sync ended set. 2965 // fully completed their initial download and apply.
2973 TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) { 2966 TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) {
2967 ModelSafeRoutingInfo routing_info;
2968 GetModelSafeRoutingInfo(&routing_info);
2969 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
2970
2974 UserShare* share = sync_manager_.GetUserShare(); 2971 UserShare* share = sync_manager_.GetUserShare();
2975 2972
2976 // Set Nigori and Bookmarks to be partial types. 2973 // The test harness automatically initializes all types in the routing info.
2977 sync_pb::DataTypeProgressMarker nigori_marker; 2974 // Check that autofill is not among them.
2978 nigori_marker.set_data_type_id( 2975 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 2976
2988 // Set Preferences to be a full type. 2977 // Further ensure that the test harness did not create its root node.
2989 sync_pb::DataTypeProgressMarker pref_marker; 2978 {
2990 pref_marker.set_data_type_id( 2979 syncable::ReadTransaction trans(FROM_HERE, share->directory.get());
2980 syncable::Entry autofill_root_node(&trans, syncable::GET_BY_SERVER_TAG,
2981 ModelTypeToRootTag(AUTOFILL));
2982 ASSERT_FALSE(autofill_root_node.good());
2983 }
2984
2985 // One more redundant check.
2986 ASSERT_FALSE(sync_manager_.InitialSyncEndedTypes().Has(AUTOFILL));
2987
2988 // Give autofill a progress marker.
2989 sync_pb::DataTypeProgressMarker autofill_marker;
2990 autofill_marker.set_data_type_id(
2991 GetSpecificsFieldNumberFromModelType(AUTOFILL));
2992 autofill_marker.set_token("token");
2993 share->directory->SetDownloadProgress(AUTOFILL, autofill_marker);
2994
2995 // Also add a pending autofill root node update from the server.
2996 TestEntryFactory factory_(share->directory.get());
2997 int autofill_meta = factory_.CreateUnappliedRootNode(AUTOFILL);
2998
2999 // Preferences is an enabled type. Check that the harness initialized it.
3000 ASSERT_TRUE(enabled_types.Has(PREFERENCES));
3001 ASSERT_TRUE(sync_manager_.InitialSyncEndedTypes().Has(PREFERENCES));
3002
3003 // Give preferencse a progress marker.
3004 sync_pb::DataTypeProgressMarker prefs_marker;
3005 prefs_marker.set_data_type_id(
2991 GetSpecificsFieldNumberFromModelType(PREFERENCES)); 3006 GetSpecificsFieldNumberFromModelType(PREFERENCES));
2992 pref_marker.set_token("token"); 3007 prefs_marker.set_token("token");
2993 share->directory->SetDownloadProgress(PREFERENCES, pref_marker); 3008 share->directory->SetDownloadProgress(PREFERENCES, prefs_marker);
2994 share->directory->set_initial_sync_ended_for_type(PREFERENCES, true);
2995 3009
2996 ModelTypeSet partial_types = 3010 // Add a fully synced preferences node under the root.
2997 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); 3011 std::string pref_client_tag = "prefABC";
2998 EXPECT_FALSE(partial_types.Has(NIGORI)); 3012 std::string pref_hashed_tag = "hashXYZ";
2999 EXPECT_FALSE(partial_types.Has(BOOKMARKS)); 3013 sync_pb::EntitySpecifics pref_specifics;
3000 EXPECT_FALSE(partial_types.Has(PREFERENCES)); 3014 AddDefaultFieldValue(PREFERENCES, &pref_specifics);
3015 int pref_meta = MakeServerNode(
3016 share, PREFERENCES, pref_client_tag, pref_hashed_tag, pref_specifics);
3001 3017
3018 // And now, the purge.
3002 EXPECT_TRUE(sync_manager_.PurgePartiallySyncedTypes()); 3019 EXPECT_TRUE(sync_manager_.PurgePartiallySyncedTypes());
3003 3020
3004 // Ensure only bookmarks and nigori lost their progress marker. Preferences 3021 // Ensure that autofill lost its progress marker, but preferences did not.
3005 // should still have it. 3022 ModelTypeSet empty_tokens =
3006 partial_types =
3007 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); 3023 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All());
3008 EXPECT_TRUE(partial_types.Has(NIGORI)); 3024 EXPECT_TRUE(empty_tokens.Has(AUTOFILL));
3009 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); 3025 EXPECT_FALSE(empty_tokens.Has(PREFERENCES));
3010 EXPECT_FALSE(partial_types.Has(PREFERENCES)); 3026
3027 // Ensure that autofill lots its node, but preferences did not.
3028 {
3029 syncable::ReadTransaction trans(FROM_HERE, share->directory.get());
3030 syncable::Entry autofill_node(&trans, GET_BY_HANDLE, autofill_meta);
3031 syncable::Entry pref_node(&trans, GET_BY_HANDLE, pref_meta);
3032 EXPECT_FALSE(autofill_node.good());
3033 EXPECT_TRUE(pref_node.good());
3034 }
3011 } 3035 }
3012 3036
3013 // Test CleanupDisabledTypes properly purges all disabled types as specified 3037 // Test CleanupDisabledTypes properly purges all disabled types as specified
3014 // by the previous and current enabled params. Enabled partial types should not 3038 // by the previous and current enabled params.
3015 // be purged.
3016 // Fails on Windows: crbug.com/139726 3039 // Fails on Windows: crbug.com/139726
3017 #if defined(OS_WIN) 3040 #if defined(OS_WIN)
3018 #define MAYBE_PurgeDisabledTypes DISABLED_PurgeDisabledTypes 3041 #define MAYBE_PurgeDisabledTypes DISABLED_PurgeDisabledTypes
3019 #else 3042 #else
3020 #define MAYBE_PurgeDisabledTypes PurgeDisabledTypes 3043 #define MAYBE_PurgeDisabledTypes PurgeDisabledTypes
3021 #endif 3044 #endif
3022 TEST_F(SyncManagerTest, MAYBE_PurgeDisabledTypes) { 3045 TEST_F(SyncManagerTest, MAYBE_PurgeDisabledTypes) {
3023 ModelSafeRoutingInfo routing_info; 3046 ModelSafeRoutingInfo routing_info;
3024 GetModelSafeRoutingInfo(&routing_info); 3047 GetModelSafeRoutingInfo(&routing_info);
3025 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 3048 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
3026 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); 3049 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
3027 ModelTypeSet partial_enabled_types(PASSWORDS);
3028 3050
3029 // Set data for all non-partial types. 3051 // The harness should have initialized the enabled_types for us.
3052 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3053
3054 // Set progress markers for all types.
3030 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good(); 3055 for (ModelTypeSet::Iterator iter = ModelTypeSet::All().First(); iter.Good();
3031 iter.Inc()) { 3056 iter.Inc()) {
3032 SetProgressMarkerForType(iter.Get(), true); 3057 SetProgressMarkerForType(iter.Get(), true);
3033 if (!partial_enabled_types.Has(iter.Get()))
3034 SetInitialSyncEndedForType(iter.Get(), true);
3035 } 3058 }
3036 3059
3037 // Verify all the enabled types remain after cleanup, and all the disabled 3060 // Verify all the enabled types remain after cleanup, and all the disabled
3038 // types were purged. 3061 // types were purged.
3039 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), enabled_types); 3062 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), enabled_types);
3040 EXPECT_TRUE(enabled_types.Equals( 3063 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3041 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
3042 EXPECT_TRUE(disabled_types.Equals( 3064 EXPECT_TRUE(disabled_types.Equals(
3043 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3065 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3044 3066
3045 // Disable some more types. 3067 // Disable some more types.
3046 disabled_types.Put(BOOKMARKS); 3068 disabled_types.Put(BOOKMARKS);
3047 disabled_types.Put(PREFERENCES); 3069 disabled_types.Put(PREFERENCES);
3048 ModelTypeSet new_enabled_types = 3070 ModelTypeSet new_enabled_types =
3049 Difference(ModelTypeSet::All(), disabled_types); 3071 Difference(ModelTypeSet::All(), disabled_types);
3050 3072
3051 // Verify only the non-disabled types remain after cleanup. 3073 // Verify only the non-disabled types remain after cleanup.
3052 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 3074 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
3053 EXPECT_TRUE(new_enabled_types.Equals( 3075 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3054 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
3055 EXPECT_TRUE(disabled_types.Equals( 3076 EXPECT_TRUE(disabled_types.Equals(
3056 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3077 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3057 } 3078 }
3058 3079
3059 } // namespace 3080 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/test_entry_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698