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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_registrar_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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 #include "chrome/browser/sync/glue/sync_backend_registrar.h" 5 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
6 6
7 #include "chrome/browser/sync/glue/change_processor_mock.h" 7 #include "chrome/browser/sync/glue/change_processor_mock.h"
8 #include "chrome/browser/sync/glue/ui_model_worker.h" 8 #include "chrome/browser/sync/glue/ui_model_worker.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 virtual void SetUp() { 43 virtual void SetUp() {
44 test_user_share_.SetUp(); 44 test_user_share_.SetUp();
45 } 45 }
46 46
47 virtual void TearDown() { 47 virtual void TearDown() {
48 test_user_share_.TearDown(); 48 test_user_share_.TearDown();
49 } 49 }
50 50
51 void ExpectRoutingInfo( 51 void ExpectRoutingInfo(
52 SyncBackendRegistrar* registrar, 52 SyncBackendRegistrar* registrar,
53 const csync::ModelSafeRoutingInfo& expected_routing_info) { 53 const syncer::ModelSafeRoutingInfo& expected_routing_info) {
54 csync::ModelSafeRoutingInfo routing_info; 54 syncer::ModelSafeRoutingInfo routing_info;
55 registrar->GetModelSafeRoutingInfo(&routing_info); 55 registrar->GetModelSafeRoutingInfo(&routing_info);
56 EXPECT_EQ(expected_routing_info, routing_info); 56 EXPECT_EQ(expected_routing_info, routing_info);
57 } 57 }
58 58
59 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, 59 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar,
60 ModelTypeSet types) { 60 ModelTypeSet types) {
61 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 61 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
62 ModelType model_type = ModelTypeFromInt(i); 62 ModelType model_type = ModelTypeFromInt(i);
63 EXPECT_EQ(types.Has(model_type), 63 EXPECT_EQ(types.Has(model_type),
64 registrar.IsTypeActivatedForTest(model_type)); 64 registrar.IsTypeActivatedForTest(model_type));
65 } 65 }
66 } 66 }
67 67
68 MessageLoop loop_; 68 MessageLoop loop_;
69 csync::TestUserShare test_user_share_; 69 syncer::TestUserShare test_user_share_;
70 70
71 private: 71 private:
72 content::TestBrowserThread ui_thread_; 72 content::TestBrowserThread ui_thread_;
73 }; 73 };
74 74
75 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { 75 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
76 TestingProfile profile; 76 TestingProfile profile;
77 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 77 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
78 EXPECT_FALSE(registrar.IsNigoriEnabled()); 78 EXPECT_FALSE(registrar.IsNigoriEnabled());
79 { 79 {
80 std::vector<csync::ModelSafeWorker*> workers; 80 std::vector<syncer::ModelSafeWorker*> workers;
81 registrar.GetWorkers(&workers); 81 registrar.GetWorkers(&workers);
82 EXPECT_EQ(4u, workers.size()); 82 EXPECT_EQ(4u, workers.size());
83 } 83 }
84 ExpectRoutingInfo(&registrar, csync::ModelSafeRoutingInfo()); 84 ExpectRoutingInfo(&registrar, syncer::ModelSafeRoutingInfo());
85 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 85 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
86 registrar.OnSyncerShutdownComplete(); 86 registrar.OnSyncerShutdownComplete();
87 registrar.StopOnUIThread(); 87 registrar.StopOnUIThread();
88 } 88 }
89 89
90 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { 90 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) {
91 TestingProfile profile; 91 TestingProfile profile;
92 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS); 92 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS);
93 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_); 93 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_);
94 EXPECT_TRUE(registrar.IsNigoriEnabled()); 94 EXPECT_TRUE(registrar.IsNigoriEnabled());
95 { 95 {
96 std::vector<csync::ModelSafeWorker*> workers; 96 std::vector<syncer::ModelSafeWorker*> workers;
97 registrar.GetWorkers(&workers); 97 registrar.GetWorkers(&workers);
98 EXPECT_EQ(4u, workers.size()); 98 EXPECT_EQ(4u, workers.size());
99 } 99 }
100 { 100 {
101 csync::ModelSafeRoutingInfo expected_routing_info; 101 syncer::ModelSafeRoutingInfo expected_routing_info;
102 expected_routing_info[BOOKMARKS] = csync::GROUP_PASSIVE; 102 expected_routing_info[BOOKMARKS] = syncer::GROUP_PASSIVE;
103 expected_routing_info[NIGORI] = csync::GROUP_PASSIVE; 103 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE;
104 // Passwords dropped because of no password store. 104 // Passwords dropped because of no password store.
105 ExpectRoutingInfo(&registrar, expected_routing_info); 105 ExpectRoutingInfo(&registrar, expected_routing_info);
106 } 106 }
107 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 107 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
108 registrar.OnSyncerShutdownComplete(); 108 registrar.OnSyncerShutdownComplete();
109 registrar.StopOnUIThread(); 109 registrar.StopOnUIThread();
110 } 110 }
111 111
112 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { 112 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) {
113 TestingProfile profile; 113 TestingProfile profile;
114 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 114 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
115 115
116 // Add. 116 // Add.
117 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL); 117 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL);
118 EXPECT_TRUE( 118 EXPECT_TRUE(
119 registrar.ConfigureDataTypes(types1, ModelTypeSet()).Equals(types1)); 119 registrar.ConfigureDataTypes(types1, ModelTypeSet()).Equals(types1));
120 { 120 {
121 csync::ModelSafeRoutingInfo expected_routing_info; 121 syncer::ModelSafeRoutingInfo expected_routing_info;
122 expected_routing_info[BOOKMARKS] = csync::GROUP_PASSIVE; 122 expected_routing_info[BOOKMARKS] = syncer::GROUP_PASSIVE;
123 expected_routing_info[NIGORI] = csync::GROUP_PASSIVE; 123 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE;
124 expected_routing_info[AUTOFILL] = csync::GROUP_PASSIVE; 124 expected_routing_info[AUTOFILL] = syncer::GROUP_PASSIVE;
125 ExpectRoutingInfo(&registrar, expected_routing_info); 125 ExpectRoutingInfo(&registrar, expected_routing_info);
126 } 126 }
127 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 127 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
128 128
129 // Add and remove. 129 // Add and remove.
130 const ModelTypeSet types2(PREFERENCES, THEMES); 130 const ModelTypeSet types2(PREFERENCES, THEMES);
131 EXPECT_TRUE(registrar.ConfigureDataTypes(types2, types1).Equals(types2)); 131 EXPECT_TRUE(registrar.ConfigureDataTypes(types2, types1).Equals(types2));
132 { 132 {
133 csync::ModelSafeRoutingInfo expected_routing_info; 133 syncer::ModelSafeRoutingInfo expected_routing_info;
134 expected_routing_info[PREFERENCES] = csync::GROUP_PASSIVE; 134 expected_routing_info[PREFERENCES] = syncer::GROUP_PASSIVE;
135 expected_routing_info[THEMES] = csync::GROUP_PASSIVE; 135 expected_routing_info[THEMES] = syncer::GROUP_PASSIVE;
136 ExpectRoutingInfo(&registrar, expected_routing_info); 136 ExpectRoutingInfo(&registrar, expected_routing_info);
137 } 137 }
138 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 138 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
139 139
140 // Remove. 140 // Remove.
141 EXPECT_TRUE(registrar.ConfigureDataTypes(ModelTypeSet(), types2).Empty()); 141 EXPECT_TRUE(registrar.ConfigureDataTypes(ModelTypeSet(), types2).Empty());
142 ExpectRoutingInfo(&registrar, csync::ModelSafeRoutingInfo()); 142 ExpectRoutingInfo(&registrar, syncer::ModelSafeRoutingInfo());
143 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 143 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
144 144
145 registrar.OnSyncerShutdownComplete(); 145 registrar.OnSyncerShutdownComplete();
146 registrar.StopOnUIThread(); 146 registrar.StopOnUIThread();
147 } 147 }
148 148
149 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { 149 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) {
150 registrar->OnChangesApplied(type, NULL, 150 registrar->OnChangesApplied(type, NULL,
151 csync::ImmutableChangeRecordList()); 151 syncer::ImmutableChangeRecordList());
152 registrar->OnChangesComplete(type); 152 registrar->OnChangesComplete(type);
153 } 153 }
154 154
155 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { 155 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
156 InSequence in_sequence; 156 InSequence in_sequence;
157 TestingProfile profile; 157 TestingProfile profile;
158 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 158 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
159 159
160 // Should do nothing. 160 // Should do nothing.
161 TriggerChanges(&registrar, BOOKMARKS); 161 TriggerChanges(&registrar, BOOKMARKS);
162 162
163 StrictMock<ChangeProcessorMock> change_processor_mock; 163 StrictMock<ChangeProcessorMock> change_processor_mock;
164 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); 164 EXPECT_CALL(change_processor_mock, StartImpl(&profile));
165 EXPECT_CALL(change_processor_mock, IsRunning()) 165 EXPECT_CALL(change_processor_mock, IsRunning())
166 .WillRepeatedly(Return(true)); 166 .WillRepeatedly(Return(true));
167 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); 167 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _));
168 EXPECT_CALL(change_processor_mock, IsRunning()) 168 EXPECT_CALL(change_processor_mock, IsRunning())
169 .WillRepeatedly(Return(true)); 169 .WillRepeatedly(Return(true));
170 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 170 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
171 EXPECT_CALL(change_processor_mock, StopImpl()); 171 EXPECT_CALL(change_processor_mock, StopImpl());
172 EXPECT_CALL(change_processor_mock, IsRunning()) 172 EXPECT_CALL(change_processor_mock, IsRunning())
173 .WillRepeatedly(Return(false)); 173 .WillRepeatedly(Return(false));
174 174
175 const ModelTypeSet types(BOOKMARKS); 175 const ModelTypeSet types(BOOKMARKS);
176 EXPECT_TRUE( 176 EXPECT_TRUE(
177 registrar.ConfigureDataTypes(types, ModelTypeSet()).Equals(types)); 177 registrar.ConfigureDataTypes(types, ModelTypeSet()).Equals(types));
178 registrar.ActivateDataType(BOOKMARKS, csync::GROUP_UI, 178 registrar.ActivateDataType(BOOKMARKS, syncer::GROUP_UI,
179 &change_processor_mock, 179 &change_processor_mock,
180 test_user_share_.user_share()); 180 test_user_share_.user_share());
181 { 181 {
182 csync::ModelSafeRoutingInfo expected_routing_info; 182 syncer::ModelSafeRoutingInfo expected_routing_info;
183 expected_routing_info[BOOKMARKS] = csync::GROUP_UI; 183 expected_routing_info[BOOKMARKS] = syncer::GROUP_UI;
184 ExpectRoutingInfo(&registrar, expected_routing_info); 184 ExpectRoutingInfo(&registrar, expected_routing_info);
185 } 185 }
186 ExpectHasProcessorsForTypes(registrar, types); 186 ExpectHasProcessorsForTypes(registrar, types);
187 187
188 TriggerChanges(&registrar, BOOKMARKS); 188 TriggerChanges(&registrar, BOOKMARKS);
189 189
190 registrar.DeactivateDataType(BOOKMARKS); 190 registrar.DeactivateDataType(BOOKMARKS);
191 ExpectRoutingInfo(&registrar, csync::ModelSafeRoutingInfo()); 191 ExpectRoutingInfo(&registrar, syncer::ModelSafeRoutingInfo());
192 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 192 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
193 193
194 // Should do nothing. 194 // Should do nothing.
195 TriggerChanges(&registrar, BOOKMARKS); 195 TriggerChanges(&registrar, BOOKMARKS);
196 196
197 registrar.OnSyncerShutdownComplete(); 197 registrar.OnSyncerShutdownComplete();
198 registrar.StopOnUIThread(); 198 registrar.StopOnUIThread();
199 } 199 }
200 200
201 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { 201 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
(...skipping 13 matching lines...) Expand all
215 EXPECT_CALL(change_processor_mock, IsRunning()) 215 EXPECT_CALL(change_processor_mock, IsRunning())
216 .WillRepeatedly(Return(true)); 216 .WillRepeatedly(Return(true));
217 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 217 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
218 EXPECT_CALL(change_processor_mock, StopImpl()); 218 EXPECT_CALL(change_processor_mock, StopImpl());
219 EXPECT_CALL(change_processor_mock, IsRunning()) 219 EXPECT_CALL(change_processor_mock, IsRunning())
220 .WillRepeatedly(Return(false)); 220 .WillRepeatedly(Return(false));
221 221
222 const ModelTypeSet types(AUTOFILL); 222 const ModelTypeSet types(AUTOFILL);
223 EXPECT_TRUE( 223 EXPECT_TRUE(
224 registrar.ConfigureDataTypes(types, ModelTypeSet()).Equals(types)); 224 registrar.ConfigureDataTypes(types, ModelTypeSet()).Equals(types));
225 registrar.ActivateDataType(AUTOFILL, csync::GROUP_DB, 225 registrar.ActivateDataType(AUTOFILL, syncer::GROUP_DB,
226 &change_processor_mock, 226 &change_processor_mock,
227 test_user_share_.user_share()); 227 test_user_share_.user_share());
228 { 228 {
229 csync::ModelSafeRoutingInfo expected_routing_info; 229 syncer::ModelSafeRoutingInfo expected_routing_info;
230 expected_routing_info[AUTOFILL] = csync::GROUP_DB; 230 expected_routing_info[AUTOFILL] = syncer::GROUP_DB;
231 ExpectRoutingInfo(&registrar, expected_routing_info); 231 ExpectRoutingInfo(&registrar, expected_routing_info);
232 } 232 }
233 ExpectHasProcessorsForTypes(registrar, types); 233 ExpectHasProcessorsForTypes(registrar, types);
234 234
235 TriggerChanges(&registrar, AUTOFILL); 235 TriggerChanges(&registrar, AUTOFILL);
236 236
237 registrar.DeactivateDataType(AUTOFILL); 237 registrar.DeactivateDataType(AUTOFILL);
238 ExpectRoutingInfo(&registrar, csync::ModelSafeRoutingInfo()); 238 ExpectRoutingInfo(&registrar, syncer::ModelSafeRoutingInfo());
239 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 239 ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
240 240
241 // Should do nothing. 241 // Should do nothing.
242 TriggerChanges(&registrar, AUTOFILL); 242 TriggerChanges(&registrar, AUTOFILL);
243 243
244 registrar.OnSyncerShutdownComplete(); 244 registrar.OnSyncerShutdownComplete();
245 registrar.StopOnUIThread(); 245 registrar.StopOnUIThread();
246 } 246 }
247 247
248 } // namespace 248 } // namespace
249 249
250 } // namespace browser_sync 250 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_registrar.cc ('k') | chrome/browser/sync/glue/theme_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698