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

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

Powered by Google App Engine
This is Rietveld 408576698