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 "chrome/browser/sync/glue/sync_backend_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 profile_.reset(); | 178 profile_.reset(); |
179 // Pump messages posted by the sync thread (which may end up | 179 // Pump messages posted by the sync thread (which may end up |
180 // posting on the IO thread). | 180 // posting on the IO thread). |
181 ui_loop_.RunUntilIdle(); | 181 ui_loop_.RunUntilIdle(); |
182 io_thread_.Stop(); | 182 io_thread_.Stop(); |
183 // Pump any messages posted by the IO thread. | 183 // Pump any messages posted by the IO thread. |
184 ui_loop_.RunUntilIdle(); | 184 ui_loop_.RunUntilIdle(); |
185 } | 185 } |
186 | 186 |
187 // Synchronously initializes the backend. | 187 // Synchronously initializes the backend. |
188 void InitializeBackend() { | 188 void InitializeBackend(bool expect_success) { |
189 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, true)). | 189 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, expect_success)). |
190 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 190 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
191 backend_->Initialize(&mock_frontend_, | 191 backend_->Initialize(&mock_frontend_, |
192 syncer::WeakHandle<syncer::JsEventHandler>(), | 192 syncer::WeakHandle<syncer::JsEventHandler>(), |
193 GURL(""), | 193 GURL(""), |
194 credentials_, | 194 credentials_, |
195 true, | 195 true, |
196 &fake_manager_factory_, | 196 &fake_manager_factory_, |
197 &handler_, | 197 &handler_, |
198 NULL); | 198 NULL); |
199 ui_loop_.PostDelayedTask(FROM_HERE, | 199 ui_loop_.PostDelayedTask(FROM_HERE, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 scoped_ptr<InvalidatorStorage> invalidator_storage_; | 243 scoped_ptr<InvalidatorStorage> invalidator_storage_; |
244 scoped_ptr<SyncBackendHost> backend_; | 244 scoped_ptr<SyncBackendHost> backend_; |
245 FakeSyncManager* fake_manager_; | 245 FakeSyncManager* fake_manager_; |
246 FakeSyncManagerFactory fake_manager_factory_; | 246 FakeSyncManagerFactory fake_manager_factory_; |
247 syncer::ModelTypeSet enabled_types_; | 247 syncer::ModelTypeSet enabled_types_; |
248 }; | 248 }; |
249 | 249 |
250 // Test basic initialization with no initial types (first time initialization). | 250 // Test basic initialization with no initial types (first time initialization). |
251 // Only the nigori should be configured. | 251 // Only the nigori should be configured. |
252 TEST_F(SyncBackendHostTest, InitShutdown) { | 252 TEST_F(SyncBackendHostTest, InitShutdown) { |
253 InitializeBackend(); | 253 InitializeBackend(true); |
254 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 254 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
255 syncer::ControlTypes())); | 255 syncer::ControlTypes())); |
256 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( | 256 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( |
257 syncer::ControlTypes())); | 257 syncer::ControlTypes())); |
258 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 258 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
259 syncer::ControlTypes()).Empty()); | 259 syncer::ControlTypes()).Empty()); |
260 } | 260 } |
261 | 261 |
262 // Test first time sync scenario. All types should be properly configured. | 262 // Test first time sync scenario. All types should be properly configured. |
263 TEST_F(SyncBackendHostTest, FirstTimeSync) { | 263 TEST_F(SyncBackendHostTest, FirstTimeSync) { |
264 InitializeBackend(); | 264 InitializeBackend(true); |
265 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 265 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
266 syncer::ControlTypes())); | 266 syncer::ControlTypes())); |
267 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( | 267 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( |
268 syncer::ControlTypes())); | 268 syncer::ControlTypes())); |
269 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 269 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
270 syncer::ControlTypes()).Empty()); | 270 syncer::ControlTypes()).Empty()); |
271 | 271 |
272 ConfigureDataTypes(enabled_types_, | 272 ConfigureDataTypes(enabled_types_, |
273 Difference(syncer::ModelTypeSet::All(), | 273 Difference(syncer::ModelTypeSet::All(), |
274 enabled_types_)); | 274 enabled_types_)); |
275 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( | 275 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( |
276 Difference(enabled_types_, syncer::ControlTypes()))); | 276 Difference(enabled_types_, syncer::ControlTypes()))); |
277 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 277 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
278 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 278 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
279 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 279 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
280 enabled_types_).Empty()); | 280 enabled_types_).Empty()); |
281 } | 281 } |
282 | 282 |
283 // Test the restart after setting up sync scenario. No enabled types should be | 283 // Test the restart after setting up sync scenario. No enabled types should be |
284 // downloaded or cleaned. | 284 // downloaded or cleaned. |
285 TEST_F(SyncBackendHostTest, Restart) { | 285 TEST_F(SyncBackendHostTest, Restart) { |
286 sync_prefs_->SetSyncSetupCompleted(); | 286 sync_prefs_->SetSyncSetupCompleted(); |
287 syncer::ModelTypeSet all_but_nigori = enabled_types_; | 287 syncer::ModelTypeSet all_but_nigori = enabled_types_; |
288 fake_manager_factory_.set_progress_marker_types(enabled_types_); | 288 fake_manager_factory_.set_progress_marker_types(enabled_types_); |
289 fake_manager_factory_.set_initial_sync_ended_types(enabled_types_); | 289 fake_manager_factory_.set_initial_sync_ended_types(enabled_types_); |
290 InitializeBackend(); | 290 InitializeBackend(true); |
291 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); | 291 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); |
292 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 292 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
293 enabled_types_).Empty()); | 293 enabled_types_).Empty()); |
294 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 294 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
295 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 295 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
296 enabled_types_).Empty()); | 296 enabled_types_).Empty()); |
297 | 297 |
298 ConfigureDataTypes(enabled_types_, | 298 ConfigureDataTypes(enabled_types_, |
299 Difference(syncer::ModelTypeSet::All(), | 299 Difference(syncer::ModelTypeSet::All(), |
300 enabled_types_)); | 300 enabled_types_)); |
(...skipping 13 matching lines...) Expand all Loading... |
314 // Set sync manager behavior before passing it down. All types have progress | 314 // Set sync manager behavior before passing it down. All types have progress |
315 // markers, but nigori and bookmarks are missing initial sync ended. | 315 // markers, but nigori and bookmarks are missing initial sync ended. |
316 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS); | 316 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS); |
317 syncer::ModelTypeSet full_types = | 317 syncer::ModelTypeSet full_types = |
318 Difference(enabled_types_, partial_types); | 318 Difference(enabled_types_, partial_types); |
319 fake_manager_factory_.set_progress_marker_types(enabled_types_); | 319 fake_manager_factory_.set_progress_marker_types(enabled_types_); |
320 fake_manager_factory_.set_initial_sync_ended_types(full_types); | 320 fake_manager_factory_.set_initial_sync_ended_types(full_types); |
321 | 321 |
322 // Bringing up the backend should purge all partial types, then proceed to | 322 // Bringing up the backend should purge all partial types, then proceed to |
323 // download the Nigori. | 323 // download the Nigori. |
324 InitializeBackend(); | 324 InitializeBackend(true); |
325 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 325 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
326 syncer::ModelTypeSet(syncer::NIGORI))); | 326 syncer::ModelTypeSet(syncer::NIGORI))); |
327 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); | 327 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); |
328 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( | 328 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( |
329 Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)))); | 329 Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)))); |
330 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 330 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
331 enabled_types_).Equals( | 331 enabled_types_).Equals( |
332 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI)))); | 332 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI)))); |
333 | 333 |
334 // Now do the actual configuration, which should download and apply bookmarks. | 334 // Now do the actual configuration, which should download and apply bookmarks. |
335 ConfigureDataTypes(enabled_types_, | 335 ConfigureDataTypes(enabled_types_, |
336 Difference(syncer::ModelTypeSet::All(), | 336 Difference(syncer::ModelTypeSet::All(), |
337 enabled_types_)); | 337 enabled_types_)); |
338 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 338 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
339 enabled_types_).Empty()); | 339 enabled_types_).Empty()); |
340 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 340 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
341 partial_types)); | 341 partial_types)); |
342 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 342 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
343 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 343 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
344 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 344 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
345 enabled_types_).Empty()); | 345 enabled_types_).Empty()); |
346 } | 346 } |
347 | 347 |
348 // Test the behavior when we lose the sync db. Although we already have types | 348 // Test the behavior when we lose the sync db. Although we already have types |
349 // enabled, we should re-download all of them because we lost their data. | 349 // enabled, we should re-download all of them because we lost their data. |
350 TEST_F(SyncBackendHostTest, LostDB) { | 350 TEST_F(SyncBackendHostTest, LostDB) { |
351 sync_prefs_->SetSyncSetupCompleted(); | 351 sync_prefs_->SetSyncSetupCompleted(); |
352 // Initialization should fetch the Nigori node. Everything else should be | 352 // Initialization should fetch the Nigori node. Everything else should be |
353 // left untouched. | 353 // left untouched. |
354 InitializeBackend(); | 354 InitializeBackend(true); |
355 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 355 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
356 syncer::ModelTypeSet(syncer::ControlTypes()))); | 356 syncer::ModelTypeSet(syncer::ControlTypes()))); |
357 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( | 357 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( |
358 syncer::ModelTypeSet(syncer::ControlTypes()))); | 358 syncer::ModelTypeSet(syncer::ControlTypes()))); |
359 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 359 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
360 enabled_types_).Equals( | 360 enabled_types_).Equals( |
361 Difference(enabled_types_, syncer::ControlTypes()))); | 361 Difference(enabled_types_, syncer::ControlTypes()))); |
362 | 362 |
363 // The database was empty, so any cleaning is entirely optional. We want to | 363 // The database was empty, so any cleaning is entirely optional. We want to |
364 // reset this value before running the next part of the test, though. | 364 // reset this value before running the next part of the test, though. |
365 fake_manager_->GetAndResetCleanedTypes(); | 365 fake_manager_->GetAndResetCleanedTypes(); |
366 | 366 |
367 // The actual configuration should redownload and apply all the enabled types. | 367 // The actual configuration should redownload and apply all the enabled types. |
368 ConfigureDataTypes(enabled_types_, | 368 ConfigureDataTypes(enabled_types_, |
369 Difference(syncer::ModelTypeSet::All(), | 369 Difference(syncer::ModelTypeSet::All(), |
370 enabled_types_)); | 370 enabled_types_)); |
371 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( | 371 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( |
372 Difference(enabled_types_, syncer::ControlTypes()))); | 372 Difference(enabled_types_, syncer::ControlTypes()))); |
373 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 373 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
374 enabled_types_).Empty()); | 374 enabled_types_).Empty()); |
375 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 375 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
376 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 376 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
377 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 377 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
378 enabled_types_).Empty()); | 378 enabled_types_).Empty()); |
379 } | 379 } |
380 | 380 |
381 TEST_F(SyncBackendHostTest, DisableTypes) { | 381 TEST_F(SyncBackendHostTest, DisableTypes) { |
382 // Simulate first time sync. | 382 // Simulate first time sync. |
383 InitializeBackend(); | 383 InitializeBackend(true); |
384 fake_manager_->GetAndResetCleanedTypes(); | 384 fake_manager_->GetAndResetCleanedTypes(); |
385 ConfigureDataTypes(enabled_types_, | 385 ConfigureDataTypes(enabled_types_, |
386 Difference(syncer::ModelTypeSet::All(), | 386 Difference(syncer::ModelTypeSet::All(), |
387 enabled_types_)); | 387 enabled_types_)); |
388 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 388 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
389 enabled_types_)); | 389 enabled_types_)); |
390 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 390 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
391 enabled_types_).Empty()); | 391 enabled_types_).Empty()); |
392 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 392 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
393 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 393 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
(...skipping 14 matching lines...) Expand all Loading... |
408 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 408 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
409 old_types).Equals(disabled_types)); | 409 old_types).Equals(disabled_types)); |
410 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 410 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
411 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 411 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
412 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 412 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
413 enabled_types_).Empty()); | 413 enabled_types_).Empty()); |
414 } | 414 } |
415 | 415 |
416 TEST_F(SyncBackendHostTest, AddTypes) { | 416 TEST_F(SyncBackendHostTest, AddTypes) { |
417 // Simulate first time sync. | 417 // Simulate first time sync. |
418 InitializeBackend(); | 418 InitializeBackend(true); |
419 fake_manager_->GetAndResetCleanedTypes(); | 419 fake_manager_->GetAndResetCleanedTypes(); |
420 ConfigureDataTypes(enabled_types_, | 420 ConfigureDataTypes(enabled_types_, |
421 Difference(syncer::ModelTypeSet::All(), | 421 Difference(syncer::ModelTypeSet::All(), |
422 enabled_types_)); | 422 enabled_types_)); |
423 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 423 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
424 enabled_types_)); | 424 enabled_types_)); |
425 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 425 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
426 enabled_types_).Empty()); | 426 enabled_types_).Empty()); |
427 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 427 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
428 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 428 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
(...skipping 15 matching lines...) Expand all Loading... |
444 enabled_types_).Empty()); | 444 enabled_types_).Empty()); |
445 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 445 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
446 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 446 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
447 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 447 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
448 enabled_types_).Empty()); | 448 enabled_types_).Empty()); |
449 } | 449 } |
450 | 450 |
451 // And and disable in the same configuration. | 451 // And and disable in the same configuration. |
452 TEST_F(SyncBackendHostTest, AddDisableTypes) { | 452 TEST_F(SyncBackendHostTest, AddDisableTypes) { |
453 // Simulate first time sync. | 453 // Simulate first time sync. |
454 InitializeBackend(); | 454 InitializeBackend(true); |
455 fake_manager_->GetAndResetCleanedTypes(); | 455 fake_manager_->GetAndResetCleanedTypes(); |
456 ConfigureDataTypes(enabled_types_, | 456 ConfigureDataTypes(enabled_types_, |
457 Difference(syncer::ModelTypeSet::All(), | 457 Difference(syncer::ModelTypeSet::All(), |
458 enabled_types_)); | 458 enabled_types_)); |
459 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 459 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
460 enabled_types_)); | 460 enabled_types_)); |
461 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 461 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
462 enabled_types_).Empty()); | 462 enabled_types_).Empty()); |
463 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 463 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
464 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 464 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
(...skipping 30 matching lines...) Expand all Loading... |
495 // Set sync manager behavior before passing it down. All types have progress | 495 // Set sync manager behavior before passing it down. All types have progress |
496 // markers and initial sync ended except the new types. | 496 // markers and initial sync ended except the new types. |
497 syncer::ModelTypeSet old_types = enabled_types_; | 497 syncer::ModelTypeSet old_types = enabled_types_; |
498 fake_manager_factory_.set_progress_marker_types(old_types); | 498 fake_manager_factory_.set_progress_marker_types(old_types); |
499 fake_manager_factory_.set_initial_sync_ended_types(old_types); | 499 fake_manager_factory_.set_initial_sync_ended_types(old_types); |
500 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, | 500 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, |
501 syncer::EXTENSION_SETTINGS); | 501 syncer::EXTENSION_SETTINGS); |
502 enabled_types_.PutAll(new_types); | 502 enabled_types_.PutAll(new_types); |
503 | 503 |
504 // Does nothing. | 504 // Does nothing. |
505 InitializeBackend(); | 505 InitializeBackend(true); |
506 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); | 506 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); |
507 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 507 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
508 old_types).Empty()); | 508 old_types).Empty()); |
509 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(old_types)); | 509 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(old_types)); |
510 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 510 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
511 enabled_types_).Equals(new_types)); | 511 enabled_types_).Equals(new_types)); |
512 | 512 |
513 // Downloads and applies the new types. | 513 // Downloads and applies the new types. |
514 ConfigureDataTypes(enabled_types_, | 514 ConfigureDataTypes(enabled_types_, |
515 Difference(syncer::ModelTypeSet::All(), | 515 Difference(syncer::ModelTypeSet::All(), |
(...skipping 20 matching lines...) Expand all Loading... |
536 syncer::ModelTypeSet full_types = | 536 syncer::ModelTypeSet full_types = |
537 Difference(enabled_types_, partial_types); | 537 Difference(enabled_types_, partial_types); |
538 fake_manager_factory_.set_progress_marker_types(old_types); | 538 fake_manager_factory_.set_progress_marker_types(old_types); |
539 fake_manager_factory_.set_initial_sync_ended_types(full_types); | 539 fake_manager_factory_.set_initial_sync_ended_types(full_types); |
540 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, | 540 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, |
541 syncer::EXTENSION_SETTINGS); | 541 syncer::EXTENSION_SETTINGS); |
542 enabled_types_.PutAll(new_types); | 542 enabled_types_.PutAll(new_types); |
543 | 543 |
544 // Purge the partial types. The nigori will be among the purged types, but | 544 // Purge the partial types. The nigori will be among the purged types, but |
545 // the syncer will re-download it by the time the initialization is complete. | 545 // the syncer will re-download it by the time the initialization is complete. |
546 InitializeBackend(); | 546 InitializeBackend(true); |
547 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 547 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
548 syncer::ModelTypeSet(syncer::NIGORI))); | 548 syncer::ModelTypeSet(syncer::NIGORI))); |
549 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); | 549 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); |
550 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( | 550 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( |
551 syncer::Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)))); | 551 syncer::Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)))); |
552 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 552 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
553 enabled_types_).Equals(Union(new_types, Difference( | 553 enabled_types_).Equals(Union(new_types, Difference( |
554 partial_types, syncer::ModelTypeSet(syncer::NIGORI))))); | 554 partial_types, syncer::ModelTypeSet(syncer::NIGORI))))); |
555 | 555 |
556 // Downloads and applies the new types and partial types (which includes | 556 // Downloads and applies the new types and partial types (which includes |
557 // nigori anyways). | 557 // nigori anyways). |
558 ConfigureDataTypes(enabled_types_, | 558 ConfigureDataTypes(enabled_types_, |
559 Difference(syncer::ModelTypeSet::All(), | 559 Difference(syncer::ModelTypeSet::All(), |
560 enabled_types_)); | 560 enabled_types_)); |
561 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 561 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
562 Union(new_types, partial_types))); | 562 Union(new_types, partial_types))); |
563 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 563 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
564 enabled_types_).Empty()); | 564 enabled_types_).Empty()); |
565 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 565 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
566 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 566 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
567 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 567 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
568 enabled_types_).Empty()); | 568 enabled_types_).Empty()); |
569 } | 569 } |
570 | 570 |
571 // Register for some IDs and trigger an invalidation. This should | 571 // Register for some IDs and trigger an invalidation. This should |
572 // propagate all the way to the frontend. | 572 // propagate all the way to the frontend. |
573 TEST_F(SyncBackendHostTest, Invalidate) { | 573 TEST_F(SyncBackendHostTest, Invalidate) { |
574 InitializeBackend(); | 574 InitializeBackend(true); |
575 | 575 |
576 syncer::ObjectIdSet ids; | 576 syncer::ObjectIdSet ids; |
577 ids.insert(invalidation::ObjectId(1, "id1")); | 577 ids.insert(invalidation::ObjectId(1, "id1")); |
578 ids.insert(invalidation::ObjectId(2, "id2")); | 578 ids.insert(invalidation::ObjectId(2, "id2")); |
579 const syncer::ObjectIdInvalidationMap& invalidation_map = | 579 const syncer::ObjectIdInvalidationMap& invalidation_map = |
580 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); | 580 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); |
581 | 581 |
582 EXPECT_CALL( | 582 EXPECT_CALL( |
583 mock_frontend_, | 583 mock_frontend_, |
584 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION)) | 584 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION)) |
585 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 585 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
586 | 586 |
587 backend_->UpdateRegisteredInvalidationIds(ids); | 587 backend_->UpdateRegisteredInvalidationIds(ids); |
588 fake_manager_->Invalidate(invalidation_map, syncer::REMOTE_INVALIDATION); | 588 fake_manager_->Invalidate(invalidation_map, syncer::REMOTE_INVALIDATION); |
589 ui_loop_.PostDelayedTask( | 589 ui_loop_.PostDelayedTask( |
590 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 590 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
591 ui_loop_.Run(); | 591 ui_loop_.Run(); |
592 } | 592 } |
593 | 593 |
594 // Register for some IDs and update the invalidator state. This | 594 // Register for some IDs and update the invalidator state. This |
595 // should propagate all the way to the frontend. | 595 // should propagate all the way to the frontend. |
596 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { | 596 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { |
597 InitializeBackend(); | 597 InitializeBackend(true); |
598 | 598 |
599 EXPECT_CALL(mock_frontend_, | 599 EXPECT_CALL(mock_frontend_, |
600 OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED)) | 600 OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED)) |
601 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 601 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
602 | 602 |
603 syncer::ObjectIdSet ids; | 603 syncer::ObjectIdSet ids; |
604 ids.insert(invalidation::ObjectId(3, "id3")); | 604 ids.insert(invalidation::ObjectId(3, "id3")); |
605 backend_->UpdateRegisteredInvalidationIds(ids); | 605 backend_->UpdateRegisteredInvalidationIds(ids); |
606 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); | 606 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
607 ui_loop_.PostDelayedTask( | 607 ui_loop_.PostDelayedTask( |
608 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 608 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
609 ui_loop_.Run(); | 609 ui_loop_.Run(); |
610 } | 610 } |
611 | 611 |
612 // Call StopSyncingForShutdown() on the backend and fire some invalidations | 612 // Call StopSyncingForShutdown() on the backend and fire some invalidations |
613 // before calling Shutdown(). Then start up and shut down the backend again. | 613 // before calling Shutdown(). Then start up and shut down the backend again. |
614 // Those notifications shouldn't propagate to the frontend. | 614 // Those notifications shouldn't propagate to the frontend. |
615 TEST_F(SyncBackendHostTest, InvalidationsAfterStopSyncingForShutdown) { | 615 TEST_F(SyncBackendHostTest, InvalidationsAfterStopSyncingForShutdown) { |
616 InitializeBackend(); | 616 InitializeBackend(true); |
617 | 617 |
618 syncer::ObjectIdSet ids; | 618 syncer::ObjectIdSet ids; |
619 ids.insert(invalidation::ObjectId(5, "id5")); | 619 ids.insert(invalidation::ObjectId(5, "id5")); |
620 backend_->UpdateRegisteredInvalidationIds(ids); | 620 backend_->UpdateRegisteredInvalidationIds(ids); |
621 | 621 |
622 backend_->StopSyncingForShutdown(); | 622 backend_->StopSyncingForShutdown(); |
623 | 623 |
624 // Should not trigger anything. | 624 // Should not trigger anything. |
625 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); | 625 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); |
626 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); | 626 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
627 const syncer::ObjectIdInvalidationMap& invalidation_map = | 627 const syncer::ObjectIdInvalidationMap& invalidation_map = |
628 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); | 628 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); |
629 fake_manager_->Invalidate(invalidation_map, syncer::REMOTE_INVALIDATION); | 629 fake_manager_->Invalidate(invalidation_map, syncer::REMOTE_INVALIDATION); |
630 | 630 |
631 // Make sure the above calls take effect before we continue. | 631 // Make sure the above calls take effect before we continue. |
632 fake_manager_->WaitForSyncThread(); | 632 fake_manager_->WaitForSyncThread(); |
633 | 633 |
634 backend_->Shutdown(false); | 634 backend_->Shutdown(false); |
635 backend_.reset(); | 635 backend_.reset(); |
636 | 636 |
637 TearDown(); | 637 TearDown(); |
638 SetUp(); | 638 SetUp(); |
639 } | 639 } |
640 | 640 |
641 // Ensure the device info tracker is initialized properly on startup. | 641 // Ensure the device info tracker is initialized properly on startup. |
642 TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { | 642 TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { |
643 ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); | 643 ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); |
644 | 644 |
645 InitializeBackend(); | 645 InitializeBackend(true); |
646 const SyncedDeviceTracker* device_tracker = | 646 const SyncedDeviceTracker* device_tracker = |
647 backend_->GetSyncedDeviceTracker(); | 647 backend_->GetSyncedDeviceTracker(); |
648 ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo()); | 648 ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo()); |
649 } | 649 } |
650 | 650 |
651 // Verify that downloading control types only downloads those types that do | 651 // Verify that downloading control types only downloads those types that do |
652 // not have initial sync ended set. | 652 // not have initial sync ended set. |
653 TEST_F(SyncBackendHostTest, DownloadControlTypes) { | 653 TEST_F(SyncBackendHostTest, DownloadControlTypes) { |
654 sync_prefs_->SetSyncSetupCompleted(); | 654 sync_prefs_->SetSyncSetupCompleted(); |
655 // Set sync manager behavior before passing it down. Experiments and device | 655 // Set sync manager behavior before passing it down. Experiments and device |
656 // info are new types without progress markers or initial sync ended, while | 656 // info are new types without progress markers or initial sync ended, while |
657 // all other types have been fully downloaded and applied. | 657 // all other types have been fully downloaded and applied. |
658 syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::DEVICE_INFO); | 658 syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::DEVICE_INFO); |
659 syncer::ModelTypeSet old_types = | 659 syncer::ModelTypeSet old_types = |
660 Difference(enabled_types_, new_types); | 660 Difference(enabled_types_, new_types); |
661 fake_manager_factory_.set_progress_marker_types(old_types); | 661 fake_manager_factory_.set_progress_marker_types(old_types); |
662 fake_manager_factory_.set_initial_sync_ended_types(old_types); | 662 fake_manager_factory_.set_initial_sync_ended_types(old_types); |
663 | 663 |
664 // Bringing up the backend should download the new types without downloading | 664 // Bringing up the backend should download the new types without downloading |
665 // any old types. | 665 // any old types. |
666 InitializeBackend(); | 666 InitializeBackend(true); |
667 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(new_types)); | 667 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(new_types)); |
668 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 668 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
669 enabled_types_).Empty()); | 669 enabled_types_).Empty()); |
670 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 670 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
671 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 671 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
672 enabled_types_).Empty()); | 672 enabled_types_).Empty()); |
673 } | 673 } |
674 | 674 |
| 675 // Fail to download control types. It's believed that there is a server bug |
| 676 // which can allow this to happen (crbug.com/164288). The sync backend host |
| 677 // should detect this condition and fail to initialize the backend. |
| 678 // |
| 679 // The failure is "silent" in the sense that the GetUpdates request appears to |
| 680 // be successful, but it returned no results. This means that the usual |
| 681 // download retry logic will not be invoked. |
| 682 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { |
| 683 fake_manager_factory_.set_configure_fail_types(syncer::ModelTypeSet::All()); |
| 684 InitializeBackend(false); |
| 685 } |
| 686 |
675 } // namespace | 687 } // namespace |
676 | 688 |
677 } // namespace browser_sync | 689 } // namespace browser_sync |
OLD | NEW |