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

Side by Side Diff: components/sync/engine_impl/model_type_registry_unittest.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/sync/engine_impl/model_type_registry.h" 5 #include "components/sync/engine_impl/model_type_registry.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/deferred_sequenced_task_runner.h" 10 #include "base/deferred_sequenced_task_runner.h"
(...skipping 21 matching lines...) Expand all
32 32
33 ModelTypeRegistry* registry(); 33 ModelTypeRegistry* registry();
34 34
35 static sync_pb::DataTypeState MakeInitialDataTypeState(ModelType type) { 35 static sync_pb::DataTypeState MakeInitialDataTypeState(ModelType type) {
36 sync_pb::DataTypeState state; 36 sync_pb::DataTypeState state;
37 state.mutable_progress_marker()->set_data_type_id( 37 state.mutable_progress_marker()->set_data_type_id(
38 GetSpecificsFieldNumberFromModelType(type)); 38 GetSpecificsFieldNumberFromModelType(type));
39 return state; 39 return state;
40 } 40 }
41 41
42 static std::unique_ptr<syncer_v2::ActivationContext> MakeActivationContext( 42 static std::unique_ptr<ActivationContext> MakeActivationContext(
43 const sync_pb::DataTypeState& data_type_state, 43 const sync_pb::DataTypeState& data_type_state,
44 std::unique_ptr<syncer_v2::ModelTypeProcessor> type_processor) { 44 std::unique_ptr<ModelTypeProcessor> type_processor) {
45 std::unique_ptr<syncer_v2::ActivationContext> context = 45 std::unique_ptr<ActivationContext> context =
46 base::WrapUnique(new syncer_v2::ActivationContext); 46 base::WrapUnique(new ActivationContext);
47 context->data_type_state = data_type_state; 47 context->data_type_state = data_type_state;
48 context->type_processor = std::move(type_processor); 48 context->type_processor = std::move(type_processor);
49 return context; 49 return context;
50 } 50 }
51 51
52 void MarkInitialSyncEndedForDirectoryType(ModelType type) { 52 void MarkInitialSyncEndedForDirectoryType(ModelType type) {
53 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::SYNCER, 53 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::SYNCER,
54 directory()); 54 directory());
55 syncable::ModelNeutralMutableEntry entry( 55 syncable::ModelNeutralMutableEntry entry(
56 &trans, syncable::CREATE_NEW_TYPE_ROOT, type); 56 &trans, syncable::CREATE_NEW_TYPE_ROOT, type);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ModelSafeRoutingInfo routing_info2; 175 ModelSafeRoutingInfo routing_info2;
176 registry()->SetEnabledDirectoryTypes(routing_info2); 176 registry()->SetEnabledDirectoryTypes(routing_info2);
177 177
178 registry()->SetEnabledDirectoryTypes(routing_info1); 178 registry()->SetEnabledDirectoryTypes(routing_info1);
179 } 179 }
180 180
181 TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { 181 TEST_F(ModelTypeRegistryTest, NonBlockingTypes) {
182 EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); 182 EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
183 183
184 registry()->ConnectType( 184 registry()->ConnectType(
185 syncer::THEMES, 185 THEMES,
186 MakeActivationContext( 186 MakeActivationContext(MakeInitialDataTypeState(THEMES),
187 MakeInitialDataTypeState(THEMES), 187 base::MakeUnique<FakeModelTypeProcessor>()));
188 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); 188 EXPECT_EQ(ModelTypeSet(THEMES), registry()->GetEnabledTypes());
189 EXPECT_EQ(ModelTypeSet(syncer::THEMES), registry()->GetEnabledTypes());
190 189
191 registry()->ConnectType( 190 registry()->ConnectType(
192 syncer::SESSIONS, 191 SESSIONS,
193 MakeActivationContext( 192 MakeActivationContext(MakeInitialDataTypeState(SESSIONS),
194 MakeInitialDataTypeState(SESSIONS), 193 base::MakeUnique<FakeModelTypeProcessor>()));
195 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); 194 EXPECT_EQ(ModelTypeSet(THEMES, SESSIONS), registry()->GetEnabledTypes());
196 EXPECT_EQ(ModelTypeSet(syncer::THEMES, syncer::SESSIONS),
197 registry()->GetEnabledTypes());
198 195
199 registry()->DisconnectType(syncer::THEMES); 196 registry()->DisconnectType(THEMES);
200 EXPECT_EQ(ModelTypeSet(syncer::SESSIONS), registry()->GetEnabledTypes()); 197 EXPECT_EQ(ModelTypeSet(SESSIONS), registry()->GetEnabledTypes());
201 198
202 // Allow ModelTypeRegistry destruction to delete the 199 // Allow ModelTypeRegistry destruction to delete the
203 // Sessions' ModelTypeSyncWorker. 200 // Sessions' ModelTypeSyncWorker.
204 } 201 }
205 202
206 TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { 203 TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
207 ModelSafeRoutingInfo routing_info1; 204 ModelSafeRoutingInfo routing_info1;
208 routing_info1.insert(std::make_pair(NIGORI, GROUP_PASSIVE)); 205 routing_info1.insert(std::make_pair(NIGORI, GROUP_PASSIVE));
209 routing_info1.insert(std::make_pair(BOOKMARKS, GROUP_UI)); 206 routing_info1.insert(std::make_pair(BOOKMARKS, GROUP_UI));
210 routing_info1.insert(std::make_pair(AUTOFILL, GROUP_DB)); 207 routing_info1.insert(std::make_pair(AUTOFILL, GROUP_DB));
211 routing_info1.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING)); 208 routing_info1.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING));
212 routing_info1.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING)); 209 routing_info1.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING));
213 210
214 ModelTypeSet directory_types(NIGORI, BOOKMARKS, AUTOFILL); 211 ModelTypeSet directory_types(NIGORI, BOOKMARKS, AUTOFILL);
215 212
216 ModelTypeSet current_types; 213 ModelTypeSet current_types;
217 EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); 214 EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
218 215
219 // Add the themes non-blocking type. 216 // Add the themes non-blocking type.
220 registry()->ConnectType( 217 registry()->ConnectType(
221 syncer::THEMES, 218 THEMES,
222 MakeActivationContext( 219 MakeActivationContext(MakeInitialDataTypeState(THEMES),
223 MakeInitialDataTypeState(THEMES), 220 base::MakeUnique<FakeModelTypeProcessor>()));
224 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); 221 current_types.Put(THEMES);
225 current_types.Put(syncer::THEMES);
226 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); 222 EXPECT_EQ(current_types, registry()->GetEnabledTypes());
227 223
228 // Add some directory types. 224 // Add some directory types.
229 registry()->SetEnabledDirectoryTypes(routing_info1); 225 registry()->SetEnabledDirectoryTypes(routing_info1);
230 current_types.PutAll(directory_types); 226 current_types.PutAll(directory_types);
231 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); 227 EXPECT_EQ(current_types, registry()->GetEnabledTypes());
232 228
233 // Add sessions non-blocking type. 229 // Add sessions non-blocking type.
234 registry()->ConnectType( 230 registry()->ConnectType(
235 syncer::SESSIONS, 231 SESSIONS,
236 MakeActivationContext( 232 MakeActivationContext(MakeInitialDataTypeState(SESSIONS),
237 MakeInitialDataTypeState(SESSIONS), 233 base::MakeUnique<FakeModelTypeProcessor>()));
238 base::MakeUnique<syncer_v2::FakeModelTypeProcessor>())); 234 current_types.Put(SESSIONS);
239 current_types.Put(syncer::SESSIONS);
240 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); 235 EXPECT_EQ(current_types, registry()->GetEnabledTypes());
241 236
242 // Remove themes non-blocking type. 237 // Remove themes non-blocking type.
243 registry()->DisconnectType(syncer::THEMES); 238 registry()->DisconnectType(THEMES);
244 current_types.Remove(syncer::THEMES); 239 current_types.Remove(THEMES);
245 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); 240 EXPECT_EQ(current_types, registry()->GetEnabledTypes());
246 241
247 // Clear all directory types. 242 // Clear all directory types.
248 ModelSafeRoutingInfo routing_info2; 243 ModelSafeRoutingInfo routing_info2;
249 registry()->SetEnabledDirectoryTypes(routing_info2); 244 registry()->SetEnabledDirectoryTypes(routing_info2);
250 current_types.RemoveAll(directory_types); 245 current_types.RemoveAll(directory_types);
251 EXPECT_EQ(current_types, registry()->GetEnabledTypes()); 246 EXPECT_EQ(current_types, registry()->GetEnabledTypes());
252 } 247 }
253 248
254 // Tests correct result returned from GetInitialSyncEndedTypes. 249 // Tests correct result returned from GetInitialSyncEndedTypes.
255 TEST_F(ModelTypeRegistryTest, GetInitialSyncEndedTypes) { 250 TEST_F(ModelTypeRegistryTest, GetInitialSyncEndedTypes) {
256 ModelSafeRoutingInfo routing_info; 251 ModelSafeRoutingInfo routing_info;
257 // Add two directory and two non-blocking types. 252 // Add two directory and two non-blocking types.
258 routing_info.insert(std::make_pair(AUTOFILL, GROUP_PASSIVE)); 253 routing_info.insert(std::make_pair(AUTOFILL, GROUP_PASSIVE));
259 routing_info.insert(std::make_pair(BOOKMARKS, GROUP_PASSIVE)); 254 routing_info.insert(std::make_pair(BOOKMARKS, GROUP_PASSIVE));
260 routing_info.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING)); 255 routing_info.insert(std::make_pair(THEMES, GROUP_NON_BLOCKING));
261 routing_info.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING)); 256 routing_info.insert(std::make_pair(SESSIONS, GROUP_NON_BLOCKING));
262 registry()->SetEnabledDirectoryTypes(routing_info); 257 registry()->SetEnabledDirectoryTypes(routing_info);
263 258
264 // Only Autofill and Themes types finished initial sync. 259 // Only Autofill and Themes types finished initial sync.
265 MarkInitialSyncEndedForDirectoryType(AUTOFILL); 260 MarkInitialSyncEndedForDirectoryType(AUTOFILL);
266 261
267 sync_pb::DataTypeState data_type_state = MakeInitialDataTypeState(THEMES); 262 sync_pb::DataTypeState data_type_state = MakeInitialDataTypeState(THEMES);
268 data_type_state.set_initial_sync_done(true); 263 data_type_state.set_initial_sync_done(true);
269 registry()->ConnectType( 264 registry()->ConnectType(
270 syncer::THEMES, 265 THEMES,
271 MakeActivationContext( 266 MakeActivationContext(data_type_state,
272 data_type_state, 267 base::WrapUnique(new FakeModelTypeProcessor())));
273 base::WrapUnique(new syncer_v2::FakeModelTypeProcessor())));
274 268
275 EXPECT_EQ(ModelTypeSet(AUTOFILL, THEMES), 269 EXPECT_EQ(ModelTypeSet(AUTOFILL, THEMES),
276 registry()->GetInitialSyncEndedTypes()); 270 registry()->GetInitialSyncEndedTypes());
277 } 271 }
278 272
279 } // namespace syncer 273 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/model_type_registry.cc ('k') | components/sync/engine_impl/model_type_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698