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

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 8772074: [Sync] Convert syncable/ directory to ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 439 }
440 440
441 bool IsInDirtyMetahandles(int64 metahandle) { 441 bool IsInDirtyMetahandles(int64 metahandle) {
442 return 1 == dir_->kernel_->dirty_metahandles->count(metahandle); 442 return 1 == dir_->kernel_->dirty_metahandles->count(metahandle);
443 } 443 }
444 444
445 bool IsInMetahandlesToPurge(int64 metahandle) { 445 bool IsInMetahandlesToPurge(int64 metahandle) {
446 return 1 == dir_->kernel_->metahandles_to_purge->count(metahandle); 446 return 1 == dir_->kernel_->metahandles_to_purge->count(metahandle);
447 } 447 }
448 448
449 void CheckPurgeEntriesWithTypeInSucceeded(const ModelTypeSet& types_to_purge, 449 void CheckPurgeEntriesWithTypeInSucceeded(ModelEnumSet types_to_purge,
450 bool before_reload) { 450 bool before_reload) {
451 SCOPED_TRACE(testing::Message("Before reload: ") << before_reload); 451 SCOPED_TRACE(testing::Message("Before reload: ") << before_reload);
452 { 452 {
453 ReadTransaction trans(FROM_HERE, dir_.get()); 453 ReadTransaction trans(FROM_HERE, dir_.get());
454 MetahandleSet all_set; 454 MetahandleSet all_set;
455 dir_->GetAllMetaHandles(&trans, &all_set); 455 dir_->GetAllMetaHandles(&trans, &all_set);
456 EXPECT_EQ(3U, all_set.size()); 456 EXPECT_EQ(3U, all_set.size());
457 if (before_reload) 457 if (before_reload)
458 EXPECT_EQ(4U, dir_->kernel_->metahandles_to_purge->size()); 458 EXPECT_EQ(4U, dir_->kernel_->metahandles_to_purge->size());
459 for (MetahandleSet::iterator iter = all_set.begin(); 459 for (MetahandleSet::iterator iter = all_set.begin();
460 iter != all_set.end(); ++iter) { 460 iter != all_set.end(); ++iter) {
461 Entry e(&trans, GET_BY_HANDLE, *iter); 461 Entry e(&trans, GET_BY_HANDLE, *iter);
462 if ((types_to_purge.count(e.GetModelType()) || 462 const ModelType local_type = e.GetModelType();
463 types_to_purge.count(e.GetServerModelType()))) { 463 const ModelType server_type = e.GetServerModelType();
464
465 // Note the dance around incrementing |it|, since we sometimes erase().
466 if ((IsRealDataType(local_type) &&
467 types_to_purge.Has(local_type)) ||
468 (IsRealDataType(server_type) &&
469 types_to_purge.Has(server_type))) {
464 FAIL() << "Illegal type should have been deleted."; 470 FAIL() << "Illegal type should have been deleted.";
465 } 471 }
466 } 472 }
467 } 473 }
468 474
469 EXPECT_FALSE(dir_->initial_sync_ended_for_type(PREFERENCES)); 475 for (ModelEnumSet::Iterator it = types_to_purge.First();
470 EXPECT_FALSE(dir_->initial_sync_ended_for_type(AUTOFILL)); 476 it.Good(); it.Inc()) {
477 EXPECT_FALSE(dir_->initial_sync_ended_for_type(it.Get()));
478 }
479 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS));
471 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 480 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS));
472 } 481 }
473 482
474 scoped_ptr<Directory> dir_; 483 scoped_ptr<Directory> dir_;
475 FilePath file_path_; 484 FilePath file_path_;
476 NullDirectoryChangeDelegate delegate_; 485 NullDirectoryChangeDelegate delegate_;
477 486
478 // Creates an empty entry and sets the ID field to the default kId. 487 // Creates an empty entry and sets the ID field to the default kId.
479 void CreateEntry(const std::string& entryname) { 488 void CreateEntry(const std::string& entryname) {
480 CreateEntry(entryname, kId); 489 CreateEntry(entryname, kId);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 all_handles.insert(e.Get(META_HANDLE)); 526 all_handles.insert(e.Get(META_HANDLE));
518 } else { 527 } else {
519 AddDefaultExtensionValue(PREFERENCES, &specs); 528 AddDefaultExtensionValue(PREFERENCES, &specs);
520 all_handles.insert(e.Get(META_HANDLE)); 529 all_handles.insert(e.Get(META_HANDLE));
521 } 530 }
522 e.Put(SPECIFICS, specs); 531 e.Put(SPECIFICS, specs);
523 e.Put(SERVER_SPECIFICS, specs); 532 e.Put(SERVER_SPECIFICS, specs);
524 } 533 }
525 } 534 }
526 535
527 ModelTypeSet to_purge; 536 syncable::ModelEnumSet to_purge(BOOKMARKS);
528 to_purge.insert(BOOKMARKS);
529 dir_->PurgeEntriesWithTypeIn(to_purge); 537 dir_->PurgeEntriesWithTypeIn(to_purge);
530 538
531 Directory::SaveChangesSnapshot snapshot1; 539 Directory::SaveChangesSnapshot snapshot1;
532 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); 540 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
533 dir_->TakeSnapshotForSaveChanges(&snapshot1); 541 dir_->TakeSnapshotForSaveChanges(&snapshot1);
534 EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge); 542 EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge);
535 543
536 to_purge.clear(); 544 to_purge.Clear();
537 to_purge.insert(PREFERENCES); 545 to_purge.Put(PREFERENCES);
538 dir_->PurgeEntriesWithTypeIn(to_purge); 546 dir_->PurgeEntriesWithTypeIn(to_purge);
539 547
540 dir_->HandleSaveChangesFailure(snapshot1); 548 dir_->HandleSaveChangesFailure(snapshot1);
541 549
542 Directory::SaveChangesSnapshot snapshot2; 550 Directory::SaveChangesSnapshot snapshot2;
543 dir_->TakeSnapshotForSaveChanges(&snapshot2); 551 dir_->TakeSnapshotForSaveChanges(&snapshot2);
544 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); 552 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge);
545 } 553 }
546 554
547 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { 555 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 sync_pb::EntitySpecifics bookmark_specs; 616 sync_pb::EntitySpecifics bookmark_specs;
609 sync_pb::EntitySpecifics autofill_specs; 617 sync_pb::EntitySpecifics autofill_specs;
610 sync_pb::EntitySpecifics preference_specs; 618 sync_pb::EntitySpecifics preference_specs;
611 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); 619 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs);
612 AddDefaultExtensionValue(PREFERENCES, &preference_specs); 620 AddDefaultExtensionValue(PREFERENCES, &preference_specs);
613 AddDefaultExtensionValue(AUTOFILL, &autofill_specs); 621 AddDefaultExtensionValue(AUTOFILL, &autofill_specs);
614 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); 622 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true);
615 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); 623 dir_->set_initial_sync_ended_for_type(PREFERENCES, true);
616 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); 624 dir_->set_initial_sync_ended_for_type(AUTOFILL, true);
617 625
618 std::set<ModelType> types_to_purge; 626 syncable::ModelEnumSet types_to_purge(PREFERENCES, AUTOFILL);
619 types_to_purge.insert(PREFERENCES);
620 types_to_purge.insert(AUTOFILL);
621 627
622 TestIdFactory id_factory; 628 TestIdFactory id_factory;
623 // Create some items for each type. 629 // Create some items for each type.
624 { 630 {
625 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 631 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
626 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); 632 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item");
627 ASSERT_TRUE(item1.good()); 633 ASSERT_TRUE(item1.good());
628 item1.Put(SPECIFICS, bookmark_specs); 634 item1.Put(SPECIFICS, bookmark_specs);
629 item1.Put(SERVER_SPECIFICS, bookmark_specs); 635 item1.Put(SERVER_SPECIFICS, bookmark_specs);
630 item1.Put(IS_UNSYNCED, true); 636 item1.Put(IS_UNSYNCED, true);
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 ASSERT_TRUE(dir_->SaveChanges()); 1372 ASSERT_TRUE(dir_->SaveChanges());
1367 1373
1368 // Now do some operations using a directory for which SaveChanges will 1374 // Now do some operations using a directory for which SaveChanges will
1369 // always fail. 1375 // always fail.
1370 dir_.reset(new TestUnsaveableDirectory()); 1376 dir_.reset(new TestUnsaveableDirectory());
1371 ASSERT_TRUE(dir_.get()); 1377 ASSERT_TRUE(dir_.get());
1372 ASSERT_EQ(OPENED, dir_->Open(file_path_, kName, 1378 ASSERT_EQ(OPENED, dir_->Open(file_path_, kName,
1373 &delegate_, NullTransactionObserver())); 1379 &delegate_, NullTransactionObserver()));
1374 ASSERT_TRUE(dir_->good()); 1380 ASSERT_TRUE(dir_->good());
1375 1381
1376 ModelTypeSet set; 1382 syncable::ModelEnumSet set(BOOKMARKS);
1377 set.insert(BOOKMARKS);
1378 dir_->PurgeEntriesWithTypeIn(set); 1383 dir_->PurgeEntriesWithTypeIn(set);
1379 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); 1384 EXPECT_TRUE(IsInMetahandlesToPurge(handle1));
1380 ASSERT_FALSE(dir_->SaveChanges()); 1385 ASSERT_FALSE(dir_->SaveChanges());
1381 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); 1386 EXPECT_TRUE(IsInMetahandlesToPurge(handle1));
1382 } 1387 }
1383 1388
1384 // Create items of each model type, and check that GetModelType and 1389 // Create items of each model type, and check that GetModelType and
1385 // GetServerModelType return the right value. 1390 // GetServerModelType return the right value.
1386 TEST_F(SyncableDirectoryTest, GetModelType) { 1391 TEST_F(SyncableDirectoryTest, GetModelType) {
1387 TestIdFactory id_factory; 1392 TestIdFactory id_factory;
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1897 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1893 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1898 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1894 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1899 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1895 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1900 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1896 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1901 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1897 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1902 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1898 } 1903 }
1899 1904
1900 } // namespace 1905 } // namespace
1901 } // namespace syncable 1906 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.cc ('k') | chrome/browser/sync/syncable/transaction_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698