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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 syncer::WriteNode::INIT_FAILED_ENTRY_NOT_GOOD); | 684 syncer::WriteNode::INIT_FAILED_ENTRY_NOT_GOOD); |
685 | 685 |
686 // Finally, the attachment is no longer linked. | 686 // Finally, the attachment is no longer linked. |
687 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto())); | 687 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto())); |
688 } | 688 } |
689 | 689 |
690 namespace { | 690 namespace { |
691 | 691 |
692 class TestHttpPostProviderInterface : public HttpPostProviderInterface { | 692 class TestHttpPostProviderInterface : public HttpPostProviderInterface { |
693 public: | 693 public: |
694 virtual ~TestHttpPostProviderInterface() {} | 694 ~TestHttpPostProviderInterface() override {} |
695 | 695 |
696 virtual void SetExtraRequestHeaders(const char* headers) override {} | 696 void SetExtraRequestHeaders(const char* headers) override {} |
697 virtual void SetURL(const char* url, int port) override {} | 697 void SetURL(const char* url, int port) override {} |
698 virtual void SetPostPayload(const char* content_type, | 698 void SetPostPayload(const char* content_type, |
699 int content_length, | 699 int content_length, |
700 const char* content) override {} | 700 const char* content) override {} |
701 virtual bool MakeSynchronousPost(int* error_code, int* response_code) | 701 bool MakeSynchronousPost(int* error_code, int* response_code) override { |
702 override { | |
703 return false; | 702 return false; |
704 } | 703 } |
705 virtual int GetResponseContentLength() const override { | 704 int GetResponseContentLength() const override { return 0; } |
706 return 0; | 705 const char* GetResponseContent() const override { return ""; } |
707 } | 706 const std::string GetResponseHeaderValue( |
708 virtual const char* GetResponseContent() const override { | |
709 return ""; | |
710 } | |
711 virtual const std::string GetResponseHeaderValue( | |
712 const std::string& name) const override { | 707 const std::string& name) const override { |
713 return std::string(); | 708 return std::string(); |
714 } | 709 } |
715 virtual void Abort() override {} | 710 void Abort() override {} |
716 }; | 711 }; |
717 | 712 |
718 class TestHttpPostProviderFactory : public HttpPostProviderFactory { | 713 class TestHttpPostProviderFactory : public HttpPostProviderFactory { |
719 public: | 714 public: |
720 virtual ~TestHttpPostProviderFactory() {} | 715 ~TestHttpPostProviderFactory() override {} |
721 virtual void Init(const std::string& user_agent) override { } | 716 void Init(const std::string& user_agent) override {} |
722 virtual HttpPostProviderInterface* Create() override { | 717 HttpPostProviderInterface* Create() override { |
723 return new TestHttpPostProviderInterface(); | 718 return new TestHttpPostProviderInterface(); |
724 } | 719 } |
725 virtual void Destroy(HttpPostProviderInterface* http) override { | 720 void Destroy(HttpPostProviderInterface* http) override { |
726 delete static_cast<TestHttpPostProviderInterface*>(http); | 721 delete static_cast<TestHttpPostProviderInterface*>(http); |
727 } | 722 } |
728 }; | 723 }; |
729 | 724 |
730 class SyncManagerObserverMock : public SyncManager::Observer { | 725 class SyncManagerObserverMock : public SyncManager::Observer { |
731 public: | 726 public: |
732 MOCK_METHOD1(OnSyncCycleCompleted, | 727 MOCK_METHOD1(OnSyncCycleCompleted, |
733 void(const SyncSessionSnapshot&)); // NOLINT | 728 void(const SyncSessionSnapshot&)); // NOLINT |
734 MOCK_METHOD4(OnInitializationComplete, | 729 MOCK_METHOD4(OnInitializationComplete, |
735 void(const WeakHandle<JsBackend>&, | 730 void(const WeakHandle<JsBackend>&, |
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2399 class ComponentsFactory : public TestInternalComponentsFactory { | 2394 class ComponentsFactory : public TestInternalComponentsFactory { |
2400 public: | 2395 public: |
2401 ComponentsFactory(const Switches& switches, | 2396 ComponentsFactory(const Switches& switches, |
2402 SyncScheduler* scheduler_to_use, | 2397 SyncScheduler* scheduler_to_use, |
2403 sessions::SyncSessionContext** session_context, | 2398 sessions::SyncSessionContext** session_context, |
2404 InternalComponentsFactory::StorageOption* storage_used) | 2399 InternalComponentsFactory::StorageOption* storage_used) |
2405 : TestInternalComponentsFactory( | 2400 : TestInternalComponentsFactory( |
2406 switches, InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used), | 2401 switches, InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used), |
2407 scheduler_to_use_(scheduler_to_use), | 2402 scheduler_to_use_(scheduler_to_use), |
2408 session_context_(session_context) {} | 2403 session_context_(session_context) {} |
2409 virtual ~ComponentsFactory() {} | 2404 ~ComponentsFactory() override {} |
2410 | 2405 |
2411 virtual scoped_ptr<SyncScheduler> BuildScheduler( | 2406 scoped_ptr<SyncScheduler> BuildScheduler( |
2412 const std::string& name, | 2407 const std::string& name, |
2413 sessions::SyncSessionContext* context, | 2408 sessions::SyncSessionContext* context, |
2414 CancelationSignal* stop_handle) override { | 2409 CancelationSignal* stop_handle) override { |
2415 *session_context_ = context; | 2410 *session_context_ = context; |
2416 return scheduler_to_use_.Pass(); | 2411 return scheduler_to_use_.Pass(); |
2417 } | 2412 } |
2418 | 2413 |
2419 private: | 2414 private: |
2420 scoped_ptr<SyncScheduler> scheduler_to_use_; | 2415 scoped_ptr<SyncScheduler> scheduler_to_use_; |
2421 sessions::SyncSessionContext** session_context_; | 2416 sessions::SyncSessionContext** session_context_; |
2422 }; | 2417 }; |
2423 | 2418 |
2424 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2419 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
2425 public: | 2420 public: |
2426 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2421 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} |
2427 virtual InternalComponentsFactory* GetFactory() override { | 2422 InternalComponentsFactory* GetFactory() override { |
2428 scheduler_ = new MockSyncScheduler(); | 2423 scheduler_ = new MockSyncScheduler(); |
2429 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, | 2424 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, |
2430 &storage_used_); | 2425 &storage_used_); |
2431 } | 2426 } |
2432 | 2427 |
2433 MockSyncScheduler* scheduler() { return scheduler_; } | 2428 MockSyncScheduler* scheduler() { return scheduler_; } |
2434 sessions::SyncSessionContext* session_context() { | 2429 sessions::SyncSessionContext* session_context() { |
2435 return session_context_; | 2430 return session_context_; |
2436 } | 2431 } |
2437 | 2432 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2804 EXPECT_GT(bookmark_node.GetServerVersion(), 0); | 2799 EXPECT_GT(bookmark_node.GetServerVersion(), 0); |
2805 EXPECT_EQ(bookmark_node.GetBaseVersion(), -1); | 2800 EXPECT_EQ(bookmark_node.GetBaseVersion(), -1); |
2806 } | 2801 } |
2807 } | 2802 } |
2808 | 2803 |
2809 // A test harness to exercise the code that processes and passes changes from | 2804 // A test harness to exercise the code that processes and passes changes from |
2810 // the "SYNCER"-WriteTransaction destructor, through the SyncManager, to the | 2805 // the "SYNCER"-WriteTransaction destructor, through the SyncManager, to the |
2811 // ChangeProcessor. | 2806 // ChangeProcessor. |
2812 class SyncManagerChangeProcessingTest : public SyncManagerTest { | 2807 class SyncManagerChangeProcessingTest : public SyncManagerTest { |
2813 public: | 2808 public: |
2814 virtual void OnChangesApplied( | 2809 void OnChangesApplied(ModelType model_type, |
2815 ModelType model_type, | 2810 int64 model_version, |
2816 int64 model_version, | 2811 const BaseTransaction* trans, |
2817 const BaseTransaction* trans, | 2812 const ImmutableChangeRecordList& changes) override { |
2818 const ImmutableChangeRecordList& changes) override { | |
2819 last_changes_ = changes; | 2813 last_changes_ = changes; |
2820 } | 2814 } |
2821 | 2815 |
2822 virtual void OnChangesComplete(ModelType model_type) override {} | 2816 void OnChangesComplete(ModelType model_type) override {} |
2823 | 2817 |
2824 const ImmutableChangeRecordList& GetRecentChangeList() { | 2818 const ImmutableChangeRecordList& GetRecentChangeList() { |
2825 return last_changes_; | 2819 return last_changes_; |
2826 } | 2820 } |
2827 | 2821 |
2828 UserShare* share() { | 2822 UserShare* share() { |
2829 return sync_manager_.GetUserShare(); | 2823 return sync_manager_.GetUserShare(); |
2830 } | 2824 } |
2831 | 2825 |
2832 // Set some flags so our nodes reasonably approximate the real world scenario | 2826 // Set some flags so our nodes reasonably approximate the real world scenario |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3163 // During initialization SyncManagerImpl loads sqlite database. If it fails to | 3157 // During initialization SyncManagerImpl loads sqlite database. If it fails to |
3164 // do so it should fail initialization. This test verifies this behavior. | 3158 // do so it should fail initialization. This test verifies this behavior. |
3165 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides | 3159 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides |
3166 // InternalComponentsFactory to return DirectoryBackingStore that always fails | 3160 // InternalComponentsFactory to return DirectoryBackingStore that always fails |
3167 // to load. | 3161 // to load. |
3168 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { | 3162 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { |
3169 public: | 3163 public: |
3170 SyncManagerInitInvalidStorageTest() { | 3164 SyncManagerInitInvalidStorageTest() { |
3171 } | 3165 } |
3172 | 3166 |
3173 virtual InternalComponentsFactory* GetFactory() override { | 3167 InternalComponentsFactory* GetFactory() override { |
3174 return new TestInternalComponentsFactory( | 3168 return new TestInternalComponentsFactory( |
3175 GetSwitches(), InternalComponentsFactory::STORAGE_INVALID, | 3169 GetSwitches(), InternalComponentsFactory::STORAGE_INVALID, |
3176 &storage_used_); | 3170 &storage_used_); |
3177 } | 3171 } |
3178 }; | 3172 }; |
3179 | 3173 |
3180 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3174 // SyncManagerInitInvalidStorageTest::GetFactory will return |
3181 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3175 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
3182 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3176 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
3183 // task is to ensure that SyncManagerImpl reported initialization failure in | 3177 // task is to ensure that SyncManagerImpl reported initialization failure in |
3184 // OnInitializationComplete callback. | 3178 // OnInitializationComplete callback. |
3185 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3179 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
3186 EXPECT_FALSE(initialization_succeeded_); | 3180 EXPECT_FALSE(initialization_succeeded_); |
3187 } | 3181 } |
3188 | 3182 |
3189 } // namespace syncer | 3183 } // namespace syncer |
OLD | NEW |