OLD | NEW |
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~MockAutofillBackend() {} |
168 virtual WebDatabase* GetDatabase() OVERRIDE { return web_database_; } | 168 virtual WebDatabase* GetDatabase() override { return web_database_; } |
169 virtual void AddObserver( | 169 virtual void AddObserver( |
170 autofill::AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE {} | 170 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} |
171 virtual void RemoveObserver( | 171 virtual void RemoveObserver( |
172 autofill::AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE {} | 172 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} |
173 virtual void RemoveExpiredFormElements() OVERRIDE {} | 173 virtual void RemoveExpiredFormElements() override {} |
174 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE { | 174 virtual 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 Loading... |
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 virtual bool IsDatabaseLoaded() override { |
210 return true; | 210 return true; |
211 } | 211 } |
212 | 212 |
213 virtual AutofillWebDataService::Handle GetAllTokens( | 213 virtual AutofillWebDataService::Handle GetAllTokens( |
214 WebDataServiceConsumer* consumer) OVERRIDE { | 214 WebDataServiceConsumer* consumer) override { |
215 // TODO(tim): It would be nice if WebDataService was injected on | 215 // TODO(tim): It would be nice if WebDataService was injected on |
216 // construction of ProfileOAuth2TokenService rather than fetched by | 216 // construction of ProfileOAuth2TokenService rather than fetched by |
217 // Initialize so that this isn't necessary (we could pass a NULL service). | 217 // 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 | 218 // 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 | 219 // 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 | 220 // which component is asking at what time, and some components in these |
221 // Autofill tests require a WebDataService. | 221 // Autofill tests require a WebDataService. |
222 return 0; | 222 return 0; |
223 } | 223 } |
224 | 224 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 void ShutdownSyncableService() { | 261 void ShutdownSyncableService() { |
262 // The |autofill_profile_syncable_service_| must be destructed on the DB | 262 // The |autofill_profile_syncable_service_| must be destructed on the DB |
263 // thread. | 263 // thread. |
264 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 264 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
265 base::Bind(&WebDataServiceFake::DestroySyncableService, | 265 base::Bind(&WebDataServiceFake::DestroySyncableService, |
266 base::Unretained(this))); | 266 base::Unretained(this))); |
267 syncable_service_created_or_destroyed_.Wait(); | 267 syncable_service_created_or_destroyed_.Wait(); |
268 } | 268 } |
269 | 269 |
270 virtual bool IsDatabaseLoaded() OVERRIDE { | 270 virtual bool IsDatabaseLoaded() override { |
271 return true; | 271 return true; |
272 } | 272 } |
273 | 273 |
274 virtual WebDatabase* GetDatabase() OVERRIDE { | 274 virtual WebDatabase* GetDatabase() override { |
275 return web_database_; | 275 return web_database_; |
276 } | 276 } |
277 | 277 |
278 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { | 278 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { |
279 WaitableEvent event(true, false); | 279 WaitableEvent event(true, false); |
280 | 280 |
281 base::Closure notify_cb = | 281 base::Closure notify_cb = |
282 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, | 282 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, |
283 base::Unretained(autocomplete_syncable_service_), | 283 base::Unretained(autocomplete_syncable_service_), |
284 changes); | 284 changes); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 AutofillWebDataService* wds, | 383 AutofillWebDataService* wds, |
384 DataTypeController* dtc) = 0; | 384 DataTypeController* dtc) = 0; |
385 virtual ~AbstractAutofillFactory() {} | 385 virtual ~AbstractAutofillFactory() {} |
386 }; | 386 }; |
387 | 387 |
388 class AutofillEntryFactory : public AbstractAutofillFactory { | 388 class AutofillEntryFactory : public AbstractAutofillFactory { |
389 public: | 389 public: |
390 virtual DataTypeController* CreateDataTypeController( | 390 virtual DataTypeController* CreateDataTypeController( |
391 ProfileSyncComponentsFactory* factory, | 391 ProfileSyncComponentsFactory* factory, |
392 TestingProfile* profile, | 392 TestingProfile* profile, |
393 ProfileSyncService* service) OVERRIDE { | 393 ProfileSyncService* service) override { |
394 return new AutofillDataTypeController(factory, profile); | 394 return new AutofillDataTypeController(factory, profile); |
395 } | 395 } |
396 | 396 |
397 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, | 397 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, |
398 ProfileSyncService* service, | 398 ProfileSyncService* service, |
399 AutofillWebDataService* wds, | 399 AutofillWebDataService* wds, |
400 DataTypeController* dtc) OVERRIDE { | 400 DataTypeController* dtc) override { |
401 EXPECT_CALL(*factory, GetSyncableServiceForType(syncer::AUTOFILL)). | 401 EXPECT_CALL(*factory, GetSyncableServiceForType(syncer::AUTOFILL)). |
402 WillOnce(MakeAutocompleteSyncComponents(wds)); | 402 WillOnce(MakeAutocompleteSyncComponents(wds)); |
403 } | 403 } |
404 }; | 404 }; |
405 | 405 |
406 class AutofillProfileFactory : public AbstractAutofillFactory { | 406 class AutofillProfileFactory : public AbstractAutofillFactory { |
407 public: | 407 public: |
408 virtual DataTypeController* CreateDataTypeController( | 408 virtual DataTypeController* CreateDataTypeController( |
409 ProfileSyncComponentsFactory* factory, | 409 ProfileSyncComponentsFactory* factory, |
410 TestingProfile* profile, | 410 TestingProfile* profile, |
411 ProfileSyncService* service) OVERRIDE { | 411 ProfileSyncService* service) override { |
412 return new AutofillProfileDataTypeController(factory, profile); | 412 return new AutofillProfileDataTypeController(factory, profile); |
413 } | 413 } |
414 | 414 |
415 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, | 415 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, |
416 ProfileSyncService* service, | 416 ProfileSyncService* service, |
417 AutofillWebDataService* wds, | 417 AutofillWebDataService* wds, |
418 DataTypeController* dtc) OVERRIDE { | 418 DataTypeController* dtc) override { |
419 EXPECT_CALL(*factory, | 419 EXPECT_CALL(*factory, |
420 GetSyncableServiceForType(syncer::AUTOFILL_PROFILE)). | 420 GetSyncableServiceForType(syncer::AUTOFILL_PROFILE)). |
421 WillOnce(MakeAutofillProfileSyncComponents(wds)); | 421 WillOnce(MakeAutofillProfileSyncComponents(wds)); |
422 } | 422 } |
423 }; | 423 }; |
424 | 424 |
425 class MockPersonalDataManager : public PersonalDataManager { | 425 class MockPersonalDataManager : public PersonalDataManager { |
426 public: | 426 public: |
427 MockPersonalDataManager() : PersonalDataManager("en-US") {} | 427 MockPersonalDataManager() : PersonalDataManager("en-US") {} |
428 MOCK_CONST_METHOD0(IsDataLoaded, bool()); | 428 MOCK_CONST_METHOD0(IsDataLoaded, bool()); |
429 MOCK_METHOD0(LoadProfiles, void()); | 429 MOCK_METHOD0(LoadProfiles, void()); |
430 MOCK_METHOD0(LoadCreditCards, void()); | 430 MOCK_METHOD0(LoadCreditCards, void()); |
431 MOCK_METHOD0(Refresh, void()); | 431 MOCK_METHOD0(Refresh, void()); |
432 | 432 |
433 static KeyedService* Build(content::BrowserContext* profile) { | 433 static KeyedService* Build(content::BrowserContext* profile) { |
434 return new MockPersonalDataManager(); | 434 return new MockPersonalDataManager(); |
435 } | 435 } |
436 }; | 436 }; |
437 | 437 |
438 template <class T> class AddAutofillHelper; | 438 template <class T> class AddAutofillHelper; |
439 | 439 |
440 class ProfileSyncServiceAutofillTest | 440 class ProfileSyncServiceAutofillTest |
441 : public AbstractProfileSyncServiceTest, | 441 : public AbstractProfileSyncServiceTest, |
442 public syncer::DataTypeDebugInfoListener { | 442 public syncer::DataTypeDebugInfoListener { |
443 public: | 443 public: |
444 // DataTypeDebugInfoListener implementation. | 444 // DataTypeDebugInfoListener implementation. |
445 virtual void OnDataTypeConfigureComplete( | 445 virtual void OnDataTypeConfigureComplete( |
446 const std::vector<syncer::DataTypeConfigurationStats>& | 446 const std::vector<syncer::DataTypeConfigurationStats>& |
447 configuration_stats) OVERRIDE { | 447 configuration_stats) override { |
448 ASSERT_EQ(1u, configuration_stats.size()); | 448 ASSERT_EQ(1u, configuration_stats.size()); |
449 association_stats_ = configuration_stats[0].association_stats; | 449 association_stats_ = configuration_stats[0].association_stats; |
450 } | 450 } |
451 | 451 |
452 protected: | 452 protected: |
453 ProfileSyncServiceAutofillTest() | 453 ProfileSyncServiceAutofillTest() |
454 : profile_manager_(TestingBrowserProcess::GetGlobal()), | 454 : profile_manager_(TestingBrowserProcess::GetGlobal()), |
455 debug_ptr_factory_(this) { | 455 debug_ptr_factory_(this) { |
456 } | 456 } |
457 virtual ~ProfileSyncServiceAutofillTest() { | 457 virtual ~ProfileSyncServiceAutofillTest() { |
458 } | 458 } |
459 | 459 |
460 AutofillProfileFactory profile_factory_; | 460 AutofillProfileFactory profile_factory_; |
461 AutofillEntryFactory entry_factory_; | 461 AutofillEntryFactory entry_factory_; |
462 | 462 |
463 AbstractAutofillFactory* GetFactory(syncer::ModelType type) { | 463 AbstractAutofillFactory* GetFactory(syncer::ModelType type) { |
464 if (type == syncer::AUTOFILL) { | 464 if (type == syncer::AUTOFILL) { |
465 return &entry_factory_; | 465 return &entry_factory_; |
466 } else if (type == syncer::AUTOFILL_PROFILE) { | 466 } else if (type == syncer::AUTOFILL_PROFILE) { |
467 return &profile_factory_; | 467 return &profile_factory_; |
468 } else { | 468 } else { |
469 NOTREACHED(); | 469 NOTREACHED(); |
470 return NULL; | 470 return NULL; |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 virtual void SetUp() OVERRIDE { | 474 virtual void SetUp() override { |
475 AbstractProfileSyncServiceTest::SetUp(); | 475 AbstractProfileSyncServiceTest::SetUp(); |
476 ASSERT_TRUE(profile_manager_.SetUp()); | 476 ASSERT_TRUE(profile_manager_.SetUp()); |
477 TestingProfile::TestingFactories testing_factories; | 477 TestingProfile::TestingFactories testing_factories; |
478 testing_factories.push_back(std::make_pair( | 478 testing_factories.push_back(std::make_pair( |
479 ProfileOAuth2TokenServiceFactory::GetInstance(), | 479 ProfileOAuth2TokenServiceFactory::GetInstance(), |
480 BuildAutoIssuingFakeProfileOAuth2TokenService)); | 480 BuildAutoIssuingFakeProfileOAuth2TokenService)); |
481 profile_ = profile_manager_.CreateTestingProfile( | 481 profile_ = profile_manager_.CreateTestingProfile( |
482 kTestProfileName, | 482 kTestProfileName, |
483 scoped_ptr<PrefServiceSyncable>(), | 483 scoped_ptr<PrefServiceSyncable>(), |
484 base::UTF8ToUTF16(kTestProfileName), | 484 base::UTF8ToUTF16(kTestProfileName), |
(...skipping 25 matching lines...) Expand all Loading... |
510 | 510 |
511 web_data_service_->StartSyncableService(); | 511 web_data_service_->StartSyncableService(); |
512 | 512 |
513 // When UpdateAutofillEntries() is called with an empty list, the return | 513 // When UpdateAutofillEntries() is called with an empty list, the return |
514 // value should be |true|, rather than the default of |false|. | 514 // value should be |true|, rather than the default of |false|. |
515 std::vector<AutofillEntry> empty; | 515 std::vector<AutofillEntry> empty; |
516 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(empty)) | 516 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(empty)) |
517 .WillRepeatedly(Return(true)); | 517 .WillRepeatedly(Return(true)); |
518 } | 518 } |
519 | 519 |
520 virtual void TearDown() OVERRIDE { | 520 virtual void TearDown() override { |
521 // Note: The tear down order is important. | 521 // Note: The tear down order is important. |
522 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); | 522 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); |
523 web_data_service_->ShutdownOnUIThread(); | 523 web_data_service_->ShutdownOnUIThread(); |
524 web_data_service_->ShutdownSyncableService(); | 524 web_data_service_->ShutdownSyncableService(); |
525 web_data_service_ = NULL; | 525 web_data_service_ = NULL; |
526 // To prevent a leak, fully release TestURLRequestContext to ensure its | 526 // To prevent a leak, fully release TestURLRequestContext to ensure its |
527 // destruction on the IO message loop. | 527 // destruction on the IO message loop. |
528 profile_ = NULL; | 528 profile_ = NULL; |
529 profile_manager_.DeleteTestingProfile(kTestProfileName); | 529 profile_manager_.DeleteTestingProfile(kTestProfileName); |
530 AbstractProfileSyncServiceTest::TearDown(); | 530 AbstractProfileSyncServiceTest::TearDown(); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 class WriteTransactionTest: public WriteTransaction { | 774 class WriteTransactionTest: public WriteTransaction { |
775 public: | 775 public: |
776 WriteTransactionTest(const tracked_objects::Location& from_here, | 776 WriteTransactionTest(const tracked_objects::Location& from_here, |
777 WriterTag writer, | 777 WriterTag writer, |
778 syncer::syncable::Directory* directory, | 778 syncer::syncable::Directory* directory, |
779 scoped_ptr<WaitableEvent>* wait_for_syncapi) | 779 scoped_ptr<WaitableEvent>* wait_for_syncapi) |
780 : WriteTransaction(from_here, writer, directory), | 780 : WriteTransaction(from_here, writer, directory), |
781 wait_for_syncapi_(wait_for_syncapi) { } | 781 wait_for_syncapi_(wait_for_syncapi) { } |
782 | 782 |
783 virtual void NotifyTransactionComplete( | 783 virtual void NotifyTransactionComplete( |
784 syncer::ModelTypeSet types) OVERRIDE { | 784 syncer::ModelTypeSet types) override { |
785 // This is where we differ. Force a thread change here, giving another | 785 // This is where we differ. Force a thread change here, giving another |
786 // thread a chance to create a WriteTransaction | 786 // thread a chance to create a WriteTransaction |
787 (*wait_for_syncapi_)->Wait(); | 787 (*wait_for_syncapi_)->Wait(); |
788 | 788 |
789 WriteTransaction::NotifyTransactionComplete(types); | 789 WriteTransaction::NotifyTransactionComplete(types); |
790 } | 790 } |
791 | 791 |
792 private: | 792 private: |
793 scoped_ptr<WaitableEvent>* wait_for_syncapi_; | 793 scoped_ptr<WaitableEvent>* wait_for_syncapi_; |
794 }; | 794 }; |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 std::vector<AutofillEntry> sync_entries; | 1380 std::vector<AutofillEntry> sync_entries; |
1381 std::vector<AutofillProfile> sync_profiles; | 1381 std::vector<AutofillProfile> sync_profiles; |
1382 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1382 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1383 EXPECT_EQ(3U, sync_entries.size()); | 1383 EXPECT_EQ(3U, sync_entries.size()); |
1384 EXPECT_EQ(0U, sync_profiles.size()); | 1384 EXPECT_EQ(0U, sync_profiles.size()); |
1385 for (size_t i = 0; i < sync_entries.size(); i++) { | 1385 for (size_t i = 0; i < sync_entries.size(); i++) { |
1386 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1386 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1387 << ", " << sync_entries[i].key().value(); | 1387 << ", " << sync_entries[i].key().value(); |
1388 } | 1388 } |
1389 } | 1389 } |
OLD | NEW |