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

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

Issue 2494873003: [Sync] Allow sync start without sign-in if the local sync backend is on. (Closed)
Patch Set: Remove ifdefs around include. Created 4 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
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/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
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
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 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2685 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); 2690 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare());
2686 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 2691 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
2687 i != routing_info.end(); ++i) { 2692 i != routing_info.end(); ++i) {
2688 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, 2693 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1,
2689 sync_manager_.GetUserShare()->directory->GetTransactionVersion( 2694 sync_manager_.GetUserShare()->directory->GetTransactionVersion(
2690 i->first)); 2695 i->first));
2691 } 2696 }
2692 } 2697 }
2693 } 2698 }
2694 2699
2700 class SyncManagerWithLocalBackendTest : public SyncManagerTest {
2701 protected:
2702 void SetUp() override { DoSetUp(true); }
2703 };
2704
2705 // This test checks that we can successfully initialize without credentials in
2706 // the local backend case.
2707 TEST_F(SyncManagerWithLocalBackendTest, StartSyncInLocalMode) {
2708 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2709 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2710 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2711 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false));
2712
2713 sync_manager_.GetEncryptionHandler()->Init();
2714 PumpLoop();
2715
2716 const ModelTypeSet encrypted_types = GetEncryptedTypes();
2717 EXPECT_TRUE(encrypted_types.Has(PASSWORDS));
2718 EXPECT_FALSE(IsEncryptEverythingEnabledForTest());
2719
2720 {
2721 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2722 ReadNode node(&trans);
2723 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(GetIdForDataType(NIGORI)));
2724 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
2725 EXPECT_TRUE(nigori.has_encryption_keybag());
2726 Cryptographer* cryptographer = trans.GetCryptographer();
2727 EXPECT_TRUE(cryptographer->is_ready());
2728 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag()));
2729 }
2730 }
2731
2695 class MockSyncScheduler : public FakeSyncScheduler { 2732 class MockSyncScheduler : public FakeSyncScheduler {
2696 public: 2733 public:
2697 MockSyncScheduler() : FakeSyncScheduler() {} 2734 MockSyncScheduler() : FakeSyncScheduler() {}
2698 virtual ~MockSyncScheduler() {} 2735 virtual ~MockSyncScheduler() {}
2699 2736
2700 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); 2737 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time));
2701 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); 2738 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&));
2702 }; 2739 };
2703 2740
2704 class ComponentsFactory : public TestEngineComponentsFactory { 2741 class ComponentsFactory : public TestEngineComponentsFactory {
2705 public: 2742 public:
2706 ComponentsFactory(const Switches& switches, 2743 ComponentsFactory(const Switches& switches,
2707 SyncScheduler* scheduler_to_use, 2744 SyncScheduler* scheduler_to_use,
2708 SyncCycleContext** cycle_context, 2745 SyncCycleContext** cycle_context,
2709 EngineComponentsFactory::StorageOption* storage_used) 2746 EngineComponentsFactory::StorageOption* storage_used)
2710 : TestEngineComponentsFactory(switches, 2747 : TestEngineComponentsFactory(switches,
2711 EngineComponentsFactory::STORAGE_IN_MEMORY, 2748 EngineComponentsFactory::STORAGE_IN_MEMORY,
2712 storage_used), 2749 storage_used),
2713 scheduler_to_use_(scheduler_to_use), 2750 scheduler_to_use_(scheduler_to_use),
2714 cycle_context_(cycle_context) {} 2751 cycle_context_(cycle_context) {}
2715 ~ComponentsFactory() override {} 2752 ~ComponentsFactory() override {}
2716 2753
2717 std::unique_ptr<SyncScheduler> BuildScheduler( 2754 std::unique_ptr<SyncScheduler> BuildScheduler(
2718 const std::string& name, 2755 const std::string& name,
2719 SyncCycleContext* context, 2756 SyncCycleContext* context,
2720 CancelationSignal* stop_handle) override { 2757 CancelationSignal* stop_handle,
2758 bool local_sync_backend_enabled) override {
2721 *cycle_context_ = context; 2759 *cycle_context_ = context;
2722 return std::move(scheduler_to_use_); 2760 return std::move(scheduler_to_use_);
2723 } 2761 }
2724 2762
2725 private: 2763 private:
2726 std::unique_ptr<SyncScheduler> scheduler_to_use_; 2764 std::unique_ptr<SyncScheduler> scheduler_to_use_;
2727 SyncCycleContext** cycle_context_; 2765 SyncCycleContext** cycle_context_;
2728 }; 2766 };
2729 2767
2730 class SyncManagerTestWithMockScheduler : public SyncManagerTest { 2768 class SyncManagerTestWithMockScheduler : public SyncManagerTest {
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
3514 // SyncManagerInitInvalidStorageTest::GetFactory will return 3552 // SyncManagerInitInvalidStorageTest::GetFactory will return
3515 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. 3553 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3516 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's 3554 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3517 // task is to ensure that SyncManagerImpl reported initialization failure in 3555 // task is to ensure that SyncManagerImpl reported initialization failure in
3518 // OnInitializationComplete callback. 3556 // OnInitializationComplete callback.
3519 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { 3557 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3520 EXPECT_FALSE(initialization_succeeded_); 3558 EXPECT_FALSE(initialization_succeeded_);
3521 } 3559 }
3522 3560
3523 } // namespace syncer 3561 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/sync_manager_impl.cc ('k') | components/sync/engine_impl/sync_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698