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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host_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/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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // |fake_manager_factory_|'s fake_manager() is set on the sync 197 // |fake_manager_factory_|'s fake_manager() is set on the sync
198 // thread, but we can rely on the message loop barriers to 198 // thread, but we can rely on the message loop barriers to
199 // guarantee that we see the updated value. 199 // guarantee that we see the updated value.
200 fake_manager_ = fake_manager_factory_.fake_manager(); 200 fake_manager_ = fake_manager_factory_.fake_manager();
201 DCHECK(fake_manager_); 201 DCHECK(fake_manager_);
202 } 202 }
203 203
204 // Synchronously configures the backend's datatypes. 204 // Synchronously configures the backend's datatypes.
205 void ConfigureDataTypes(syncer::ModelTypeSet types_to_add, 205 void ConfigureDataTypes(syncer::ModelTypeSet types_to_add,
206 syncer::ModelTypeSet types_to_remove) { 206 syncer::ModelTypeSet types_to_remove) {
207 types_to_add.Put(syncer::NIGORI); 207 types_to_add.PutAll(syncer::ControlTypes());
208 backend_->ConfigureDataTypes( 208 backend_->ConfigureDataTypes(
209 syncer::CONFIGURE_REASON_RECONFIGURATION, 209 syncer::CONFIGURE_REASON_RECONFIGURATION,
210 types_to_add, 210 types_to_add,
211 types_to_remove, 211 types_to_remove,
212 base::Bind(&SyncBackendHostTest::DownloadReady, 212 base::Bind(&SyncBackendHostTest::DownloadReady,
213 base::Unretained(this)), 213 base::Unretained(this)),
214 base::Bind(&SyncBackendHostTest::OnDownloadRetry, 214 base::Bind(&SyncBackendHostTest::OnDownloadRetry,
215 base::Unretained(this))); 215 base::Unretained(this)));
216 ui_loop_.PostDelayedTask(FROM_HERE, 216 ui_loop_.PostDelayedTask(FROM_HERE,
217 ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); 217 ui_loop_.QuitClosure(), TestTimeouts::action_timeout());
(...skipping 22 matching lines...) Expand all
240 FakeSyncManager* fake_manager_; 240 FakeSyncManager* fake_manager_;
241 FakeSyncManagerFactory fake_manager_factory_; 241 FakeSyncManagerFactory fake_manager_factory_;
242 syncer::ModelTypeSet enabled_types_; 242 syncer::ModelTypeSet enabled_types_;
243 }; 243 };
244 244
245 // Test basic initialization with no initial types (first time initialization). 245 // Test basic initialization with no initial types (first time initialization).
246 // Only the nigori should be configured. 246 // Only the nigori should be configured.
247 TEST_F(SyncBackendHostTest, InitShutdown) { 247 TEST_F(SyncBackendHostTest, InitShutdown) {
248 InitializeBackend(); 248 InitializeBackend();
249 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( 249 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
250 syncer::ModelTypeSet(syncer::NIGORI))); 250 syncer::ControlTypes()));
251 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( 251 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(
252 syncer::ModelTypeSet(syncer::NIGORI))); 252 syncer::ControlTypes()));
253 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 253 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
254 syncer::ModelTypeSet(syncer::NIGORI)).Empty()); 254 syncer::ControlTypes()).Empty());
255 } 255 }
256 256
257 // Test first time sync scenario. All types should be properly configured. 257 // Test first time sync scenario. All types should be properly configured.
258 TEST_F(SyncBackendHostTest, FirstTimeSync) { 258 TEST_F(SyncBackendHostTest, FirstTimeSync) {
259 InitializeBackend(); 259 InitializeBackend();
260 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( 260 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
261 syncer::ModelTypeSet(syncer::NIGORI))); 261 syncer::ControlTypes()));
262 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( 262 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(
263 syncer::ModelTypeSet(syncer::NIGORI))); 263 syncer::ControlTypes()));
264 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 264 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
265 syncer::ModelTypeSet(syncer::NIGORI)).Empty()); 265 syncer::ControlTypes()).Empty());
266 266
267 ConfigureDataTypes(enabled_types_, 267 ConfigureDataTypes(enabled_types_,
268 Difference(syncer::ModelTypeSet::All(), 268 Difference(syncer::ModelTypeSet::All(),
269 enabled_types_)); 269 enabled_types_));
270 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 270 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
271 enabled_types_)); 271 Difference(enabled_types_, syncer::ControlTypes())));
272 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); 272 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
273 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); 273 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_));
274 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 274 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
275 enabled_types_).Empty()); 275 enabled_types_).Empty());
276 } 276 }
277 277
278 // Test the restart after setting up sync scenario. No enabled types should be 278 // Test the restart after setting up sync scenario. No enabled types should be
279 // downloaded or cleaned. 279 // downloaded or cleaned.
280 TEST_F(SyncBackendHostTest, Restart) { 280 TEST_F(SyncBackendHostTest, Restart) {
281 sync_prefs_->SetSyncSetupCompleted(); 281 sync_prefs_->SetSyncSetupCompleted();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 341 }
342 342
343 // Test the behavior when we lose the sync db. Although we already have types 343 // Test the behavior when we lose the sync db. Although we already have types
344 // enabled, we should re-download all of them because we lost their data. 344 // enabled, we should re-download all of them because we lost their data.
345 TEST_F(SyncBackendHostTest, LostDB) { 345 TEST_F(SyncBackendHostTest, LostDB) {
346 sync_prefs_->SetSyncSetupCompleted(); 346 sync_prefs_->SetSyncSetupCompleted();
347 // Initialization should fetch the Nigori node. Everything else should be 347 // Initialization should fetch the Nigori node. Everything else should be
348 // left untouched. 348 // left untouched.
349 InitializeBackend(); 349 InitializeBackend();
350 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( 350 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
351 syncer::ModelTypeSet(syncer::NIGORI))); 351 syncer::ModelTypeSet(syncer::ControlTypes())));
352 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals( 352 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(
353 syncer::ModelTypeSet(syncer::NIGORI))); 353 syncer::ModelTypeSet(syncer::ControlTypes())));
354 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 354 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
355 enabled_types_).Equals( 355 enabled_types_).Equals(
356 Difference(enabled_types_, syncer::ModelTypeSet(syncer::NIGORI)))); 356 Difference(enabled_types_, syncer::ControlTypes())));
357 357
358 // The database was empty, so any cleaning is entirely optional. We want to 358 // The database was empty, so any cleaning is entirely optional. We want to
359 // reset this value before running the next part of the test, though. 359 // reset this value before running the next part of the test, though.
360 fake_manager_->GetAndResetCleanedTypes(); 360 fake_manager_->GetAndResetCleanedTypes();
361 361
362 // The actual configuration should redownload and apply all the enabled types. 362 // The actual configuration should redownload and apply all the enabled types.
363 ConfigureDataTypes(enabled_types_, 363 ConfigureDataTypes(enabled_types_,
364 Difference(syncer::ModelTypeSet::All(), 364 Difference(syncer::ModelTypeSet::All(),
365 enabled_types_)); 365 enabled_types_));
366 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 366 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
367 enabled_types_)); 367 Difference(enabled_types_, syncer::ControlTypes())));
368 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 368 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
369 enabled_types_).Empty()); 369 enabled_types_).Empty());
370 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); 370 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
371 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); 371 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_));
372 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 372 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
373 enabled_types_).Empty()); 373 enabled_types_).Empty());
374 } 374 }
375 375
376 TEST_F(SyncBackendHostTest, DisableTypes) { 376 TEST_F(SyncBackendHostTest, DisableTypes) {
377 // Simulate first time sync. 377 // Simulate first time sync.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 backend_->Shutdown(false); 646 backend_->Shutdown(false);
647 backend_.reset(); 647 backend_.reset();
648 648
649 TearDown(); 649 TearDown();
650 SetUp(); 650 SetUp();
651 } 651 }
652 652
653 } // namespace 653 } // namespace
654 654
655 } // namespace browser_sync 655 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698