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

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

Issue 8919021: [Sync] Rename ModelEnumSet to ModelTypeSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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(ModelEnumSet types_to_purge, 449 void CheckPurgeEntriesWithTypeInSucceeded(ModelTypeSet 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 const ModelType local_type = e.GetModelType(); 462 const ModelType local_type = e.GetModelType();
463 const ModelType server_type = e.GetServerModelType(); 463 const ModelType server_type = e.GetServerModelType();
464 464
465 // Note the dance around incrementing |it|, since we sometimes erase(). 465 // Note the dance around incrementing |it|, since we sometimes erase().
466 if ((IsRealDataType(local_type) && 466 if ((IsRealDataType(local_type) &&
467 types_to_purge.Has(local_type)) || 467 types_to_purge.Has(local_type)) ||
468 (IsRealDataType(server_type) && 468 (IsRealDataType(server_type) &&
469 types_to_purge.Has(server_type))) { 469 types_to_purge.Has(server_type))) {
470 FAIL() << "Illegal type should have been deleted."; 470 FAIL() << "Illegal type should have been deleted.";
471 } 471 }
472 } 472 }
473 } 473 }
474 474
475 for (ModelEnumSet::Iterator it = types_to_purge.First(); 475 for (ModelTypeSet::Iterator it = types_to_purge.First();
476 it.Good(); it.Inc()) { 476 it.Good(); it.Inc()) {
477 EXPECT_FALSE(dir_->initial_sync_ended_for_type(it.Get())); 477 EXPECT_FALSE(dir_->initial_sync_ended_for_type(it.Get()));
478 } 478 }
479 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS)); 479 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS));
480 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 480 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS));
481 } 481 }
482 482
483 scoped_ptr<Directory> dir_; 483 scoped_ptr<Directory> dir_;
484 FilePath file_path_; 484 FilePath file_path_;
485 NullDirectoryChangeDelegate delegate_; 485 NullDirectoryChangeDelegate delegate_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 all_handles.insert(e.Get(META_HANDLE)); 526 all_handles.insert(e.Get(META_HANDLE));
527 } else { 527 } else {
528 AddDefaultExtensionValue(PREFERENCES, &specs); 528 AddDefaultExtensionValue(PREFERENCES, &specs);
529 all_handles.insert(e.Get(META_HANDLE)); 529 all_handles.insert(e.Get(META_HANDLE));
530 } 530 }
531 e.Put(SPECIFICS, specs); 531 e.Put(SPECIFICS, specs);
532 e.Put(SERVER_SPECIFICS, specs); 532 e.Put(SERVER_SPECIFICS, specs);
533 } 533 }
534 } 534 }
535 535
536 syncable::ModelEnumSet to_purge(BOOKMARKS); 536 syncable::ModelTypeSet to_purge(BOOKMARKS);
537 dir_->PurgeEntriesWithTypeIn(to_purge); 537 dir_->PurgeEntriesWithTypeIn(to_purge);
538 538
539 Directory::SaveChangesSnapshot snapshot1; 539 Directory::SaveChangesSnapshot snapshot1;
540 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); 540 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
541 dir_->TakeSnapshotForSaveChanges(&snapshot1); 541 dir_->TakeSnapshotForSaveChanges(&snapshot1);
542 EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge); 542 EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge);
543 543
544 to_purge.Clear(); 544 to_purge.Clear();
545 to_purge.Put(PREFERENCES); 545 to_purge.Put(PREFERENCES);
546 dir_->PurgeEntriesWithTypeIn(to_purge); 546 dir_->PurgeEntriesWithTypeIn(to_purge);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 sync_pb::EntitySpecifics bookmark_specs; 616 sync_pb::EntitySpecifics bookmark_specs;
617 sync_pb::EntitySpecifics autofill_specs; 617 sync_pb::EntitySpecifics autofill_specs;
618 sync_pb::EntitySpecifics preference_specs; 618 sync_pb::EntitySpecifics preference_specs;
619 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); 619 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs);
620 AddDefaultExtensionValue(PREFERENCES, &preference_specs); 620 AddDefaultExtensionValue(PREFERENCES, &preference_specs);
621 AddDefaultExtensionValue(AUTOFILL, &autofill_specs); 621 AddDefaultExtensionValue(AUTOFILL, &autofill_specs);
622 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); 622 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true);
623 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); 623 dir_->set_initial_sync_ended_for_type(PREFERENCES, true);
624 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); 624 dir_->set_initial_sync_ended_for_type(AUTOFILL, true);
625 625
626 syncable::ModelEnumSet types_to_purge(PREFERENCES, AUTOFILL); 626 syncable::ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL);
627 627
628 TestIdFactory id_factory; 628 TestIdFactory id_factory;
629 // Create some items for each type. 629 // Create some items for each type.
630 { 630 {
631 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 631 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
632 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); 632 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item");
633 ASSERT_TRUE(item1.good()); 633 ASSERT_TRUE(item1.good());
634 item1.Put(SPECIFICS, bookmark_specs); 634 item1.Put(SPECIFICS, bookmark_specs);
635 item1.Put(SERVER_SPECIFICS, bookmark_specs); 635 item1.Put(SERVER_SPECIFICS, bookmark_specs);
636 item1.Put(IS_UNSYNCED, true); 636 item1.Put(IS_UNSYNCED, true);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 878 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
879 dir_->GetUnsyncedMetaHandles(&trans, &handles); 879 dir_->GetUnsyncedMetaHandles(&trans, &handles);
880 ASSERT_TRUE(1 == handles.size()); 880 ASSERT_TRUE(1 == handles.size());
881 ASSERT_TRUE(handle2 == handles[0]); 881 ASSERT_TRUE(handle2 == handles[0]);
882 } 882 }
883 } 883 }
884 884
885 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { 885 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) {
886 Directory::UnappliedUpdateMetaHandles handles; 886 Directory::UnappliedUpdateMetaHandles handles;
887 int64 handle1, handle2; 887 int64 handle1, handle2;
888 const syncable::FullModelEnumSet all_types = 888 const syncable::FullModelTypeSet all_types =
889 syncable::FullModelEnumSet::All(); 889 syncable::FullModelTypeSet::All();
890 { 890 {
891 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 891 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
892 892
893 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); 893 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
894 ASSERT_TRUE(0 == handles.size()); 894 ASSERT_TRUE(0 == handles.size());
895 895
896 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); 896 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba");
897 ASSERT_TRUE(e1.good()); 897 ASSERT_TRUE(e1.good());
898 handle1 = e1.Get(META_HANDLE); 898 handle1 = e1.Get(META_HANDLE);
899 e1.Put(IS_UNAPPLIED_UPDATE, false); 899 e1.Put(IS_UNAPPLIED_UPDATE, false);
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 ASSERT_TRUE(dir_->SaveChanges()); 1372 ASSERT_TRUE(dir_->SaveChanges());
1373 1373
1374 // Now do some operations using a directory for which SaveChanges will 1374 // Now do some operations using a directory for which SaveChanges will
1375 // always fail. 1375 // always fail.
1376 dir_.reset(new TestUnsaveableDirectory()); 1376 dir_.reset(new TestUnsaveableDirectory());
1377 ASSERT_TRUE(dir_.get()); 1377 ASSERT_TRUE(dir_.get());
1378 ASSERT_EQ(OPENED, dir_->Open(file_path_, kName, 1378 ASSERT_EQ(OPENED, dir_->Open(file_path_, kName,
1379 &delegate_, NullTransactionObserver())); 1379 &delegate_, NullTransactionObserver()));
1380 ASSERT_TRUE(dir_->good()); 1380 ASSERT_TRUE(dir_->good());
1381 1381
1382 syncable::ModelEnumSet set(BOOKMARKS); 1382 syncable::ModelTypeSet set(BOOKMARKS);
1383 dir_->PurgeEntriesWithTypeIn(set); 1383 dir_->PurgeEntriesWithTypeIn(set);
1384 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); 1384 EXPECT_TRUE(IsInMetahandlesToPurge(handle1));
1385 ASSERT_FALSE(dir_->SaveChanges()); 1385 ASSERT_FALSE(dir_->SaveChanges());
1386 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); 1386 EXPECT_TRUE(IsInMetahandlesToPurge(handle1));
1387 } 1387 }
1388 1388
1389 // Create items of each model type, and check that GetModelType and 1389 // Create items of each model type, and check that GetModelType and
1390 // GetServerModelType return the right value. 1390 // GetServerModelType return the right value.
1391 TEST_F(SyncableDirectoryTest, GetModelType) { 1391 TEST_F(SyncableDirectoryTest, GetModelType) {
1392 TestIdFactory id_factory; 1392 TestIdFactory id_factory;
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1897 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1898 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1898 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1899 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1899 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1900 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1900 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1901 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1901 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1902 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1902 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1903 } 1903 }
1904 1904
1905 } // namespace 1905 } // namespace
1906 } // 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