Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: components/browser_sync/abstract_profile_sync_service_test.cc

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
25 using syncer::ModelType; 26 using syncer::ModelType;
26 using testing::_; 27 using testing::_;
27 using testing::Return; 28 using testing::Return;
28 29
29 namespace browser_sync { 30 namespace browser_sync {
30 31
31 namespace { 32 namespace {
32 33
33 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl { 34 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
34 public: 35 public:
35 SyncBackendHostForProfileSyncTest( 36 SyncBackendHostForProfileSyncTest(
36 const base::FilePath& temp_dir, 37 const base::FilePath& temp_dir,
37 sync_driver::SyncClient* sync_client, 38 syncer::SyncClient* sync_client,
38 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, 39 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
39 invalidation::InvalidationService* invalidator, 40 invalidation::InvalidationService* invalidator,
40 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, 41 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs,
41 const base::Closure& callback); 42 const base::Closure& callback);
42 ~SyncBackendHostForProfileSyncTest() override; 43 ~SyncBackendHostForProfileSyncTest() override;
43 44
44 void RequestConfigureSyncer( 45 void RequestConfigureSyncer(
45 syncer::ConfigureReason reason, 46 syncer::ConfigureReason reason,
46 syncer::ModelTypeSet to_download, 47 syncer::ModelTypeSet to_download,
47 syncer::ModelTypeSet to_purge, 48 syncer::ModelTypeSet to_purge,
48 syncer::ModelTypeSet to_journal, 49 syncer::ModelTypeSet to_journal,
49 syncer::ModelTypeSet to_unapply, 50 syncer::ModelTypeSet to_unapply,
50 syncer::ModelTypeSet to_ignore, 51 syncer::ModelTypeSet to_ignore,
51 const syncer::ModelSafeRoutingInfo& routing_info, 52 const syncer::ModelSafeRoutingInfo& routing_info,
52 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& 53 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
53 ready_task, 54 ready_task,
54 const base::Closure& retry_callback) override; 55 const base::Closure& retry_callback) override;
55 56
56 protected: 57 protected:
57 void InitCore(std::unique_ptr<DoInitializeOptions> options) override; 58 void InitCore(std::unique_ptr<syncer::DoInitializeOptions> options) override;
58 59
59 private: 60 private:
60 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. 61 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
61 // Allows extra initialization work to be performed before the backend comes 62 // Allows extra initialization work to be performed before the backend comes
62 // up. 63 // up.
63 base::Closure callback_; 64 base::Closure callback_;
64 65
65 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest); 66 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest);
66 }; 67 };
67 68
68 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( 69 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
69 const base::FilePath& temp_dir, 70 const base::FilePath& temp_dir,
70 sync_driver::SyncClient* sync_client, 71 syncer::SyncClient* sync_client,
71 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, 72 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
72 invalidation::InvalidationService* invalidator, 73 invalidation::InvalidationService* invalidator,
73 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, 74 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs,
74 const base::Closure& callback) 75 const base::Closure& callback)
75 : SyncBackendHostImpl( 76 : SyncBackendHostImpl(
76 "dummy_debug_name", 77 "dummy_debug_name",
77 sync_client, 78 sync_client,
78 ui_thread, 79 ui_thread,
79 invalidator, 80 invalidator,
80 sync_prefs, 81 sync_prefs,
81 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))), 82 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))),
82 callback_(callback) {} 83 callback_(callback) {}
83 84
84 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} 85 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {}
85 86
86 void SyncBackendHostForProfileSyncTest::InitCore( 87 void SyncBackendHostForProfileSyncTest::InitCore(
87 std::unique_ptr<DoInitializeOptions> options) { 88 std::unique_ptr<syncer::DoInitializeOptions> options) {
88 options->http_bridge_factory = 89 options->http_bridge_factory =
89 std::unique_ptr<syncer::HttpPostProviderFactory>( 90 std::unique_ptr<syncer::HttpPostProviderFactory>(
90 new TestHttpBridgeFactory()); 91 new TestHttpBridgeFactory());
91 options->sync_manager_factory.reset( 92 options->sync_manager_factory.reset(
92 new syncer::SyncManagerFactoryForProfileSyncTest(callback_)); 93 new syncer::SyncManagerFactoryForProfileSyncTest(callback_));
93 options->credentials.email = "testuser@gmail.com"; 94 options->credentials.email = "testuser@gmail.com";
94 options->credentials.sync_token = "token"; 95 options->credentials.sync_token = "token";
95 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); 96 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope);
96 options->restored_key_for_bootstrapping.clear(); 97 options->restored_key_for_bootstrapping.clear();
97 98
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 FROM_HERE, 131 FROM_HERE,
131 base::Bind(&SyncBackendHostForProfileSyncTest:: 132 base::Bind(&SyncBackendHostForProfileSyncTest::
132 FinishConfigureDataTypesOnFrontendLoop, 133 FinishConfigureDataTypesOnFrontendLoop,
133 base::Unretained(this), 134 base::Unretained(this),
134 syncer::Difference(to_download, failed_configuration_types), 135 syncer::Difference(to_download, failed_configuration_types),
135 syncer::Difference(to_download, failed_configuration_types), 136 syncer::Difference(to_download, failed_configuration_types),
136 failed_configuration_types, ready_task)); 137 failed_configuration_types, ready_task));
137 } 138 }
138 139
139 // Helper function for return-type-upcasting of the callback. 140 // Helper function for return-type-upcasting of the callback.
140 sync_driver::SyncService* GetSyncService( 141 syncer::SyncService* GetSyncService(
141 base::Callback<TestProfileSyncService*(void)> get_sync_service_callback) { 142 base::Callback<TestProfileSyncService*(void)> get_sync_service_callback) {
142 return get_sync_service_callback.Run(); 143 return get_sync_service_callback.Run();
143 } 144 }
144 145
145 } // namespace 146 } // namespace
146 147
147 /* static */ 148 /* static */
148 syncer::ImmutableChangeRecordList 149 syncer::ImmutableChangeRecordList
149 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( 150 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList(
150 int64_t node_id, 151 int64_t node_id,
(...skipping 26 matching lines...) Expand all
177 AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() { 178 AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {
178 sync_service_->Shutdown(); 179 sync_service_->Shutdown();
179 } 180 }
180 181
181 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) { 182 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
182 return syncer::TestUserShare::CreateRoot(model_type, 183 return syncer::TestUserShare::CreateRoot(model_type,
183 sync_service_->GetUserShare()); 184 sync_service_->GetUserShare());
184 } 185 }
185 186
186 void AbstractProfileSyncServiceTest::CreateSyncService( 187 void AbstractProfileSyncServiceTest::CreateSyncService(
187 std::unique_ptr<sync_driver::SyncClient> sync_client, 188 std::unique_ptr<syncer::SyncClient> sync_client,
188 const base::Closure& initialization_success_callback) { 189 const base::Closure& initialization_success_callback) {
189 DCHECK(sync_client); 190 DCHECK(sync_client);
190 ProfileSyncService::InitParams init_params = 191 ProfileSyncService::InitParams init_params =
191 profile_sync_service_bundle_.CreateBasicInitParams( 192 profile_sync_service_bundle_.CreateBasicInitParams(
192 ProfileSyncService::AUTO_START, std::move(sync_client)); 193 ProfileSyncService::AUTO_START, std::move(sync_client));
193 sync_service_ = 194 sync_service_ =
194 base::MakeUnique<TestProfileSyncService>(std::move(init_params)); 195 base::MakeUnique<TestProfileSyncService>(std::move(init_params));
195 196
196 SyncApiComponentFactoryMock* components = 197 syncer::SyncApiComponentFactoryMock* components =
197 profile_sync_service_bundle_.component_factory(); 198 profile_sync_service_bundle_.component_factory();
198 EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _)) 199 EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _))
199 .WillOnce(Return(new SyncBackendHostForProfileSyncTest( 200 .WillOnce(Return(new SyncBackendHostForProfileSyncTest(
200 temp_dir_.GetPath(), sync_service_->GetSyncClient(), 201 temp_dir_.GetPath(), sync_service_->GetSyncClient(),
201 base::ThreadTaskRunnerHandle::Get(), 202 base::ThreadTaskRunnerHandle::Get(),
202 profile_sync_service_bundle_.fake_invalidation_service(), 203 profile_sync_service_bundle_.fake_invalidation_service(),
203 sync_service_->sync_prefs()->AsWeakPtr(), 204 sync_service_->sync_prefs()->AsWeakPtr(),
204 initialization_success_callback))); 205 initialization_success_callback)));
205 206
206 sync_service_->SetFirstSetupComplete(); 207 sync_service_->SetFirstSetupComplete();
207 } 208 }
208 209
209 base::Callback<sync_driver::SyncService*(void)> 210 base::Callback<syncer::SyncService*(void)>
210 AbstractProfileSyncServiceTest::GetSyncServiceCallback() { 211 AbstractProfileSyncServiceTest::GetSyncServiceCallback() {
211 return base::Bind(GetSyncService, 212 return base::Bind(GetSyncService,
212 base::Bind(&AbstractProfileSyncServiceTest::sync_service, 213 base::Bind(&AbstractProfileSyncServiceTest::sync_service,
213 base::Unretained(this))); 214 base::Unretained(this)));
214 } 215 }
215 216
216 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test, 217 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test,
217 ModelType model_type) 218 ModelType model_type)
218 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, 219 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback,
219 base::Unretained(this))), 220 base::Unretained(this))),
220 test_(test), 221 test_(test),
221 model_type_(model_type), 222 model_type_(model_type),
222 success_(false) {} 223 success_(false) {}
223 224
224 CreateRootHelper::~CreateRootHelper() {} 225 CreateRootHelper::~CreateRootHelper() {}
225 226
226 const base::Closure& CreateRootHelper::callback() const { 227 const base::Closure& CreateRootHelper::callback() const {
227 return callback_; 228 return callback_;
228 } 229 }
229 230
230 bool CreateRootHelper::success() { 231 bool CreateRootHelper::success() {
231 return success_; 232 return success_;
232 } 233 }
233 234
234 void CreateRootHelper::CreateRootCallback() { 235 void CreateRootHelper::CreateRootCallback() {
235 success_ = test_->CreateRoot(model_type_); 236 success_ = test_->CreateRoot(model_type_);
236 } 237 }
237 238
238 } // namespace browser_sync 239 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698