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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/message_loop/message_loop_proxy.h" | 20 #include "base/message_loop/message_loop_proxy.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/test/values_test_util.h" | 24 #include "base/test/values_test_util.h" |
25 #include "base/values.h" | 25 #include "base/values.h" |
26 #include "sync/engine/sync_scheduler.h" | 26 #include "sync/engine/sync_scheduler.h" |
| 27 #include "sync/internal_api/public/base/cancelation_signal.h" |
27 #include "sync/internal_api/public/base/model_type_test_util.h" | 28 #include "sync/internal_api/public/base/model_type_test_util.h" |
28 #include "sync/internal_api/public/change_record.h" | 29 #include "sync/internal_api/public/change_record.h" |
29 #include "sync/internal_api/public/engine/model_safe_worker.h" | 30 #include "sync/internal_api/public/engine/model_safe_worker.h" |
30 #include "sync/internal_api/public/engine/polling_constants.h" | 31 #include "sync/internal_api/public/engine/polling_constants.h" |
31 #include "sync/internal_api/public/http_post_provider_factory.h" | 32 #include "sync/internal_api/public/http_post_provider_factory.h" |
32 #include "sync/internal_api/public/http_post_provider_interface.h" | 33 #include "sync/internal_api/public/http_post_provider_interface.h" |
33 #include "sync/internal_api/public/read_node.h" | 34 #include "sync/internal_api/public/read_node.h" |
34 #include "sync/internal_api/public/read_transaction.h" | 35 #include "sync/internal_api/public/read_transaction.h" |
35 #include "sync/internal_api/public/test/test_entry_factory.h" | 36 #include "sync/internal_api/public/test/test_entry_factory.h" |
36 #include "sync/internal_api/public/test/test_internal_components_factory.h" | 37 #include "sync/internal_api/public/test/test_internal_components_factory.h" |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 virtual const std::string GetResponseHeaderValue( | 723 virtual const std::string GetResponseHeaderValue( |
723 const std::string& name) const OVERRIDE { | 724 const std::string& name) const OVERRIDE { |
724 return std::string(); | 725 return std::string(); |
725 } | 726 } |
726 virtual void Abort() OVERRIDE {} | 727 virtual void Abort() OVERRIDE {} |
727 }; | 728 }; |
728 | 729 |
729 class TestHttpPostProviderFactory : public HttpPostProviderFactory { | 730 class TestHttpPostProviderFactory : public HttpPostProviderFactory { |
730 public: | 731 public: |
731 virtual ~TestHttpPostProviderFactory() {} | 732 virtual ~TestHttpPostProviderFactory() {} |
| 733 virtual void Init(const std::string& user_agent) OVERRIDE { } |
732 virtual HttpPostProviderInterface* Create() OVERRIDE { | 734 virtual HttpPostProviderInterface* Create() OVERRIDE { |
733 return new TestHttpPostProviderInterface(); | 735 return new TestHttpPostProviderInterface(); |
734 } | 736 } |
735 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE { | 737 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE { |
736 delete static_cast<TestHttpPostProviderInterface*>(http); | 738 delete static_cast<TestHttpPostProviderInterface*>(http); |
737 } | 739 } |
738 virtual void Shutdown() OVERRIDE {} | |
739 }; | 740 }; |
740 | 741 |
741 class SyncManagerObserverMock : public SyncManager::Observer { | 742 class SyncManagerObserverMock : public SyncManager::Observer { |
742 public: | 743 public: |
743 MOCK_METHOD1(OnSyncCycleCompleted, | 744 MOCK_METHOD1(OnSyncCycleCompleted, |
744 void(const SyncSessionSnapshot&)); // NOLINT | 745 void(const SyncSessionSnapshot&)); // NOLINT |
745 MOCK_METHOD4(OnInitializationComplete, | 746 MOCK_METHOD4(OnInitializationComplete, |
746 void(const WeakHandle<JsBackend>&, | 747 void(const WeakHandle<JsBackend>&, |
747 const WeakHandle<DataTypeDebugInfoListener>&, | 748 const WeakHandle<DataTypeDebugInfoListener>&, |
748 bool, | 749 bool, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 this, | 830 this, |
830 credentials, | 831 credentials, |
831 "fake_invalidator_client_id", | 832 "fake_invalidator_client_id", |
832 std::string(), | 833 std::string(), |
833 std::string(), // bootstrap tokens | 834 std::string(), // bootstrap tokens |
834 scoped_ptr<InternalComponentsFactory>(GetFactory()).get(), | 835 scoped_ptr<InternalComponentsFactory>(GetFactory()).get(), |
835 &encryptor_, | 836 &encryptor_, |
836 scoped_ptr<UnrecoverableErrorHandler>( | 837 scoped_ptr<UnrecoverableErrorHandler>( |
837 new TestUnrecoverableErrorHandler).Pass(), | 838 new TestUnrecoverableErrorHandler).Pass(), |
838 NULL, | 839 NULL, |
839 false); | 840 false, |
| 841 &cancelation_signal_); |
840 | 842 |
841 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 843 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
842 | 844 |
843 EXPECT_TRUE(js_backend_.IsInitialized()); | 845 EXPECT_TRUE(js_backend_.IsInitialized()); |
844 | 846 |
845 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 847 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
846 i != routing_info.end(); ++i) { | 848 i != routing_info.end(); ++i) { |
847 type_roots_[i->first] = MakeServerNodeForType( | 849 type_roots_[i->first] = MakeServerNodeForType( |
848 sync_manager_.GetUserShare(), i->first); | 850 sync_manager_.GetUserShare(), i->first); |
849 } | 851 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 base::MessageLoop message_loop_; | 1014 base::MessageLoop message_loop_; |
1013 // Needed by |sync_manager_|. | 1015 // Needed by |sync_manager_|. |
1014 base::ScopedTempDir temp_dir_; | 1016 base::ScopedTempDir temp_dir_; |
1015 // Sync Id's for the roots of the enabled datatypes. | 1017 // Sync Id's for the roots of the enabled datatypes. |
1016 std::map<ModelType, int64> type_roots_; | 1018 std::map<ModelType, int64> type_roots_; |
1017 scoped_refptr<ExtensionsActivity> extensions_activity_; | 1019 scoped_refptr<ExtensionsActivity> extensions_activity_; |
1018 | 1020 |
1019 protected: | 1021 protected: |
1020 FakeEncryptor encryptor_; | 1022 FakeEncryptor encryptor_; |
1021 SyncManagerImpl sync_manager_; | 1023 SyncManagerImpl sync_manager_; |
| 1024 CancelationSignal cancelation_signal_; |
1022 WeakHandle<JsBackend> js_backend_; | 1025 WeakHandle<JsBackend> js_backend_; |
1023 StrictMock<SyncManagerObserverMock> manager_observer_; | 1026 StrictMock<SyncManagerObserverMock> manager_observer_; |
1024 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 1027 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
1025 InternalComponentsFactory::Switches switches_; | 1028 InternalComponentsFactory::Switches switches_; |
1026 }; | 1029 }; |
1027 | 1030 |
1028 TEST_F(SyncManagerTest, ProcessJsMessage) { | 1031 TEST_F(SyncManagerTest, ProcessJsMessage) { |
1029 const JsArgList kNoArgs; | 1032 const JsArgList kNoArgs; |
1030 | 1033 |
1031 StrictMock<MockJsReplyHandler> reply_handler; | 1034 StrictMock<MockJsReplyHandler> reply_handler; |
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2790 ComponentsFactory(const Switches& switches, | 2793 ComponentsFactory(const Switches& switches, |
2791 SyncScheduler* scheduler_to_use, | 2794 SyncScheduler* scheduler_to_use, |
2792 sessions::SyncSessionContext** session_context) | 2795 sessions::SyncSessionContext** session_context) |
2793 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), | 2796 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), |
2794 scheduler_to_use_(scheduler_to_use), | 2797 scheduler_to_use_(scheduler_to_use), |
2795 session_context_(session_context) {} | 2798 session_context_(session_context) {} |
2796 virtual ~ComponentsFactory() {} | 2799 virtual ~ComponentsFactory() {} |
2797 | 2800 |
2798 virtual scoped_ptr<SyncScheduler> BuildScheduler( | 2801 virtual scoped_ptr<SyncScheduler> BuildScheduler( |
2799 const std::string& name, | 2802 const std::string& name, |
2800 sessions::SyncSessionContext* context) OVERRIDE { | 2803 sessions::SyncSessionContext* context, |
| 2804 CancelationSignal* stop_handle) OVERRIDE { |
2801 *session_context_ = context; | 2805 *session_context_ = context; |
2802 return scheduler_to_use_.Pass(); | 2806 return scheduler_to_use_.Pass(); |
2803 } | 2807 } |
2804 | 2808 |
2805 private: | 2809 private: |
2806 scoped_ptr<SyncScheduler> scheduler_to_use_; | 2810 scoped_ptr<SyncScheduler> scheduler_to_use_; |
2807 sessions::SyncSessionContext** session_context_; | 2811 sessions::SyncSessionContext** session_context_; |
2808 }; | 2812 }; |
2809 | 2813 |
2810 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2814 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3509 size_t folder_b_pos = | 3513 size_t folder_b_pos = |
3510 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3514 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
3511 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3515 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
3512 | 3516 |
3513 // Deletes should appear before updates. | 3517 // Deletes should appear before updates. |
3514 EXPECT_LT(child_pos, folder_a_pos); | 3518 EXPECT_LT(child_pos, folder_a_pos); |
3515 EXPECT_LT(folder_b_pos, folder_a_pos); | 3519 EXPECT_LT(folder_b_pos, folder_a_pos); |
3516 } | 3520 } |
3517 | 3521 |
3518 } // namespace | 3522 } // namespace |
OLD | NEW |