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

Side by Side Diff: components/sync/engine_impl/syncer_unittest.cc

Issue 2641523004: [Sync] Make directory types registration explicit in ModelTypeRegistry (Closed)
Patch Set: Address comments Created 3 years, 11 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/sync/engine_impl/syncer.h" 5 #include "components/sync/engine_impl/syncer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 last_bookmarks_commit_delay_ = iter->second; 212 last_bookmarks_commit_delay_ = iter->second;
213 } 213 }
214 void OnReceivedClientInvalidationHintBufferSize(int size) override { 214 void OnReceivedClientInvalidationHintBufferSize(int size) override {
215 last_client_invalidation_hint_buffer_size_ = size; 215 last_client_invalidation_hint_buffer_size_ = size;
216 } 216 }
217 void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override {} 217 void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override {}
218 void OnReceivedMigrationRequest(ModelTypeSet types) override {} 218 void OnReceivedMigrationRequest(ModelTypeSet types) override {}
219 void OnProtocolEvent(const ProtocolEvent& event) override {} 219 void OnProtocolEvent(const ProtocolEvent& event) override {}
220 void OnSyncProtocolError(const SyncProtocolError& error) override {} 220 void OnSyncProtocolError(const SyncProtocolError& error) override {}
221 221
222 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
223 // We're just testing the sync engine here, so we shunt everything to
224 // the SyncerThread. Datatypes which aren't enabled aren't in the map.
225 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); it.Good();
226 it.Inc()) {
227 (*out)[it.Get()] = GROUP_PASSIVE;
228 }
229 }
230
231 void OnSyncCycleEvent(const SyncCycleEvent& event) override { 222 void OnSyncCycleEvent(const SyncCycleEvent& event) override {
232 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; 223 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened;
233 // we only test for entry-specific events, not status changed ones. 224 // we only test for entry-specific events, not status changed ones.
234 switch (event.what_happened) { 225 switch (event.what_happened) {
235 case SyncCycleEvent::SYNC_CYCLE_BEGIN: // Fall through. 226 case SyncCycleEvent::SYNC_CYCLE_BEGIN: // Fall through.
236 case SyncCycleEvent::STATUS_CHANGED: 227 case SyncCycleEvent::STATUS_CHANGED:
237 case SyncCycleEvent::SYNC_CYCLE_ENDED: 228 case SyncCycleEvent::SYNC_CYCLE_ENDED:
238 return; 229 return;
239 default: 230 default:
240 FAIL() << "Handling unknown error type in unit tests!!"; 231 FAIL() << "Handling unknown error type in unit tests!!";
(...skipping 23 matching lines...) Expand all
264 return syncer_->ConfigureSyncShare( 255 return syncer_->ConfigureSyncShare(
265 context_->GetEnabledTypes(), 256 context_->GetEnabledTypes(),
266 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, cycle_.get()); 257 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, cycle_.get());
267 } 258 }
268 259
269 void SetUp() override { 260 void SetUp() override {
270 test_user_share_.SetUp(); 261 test_user_share_.SetUp();
271 mock_server_ = base::MakeUnique<MockConnectionManager>( 262 mock_server_ = base::MakeUnique<MockConnectionManager>(
272 directory(), &cancelation_signal_); 263 directory(), &cancelation_signal_);
273 debug_info_getter_ = base::MakeUnique<MockDebugInfoGetter>(); 264 debug_info_getter_ = base::MakeUnique<MockDebugInfoGetter>();
274 EnableDatatype(BOOKMARKS);
275 EnableDatatype(EXTENSIONS);
276 EnableDatatype(NIGORI);
277 EnableDatatype(PREFERENCES);
278 EnableDatatype(NIGORI);
279 workers_.push_back( 265 workers_.push_back(
280 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE))); 266 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE)));
281 std::vector<SyncEngineEventListener*> listeners; 267 std::vector<SyncEngineEventListener*> listeners;
282 listeners.push_back(this); 268 listeners.push_back(this);
283 269
284 ModelSafeRoutingInfo routing_info;
285 GetModelSafeRoutingInfo(&routing_info);
286
287 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( 270 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>(
288 workers_, test_user_share_.user_share(), &mock_nudge_handler_, 271 workers_, test_user_share_.user_share(), &mock_nudge_handler_,
289 UssMigrator()); 272 UssMigrator());
290 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( 273 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver(
291 &debug_info_cache_); 274 &debug_info_cache_);
292 275
276 EnableDatatype(BOOKMARKS);
277 EnableDatatype(EXTENSIONS);
278 EnableDatatype(NIGORI);
279 EnableDatatype(PREFERENCES);
280
293 context_ = base::MakeUnique<SyncCycleContext>( 281 context_ = base::MakeUnique<SyncCycleContext>(
294 mock_server_.get(), directory(), extensions_activity_.get(), listeners, 282 mock_server_.get(), directory(), extensions_activity_.get(), listeners,
295 debug_info_getter_.get(), model_type_registry_.get(), 283 debug_info_getter_.get(), model_type_registry_.get(),
296 true, // enable keystore encryption 284 true, // enable keystore encryption
297 false, // force enable pre-commit GU avoidance experiment 285 false, // force enable pre-commit GU avoidance experiment
298 "fake_invalidator_client_id"); 286 "fake_invalidator_client_id");
299 context_->SetRoutingInfo(routing_info);
300 syncer_ = new Syncer(&cancelation_signal_); 287 syncer_ = new Syncer(&cancelation_signal_);
301 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( 288 scheduler_ = base::MakeUnique<SyncSchedulerImpl>(
302 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), 289 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(),
303 context_.get(), 290 context_.get(),
304 // scheduler_ owned syncer_ now and will manage the memory of syncer_ 291 // scheduler_ owned syncer_ now and will manage the memory of syncer_
305 syncer_, false); 292 syncer_, false);
306 293
307 syncable::ReadTransaction trans(FROM_HERE, directory()); 294 syncable::ReadTransaction trans(FROM_HERE, directory());
308 Directory::Metahandles children; 295 Directory::Metahandles children;
309 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 296 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 entry.PutIsUnsynced(true); 490 entry.PutIsUnsynced(true);
504 entry.PutIsDir(true); 491 entry.PutIsDir(true);
505 entry.PutSpecifics(DefaultBookmarkSpecifics()); 492 entry.PutSpecifics(DefaultBookmarkSpecifics());
506 entry.PutBaseVersion(id.ServerKnows() ? 1 : 0); 493 entry.PutBaseVersion(id.ServerKnows() ? 1 : 0);
507 entry.PutId(id); 494 entry.PutId(id);
508 return entry.GetMetahandle(); 495 return entry.GetMetahandle();
509 } 496 }
510 497
511 void EnableDatatype(ModelType model_type) { 498 void EnableDatatype(ModelType model_type) {
512 enabled_datatypes_.Put(model_type); 499 enabled_datatypes_.Put(model_type);
513 500 model_type_registry_->RegisterDirectoryType(model_type, GROUP_PASSIVE);
514 ModelSafeRoutingInfo routing_info;
515 GetModelSafeRoutingInfo(&routing_info);
516
517 if (context_) {
518 context_->SetRoutingInfo(routing_info);
519 }
520
521 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 501 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
522 } 502 }
523 503
524 void DisableDatatype(ModelType model_type) { 504 void DisableDatatype(ModelType model_type) {
525 enabled_datatypes_.Remove(model_type); 505 enabled_datatypes_.Remove(model_type);
526 506 model_type_registry_->UnregisterDirectoryType(model_type);
527 ModelSafeRoutingInfo routing_info;
528 GetModelSafeRoutingInfo(&routing_info);
529
530 if (context_) {
531 context_->SetRoutingInfo(routing_info);
532 }
533
534 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 507 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
535 } 508 }
536 509
537 Cryptographer* GetCryptographer(syncable::BaseTransaction* trans) { 510 Cryptographer* GetCryptographer(syncable::BaseTransaction* trans) {
538 return directory()->GetCryptographer(trans); 511 return directory()->GetCryptographer(trans);
539 } 512 }
540 513
541 // Configures SyncCycleContext and NudgeTracker so Syncer won't call 514 // Configures SyncCycleContext and NudgeTracker so Syncer won't call
542 // GetUpdates prior to Commit. This method can be used to ensure a Commit is 515 // GetUpdates prior to Commit. This method can be used to ensure a Commit is
543 // not preceeded by GetUpdates. 516 // not preceeded by GetUpdates.
(...skipping 4345 matching lines...) Expand 10 before | Expand all | Expand 10 after
4889 ASSERT_TRUE(!hurdle.GetIsDel()); 4862 ASSERT_TRUE(!hurdle.GetIsDel());
4890 ASSERT_TRUE(hurdle.GetUniqueServerTag().empty()); 4863 ASSERT_TRUE(hurdle.GetUniqueServerTag().empty());
4891 ASSERT_EQ("bob", hurdle.GetNonUniqueName()); 4864 ASSERT_EQ("bob", hurdle.GetNonUniqueName());
4892 } 4865 }
4893 } 4866 }
4894 4867
4895 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) { 4868 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) {
4896 // The expectations of this test happen in the MockConnectionManager's 4869 // The expectations of this test happen in the MockConnectionManager's
4897 // GetUpdates handler. EnableDatatype sets the expectation value from our 4870 // GetUpdates handler. EnableDatatype sets the expectation value from our
4898 // set of enabled/disabled datatypes. 4871 // set of enabled/disabled datatypes.
4899 EnableDatatype(BOOKMARKS);
4900 EXPECT_TRUE(SyncShareNudge()); 4872 EXPECT_TRUE(SyncShareNudge());
4901 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4873 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4902 4874
4903 EnableDatatype(AUTOFILL); 4875 EnableDatatype(AUTOFILL);
4904 EXPECT_TRUE(SyncShareNudge()); 4876 EXPECT_TRUE(SyncShareNudge());
4905 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4877 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4906 4878
4907 EnableDatatype(PREFERENCES);
4908 EXPECT_TRUE(SyncShareNudge());
4909 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4910
4911 DisableDatatype(BOOKMARKS); 4879 DisableDatatype(BOOKMARKS);
4912 EXPECT_TRUE(SyncShareNudge()); 4880 EXPECT_TRUE(SyncShareNudge());
4913 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4881 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4914 4882
4915 DisableDatatype(AUTOFILL); 4883 DisableDatatype(AUTOFILL);
4916 EXPECT_TRUE(SyncShareNudge()); 4884 EXPECT_TRUE(SyncShareNudge());
4917 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4885 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4918 4886
4919 DisableDatatype(PREFERENCES); 4887 DisableDatatype(PREFERENCES);
4920 EnableDatatype(AUTOFILL); 4888 EnableDatatype(AUTOFILL);
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
5925 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 5893 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
5926 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 5894 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
5927 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 5895 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
5928 } else { 5896 } else {
5929 EXPECT_TRUE(final_monitor_records.empty()) 5897 EXPECT_TRUE(final_monitor_records.empty())
5930 << "Should not restore records after successful bookmark commit."; 5898 << "Should not restore records after successful bookmark commit.";
5931 } 5899 }
5932 } 5900 }
5933 5901
5934 } // namespace syncer 5902 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/sync_scheduler_impl_unittest.cc ('k') | components/sync/tools/sync_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698