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

Side by Side Diff: chrome/browser/sync/abstract_profile_sync_service_test.cc

Issue 1692873004: Move ProfileSyncService tests for autofill & typed URLs to components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@581640_no_browser_thread
Patch Set: Just rebased Created 4 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/files/file_path.h"
12 #include "base/location.h"
13 #include "base/run_loop.h"
14 #include "chrome/browser/sync/test/test_http_bridge_factory.h"
15 #include "chrome/browser/sync/test_profile_sync_service.h"
16 #include "components/sync_driver/glue/sync_backend_host_core.h"
17 #include "components/sync_driver/sync_api_component_factory_mock.h"
18 #include "google_apis/gaia/gaia_constants.h"
19 #include "sync/internal_api/public/test/sync_manager_factory_for_profile_sync_te st.h"
20 #include "sync/internal_api/public/test/test_internal_components_factory.h"
21 #include "sync/internal_api/public/test/test_user_share.h"
22 #include "sync/protocol/sync.pb.h"
23
24 using syncer::ModelType;
25 using testing::_;
26 using testing::Return;
27
28 namespace {
29
30 class SyncBackendHostForProfileSyncTest
31 : public browser_sync::SyncBackendHostImpl {
32 public:
33 SyncBackendHostForProfileSyncTest(
34 const base::FilePath& temp_dir,
35 sync_driver::SyncClient* sync_client,
36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
37 invalidation::InvalidationService* invalidator,
38 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
39 const base::Closure& callback);
40 ~SyncBackendHostForProfileSyncTest() override;
41
42 void RequestConfigureSyncer(
43 syncer::ConfigureReason reason,
44 syncer::ModelTypeSet to_download,
45 syncer::ModelTypeSet to_purge,
46 syncer::ModelTypeSet to_journal,
47 syncer::ModelTypeSet to_unapply,
48 syncer::ModelTypeSet to_ignore,
49 const syncer::ModelSafeRoutingInfo& routing_info,
50 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
51 ready_task,
52 const base::Closure& retry_callback) override;
53
54 protected:
55 void InitCore(scoped_ptr<browser_sync::DoInitializeOptions> options) override;
56
57 private:
58 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
59 // Allows extra initialization work to be performed before the backend comes
60 // up.
61 base::Closure callback_;
62
63 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest);
64 };
65
66 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
67 const base::FilePath& temp_dir,
68 sync_driver::SyncClient* sync_client,
69 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
70 invalidation::InvalidationService* invalidator,
71 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
72 const base::Closure& callback)
73 : browser_sync::SyncBackendHostImpl(
74 "dummy_debug_name",
75 sync_client,
76 ui_thread,
77 invalidator,
78 sync_prefs,
79 temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))),
80 callback_(callback) {}
81
82 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {}
83
84 void SyncBackendHostForProfileSyncTest::InitCore(
85 scoped_ptr<browser_sync::DoInitializeOptions> options) {
86 options->http_bridge_factory = scoped_ptr<syncer::HttpPostProviderFactory>(
87 new browser_sync::TestHttpBridgeFactory());
88 options->sync_manager_factory.reset(
89 new syncer::SyncManagerFactoryForProfileSyncTest(callback_));
90 options->credentials.email = "testuser@gmail.com";
91 options->credentials.sync_token = "token";
92 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope);
93 options->restored_key_for_bootstrapping.clear();
94
95 // It'd be nice if we avoided creating the InternalComponentsFactory in the
96 // first place, but SyncBackendHost will have created one by now so we must
97 // free it. Grab the switches to pass on first.
98 syncer::InternalComponentsFactory::Switches factory_switches =
99 options->internal_components_factory->GetSwitches();
100 options->internal_components_factory.reset(
101 new syncer::TestInternalComponentsFactory(
102 factory_switches,
103 syncer::InternalComponentsFactory::STORAGE_IN_MEMORY, nullptr));
104
105 browser_sync::SyncBackendHostImpl::InitCore(std::move(options));
106 }
107
108 void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer(
109 syncer::ConfigureReason reason,
110 syncer::ModelTypeSet to_download,
111 syncer::ModelTypeSet to_purge,
112 syncer::ModelTypeSet to_journal,
113 syncer::ModelTypeSet to_unapply,
114 syncer::ModelTypeSet to_ignore,
115 const syncer::ModelSafeRoutingInfo& routing_info,
116 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
117 ready_task,
118 const base::Closure& retry_callback) {
119 syncer::ModelTypeSet failed_configuration_types;
120
121 // The first parameter there should be the set of enabled types. That's not
122 // something we have access to from this strange test harness. We'll just
123 // send back the list of newly configured types instead and hope it doesn't
124 // break anything.
125 // Posted to avoid re-entrancy issues.
126 base::ThreadTaskRunnerHandle::Get()->PostTask(
127 FROM_HERE,
128 base::Bind(&SyncBackendHostForProfileSyncTest::
129 FinishConfigureDataTypesOnFrontendLoop,
130 base::Unretained(this),
131 syncer::Difference(to_download, failed_configuration_types),
132 syncer::Difference(to_download, failed_configuration_types),
133 failed_configuration_types, ready_task));
134 }
135
136 } // namespace
137
138 /* static */
139 syncer::ImmutableChangeRecordList
140 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList(
141 int64_t node_id,
142 syncer::ChangeRecord::Action action) {
143 syncer::ChangeRecord record;
144 record.action = action;
145 record.id = node_id;
146 syncer::ChangeRecordList records(1, record);
147 return syncer::ImmutableChangeRecordList(&records);
148 }
149
150 /* static */
151 syncer::ImmutableChangeRecordList
152 ProfileSyncServiceTestHelper::MakeSingletonDeletionChangeRecordList(
153 int64_t node_id,
154 const sync_pb::EntitySpecifics& specifics) {
155 syncer::ChangeRecord record;
156 record.action = syncer::ChangeRecord::ACTION_DELETE;
157 record.id = node_id;
158 record.specifics = specifics;
159 syncer::ChangeRecordList records(1, record);
160 return syncer::ImmutableChangeRecordList(&records);
161 }
162
163 AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest()
164 : data_type_thread_("Extra thread") {
165 CHECK(temp_dir_.CreateUniqueTempDir());
166 }
167
168 AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {
169 sync_service_->Shutdown();
170 }
171
172 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
173 return syncer::TestUserShare::CreateRoot(model_type,
174 sync_service_->GetUserShare());
175 }
176
177 scoped_ptr<TestProfileSyncService>
178 AbstractProfileSyncServiceTest::CreateSyncService(
179 scoped_ptr<sync_driver::SyncClient> sync_client,
180 const base::Closure& initialization_success_callback) {
181 DCHECK(sync_client);
182 ProfileSyncService::InitParams init_params =
183 profile_sync_service_bundle_.CreateBasicInitParams(
184 browser_sync::AUTO_START, std::move(sync_client));
185 auto sync_service =
186 make_scoped_ptr(new TestProfileSyncService(std::move(init_params)));
187
188 SyncApiComponentFactoryMock* components =
189 profile_sync_service_bundle_.component_factory();
190 EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _))
191 .WillOnce(Return(new SyncBackendHostForProfileSyncTest(
192 temp_dir_.path(), sync_service->GetSyncClient(),
193 base::ThreadTaskRunnerHandle::Get(),
194 profile_sync_service_bundle_.fake_invalidation_service(),
195 sync_service->sync_prefs()->AsWeakPtr(),
196 initialization_success_callback)));
197
198 sync_service->SetFirstSetupComplete();
199 return sync_service;
200 }
201
202 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test,
203 ModelType model_type)
204 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback,
205 base::Unretained(this))),
206 test_(test),
207 model_type_(model_type),
208 success_(false) {
209 }
210
211 CreateRootHelper::~CreateRootHelper() {
212 }
213
214 const base::Closure& CreateRootHelper::callback() const {
215 return callback_;
216 }
217
218 bool CreateRootHelper::success() {
219 return success_;
220 }
221
222 void CreateRootHelper::CreateRootCallback() {
223 success_ = test_->CreateRoot(model_type_);
224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698