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

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

Issue 12494020: Remove knowledge of Chrome-specific SyncableService classes from WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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 #include <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // TODO(tim): It would be nice if WebDataService was injected on 186 // TODO(tim): It would be nice if WebDataService was injected on
187 // construction of TokenService rather than fetched by Initialize so that 187 // construction of TokenService rather than fetched by Initialize so that
188 // this isn't necessary (we could pass a NULL service). We currently do 188 // this isn't necessary (we could pass a NULL service). We currently do
189 // return it via EXPECT_CALLs, but without depending on order-of- 189 // return it via EXPECT_CALLs, but without depending on order-of-
190 // initialization (which seems way more fragile) we can't tell which 190 // initialization (which seems way more fragile) we can't tell which
191 // component is asking at what time, and some components in these Autofill 191 // component is asking at what time, and some components in these Autofill
192 // tests require a WebDataService. 192 // tests require a WebDataService.
193 return 0; 193 return 0;
194 } 194 }
195 195
196 virtual AutocompleteSyncableService*
197 GetAutocompleteSyncableService() const OVERRIDE {
198 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
199 EXPECT_TRUE(autocomplete_syncable_service_);
200
201 return autocomplete_syncable_service_;
202 }
203
204 virtual AutofillProfileSyncableService*
205 GetAutofillProfileSyncableService() const OVERRIDE {
206 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
207 EXPECT_TRUE(autofill_profile_syncable_service_);
208
209 return autofill_profile_syncable_service_;
210 }
211
212 virtual void ShutdownOnUIThread() OVERRIDE {} 196 virtual void ShutdownOnUIThread() OVERRIDE {}
213 197
214 private: 198 private:
215 virtual ~WebDataServiceFake() {} 199 virtual ~WebDataServiceFake() {}
216 200
217 void CreateSyncableService() { 201 void CreateSyncableService() {
218 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 202 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
219 // These services are deleted in DestroySyncableService(). 203 // These services are deleted in DestroySyncableService().
220 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); 204 AutocompleteSyncableService::AttachToWebData(
221 autofill_profile_syncable_service_ = 205 make_scoped_ptr(new AutocompleteSyncableService(this)), this);
222 new AutofillProfileSyncableService(this); 206 AutofillProfileSyncableService::AttachToWebData(
207 make_scoped_ptr(new AutofillProfileSyncableService(this)), this);
223 syncable_service_created_or_destroyed_.Signal(); 208 syncable_service_created_or_destroyed_.Signal();
224 } 209 }
225 210
226 void DestroySyncableService() { 211 void DestroySyncableService() {
227 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 212 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
228 delete autofill_profile_syncable_service_; 213 WebDataServiceBase::ShutdownOnDBThread();
229 delete autocomplete_syncable_service_;
230 syncable_service_created_or_destroyed_.Signal(); 214 syncable_service_created_or_destroyed_.Signal();
231 } 215 }
232 216
233 WebDatabase* web_database_; 217 WebDatabase* web_database_;
234 218
235 // We own the syncable services, but don't use a |scoped_ptr| because the
236 // lifetime must be managed on the DB thread.
237 AutocompleteSyncableService* autocomplete_syncable_service_;
238 AutofillProfileSyncableService* autofill_profile_syncable_service_;
239 WaitableEvent syncable_service_created_or_destroyed_; 219 WaitableEvent syncable_service_created_or_destroyed_;
240 }; 220 };
241 221
242 class MockWebDataServiceWrapper : public WebDataServiceWrapper { 222 class MockWebDataServiceWrapper : public WebDataServiceWrapper {
243 public: 223 public:
244 static ProfileKeyedService* Build(Profile* profile) { 224 static ProfileKeyedService* Build(Profile* profile) {
245 return new MockWebDataServiceWrapper(); 225 return new MockWebDataServiceWrapper();
246 } 226 }
247 227
248 MockWebDataServiceWrapper() { 228 MockWebDataServiceWrapper() {
(...skipping 13 matching lines...) Expand all
262 242
263 private: 243 private:
264 scoped_refptr<WebDataServiceFake> web_data_service_fake_; 244 scoped_refptr<WebDataServiceFake> web_data_service_fake_;
265 245
266 }; 246 };
267 247
268 ACTION_P(MakeAutocompleteSyncComponents, wds) { 248 ACTION_P(MakeAutocompleteSyncComponents, wds) {
269 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 249 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
270 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 250 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
271 return base::WeakPtr<syncer::SyncableService>(); 251 return base::WeakPtr<syncer::SyncableService>();
272 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); 252 return AutocompleteSyncableService::FromWebData(wds)->AsWeakPtr();
273 } 253 }
274 254
275 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { 255 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) {
276 return new browser_sync::DataTypeManagerImpl( 256 return new browser_sync::DataTypeManagerImpl(
277 debug_listener, 257 debug_listener,
278 arg1, 258 arg1,
279 arg2, 259 arg2,
280 arg3, 260 arg3,
281 arg4); 261 arg4);
282 } 262 }
283 263
284 ACTION(MakeGenericChangeProcessor) { 264 ACTION(MakeGenericChangeProcessor) {
285 syncer::UserShare* user_share = arg0->GetUserShare(); 265 syncer::UserShare* user_share = arg0->GetUserShare();
286 return new GenericChangeProcessor( 266 return new GenericChangeProcessor(
287 arg1, 267 arg1,
288 arg2, 268 arg2,
289 arg3, 269 arg3,
290 user_share); 270 user_share);
291 } 271 }
292 272
293 ACTION(MakeSharedChangeProcessor) { 273 ACTION(MakeSharedChangeProcessor) {
294 return new SharedChangeProcessor(); 274 return new SharedChangeProcessor();
295 } 275 }
296 276
297 ACTION_P(MakeAutofillProfileSyncComponents, wds) { 277 ACTION_P(MakeAutofillProfileSyncComponents, wds) {
298 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 278 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
299 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) 279 if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
300 return base::WeakPtr<syncer::SyncableService>();; 280 return base::WeakPtr<syncer::SyncableService>();;
301 return wds->GetAutofillProfileSyncableService()->AsWeakPtr(); 281 return AutofillProfileSyncableService::FromWebData(wds)->AsWeakPtr();
302 } 282 }
303 283
304 class AbstractAutofillFactory { 284 class AbstractAutofillFactory {
305 public: 285 public:
306 virtual DataTypeController* CreateDataTypeController( 286 virtual DataTypeController* CreateDataTypeController(
307 ProfileSyncComponentsFactory* factory, 287 ProfileSyncComponentsFactory* factory,
308 ProfileMock* profile, 288 ProfileMock* profile,
309 ProfileSyncService* service) = 0; 289 ProfileSyncService* service) = 0;
310 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 290 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
311 ProfileSyncService* service, 291 ProfileSyncService* service,
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 std::vector<AutofillEntry> sync_entries; 1317 std::vector<AutofillEntry> sync_entries;
1338 std::vector<AutofillProfile> sync_profiles; 1318 std::vector<AutofillProfile> sync_profiles;
1339 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1319 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1340 EXPECT_EQ(3U, sync_entries.size()); 1320 EXPECT_EQ(3U, sync_entries.size());
1341 EXPECT_EQ(0U, sync_profiles.size()); 1321 EXPECT_EQ(0U, sync_profiles.size());
1342 for (size_t i = 0; i < sync_entries.size(); i++) { 1322 for (size_t i = 0; i < sync_entries.size(); i++) {
1343 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1323 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1344 << ", " << sync_entries[i].key().value(); 1324 << ", " << sync_entries[i].key().value();
1345 } 1325 }
1346 } 1326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698