| 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 // 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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 args.invalidator_client_id = "fake_invalidator_client_id"; | 827 args.invalidator_client_id = "fake_invalidator_client_id"; |
| 828 args.internal_components_factory.reset(GetFactory()); | 828 args.internal_components_factory.reset(GetFactory()); |
| 829 args.encryptor = &encryptor_; | 829 args.encryptor = &encryptor_; |
| 830 args.unrecoverable_error_handler.reset(new TestUnrecoverableErrorHandler); | 830 args.unrecoverable_error_handler.reset(new TestUnrecoverableErrorHandler); |
| 831 args.cancelation_signal = &cancelation_signal_; | 831 args.cancelation_signal = &cancelation_signal_; |
| 832 sync_manager_.Init(&args); | 832 sync_manager_.Init(&args); |
| 833 | 833 |
| 834 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 834 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 835 | 835 |
| 836 EXPECT_TRUE(js_backend_.IsInitialized()); | 836 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 837 EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK, |
| 838 storage_used_); |
| 837 | 839 |
| 838 if (initialization_succeeded_) { | 840 if (initialization_succeeded_) { |
| 839 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 841 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 840 i != routing_info.end(); ++i) { | 842 i != routing_info.end(); ++i) { |
| 841 type_roots_[i->first] = MakeServerNodeForType( | 843 type_roots_[i->first] = MakeServerNodeForType( |
| 842 sync_manager_.GetUserShare(), i->first); | 844 sync_manager_.GetUserShare(), i->first); |
| 843 } | 845 } |
| 844 } | 846 } |
| 845 | 847 |
| 846 PumpLoop(); | 848 PumpLoop(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, | 946 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, |
| 945 hash); | 947 hash); |
| 946 EXPECT_TRUE(entry.good()); | 948 EXPECT_TRUE(entry.good()); |
| 947 if (!entry.GetIsUnsynced()) | 949 if (!entry.GetIsUnsynced()) |
| 948 return false; | 950 return false; |
| 949 entry.PutIsUnsynced(false); | 951 entry.PutIsUnsynced(false); |
| 950 return true; | 952 return true; |
| 951 } | 953 } |
| 952 | 954 |
| 953 virtual InternalComponentsFactory* GetFactory() { | 955 virtual InternalComponentsFactory* GetFactory() { |
| 954 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_IN_MEMORY); | 956 return new TestInternalComponentsFactory( |
| 957 GetSwitches(), InternalComponentsFactory::STORAGE_IN_MEMORY, |
| 958 &storage_used_); |
| 955 } | 959 } |
| 956 | 960 |
| 957 // Returns true if we are currently encrypting all sync data. May | 961 // Returns true if we are currently encrypting all sync data. May |
| 958 // be called on any thread. | 962 // be called on any thread. |
| 959 bool EncryptEverythingEnabledForTest() { | 963 bool EncryptEverythingEnabledForTest() { |
| 960 return sync_manager_.GetEncryptionHandler()->EncryptEverythingEnabled(); | 964 return sync_manager_.GetEncryptionHandler()->EncryptEverythingEnabled(); |
| 961 } | 965 } |
| 962 | 966 |
| 963 // Gets the set of encrypted types from the cryptographer | 967 // Gets the set of encrypted types from the cryptographer |
| 964 // Note: opens a transaction. May be called from any thread. | 968 // Note: opens a transaction. May be called from any thread. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 | 1008 |
| 1005 protected: | 1009 protected: |
| 1006 FakeEncryptor encryptor_; | 1010 FakeEncryptor encryptor_; |
| 1007 SyncManagerImpl sync_manager_; | 1011 SyncManagerImpl sync_manager_; |
| 1008 CancelationSignal cancelation_signal_; | 1012 CancelationSignal cancelation_signal_; |
| 1009 WeakHandle<JsBackend> js_backend_; | 1013 WeakHandle<JsBackend> js_backend_; |
| 1010 bool initialization_succeeded_; | 1014 bool initialization_succeeded_; |
| 1011 StrictMock<SyncManagerObserverMock> manager_observer_; | 1015 StrictMock<SyncManagerObserverMock> manager_observer_; |
| 1012 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 1016 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
| 1013 InternalComponentsFactory::Switches switches_; | 1017 InternalComponentsFactory::Switches switches_; |
| 1018 InternalComponentsFactory::StorageOption storage_used_; |
| 1014 }; | 1019 }; |
| 1015 | 1020 |
| 1016 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { | 1021 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { |
| 1017 ModelSafeRoutingInfo routing_info; | 1022 ModelSafeRoutingInfo routing_info; |
| 1018 GetModelSafeRoutingInfo(&routing_info); | 1023 GetModelSafeRoutingInfo(&routing_info); |
| 1019 sync_manager_.StartSyncingNormally(routing_info); | 1024 sync_manager_.StartSyncingNormally(routing_info); |
| 1020 | 1025 |
| 1021 scoped_ptr<base::ListValue> node_list( | 1026 scoped_ptr<base::ListValue> node_list( |
| 1022 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); | 1027 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); |
| 1023 | 1028 |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2402 virtual ~MockSyncScheduler() {} | 2407 virtual ~MockSyncScheduler() {} |
| 2403 | 2408 |
| 2404 MOCK_METHOD1(Start, void(SyncScheduler::Mode)); | 2409 MOCK_METHOD1(Start, void(SyncScheduler::Mode)); |
| 2405 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); | 2410 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); |
| 2406 }; | 2411 }; |
| 2407 | 2412 |
| 2408 class ComponentsFactory : public TestInternalComponentsFactory { | 2413 class ComponentsFactory : public TestInternalComponentsFactory { |
| 2409 public: | 2414 public: |
| 2410 ComponentsFactory(const Switches& switches, | 2415 ComponentsFactory(const Switches& switches, |
| 2411 SyncScheduler* scheduler_to_use, | 2416 SyncScheduler* scheduler_to_use, |
| 2412 sessions::SyncSessionContext** session_context) | 2417 sessions::SyncSessionContext** session_context, |
| 2413 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), | 2418 InternalComponentsFactory::StorageOption* storage_used) |
| 2419 : TestInternalComponentsFactory( |
| 2420 switches, InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used), |
| 2414 scheduler_to_use_(scheduler_to_use), | 2421 scheduler_to_use_(scheduler_to_use), |
| 2415 session_context_(session_context) {} | 2422 session_context_(session_context) {} |
| 2416 virtual ~ComponentsFactory() {} | 2423 virtual ~ComponentsFactory() {} |
| 2417 | 2424 |
| 2418 virtual scoped_ptr<SyncScheduler> BuildScheduler( | 2425 virtual scoped_ptr<SyncScheduler> BuildScheduler( |
| 2419 const std::string& name, | 2426 const std::string& name, |
| 2420 sessions::SyncSessionContext* context, | 2427 sessions::SyncSessionContext* context, |
| 2421 CancelationSignal* stop_handle) OVERRIDE { | 2428 CancelationSignal* stop_handle) OVERRIDE { |
| 2422 *session_context_ = context; | 2429 *session_context_ = context; |
| 2423 return scheduler_to_use_.Pass(); | 2430 return scheduler_to_use_.Pass(); |
| 2424 } | 2431 } |
| 2425 | 2432 |
| 2426 private: | 2433 private: |
| 2427 scoped_ptr<SyncScheduler> scheduler_to_use_; | 2434 scoped_ptr<SyncScheduler> scheduler_to_use_; |
| 2428 sessions::SyncSessionContext** session_context_; | 2435 sessions::SyncSessionContext** session_context_; |
| 2429 }; | 2436 }; |
| 2430 | 2437 |
| 2431 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2438 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| 2432 public: | 2439 public: |
| 2433 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2440 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} |
| 2434 virtual InternalComponentsFactory* GetFactory() OVERRIDE { | 2441 virtual InternalComponentsFactory* GetFactory() OVERRIDE { |
| 2435 scheduler_ = new MockSyncScheduler(); | 2442 scheduler_ = new MockSyncScheduler(); |
| 2436 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_); | 2443 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, |
| 2444 &storage_used_); |
| 2437 } | 2445 } |
| 2438 | 2446 |
| 2439 MockSyncScheduler* scheduler() { return scheduler_; } | 2447 MockSyncScheduler* scheduler() { return scheduler_; } |
| 2440 sessions::SyncSessionContext* session_context() { | 2448 sessions::SyncSessionContext* session_context() { |
| 2441 return session_context_; | 2449 return session_context_; |
| 2442 } | 2450 } |
| 2443 | 2451 |
| 2444 private: | 2452 private: |
| 2445 MockSyncScheduler* scheduler_; | 2453 MockSyncScheduler* scheduler_; |
| 2446 sessions::SyncSessionContext* session_context_; | 2454 sessions::SyncSessionContext* session_context_; |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3170 // do so it should fail initialization. This test verifies this behavior. | 3178 // do so it should fail initialization. This test verifies this behavior. |
| 3171 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides | 3179 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides |
| 3172 // InternalComponentsFactory to return DirectoryBackingStore that always fails | 3180 // InternalComponentsFactory to return DirectoryBackingStore that always fails |
| 3173 // to load. | 3181 // to load. |
| 3174 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { | 3182 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { |
| 3175 public: | 3183 public: |
| 3176 SyncManagerInitInvalidStorageTest() { | 3184 SyncManagerInitInvalidStorageTest() { |
| 3177 } | 3185 } |
| 3178 | 3186 |
| 3179 virtual InternalComponentsFactory* GetFactory() OVERRIDE { | 3187 virtual InternalComponentsFactory* GetFactory() OVERRIDE { |
| 3180 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_INVALID); | 3188 return new TestInternalComponentsFactory( |
| 3189 GetSwitches(), InternalComponentsFactory::STORAGE_INVALID, |
| 3190 &storage_used_); |
| 3181 } | 3191 } |
| 3182 }; | 3192 }; |
| 3183 | 3193 |
| 3184 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3194 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3185 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3195 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3186 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3196 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3187 // task is to ensure that SyncManagerImpl reported initialization failure in | 3197 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3188 // OnInitializationComplete callback. | 3198 // OnInitializationComplete callback. |
| 3189 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3199 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3190 EXPECT_FALSE(initialization_succeeded_); | 3200 EXPECT_FALSE(initialization_succeeded_); |
| 3191 } | 3201 } |
| 3192 | 3202 |
| 3193 } // namespace syncer | 3203 } // namespace syncer |
| OLD | NEW |