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 "components/sync/driver/model_association_manager.h" | 5 #include "components/sync/driver/model_association_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "components/sync/driver/fake_data_type_controller.h" | 11 #include "components/sync/driver/fake_data_type_controller.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using ::testing::_; | 15 using ::testing::_; |
16 | 16 |
17 namespace sync_driver { | 17 namespace syncer { |
18 | 18 |
19 class MockModelAssociationManagerDelegate | 19 class MockModelAssociationManagerDelegate |
20 : public ModelAssociationManagerDelegate { | 20 : public ModelAssociationManagerDelegate { |
21 public: | 21 public: |
22 MockModelAssociationManagerDelegate() {} | 22 MockModelAssociationManagerDelegate() {} |
23 ~MockModelAssociationManagerDelegate() {} | 23 ~MockModelAssociationManagerDelegate() {} |
24 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); | 24 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); |
25 MOCK_METHOD2(OnSingleDataTypeAssociationDone, | 25 MOCK_METHOD2(OnSingleDataTypeAssociationDone, |
26 void(syncer::ModelType type, | 26 void(ModelType type, |
27 const syncer::DataTypeAssociationStats& association_stats)); | 27 const DataTypeAssociationStats& association_stats)); |
28 MOCK_METHOD2(OnSingleDataTypeWillStop, | 28 MOCK_METHOD2(OnSingleDataTypeWillStop, |
29 void(syncer::ModelType, const syncer::SyncError& error)); | 29 void(ModelType, const SyncError& error)); |
30 MOCK_METHOD1(OnModelAssociationDone, | 30 MOCK_METHOD1(OnModelAssociationDone, |
31 void(const DataTypeManager::ConfigureResult& result)); | 31 void(const DataTypeManager::ConfigureResult& result)); |
32 }; | 32 }; |
33 | 33 |
34 FakeDataTypeController* GetController( | 34 FakeDataTypeController* GetController( |
35 const DataTypeController::TypeMap& controllers, | 35 const DataTypeController::TypeMap& controllers, |
36 syncer::ModelType model_type) { | 36 ModelType model_type) { |
37 DataTypeController::TypeMap::const_iterator it = controllers.find(model_type); | 37 DataTypeController::TypeMap::const_iterator it = controllers.find(model_type); |
38 if (it == controllers.end()) { | 38 if (it == controllers.end()) { |
39 return NULL; | 39 return NULL; |
40 } | 40 } |
41 return static_cast<FakeDataTypeController*>(it->second.get()); | 41 return static_cast<FakeDataTypeController*>(it->second.get()); |
42 } | 42 } |
43 | 43 |
44 ACTION_P(VerifyResult, expected_result) { | 44 ACTION_P(VerifyResult, expected_result) { |
45 EXPECT_EQ(arg0.status, expected_result.status); | 45 EXPECT_EQ(arg0.status, expected_result.status); |
46 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); | 46 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); |
47 } | 47 } |
48 | 48 |
49 class SyncModelAssociationManagerTest : public testing::Test { | 49 class SyncModelAssociationManagerTest : public testing::Test { |
50 public: | 50 public: |
51 SyncModelAssociationManagerTest() {} | 51 SyncModelAssociationManagerTest() {} |
52 | 52 |
53 protected: | 53 protected: |
54 base::MessageLoopForUI ui_loop_; | 54 base::MessageLoopForUI ui_loop_; |
55 MockModelAssociationManagerDelegate delegate_; | 55 MockModelAssociationManagerDelegate delegate_; |
56 DataTypeController::TypeMap controllers_; | 56 DataTypeController::TypeMap controllers_; |
57 }; | 57 }; |
58 | 58 |
59 // Start a type and make sure ModelAssociationManager callst the |Start| | 59 // Start a type and make sure ModelAssociationManager callst the |Start| |
60 // method and calls the callback when it is done. | 60 // method and calls the callback when it is done. |
61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { | 61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
62 controllers_[syncer::BOOKMARKS] = | 62 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
63 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 63 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
64 controllers_[syncer::APPS] = | |
65 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | |
66 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 64 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
67 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 65 ModelTypeSet types(BOOKMARKS, APPS); |
68 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 66 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
69 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 67 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
70 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 68 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
71 .WillOnce(VerifyResult(expected_result)); | 69 .WillOnce(VerifyResult(expected_result)); |
72 | 70 |
73 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 71 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
74 DataTypeController::NOT_RUNNING); | 72 DataTypeController::NOT_RUNNING); |
75 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 73 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
76 DataTypeController::NOT_RUNNING); | 74 DataTypeController::NOT_RUNNING); |
77 | 75 |
78 // Initialize() kicks off model loading. | 76 // Initialize() kicks off model loading. |
79 model_association_manager.Initialize(types); | 77 model_association_manager.Initialize(types); |
80 | 78 |
81 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 79 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
82 DataTypeController::MODEL_LOADED); | 80 DataTypeController::MODEL_LOADED); |
83 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 81 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
84 DataTypeController::MODEL_LOADED); | 82 DataTypeController::MODEL_LOADED); |
85 | 83 |
86 model_association_manager.StartAssociationAsync(types); | 84 model_association_manager.StartAssociationAsync(types); |
87 | 85 |
88 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 86 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
89 DataTypeController::ASSOCIATING); | 87 DataTypeController::ASSOCIATING); |
90 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 88 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
91 DataTypeController::ASSOCIATING); | 89 DataTypeController::ASSOCIATING); |
92 GetController(controllers_, syncer::BOOKMARKS) | 90 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); |
93 ->FinishStart(DataTypeController::OK); | 91 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); |
94 GetController(controllers_, syncer::APPS) | |
95 ->FinishStart(DataTypeController::OK); | |
96 } | 92 } |
97 | 93 |
98 // Start a type and call stop before it finishes associating. | 94 // Start a type and call stop before it finishes associating. |
99 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { | 95 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
100 controllers_[syncer::BOOKMARKS] = | 96 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
101 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | |
102 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 97 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
103 | 98 |
104 syncer::ModelTypeSet types; | 99 ModelTypeSet types; |
105 types.Put(syncer::BOOKMARKS); | 100 types.Put(BOOKMARKS); |
106 | 101 |
107 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, | 102 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, |
108 types); | 103 types); |
109 | 104 |
110 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 105 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
111 .WillOnce(VerifyResult(expected_result)); | 106 .WillOnce(VerifyResult(expected_result)); |
112 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 107 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
113 | 108 |
114 model_association_manager.Initialize(types); | 109 model_association_manager.Initialize(types); |
115 model_association_manager.StartAssociationAsync(types); | 110 model_association_manager.StartAssociationAsync(types); |
116 | 111 |
117 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 112 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
118 DataTypeController::ASSOCIATING); | 113 DataTypeController::ASSOCIATING); |
119 model_association_manager.Stop(); | 114 model_association_manager.Stop(); |
120 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 115 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
121 DataTypeController::NOT_RUNNING); | 116 DataTypeController::NOT_RUNNING); |
122 } | 117 } |
123 | 118 |
124 // Start a type, let it finish and then call stop. | 119 // Start a type, let it finish and then call stop. |
125 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { | 120 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
126 controllers_[syncer::BOOKMARKS] = | 121 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
127 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | |
128 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 122 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
129 syncer::ModelTypeSet types; | 123 ModelTypeSet types; |
130 types.Put(syncer::BOOKMARKS); | 124 types.Put(BOOKMARKS); |
131 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 125 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
132 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 126 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
133 .WillOnce(VerifyResult(expected_result)); | 127 .WillOnce(VerifyResult(expected_result)); |
134 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 128 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
135 | 129 |
136 model_association_manager.Initialize(types); | 130 model_association_manager.Initialize(types); |
137 model_association_manager.StartAssociationAsync(types); | 131 model_association_manager.StartAssociationAsync(types); |
138 | 132 |
139 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 133 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
140 DataTypeController::ASSOCIATING); | 134 DataTypeController::ASSOCIATING); |
141 GetController(controllers_, syncer::BOOKMARKS) | 135 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); |
142 ->FinishStart(DataTypeController::OK); | |
143 | 136 |
144 model_association_manager.Stop(); | 137 model_association_manager.Stop(); |
145 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 138 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
146 DataTypeController::NOT_RUNNING); | 139 DataTypeController::NOT_RUNNING); |
147 } | 140 } |
148 | 141 |
149 // Make a type fail model association and verify correctness. | 142 // Make a type fail model association and verify correctness. |
150 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { | 143 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
151 controllers_[syncer::BOOKMARKS] = | 144 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
152 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | |
153 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 145 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
154 syncer::ModelTypeSet types; | 146 ModelTypeSet types; |
155 types.Put(syncer::BOOKMARKS); | 147 types.Put(BOOKMARKS); |
156 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 148 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
157 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 149 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
158 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 150 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
159 .WillOnce(VerifyResult(expected_result)); | 151 .WillOnce(VerifyResult(expected_result)); |
160 | 152 |
161 model_association_manager.Initialize(types); | 153 model_association_manager.Initialize(types); |
162 model_association_manager.StartAssociationAsync(types); | 154 model_association_manager.StartAssociationAsync(types); |
163 | 155 |
164 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 156 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
165 DataTypeController::ASSOCIATING); | 157 DataTypeController::ASSOCIATING); |
166 GetController(controllers_, syncer::BOOKMARKS) | 158 GetController(controllers_, BOOKMARKS) |
167 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); | 159 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); |
168 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 160 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
169 DataTypeController::NOT_RUNNING); | 161 DataTypeController::NOT_RUNNING); |
170 } | 162 } |
171 | 163 |
172 // Ensure configuring stops when a type returns a unrecoverable error. | 164 // Ensure configuring stops when a type returns a unrecoverable error. |
173 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 165 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
174 controllers_[syncer::BOOKMARKS] = | 166 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
175 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | |
176 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 167 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
177 syncer::ModelTypeSet types; | 168 ModelTypeSet types; |
178 types.Put(syncer::BOOKMARKS); | 169 types.Put(BOOKMARKS); |
179 DataTypeManager::ConfigureResult expected_result( | 170 DataTypeManager::ConfigureResult expected_result( |
180 DataTypeManager::UNRECOVERABLE_ERROR, types); | 171 DataTypeManager::UNRECOVERABLE_ERROR, types); |
181 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 172 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
182 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 173 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
183 .WillOnce(VerifyResult(expected_result)); | 174 .WillOnce(VerifyResult(expected_result)); |
184 | 175 |
185 model_association_manager.Initialize(types); | 176 model_association_manager.Initialize(types); |
186 | 177 |
187 model_association_manager.StartAssociationAsync(types); | 178 model_association_manager.StartAssociationAsync(types); |
188 | 179 |
189 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 180 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
190 DataTypeController::ASSOCIATING); | 181 DataTypeController::ASSOCIATING); |
191 GetController(controllers_, syncer::BOOKMARKS) | 182 GetController(controllers_, BOOKMARKS) |
192 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); | 183 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); |
193 } | 184 } |
194 | 185 |
195 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { | 186 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
196 controllers_[syncer::BOOKMARKS] = | 187 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
197 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 188 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
198 controllers_[syncer::APPS] = | 189 GetController(controllers_, BOOKMARKS)->SetDelayModelLoad(); |
199 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | |
200 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | |
201 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 190 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
202 syncer::ModelTypeSet types; | 191 ModelTypeSet types; |
203 types.Put(syncer::BOOKMARKS); | 192 types.Put(BOOKMARKS); |
204 types.Put(syncer::APPS); | 193 types.Put(APPS); |
205 | 194 |
206 DataTypeManager::ConfigureResult expected_result_partially_done( | 195 DataTypeManager::ConfigureResult expected_result_partially_done( |
207 DataTypeManager::OK, types); | 196 DataTypeManager::OK, types); |
208 | 197 |
209 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 198 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
210 .WillOnce(VerifyResult(expected_result_partially_done)); | 199 .WillOnce(VerifyResult(expected_result_partially_done)); |
211 | 200 |
212 model_association_manager.Initialize(types); | 201 model_association_manager.Initialize(types); |
213 model_association_manager.StartAssociationAsync(types); | 202 model_association_manager.StartAssociationAsync(types); |
214 GetController(controllers_, syncer::APPS) | 203 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); |
215 ->FinishStart(DataTypeController::OK); | |
216 | 204 |
217 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 205 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
218 model_association_manager.GetTimerForTesting()->user_task().Run(); | 206 model_association_manager.GetTimerForTesting()->user_task().Run(); |
219 | 207 |
220 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 208 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
221 GetController(controllers_, syncer::BOOKMARKS)->state()); | 209 GetController(controllers_, BOOKMARKS)->state()); |
222 } | 210 } |
223 | 211 |
224 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { | 212 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
225 controllers_[syncer::BOOKMARKS] = | 213 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
226 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 214 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
227 controllers_[syncer::APPS] = | |
228 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | |
229 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 215 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
230 syncer::ModelTypeSet types; | 216 ModelTypeSet types; |
231 types.Put(syncer::BOOKMARKS); | 217 types.Put(BOOKMARKS); |
232 types.Put(syncer::APPS); | 218 types.Put(APPS); |
233 | 219 |
234 DataTypeManager::ConfigureResult result_1st( | 220 DataTypeManager::ConfigureResult result_1st(DataTypeManager::OK, |
235 DataTypeManager::OK, syncer::ModelTypeSet(syncer::BOOKMARKS)); | 221 ModelTypeSet(BOOKMARKS)); |
236 DataTypeManager::ConfigureResult result_2nd( | 222 DataTypeManager::ConfigureResult result_2nd(DataTypeManager::OK, |
237 DataTypeManager::OK, syncer::ModelTypeSet(syncer::APPS)); | 223 ModelTypeSet(APPS)); |
238 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 224 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
239 .Times(2) | 225 .Times(2) |
240 .WillOnce(VerifyResult(result_1st)) | 226 .WillOnce(VerifyResult(result_1st)) |
241 .WillOnce(VerifyResult(result_2nd)); | 227 .WillOnce(VerifyResult(result_2nd)); |
242 | 228 |
243 model_association_manager.Initialize(types); | 229 model_association_manager.Initialize(types); |
244 | 230 |
245 // Start BOOKMARKS first. | 231 // Start BOOKMARKS first. |
246 model_association_manager.StartAssociationAsync( | 232 model_association_manager.StartAssociationAsync(ModelTypeSet(BOOKMARKS)); |
247 syncer::ModelTypeSet(syncer::BOOKMARKS)); | 233 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
248 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
249 DataTypeController::ASSOCIATING); | 234 DataTypeController::ASSOCIATING); |
250 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 235 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
251 DataTypeController::MODEL_LOADED); | 236 DataTypeController::MODEL_LOADED); |
252 | 237 |
253 // Finish BOOKMARKS association. | 238 // Finish BOOKMARKS association. |
254 GetController(controllers_, syncer::BOOKMARKS) | 239 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); |
255 ->FinishStart(DataTypeController::OK); | 240 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
256 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
257 DataTypeController::RUNNING); | 241 DataTypeController::RUNNING); |
258 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 242 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
259 DataTypeController::MODEL_LOADED); | 243 DataTypeController::MODEL_LOADED); |
260 | 244 |
261 // Start APPS next. | 245 // Start APPS next. |
262 model_association_manager.StartAssociationAsync( | 246 model_association_manager.StartAssociationAsync(ModelTypeSet(APPS)); |
263 syncer::ModelTypeSet(syncer::APPS)); | 247 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
264 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
265 DataTypeController::ASSOCIATING); | 248 DataTypeController::ASSOCIATING); |
266 GetController(controllers_, syncer::APPS) | 249 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); |
267 ->FinishStart(DataTypeController::OK); | 250 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
268 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
269 DataTypeController::RUNNING); | 251 DataTypeController::RUNNING); |
270 } | 252 } |
271 | 253 |
272 // Test that model that failed to load between initialization and association | 254 // Test that model that failed to load between initialization and association |
273 // is reported and stopped properly. | 255 // is reported and stopped properly. |
274 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { | 256 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { |
275 controllers_[syncer::BOOKMARKS] = | 257 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
276 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 258 GetController(controllers_, BOOKMARKS) |
277 GetController(controllers_, syncer::BOOKMARKS) | 259 ->SetModelLoadError( |
278 ->SetModelLoadError(syncer::SyncError( | 260 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "", BOOKMARKS)); |
279 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::BOOKMARKS)); | |
280 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 261 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
281 syncer::ModelTypeSet types; | 262 ModelTypeSet types; |
282 types.Put(syncer::BOOKMARKS); | 263 types.Put(BOOKMARKS); |
283 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 264 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
284 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 265 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
285 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 266 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
286 .WillOnce(VerifyResult(expected_result)); | 267 .WillOnce(VerifyResult(expected_result)); |
287 | 268 |
288 model_association_manager.Initialize(types); | 269 model_association_manager.Initialize(types); |
289 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 270 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
290 GetController(controllers_, syncer::BOOKMARKS)->state()); | 271 GetController(controllers_, BOOKMARKS)->state()); |
291 model_association_manager.StartAssociationAsync(types); | 272 model_association_manager.StartAssociationAsync(types); |
292 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 273 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
293 GetController(controllers_, syncer::BOOKMARKS)->state()); | 274 GetController(controllers_, BOOKMARKS)->state()); |
294 } | 275 } |
295 | 276 |
296 // Test that a runtime error is handled by stopping the type. | 277 // Test that a runtime error is handled by stopping the type. |
297 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { | 278 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
298 controllers_[syncer::BOOKMARKS] = | 279 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
299 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | |
300 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 280 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
301 syncer::ModelTypeSet types; | 281 ModelTypeSet types; |
302 types.Put(syncer::BOOKMARKS); | 282 types.Put(BOOKMARKS); |
303 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 283 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
304 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 284 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
305 .WillOnce(VerifyResult(expected_result)); | 285 .WillOnce(VerifyResult(expected_result)); |
306 | 286 |
307 model_association_manager.Initialize(types); | 287 model_association_manager.Initialize(types); |
308 model_association_manager.StartAssociationAsync(types); | 288 model_association_manager.StartAssociationAsync(types); |
309 | 289 |
310 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 290 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
311 DataTypeController::ASSOCIATING); | 291 DataTypeController::ASSOCIATING); |
312 GetController(controllers_, syncer::BOOKMARKS) | 292 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); |
313 ->FinishStart(DataTypeController::OK); | 293 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
314 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
315 DataTypeController::RUNNING); | 294 DataTypeController::RUNNING); |
316 | 295 |
317 testing::Mock::VerifyAndClearExpectations(&delegate_); | 296 testing::Mock::VerifyAndClearExpectations(&delegate_); |
318 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 297 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
319 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", | 298 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, "error", BOOKMARKS); |
320 syncer::BOOKMARKS); | 299 GetController(controllers_, BOOKMARKS) |
321 GetController(controllers_, syncer::BOOKMARKS) | |
322 ->CreateErrorHandler() | 300 ->CreateErrorHandler() |
323 ->OnUnrecoverableError(error); | 301 ->OnUnrecoverableError(error); |
324 base::RunLoop().RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
325 } | 303 } |
326 | 304 |
327 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { | 305 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { |
328 controllers_[syncer::BOOKMARKS] = | 306 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
329 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 307 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
330 controllers_[syncer::APPS] = | |
331 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | |
332 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 308 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
333 syncer::ModelTypeSet types; | 309 ModelTypeSet types; |
334 types.Put(syncer::BOOKMARKS); | 310 types.Put(BOOKMARKS); |
335 types.Put(syncer::APPS); | 311 types.Put(APPS); |
336 | 312 |
337 syncer::ModelTypeSet expected_types_unfinished; | 313 ModelTypeSet expected_types_unfinished; |
338 expected_types_unfinished.Put(syncer::BOOKMARKS); | 314 expected_types_unfinished.Put(BOOKMARKS); |
339 DataTypeManager::ConfigureResult expected_result_partially_done( | 315 DataTypeManager::ConfigureResult expected_result_partially_done( |
340 DataTypeManager::OK, types); | 316 DataTypeManager::OK, types); |
341 | 317 |
342 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 318 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
343 .WillOnce(VerifyResult(expected_result_partially_done)); | 319 .WillOnce(VerifyResult(expected_result_partially_done)); |
344 | 320 |
345 model_association_manager.Initialize(types); | 321 model_association_manager.Initialize(types); |
346 model_association_manager.StartAssociationAsync(types); | 322 model_association_manager.StartAssociationAsync(types); |
347 GetController(controllers_, syncer::APPS) | 323 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); |
348 ->FinishStart(DataTypeController::OK); | 324 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
349 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
350 DataTypeController::RUNNING); | 325 DataTypeController::RUNNING); |
351 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 326 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
352 DataTypeController::ASSOCIATING); | 327 DataTypeController::ASSOCIATING); |
353 | 328 |
354 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 329 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); |
355 model_association_manager.GetTimerForTesting()->user_task().Run(); | 330 model_association_manager.GetTimerForTesting()->user_task().Run(); |
356 | 331 |
357 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 332 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
358 GetController(controllers_, syncer::BOOKMARKS)->state()); | 333 GetController(controllers_, BOOKMARKS)->state()); |
359 } | 334 } |
360 | 335 |
361 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that | 336 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that |
362 // require LoadModels before configuration are loaded. | 337 // require LoadModels before configuration are loaded. |
363 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { | 338 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { |
364 // Create two controllers with delayed model load. | 339 // Create two controllers with delayed model load. |
365 controllers_[syncer::BOOKMARKS] = | 340 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
366 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 341 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
367 controllers_[syncer::APPS] = | 342 GetController(controllers_, BOOKMARKS)->SetDelayModelLoad(); |
368 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | 343 GetController(controllers_, APPS)->SetDelayModelLoad(); |
369 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | |
370 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | |
371 | 344 |
372 // APPS controller requires LoadModels complete before configure. | 345 // APPS controller requires LoadModels complete before configure. |
373 GetController(controllers_, syncer::APPS) | 346 GetController(controllers_, APPS)->SetShouldLoadModelBeforeConfigure(true); |
374 ->SetShouldLoadModelBeforeConfigure(true); | |
375 | 347 |
376 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 348 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
377 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 349 ModelTypeSet types(BOOKMARKS, APPS); |
378 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 350 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
379 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | 351 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not |
380 // loaded yet. | 352 // loaded yet. |
381 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 353 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
382 | 354 |
383 model_association_manager.Initialize(types); | 355 model_association_manager.Initialize(types); |
384 | 356 |
385 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 357 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
386 DataTypeController::MODEL_STARTING); | 358 DataTypeController::MODEL_STARTING); |
387 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 359 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
388 DataTypeController::MODEL_STARTING); | 360 DataTypeController::MODEL_STARTING); |
389 | 361 |
390 testing::Mock::VerifyAndClearExpectations(&delegate_); | 362 testing::Mock::VerifyAndClearExpectations(&delegate_); |
391 | 363 |
392 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 364 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
393 // Finish loading APPS. This should trigger OnAllDataTypesReadyForConfigure | 365 // Finish loading APPS. This should trigger OnAllDataTypesReadyForConfigure |
394 // even though BOOKMARKS is not loaded yet. | 366 // even though BOOKMARKS is not loaded yet. |
395 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); | 367 GetController(controllers_, APPS)->SimulateModelLoadFinishing(); |
396 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 368 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
397 DataTypeController::MODEL_STARTING); | 369 DataTypeController::MODEL_STARTING); |
398 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 370 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
399 DataTypeController::MODEL_LOADED); | 371 DataTypeController::MODEL_LOADED); |
400 | 372 |
401 // Call ModelAssociationManager::Initialize with reduced set of datatypes. | 373 // Call ModelAssociationManager::Initialize with reduced set of datatypes. |
402 // All datatypes in reduced set are already loaded. | 374 // All datatypes in reduced set are already loaded. |
403 // OnAllDataTypesReadyForConfigure() should be called. | 375 // OnAllDataTypesReadyForConfigure() should be called. |
404 testing::Mock::VerifyAndClearExpectations(&delegate_); | 376 testing::Mock::VerifyAndClearExpectations(&delegate_); |
405 | 377 |
406 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 378 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
407 syncer::ModelTypeSet reduced_types(syncer::APPS); | 379 ModelTypeSet reduced_types(APPS); |
408 model_association_manager.Initialize(reduced_types); | 380 model_association_manager.Initialize(reduced_types); |
409 } | 381 } |
410 | 382 |
411 // Test that OnAllDataTypesReadyForConfigure() is called correctly after | 383 // Test that OnAllDataTypesReadyForConfigure() is called correctly after |
412 // LoadModels fails for one of datatypes. | 384 // LoadModels fails for one of datatypes. |
413 TEST_F(SyncModelAssociationManagerTest, | 385 TEST_F(SyncModelAssociationManagerTest, |
414 OnAllDataTypesReadyForConfigure_FailedLoadModels) { | 386 OnAllDataTypesReadyForConfigure_FailedLoadModels) { |
415 controllers_[syncer::APPS] = | 387 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
416 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | 388 GetController(controllers_, APPS)->SetDelayModelLoad(); |
417 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | |
418 | 389 |
419 // APPS controller requires LoadModels complete before configure. | 390 // APPS controller requires LoadModels complete before configure. |
420 GetController(controllers_, syncer::APPS) | 391 GetController(controllers_, APPS)->SetShouldLoadModelBeforeConfigure(true); |
421 ->SetShouldLoadModelBeforeConfigure(true); | |
422 | 392 |
423 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 393 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
424 syncer::ModelTypeSet types(syncer::APPS); | 394 ModelTypeSet types(APPS); |
425 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 395 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
426 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | 396 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not |
427 // loaded yet. | 397 // loaded yet. |
428 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 398 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
429 | 399 |
430 model_association_manager.Initialize(types); | 400 model_association_manager.Initialize(types); |
431 | 401 |
432 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 402 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
433 DataTypeController::MODEL_STARTING); | 403 DataTypeController::MODEL_STARTING); |
434 | 404 |
435 testing::Mock::VerifyAndClearExpectations(&delegate_); | 405 testing::Mock::VerifyAndClearExpectations(&delegate_); |
436 | 406 |
437 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 407 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
438 // Simulate model load error for APPS and finish loading it. This should | 408 // Simulate model load error for APPS and finish loading it. This should |
439 // trigger OnAllDataTypesReadyForConfigure. | 409 // trigger OnAllDataTypesReadyForConfigure. |
440 GetController(controllers_, syncer::APPS) | 410 GetController(controllers_, APPS) |
441 ->SetModelLoadError(syncer::SyncError( | 411 ->SetModelLoadError( |
442 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::APPS)); | 412 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "", APPS)); |
443 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); | 413 GetController(controllers_, APPS)->SimulateModelLoadFinishing(); |
444 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 414 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
445 DataTypeController::NOT_RUNNING); | 415 DataTypeController::NOT_RUNNING); |
446 } | 416 } |
447 | 417 |
448 // Test that if one of the types fails while another is still being loaded then | 418 // Test that if one of the types fails while another is still being loaded then |
449 // OnAllDataTypesReadyForConfgiure is still called correctly. | 419 // OnAllDataTypesReadyForConfgiure is still called correctly. |
450 TEST_F(SyncModelAssociationManagerTest, | 420 TEST_F(SyncModelAssociationManagerTest, |
451 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { | 421 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { |
452 // Create two controllers with delayed model load. Both should block | 422 // Create two controllers with delayed model load. Both should block |
453 // configuration. | 423 // configuration. |
454 controllers_[syncer::BOOKMARKS] = | 424 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); |
455 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); | 425 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); |
456 controllers_[syncer::APPS] = | 426 GetController(controllers_, BOOKMARKS)->SetDelayModelLoad(); |
457 base::MakeUnique<FakeDataTypeController>(syncer::APPS); | 427 GetController(controllers_, APPS)->SetDelayModelLoad(); |
458 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | |
459 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | |
460 | 428 |
461 GetController(controllers_, syncer::BOOKMARKS) | 429 GetController(controllers_, BOOKMARKS) |
462 ->SetShouldLoadModelBeforeConfigure(true); | 430 ->SetShouldLoadModelBeforeConfigure(true); |
463 GetController(controllers_, syncer::APPS) | 431 GetController(controllers_, APPS)->SetShouldLoadModelBeforeConfigure(true); |
464 ->SetShouldLoadModelBeforeConfigure(true); | |
465 | 432 |
466 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 433 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
467 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 434 ModelTypeSet types(BOOKMARKS, APPS); |
468 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 435 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
469 | 436 |
470 // Apps will finish loading but bookmarks won't. | 437 // Apps will finish loading but bookmarks won't. |
471 // OnAllDataTypesReadyForConfigure shouldn't be called. | 438 // OnAllDataTypesReadyForConfigure shouldn't be called. |
472 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 439 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
473 | 440 |
474 model_association_manager.Initialize(types); | 441 model_association_manager.Initialize(types); |
475 | 442 |
476 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); | 443 GetController(controllers_, APPS)->SimulateModelLoadFinishing(); |
477 | 444 |
478 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 445 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
479 DataTypeController::MODEL_STARTING); | 446 DataTypeController::MODEL_STARTING); |
480 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 447 EXPECT_EQ(GetController(controllers_, APPS)->state(), |
481 DataTypeController::MODEL_LOADED); | 448 DataTypeController::MODEL_LOADED); |
482 | 449 |
483 testing::Mock::VerifyAndClearExpectations(&delegate_); | 450 testing::Mock::VerifyAndClearExpectations(&delegate_); |
484 | 451 |
485 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 452 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
486 | 453 |
487 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::APPS, _)); | 454 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _)); |
488 // Apps datatype reports failure. | 455 // Apps datatype reports failure. |
489 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", | 456 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, "error", APPS); |
490 syncer::APPS); | 457 GetController(controllers_, APPS) |
491 GetController(controllers_, syncer::APPS) | |
492 ->CreateErrorHandler() | 458 ->CreateErrorHandler() |
493 ->OnUnrecoverableError(error); | 459 ->OnUnrecoverableError(error); |
494 base::RunLoop().RunUntilIdle(); | 460 base::RunLoop().RunUntilIdle(); |
495 | 461 |
496 testing::Mock::VerifyAndClearExpectations(&delegate_); | 462 testing::Mock::VerifyAndClearExpectations(&delegate_); |
497 | 463 |
498 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 464 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
499 // Finish loading BOOKMARKS. This should trigger | 465 // Finish loading BOOKMARKS. This should trigger |
500 // OnAllDataTypesReadyForConfigure(). | 466 // OnAllDataTypesReadyForConfigure(). |
501 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); | 467 GetController(controllers_, BOOKMARKS)->SimulateModelLoadFinishing(); |
502 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 468 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), |
503 DataTypeController::MODEL_LOADED); | 469 DataTypeController::MODEL_LOADED); |
504 } | 470 } |
505 | 471 |
506 } // namespace sync_driver | 472 } // namespace syncer |
OLD | NEW |