OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 6 #include "base/message_loop.h" |
7 #include "chrome/browser/sync/glue/fake_data_type_controller.h" | 7 #include "chrome/browser/sync/glue/fake_data_type_controller.h" |
8 #include "chrome/browser/sync/glue/model_association_manager.h" | 8 #include "chrome/browser/sync/glue/model_association_manager.h" |
9 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 ACTION_P(VerifyResult, expected_result) { | 36 ACTION_P(VerifyResult, expected_result) { |
37 EXPECT_EQ(arg0.status, expected_result.status); | 37 EXPECT_EQ(arg0.status, expected_result.status); |
38 EXPECT_TRUE(arg0.requested_types.Equals(expected_result.requested_types)); | 38 EXPECT_TRUE(arg0.requested_types.Equals(expected_result.requested_types)); |
39 EXPECT_EQ(arg0.failed_data_types.size(), | 39 EXPECT_EQ(arg0.failed_data_types.size(), |
40 expected_result.failed_data_types.size()); | 40 expected_result.failed_data_types.size()); |
41 | 41 |
42 if (arg0.failed_data_types.size() == | 42 if (arg0.failed_data_types.size() == |
43 expected_result.failed_data_types.size()) { | 43 expected_result.failed_data_types.size()) { |
44 std::list<SyncError>::const_iterator it1, it2; | 44 std::list<csync::SyncError>::const_iterator it1, it2; |
45 for (it1 = arg0.failed_data_types.begin(), | 45 for (it1 = arg0.failed_data_types.begin(), |
46 it2 = expected_result.failed_data_types.begin(); | 46 it2 = expected_result.failed_data_types.begin(); |
47 it1 != arg0.failed_data_types.end(); | 47 it1 != arg0.failed_data_types.end(); |
48 ++it1, ++it2) { | 48 ++it1, ++it2) { |
49 EXPECT_EQ((*it1).type(), (*it2).type()); | 49 EXPECT_EQ((*it1).type(), (*it2).type()); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 EXPECT_TRUE(arg0.waiting_to_start.Equals(expected_result.waiting_to_start)); | 53 EXPECT_TRUE(arg0.waiting_to_start.Equals(expected_result.waiting_to_start)); |
54 } | 54 } |
(...skipping 16 matching lines...) Expand all Loading... |
71 TEST_F(ModelAssociationManagerTest, SimpleModelStart) { | 71 TEST_F(ModelAssociationManagerTest, SimpleModelStart) { |
72 controllers_[syncable::BOOKMARKS] = | 72 controllers_[syncable::BOOKMARKS] = |
73 new FakeDataTypeController(syncable::BOOKMARKS); | 73 new FakeDataTypeController(syncable::BOOKMARKS); |
74 ModelAssociationManager model_association_manager(&controllers_, | 74 ModelAssociationManager model_association_manager(&controllers_, |
75 &result_processor_); | 75 &result_processor_); |
76 syncable::ModelTypeSet types; | 76 syncable::ModelTypeSet types; |
77 types.Put(syncable::BOOKMARKS); | 77 types.Put(syncable::BOOKMARKS); |
78 DataTypeManager::ConfigureResult expected_result( | 78 DataTypeManager::ConfigureResult expected_result( |
79 DataTypeManager::OK, | 79 DataTypeManager::OK, |
80 types, | 80 types, |
81 std::list<SyncError>(), | 81 std::list<csync::SyncError>(), |
82 syncable::ModelTypeSet()); | 82 syncable::ModelTypeSet()); |
83 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 83 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
84 WillOnce(VerifyResult(expected_result)); | 84 WillOnce(VerifyResult(expected_result)); |
85 | 85 |
86 model_association_manager.Initialize(types); | 86 model_association_manager.Initialize(types); |
87 model_association_manager.StopDisabledTypes(); | 87 model_association_manager.StopDisabledTypes(); |
88 model_association_manager.StartAssociationAsync(); | 88 model_association_manager.StartAssociationAsync(); |
89 | 89 |
90 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 90 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), |
91 DataTypeController::MODEL_LOADED); | 91 DataTypeController::MODEL_LOADED); |
92 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 92 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( |
93 DataTypeController::OK); | 93 DataTypeController::OK); |
94 } | 94 } |
95 | 95 |
96 // Start a type and call stop before it finishes associating. | 96 // Start a type and call stop before it finishes associating. |
97 TEST_F(ModelAssociationManagerTest, StopModelBeforeFinish) { | 97 TEST_F(ModelAssociationManagerTest, StopModelBeforeFinish) { |
98 controllers_[syncable::BOOKMARKS] = | 98 controllers_[syncable::BOOKMARKS] = |
99 new FakeDataTypeController(syncable::BOOKMARKS); | 99 new FakeDataTypeController(syncable::BOOKMARKS); |
100 ModelAssociationManager model_association_manager(&controllers_, | 100 ModelAssociationManager model_association_manager(&controllers_, |
101 &result_processor_); | 101 &result_processor_); |
102 | 102 |
103 syncable::ModelTypeSet types; | 103 syncable::ModelTypeSet types; |
104 types.Put(syncable::BOOKMARKS); | 104 types.Put(syncable::BOOKMARKS); |
105 | 105 |
106 DataTypeManager::ConfigureResult expected_result( | 106 DataTypeManager::ConfigureResult expected_result( |
107 DataTypeManager::ABORTED, | 107 DataTypeManager::ABORTED, |
108 types, | 108 types, |
109 std::list<SyncError>(), | 109 std::list<csync::SyncError>(), |
110 syncable::ModelTypeSet()); | 110 syncable::ModelTypeSet()); |
111 | 111 |
112 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 112 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
113 WillOnce(VerifyResult(expected_result)); | 113 WillOnce(VerifyResult(expected_result)); |
114 | 114 |
115 model_association_manager.Initialize(types); | 115 model_association_manager.Initialize(types); |
116 model_association_manager.StopDisabledTypes(); | 116 model_association_manager.StopDisabledTypes(); |
117 model_association_manager.StartAssociationAsync(); | 117 model_association_manager.StartAssociationAsync(); |
118 | 118 |
119 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 119 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), |
120 DataTypeController::MODEL_LOADED); | 120 DataTypeController::MODEL_LOADED); |
121 model_association_manager.Stop(); | 121 model_association_manager.Stop(); |
122 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 122 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), |
123 DataTypeController::NOT_RUNNING); | 123 DataTypeController::NOT_RUNNING); |
124 } | 124 } |
125 | 125 |
126 // Start a type, let it finish and then call stop. | 126 // Start a type, let it finish and then call stop. |
127 TEST_F(ModelAssociationManagerTest, StopAfterFinish) { | 127 TEST_F(ModelAssociationManagerTest, StopAfterFinish) { |
128 controllers_[syncable::BOOKMARKS] = | 128 controllers_[syncable::BOOKMARKS] = |
129 new FakeDataTypeController(syncable::BOOKMARKS); | 129 new FakeDataTypeController(syncable::BOOKMARKS); |
130 ModelAssociationManager model_association_manager(&controllers_, | 130 ModelAssociationManager model_association_manager(&controllers_, |
131 &result_processor_); | 131 &result_processor_); |
132 syncable::ModelTypeSet types; | 132 syncable::ModelTypeSet types; |
133 types.Put(syncable::BOOKMARKS); | 133 types.Put(syncable::BOOKMARKS); |
134 DataTypeManager::ConfigureResult expected_result( | 134 DataTypeManager::ConfigureResult expected_result( |
135 DataTypeManager::OK, | 135 DataTypeManager::OK, |
136 types, | 136 types, |
137 std::list<SyncError>(), | 137 std::list<csync::SyncError>(), |
138 syncable::ModelTypeSet()); | 138 syncable::ModelTypeSet()); |
139 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 139 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
140 WillOnce(VerifyResult(expected_result)); | 140 WillOnce(VerifyResult(expected_result)); |
141 | 141 |
142 model_association_manager.Initialize(types); | 142 model_association_manager.Initialize(types); |
143 model_association_manager.StopDisabledTypes(); | 143 model_association_manager.StopDisabledTypes(); |
144 model_association_manager.StartAssociationAsync(); | 144 model_association_manager.StartAssociationAsync(); |
145 | 145 |
146 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 146 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), |
147 DataTypeController::MODEL_LOADED); | 147 DataTypeController::MODEL_LOADED); |
148 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 148 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( |
149 DataTypeController::OK); | 149 DataTypeController::OK); |
150 | 150 |
151 model_association_manager.Stop(); | 151 model_association_manager.Stop(); |
152 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 152 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), |
153 DataTypeController::NOT_RUNNING); | 153 DataTypeController::NOT_RUNNING); |
154 } | 154 } |
155 | 155 |
156 // Make a type fail model association and verify correctness. | 156 // Make a type fail model association and verify correctness. |
157 TEST_F(ModelAssociationManagerTest, TypeFailModelAssociation) { | 157 TEST_F(ModelAssociationManagerTest, TypeFailModelAssociation) { |
158 controllers_[syncable::BOOKMARKS] = | 158 controllers_[syncable::BOOKMARKS] = |
159 new FakeDataTypeController(syncable::BOOKMARKS); | 159 new FakeDataTypeController(syncable::BOOKMARKS); |
160 ModelAssociationManager model_association_manager(&controllers_, | 160 ModelAssociationManager model_association_manager(&controllers_, |
161 &result_processor_); | 161 &result_processor_); |
162 syncable::ModelTypeSet types; | 162 syncable::ModelTypeSet types; |
163 types.Put(syncable::BOOKMARKS); | 163 types.Put(syncable::BOOKMARKS); |
164 std::list<SyncError> errors; | 164 std::list<csync::SyncError> errors; |
165 SyncError error(FROM_HERE, "Failed", syncable::BOOKMARKS); | 165 csync::SyncError error(FROM_HERE, "Failed", syncable::BOOKMARKS); |
166 errors.push_back(error); | 166 errors.push_back(error); |
167 DataTypeManager::ConfigureResult expected_result( | 167 DataTypeManager::ConfigureResult expected_result( |
168 DataTypeManager::PARTIAL_SUCCESS, | 168 DataTypeManager::PARTIAL_SUCCESS, |
169 types, | 169 types, |
170 errors, | 170 errors, |
171 syncable::ModelTypeSet()); | 171 syncable::ModelTypeSet()); |
172 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 172 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
173 WillOnce(VerifyResult(expected_result)); | 173 WillOnce(VerifyResult(expected_result)); |
174 | 174 |
175 model_association_manager.Initialize(types); | 175 model_association_manager.Initialize(types); |
176 model_association_manager.StopDisabledTypes(); | 176 model_association_manager.StopDisabledTypes(); |
177 model_association_manager.StartAssociationAsync(); | 177 model_association_manager.StartAssociationAsync(); |
178 | 178 |
179 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 179 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), |
180 DataTypeController::MODEL_LOADED); | 180 DataTypeController::MODEL_LOADED); |
181 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 181 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( |
182 DataTypeController::ASSOCIATION_FAILED); | 182 DataTypeController::ASSOCIATION_FAILED); |
183 } | 183 } |
184 | 184 |
185 // Ensure configuring stops when a type returns a unrecoverable error. | 185 // Ensure configuring stops when a type returns a unrecoverable error. |
186 TEST_F(ModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 186 TEST_F(ModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
187 controllers_[syncable::BOOKMARKS] = | 187 controllers_[syncable::BOOKMARKS] = |
188 new FakeDataTypeController(syncable::BOOKMARKS); | 188 new FakeDataTypeController(syncable::BOOKMARKS); |
189 ModelAssociationManager model_association_manager(&controllers_, | 189 ModelAssociationManager model_association_manager(&controllers_, |
190 &result_processor_); | 190 &result_processor_); |
191 syncable::ModelTypeSet types; | 191 syncable::ModelTypeSet types; |
192 types.Put(syncable::BOOKMARKS); | 192 types.Put(syncable::BOOKMARKS); |
193 std::list<SyncError> errors; | 193 std::list<csync::SyncError> errors; |
194 SyncError error(FROM_HERE, "Failed", syncable::BOOKMARKS); | 194 csync::SyncError error(FROM_HERE, "Failed", syncable::BOOKMARKS); |
195 errors.push_back(error); | 195 errors.push_back(error); |
196 DataTypeManager::ConfigureResult expected_result( | 196 DataTypeManager::ConfigureResult expected_result( |
197 DataTypeManager::UNRECOVERABLE_ERROR, | 197 DataTypeManager::UNRECOVERABLE_ERROR, |
198 types, | 198 types, |
199 errors, | 199 errors, |
200 syncable::ModelTypeSet()); | 200 syncable::ModelTypeSet()); |
201 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 201 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
202 WillOnce(VerifyResult(expected_result)); | 202 WillOnce(VerifyResult(expected_result)); |
203 | 203 |
204 model_association_manager.Initialize(types); | 204 model_association_manager.Initialize(types); |
(...skipping 18 matching lines...) Expand all Loading... |
223 &result_processor_); | 223 &result_processor_); |
224 syncable::ModelTypeSet types; | 224 syncable::ModelTypeSet types; |
225 types.Put(syncable::BOOKMARKS); | 225 types.Put(syncable::BOOKMARKS); |
226 types.Put(syncable::APPS); | 226 types.Put(syncable::APPS); |
227 | 227 |
228 syncable::ModelTypeSet expected_types_waiting_to_load; | 228 syncable::ModelTypeSet expected_types_waiting_to_load; |
229 expected_types_waiting_to_load.Put(syncable::BOOKMARKS); | 229 expected_types_waiting_to_load.Put(syncable::BOOKMARKS); |
230 DataTypeManager::ConfigureResult expected_result_partially_done( | 230 DataTypeManager::ConfigureResult expected_result_partially_done( |
231 DataTypeManager::PARTIAL_SUCCESS, | 231 DataTypeManager::PARTIAL_SUCCESS, |
232 types, | 232 types, |
233 std::list<SyncError>(), | 233 std::list<csync::SyncError>(), |
234 expected_types_waiting_to_load); | 234 expected_types_waiting_to_load); |
235 | 235 |
236 DataTypeManager::ConfigureResult expected_result_done( | 236 DataTypeManager::ConfigureResult expected_result_done( |
237 DataTypeManager::OK, | 237 DataTypeManager::OK, |
238 types, | 238 types, |
239 std::list<SyncError>(), | 239 std::list<csync::SyncError>(), |
240 syncable::ModelTypeSet()); | 240 syncable::ModelTypeSet()); |
241 | 241 |
242 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 242 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
243 WillOnce(VerifyResult(expected_result_partially_done)); | 243 WillOnce(VerifyResult(expected_result_partially_done)); |
244 EXPECT_CALL(result_processor_, OnTypesLoaded()); | 244 EXPECT_CALL(result_processor_, OnTypesLoaded()); |
245 | 245 |
246 model_association_manager.Initialize(types); | 246 model_association_manager.Initialize(types); |
247 model_association_manager.StopDisabledTypes(); | 247 model_association_manager.StopDisabledTypes(); |
248 model_association_manager.StartAssociationAsync(); | 248 model_association_manager.StartAssociationAsync(); |
249 | 249 |
(...skipping 25 matching lines...) Expand all Loading... |
275 GetController(controllers_, | 275 GetController(controllers_, |
276 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); | 276 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); |
277 | 277 |
278 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 278 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( |
279 DataTypeController::OK); | 279 DataTypeController::OK); |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 } // namespace browser_sync | 283 } // namespace browser_sync |
284 | 284 |
OLD | NEW |