OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "components/browser_sync/abstract_profile_sync_service_test.h" | 5 #include "components/browser_sync/abstract_profile_sync_service_test.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "components/browser_sync/test_http_bridge_factory.h" | 15 #include "components/browser_sync/test_http_bridge_factory.h" |
16 #include "components/browser_sync/test_profile_sync_service.h" | 16 #include "components/browser_sync/test_profile_sync_service.h" |
17 #include "components/sync/core/test/sync_manager_factory_for_profile_sync_test.h
" | 17 #include "components/sync/core/test/sync_manager_factory_for_profile_sync_test.h
" |
18 #include "components/sync/core/test/test_internal_components_factory.h" | 18 #include "components/sync/core/test/test_internal_components_factory.h" |
19 #include "components/sync/core/test/test_user_share.h" | 19 #include "components/sync/core/test/test_user_share.h" |
20 #include "components/sync/driver/glue/sync_backend_host_core.h" | 20 #include "components/sync/driver/glue/sync_backend_host_core.h" |
21 #include "components/sync/driver/sync_api_component_factory_mock.h" | 21 #include "components/sync/driver/sync_api_component_factory_mock.h" |
22 #include "components/sync/protocol/sync.pb.h" | 22 #include "components/sync/protocol/sync.pb.h" |
23 #include "google_apis/gaia/gaia_constants.h" | 23 #include "google_apis/gaia/gaia_constants.h" |
24 | 24 |
25 using syncer::SyncBackendHostImpl; | |
26 using syncer::ModelType; | 25 using syncer::ModelType; |
27 using testing::_; | 26 using testing::_; |
28 using testing::Return; | 27 using testing::Return; |
29 | 28 |
30 namespace browser_sync { | 29 namespace browser_sync { |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl { | 33 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl { |
35 public: | 34 public: |
36 SyncBackendHostForProfileSyncTest( | 35 SyncBackendHostForProfileSyncTest( |
37 const base::FilePath& temp_dir, | 36 const base::FilePath& temp_dir, |
38 syncer::SyncClient* sync_client, | 37 sync_driver::SyncClient* sync_client, |
39 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 38 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
40 invalidation::InvalidationService* invalidator, | 39 invalidation::InvalidationService* invalidator, |
41 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs, | 40 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
42 const base::Closure& callback); | 41 const base::Closure& callback); |
43 ~SyncBackendHostForProfileSyncTest() override; | 42 ~SyncBackendHostForProfileSyncTest() override; |
44 | 43 |
45 void RequestConfigureSyncer( | 44 void RequestConfigureSyncer( |
46 syncer::ConfigureReason reason, | 45 syncer::ConfigureReason reason, |
47 syncer::ModelTypeSet to_download, | 46 syncer::ModelTypeSet to_download, |
48 syncer::ModelTypeSet to_purge, | 47 syncer::ModelTypeSet to_purge, |
49 syncer::ModelTypeSet to_journal, | 48 syncer::ModelTypeSet to_journal, |
50 syncer::ModelTypeSet to_unapply, | 49 syncer::ModelTypeSet to_unapply, |
51 syncer::ModelTypeSet to_ignore, | 50 syncer::ModelTypeSet to_ignore, |
52 const syncer::ModelSafeRoutingInfo& routing_info, | 51 const syncer::ModelSafeRoutingInfo& routing_info, |
53 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& | 52 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
54 ready_task, | 53 ready_task, |
55 const base::Closure& retry_callback) override; | 54 const base::Closure& retry_callback) override; |
56 | 55 |
57 protected: | 56 protected: |
58 void InitCore(std::unique_ptr<syncer::DoInitializeOptions> options) override; | 57 void InitCore(std::unique_ptr<DoInitializeOptions> options) override; |
59 | 58 |
60 private: | 59 private: |
61 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. | 60 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. |
62 // Allows extra initialization work to be performed before the backend comes | 61 // Allows extra initialization work to be performed before the backend comes |
63 // up. | 62 // up. |
64 base::Closure callback_; | 63 base::Closure callback_; |
65 | 64 |
66 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest); | 65 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest); |
67 }; | 66 }; |
68 | 67 |
69 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( | 68 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
70 const base::FilePath& temp_dir, | 69 const base::FilePath& temp_dir, |
71 syncer::SyncClient* sync_client, | 70 sync_driver::SyncClient* sync_client, |
72 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 71 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
73 invalidation::InvalidationService* invalidator, | 72 invalidation::InvalidationService* invalidator, |
74 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs, | 73 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
75 const base::Closure& callback) | 74 const base::Closure& callback) |
76 : SyncBackendHostImpl( | 75 : SyncBackendHostImpl( |
77 "dummy_debug_name", | 76 "dummy_debug_name", |
78 sync_client, | 77 sync_client, |
79 ui_thread, | 78 ui_thread, |
80 invalidator, | 79 invalidator, |
81 sync_prefs, | 80 sync_prefs, |
82 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))), | 81 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))), |
83 callback_(callback) {} | 82 callback_(callback) {} |
84 | 83 |
85 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 84 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
86 | 85 |
87 void SyncBackendHostForProfileSyncTest::InitCore( | 86 void SyncBackendHostForProfileSyncTest::InitCore( |
88 std::unique_ptr<syncer::DoInitializeOptions> options) { | 87 std::unique_ptr<DoInitializeOptions> options) { |
89 options->http_bridge_factory = | 88 options->http_bridge_factory = |
90 std::unique_ptr<syncer::HttpPostProviderFactory>( | 89 std::unique_ptr<syncer::HttpPostProviderFactory>( |
91 new TestHttpBridgeFactory()); | 90 new TestHttpBridgeFactory()); |
92 options->sync_manager_factory.reset( | 91 options->sync_manager_factory.reset( |
93 new syncer::SyncManagerFactoryForProfileSyncTest(callback_)); | 92 new syncer::SyncManagerFactoryForProfileSyncTest(callback_)); |
94 options->credentials.email = "testuser@gmail.com"; | 93 options->credentials.email = "testuser@gmail.com"; |
95 options->credentials.sync_token = "token"; | 94 options->credentials.sync_token = "token"; |
96 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 95 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
97 options->restored_key_for_bootstrapping.clear(); | 96 options->restored_key_for_bootstrapping.clear(); |
98 | 97 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 FROM_HERE, | 130 FROM_HERE, |
132 base::Bind(&SyncBackendHostForProfileSyncTest:: | 131 base::Bind(&SyncBackendHostForProfileSyncTest:: |
133 FinishConfigureDataTypesOnFrontendLoop, | 132 FinishConfigureDataTypesOnFrontendLoop, |
134 base::Unretained(this), | 133 base::Unretained(this), |
135 syncer::Difference(to_download, failed_configuration_types), | 134 syncer::Difference(to_download, failed_configuration_types), |
136 syncer::Difference(to_download, failed_configuration_types), | 135 syncer::Difference(to_download, failed_configuration_types), |
137 failed_configuration_types, ready_task)); | 136 failed_configuration_types, ready_task)); |
138 } | 137 } |
139 | 138 |
140 // Helper function for return-type-upcasting of the callback. | 139 // Helper function for return-type-upcasting of the callback. |
141 syncer::SyncService* GetSyncService( | 140 sync_driver::SyncService* GetSyncService( |
142 base::Callback<TestProfileSyncService*(void)> get_sync_service_callback) { | 141 base::Callback<TestProfileSyncService*(void)> get_sync_service_callback) { |
143 return get_sync_service_callback.Run(); | 142 return get_sync_service_callback.Run(); |
144 } | 143 } |
145 | 144 |
146 } // namespace | 145 } // namespace |
147 | 146 |
148 /* static */ | 147 /* static */ |
149 syncer::ImmutableChangeRecordList | 148 syncer::ImmutableChangeRecordList |
150 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( | 149 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( |
151 int64_t node_id, | 150 int64_t node_id, |
(...skipping 26 matching lines...) Expand all Loading... |
178 AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() { | 177 AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() { |
179 sync_service_->Shutdown(); | 178 sync_service_->Shutdown(); |
180 } | 179 } |
181 | 180 |
182 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) { | 181 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) { |
183 return syncer::TestUserShare::CreateRoot(model_type, | 182 return syncer::TestUserShare::CreateRoot(model_type, |
184 sync_service_->GetUserShare()); | 183 sync_service_->GetUserShare()); |
185 } | 184 } |
186 | 185 |
187 void AbstractProfileSyncServiceTest::CreateSyncService( | 186 void AbstractProfileSyncServiceTest::CreateSyncService( |
188 std::unique_ptr<syncer::SyncClient> sync_client, | 187 std::unique_ptr<sync_driver::SyncClient> sync_client, |
189 const base::Closure& initialization_success_callback) { | 188 const base::Closure& initialization_success_callback) { |
190 DCHECK(sync_client); | 189 DCHECK(sync_client); |
191 ProfileSyncService::InitParams init_params = | 190 ProfileSyncService::InitParams init_params = |
192 profile_sync_service_bundle_.CreateBasicInitParams( | 191 profile_sync_service_bundle_.CreateBasicInitParams( |
193 ProfileSyncService::AUTO_START, std::move(sync_client)); | 192 ProfileSyncService::AUTO_START, std::move(sync_client)); |
194 sync_service_ = | 193 sync_service_ = |
195 base::MakeUnique<TestProfileSyncService>(std::move(init_params)); | 194 base::MakeUnique<TestProfileSyncService>(std::move(init_params)); |
196 | 195 |
197 syncer::SyncApiComponentFactoryMock* components = | 196 SyncApiComponentFactoryMock* components = |
198 profile_sync_service_bundle_.component_factory(); | 197 profile_sync_service_bundle_.component_factory(); |
199 EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _)) | 198 EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _)) |
200 .WillOnce(Return(new SyncBackendHostForProfileSyncTest( | 199 .WillOnce(Return(new SyncBackendHostForProfileSyncTest( |
201 temp_dir_.GetPath(), sync_service_->GetSyncClient(), | 200 temp_dir_.GetPath(), sync_service_->GetSyncClient(), |
202 base::ThreadTaskRunnerHandle::Get(), | 201 base::ThreadTaskRunnerHandle::Get(), |
203 profile_sync_service_bundle_.fake_invalidation_service(), | 202 profile_sync_service_bundle_.fake_invalidation_service(), |
204 sync_service_->sync_prefs()->AsWeakPtr(), | 203 sync_service_->sync_prefs()->AsWeakPtr(), |
205 initialization_success_callback))); | 204 initialization_success_callback))); |
206 | 205 |
207 sync_service_->SetFirstSetupComplete(); | 206 sync_service_->SetFirstSetupComplete(); |
208 } | 207 } |
209 | 208 |
210 base::Callback<syncer::SyncService*(void)> | 209 base::Callback<sync_driver::SyncService*(void)> |
211 AbstractProfileSyncServiceTest::GetSyncServiceCallback() { | 210 AbstractProfileSyncServiceTest::GetSyncServiceCallback() { |
212 return base::Bind(GetSyncService, | 211 return base::Bind(GetSyncService, |
213 base::Bind(&AbstractProfileSyncServiceTest::sync_service, | 212 base::Bind(&AbstractProfileSyncServiceTest::sync_service, |
214 base::Unretained(this))); | 213 base::Unretained(this))); |
215 } | 214 } |
216 | 215 |
217 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test, | 216 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test, |
218 ModelType model_type) | 217 ModelType model_type) |
219 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, | 218 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, |
220 base::Unretained(this))), | 219 base::Unretained(this))), |
221 test_(test), | 220 test_(test), |
222 model_type_(model_type), | 221 model_type_(model_type), |
223 success_(false) {} | 222 success_(false) {} |
224 | 223 |
225 CreateRootHelper::~CreateRootHelper() {} | 224 CreateRootHelper::~CreateRootHelper() {} |
226 | 225 |
227 const base::Closure& CreateRootHelper::callback() const { | 226 const base::Closure& CreateRootHelper::callback() const { |
228 return callback_; | 227 return callback_; |
229 } | 228 } |
230 | 229 |
231 bool CreateRootHelper::success() { | 230 bool CreateRootHelper::success() { |
232 return success_; | 231 return success_; |
233 } | 232 } |
234 | 233 |
235 void CreateRootHelper::CreateRootCallback() { | 234 void CreateRootHelper::CreateRootCallback() { |
236 success_ = test_->CreateRoot(model_type_); | 235 success_ = test_->CreateRoot(model_type_); |
237 } | 236 } |
238 | 237 |
239 } // namespace browser_sync | 238 } // namespace browser_sync |
OLD | NEW |