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

Side by Side Diff: components/sync_driver/model_association_manager_unittest.cc

Issue 317453002: sync: cut a few profile deps from DataTypeControllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move OnUserShareReady Created 6 years, 6 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
« no previous file with comments | « components/sync_driver/model_association_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "components/sync_driver/fake_data_type_controller.h" 7 #include "components/sync_driver/fake_data_type_controller.h"
8 #include "components/sync_driver/model_association_manager.h" 8 #include "components/sync_driver/model_association_manager.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using ::testing::_; 12 using ::testing::_;
13 namespace browser_sync { 13 namespace browser_sync {
14 class MockModelAssociationResultProcessor : 14 class MockModelAssociationManagerDelegate :
15 public ModelAssociationResultProcessor { 15 public ModelAssociationManagerDelegate {
16 public: 16 public:
17 MockModelAssociationResultProcessor() {} 17 MockModelAssociationManagerDelegate() {}
18 ~MockModelAssociationResultProcessor() {} 18 ~MockModelAssociationManagerDelegate() {}
19 MOCK_METHOD2(OnSingleDataTypeAssociationDone, 19 MOCK_METHOD2(OnSingleDataTypeAssociationDone,
20 void(syncer::ModelType type, 20 void(syncer::ModelType type,
21 const syncer::DataTypeAssociationStats& association_stats)); 21 const syncer::DataTypeAssociationStats& association_stats));
22 MOCK_METHOD1(OnSingleDataTypeWillStop, void(syncer::ModelType));
22 MOCK_METHOD1(OnModelAssociationDone, void( 23 MOCK_METHOD1(OnModelAssociationDone, void(
23 const DataTypeManager::ConfigureResult& result)); 24 const DataTypeManager::ConfigureResult& result));
24 }; 25 };
25 26
26 FakeDataTypeController* GetController( 27 FakeDataTypeController* GetController(
27 const DataTypeController::TypeMap& controllers, 28 const DataTypeController::TypeMap& controllers,
28 syncer::ModelType model_type) { 29 syncer::ModelType model_type) {
29 DataTypeController::TypeMap::const_iterator it = 30 DataTypeController::TypeMap::const_iterator it =
30 controllers.find(model_type); 31 controllers.find(model_type);
31 if (it == controllers.end()) { 32 if (it == controllers.end()) {
(...skipping 23 matching lines...) Expand all
55 expected_result.unfinished_data_types)); 56 expected_result.unfinished_data_types));
56 } 57 }
57 58
58 class SyncModelAssociationManagerTest : public testing::Test { 59 class SyncModelAssociationManagerTest : public testing::Test {
59 public: 60 public:
60 SyncModelAssociationManagerTest() { 61 SyncModelAssociationManagerTest() {
61 } 62 }
62 63
63 protected: 64 protected:
64 base::MessageLoopForUI ui_loop_; 65 base::MessageLoopForUI ui_loop_;
65 MockModelAssociationResultProcessor result_processor_; 66 MockModelAssociationManagerDelegate delegate_;
66 DataTypeController::TypeMap controllers_; 67 DataTypeController::TypeMap controllers_;
67 }; 68 };
68 69
69 // Start a type and make sure ModelAssociationManager callst the |Start| 70 // Start a type and make sure ModelAssociationManager callst the |Start|
70 // method and calls the callback when it is done. 71 // method and calls the callback when it is done.
71 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { 72 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) {
72 controllers_[syncer::BOOKMARKS] = 73 controllers_[syncer::BOOKMARKS] =
73 new FakeDataTypeController(syncer::BOOKMARKS); 74 new FakeDataTypeController(syncer::BOOKMARKS);
74 controllers_[syncer::APPS] = 75 controllers_[syncer::APPS] =
75 new FakeDataTypeController(syncer::APPS); 76 new FakeDataTypeController(syncer::APPS);
76 ModelAssociationManager model_association_manager(&controllers_, 77 ModelAssociationManager model_association_manager(&controllers_,
77 &result_processor_); 78 &delegate_);
78 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); 79 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS);
79 DataTypeManager::ConfigureResult expected_result( 80 DataTypeManager::ConfigureResult expected_result(
80 DataTypeManager::OK, 81 DataTypeManager::OK,
81 types, 82 types,
82 std::map<syncer::ModelType, syncer::SyncError>(), 83 std::map<syncer::ModelType, syncer::SyncError>(),
83 syncer::ModelTypeSet(), 84 syncer::ModelTypeSet(),
84 syncer::ModelTypeSet()); 85 syncer::ModelTypeSet());
85 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 86 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
86 WillOnce(VerifyResult(expected_result)); 87 WillOnce(VerifyResult(expected_result));
87 88
88 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 89 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
89 DataTypeController::NOT_RUNNING); 90 DataTypeController::NOT_RUNNING);
90 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), 91 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
91 DataTypeController::NOT_RUNNING); 92 DataTypeController::NOT_RUNNING);
92 93
93 // Initialize() kicks off model loading. 94 // Initialize() kicks off model loading.
94 model_association_manager.Initialize(types); 95 model_association_manager.Initialize(types);
95 96
(...skipping 13 matching lines...) Expand all
109 GetController(controllers_, syncer::APPS)->FinishStart( 110 GetController(controllers_, syncer::APPS)->FinishStart(
110 DataTypeController::OK); 111 DataTypeController::OK);
111 } 112 }
112 113
113 // Start a type and call stop before it finishes associating. 114 // Start a type and call stop before it finishes associating.
114 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { 115 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) {
115 controllers_[syncer::BOOKMARKS] = 116 controllers_[syncer::BOOKMARKS] =
116 new FakeDataTypeController(syncer::BOOKMARKS); 117 new FakeDataTypeController(syncer::BOOKMARKS);
117 ModelAssociationManager model_association_manager( 118 ModelAssociationManager model_association_manager(
118 &controllers_, 119 &controllers_,
119 &result_processor_); 120 &delegate_);
120 121
121 syncer::ModelTypeSet types; 122 syncer::ModelTypeSet types;
122 types.Put(syncer::BOOKMARKS); 123 types.Put(syncer::BOOKMARKS);
123 124
124 std::map<syncer::ModelType, syncer::SyncError> errors; 125 std::map<syncer::ModelType, syncer::SyncError> errors;
125 syncer::SyncError error(FROM_HERE, 126 syncer::SyncError error(FROM_HERE,
126 syncer::SyncError::DATATYPE_ERROR, 127 syncer::SyncError::DATATYPE_ERROR,
127 "Failed", 128 "Failed",
128 syncer::BOOKMARKS); 129 syncer::BOOKMARKS);
129 errors[syncer::BOOKMARKS] = error; 130 errors[syncer::BOOKMARKS] = error;
130 131
131 DataTypeManager::ConfigureResult expected_result( 132 DataTypeManager::ConfigureResult expected_result(
132 DataTypeManager::ABORTED, 133 DataTypeManager::ABORTED,
133 types, 134 types,
134 errors, 135 errors,
135 syncer::ModelTypeSet(syncer::BOOKMARKS), 136 syncer::ModelTypeSet(syncer::BOOKMARKS),
136 syncer::ModelTypeSet()); 137 syncer::ModelTypeSet());
137 138
138 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 139 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
139 WillOnce(VerifyResult(expected_result)); 140 WillOnce(VerifyResult(expected_result));
141 EXPECT_CALL(delegate_,
142 OnSingleDataTypeWillStop(syncer::BOOKMARKS));
140 143
141 model_association_manager.Initialize(types); 144 model_association_manager.Initialize(types);
142 model_association_manager.StartAssociationAsync(types); 145 model_association_manager.StartAssociationAsync(types);
143 146
144 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 147 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
145 DataTypeController::ASSOCIATING); 148 DataTypeController::ASSOCIATING);
146 model_association_manager.Stop(); 149 model_association_manager.Stop();
147 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 150 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
148 DataTypeController::NOT_RUNNING); 151 DataTypeController::NOT_RUNNING);
149 } 152 }
150 153
151 // Start a type, let it finish and then call stop. 154 // Start a type, let it finish and then call stop.
152 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { 155 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) {
153 controllers_[syncer::BOOKMARKS] = 156 controllers_[syncer::BOOKMARKS] =
154 new FakeDataTypeController(syncer::BOOKMARKS); 157 new FakeDataTypeController(syncer::BOOKMARKS);
155 ModelAssociationManager model_association_manager( 158 ModelAssociationManager model_association_manager(
156 &controllers_, 159 &controllers_,
157 &result_processor_); 160 &delegate_);
158 syncer::ModelTypeSet types; 161 syncer::ModelTypeSet types;
159 types.Put(syncer::BOOKMARKS); 162 types.Put(syncer::BOOKMARKS);
160 DataTypeManager::ConfigureResult expected_result( 163 DataTypeManager::ConfigureResult expected_result(
161 DataTypeManager::OK, 164 DataTypeManager::OK,
162 types, 165 types,
163 std::map<syncer::ModelType, syncer::SyncError>(), 166 std::map<syncer::ModelType, syncer::SyncError>(),
164 syncer::ModelTypeSet(), 167 syncer::ModelTypeSet(),
165 syncer::ModelTypeSet()); 168 syncer::ModelTypeSet());
166 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 169 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
167 WillOnce(VerifyResult(expected_result)); 170 WillOnce(VerifyResult(expected_result));
171 EXPECT_CALL(delegate_,
172 OnSingleDataTypeWillStop(syncer::BOOKMARKS));
168 173
169 model_association_manager.Initialize(types); 174 model_association_manager.Initialize(types);
170 model_association_manager.StartAssociationAsync(types); 175 model_association_manager.StartAssociationAsync(types);
171 176
172 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 177 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
173 DataTypeController::ASSOCIATING); 178 DataTypeController::ASSOCIATING);
174 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( 179 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
175 DataTypeController::OK); 180 DataTypeController::OK);
176 181
177 model_association_manager.Stop(); 182 model_association_manager.Stop();
178 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 183 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
179 DataTypeController::NOT_RUNNING); 184 DataTypeController::NOT_RUNNING);
180 } 185 }
181 186
182 // Make a type fail model association and verify correctness. 187 // Make a type fail model association and verify correctness.
183 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { 188 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) {
184 controllers_[syncer::BOOKMARKS] = 189 controllers_[syncer::BOOKMARKS] =
185 new FakeDataTypeController(syncer::BOOKMARKS); 190 new FakeDataTypeController(syncer::BOOKMARKS);
186 ModelAssociationManager model_association_manager( 191 ModelAssociationManager model_association_manager(
187 &controllers_, 192 &controllers_,
188 &result_processor_); 193 &delegate_);
189 syncer::ModelTypeSet types; 194 syncer::ModelTypeSet types;
190 types.Put(syncer::BOOKMARKS); 195 types.Put(syncer::BOOKMARKS);
191 std::map<syncer::ModelType, syncer::SyncError> errors; 196 std::map<syncer::ModelType, syncer::SyncError> errors;
192 syncer::SyncError error(FROM_HERE, 197 syncer::SyncError error(FROM_HERE,
193 syncer::SyncError::DATATYPE_ERROR, 198 syncer::SyncError::DATATYPE_ERROR,
194 "Failed", 199 "Failed",
195 syncer::BOOKMARKS); 200 syncer::BOOKMARKS);
196 errors[syncer::BOOKMARKS] = error; 201 errors[syncer::BOOKMARKS] = error;
197 DataTypeManager::ConfigureResult expected_result( 202 DataTypeManager::ConfigureResult expected_result(
198 DataTypeManager::PARTIAL_SUCCESS, 203 DataTypeManager::PARTIAL_SUCCESS,
199 types, 204 types,
200 errors, 205 errors,
201 syncer::ModelTypeSet(), 206 syncer::ModelTypeSet(),
202 syncer::ModelTypeSet()); 207 syncer::ModelTypeSet());
203 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 208 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
204 WillOnce(VerifyResult(expected_result)); 209 WillOnce(VerifyResult(expected_result));
205 210
206 model_association_manager.Initialize(types); 211 model_association_manager.Initialize(types);
207 model_association_manager.StartAssociationAsync(types); 212 model_association_manager.StartAssociationAsync(types);
208 213
209 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 214 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
210 DataTypeController::ASSOCIATING); 215 DataTypeController::ASSOCIATING);
211 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( 216 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
212 DataTypeController::ASSOCIATION_FAILED); 217 DataTypeController::ASSOCIATION_FAILED);
213 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 218 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
214 DataTypeController::NOT_RUNNING); 219 DataTypeController::NOT_RUNNING);
215 } 220 }
216 221
217 // Ensure configuring stops when a type returns a unrecoverable error. 222 // Ensure configuring stops when a type returns a unrecoverable error.
218 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { 223 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) {
219 controllers_[syncer::BOOKMARKS] = 224 controllers_[syncer::BOOKMARKS] =
220 new FakeDataTypeController(syncer::BOOKMARKS); 225 new FakeDataTypeController(syncer::BOOKMARKS);
221 ModelAssociationManager model_association_manager( 226 ModelAssociationManager model_association_manager(
222 &controllers_, 227 &controllers_,
223 &result_processor_); 228 &delegate_);
224 syncer::ModelTypeSet types; 229 syncer::ModelTypeSet types;
225 types.Put(syncer::BOOKMARKS); 230 types.Put(syncer::BOOKMARKS);
226 std::map<syncer::ModelType, syncer::SyncError> errors; 231 std::map<syncer::ModelType, syncer::SyncError> errors;
227 syncer::SyncError error(FROM_HERE, 232 syncer::SyncError error(FROM_HERE,
228 syncer::SyncError::DATATYPE_ERROR, 233 syncer::SyncError::DATATYPE_ERROR,
229 "Failed", 234 "Failed",
230 syncer::BOOKMARKS); 235 syncer::BOOKMARKS);
231 errors[syncer::BOOKMARKS] = error; 236 errors[syncer::BOOKMARKS] = error;
232 DataTypeManager::ConfigureResult expected_result( 237 DataTypeManager::ConfigureResult expected_result(
233 DataTypeManager::UNRECOVERABLE_ERROR, 238 DataTypeManager::UNRECOVERABLE_ERROR,
234 types, 239 types,
235 errors, 240 errors,
236 syncer::ModelTypeSet(), 241 syncer::ModelTypeSet(),
237 syncer::ModelTypeSet()); 242 syncer::ModelTypeSet());
238 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 243 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
239 WillOnce(VerifyResult(expected_result)); 244 WillOnce(VerifyResult(expected_result));
240 245
241 model_association_manager.Initialize(types); 246 model_association_manager.Initialize(types);
242 247
243 model_association_manager.StartAssociationAsync(types); 248 model_association_manager.StartAssociationAsync(types);
244 249
245 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 250 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
246 DataTypeController::ASSOCIATING); 251 DataTypeController::ASSOCIATING);
247 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( 252 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
248 DataTypeController::UNRECOVERABLE_ERROR); 253 DataTypeController::UNRECOVERABLE_ERROR);
249 } 254 }
250 255
251 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { 256 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) {
252 controllers_[syncer::BOOKMARKS] = 257 controllers_[syncer::BOOKMARKS] =
253 new FakeDataTypeController(syncer::BOOKMARKS); 258 new FakeDataTypeController(syncer::BOOKMARKS);
254 controllers_[syncer::APPS] = 259 controllers_[syncer::APPS] =
255 new FakeDataTypeController(syncer::APPS); 260 new FakeDataTypeController(syncer::APPS);
256 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); 261 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad();
257 ModelAssociationManager model_association_manager(&controllers_, 262 ModelAssociationManager model_association_manager(&controllers_,
258 &result_processor_); 263 &delegate_);
259 syncer::ModelTypeSet types; 264 syncer::ModelTypeSet types;
260 types.Put(syncer::BOOKMARKS); 265 types.Put(syncer::BOOKMARKS);
261 types.Put(syncer::APPS); 266 types.Put(syncer::APPS);
262 267
263 std::map<syncer::ModelType, syncer::SyncError> errors; 268 std::map<syncer::ModelType, syncer::SyncError> errors;
264 syncer::SyncError error(FROM_HERE, 269 syncer::SyncError error(FROM_HERE,
265 syncer::SyncError::DATATYPE_ERROR, 270 syncer::SyncError::DATATYPE_ERROR,
266 "Association timed out.", 271 "Association timed out.",
267 syncer::BOOKMARKS); 272 syncer::BOOKMARKS);
268 errors[syncer::BOOKMARKS] = error; 273 errors[syncer::BOOKMARKS] = error;
269 274
270 syncer::ModelTypeSet expected_types_unfinished; 275 syncer::ModelTypeSet expected_types_unfinished;
271 expected_types_unfinished.Put(syncer::BOOKMARKS); 276 expected_types_unfinished.Put(syncer::BOOKMARKS);
272 DataTypeManager::ConfigureResult expected_result_partially_done( 277 DataTypeManager::ConfigureResult expected_result_partially_done(
273 DataTypeManager::PARTIAL_SUCCESS, 278 DataTypeManager::PARTIAL_SUCCESS,
274 types, 279 types,
275 errors, 280 errors,
276 expected_types_unfinished, 281 expected_types_unfinished,
277 syncer::ModelTypeSet()); 282 syncer::ModelTypeSet());
278 283
279 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 284 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
280 WillOnce(VerifyResult(expected_result_partially_done)); 285 WillOnce(VerifyResult(expected_result_partially_done));
281 286
282 model_association_manager.Initialize(types); 287 model_association_manager.Initialize(types);
283 model_association_manager.StartAssociationAsync(types); 288 model_association_manager.StartAssociationAsync(types);
284 GetController(controllers_, syncer::APPS)->FinishStart( 289 GetController(controllers_, syncer::APPS)->FinishStart(
285 DataTypeController::OK); 290 DataTypeController::OK);
286 291
287 model_association_manager.GetTimerForTesting()->user_task().Run(); 292 model_association_manager.GetTimerForTesting()->user_task().Run();
288 293
289 EXPECT_EQ(DataTypeController::NOT_RUNNING, 294 EXPECT_EQ(DataTypeController::NOT_RUNNING,
290 GetController(controllers_, syncer::BOOKMARKS)->state()); 295 GetController(controllers_, syncer::BOOKMARKS)->state());
291 } 296 }
292 297
293 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { 298 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) {
294 controllers_[syncer::BOOKMARKS] = 299 controllers_[syncer::BOOKMARKS] =
295 new FakeDataTypeController(syncer::BOOKMARKS); 300 new FakeDataTypeController(syncer::BOOKMARKS);
296 controllers_[syncer::APPS] = 301 controllers_[syncer::APPS] =
297 new FakeDataTypeController(syncer::APPS); 302 new FakeDataTypeController(syncer::APPS);
298 ModelAssociationManager model_association_manager(&controllers_, 303 ModelAssociationManager model_association_manager(&controllers_,
299 &result_processor_); 304 &delegate_);
300 syncer::ModelTypeSet types; 305 syncer::ModelTypeSet types;
301 types.Put(syncer::BOOKMARKS); 306 types.Put(syncer::BOOKMARKS);
302 types.Put(syncer::APPS); 307 types.Put(syncer::APPS);
303 308
304 DataTypeManager::ConfigureResult result_1st( 309 DataTypeManager::ConfigureResult result_1st(
305 DataTypeManager::OK, 310 DataTypeManager::OK,
306 syncer::ModelTypeSet(syncer::BOOKMARKS), 311 syncer::ModelTypeSet(syncer::BOOKMARKS),
307 std::map<syncer::ModelType, syncer::SyncError>(), 312 std::map<syncer::ModelType, syncer::SyncError>(),
308 syncer::ModelTypeSet(), 313 syncer::ModelTypeSet(),
309 syncer::ModelTypeSet()); 314 syncer::ModelTypeSet());
310 DataTypeManager::ConfigureResult result_2nd( 315 DataTypeManager::ConfigureResult result_2nd(
311 DataTypeManager::OK, 316 DataTypeManager::OK,
312 syncer::ModelTypeSet(syncer::APPS), 317 syncer::ModelTypeSet(syncer::APPS),
313 std::map<syncer::ModelType, syncer::SyncError>(), 318 std::map<syncer::ModelType, syncer::SyncError>(),
314 syncer::ModelTypeSet(), 319 syncer::ModelTypeSet(),
315 syncer::ModelTypeSet()); 320 syncer::ModelTypeSet());
316 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 321 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
317 Times(2). 322 Times(2).
318 WillOnce(VerifyResult(result_1st)). 323 WillOnce(VerifyResult(result_1st)).
319 WillOnce(VerifyResult(result_2nd)); 324 WillOnce(VerifyResult(result_2nd));
320 325
321 model_association_manager.Initialize(types); 326 model_association_manager.Initialize(types);
322 327
323 // Start BOOKMARKS first. 328 // Start BOOKMARKS first.
324 model_association_manager.StartAssociationAsync( 329 model_association_manager.StartAssociationAsync(
325 syncer::ModelTypeSet(syncer::BOOKMARKS)); 330 syncer::ModelTypeSet(syncer::BOOKMARKS));
326 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), 331 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
(...skipping 23 matching lines...) Expand all
350 // Test that model that failed to load between initialization and association 355 // Test that model that failed to load between initialization and association
351 // is reported and stopped properly. 356 // is reported and stopped properly.
352 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { 357 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) {
353 controllers_[syncer::BOOKMARKS] = 358 controllers_[syncer::BOOKMARKS] =
354 new FakeDataTypeController(syncer::BOOKMARKS); 359 new FakeDataTypeController(syncer::BOOKMARKS);
355 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError( 360 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError(
356 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, 361 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
357 "", syncer::BOOKMARKS)); 362 "", syncer::BOOKMARKS));
358 ModelAssociationManager model_association_manager( 363 ModelAssociationManager model_association_manager(
359 &controllers_, 364 &controllers_,
360 &result_processor_); 365 &delegate_);
361 syncer::ModelTypeSet types; 366 syncer::ModelTypeSet types;
362 types.Put(syncer::BOOKMARKS); 367 types.Put(syncer::BOOKMARKS);
363 std::map<syncer::ModelType, syncer::SyncError> errors; 368 std::map<syncer::ModelType, syncer::SyncError> errors;
364 syncer::SyncError error(FROM_HERE, 369 syncer::SyncError error(FROM_HERE,
365 syncer::SyncError::DATATYPE_ERROR, 370 syncer::SyncError::DATATYPE_ERROR,
366 "Failed", 371 "Failed",
367 syncer::BOOKMARKS); 372 syncer::BOOKMARKS);
368 errors[syncer::BOOKMARKS] = error; 373 errors[syncer::BOOKMARKS] = error;
369 DataTypeManager::ConfigureResult expected_result( 374 DataTypeManager::ConfigureResult expected_result(
370 DataTypeManager::PARTIAL_SUCCESS, 375 DataTypeManager::PARTIAL_SUCCESS,
371 types, 376 types,
372 errors, 377 errors,
373 syncer::ModelTypeSet(), 378 syncer::ModelTypeSet(),
374 syncer::ModelTypeSet()); 379 syncer::ModelTypeSet());
375 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). 380 EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
376 WillOnce(VerifyResult(expected_result)); 381 WillOnce(VerifyResult(expected_result));
377 382
378 model_association_manager.Initialize(types); 383 model_association_manager.Initialize(types);
379 EXPECT_EQ(DataTypeController::DISABLED, 384 EXPECT_EQ(DataTypeController::DISABLED,
380 GetController(controllers_, syncer::BOOKMARKS)->state()); 385 GetController(controllers_, syncer::BOOKMARKS)->state());
381 model_association_manager.StartAssociationAsync(types); 386 model_association_manager.StartAssociationAsync(types);
382 EXPECT_EQ(DataTypeController::NOT_RUNNING, 387 EXPECT_EQ(DataTypeController::NOT_RUNNING,
383 GetController(controllers_, syncer::BOOKMARKS)->state()); 388 GetController(controllers_, syncer::BOOKMARKS)->state());
384 } 389 }
385 390
386 } // namespace browser_sync 391 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/model_association_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698