OLD | NEW |
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 | 13 |
14 namespace sync_driver { | 14 namespace sync_driver { |
15 | 15 |
16 class MockModelAssociationManagerDelegate : | 16 class MockModelAssociationManagerDelegate : |
17 public ModelAssociationManagerDelegate { | 17 public ModelAssociationManagerDelegate { |
18 public: | 18 public: |
19 MockModelAssociationManagerDelegate() {} | 19 MockModelAssociationManagerDelegate() {} |
20 ~MockModelAssociationManagerDelegate() {} | 20 ~MockModelAssociationManagerDelegate() {} |
21 MOCK_METHOD2(OnSingleDataTypeAssociationDone, | 21 MOCK_METHOD2(OnSingleDataTypeAssociationDone, |
22 void(syncer::ModelType type, | 22 void(syncer::ModelType type, |
23 const syncer::DataTypeAssociationStats& association_stats)); | 23 const syncer::DataTypeAssociationStats& association_stats)); |
24 MOCK_METHOD1(OnSingleDataTypeWillStop, void(syncer::ModelType)); | 24 MOCK_METHOD2(OnSingleDataTypeWillStop, |
| 25 void(syncer::ModelType, const syncer::SyncError& error)); |
25 MOCK_METHOD1(OnModelAssociationDone, void( | 26 MOCK_METHOD1(OnModelAssociationDone, void( |
26 const DataTypeManager::ConfigureResult& result)); | 27 const DataTypeManager::ConfigureResult& result)); |
27 }; | 28 }; |
28 | 29 |
29 FakeDataTypeController* GetController( | 30 FakeDataTypeController* GetController( |
30 const DataTypeController::TypeMap& controllers, | 31 const DataTypeController::TypeMap& controllers, |
31 syncer::ModelType model_type) { | 32 syncer::ModelType model_type) { |
32 DataTypeController::TypeMap::const_iterator it = | 33 DataTypeController::TypeMap::const_iterator it = |
33 controllers.find(model_type); | 34 controllers.find(model_type); |
34 if (it == controllers.end()) { | 35 if (it == controllers.end()) { |
35 return NULL; | 36 return NULL; |
36 } | 37 } |
37 return (FakeDataTypeController*)(it->second.get()); | 38 return (FakeDataTypeController*)(it->second.get()); |
38 } | 39 } |
39 | 40 |
40 ACTION_P(VerifyResult, expected_result) { | 41 ACTION_P(VerifyResult, expected_result) { |
41 EXPECT_EQ(arg0.status, expected_result.status); | 42 EXPECT_EQ(arg0.status, expected_result.status); |
42 EXPECT_TRUE(arg0.requested_types.Equals(expected_result.requested_types)); | 43 EXPECT_TRUE(arg0.requested_types.Equals(expected_result.requested_types)); |
43 EXPECT_EQ(arg0.failed_data_types.size(), | |
44 expected_result.failed_data_types.size()); | |
45 | |
46 if (arg0.failed_data_types.size() == | |
47 expected_result.failed_data_types.size()) { | |
48 std::map<syncer::ModelType, syncer::SyncError>::const_iterator it1, it2; | |
49 for (it1 = arg0.failed_data_types.begin(), | |
50 it2 = expected_result.failed_data_types.begin(); | |
51 it1 != arg0.failed_data_types.end(); | |
52 ++it1, ++it2) { | |
53 EXPECT_EQ((*it1).first, (*it2).first); | |
54 } | |
55 } | |
56 | |
57 EXPECT_TRUE(arg0.unfinished_data_types.Equals( | |
58 expected_result.unfinished_data_types)); | |
59 } | 44 } |
60 | 45 |
61 class SyncModelAssociationManagerTest : public testing::Test { | 46 class SyncModelAssociationManagerTest : public testing::Test { |
62 public: | 47 public: |
63 SyncModelAssociationManagerTest() { | 48 SyncModelAssociationManagerTest() { |
64 } | 49 } |
65 | 50 |
66 protected: | 51 protected: |
67 base::MessageLoopForUI ui_loop_; | 52 base::MessageLoopForUI ui_loop_; |
68 MockModelAssociationManagerDelegate delegate_; | 53 MockModelAssociationManagerDelegate delegate_; |
69 DataTypeController::TypeMap controllers_; | 54 DataTypeController::TypeMap controllers_; |
70 }; | 55 }; |
71 | 56 |
72 // Start a type and make sure ModelAssociationManager callst the |Start| | 57 // Start a type and make sure ModelAssociationManager callst the |Start| |
73 // method and calls the callback when it is done. | 58 // method and calls the callback when it is done. |
74 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { | 59 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
75 controllers_[syncer::BOOKMARKS] = | 60 controllers_[syncer::BOOKMARKS] = |
76 new FakeDataTypeController(syncer::BOOKMARKS); | 61 new FakeDataTypeController(syncer::BOOKMARKS); |
77 controllers_[syncer::APPS] = | 62 controllers_[syncer::APPS] = |
78 new FakeDataTypeController(syncer::APPS); | 63 new FakeDataTypeController(syncer::APPS); |
79 ModelAssociationManager model_association_manager(&controllers_, | 64 ModelAssociationManager model_association_manager(&controllers_, |
80 &delegate_); | 65 &delegate_); |
81 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 66 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
82 DataTypeManager::ConfigureResult expected_result( | 67 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
83 DataTypeManager::OK, | |
84 types, | |
85 std::map<syncer::ModelType, syncer::SyncError>(), | |
86 syncer::ModelTypeSet(), | |
87 syncer::ModelTypeSet()); | |
88 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 68 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
89 WillOnce(VerifyResult(expected_result)); | 69 WillOnce(VerifyResult(expected_result)); |
90 | 70 |
91 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 71 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
92 DataTypeController::NOT_RUNNING); | 72 DataTypeController::NOT_RUNNING); |
93 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 73 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
94 DataTypeController::NOT_RUNNING); | 74 DataTypeController::NOT_RUNNING); |
95 | 75 |
96 // Initialize() kicks off model loading. | 76 // Initialize() kicks off model loading. |
97 model_association_manager.Initialize(types); | 77 model_association_manager.Initialize(types); |
(...skipping 19 matching lines...) Expand all Loading... |
117 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { | 97 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
118 controllers_[syncer::BOOKMARKS] = | 98 controllers_[syncer::BOOKMARKS] = |
119 new FakeDataTypeController(syncer::BOOKMARKS); | 99 new FakeDataTypeController(syncer::BOOKMARKS); |
120 ModelAssociationManager model_association_manager( | 100 ModelAssociationManager model_association_manager( |
121 &controllers_, | 101 &controllers_, |
122 &delegate_); | 102 &delegate_); |
123 | 103 |
124 syncer::ModelTypeSet types; | 104 syncer::ModelTypeSet types; |
125 types.Put(syncer::BOOKMARKS); | 105 types.Put(syncer::BOOKMARKS); |
126 | 106 |
127 std::map<syncer::ModelType, syncer::SyncError> errors; | 107 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, |
128 syncer::SyncError error(FROM_HERE, | 108 types); |
129 syncer::SyncError::DATATYPE_ERROR, | |
130 "Failed", | |
131 syncer::BOOKMARKS); | |
132 errors[syncer::BOOKMARKS] = error; | |
133 | |
134 DataTypeManager::ConfigureResult expected_result( | |
135 DataTypeManager::ABORTED, | |
136 types, | |
137 errors, | |
138 syncer::ModelTypeSet(syncer::BOOKMARKS), | |
139 syncer::ModelTypeSet()); | |
140 | 109 |
141 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 110 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
142 WillOnce(VerifyResult(expected_result)); | 111 WillOnce(VerifyResult(expected_result)); |
143 EXPECT_CALL(delegate_, | 112 EXPECT_CALL(delegate_, |
144 OnSingleDataTypeWillStop(syncer::BOOKMARKS)); | 113 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
145 | 114 |
146 model_association_manager.Initialize(types); | 115 model_association_manager.Initialize(types); |
147 model_association_manager.StartAssociationAsync(types); | 116 model_association_manager.StartAssociationAsync(types); |
148 | 117 |
149 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 118 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
150 DataTypeController::ASSOCIATING); | 119 DataTypeController::ASSOCIATING); |
151 model_association_manager.Stop(); | 120 model_association_manager.Stop(); |
152 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 121 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
153 DataTypeController::NOT_RUNNING); | 122 DataTypeController::NOT_RUNNING); |
154 } | 123 } |
155 | 124 |
156 // Start a type, let it finish and then call stop. | 125 // Start a type, let it finish and then call stop. |
157 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { | 126 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
158 controllers_[syncer::BOOKMARKS] = | 127 controllers_[syncer::BOOKMARKS] = |
159 new FakeDataTypeController(syncer::BOOKMARKS); | 128 new FakeDataTypeController(syncer::BOOKMARKS); |
160 ModelAssociationManager model_association_manager( | 129 ModelAssociationManager model_association_manager( |
161 &controllers_, | 130 &controllers_, |
162 &delegate_); | 131 &delegate_); |
163 syncer::ModelTypeSet types; | 132 syncer::ModelTypeSet types; |
164 types.Put(syncer::BOOKMARKS); | 133 types.Put(syncer::BOOKMARKS); |
165 DataTypeManager::ConfigureResult expected_result( | 134 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
166 DataTypeManager::OK, | |
167 types, | |
168 std::map<syncer::ModelType, syncer::SyncError>(), | |
169 syncer::ModelTypeSet(), | |
170 syncer::ModelTypeSet()); | |
171 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 135 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
172 WillOnce(VerifyResult(expected_result)); | 136 WillOnce(VerifyResult(expected_result)); |
173 EXPECT_CALL(delegate_, | 137 EXPECT_CALL(delegate_, |
174 OnSingleDataTypeWillStop(syncer::BOOKMARKS)); | 138 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
175 | 139 |
176 model_association_manager.Initialize(types); | 140 model_association_manager.Initialize(types); |
177 model_association_manager.StartAssociationAsync(types); | 141 model_association_manager.StartAssociationAsync(types); |
178 | 142 |
179 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 143 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
180 DataTypeController::ASSOCIATING); | 144 DataTypeController::ASSOCIATING); |
181 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 145 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
182 DataTypeController::OK); | 146 DataTypeController::OK); |
183 | 147 |
184 model_association_manager.Stop(); | 148 model_association_manager.Stop(); |
185 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 149 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
186 DataTypeController::NOT_RUNNING); | 150 DataTypeController::NOT_RUNNING); |
187 } | 151 } |
188 | 152 |
189 // Make a type fail model association and verify correctness. | 153 // Make a type fail model association and verify correctness. |
190 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { | 154 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
191 controllers_[syncer::BOOKMARKS] = | 155 controllers_[syncer::BOOKMARKS] = |
192 new FakeDataTypeController(syncer::BOOKMARKS); | 156 new FakeDataTypeController(syncer::BOOKMARKS); |
193 ModelAssociationManager model_association_manager( | 157 ModelAssociationManager model_association_manager( |
194 &controllers_, | 158 &controllers_, |
195 &delegate_); | 159 &delegate_); |
196 syncer::ModelTypeSet types; | 160 syncer::ModelTypeSet types; |
197 types.Put(syncer::BOOKMARKS); | 161 types.Put(syncer::BOOKMARKS); |
198 std::map<syncer::ModelType, syncer::SyncError> errors; | 162 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
199 syncer::SyncError error(FROM_HERE, | 163 EXPECT_CALL(delegate_, |
200 syncer::SyncError::DATATYPE_ERROR, | 164 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
201 "Failed", | |
202 syncer::BOOKMARKS); | |
203 errors[syncer::BOOKMARKS] = error; | |
204 DataTypeManager::ConfigureResult expected_result( | |
205 DataTypeManager::PARTIAL_SUCCESS, | |
206 types, | |
207 errors, | |
208 syncer::ModelTypeSet(), | |
209 syncer::ModelTypeSet()); | |
210 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 165 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
211 WillOnce(VerifyResult(expected_result)); | 166 WillOnce(VerifyResult(expected_result)); |
212 | 167 |
213 model_association_manager.Initialize(types); | 168 model_association_manager.Initialize(types); |
214 model_association_manager.StartAssociationAsync(types); | 169 model_association_manager.StartAssociationAsync(types); |
215 | 170 |
216 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 171 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
217 DataTypeController::ASSOCIATING); | 172 DataTypeController::ASSOCIATING); |
218 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 173 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
219 DataTypeController::ASSOCIATION_FAILED); | 174 DataTypeController::ASSOCIATION_FAILED); |
220 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 175 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
221 DataTypeController::NOT_RUNNING); | 176 DataTypeController::NOT_RUNNING); |
222 } | 177 } |
223 | 178 |
224 // Ensure configuring stops when a type returns a unrecoverable error. | 179 // Ensure configuring stops when a type returns a unrecoverable error. |
225 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 180 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
226 controllers_[syncer::BOOKMARKS] = | 181 controllers_[syncer::BOOKMARKS] = |
227 new FakeDataTypeController(syncer::BOOKMARKS); | 182 new FakeDataTypeController(syncer::BOOKMARKS); |
228 ModelAssociationManager model_association_manager( | 183 ModelAssociationManager model_association_manager( |
229 &controllers_, | 184 &controllers_, |
230 &delegate_); | 185 &delegate_); |
231 syncer::ModelTypeSet types; | 186 syncer::ModelTypeSet types; |
232 types.Put(syncer::BOOKMARKS); | 187 types.Put(syncer::BOOKMARKS); |
233 std::map<syncer::ModelType, syncer::SyncError> errors; | |
234 syncer::SyncError error(FROM_HERE, | |
235 syncer::SyncError::DATATYPE_ERROR, | |
236 "Failed", | |
237 syncer::BOOKMARKS); | |
238 errors[syncer::BOOKMARKS] = error; | |
239 DataTypeManager::ConfigureResult expected_result( | 188 DataTypeManager::ConfigureResult expected_result( |
240 DataTypeManager::UNRECOVERABLE_ERROR, | 189 DataTypeManager::UNRECOVERABLE_ERROR, types); |
241 types, | 190 EXPECT_CALL(delegate_, |
242 errors, | 191 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
243 syncer::ModelTypeSet(), | |
244 syncer::ModelTypeSet()); | |
245 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 192 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
246 WillOnce(VerifyResult(expected_result)); | 193 WillOnce(VerifyResult(expected_result)); |
247 | 194 |
248 model_association_manager.Initialize(types); | 195 model_association_manager.Initialize(types); |
249 | 196 |
250 model_association_manager.StartAssociationAsync(types); | 197 model_association_manager.StartAssociationAsync(types); |
251 | 198 |
252 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 199 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
253 DataTypeController::ASSOCIATING); | 200 DataTypeController::ASSOCIATING); |
254 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 201 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
255 DataTypeController::UNRECOVERABLE_ERROR); | 202 DataTypeController::UNRECOVERABLE_ERROR); |
256 } | 203 } |
257 | 204 |
258 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { | 205 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
259 controllers_[syncer::BOOKMARKS] = | 206 controllers_[syncer::BOOKMARKS] = |
260 new FakeDataTypeController(syncer::BOOKMARKS); | 207 new FakeDataTypeController(syncer::BOOKMARKS); |
261 controllers_[syncer::APPS] = | 208 controllers_[syncer::APPS] = |
262 new FakeDataTypeController(syncer::APPS); | 209 new FakeDataTypeController(syncer::APPS); |
263 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | 210 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
264 ModelAssociationManager model_association_manager(&controllers_, | 211 ModelAssociationManager model_association_manager(&controllers_, |
265 &delegate_); | 212 &delegate_); |
266 syncer::ModelTypeSet types; | 213 syncer::ModelTypeSet types; |
267 types.Put(syncer::BOOKMARKS); | 214 types.Put(syncer::BOOKMARKS); |
268 types.Put(syncer::APPS); | 215 types.Put(syncer::APPS); |
269 | 216 |
270 std::map<syncer::ModelType, syncer::SyncError> errors; | |
271 syncer::SyncError error(FROM_HERE, | |
272 syncer::SyncError::DATATYPE_ERROR, | |
273 "Association timed out.", | |
274 syncer::BOOKMARKS); | |
275 errors[syncer::BOOKMARKS] = error; | |
276 | |
277 syncer::ModelTypeSet expected_types_unfinished; | 217 syncer::ModelTypeSet expected_types_unfinished; |
278 expected_types_unfinished.Put(syncer::BOOKMARKS); | 218 expected_types_unfinished.Put(syncer::BOOKMARKS); |
279 DataTypeManager::ConfigureResult expected_result_partially_done( | 219 DataTypeManager::ConfigureResult expected_result_partially_done( |
280 DataTypeManager::PARTIAL_SUCCESS, | 220 DataTypeManager::OK, types); |
281 types, | |
282 errors, | |
283 expected_types_unfinished, | |
284 syncer::ModelTypeSet()); | |
285 | 221 |
286 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 222 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
287 WillOnce(VerifyResult(expected_result_partially_done)); | 223 WillOnce(VerifyResult(expected_result_partially_done)); |
288 | 224 |
289 model_association_manager.Initialize(types); | 225 model_association_manager.Initialize(types); |
290 model_association_manager.StartAssociationAsync(types); | 226 model_association_manager.StartAssociationAsync(types); |
291 GetController(controllers_, syncer::APPS)->FinishStart( | 227 GetController(controllers_, syncer::APPS)->FinishStart( |
292 DataTypeController::OK); | 228 DataTypeController::OK); |
293 | 229 |
| 230 EXPECT_CALL(delegate_, |
| 231 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
294 model_association_manager.GetTimerForTesting()->user_task().Run(); | 232 model_association_manager.GetTimerForTesting()->user_task().Run(); |
295 | 233 |
296 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 234 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
297 GetController(controllers_, syncer::BOOKMARKS)->state()); | 235 GetController(controllers_, syncer::BOOKMARKS)->state()); |
298 } | 236 } |
299 | 237 |
300 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { | 238 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
301 controllers_[syncer::BOOKMARKS] = | 239 controllers_[syncer::BOOKMARKS] = |
302 new FakeDataTypeController(syncer::BOOKMARKS); | 240 new FakeDataTypeController(syncer::BOOKMARKS); |
303 controllers_[syncer::APPS] = | 241 controllers_[syncer::APPS] = |
304 new FakeDataTypeController(syncer::APPS); | 242 new FakeDataTypeController(syncer::APPS); |
305 ModelAssociationManager model_association_manager(&controllers_, | 243 ModelAssociationManager model_association_manager(&controllers_, |
306 &delegate_); | 244 &delegate_); |
307 syncer::ModelTypeSet types; | 245 syncer::ModelTypeSet types; |
308 types.Put(syncer::BOOKMARKS); | 246 types.Put(syncer::BOOKMARKS); |
309 types.Put(syncer::APPS); | 247 types.Put(syncer::APPS); |
310 | 248 |
311 DataTypeManager::ConfigureResult result_1st( | 249 DataTypeManager::ConfigureResult result_1st( |
312 DataTypeManager::OK, | 250 DataTypeManager::OK, |
313 syncer::ModelTypeSet(syncer::BOOKMARKS), | 251 syncer::ModelTypeSet(syncer::BOOKMARKS)); |
314 std::map<syncer::ModelType, syncer::SyncError>(), | |
315 syncer::ModelTypeSet(), | |
316 syncer::ModelTypeSet()); | |
317 DataTypeManager::ConfigureResult result_2nd( | 252 DataTypeManager::ConfigureResult result_2nd( |
318 DataTypeManager::OK, | 253 DataTypeManager::OK, |
319 syncer::ModelTypeSet(syncer::APPS), | 254 syncer::ModelTypeSet(syncer::APPS)); |
320 std::map<syncer::ModelType, syncer::SyncError>(), | |
321 syncer::ModelTypeSet(), | |
322 syncer::ModelTypeSet()); | |
323 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 255 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
324 Times(2). | 256 Times(2). |
325 WillOnce(VerifyResult(result_1st)). | 257 WillOnce(VerifyResult(result_1st)). |
326 WillOnce(VerifyResult(result_2nd)); | 258 WillOnce(VerifyResult(result_2nd)); |
327 | 259 |
328 model_association_manager.Initialize(types); | 260 model_association_manager.Initialize(types); |
329 | 261 |
330 // Start BOOKMARKS first. | 262 // Start BOOKMARKS first. |
331 model_association_manager.StartAssociationAsync( | 263 model_association_manager.StartAssociationAsync( |
332 syncer::ModelTypeSet(syncer::BOOKMARKS)); | 264 syncer::ModelTypeSet(syncer::BOOKMARKS)); |
(...skipping 27 matching lines...) Expand all Loading... |
360 controllers_[syncer::BOOKMARKS] = | 292 controllers_[syncer::BOOKMARKS] = |
361 new FakeDataTypeController(syncer::BOOKMARKS); | 293 new FakeDataTypeController(syncer::BOOKMARKS); |
362 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError( | 294 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError( |
363 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, | 295 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, |
364 "", syncer::BOOKMARKS)); | 296 "", syncer::BOOKMARKS)); |
365 ModelAssociationManager model_association_manager( | 297 ModelAssociationManager model_association_manager( |
366 &controllers_, | 298 &controllers_, |
367 &delegate_); | 299 &delegate_); |
368 syncer::ModelTypeSet types; | 300 syncer::ModelTypeSet types; |
369 types.Put(syncer::BOOKMARKS); | 301 types.Put(syncer::BOOKMARKS); |
370 std::map<syncer::ModelType, syncer::SyncError> errors; | 302 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
371 syncer::SyncError error(FROM_HERE, | 303 EXPECT_CALL(delegate_, |
372 syncer::SyncError::DATATYPE_ERROR, | 304 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
373 "Failed", | |
374 syncer::BOOKMARKS); | |
375 errors[syncer::BOOKMARKS] = error; | |
376 DataTypeManager::ConfigureResult expected_result( | |
377 DataTypeManager::PARTIAL_SUCCESS, | |
378 types, | |
379 errors, | |
380 syncer::ModelTypeSet(), | |
381 syncer::ModelTypeSet()); | |
382 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 305 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
383 WillOnce(VerifyResult(expected_result)); | 306 WillOnce(VerifyResult(expected_result)); |
384 | 307 |
385 model_association_manager.Initialize(types); | 308 model_association_manager.Initialize(types); |
386 EXPECT_EQ(DataTypeController::DISABLED, | 309 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
387 GetController(controllers_, syncer::BOOKMARKS)->state()); | 310 GetController(controllers_, syncer::BOOKMARKS)->state()); |
388 model_association_manager.StartAssociationAsync(types); | 311 model_association_manager.StartAssociationAsync(types); |
389 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 312 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
390 GetController(controllers_, syncer::BOOKMARKS)->state()); | 313 GetController(controllers_, syncer::BOOKMARKS)->state()); |
391 } | 314 } |
392 | 315 |
| 316 // Test that a runtime error is handled by stopping the type. |
| 317 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
| 318 controllers_[syncer::BOOKMARKS] = |
| 319 new FakeDataTypeController(syncer::BOOKMARKS); |
| 320 ModelAssociationManager model_association_manager( |
| 321 &controllers_, |
| 322 &delegate_); |
| 323 syncer::ModelTypeSet types; |
| 324 types.Put(syncer::BOOKMARKS); |
| 325 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 326 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
| 327 WillOnce(VerifyResult(expected_result)); |
| 328 |
| 329 model_association_manager.Initialize(types); |
| 330 model_association_manager.StartAssociationAsync(types); |
| 331 |
| 332 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 333 DataTypeController::ASSOCIATING); |
| 334 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 335 DataTypeController::OK); |
| 336 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 337 DataTypeController::RUNNING); |
| 338 |
| 339 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 340 EXPECT_CALL(delegate_, |
| 341 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 342 GetController(controllers_, syncer::BOOKMARKS) |
| 343 ->OnSingleDatatypeUnrecoverableError(FROM_HERE, "runtime error"); |
| 344 } |
| 345 |
393 } // namespace sync_driver | 346 } // namespace sync_driver |
OLD | NEW |