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

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

Issue 2413313004: [Sync] Move the last things out of core/. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include "components/sync/core_impl/sync_manager_impl.h" 9 #include "components/sync/engine_impl/sync_manager_impl.h"
10 10
11 #include <cstddef> 11 #include <cstddef>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
18 #include "base/format_macros.h" 18 #include "base/format_macros.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/test/values_test_util.h" 24 #include "base/test/values_test_util.h"
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "components/sync/base/attachment_id_proto.h" 26 #include "components/sync/base/attachment_id_proto.h"
27 #include "components/sync/base/cancelation_signal.h" 27 #include "components/sync/base/cancelation_signal.h"
28 #include "components/sync/base/extensions_activity.h" 28 #include "components/sync/base/extensions_activity.h"
29 #include "components/sync/base/fake_encryptor.h" 29 #include "components/sync/base/fake_encryptor.h"
30 #include "components/sync/base/mock_unrecoverable_error_handler.h" 30 #include "components/sync/base/mock_unrecoverable_error_handler.h"
31 #include "components/sync/base/model_type_test_util.h" 31 #include "components/sync/base/model_type_test_util.h"
32 #include "components/sync/core/test/test_entry_factory.h" 32 #include "components/sync/engine/engine_util.h"
33 #include "components/sync/core/test/test_internal_components_factory.h"
34 #include "components/sync/core_impl/syncapi_internal.h"
35 #include "components/sync/engine/events/protocol_event.h" 33 #include "components/sync/engine/events/protocol_event.h"
36 #include "components/sync/engine/model_safe_worker.h" 34 #include "components/sync/engine/model_safe_worker.h"
37 #include "components/sync/engine/net/http_post_provider_factory.h" 35 #include "components/sync/engine/net/http_post_provider_factory.h"
38 #include "components/sync/engine/net/http_post_provider_interface.h" 36 #include "components/sync/engine/net/http_post_provider_interface.h"
39 #include "components/sync/engine/polling_constants.h" 37 #include "components/sync/engine/polling_constants.h"
38 #include "components/sync/engine/test_engine_components_factory.h"
40 #include "components/sync/engine_impl/cycle/sync_cycle.h" 39 #include "components/sync/engine_impl/cycle/sync_cycle.h"
41 #include "components/sync/engine_impl/sync_scheduler.h" 40 #include "components/sync/engine_impl/sync_scheduler.h"
41 #include "components/sync/engine_impl/test_entry_factory.h"
42 #include "components/sync/js/js_event_handler.h" 42 #include "components/sync/js/js_event_handler.h"
43 #include "components/sync/js/js_test_util.h" 43 #include "components/sync/js/js_test_util.h"
44 #include "components/sync/protocol/bookmark_specifics.pb.h" 44 #include "components/sync/protocol/bookmark_specifics.pb.h"
45 #include "components/sync/protocol/encryption.pb.h" 45 #include "components/sync/protocol/encryption.pb.h"
46 #include "components/sync/protocol/extension_specifics.pb.h" 46 #include "components/sync/protocol/extension_specifics.pb.h"
47 #include "components/sync/protocol/password_specifics.pb.h" 47 #include "components/sync/protocol/password_specifics.pb.h"
48 #include "components/sync/protocol/preference_specifics.pb.h" 48 #include "components/sync/protocol/preference_specifics.pb.h"
49 #include "components/sync/protocol/proto_value_conversions.h" 49 #include "components/sync/protocol/proto_value_conversions.h"
50 #include "components/sync/protocol/sync.pb.h" 50 #include "components/sync/protocol/sync.pb.h"
51 #include "components/sync/syncable/change_record.h" 51 #include "components/sync/syncable/change_record.h"
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 } // namespace 934 } // namespace
935 935
936 class SyncManagerTest : public testing::Test, 936 class SyncManagerTest : public testing::Test,
937 public SyncManager::ChangeDelegate { 937 public SyncManager::ChangeDelegate {
938 protected: 938 protected:
939 enum NigoriStatus { DONT_WRITE_NIGORI, WRITE_TO_NIGORI }; 939 enum NigoriStatus { DONT_WRITE_NIGORI, WRITE_TO_NIGORI };
940 940
941 enum EncryptionStatus { UNINITIALIZED, DEFAULT_ENCRYPTION, FULL_ENCRYPTION }; 941 enum EncryptionStatus { UNINITIALIZED, DEFAULT_ENCRYPTION, FULL_ENCRYPTION };
942 942
943 SyncManagerTest() : sync_manager_("Test sync manager") { 943 SyncManagerTest() : sync_manager_("Test sync manager") {
944 switches_.encryption_method = 944 switches_.encryption_method = EngineComponentsFactory::ENCRYPTION_KEYSTORE;
945 InternalComponentsFactory::ENCRYPTION_KEYSTORE;
946 } 945 }
947 946
948 virtual ~SyncManagerTest() {} 947 virtual ~SyncManagerTest() {}
949 948
950 // Test implementation. 949 // Test implementation.
951 void SetUp() { 950 void SetUp() {
952 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 951 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
953 952
954 extensions_activity_ = new ExtensionsActivity(); 953 extensions_activity_ = new ExtensionsActivity();
955 954
(...skipping 25 matching lines...) Expand all
981 SyncManager::InitArgs args; 980 SyncManager::InitArgs args;
982 args.database_location = temp_dir_.GetPath(); 981 args.database_location = temp_dir_.GetPath();
983 args.service_url = GURL("https://example.com/"); 982 args.service_url = GURL("https://example.com/");
984 args.post_factory = std::unique_ptr<HttpPostProviderFactory>( 983 args.post_factory = std::unique_ptr<HttpPostProviderFactory>(
985 new TestHttpPostProviderFactory()); 984 new TestHttpPostProviderFactory());
986 args.workers = workers; 985 args.workers = workers;
987 args.extensions_activity = extensions_activity_.get(), 986 args.extensions_activity = extensions_activity_.get(),
988 args.change_delegate = this; 987 args.change_delegate = this;
989 args.credentials = credentials; 988 args.credentials = credentials;
990 args.invalidator_client_id = "fake_invalidator_client_id"; 989 args.invalidator_client_id = "fake_invalidator_client_id";
991 args.internal_components_factory.reset(GetFactory()); 990 args.engine_components_factory.reset(GetFactory());
992 args.encryptor = &encryptor_; 991 args.encryptor = &encryptor_;
993 args.unrecoverable_error_handler = 992 args.unrecoverable_error_handler =
994 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); 993 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr());
995 args.cancelation_signal = &cancelation_signal_; 994 args.cancelation_signal = &cancelation_signal_;
996 sync_manager_.Init(&args); 995 sync_manager_.Init(&args);
997 996
998 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); 997 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
999 998
1000 EXPECT_TRUE(js_backend_.IsInitialized()); 999 EXPECT_TRUE(js_backend_.IsInitialized());
1001 EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK, storage_used_); 1000 EXPECT_EQ(EngineComponentsFactory::STORAGE_ON_DISK, storage_used_);
1002 1001
1003 if (initialization_succeeded_) { 1002 if (initialization_succeeded_) {
1004 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 1003 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
1005 i != routing_info.end(); ++i) { 1004 i != routing_info.end(); ++i) {
1006 type_roots_[i->first] = 1005 type_roots_[i->first] =
1007 MakeTypeRoot(sync_manager_.GetUserShare(), i->first); 1006 MakeTypeRoot(sync_manager_.GetUserShare(), i->first);
1008 } 1007 }
1009 } 1008 }
1010 1009
1011 PumpLoop(); 1010 PumpLoop();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 share->directory.get()); 1100 share->directory.get());
1102 const std::string hash = syncable::GenerateSyncableHash(type, client_tag); 1101 const std::string hash = syncable::GenerateSyncableHash(type, client_tag);
1103 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, hash); 1102 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, hash);
1104 EXPECT_TRUE(entry.good()); 1103 EXPECT_TRUE(entry.good());
1105 if (!entry.GetIsUnsynced()) 1104 if (!entry.GetIsUnsynced())
1106 return false; 1105 return false;
1107 entry.PutIsUnsynced(false); 1106 entry.PutIsUnsynced(false);
1108 return true; 1107 return true;
1109 } 1108 }
1110 1109
1111 virtual InternalComponentsFactory* GetFactory() { 1110 virtual EngineComponentsFactory* GetFactory() {
1112 return new TestInternalComponentsFactory( 1111 return new TestEngineComponentsFactory(
1113 GetSwitches(), InternalComponentsFactory::STORAGE_IN_MEMORY, 1112 GetSwitches(), EngineComponentsFactory::STORAGE_IN_MEMORY,
1114 &storage_used_); 1113 &storage_used_);
1115 } 1114 }
1116 1115
1117 // Returns true if we are currently encrypting all sync data. May 1116 // Returns true if we are currently encrypting all sync data. May
1118 // be called on any thread. 1117 // be called on any thread.
1119 bool IsEncryptEverythingEnabledForTest() { 1118 bool IsEncryptEverythingEnabledForTest() {
1120 return sync_manager_.GetEncryptionHandler()->IsEncryptEverythingEnabled(); 1119 return sync_manager_.GetEncryptionHandler()->IsEncryptEverythingEnabled();
1121 } 1120 }
1122 1121
1123 // Gets the set of encrypted types from the cryptographer 1122 // Gets the set of encrypted types from the cryptographer
(...skipping 28 matching lines...) Expand all
1152 sync_pb::DataTypeProgressMarker marker; 1151 sync_pb::DataTypeProgressMarker marker;
1153 marker.set_token("token"); 1152 marker.set_token("token");
1154 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); 1153 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
1155 sync_manager_.directory()->SetDownloadProgress(type, marker); 1154 sync_manager_.directory()->SetDownloadProgress(type, marker);
1156 } else { 1155 } else {
1157 sync_pb::DataTypeProgressMarker marker; 1156 sync_pb::DataTypeProgressMarker marker;
1158 sync_manager_.directory()->SetDownloadProgress(type, marker); 1157 sync_manager_.directory()->SetDownloadProgress(type, marker);
1159 } 1158 }
1160 } 1159 }
1161 1160
1162 InternalComponentsFactory::Switches GetSwitches() const { return switches_; } 1161 EngineComponentsFactory::Switches GetSwitches() const { return switches_; }
1163 1162
1164 void ExpectPassphraseAcceptance() { 1163 void ExpectPassphraseAcceptance() {
1165 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1164 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1166 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1165 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1167 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1166 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1168 } 1167 }
1169 1168
1170 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { 1169 void SetImplicitPassphraseAndCheck(const std::string& passphrase) {
1171 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, 1170 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase,
1172 false); 1171 false);
(...skipping 22 matching lines...) Expand all
1195 scoped_refptr<ExtensionsActivity> extensions_activity_; 1194 scoped_refptr<ExtensionsActivity> extensions_activity_;
1196 1195
1197 protected: 1196 protected:
1198 FakeEncryptor encryptor_; 1197 FakeEncryptor encryptor_;
1199 SyncManagerImpl sync_manager_; 1198 SyncManagerImpl sync_manager_;
1200 CancelationSignal cancelation_signal_; 1199 CancelationSignal cancelation_signal_;
1201 WeakHandle<JsBackend> js_backend_; 1200 WeakHandle<JsBackend> js_backend_;
1202 bool initialization_succeeded_; 1201 bool initialization_succeeded_;
1203 StrictMock<SyncManagerObserverMock> manager_observer_; 1202 StrictMock<SyncManagerObserverMock> manager_observer_;
1204 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 1203 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
1205 InternalComponentsFactory::Switches switches_; 1204 EngineComponentsFactory::Switches switches_;
1206 InternalComponentsFactory::StorageOption storage_used_; 1205 EngineComponentsFactory::StorageOption storage_used_;
1207 MockUnrecoverableErrorHandler mock_unrecoverable_error_handler_; 1206 MockUnrecoverableErrorHandler mock_unrecoverable_error_handler_;
1208 }; 1207 };
1209 1208
1210 TEST_F(SyncManagerTest, RefreshEncryptionReady) { 1209 TEST_F(SyncManagerTest, RefreshEncryptionReady) {
1211 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1210 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1212 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1211 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1213 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1212 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1214 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); 1213 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false));
1215 1214
1216 sync_manager_.GetEncryptionHandler()->Init(); 1215 sync_manager_.GetEncryptionHandler()->Init();
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 2534
2536 class MockSyncScheduler : public FakeSyncScheduler { 2535 class MockSyncScheduler : public FakeSyncScheduler {
2537 public: 2536 public:
2538 MockSyncScheduler() : FakeSyncScheduler() {} 2537 MockSyncScheduler() : FakeSyncScheduler() {}
2539 virtual ~MockSyncScheduler() {} 2538 virtual ~MockSyncScheduler() {}
2540 2539
2541 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); 2540 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time));
2542 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); 2541 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&));
2543 }; 2542 };
2544 2543
2545 class ComponentsFactory : public TestInternalComponentsFactory { 2544 class ComponentsFactory : public TestEngineComponentsFactory {
2546 public: 2545 public:
2547 ComponentsFactory(const Switches& switches, 2546 ComponentsFactory(const Switches& switches,
2548 SyncScheduler* scheduler_to_use, 2547 SyncScheduler* scheduler_to_use,
2549 SyncCycleContext** cycle_context, 2548 SyncCycleContext** cycle_context,
2550 InternalComponentsFactory::StorageOption* storage_used) 2549 EngineComponentsFactory::StorageOption* storage_used)
2551 : TestInternalComponentsFactory( 2550 : TestEngineComponentsFactory(switches,
2552 switches, 2551 EngineComponentsFactory::STORAGE_IN_MEMORY,
2553 InternalComponentsFactory::STORAGE_IN_MEMORY, 2552 storage_used),
2554 storage_used),
2555 scheduler_to_use_(scheduler_to_use), 2553 scheduler_to_use_(scheduler_to_use),
2556 cycle_context_(cycle_context) {} 2554 cycle_context_(cycle_context) {}
2557 ~ComponentsFactory() override {} 2555 ~ComponentsFactory() override {}
2558 2556
2559 std::unique_ptr<SyncScheduler> BuildScheduler( 2557 std::unique_ptr<SyncScheduler> BuildScheduler(
2560 const std::string& name, 2558 const std::string& name,
2561 SyncCycleContext* context, 2559 SyncCycleContext* context,
2562 CancelationSignal* stop_handle) override { 2560 CancelationSignal* stop_handle) override {
2563 *cycle_context_ = context; 2561 *cycle_context_ = context;
2564 return std::move(scheduler_to_use_); 2562 return std::move(scheduler_to_use_);
2565 } 2563 }
2566 2564
2567 private: 2565 private:
2568 std::unique_ptr<SyncScheduler> scheduler_to_use_; 2566 std::unique_ptr<SyncScheduler> scheduler_to_use_;
2569 SyncCycleContext** cycle_context_; 2567 SyncCycleContext** cycle_context_;
2570 }; 2568 };
2571 2569
2572 class SyncManagerTestWithMockScheduler : public SyncManagerTest { 2570 class SyncManagerTestWithMockScheduler : public SyncManagerTest {
2573 public: 2571 public:
2574 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} 2572 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {}
2575 InternalComponentsFactory* GetFactory() override { 2573 EngineComponentsFactory* GetFactory() override {
2576 scheduler_ = new MockSyncScheduler(); 2574 scheduler_ = new MockSyncScheduler();
2577 return new ComponentsFactory(GetSwitches(), scheduler_, &cycle_context_, 2575 return new ComponentsFactory(GetSwitches(), scheduler_, &cycle_context_,
2578 &storage_used_); 2576 &storage_used_);
2579 } 2577 }
2580 2578
2581 MockSyncScheduler* scheduler() { return scheduler_; } 2579 MockSyncScheduler* scheduler() { return scheduler_; }
2582 SyncCycleContext* cycle_context() { return cycle_context_; } 2580 SyncCycleContext* cycle_context() { return cycle_context_; }
2583 2581
2584 private: 2582 private:
2585 MockSyncScheduler* scheduler_; 2583 MockSyncScheduler* scheduler_;
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
3329 share()->directory.get()); 3327 share()->directory.get());
3330 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); 3328 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id);
3331 article.PutAttachmentMetadata(article.GetAttachmentMetadata()); 3329 article.PutAttachmentMetadata(article.GetAttachmentMetadata());
3332 } 3330 }
3333 ASSERT_EQ(0UL, GetChangeListSize()); 3331 ASSERT_EQ(0UL, GetChangeListSize());
3334 } 3332 }
3335 3333
3336 // During initialization SyncManagerImpl loads sqlite database. If it fails to 3334 // During initialization SyncManagerImpl loads sqlite database. If it fails to
3337 // do so it should fail initialization. This test verifies this behavior. 3335 // do so it should fail initialization. This test verifies this behavior.
3338 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides 3336 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides
3339 // InternalComponentsFactory to return DirectoryBackingStore that always fails 3337 // EngineComponentsFactory to return DirectoryBackingStore that always fails
3340 // to load. 3338 // to load.
3341 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { 3339 class SyncManagerInitInvalidStorageTest : public SyncManagerTest {
3342 public: 3340 public:
3343 SyncManagerInitInvalidStorageTest() {} 3341 SyncManagerInitInvalidStorageTest() {}
3344 3342
3345 InternalComponentsFactory* GetFactory() override { 3343 EngineComponentsFactory* GetFactory() override {
3346 return new TestInternalComponentsFactory( 3344 return new TestEngineComponentsFactory(
3347 GetSwitches(), InternalComponentsFactory::STORAGE_INVALID, 3345 GetSwitches(), EngineComponentsFactory::STORAGE_INVALID,
3348 &storage_used_); 3346 &storage_used_);
3349 } 3347 }
3350 }; 3348 };
3351 3349
3352 // SyncManagerInitInvalidStorageTest::GetFactory will return 3350 // SyncManagerInitInvalidStorageTest::GetFactory will return
3353 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. 3351 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3354 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's 3352 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3355 // task is to ensure that SyncManagerImpl reported initialization failure in 3353 // task is to ensure that SyncManagerImpl reported initialization failure in
3356 // OnInitializationComplete callback. 3354 // OnInitializationComplete callback.
3357 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { 3355 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3358 EXPECT_FALSE(initialization_succeeded_); 3356 EXPECT_FALSE(initialization_succeeded_);
3359 } 3357 }
3360 3358
3361 } // namespace syncer 3359 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/sync_manager_impl.cc ('k') | components/sync/engine_impl/syncer_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698