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

Side by Side Diff: chrome/browser/sync/backend_migrator_unittest.cc

Issue 10832286: sync: Introduce control data types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ToFullModelTypeSet() function Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/sync/backend_migrator.h" 5 #include "chrome/browser/sync/backend_migrator.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/tracked_objects.h" 8 #include "base/tracked_objects.h"
9 #include "chrome/browser/sync/glue/data_type_manager_mock.h" 9 #include "chrome/browser/sync/glue/data_type_manager_mock.h"
10 #include "chrome/browser/sync/profile_sync_service_mock.h" 10 #include "chrome/browser/sync/profile_sync_service_mock.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 migrator()->AddMigrationObserver(&migration_observer); 123 migrator()->AddMigrationObserver(&migration_observer);
124 EXPECT_CALL(migration_observer, OnMigrationStateChange()).Times(4); 124 EXPECT_CALL(migration_observer, OnMigrationStateChange()).Times(4);
125 125
126 syncer::ModelTypeSet to_migrate, difference; 126 syncer::ModelTypeSet to_migrate, difference;
127 to_migrate.Put(syncer::PREFERENCES); 127 to_migrate.Put(syncer::PREFERENCES);
128 difference.Put(syncer::AUTOFILL); 128 difference.Put(syncer::AUTOFILL);
129 difference.Put(syncer::BOOKMARKS); 129 difference.Put(syncer::BOOKMARKS);
130 130
131 EXPECT_CALL(*manager(), state()) 131 EXPECT_CALL(*manager(), state())
132 .WillOnce(Return(DataTypeManager::CONFIGURED)); 132 .WillOnce(Return(DataTypeManager::CONFIGURED));
133 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 133 EXPECT_CALL(
134 .Times(2); 134 *manager(),
135 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
136 EXPECT_CALL(
137 *manager(),
138 Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
135 139
136 migrator()->MigrateTypes(to_migrate); 140 migrator()->MigrateTypes(to_migrate);
137 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 141 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
138 142
139 SetUnsyncedTypes(to_migrate); 143 SetUnsyncedTypes(to_migrate);
140 SendConfigureDone(DataTypeManager::OK, difference); 144 SendConfigureDone(DataTypeManager::OK, difference);
141 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 145 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
142 146
143 SetUnsyncedTypes(syncer::ModelTypeSet()); 147 SetUnsyncedTypes(syncer::ModelTypeSet());
144 SendConfigureDone(DataTypeManager::OK, preferred_types()); 148 SendConfigureDone(DataTypeManager::OK, preferred_types());
145 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); 149 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
146 150
147 migrator()->RemoveMigrationObserver(&migration_observer); 151 migrator()->RemoveMigrationObserver(&migration_observer);
148 } 152 }
149 153
150 // Test that in the normal case with Nigori a migration transitions through 154 // Test that in the normal case with Nigori a migration transitions through
151 // each state and wind up back in IDLE. 155 // each state and wind up back in IDLE.
152 TEST_F(SyncBackendMigratorTest, MigrateNigori) { 156 TEST_F(SyncBackendMigratorTest, MigrateNigori) {
153 syncer::ModelTypeSet to_migrate, difference; 157 syncer::ModelTypeSet to_migrate, difference;
154 to_migrate.Put(syncer::NIGORI); 158 to_migrate.Put(syncer::NIGORI);
155 difference.Put(syncer::AUTOFILL); 159 difference.Put(syncer::AUTOFILL);
156 difference.Put(syncer::BOOKMARKS); 160 difference.Put(syncer::BOOKMARKS);
157 161
158 EXPECT_CALL(*manager(), state()) 162 EXPECT_CALL(*manager(), state())
159 .WillOnce(Return(DataTypeManager::CONFIGURED)); 163 .WillOnce(Return(DataTypeManager::CONFIGURED));
160 164
161 EXPECT_CALL(*manager(), ConfigureWithoutNigori(_, 165 EXPECT_CALL(*manager(), PurgeForMigration(_,
162 syncer::CONFIGURE_REASON_MIGRATION)); 166 syncer::CONFIGURE_REASON_MIGRATION));
163 167
164 migrator()->MigrateTypes(to_migrate); 168 migrator()->MigrateTypes(to_migrate);
165 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 169 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
166 170
167 SetUnsyncedTypes(to_migrate); 171 SetUnsyncedTypes(to_migrate);
168 SendConfigureDone(DataTypeManager::OK, difference); 172 SendConfigureDone(DataTypeManager::OK, difference);
169 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 173 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
170 174
171 SetUnsyncedTypes(syncer::ModelTypeSet()); 175 SetUnsyncedTypes(syncer::ModelTypeSet());
(...skipping 10 matching lines...) Expand all
182 186
183 EXPECT_CALL(*manager(), state()) 187 EXPECT_CALL(*manager(), state())
184 .WillOnce(Return(DataTypeManager::CONFIGURING)); 188 .WillOnce(Return(DataTypeManager::CONFIGURING));
185 EXPECT_CALL(*manager(), Configure(_, _)).Times(0); 189 EXPECT_CALL(*manager(), Configure(_, _)).Times(0);
186 migrator()->MigrateTypes(to_migrate); 190 migrator()->MigrateTypes(to_migrate);
187 EXPECT_EQ(BackendMigrator::WAITING_TO_START, migrator()->state()); 191 EXPECT_EQ(BackendMigrator::WAITING_TO_START, migrator()->state());
188 192
189 Mock::VerifyAndClearExpectations(manager()); 193 Mock::VerifyAndClearExpectations(manager());
190 EXPECT_CALL(*manager(), state()) 194 EXPECT_CALL(*manager(), state())
191 .WillOnce(Return(DataTypeManager::CONFIGURED)); 195 .WillOnce(Return(DataTypeManager::CONFIGURED));
192 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)); 196 EXPECT_CALL(*manager(),
197 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION));
193 SetUnsyncedTypes(syncer::ModelTypeSet()); 198 SetUnsyncedTypes(syncer::ModelTypeSet());
194 SendConfigureDone(DataTypeManager::OK, syncer::ModelTypeSet()); 199 SendConfigureDone(DataTypeManager::OK, syncer::ModelTypeSet());
195 200
196 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 201 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
197 } 202 }
198 203
199 // Test that the migrator can cope with a migration request while a migration 204 // Test that the migrator can cope with a migration request while a migration
200 // is in progress. 205 // is in progress.
201 TEST_F(SyncBackendMigratorTest, RestartMigration) { 206 TEST_F(SyncBackendMigratorTest, RestartMigration) {
202 syncer::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks; 207 syncer::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks;
203 to_migrate1.Put(syncer::PREFERENCES); 208 to_migrate1.Put(syncer::PREFERENCES);
204 to_migrate2.Put(syncer::AUTOFILL); 209 to_migrate2.Put(syncer::AUTOFILL);
205 to_migrate_union.Put(syncer::PREFERENCES); 210 to_migrate_union.Put(syncer::PREFERENCES);
206 to_migrate_union.Put(syncer::AUTOFILL); 211 to_migrate_union.Put(syncer::AUTOFILL);
207 bookmarks.Put(syncer::BOOKMARKS); 212 bookmarks.Put(syncer::BOOKMARKS);
208 213
209 EXPECT_CALL(*manager(), state()) 214 EXPECT_CALL(*manager(), state())
210 .WillOnce(Return(DataTypeManager::CONFIGURED)); 215 .WillOnce(Return(DataTypeManager::CONFIGURED));
211 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 216 EXPECT_CALL(
212 .Times(2); 217 *manager(),
218 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(2);
213 migrator()->MigrateTypes(to_migrate1); 219 migrator()->MigrateTypes(to_migrate1);
214 220
215 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 221 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
216 migrator()->MigrateTypes(to_migrate2); 222 migrator()->MigrateTypes(to_migrate2);
217 223
218 const syncer::ModelTypeSet difference1 = 224 const syncer::ModelTypeSet difference1 =
219 Difference(preferred_types(), to_migrate1); 225 Difference(preferred_types(), to_migrate1);
220 226
221 Mock::VerifyAndClearExpectations(manager()); 227 Mock::VerifyAndClearExpectations(manager());
228 EXPECT_CALL(
229 *manager(),
230 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
222 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 231 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
223 .Times(2); 232 .Times(1);
224 SetUnsyncedTypes(to_migrate1); 233 SetUnsyncedTypes(to_migrate1);
225 SendConfigureDone(DataTypeManager::OK, difference1); 234 SendConfigureDone(DataTypeManager::OK, difference1);
226 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 235 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
227 236
228 SetUnsyncedTypes(to_migrate_union); 237 SetUnsyncedTypes(to_migrate_union);
229 SendConfigureDone(DataTypeManager::OK, bookmarks); 238 SendConfigureDone(DataTypeManager::OK, bookmarks);
230 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 239 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
231 } 240 }
232 241
233 // Test that an external invocation of Configure(...) during a migration results 242 // Test that an external invocation of Configure(...) during a migration results
234 // in a migration reattempt. 243 // in a migration reattempt.
235 TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) { 244 TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) {
236 syncer::ModelTypeSet to_migrate; 245 syncer::ModelTypeSet to_migrate;
237 syncer::ModelTypeSet difference; 246 syncer::ModelTypeSet difference;
238 to_migrate.Put(syncer::PREFERENCES); 247 to_migrate.Put(syncer::PREFERENCES);
239 difference.Put(syncer::AUTOFILL); 248 difference.Put(syncer::AUTOFILL);
240 difference.Put(syncer::BOOKMARKS); 249 difference.Put(syncer::BOOKMARKS);
241 250
242 EXPECT_CALL(*manager(), state()) 251 EXPECT_CALL(*manager(), state())
243 .WillOnce(Return(DataTypeManager::CONFIGURED)); 252 .WillOnce(Return(DataTypeManager::CONFIGURED));
244 EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), 253 EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate),
245 syncer::CONFIGURE_REASON_MIGRATION)); 254 syncer::CONFIGURE_REASON_MIGRATION));
246 migrator()->MigrateTypes(to_migrate); 255 migrator()->MigrateTypes(to_migrate);
247 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 256 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
248 257
249 Mock::VerifyAndClearExpectations(manager()); 258 Mock::VerifyAndClearExpectations(manager());
250 EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), 259 EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate),
251 syncer::CONFIGURE_REASON_MIGRATION)); 260 syncer::CONFIGURE_REASON_MIGRATION));
252 SetUnsyncedTypes(syncer::ModelTypeSet()); 261 SetUnsyncedTypes(syncer::ModelTypeSet());
253 SendConfigureDone(DataTypeManager::OK, preferred_types()); 262 SendConfigureDone(DataTypeManager::OK, preferred_types());
254 263
255 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 264 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
256 } 265 }
257 266
258 // Test that spurious OnConfigureDone events don't confuse the 267 // Test that spurious OnConfigureDone events don't confuse the
259 // migrator while it's waiting for disabled types to have been purged 268 // migrator while it's waiting for disabled types to have been purged
260 // from the sync db. 269 // from the sync db.
261 TEST_F(SyncBackendMigratorTest, WaitingForPurge) { 270 TEST_F(SyncBackendMigratorTest, WaitingForPurge) {
262 syncer::ModelTypeSet to_migrate, difference; 271 syncer::ModelTypeSet to_migrate, difference;
263 to_migrate.Put(syncer::PREFERENCES); 272 to_migrate.Put(syncer::PREFERENCES);
264 to_migrate.Put(syncer::AUTOFILL); 273 to_migrate.Put(syncer::AUTOFILL);
265 difference.Put(syncer::BOOKMARKS); 274 difference.Put(syncer::BOOKMARKS);
266 275
267 EXPECT_CALL(*manager(), state()) 276 EXPECT_CALL(*manager(), state())
268 .WillOnce(Return(DataTypeManager::CONFIGURED)); 277 .WillOnce(Return(DataTypeManager::CONFIGURED));
269 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 278 EXPECT_CALL(
270 .Times(2); 279 *manager(),
280 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
281 EXPECT_CALL(
282 *manager(),
283 Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
271 284
272 migrator()->MigrateTypes(to_migrate); 285 migrator()->MigrateTypes(to_migrate);
273 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 286 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
274 287
275 SendConfigureDone(DataTypeManager::OK, difference); 288 SendConfigureDone(DataTypeManager::OK, difference);
276 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 289 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
277 290
278 syncer::ModelTypeSet prefs; 291 syncer::ModelTypeSet prefs;
279 prefs.Put(syncer::PREFERENCES); 292 prefs.Put(syncer::PREFERENCES);
280 SetUnsyncedTypes(prefs); 293 SetUnsyncedTypes(prefs);
281 SendConfigureDone(DataTypeManager::OK, difference); 294 SendConfigureDone(DataTypeManager::OK, difference);
282 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 295 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
283 296
284 SetUnsyncedTypes(to_migrate); 297 SetUnsyncedTypes(to_migrate);
285 SendConfigureDone(DataTypeManager::OK, difference); 298 SendConfigureDone(DataTypeManager::OK, difference);
286 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 299 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
287 } 300 }
288 301
289 TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) { 302 TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) {
290 syncer::ModelTypeSet to_migrate; 303 syncer::ModelTypeSet to_migrate;
291 to_migrate.Put(syncer::PREFERENCES); 304 to_migrate.Put(syncer::PREFERENCES);
292 305
293 EXPECT_CALL(*manager(), state()) 306 EXPECT_CALL(*manager(), state())
294 .WillOnce(Return(DataTypeManager::CONFIGURED)); 307 .WillOnce(Return(DataTypeManager::CONFIGURED));
295 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 308 EXPECT_CALL(
296 .Times(2); 309 *manager(),
310 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
311 EXPECT_CALL(
312 *manager(),
313 Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
297 migrator()->MigrateTypes(to_migrate); 314 migrator()->MigrateTypes(to_migrate);
298 315
299 RemovePreferredType(syncer::PREFERENCES); 316 RemovePreferredType(syncer::PREFERENCES);
300 SetUnsyncedTypes(to_migrate); 317 SetUnsyncedTypes(to_migrate);
301 SendConfigureDone(DataTypeManager::OK, preferred_types()); 318 SendConfigureDone(DataTypeManager::OK, preferred_types());
302 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 319 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
303 SetUnsyncedTypes(syncer::ModelTypeSet()); 320 SetUnsyncedTypes(syncer::ModelTypeSet());
304 SendConfigureDone(DataTypeManager::OK, preferred_types()); 321 SendConfigureDone(DataTypeManager::OK, preferred_types());
305 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); 322 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
306 } 323 }
307 324
308 TEST_F(SyncBackendMigratorTest, ConfigureFailure) { 325 TEST_F(SyncBackendMigratorTest, ConfigureFailure) {
309 syncer::ModelTypeSet to_migrate; 326 syncer::ModelTypeSet to_migrate;
310 to_migrate.Put(syncer::PREFERENCES); 327 to_migrate.Put(syncer::PREFERENCES);
311 328
312 EXPECT_CALL(*manager(), state()) 329 EXPECT_CALL(*manager(), state())
313 .WillOnce(Return(DataTypeManager::CONFIGURED)); 330 .WillOnce(Return(DataTypeManager::CONFIGURED));
314 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 331 EXPECT_CALL(
315 .Times(1); 332 *manager(),
333 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
316 migrator()->MigrateTypes(to_migrate); 334 migrator()->MigrateTypes(to_migrate);
317 SetUnsyncedTypes(syncer::ModelTypeSet()); 335 SetUnsyncedTypes(syncer::ModelTypeSet());
318 SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet()); 336 SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet());
319 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); 337 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
320 } 338 }
321 339
322 }; // namespace browser_sync 340 }; // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698