| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 }; | 718 }; |
| 719 | 719 |
| 720 enum EncryptionStatus { | 720 enum EncryptionStatus { |
| 721 UNINITIALIZED, | 721 UNINITIALIZED, |
| 722 DEFAULT_ENCRYPTION, | 722 DEFAULT_ENCRYPTION, |
| 723 FULL_ENCRYPTION | 723 FULL_ENCRYPTION |
| 724 }; | 724 }; |
| 725 | 725 |
| 726 SyncManagerTest() | 726 SyncManagerTest() |
| 727 : sync_notifier_mock_(NULL), | 727 : sync_notifier_mock_(NULL), |
| 728 sync_manager_("Test sync manager") {} | 728 sync_manager_("Test sync manager") { |
| 729 switches_.encryption_method = |
| 730 InternalComponentsFactory::ENCRYPTION_KEYSTORE; |
| 731 } |
| 729 | 732 |
| 730 virtual ~SyncManagerTest() { | 733 virtual ~SyncManagerTest() { |
| 731 EXPECT_FALSE(sync_notifier_mock_); | 734 EXPECT_FALSE(sync_notifier_mock_); |
| 732 } | 735 } |
| 733 | 736 |
| 734 // Test implementation. | 737 // Test implementation. |
| 735 void SetUp() { | 738 void SetUp() { |
| 736 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 739 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 737 | 740 |
| 738 SyncCredentials credentials; | 741 SyncCredentials credentials; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 763 sync_manager_.Init(temp_dir_.path(), | 766 sync_manager_.Init(temp_dir_.path(), |
| 764 WeakHandle<JsEventHandler>(), | 767 WeakHandle<JsEventHandler>(), |
| 765 "bogus", 0, false, | 768 "bogus", 0, false, |
| 766 base::MessageLoopProxy::current(), | 769 base::MessageLoopProxy::current(), |
| 767 scoped_ptr<HttpPostProviderFactory>( | 770 scoped_ptr<HttpPostProviderFactory>( |
| 768 new TestHttpPostProviderFactory()), | 771 new TestHttpPostProviderFactory()), |
| 769 workers, &extensions_activity_monitor_, this, | 772 workers, &extensions_activity_monitor_, this, |
| 770 credentials, | 773 credentials, |
| 771 scoped_ptr<SyncNotifier>(sync_notifier_mock_), | 774 scoped_ptr<SyncNotifier>(sync_notifier_mock_), |
| 772 "", "", // bootstrap tokens | 775 "", "", // bootstrap tokens |
| 773 true, // enable keystore encryption | |
| 774 scoped_ptr<InternalComponentsFactory>(GetFactory()), | 776 scoped_ptr<InternalComponentsFactory>(GetFactory()), |
| 775 &encryptor_, | 777 &encryptor_, |
| 776 &handler_, | 778 &handler_, |
| 777 NULL); | 779 NULL); |
| 778 | 780 |
| 779 EXPECT_TRUE(js_backend_.IsInitialized()); | 781 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 780 | 782 |
| 781 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 783 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 782 i != routing_info.end(); ++i) { | 784 i != routing_info.end(); ++i) { |
| 783 type_roots_[i->first] = MakeServerNodeForType( | 785 type_roots_[i->first] = MakeServerNodeForType( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, | 883 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, |
| 882 hash); | 884 hash); |
| 883 EXPECT_TRUE(entry.good()); | 885 EXPECT_TRUE(entry.good()); |
| 884 if (!entry.Get(IS_UNSYNCED)) | 886 if (!entry.Get(IS_UNSYNCED)) |
| 885 return false; | 887 return false; |
| 886 entry.Put(IS_UNSYNCED, false); | 888 entry.Put(IS_UNSYNCED, false); |
| 887 return true; | 889 return true; |
| 888 } | 890 } |
| 889 | 891 |
| 890 virtual InternalComponentsFactory* GetFactory() { | 892 virtual InternalComponentsFactory* GetFactory() { |
| 891 return new TestInternalComponentsFactory(STORAGE_IN_MEMORY); | 893 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_IN_MEMORY); |
| 892 } | 894 } |
| 893 | 895 |
| 894 // Returns true if we are currently encrypting all sync data. May | 896 // Returns true if we are currently encrypting all sync data. May |
| 895 // be called on any thread. | 897 // be called on any thread. |
| 896 bool EncryptEverythingEnabledForTest() { | 898 bool EncryptEverythingEnabledForTest() { |
| 897 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 899 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 898 return trans.GetCryptographer()->encrypt_everything(); | 900 return trans.GetCryptographer()->encrypt_everything(); |
| 899 } | 901 } |
| 900 | 902 |
| 901 // Gets the set of encrypted types from the cryptographer | 903 // Gets the set of encrypted types from the cryptographer |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } else { | 936 } else { |
| 935 sync_pb::DataTypeProgressMarker marker; | 937 sync_pb::DataTypeProgressMarker marker; |
| 936 sync_manager_.directory()->SetDownloadProgress(type, marker); | 938 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 937 } | 939 } |
| 938 } | 940 } |
| 939 | 941 |
| 940 void SetInitialSyncEndedForType(ModelType type, bool value) { | 942 void SetInitialSyncEndedForType(ModelType type, bool value) { |
| 941 sync_manager_.directory()->set_initial_sync_ended_for_type(type, value); | 943 sync_manager_.directory()->set_initial_sync_ended_for_type(type, value); |
| 942 } | 944 } |
| 943 | 945 |
| 946 InternalComponentsFactory::Switches GetSwitches() const { |
| 947 return switches_; |
| 948 } |
| 949 |
| 944 private: | 950 private: |
| 945 // Needed by |sync_manager_|. | 951 // Needed by |sync_manager_|. |
| 946 MessageLoop message_loop_; | 952 MessageLoop message_loop_; |
| 947 // Needed by |sync_manager_|. | 953 // Needed by |sync_manager_|. |
| 948 ScopedTempDir temp_dir_; | 954 ScopedTempDir temp_dir_; |
| 949 // Sync Id's for the roots of the enabled datatypes. | 955 // Sync Id's for the roots of the enabled datatypes. |
| 950 std::map<ModelType, int64> type_roots_; | 956 std::map<ModelType, int64> type_roots_; |
| 951 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 957 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 952 | 958 |
| 953 protected: | 959 protected: |
| 954 FakeEncryptor encryptor_; | 960 FakeEncryptor encryptor_; |
| 955 TestUnrecoverableErrorHandler handler_; | 961 TestUnrecoverableErrorHandler handler_; |
| 956 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 962 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
| 957 SyncManagerImpl sync_manager_; | 963 SyncManagerImpl sync_manager_; |
| 958 WeakHandle<JsBackend> js_backend_; | 964 WeakHandle<JsBackend> js_backend_; |
| 959 StrictMock<SyncManagerObserverMock> observer_; | 965 StrictMock<SyncManagerObserverMock> observer_; |
| 966 InternalComponentsFactory::Switches switches_; |
| 960 }; | 967 }; |
| 961 | 968 |
| 962 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 969 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
| 963 ModelSafeRoutingInfo routes; | 970 ModelSafeRoutingInfo routes; |
| 964 GetModelSafeRoutingInfo(&routes); | 971 GetModelSafeRoutingInfo(&routes); |
| 965 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 972 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
| 966 EXPECT_CALL(*sync_notifier_mock_, | 973 EXPECT_CALL(*sync_notifier_mock_, |
| 967 UpdateRegisteredIds( | 974 UpdateRegisteredIds( |
| 968 _, ModelTypeSetToObjectIdSet(enabled_types))); | 975 _, ModelTypeSetToObjectIdSet(enabled_types))); |
| 969 | 976 |
| (...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 public: | 2541 public: |
| 2535 MockSyncScheduler() : FakeSyncScheduler() {} | 2542 MockSyncScheduler() : FakeSyncScheduler() {} |
| 2536 virtual ~MockSyncScheduler() {} | 2543 virtual ~MockSyncScheduler() {} |
| 2537 | 2544 |
| 2538 MOCK_METHOD1(Start, void(SyncScheduler::Mode)); | 2545 MOCK_METHOD1(Start, void(SyncScheduler::Mode)); |
| 2539 MOCK_METHOD1(ScheduleConfiguration, bool(const ConfigurationParams&)); | 2546 MOCK_METHOD1(ScheduleConfiguration, bool(const ConfigurationParams&)); |
| 2540 }; | 2547 }; |
| 2541 | 2548 |
| 2542 class ComponentsFactory : public TestInternalComponentsFactory { | 2549 class ComponentsFactory : public TestInternalComponentsFactory { |
| 2543 public: | 2550 public: |
| 2544 ComponentsFactory(SyncScheduler* scheduler_to_use, | 2551 ComponentsFactory(const Switches& switches, |
| 2552 SyncScheduler* scheduler_to_use, |
| 2545 sessions::SyncSessionContext** session_context) | 2553 sessions::SyncSessionContext** session_context) |
| 2546 : TestInternalComponentsFactory( | 2554 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), |
| 2547 syncer::STORAGE_IN_MEMORY), | |
| 2548 scheduler_to_use_(scheduler_to_use), | 2555 scheduler_to_use_(scheduler_to_use), |
| 2549 session_context_(session_context) {} | 2556 session_context_(session_context) {} |
| 2550 virtual ~ComponentsFactory() {} | 2557 virtual ~ComponentsFactory() {} |
| 2551 | 2558 |
| 2552 virtual scoped_ptr<SyncScheduler> BuildScheduler( | 2559 virtual scoped_ptr<SyncScheduler> BuildScheduler( |
| 2553 const std::string& name, | 2560 const std::string& name, |
| 2554 sessions::SyncSessionContext* context) OVERRIDE { | 2561 sessions::SyncSessionContext* context) OVERRIDE { |
| 2555 *session_context_ = context; | 2562 *session_context_ = context; |
| 2556 return scheduler_to_use_.Pass(); | 2563 return scheduler_to_use_.Pass(); |
| 2557 } | 2564 } |
| 2558 | 2565 |
| 2559 private: | 2566 private: |
| 2560 scoped_ptr<SyncScheduler> scheduler_to_use_; | 2567 scoped_ptr<SyncScheduler> scheduler_to_use_; |
| 2561 sessions::SyncSessionContext** session_context_; | 2568 sessions::SyncSessionContext** session_context_; |
| 2562 }; | 2569 }; |
| 2563 | 2570 |
| 2564 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2571 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| 2565 public: | 2572 public: |
| 2566 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2573 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} |
| 2567 virtual InternalComponentsFactory* GetFactory() OVERRIDE { | 2574 virtual InternalComponentsFactory* GetFactory() OVERRIDE { |
| 2568 scheduler_ = new MockSyncScheduler(); | 2575 scheduler_ = new MockSyncScheduler(); |
| 2569 return new ComponentsFactory(scheduler_, &session_context_); | 2576 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_); |
| 2570 } | 2577 } |
| 2571 | 2578 |
| 2572 MockSyncScheduler* scheduler() { return scheduler_; } | 2579 MockSyncScheduler* scheduler() { return scheduler_; } |
| 2573 sessions::SyncSessionContext* session_context() { | 2580 sessions::SyncSessionContext* session_context() { |
| 2574 return session_context_; | 2581 return session_context_; |
| 2575 } | 2582 } |
| 2576 | 2583 |
| 2577 private: | 2584 private: |
| 2578 MockSyncScheduler* scheduler_; | 2585 MockSyncScheduler* scheduler_; |
| 2579 sessions::SyncSessionContext* session_context_; | 2586 sessions::SyncSessionContext* session_context_; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2800 | 2807 |
| 2801 // Verify only the non-disabled types remain after cleanup. | 2808 // Verify only the non-disabled types remain after cleanup. |
| 2802 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2809 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 2803 EXPECT_TRUE(new_enabled_types.Equals( | 2810 EXPECT_TRUE(new_enabled_types.Equals( |
| 2804 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2811 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
| 2805 EXPECT_TRUE(disabled_types.Equals( | 2812 EXPECT_TRUE(disabled_types.Equals( |
| 2806 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2813 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 2807 } | 2814 } |
| 2808 | 2815 |
| 2809 } // namespace | 2816 } // namespace |
| OLD | NEW |