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

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

Issue 666733003: Standardize usage of virtual/override/final in chrome/browser/sync/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 class MockAutofillBackend : public autofill::AutofillWebDataBackend { 158 class MockAutofillBackend : public autofill::AutofillWebDataBackend {
159 public: 159 public:
160 MockAutofillBackend( 160 MockAutofillBackend(
161 WebDatabase* web_database, 161 WebDatabase* web_database,
162 const base::Closure& on_changed) 162 const base::Closure& on_changed)
163 : web_database_(web_database), 163 : web_database_(web_database),
164 on_changed_(on_changed) { 164 on_changed_(on_changed) {
165 } 165 }
166 166
167 virtual ~MockAutofillBackend() {} 167 ~MockAutofillBackend() override {}
168 virtual WebDatabase* GetDatabase() override { return web_database_; } 168 WebDatabase* GetDatabase() override { return web_database_; }
169 virtual void AddObserver( 169 void AddObserver(
170 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} 170 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {}
171 virtual void RemoveObserver( 171 void RemoveObserver(
172 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} 172 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {}
173 virtual void RemoveExpiredFormElements() override {} 173 void RemoveExpiredFormElements() override {}
174 virtual void NotifyOfMultipleAutofillChanges() override { 174 void NotifyOfMultipleAutofillChanges() override {
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
176 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_changed_); 176 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_changed_);
177 } 177 }
178 178
179 private: 179 private:
180 WebDatabase* web_database_; 180 WebDatabase* web_database_;
181 base::Closure on_changed_; 181 base::Closure on_changed_;
182 }; 182 };
183 183
184 class ProfileSyncServiceAutofillTest; 184 class ProfileSyncServiceAutofillTest;
(...skipping 14 matching lines...) Expand all
199 } 199 }
200 200
201 class TokenWebDataServiceFake : public TokenWebData { 201 class TokenWebDataServiceFake : public TokenWebData {
202 public: 202 public:
203 TokenWebDataServiceFake() 203 TokenWebDataServiceFake()
204 : TokenWebData( 204 : TokenWebData(
205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
206 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)) { 206 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)) {
207 } 207 }
208 208
209 virtual bool IsDatabaseLoaded() override { 209 bool IsDatabaseLoaded() override { return true; }
210 return true;
211 }
212 210
213 virtual AutofillWebDataService::Handle GetAllTokens( 211 AutofillWebDataService::Handle GetAllTokens(
214 WebDataServiceConsumer* consumer) override { 212 WebDataServiceConsumer* consumer) override {
215 // TODO(tim): It would be nice if WebDataService was injected on 213 // TODO(tim): It would be nice if WebDataService was injected on
216 // construction of ProfileOAuth2TokenService rather than fetched by 214 // construction of ProfileOAuth2TokenService rather than fetched by
217 // Initialize so that this isn't necessary (we could pass a NULL service). 215 // Initialize so that this isn't necessary (we could pass a NULL service).
218 // We currently do return it via EXPECT_CALLs, but without depending on 216 // We currently do return it via EXPECT_CALLs, but without depending on
219 // order-of-initialization (which seems way more fragile) we can't tell 217 // order-of-initialization (which seems way more fragile) we can't tell
220 // which component is asking at what time, and some components in these 218 // which component is asking at what time, and some components in these
221 // Autofill tests require a WebDataService. 219 // Autofill tests require a WebDataService.
222 return 0; 220 return 0;
223 } 221 }
224 222
225 private: 223 private:
226 virtual ~TokenWebDataServiceFake() {} 224 ~TokenWebDataServiceFake() override {}
227 225
228 DISALLOW_COPY_AND_ASSIGN(TokenWebDataServiceFake); 226 DISALLOW_COPY_AND_ASSIGN(TokenWebDataServiceFake);
229 }; 227 };
230 228
231 class WebDataServiceFake : public AutofillWebDataService { 229 class WebDataServiceFake : public AutofillWebDataService {
232 public: 230 public:
233 WebDataServiceFake() 231 WebDataServiceFake()
234 : AutofillWebDataService( 232 : AutofillWebDataService(
235 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 233 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
236 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)), 234 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)),
(...skipping 23 matching lines...) Expand all
260 258
261 void ShutdownSyncableService() { 259 void ShutdownSyncableService() {
262 // The |autofill_profile_syncable_service_| must be destructed on the DB 260 // The |autofill_profile_syncable_service_| must be destructed on the DB
263 // thread. 261 // thread.
264 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 262 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
265 base::Bind(&WebDataServiceFake::DestroySyncableService, 263 base::Bind(&WebDataServiceFake::DestroySyncableService,
266 base::Unretained(this))); 264 base::Unretained(this)));
267 syncable_service_created_or_destroyed_.Wait(); 265 syncable_service_created_or_destroyed_.Wait();
268 } 266 }
269 267
270 virtual bool IsDatabaseLoaded() override { 268 bool IsDatabaseLoaded() override { return true; }
271 return true;
272 }
273 269
274 virtual WebDatabase* GetDatabase() override { 270 WebDatabase* GetDatabase() override { return web_database_; }
275 return web_database_;
276 }
277 271
278 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { 272 void OnAutofillEntriesChanged(const AutofillChangeList& changes) {
279 WaitableEvent event(true, false); 273 WaitableEvent event(true, false);
280 274
281 base::Closure notify_cb = 275 base::Closure notify_cb =
282 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, 276 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged,
283 base::Unretained(autocomplete_syncable_service_), 277 base::Unretained(autocomplete_syncable_service_),
284 changes); 278 changes);
285 BrowserThread::PostTask( 279 BrowserThread::PostTask(
286 BrowserThread::DB, 280 BrowserThread::DB,
(...skipping 10 matching lines...) Expand all
297 base::Unretained(autofill_profile_syncable_service_), 291 base::Unretained(autofill_profile_syncable_service_),
298 changes); 292 changes);
299 BrowserThread::PostTask( 293 BrowserThread::PostTask(
300 BrowserThread::DB, 294 BrowserThread::DB,
301 FROM_HERE, 295 FROM_HERE,
302 base::Bind(&RunAndSignal, notify_cb, &event)); 296 base::Bind(&RunAndSignal, notify_cb, &event));
303 event.Wait(); 297 event.Wait();
304 } 298 }
305 299
306 private: 300 private:
307 virtual ~WebDataServiceFake() {} 301 ~WebDataServiceFake() override {}
308 302
309 void CreateSyncableService(const base::Closure& on_changed_callback) { 303 void CreateSyncableService(const base::Closure& on_changed_callback) {
310 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 304 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
311 // These services are deleted in DestroySyncableService(). 305 // These services are deleted in DestroySyncableService().
312 backend_.reset(new MockAutofillBackend( 306 backend_.reset(new MockAutofillBackend(
313 GetDatabase(), on_changed_callback)); 307 GetDatabase(), on_changed_callback));
314 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( 308 AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
315 this, backend_.get()); 309 this, backend_.get());
316 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( 310 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
317 this, backend_.get(), "en-US"); 311 this, backend_.get(), "en-US");
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ProfileSyncService* service) = 0; 374 ProfileSyncService* service) = 0;
381 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 375 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
382 ProfileSyncService* service, 376 ProfileSyncService* service,
383 AutofillWebDataService* wds, 377 AutofillWebDataService* wds,
384 DataTypeController* dtc) = 0; 378 DataTypeController* dtc) = 0;
385 virtual ~AbstractAutofillFactory() {} 379 virtual ~AbstractAutofillFactory() {}
386 }; 380 };
387 381
388 class AutofillEntryFactory : public AbstractAutofillFactory { 382 class AutofillEntryFactory : public AbstractAutofillFactory {
389 public: 383 public:
390 virtual DataTypeController* CreateDataTypeController( 384 DataTypeController* CreateDataTypeController(
391 ProfileSyncComponentsFactory* factory, 385 ProfileSyncComponentsFactory* factory,
392 TestingProfile* profile, 386 TestingProfile* profile,
393 ProfileSyncService* service) override { 387 ProfileSyncService* service) override {
394 return new AutofillDataTypeController(factory, profile); 388 return new AutofillDataTypeController(factory, profile);
395 } 389 }
396 390
397 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 391 void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
398 ProfileSyncService* service, 392 ProfileSyncService* service,
399 AutofillWebDataService* wds, 393 AutofillWebDataService* wds,
400 DataTypeController* dtc) override { 394 DataTypeController* dtc) override {
401 EXPECT_CALL(*factory, GetSyncableServiceForType(syncer::AUTOFILL)). 395 EXPECT_CALL(*factory, GetSyncableServiceForType(syncer::AUTOFILL)).
402 WillOnce(MakeAutocompleteSyncComponents(wds)); 396 WillOnce(MakeAutocompleteSyncComponents(wds));
403 } 397 }
404 }; 398 };
405 399
406 class AutofillProfileFactory : public AbstractAutofillFactory { 400 class AutofillProfileFactory : public AbstractAutofillFactory {
407 public: 401 public:
408 virtual DataTypeController* CreateDataTypeController( 402 DataTypeController* CreateDataTypeController(
409 ProfileSyncComponentsFactory* factory, 403 ProfileSyncComponentsFactory* factory,
410 TestingProfile* profile, 404 TestingProfile* profile,
411 ProfileSyncService* service) override { 405 ProfileSyncService* service) override {
412 return new AutofillProfileDataTypeController(factory, profile); 406 return new AutofillProfileDataTypeController(factory, profile);
413 } 407 }
414 408
415 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 409 void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
416 ProfileSyncService* service, 410 ProfileSyncService* service,
417 AutofillWebDataService* wds, 411 AutofillWebDataService* wds,
418 DataTypeController* dtc) override { 412 DataTypeController* dtc) override {
419 EXPECT_CALL(*factory, 413 EXPECT_CALL(*factory,
420 GetSyncableServiceForType(syncer::AUTOFILL_PROFILE)). 414 GetSyncableServiceForType(syncer::AUTOFILL_PROFILE)).
421 WillOnce(MakeAutofillProfileSyncComponents(wds)); 415 WillOnce(MakeAutofillProfileSyncComponents(wds));
422 } 416 }
423 }; 417 };
424 418
425 class MockPersonalDataManager : public PersonalDataManager { 419 class MockPersonalDataManager : public PersonalDataManager {
426 public: 420 public:
427 MockPersonalDataManager() : PersonalDataManager("en-US") {} 421 MockPersonalDataManager() : PersonalDataManager("en-US") {}
428 MOCK_CONST_METHOD0(IsDataLoaded, bool()); 422 MOCK_CONST_METHOD0(IsDataLoaded, bool());
429 MOCK_METHOD0(LoadProfiles, void()); 423 MOCK_METHOD0(LoadProfiles, void());
430 MOCK_METHOD0(LoadCreditCards, void()); 424 MOCK_METHOD0(LoadCreditCards, void());
431 MOCK_METHOD0(Refresh, void()); 425 MOCK_METHOD0(Refresh, void());
432 426
433 static KeyedService* Build(content::BrowserContext* profile) { 427 static KeyedService* Build(content::BrowserContext* profile) {
434 return new MockPersonalDataManager(); 428 return new MockPersonalDataManager();
435 } 429 }
436 }; 430 };
437 431
438 template <class T> class AddAutofillHelper; 432 template <class T> class AddAutofillHelper;
439 433
440 class ProfileSyncServiceAutofillTest 434 class ProfileSyncServiceAutofillTest
441 : public AbstractProfileSyncServiceTest, 435 : public AbstractProfileSyncServiceTest,
442 public syncer::DataTypeDebugInfoListener { 436 public syncer::DataTypeDebugInfoListener {
443 public: 437 public:
444 // DataTypeDebugInfoListener implementation. 438 // DataTypeDebugInfoListener implementation.
445 virtual void OnDataTypeConfigureComplete( 439 void OnDataTypeConfigureComplete(const std::vector<
446 const std::vector<syncer::DataTypeConfigurationStats>& 440 syncer::DataTypeConfigurationStats>& configuration_stats) override {
447 configuration_stats) override {
448 ASSERT_EQ(1u, configuration_stats.size()); 441 ASSERT_EQ(1u, configuration_stats.size());
449 association_stats_ = configuration_stats[0].association_stats; 442 association_stats_ = configuration_stats[0].association_stats;
450 } 443 }
451 444
452 protected: 445 protected:
453 ProfileSyncServiceAutofillTest() 446 ProfileSyncServiceAutofillTest()
454 : profile_manager_(TestingBrowserProcess::GetGlobal()), 447 : profile_manager_(TestingBrowserProcess::GetGlobal()),
455 debug_ptr_factory_(this) { 448 debug_ptr_factory_(this) {
456 } 449 }
457 virtual ~ProfileSyncServiceAutofillTest() { 450 virtual ~ProfileSyncServiceAutofillTest() {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 // Overload write transaction to use custom NotifyTransactionComplete 766 // Overload write transaction to use custom NotifyTransactionComplete
774 class WriteTransactionTest: public WriteTransaction { 767 class WriteTransactionTest: public WriteTransaction {
775 public: 768 public:
776 WriteTransactionTest(const tracked_objects::Location& from_here, 769 WriteTransactionTest(const tracked_objects::Location& from_here,
777 WriterTag writer, 770 WriterTag writer,
778 syncer::syncable::Directory* directory, 771 syncer::syncable::Directory* directory,
779 scoped_ptr<WaitableEvent>* wait_for_syncapi) 772 scoped_ptr<WaitableEvent>* wait_for_syncapi)
780 : WriteTransaction(from_here, writer, directory), 773 : WriteTransaction(from_here, writer, directory),
781 wait_for_syncapi_(wait_for_syncapi) { } 774 wait_for_syncapi_(wait_for_syncapi) { }
782 775
783 virtual void NotifyTransactionComplete( 776 void NotifyTransactionComplete(syncer::ModelTypeSet types) override {
784 syncer::ModelTypeSet types) override {
785 // This is where we differ. Force a thread change here, giving another 777 // This is where we differ. Force a thread change here, giving another
786 // thread a chance to create a WriteTransaction 778 // thread a chance to create a WriteTransaction
787 (*wait_for_syncapi_)->Wait(); 779 (*wait_for_syncapi_)->Wait();
788 780
789 WriteTransaction::NotifyTransactionComplete(types); 781 WriteTransaction::NotifyTransactionComplete(types);
790 } 782 }
791 783
792 private: 784 private:
793 scoped_ptr<WaitableEvent>* wait_for_syncapi_; 785 scoped_ptr<WaitableEvent>* wait_for_syncapi_;
794 }; 786 };
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 std::vector<AutofillEntry> sync_entries; 1372 std::vector<AutofillEntry> sync_entries;
1381 std::vector<AutofillProfile> sync_profiles; 1373 std::vector<AutofillProfile> sync_profiles;
1382 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1374 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1383 EXPECT_EQ(3U, sync_entries.size()); 1375 EXPECT_EQ(3U, sync_entries.size());
1384 EXPECT_EQ(0U, sync_profiles.size()); 1376 EXPECT_EQ(0U, sync_profiles.size());
1385 for (size_t i = 0; i < sync_entries.size(); i++) { 1377 for (size_t i = 0; i < sync_entries.size(); i++) {
1386 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1378 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1387 << ", " << sync_entries[i].key().value(); 1379 << ", " << sync_entries[i].key().value();
1388 } 1380 }
1389 } 1381 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_bookmark_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698