| 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/sync_manager_impl.h" | 5 #include "components/sync/engine_impl/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 enum NigoriStatus { DONT_WRITE_NIGORI, WRITE_TO_NIGORI }; | 989 enum NigoriStatus { DONT_WRITE_NIGORI, WRITE_TO_NIGORI }; |
| 990 | 990 |
| 991 enum EncryptionStatus { UNINITIALIZED, DEFAULT_ENCRYPTION, FULL_ENCRYPTION }; | 991 enum EncryptionStatus { UNINITIALIZED, DEFAULT_ENCRYPTION, FULL_ENCRYPTION }; |
| 992 | 992 |
| 993 SyncManagerTest() : sync_manager_("Test sync manager") { | 993 SyncManagerTest() : sync_manager_("Test sync manager") { |
| 994 switches_.encryption_method = EngineComponentsFactory::ENCRYPTION_KEYSTORE; | 994 switches_.encryption_method = EngineComponentsFactory::ENCRYPTION_KEYSTORE; |
| 995 } | 995 } |
| 996 | 996 |
| 997 virtual ~SyncManagerTest() {} | 997 virtual ~SyncManagerTest() {} |
| 998 | 998 |
| 999 // Test implementation. | 999 virtual void DoSetUp(bool enable_local_sync_backend) { |
| 1000 void SetUp() { | |
| 1001 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 1000 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1002 | 1001 |
| 1003 extensions_activity_ = new ExtensionsActivity(); | 1002 extensions_activity_ = new ExtensionsActivity(); |
| 1004 | 1003 |
| 1005 SyncCredentials credentials; | 1004 SyncCredentials credentials; |
| 1006 credentials.account_id = "foo@bar.com"; | 1005 credentials.account_id = "foo@bar.com"; |
| 1007 credentials.email = "foo@bar.com"; | 1006 credentials.email = "foo@bar.com"; |
| 1008 credentials.sync_token = "sometoken"; | 1007 credentials.sync_token = "sometoken"; |
| 1009 OAuth2TokenService::ScopeSet scope_set; | 1008 OAuth2TokenService::ScopeSet scope_set; |
| 1010 scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 1009 scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1028 workers.push_back(worker); | 1027 workers.push_back(worker); |
| 1029 | 1028 |
| 1030 SyncManager::InitArgs args; | 1029 SyncManager::InitArgs args; |
| 1031 args.database_location = temp_dir_.GetPath(); | 1030 args.database_location = temp_dir_.GetPath(); |
| 1032 args.service_url = GURL("https://example.com/"); | 1031 args.service_url = GURL("https://example.com/"); |
| 1033 args.post_factory = std::unique_ptr<HttpPostProviderFactory>( | 1032 args.post_factory = std::unique_ptr<HttpPostProviderFactory>( |
| 1034 new TestHttpPostProviderFactory()); | 1033 new TestHttpPostProviderFactory()); |
| 1035 args.workers = workers; | 1034 args.workers = workers; |
| 1036 args.extensions_activity = extensions_activity_.get(), | 1035 args.extensions_activity = extensions_activity_.get(), |
| 1037 args.change_delegate = this; | 1036 args.change_delegate = this; |
| 1038 args.credentials = credentials; | 1037 if (!enable_local_sync_backend) |
| 1038 args.credentials = credentials; |
| 1039 args.invalidator_client_id = "fake_invalidator_client_id"; | 1039 args.invalidator_client_id = "fake_invalidator_client_id"; |
| 1040 args.enable_local_sync_backend = enable_local_sync_backend; |
| 1041 args.local_sync_backend_folder = temp_dir_.GetPath(); |
| 1040 args.engine_components_factory.reset(GetFactory()); | 1042 args.engine_components_factory.reset(GetFactory()); |
| 1041 args.encryptor = &encryptor_; | 1043 args.encryptor = &encryptor_; |
| 1042 args.unrecoverable_error_handler = | 1044 args.unrecoverable_error_handler = |
| 1043 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); | 1045 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); |
| 1044 args.cancelation_signal = &cancelation_signal_; | 1046 args.cancelation_signal = &cancelation_signal_; |
| 1045 sync_manager_.Init(&args); | 1047 sync_manager_.Init(&args); |
| 1046 | 1048 |
| 1047 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 1049 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 1048 | 1050 |
| 1049 EXPECT_TRUE(js_backend_.IsInitialized()); | 1051 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 1050 EXPECT_EQ(EngineComponentsFactory::STORAGE_ON_DISK, storage_used_); | 1052 EXPECT_EQ(EngineComponentsFactory::STORAGE_ON_DISK, storage_used_); |
| 1051 | 1053 |
| 1052 if (initialization_succeeded_) { | 1054 if (initialization_succeeded_) { |
| 1053 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 1055 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 1054 i != routing_info.end(); ++i) { | 1056 i != routing_info.end(); ++i) { |
| 1055 type_roots_[i->first] = | 1057 type_roots_[i->first] = |
| 1056 MakeTypeRoot(sync_manager_.GetUserShare(), i->first); | 1058 MakeTypeRoot(sync_manager_.GetUserShare(), i->first); |
| 1057 } | 1059 } |
| 1058 } | 1060 } |
| 1059 | 1061 |
| 1060 PumpLoop(); | 1062 PumpLoop(); |
| 1061 } | 1063 } |
| 1062 | 1064 |
| 1065 // Test implementation. |
| 1066 void SetUp() { DoSetUp(false); } |
| 1067 |
| 1063 void TearDown() { | 1068 void TearDown() { |
| 1064 sync_manager_.RemoveObserver(&manager_observer_); | 1069 sync_manager_.RemoveObserver(&manager_observer_); |
| 1065 sync_manager_.ShutdownOnSyncThread(STOP_SYNC); | 1070 sync_manager_.ShutdownOnSyncThread(STOP_SYNC); |
| 1066 PumpLoop(); | 1071 PumpLoop(); |
| 1067 } | 1072 } |
| 1068 | 1073 |
| 1069 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 1074 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 1070 (*out)[NIGORI] = GROUP_PASSIVE; | 1075 (*out)[NIGORI] = GROUP_PASSIVE; |
| 1071 (*out)[DEVICE_INFO] = GROUP_PASSIVE; | 1076 (*out)[DEVICE_INFO] = GROUP_PASSIVE; |
| 1072 (*out)[EXPERIMENTS] = GROUP_PASSIVE; | 1077 (*out)[EXPERIMENTS] = GROUP_PASSIVE; |
| (...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2698 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); | 2703 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2699 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 2704 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 2700 i != routing_info.end(); ++i) { | 2705 i != routing_info.end(); ++i) { |
| 2701 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, | 2706 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, |
| 2702 sync_manager_.GetUserShare()->directory->GetTransactionVersion( | 2707 sync_manager_.GetUserShare()->directory->GetTransactionVersion( |
| 2703 i->first)); | 2708 i->first)); |
| 2704 } | 2709 } |
| 2705 } | 2710 } |
| 2706 } | 2711 } |
| 2707 | 2712 |
| 2713 #if defined(OS_WIN) |
| 2714 class SyncManagerWithLocalBackendTest : public SyncManagerTest { |
| 2715 protected: |
| 2716 void SetUp() override { DoSetUp(true); } |
| 2717 }; |
| 2718 |
| 2719 // This test checks that we can successfully initialize without credentials in |
| 2720 // the local backend case. |
| 2721 TEST_F(SyncManagerWithLocalBackendTest, StartSyncInLocalMode) { |
| 2722 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2723 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2724 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2725 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2726 |
| 2727 sync_manager_.GetEncryptionHandler()->Init(); |
| 2728 PumpLoop(); |
| 2729 |
| 2730 const ModelTypeSet encrypted_types = GetEncryptedTypes(); |
| 2731 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); |
| 2732 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 2733 |
| 2734 { |
| 2735 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2736 ReadNode node(&trans); |
| 2737 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 2738 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 2739 EXPECT_TRUE(nigori.has_encryption_keybag()); |
| 2740 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2741 EXPECT_TRUE(cryptographer->is_ready()); |
| 2742 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); |
| 2743 } |
| 2744 } |
| 2745 #endif // defined(OS_WIN) |
| 2746 |
| 2708 class MockSyncScheduler : public FakeSyncScheduler { | 2747 class MockSyncScheduler : public FakeSyncScheduler { |
| 2709 public: | 2748 public: |
| 2710 MockSyncScheduler() : FakeSyncScheduler() {} | 2749 MockSyncScheduler() : FakeSyncScheduler() {} |
| 2711 virtual ~MockSyncScheduler() {} | 2750 virtual ~MockSyncScheduler() {} |
| 2712 | 2751 |
| 2713 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); | 2752 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); |
| 2714 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); | 2753 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); |
| 2715 }; | 2754 }; |
| 2716 | 2755 |
| 2717 class ComponentsFactory : public TestEngineComponentsFactory { | 2756 class ComponentsFactory : public TestEngineComponentsFactory { |
| 2718 public: | 2757 public: |
| 2719 ComponentsFactory(const Switches& switches, | 2758 ComponentsFactory(const Switches& switches, |
| 2720 SyncScheduler* scheduler_to_use, | 2759 SyncScheduler* scheduler_to_use, |
| 2721 SyncCycleContext** cycle_context, | 2760 SyncCycleContext** cycle_context, |
| 2722 EngineComponentsFactory::StorageOption* storage_used) | 2761 EngineComponentsFactory::StorageOption* storage_used) |
| 2723 : TestEngineComponentsFactory(switches, | 2762 : TestEngineComponentsFactory(switches, |
| 2724 EngineComponentsFactory::STORAGE_IN_MEMORY, | 2763 EngineComponentsFactory::STORAGE_IN_MEMORY, |
| 2725 storage_used), | 2764 storage_used), |
| 2726 scheduler_to_use_(scheduler_to_use), | 2765 scheduler_to_use_(scheduler_to_use), |
| 2727 cycle_context_(cycle_context) {} | 2766 cycle_context_(cycle_context) {} |
| 2728 ~ComponentsFactory() override {} | 2767 ~ComponentsFactory() override {} |
| 2729 | 2768 |
| 2730 std::unique_ptr<SyncScheduler> BuildScheduler( | 2769 std::unique_ptr<SyncScheduler> BuildScheduler( |
| 2731 const std::string& name, | 2770 const std::string& name, |
| 2732 SyncCycleContext* context, | 2771 SyncCycleContext* context, |
| 2733 CancelationSignal* stop_handle) override { | 2772 CancelationSignal* stop_handle, |
| 2773 bool local_sync_backend_enabled) override { |
| 2734 *cycle_context_ = context; | 2774 *cycle_context_ = context; |
| 2735 return std::move(scheduler_to_use_); | 2775 return std::move(scheduler_to_use_); |
| 2736 } | 2776 } |
| 2737 | 2777 |
| 2738 private: | 2778 private: |
| 2739 std::unique_ptr<SyncScheduler> scheduler_to_use_; | 2779 std::unique_ptr<SyncScheduler> scheduler_to_use_; |
| 2740 SyncCycleContext** cycle_context_; | 2780 SyncCycleContext** cycle_context_; |
| 2741 }; | 2781 }; |
| 2742 | 2782 |
| 2743 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2783 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3523 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3563 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3524 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3564 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3525 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3565 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3526 // task is to ensure that SyncManagerImpl reported initialization failure in | 3566 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3527 // OnInitializationComplete callback. | 3567 // OnInitializationComplete callback. |
| 3528 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3568 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3529 EXPECT_FALSE(initialization_succeeded_); | 3569 EXPECT_FALSE(initialization_succeeded_); |
| 3530 } | 3570 } |
| 3531 | 3571 |
| 3532 } // namespace syncer | 3572 } // namespace syncer |
| OLD | NEW |