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

Side by Side Diff: chrome/browser/sync/engine/syncer_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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 // ModelSafeWorkerRegistrar implementation. 139 // ModelSafeWorkerRegistrar implementation.
140 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE { 140 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE {
141 out->push_back(worker_.get()); 141 out->push_back(worker_.get());
142 } 142 }
143 143
144 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE { 144 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE {
145 // We're just testing the sync engine here, so we shunt everything to 145 // We're just testing the sync engine here, so we shunt everything to
146 // the SyncerThread. Datatypes which aren't enabled aren't in the map. 146 // the SyncerThread. Datatypes which aren't enabled aren't in the map.
147 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { 147 for (syncable::ModelEnumSet::Iterator it = enabled_datatypes_.First();
148 if (enabled_datatypes_[i]) { 148 it.Good(); it.Inc()) {
149 (*out)[syncable::ModelTypeFromInt(i)] = GROUP_PASSIVE; 149 (*out)[it.Get()] = GROUP_PASSIVE;
150 }
151 } 150 }
152 } 151 }
153 152
154 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { 153 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE {
155 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; 154 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened;
156 // we only test for entry-specific events, not status changed ones. 155 // we only test for entry-specific events, not status changed ones.
157 switch (event.what_happened) { 156 switch (event.what_happened) {
158 case SyncEngineEvent::STATUS_CHANGED: 157 case SyncEngineEvent::STATUS_CHANGED:
159 // fall through 158 // fall through
160 case SyncEngineEvent::SYNC_CYCLE_ENDED: 159 case SyncEngineEvent::SYNC_CYCLE_ENDED:
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 EXPECT_TRUE(entry.good()); 409 EXPECT_TRUE(entry.good());
411 entry.Put(syncable::IS_UNSYNCED, true); 410 entry.Put(syncable::IS_UNSYNCED, true);
412 entry.Put(syncable::IS_DIR, true); 411 entry.Put(syncable::IS_DIR, true);
413 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 412 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
414 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); 413 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0);
415 entry.Put(syncable::ID, id); 414 entry.Put(syncable::ID, id);
416 return entry.Get(META_HANDLE); 415 return entry.Get(META_HANDLE);
417 } 416 }
418 417
419 void EnableDatatype(syncable::ModelType model_type) { 418 void EnableDatatype(syncable::ModelType model_type) {
420 enabled_datatypes_[model_type] = true; 419 enabled_datatypes_.Put(model_type);
421 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 420 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
422 } 421 }
423 422
424 void DisableDatatype(syncable::ModelType model_type) { 423 void DisableDatatype(syncable::ModelType model_type) {
425 enabled_datatypes_[model_type] = false; 424 enabled_datatypes_.Remove(model_type);
426 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 425 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
427 } 426 }
428 427
429 template<typename FieldType, typename ValueType> 428 template<typename FieldType, typename ValueType>
430 ValueType GetField(int64 metahandle, FieldType field, 429 ValueType GetField(int64 metahandle, FieldType field,
431 ValueType default_value) const { 430 ValueType default_value) const {
432 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 431 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
433 EXPECT_TRUE(dir.good()); 432 EXPECT_TRUE(dir.good());
434 ReadTransaction trans(FROM_HERE, dir); 433 ReadTransaction trans(FROM_HERE, dir);
435 Entry entry(&trans, GET_BY_HANDLE, metahandle); 434 Entry entry(&trans, GET_BY_HANDLE, metahandle);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 Syncer* syncer_; 488 Syncer* syncer_;
490 489
491 scoped_ptr<SyncSession> session_; 490 scoped_ptr<SyncSession> session_;
492 scoped_ptr<SyncSessionContext> context_; 491 scoped_ptr<SyncSessionContext> context_;
493 bool saw_syncer_event_; 492 bool saw_syncer_event_;
494 base::TimeDelta last_short_poll_interval_received_; 493 base::TimeDelta last_short_poll_interval_received_;
495 base::TimeDelta last_long_poll_interval_received_; 494 base::TimeDelta last_long_poll_interval_received_;
496 base::TimeDelta last_sessions_commit_delay_seconds_; 495 base::TimeDelta last_sessions_commit_delay_seconds_;
497 scoped_refptr<ModelSafeWorker> worker_; 496 scoped_refptr<ModelSafeWorker> worker_;
498 497
499 syncable::ModelTypeBitSet enabled_datatypes_; 498 syncable::ModelEnumSet enabled_datatypes_;
500 499
501 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 500 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
502 }; 501 };
503 502
504 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 503 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
505 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 504 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
506 ASSERT_TRUE(dir.good()); 505 ASSERT_TRUE(dir.good());
507 { 506 {
508 Syncer::UnsyncedMetaHandles handles; 507 Syncer::UnsyncedMetaHandles handles;
509 { 508 {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 850
852 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); 851 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim");
853 ASSERT_TRUE(parent2.good()); 852 ASSERT_TRUE(parent2.good());
854 parent2.Put(syncable::IS_UNSYNCED, true); 853 parent2.Put(syncable::IS_UNSYNCED, true);
855 parent2.Put(syncable::IS_DIR, true); 854 parent2.Put(syncable::IS_DIR, true);
856 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); 855 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics());
857 parent2.Put(syncable::BASE_VERSION, 1); 856 parent2.Put(syncable::BASE_VERSION, 1);
858 parent2.Put(syncable::ID, pref_node_id); 857 parent2.Put(syncable::ID, pref_node_id);
859 } 858 }
860 859
861 std::set<syncable::ModelType> types_to_purge; 860 dir->PurgeEntriesWithTypeIn(syncable::ModelEnumSet(syncable::PREFERENCES));
862 types_to_purge.insert(syncable::PREFERENCES);
863 dir->PurgeEntriesWithTypeIn(types_to_purge);
864 861
865 const StatusController& status = session_->status_controller(); 862 const StatusController& status = session_->status_controller();
866 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 863 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
867 EXPECT_EQ(2U, status.unsynced_handles().size()); 864 EXPECT_EQ(2U, status.unsynced_handles().size());
868 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 865 ASSERT_EQ(2U, mock_server_->committed_ids().size());
869 // If this test starts failing, be aware other sort orders could be valid. 866 // If this test starts failing, be aware other sort orders could be valid.
870 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 867 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
871 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 868 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
872 { 869 {
873 ReadTransaction rt(FROM_HERE, dir); 870 ReadTransaction rt(FROM_HERE, dir);
(...skipping 17 matching lines...) Expand all
891 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); 888 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
892 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 889 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete");
893 ASSERT_TRUE(parent.good()); 890 ASSERT_TRUE(parent.good());
894 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); 891 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true);
895 parent.Put(syncable::IS_DIR, true); 892 parent.Put(syncable::IS_DIR, true);
896 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 893 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
897 parent.Put(syncable::BASE_VERSION, 1); 894 parent.Put(syncable::BASE_VERSION, 1);
898 parent.Put(syncable::ID, parent_id_); 895 parent.Put(syncable::ID, parent_id_);
899 } 896 }
900 897
901 std::set<syncable::ModelType> types_to_purge; 898 dir->PurgeEntriesWithTypeIn(syncable::ModelEnumSet(syncable::BOOKMARKS));
902 types_to_purge.insert(syncable::BOOKMARKS);
903 dir->PurgeEntriesWithTypeIn(types_to_purge);
904 899
905 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 900 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
906 dir->SaveChanges(); 901 dir->SaveChanges();
907 { 902 {
908 ReadTransaction rt(FROM_HERE, dir); 903 ReadTransaction rt(FROM_HERE, dir);
909 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); 904 Entry entry(&rt, syncable::GET_BY_ID, parent_id_);
910 ASSERT_FALSE(entry.good()); 905 ASSERT_FALSE(entry.good());
911 } 906 }
912 } 907 }
913 908
(...skipping 4443 matching lines...) Expand 10 before | Expand all | Expand 10 after
5357 Add(low_id_); 5352 Add(low_id_);
5358 Add(high_id_); 5353 Add(high_id_);
5359 SyncShareAsDelegate(); 5354 SyncShareAsDelegate();
5360 ExpectLocalOrderIsByServerId(); 5355 ExpectLocalOrderIsByServerId();
5361 } 5356 }
5362 5357
5363 const SyncerTest::CommitOrderingTest 5358 const SyncerTest::CommitOrderingTest
5364 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; 5359 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()};
5365 5360
5366 } // namespace browser_sync 5361 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler_unittest.cc ('k') | chrome/browser/sync/internal_api/sync_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698