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

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: Rebase Created 8 years, 4 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(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION))
134 .Times(1);
133 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 135 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
134 .Times(2); 136 .Times(1);
135 137
136 migrator()->MigrateTypes(to_migrate); 138 migrator()->MigrateTypes(to_migrate);
137 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 139 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
138 140
139 SetUnsyncedTypes(to_migrate); 141 SetUnsyncedTypes(to_migrate);
140 SendConfigureDone(DataTypeManager::OK, difference); 142 SendConfigureDone(DataTypeManager::OK, difference);
141 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 143 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
142 144
143 SetUnsyncedTypes(syncer::ModelTypeSet()); 145 SetUnsyncedTypes(syncer::ModelTypeSet());
144 SendConfigureDone(DataTypeManager::OK, preferred_types()); 146 SendConfigureDone(DataTypeManager::OK, preferred_types());
145 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); 147 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
146 148
147 migrator()->RemoveMigrationObserver(&migration_observer); 149 migrator()->RemoveMigrationObserver(&migration_observer);
148 } 150 }
149 151
150 // Test that in the normal case with Nigori a migration transitions through 152 // Test that in the normal case with Nigori a migration transitions through
151 // each state and wind up back in IDLE. 153 // each state and wind up back in IDLE.
152 TEST_F(SyncBackendMigratorTest, MigrateNigori) { 154 TEST_F(SyncBackendMigratorTest, MigrateNigori) {
153 syncer::ModelTypeSet to_migrate, difference; 155 syncer::ModelTypeSet to_migrate, difference;
154 to_migrate.Put(syncer::NIGORI); 156 to_migrate.Put(syncer::NIGORI);
155 difference.Put(syncer::AUTOFILL); 157 difference.Put(syncer::AUTOFILL);
156 difference.Put(syncer::BOOKMARKS); 158 difference.Put(syncer::BOOKMARKS);
157 159
158 EXPECT_CALL(*manager(), state()) 160 EXPECT_CALL(*manager(), state())
159 .WillOnce(Return(DataTypeManager::CONFIGURED)); 161 .WillOnce(Return(DataTypeManager::CONFIGURED));
160 162
161 EXPECT_CALL(*manager(), ConfigureWithoutNigori(_, 163 EXPECT_CALL(*manager(), Purge(_,
162 syncer::CONFIGURE_REASON_MIGRATION)); 164 syncer::CONFIGURE_REASON_MIGRATION));
163 165
164 migrator()->MigrateTypes(to_migrate); 166 migrator()->MigrateTypes(to_migrate);
165 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 167 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
166 168
167 SetUnsyncedTypes(to_migrate); 169 SetUnsyncedTypes(to_migrate);
168 SendConfigureDone(DataTypeManager::OK, difference); 170 SendConfigureDone(DataTypeManager::OK, difference);
169 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 171 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
170 172
171 SetUnsyncedTypes(syncer::ModelTypeSet()); 173 SetUnsyncedTypes(syncer::ModelTypeSet());
(...skipping 10 matching lines...) Expand all
182 184
183 EXPECT_CALL(*manager(), state()) 185 EXPECT_CALL(*manager(), state())
184 .WillOnce(Return(DataTypeManager::CONFIGURING)); 186 .WillOnce(Return(DataTypeManager::CONFIGURING));
185 EXPECT_CALL(*manager(), Configure(_, _)).Times(0); 187 EXPECT_CALL(*manager(), Configure(_, _)).Times(0);
186 migrator()->MigrateTypes(to_migrate); 188 migrator()->MigrateTypes(to_migrate);
187 EXPECT_EQ(BackendMigrator::WAITING_TO_START, migrator()->state()); 189 EXPECT_EQ(BackendMigrator::WAITING_TO_START, migrator()->state());
188 190
189 Mock::VerifyAndClearExpectations(manager()); 191 Mock::VerifyAndClearExpectations(manager());
190 EXPECT_CALL(*manager(), state()) 192 EXPECT_CALL(*manager(), state())
191 .WillOnce(Return(DataTypeManager::CONFIGURED)); 193 .WillOnce(Return(DataTypeManager::CONFIGURED));
192 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)); 194 EXPECT_CALL(*manager(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION));
193 SetUnsyncedTypes(syncer::ModelTypeSet()); 195 SetUnsyncedTypes(syncer::ModelTypeSet());
194 SendConfigureDone(DataTypeManager::OK, syncer::ModelTypeSet()); 196 SendConfigureDone(DataTypeManager::OK, syncer::ModelTypeSet());
195 197
196 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 198 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
197 } 199 }
198 200
199 // Test that the migrator can cope with a migration request while a migration 201 // Test that the migrator can cope with a migration request while a migration
200 // is in progress. 202 // is in progress.
201 TEST_F(SyncBackendMigratorTest, RestartMigration) { 203 TEST_F(SyncBackendMigratorTest, RestartMigration) {
202 syncer::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks; 204 syncer::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks;
203 to_migrate1.Put(syncer::PREFERENCES); 205 to_migrate1.Put(syncer::PREFERENCES);
204 to_migrate2.Put(syncer::AUTOFILL); 206 to_migrate2.Put(syncer::AUTOFILL);
205 to_migrate_union.Put(syncer::PREFERENCES); 207 to_migrate_union.Put(syncer::PREFERENCES);
206 to_migrate_union.Put(syncer::AUTOFILL); 208 to_migrate_union.Put(syncer::AUTOFILL);
207 bookmarks.Put(syncer::BOOKMARKS); 209 bookmarks.Put(syncer::BOOKMARKS);
208 210
209 EXPECT_CALL(*manager(), state()) 211 EXPECT_CALL(*manager(), state())
210 .WillOnce(Return(DataTypeManager::CONFIGURED)); 212 .WillOnce(Return(DataTypeManager::CONFIGURED));
211 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 213 EXPECT_CALL(*manager(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION))
212 .Times(2); 214 .Times(2);
213 migrator()->MigrateTypes(to_migrate1); 215 migrator()->MigrateTypes(to_migrate1);
214 216
215 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 217 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
216 migrator()->MigrateTypes(to_migrate2); 218 migrator()->MigrateTypes(to_migrate2);
217 219
218 const syncer::ModelTypeSet difference1 = 220 const syncer::ModelTypeSet difference1 =
219 Difference(preferred_types(), to_migrate1); 221 Difference(preferred_types(), to_migrate1);
220 222
221 Mock::VerifyAndClearExpectations(manager()); 223 Mock::VerifyAndClearExpectations(manager());
224 EXPECT_CALL(*manager(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION))
225 .Times(1);
222 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 226 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
223 .Times(2); 227 .Times(1);
224 SetUnsyncedTypes(to_migrate1); 228 SetUnsyncedTypes(to_migrate1);
225 SendConfigureDone(DataTypeManager::OK, difference1); 229 SendConfigureDone(DataTypeManager::OK, difference1);
226 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 230 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
227 231
228 SetUnsyncedTypes(to_migrate_union); 232 SetUnsyncedTypes(to_migrate_union);
229 SendConfigureDone(DataTypeManager::OK, bookmarks); 233 SendConfigureDone(DataTypeManager::OK, bookmarks);
230 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 234 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
231 } 235 }
232 236
233 // Test that an external invocation of Configure(...) during a migration results 237 // Test that an external invocation of Configure(...) during a migration results
234 // in a migration reattempt. 238 // in a migration reattempt.
235 TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) { 239 TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) {
236 syncer::ModelTypeSet to_migrate; 240 syncer::ModelTypeSet to_migrate;
237 syncer::ModelTypeSet difference; 241 syncer::ModelTypeSet difference;
238 to_migrate.Put(syncer::PREFERENCES); 242 to_migrate.Put(syncer::PREFERENCES);
239 difference.Put(syncer::AUTOFILL); 243 difference.Put(syncer::AUTOFILL);
240 difference.Put(syncer::BOOKMARKS); 244 difference.Put(syncer::BOOKMARKS);
241 245
242 EXPECT_CALL(*manager(), state()) 246 EXPECT_CALL(*manager(), state())
243 .WillOnce(Return(DataTypeManager::CONFIGURED)); 247 .WillOnce(Return(DataTypeManager::CONFIGURED));
244 EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), 248 EXPECT_CALL(*manager(), Purge(HasModelTypes(to_migrate),
245 syncer::CONFIGURE_REASON_MIGRATION)); 249 syncer::CONFIGURE_REASON_MIGRATION));
246 migrator()->MigrateTypes(to_migrate); 250 migrator()->MigrateTypes(to_migrate);
247 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 251 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
248 252
249 Mock::VerifyAndClearExpectations(manager()); 253 Mock::VerifyAndClearExpectations(manager());
250 EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), 254 EXPECT_CALL(*manager(), Purge(HasModelTypes(to_migrate),
251 syncer::CONFIGURE_REASON_MIGRATION)); 255 syncer::CONFIGURE_REASON_MIGRATION));
252 SetUnsyncedTypes(syncer::ModelTypeSet()); 256 SetUnsyncedTypes(syncer::ModelTypeSet());
253 SendConfigureDone(DataTypeManager::OK, preferred_types()); 257 SendConfigureDone(DataTypeManager::OK, preferred_types());
254 258
255 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 259 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
256 } 260 }
257 261
258 // Test that spurious OnConfigureDone events don't confuse the 262 // Test that spurious OnConfigureDone events don't confuse the
259 // migrator while it's waiting for disabled types to have been purged 263 // migrator while it's waiting for disabled types to have been purged
260 // from the sync db. 264 // from the sync db.
261 TEST_F(SyncBackendMigratorTest, WaitingForPurge) { 265 TEST_F(SyncBackendMigratorTest, WaitingForPurge) {
262 syncer::ModelTypeSet to_migrate, difference; 266 syncer::ModelTypeSet to_migrate, difference;
263 to_migrate.Put(syncer::PREFERENCES); 267 to_migrate.Put(syncer::PREFERENCES);
264 to_migrate.Put(syncer::AUTOFILL); 268 to_migrate.Put(syncer::AUTOFILL);
265 difference.Put(syncer::BOOKMARKS); 269 difference.Put(syncer::BOOKMARKS);
266 270
267 EXPECT_CALL(*manager(), state()) 271 EXPECT_CALL(*manager(), state())
268 .WillOnce(Return(DataTypeManager::CONFIGURED)); 272 .WillOnce(Return(DataTypeManager::CONFIGURED));
273 EXPECT_CALL(*manager(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION))
274 .Times(1);
269 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 275 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
270 .Times(2); 276 .Times(1);
271 277
272 migrator()->MigrateTypes(to_migrate); 278 migrator()->MigrateTypes(to_migrate);
273 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 279 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
274 280
275 SendConfigureDone(DataTypeManager::OK, difference); 281 SendConfigureDone(DataTypeManager::OK, difference);
276 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 282 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
277 283
278 syncer::ModelTypeSet prefs; 284 syncer::ModelTypeSet prefs;
279 prefs.Put(syncer::PREFERENCES); 285 prefs.Put(syncer::PREFERENCES);
280 SetUnsyncedTypes(prefs); 286 SetUnsyncedTypes(prefs);
281 SendConfigureDone(DataTypeManager::OK, difference); 287 SendConfigureDone(DataTypeManager::OK, difference);
282 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); 288 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
283 289
284 SetUnsyncedTypes(to_migrate); 290 SetUnsyncedTypes(to_migrate);
285 SendConfigureDone(DataTypeManager::OK, difference); 291 SendConfigureDone(DataTypeManager::OK, difference);
286 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 292 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
287 } 293 }
288 294
289 TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) { 295 TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) {
290 syncer::ModelTypeSet to_migrate; 296 syncer::ModelTypeSet to_migrate;
291 to_migrate.Put(syncer::PREFERENCES); 297 to_migrate.Put(syncer::PREFERENCES);
292 298
293 EXPECT_CALL(*manager(), state()) 299 EXPECT_CALL(*manager(), state())
294 .WillOnce(Return(DataTypeManager::CONFIGURED)); 300 .WillOnce(Return(DataTypeManager::CONFIGURED));
301 EXPECT_CALL(*manager(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION))
302 .Times(1);
295 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 303 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
296 .Times(2); 304 .Times(1);
297 migrator()->MigrateTypes(to_migrate); 305 migrator()->MigrateTypes(to_migrate);
298 306
299 RemovePreferredType(syncer::PREFERENCES); 307 RemovePreferredType(syncer::PREFERENCES);
300 SetUnsyncedTypes(to_migrate); 308 SetUnsyncedTypes(to_migrate);
301 SendConfigureDone(DataTypeManager::OK, preferred_types()); 309 SendConfigureDone(DataTypeManager::OK, preferred_types());
302 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); 310 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
303 SetUnsyncedTypes(syncer::ModelTypeSet()); 311 SetUnsyncedTypes(syncer::ModelTypeSet());
304 SendConfigureDone(DataTypeManager::OK, preferred_types()); 312 SendConfigureDone(DataTypeManager::OK, preferred_types());
305 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); 313 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
306 } 314 }
307 315
308 TEST_F(SyncBackendMigratorTest, ConfigureFailure) { 316 TEST_F(SyncBackendMigratorTest, ConfigureFailure) {
309 syncer::ModelTypeSet to_migrate; 317 syncer::ModelTypeSet to_migrate;
310 to_migrate.Put(syncer::PREFERENCES); 318 to_migrate.Put(syncer::PREFERENCES);
311 319
312 EXPECT_CALL(*manager(), state()) 320 EXPECT_CALL(*manager(), state())
313 .WillOnce(Return(DataTypeManager::CONFIGURED)); 321 .WillOnce(Return(DataTypeManager::CONFIGURED));
314 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) 322 EXPECT_CALL(*manager(), Purge(_, syncer::CONFIGURE_REASON_MIGRATION))
315 .Times(1); 323 .Times(1);
316 migrator()->MigrateTypes(to_migrate); 324 migrator()->MigrateTypes(to_migrate);
317 SetUnsyncedTypes(syncer::ModelTypeSet()); 325 SetUnsyncedTypes(syncer::ModelTypeSet());
318 SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet()); 326 SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet());
319 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); 327 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
320 } 328 }
321 329
322 }; // namespace browser_sync 330 }; // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698