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

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: Merge pref changes from https://codereview.chromium.org/2528163002/. 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 #if defined(OS_WIN)
Nicolas Zea 2016/12/15 00:37:28 May as well remove the OS requirement here right?
pastarmovj 2016/12/16 17:04:48 Actually I added it after I tried compiling on the
Nicolas Zea 2016/12/16 18:50:35 That implies to me a layering violation. Everythin
pastarmovj 2016/12/19 11:12:00 it is because of this ifdef here: https://cs.chrom
2701 class SyncManagerWithLocalBackendTest : public SyncManagerTest {
2702 protected:
2703 void SetUp() override { DoSetUp(true); }
2704 };
2705
2706 // This test checks that we can successfully initialize without credentials in
2707 // the local backend case.
2708 TEST_F(SyncManagerWithLocalBackendTest, StartSyncInLocalMode) {
2709 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2710 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2711 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2712 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false));
2713
2714 sync_manager_.GetEncryptionHandler()->Init();
2715 PumpLoop();
2716
2717 const ModelTypeSet encrypted_types = GetEncryptedTypes();
2718 EXPECT_TRUE(encrypted_types.Has(PASSWORDS));
2719 EXPECT_FALSE(IsEncryptEverythingEnabledForTest());
2720
2721 {
2722 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2723 ReadNode node(&trans);
2724 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(GetIdForDataType(NIGORI)));
2725 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
2726 EXPECT_TRUE(nigori.has_encryption_keybag());
2727 Cryptographer* cryptographer = trans.GetCryptographer();
2728 EXPECT_TRUE(cryptographer->is_ready());
2729 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag()));
2730 }
2731 }
2732 #endif // defined(OS_WIN)
2733
2695 class MockSyncScheduler : public FakeSyncScheduler { 2734 class MockSyncScheduler : public FakeSyncScheduler {
2696 public: 2735 public:
2697 MockSyncScheduler() : FakeSyncScheduler() {} 2736 MockSyncScheduler() : FakeSyncScheduler() {}
2698 virtual ~MockSyncScheduler() {} 2737 virtual ~MockSyncScheduler() {}
2699 2738
2700 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); 2739 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time));
2701 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); 2740 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&));
2702 }; 2741 };
2703 2742
2704 class ComponentsFactory : public TestEngineComponentsFactory { 2743 class ComponentsFactory : public TestEngineComponentsFactory {
2705 public: 2744 public:
2706 ComponentsFactory(const Switches& switches, 2745 ComponentsFactory(const Switches& switches,
2707 SyncScheduler* scheduler_to_use, 2746 SyncScheduler* scheduler_to_use,
2708 SyncCycleContext** cycle_context, 2747 SyncCycleContext** cycle_context,
2709 EngineComponentsFactory::StorageOption* storage_used) 2748 EngineComponentsFactory::StorageOption* storage_used)
2710 : TestEngineComponentsFactory(switches, 2749 : TestEngineComponentsFactory(switches,
2711 EngineComponentsFactory::STORAGE_IN_MEMORY, 2750 EngineComponentsFactory::STORAGE_IN_MEMORY,
2712 storage_used), 2751 storage_used),
2713 scheduler_to_use_(scheduler_to_use), 2752 scheduler_to_use_(scheduler_to_use),
2714 cycle_context_(cycle_context) {} 2753 cycle_context_(cycle_context) {}
2715 ~ComponentsFactory() override {} 2754 ~ComponentsFactory() override {}
2716 2755
2717 std::unique_ptr<SyncScheduler> BuildScheduler( 2756 std::unique_ptr<SyncScheduler> BuildScheduler(
2718 const std::string& name, 2757 const std::string& name,
2719 SyncCycleContext* context, 2758 SyncCycleContext* context,
2720 CancelationSignal* stop_handle) override { 2759 CancelationSignal* stop_handle,
2760 bool local_sync_backend_enabled) override {
2721 *cycle_context_ = context; 2761 *cycle_context_ = context;
2722 return std::move(scheduler_to_use_); 2762 return std::move(scheduler_to_use_);
2723 } 2763 }
2724 2764
2725 private: 2765 private:
2726 std::unique_ptr<SyncScheduler> scheduler_to_use_; 2766 std::unique_ptr<SyncScheduler> scheduler_to_use_;
2727 SyncCycleContext** cycle_context_; 2767 SyncCycleContext** cycle_context_;
2728 }; 2768 };
2729 2769
2730 class SyncManagerTestWithMockScheduler : public SyncManagerTest { 2770 class SyncManagerTestWithMockScheduler : public SyncManagerTest {
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
3510 // SyncManagerInitInvalidStorageTest::GetFactory will return 3550 // SyncManagerInitInvalidStorageTest::GetFactory will return
3511 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. 3551 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3512 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's 3552 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3513 // task is to ensure that SyncManagerImpl reported initialization failure in 3553 // task is to ensure that SyncManagerImpl reported initialization failure in
3514 // OnInitializationComplete callback. 3554 // OnInitializationComplete callback.
3515 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { 3555 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3516 EXPECT_FALSE(initialization_succeeded_); 3556 EXPECT_FALSE(initialization_succeeded_);
3517 } 3557 }
3518 3558
3519 } // namespace syncer 3559 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698