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