| 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 this, | 829 this, |
| 829 credentials, | 830 credentials, |
| 830 "fake_invalidator_client_id", | 831 "fake_invalidator_client_id", |
| 831 std::string(), | 832 std::string(), |
| 832 std::string(), // bootstrap tokens | 833 std::string(), // bootstrap tokens |
| 833 scoped_ptr<InternalComponentsFactory>(GetFactory()).get(), | 834 scoped_ptr<InternalComponentsFactory>(GetFactory()).get(), |
| 834 &encryptor_, | 835 &encryptor_, |
| 835 scoped_ptr<UnrecoverableErrorHandler>( | 836 scoped_ptr<UnrecoverableErrorHandler>( |
| 836 new TestUnrecoverableErrorHandler).Pass(), | 837 new TestUnrecoverableErrorHandler).Pass(), |
| 837 NULL, | 838 NULL, |
| 838 false); | 839 false, |
| 840 &cancelation_signal_); |
| 839 | 841 |
| 840 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 842 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 841 | 843 |
| 842 EXPECT_TRUE(js_backend_.IsInitialized()); | 844 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 843 | 845 |
| 844 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 846 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 845 i != routing_info.end(); ++i) { | 847 i != routing_info.end(); ++i) { |
| 846 type_roots_[i->first] = MakeServerNodeForType( | 848 type_roots_[i->first] = MakeServerNodeForType( |
| 847 sync_manager_.GetUserShare(), i->first); | 849 sync_manager_.GetUserShare(), i->first); |
| 848 } | 850 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 base::MessageLoop message_loop_; | 1013 base::MessageLoop message_loop_; |
| 1012 // Needed by |sync_manager_|. | 1014 // Needed by |sync_manager_|. |
| 1013 base::ScopedTempDir temp_dir_; | 1015 base::ScopedTempDir temp_dir_; |
| 1014 // Sync Id's for the roots of the enabled datatypes. | 1016 // Sync Id's for the roots of the enabled datatypes. |
| 1015 std::map<ModelType, int64> type_roots_; | 1017 std::map<ModelType, int64> type_roots_; |
| 1016 scoped_refptr<ExtensionsActivity> extensions_activity_; | 1018 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| 1017 | 1019 |
| 1018 protected: | 1020 protected: |
| 1019 FakeEncryptor encryptor_; | 1021 FakeEncryptor encryptor_; |
| 1020 SyncManagerImpl sync_manager_; | 1022 SyncManagerImpl sync_manager_; |
| 1023 CancelationSignal cancelation_signal_; |
| 1021 WeakHandle<JsBackend> js_backend_; | 1024 WeakHandle<JsBackend> js_backend_; |
| 1022 StrictMock<SyncManagerObserverMock> manager_observer_; | 1025 StrictMock<SyncManagerObserverMock> manager_observer_; |
| 1023 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 1026 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
| 1024 InternalComponentsFactory::Switches switches_; | 1027 InternalComponentsFactory::Switches switches_; |
| 1025 }; | 1028 }; |
| 1026 | 1029 |
| 1027 TEST_F(SyncManagerTest, ProcessJsMessage) { | 1030 TEST_F(SyncManagerTest, ProcessJsMessage) { |
| 1028 const JsArgList kNoArgs; | 1031 const JsArgList kNoArgs; |
| 1029 | 1032 |
| 1030 StrictMock<MockJsReplyHandler> reply_handler; | 1033 StrictMock<MockJsReplyHandler> reply_handler; |
| (...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2789 ComponentsFactory(const Switches& switches, | 2792 ComponentsFactory(const Switches& switches, |
| 2790 SyncScheduler* scheduler_to_use, | 2793 SyncScheduler* scheduler_to_use, |
| 2791 sessions::SyncSessionContext** session_context) | 2794 sessions::SyncSessionContext** session_context) |
| 2792 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), | 2795 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), |
| 2793 scheduler_to_use_(scheduler_to_use), | 2796 scheduler_to_use_(scheduler_to_use), |
| 2794 session_context_(session_context) {} | 2797 session_context_(session_context) {} |
| 2795 virtual ~ComponentsFactory() {} | 2798 virtual ~ComponentsFactory() {} |
| 2796 | 2799 |
| 2797 virtual scoped_ptr<SyncScheduler> BuildScheduler( | 2800 virtual scoped_ptr<SyncScheduler> BuildScheduler( |
| 2798 const std::string& name, | 2801 const std::string& name, |
| 2799 sessions::SyncSessionContext* context) OVERRIDE { | 2802 sessions::SyncSessionContext* context, |
| 2803 CancelationSignal* stop_handle) OVERRIDE { |
| 2800 *session_context_ = context; | 2804 *session_context_ = context; |
| 2801 return scheduler_to_use_.Pass(); | 2805 return scheduler_to_use_.Pass(); |
| 2802 } | 2806 } |
| 2803 | 2807 |
| 2804 private: | 2808 private: |
| 2805 scoped_ptr<SyncScheduler> scheduler_to_use_; | 2809 scoped_ptr<SyncScheduler> scheduler_to_use_; |
| 2806 sessions::SyncSessionContext** session_context_; | 2810 sessions::SyncSessionContext** session_context_; |
| 2807 }; | 2811 }; |
| 2808 | 2812 |
| 2809 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2813 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3508 size_t folder_b_pos = | 3512 size_t folder_b_pos = |
| 3509 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3513 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
| 3510 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3514 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
| 3511 | 3515 |
| 3512 // Deletes should appear before updates. | 3516 // Deletes should appear before updates. |
| 3513 EXPECT_LT(child_pos, folder_a_pos); | 3517 EXPECT_LT(child_pos, folder_a_pos); |
| 3514 EXPECT_LT(folder_b_pos, folder_a_pos); | 3518 EXPECT_LT(folder_b_pos, folder_a_pos); |
| 3515 } | 3519 } |
| 3516 | 3520 |
| 3517 } // namespace | 3521 } // namespace |
| OLD | NEW |