| 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 "sync/internal_api/sync_manager_impl.h" | 9 #include "sync/internal_api/sync_manager_impl.h" |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 |
| 12 #include <cstddef> | 13 #include <cstddef> |
| 13 #include <map> | 14 #include <map> |
| 15 #include <memory> |
| 14 #include <utility> | 16 #include <utility> |
| 15 | 17 |
| 16 #include "base/callback.h" | 18 #include "base/callback.h" |
| 17 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 20 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/format_macros.h" | 21 #include "base/format_macros.h" |
| 20 #include "base/location.h" | 22 #include "base/location.h" |
| 21 #include "base/memory/scoped_ptr.h" | |
| 22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
| 23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/test/values_test_util.h" | 27 #include "base/test/values_test_util.h" |
| 27 #include "base/values.h" | 28 #include "base/values.h" |
| 28 #include "google_apis/gaia/gaia_constants.h" | 29 #include "google_apis/gaia/gaia_constants.h" |
| 29 #include "sync/engine/sync_scheduler.h" | 30 #include "sync/engine/sync_scheduler.h" |
| 30 #include "sync/internal_api/public/base/attachment_id_proto.h" | 31 #include "sync/internal_api/public/base/attachment_id_proto.h" |
| 31 #include "sync/internal_api/public/base/cancelation_signal.h" | 32 #include "sync/internal_api/public/base/cancelation_signal.h" |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 | 904 |
| 904 // This works only because all routing info types are GROUP_PASSIVE. | 905 // This works only because all routing info types are GROUP_PASSIVE. |
| 905 // If we had types in other groups, we would need additional workers | 906 // If we had types in other groups, we would need additional workers |
| 906 // to support them. | 907 // to support them. |
| 907 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE); | 908 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE); |
| 908 workers.push_back(worker); | 909 workers.push_back(worker); |
| 909 | 910 |
| 910 SyncManager::InitArgs args; | 911 SyncManager::InitArgs args; |
| 911 args.database_location = temp_dir_.path(); | 912 args.database_location = temp_dir_.path(); |
| 912 args.service_url = GURL("https://example.com/"); | 913 args.service_url = GURL("https://example.com/"); |
| 913 args.post_factory = | 914 args.post_factory = std::unique_ptr<HttpPostProviderFactory>( |
| 914 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()); | 915 new TestHttpPostProviderFactory()); |
| 915 args.workers = workers; | 916 args.workers = workers; |
| 916 args.extensions_activity = extensions_activity_.get(), | 917 args.extensions_activity = extensions_activity_.get(), |
| 917 args.change_delegate = this; | 918 args.change_delegate = this; |
| 918 args.credentials = credentials; | 919 args.credentials = credentials; |
| 919 args.invalidator_client_id = "fake_invalidator_client_id"; | 920 args.invalidator_client_id = "fake_invalidator_client_id"; |
| 920 args.internal_components_factory.reset(GetFactory()); | 921 args.internal_components_factory.reset(GetFactory()); |
| 921 args.encryptor = &encryptor_; | 922 args.encryptor = &encryptor_; |
| 922 args.unrecoverable_error_handler = | 923 args.unrecoverable_error_handler = |
| 923 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); | 924 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); |
| 924 args.cancelation_signal = &cancelation_signal_; | 925 args.cancelation_signal = &cancelation_signal_; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 InternalComponentsFactory::Switches switches_; | 1138 InternalComponentsFactory::Switches switches_; |
| 1138 InternalComponentsFactory::StorageOption storage_used_; | 1139 InternalComponentsFactory::StorageOption storage_used_; |
| 1139 MockUnrecoverableErrorHandler mock_unrecoverable_error_handler_; | 1140 MockUnrecoverableErrorHandler mock_unrecoverable_error_handler_; |
| 1140 }; | 1141 }; |
| 1141 | 1142 |
| 1142 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { | 1143 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { |
| 1143 ModelSafeRoutingInfo routing_info; | 1144 ModelSafeRoutingInfo routing_info; |
| 1144 GetModelSafeRoutingInfo(&routing_info); | 1145 GetModelSafeRoutingInfo(&routing_info); |
| 1145 sync_manager_.StartSyncingNormally(routing_info, base::Time()); | 1146 sync_manager_.StartSyncingNormally(routing_info, base::Time()); |
| 1146 | 1147 |
| 1147 scoped_ptr<base::ListValue> node_list( | 1148 std::unique_ptr<base::ListValue> node_list( |
| 1148 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); | 1149 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); |
| 1149 | 1150 |
| 1150 // Should have one node: the type root node. | 1151 // Should have one node: the type root node. |
| 1151 ASSERT_EQ(1U, node_list->GetSize()); | 1152 ASSERT_EQ(1U, node_list->GetSize()); |
| 1152 | 1153 |
| 1153 const base::DictionaryValue* first_result; | 1154 const base::DictionaryValue* first_result; |
| 1154 ASSERT_TRUE(node_list->GetDictionary(0, &first_result)); | 1155 ASSERT_TRUE(node_list->GetDictionary(0, &first_result)); |
| 1155 EXPECT_TRUE(first_result->HasKey("ID")); | 1156 EXPECT_TRUE(first_result->HasKey("ID")); |
| 1156 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); | 1157 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); |
| 1157 } | 1158 } |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 ComponentsFactory(const Switches& switches, | 2539 ComponentsFactory(const Switches& switches, |
| 2539 SyncScheduler* scheduler_to_use, | 2540 SyncScheduler* scheduler_to_use, |
| 2540 sessions::SyncSessionContext** session_context, | 2541 sessions::SyncSessionContext** session_context, |
| 2541 InternalComponentsFactory::StorageOption* storage_used) | 2542 InternalComponentsFactory::StorageOption* storage_used) |
| 2542 : TestInternalComponentsFactory( | 2543 : TestInternalComponentsFactory( |
| 2543 switches, InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used), | 2544 switches, InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used), |
| 2544 scheduler_to_use_(scheduler_to_use), | 2545 scheduler_to_use_(scheduler_to_use), |
| 2545 session_context_(session_context) {} | 2546 session_context_(session_context) {} |
| 2546 ~ComponentsFactory() override {} | 2547 ~ComponentsFactory() override {} |
| 2547 | 2548 |
| 2548 scoped_ptr<SyncScheduler> BuildScheduler( | 2549 std::unique_ptr<SyncScheduler> BuildScheduler( |
| 2549 const std::string& name, | 2550 const std::string& name, |
| 2550 sessions::SyncSessionContext* context, | 2551 sessions::SyncSessionContext* context, |
| 2551 CancelationSignal* stop_handle) override { | 2552 CancelationSignal* stop_handle) override { |
| 2552 *session_context_ = context; | 2553 *session_context_ = context; |
| 2553 return std::move(scheduler_to_use_); | 2554 return std::move(scheduler_to_use_); |
| 2554 } | 2555 } |
| 2555 | 2556 |
| 2556 private: | 2557 private: |
| 2557 scoped_ptr<SyncScheduler> scheduler_to_use_; | 2558 std::unique_ptr<SyncScheduler> scheduler_to_use_; |
| 2558 sessions::SyncSessionContext** session_context_; | 2559 sessions::SyncSessionContext** session_context_; |
| 2559 }; | 2560 }; |
| 2560 | 2561 |
| 2561 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2562 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| 2562 public: | 2563 public: |
| 2563 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2564 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} |
| 2564 InternalComponentsFactory* GetFactory() override { | 2565 InternalComponentsFactory* GetFactory() override { |
| 2565 scheduler_ = new MockSyncScheduler(); | 2566 scheduler_ = new MockSyncScheduler(); |
| 2566 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, | 2567 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, |
| 2567 &storage_used_); | 2568 &storage_used_); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3359 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3360 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3360 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3361 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3361 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3362 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3362 // task is to ensure that SyncManagerImpl reported initialization failure in | 3363 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3363 // OnInitializationComplete callback. | 3364 // OnInitializationComplete callback. |
| 3364 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3365 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3365 EXPECT_FALSE(initialization_succeeded_); | 3366 EXPECT_FALSE(initialization_succeeded_); |
| 3366 } | 3367 } |
| 3367 | 3368 |
| 3368 } // namespace syncer | 3369 } // namespace syncer |
| OLD | NEW |