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

Side by Side Diff: chrome/browser/sync/engine/syncer_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 // 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 (syncable::ModelEnumSet::Iterator it = enabled_datatypes_.First(); 147 for (syncable::ModelTypeSet::Iterator it = enabled_datatypes_.First();
148 it.Good(); it.Inc()) { 148 it.Good(); it.Inc()) {
149 (*out)[it.Get()] = GROUP_PASSIVE; 149 (*out)[it.Get()] = GROUP_PASSIVE;
150 } 150 }
151 } 151 }
152 152
153 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { 153 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE {
154 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; 154 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened;
155 // we only test for entry-specific events, not status changed ones. 155 // we only test for entry-specific events, not status changed ones.
156 switch (event.what_happened) { 156 switch (event.what_happened) {
157 case SyncEngineEvent::STATUS_CHANGED: 157 case SyncEngineEvent::STATUS_CHANGED:
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 StatusController* status = session_->mutable_status_controller(); 363 StatusController* status = session_->mutable_status_controller();
364 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); 364 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
365 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 365 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
366 status->set_unsynced_handles(unsynced_handle_view); 366 status->set_unsynced_handles(unsynced_handle_view);
367 367
368 ModelSafeRoutingInfo routes; 368 ModelSafeRoutingInfo routes;
369 GetModelSafeRoutingInfo(&routes); 369 GetModelSafeRoutingInfo(&routes);
370 GetCommitIdsCommand command(limit); 370 GetCommitIdsCommand command(limit);
371 command.BuildCommitIds( 371 command.BuildCommitIds(
372 session_->status_controller().unsynced_handles(), 372 session_->status_controller().unsynced_handles(),
373 session_->write_transaction(), routes, syncable::ModelEnumSet()); 373 session_->write_transaction(), routes, syncable::ModelTypeSet());
374 vector<syncable::Id> output = 374 vector<syncable::Id> output =
375 command.ordered_commit_set_->GetAllCommitIds(); 375 command.ordered_commit_set_->GetAllCommitIds();
376 size_t truncated_size = std::min(limit, expected_id_order.size()); 376 size_t truncated_size = std::min(limit, expected_id_order.size());
377 ASSERT_TRUE(truncated_size == output.size()); 377 ASSERT_TRUE(truncated_size == output.size());
378 for (size_t i = 0; i < truncated_size; ++i) { 378 for (size_t i = 0; i < truncated_size; ++i) {
379 ASSERT_TRUE(expected_id_order[i] == output[i]) 379 ASSERT_TRUE(expected_id_order[i] == output[i])
380 << "At index " << i << " with batch size limited to " << limit; 380 << "At index " << i << " with batch size limited to " << limit;
381 } 381 }
382 sessions::OrderedCommitSet::Projection proj; 382 sessions::OrderedCommitSet::Projection proj;
383 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); 383 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 Syncer* syncer_; 488 Syncer* syncer_;
489 489
490 scoped_ptr<SyncSession> session_; 490 scoped_ptr<SyncSession> session_;
491 scoped_ptr<SyncSessionContext> context_; 491 scoped_ptr<SyncSessionContext> context_;
492 bool saw_syncer_event_; 492 bool saw_syncer_event_;
493 base::TimeDelta last_short_poll_interval_received_; 493 base::TimeDelta last_short_poll_interval_received_;
494 base::TimeDelta last_long_poll_interval_received_; 494 base::TimeDelta last_long_poll_interval_received_;
495 base::TimeDelta last_sessions_commit_delay_seconds_; 495 base::TimeDelta last_sessions_commit_delay_seconds_;
496 scoped_refptr<ModelSafeWorker> worker_; 496 scoped_refptr<ModelSafeWorker> worker_;
497 497
498 syncable::ModelEnumSet enabled_datatypes_; 498 syncable::ModelTypeSet enabled_datatypes_;
499 499
500 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 500 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
501 }; 501 };
502 502
503 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 503 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
504 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 504 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
505 ASSERT_TRUE(dir.good()); 505 ASSERT_TRUE(dir.good());
506 { 506 {
507 Syncer::UnsyncedMetaHandles handles; 507 Syncer::UnsyncedMetaHandles handles;
508 { 508 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 expected_order.push_back(ids_.MakeLocal("x")); 551 expected_order.push_back(ids_.MakeLocal("x"));
552 expected_order.push_back(ids_.MakeLocal("b")); 552 expected_order.push_back(ids_.MakeLocal("b"));
553 expected_order.push_back(ids_.MakeLocal("c")); 553 expected_order.push_back(ids_.MakeLocal("c"));
554 expected_order.push_back(ids_.MakeLocal("e")); 554 expected_order.push_back(ids_.MakeLocal("e"));
555 DoTruncationTest(dir, unsynced_handle_view, expected_order); 555 DoTruncationTest(dir, unsynced_handle_view, expected_order);
556 } 556 }
557 557
558 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { 558 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
559 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 559 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
560 ASSERT_TRUE(dir.good()); 560 ASSERT_TRUE(dir.good());
561 const syncable::ModelEnumSet throttled_types(syncable::BOOKMARKS); 561 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS);
562 KeyParams key_params = {"localhost", "dummy", "foobar"}; 562 KeyParams key_params = {"localhost", "dummy", "foobar"};
563 sync_pb::EntitySpecifics bookmark_data; 563 sync_pb::EntitySpecifics bookmark_data;
564 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data); 564 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data);
565 565
566 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 566 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
567 SyncShareAsDelegate(); 567 SyncShareAsDelegate();
568 568
569 { 569 {
570 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); 570 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
571 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 571 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 849
850 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); 850 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim");
851 ASSERT_TRUE(parent2.good()); 851 ASSERT_TRUE(parent2.good());
852 parent2.Put(syncable::IS_UNSYNCED, true); 852 parent2.Put(syncable::IS_UNSYNCED, true);
853 parent2.Put(syncable::IS_DIR, true); 853 parent2.Put(syncable::IS_DIR, true);
854 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); 854 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics());
855 parent2.Put(syncable::BASE_VERSION, 1); 855 parent2.Put(syncable::BASE_VERSION, 1);
856 parent2.Put(syncable::ID, pref_node_id); 856 parent2.Put(syncable::ID, pref_node_id);
857 } 857 }
858 858
859 dir->PurgeEntriesWithTypeIn(syncable::ModelEnumSet(syncable::PREFERENCES)); 859 dir->PurgeEntriesWithTypeIn(syncable::ModelTypeSet(syncable::PREFERENCES));
860 860
861 const StatusController& status = session_->status_controller(); 861 const StatusController& status = session_->status_controller();
862 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 862 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
863 EXPECT_EQ(2U, status.unsynced_handles().size()); 863 EXPECT_EQ(2U, status.unsynced_handles().size());
864 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 864 ASSERT_EQ(2U, mock_server_->committed_ids().size());
865 // If this test starts failing, be aware other sort orders could be valid. 865 // If this test starts failing, be aware other sort orders could be valid.
866 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 866 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
867 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 867 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
868 { 868 {
869 ReadTransaction rt(FROM_HERE, dir); 869 ReadTransaction rt(FROM_HERE, dir);
(...skipping 17 matching lines...) Expand all
887 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); 887 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
888 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 888 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete");
889 ASSERT_TRUE(parent.good()); 889 ASSERT_TRUE(parent.good());
890 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); 890 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true);
891 parent.Put(syncable::IS_DIR, true); 891 parent.Put(syncable::IS_DIR, true);
892 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 892 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
893 parent.Put(syncable::BASE_VERSION, 1); 893 parent.Put(syncable::BASE_VERSION, 1);
894 parent.Put(syncable::ID, parent_id_); 894 parent.Put(syncable::ID, parent_id_);
895 } 895 }
896 896
897 dir->PurgeEntriesWithTypeIn(syncable::ModelEnumSet(syncable::BOOKMARKS)); 897 dir->PurgeEntriesWithTypeIn(syncable::ModelTypeSet(syncable::BOOKMARKS));
898 898
899 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 899 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
900 dir->SaveChanges(); 900 dir->SaveChanges();
901 { 901 {
902 ReadTransaction rt(FROM_HERE, dir); 902 ReadTransaction rt(FROM_HERE, dir);
903 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); 903 Entry entry(&rt, syncable::GET_BY_ID, parent_id_);
904 ASSERT_FALSE(entry.good()); 904 ASSERT_FALSE(entry.good());
905 } 905 }
906 } 906 }
907 907
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 SyncShareAsDelegate(); 2149 SyncShareAsDelegate();
2150 { 2150 {
2151 ReadTransaction trans(FROM_HERE, dir); 2151 ReadTransaction trans(FROM_HERE, dir);
2152 Entry entry(&trans, syncable::GET_BY_ID, id); 2152 Entry entry(&trans, syncable::GET_BY_ID, id);
2153 ASSERT_TRUE(entry.good()); 2153 ASSERT_TRUE(entry.good());
2154 EXPECT_TRUE(entry.Get(MTIME) == test_time); 2154 EXPECT_TRUE(entry.Get(MTIME) == test_time);
2155 } 2155 }
2156 } 2156 }
2157 2157
2158 TEST_F(SyncerTest, ParentAndChildBothMatch) { 2158 TEST_F(SyncerTest, ParentAndChildBothMatch) {
2159 const syncable::FullModelEnumSet all_types = 2159 const syncable::FullModelTypeSet all_types =
2160 syncable::FullModelEnumSet::All(); 2160 syncable::FullModelTypeSet::All();
2161 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2161 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2162 CHECK(dir.good()); 2162 CHECK(dir.good());
2163 syncable::Id parent_id = ids_.NewServerId(); 2163 syncable::Id parent_id = ids_.NewServerId();
2164 syncable::Id child_id = ids_.NewServerId(); 2164 syncable::Id child_id = ids_.NewServerId();
2165 2165
2166 { 2166 {
2167 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); 2167 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
2168 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); 2168 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder");
2169 ASSERT_TRUE(parent.good()); 2169 ASSERT_TRUE(parent.good());
2170 parent.Put(IS_DIR, true); 2170 parent.Put(IS_DIR, true);
(...skipping 3180 matching lines...) Expand 10 before | Expand all | Expand 10 after
5351 Add(low_id_); 5351 Add(low_id_);
5352 Add(high_id_); 5352 Add(high_id_);
5353 SyncShareAsDelegate(); 5353 SyncShareAsDelegate();
5354 ExpectLocalOrderIsByServerId(); 5354 ExpectLocalOrderIsByServerId();
5355 } 5355 }
5356 5356
5357 const SyncerTest::CommitOrderingTest 5357 const SyncerTest::CommitOrderingTest
5358 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; 5358 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()};
5359 5359
5360 } // namespace browser_sync 5360 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_proto_util_unittest.cc ('k') | chrome/browser/sync/engine/syncer_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698