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