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

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

Issue 16154031: Un-refcount AutofillWebData and TokenWebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on ToT Created 7 years, 6 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 class WebDataServiceFake : public AutofillWebDataService { 219 class WebDataServiceFake : public AutofillWebDataService {
220 public: 220 public:
221 WebDataServiceFake() 221 WebDataServiceFake()
222 : AutofillWebDataService(), 222 : AutofillWebDataService(),
223 web_database_(NULL), 223 web_database_(NULL),
224 autocomplete_syncable_service_(NULL), 224 autocomplete_syncable_service_(NULL),
225 autofill_profile_syncable_service_(NULL), 225 autofill_profile_syncable_service_(NULL),
226 syncable_service_created_or_destroyed_(false, false) { 226 syncable_service_created_or_destroyed_(false, false) {
227 } 227 }
228 228
229 virtual ~WebDataServiceFake() {}
230
229 void SetDatabase(WebDatabase* web_database) { 231 void SetDatabase(WebDatabase* web_database) {
230 web_database_ = web_database; 232 web_database_ = web_database;
231 } 233 }
232 234
233 void StartSyncableService() { 235 void StartSyncableService() {
234 // The |autofill_profile_syncable_service_| must be constructed on the DB 236 // The |autofill_profile_syncable_service_| must be constructed on the DB
235 // thread. 237 // thread.
236 const base::Closure& on_changed_callback = base::Bind( 238 const base::Closure& on_changed_callback = base::Bind(
237 &WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread, 239 &WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread,
238 AsWeakPtr()); 240 AsWeakPtr());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 base::Unretained(autofill_profile_syncable_service_), 285 base::Unretained(autofill_profile_syncable_service_),
284 changes); 286 changes);
285 BrowserThread::PostTask( 287 BrowserThread::PostTask(
286 BrowserThread::DB, 288 BrowserThread::DB,
287 FROM_HERE, 289 FROM_HERE,
288 base::Bind(&RunAndSignal, notify_cb, &event)); 290 base::Bind(&RunAndSignal, notify_cb, &event));
289 event.Wait(); 291 event.Wait();
290 } 292 }
291 293
292 private: 294 private:
293 virtual ~WebDataServiceFake() {}
294
295 void CreateSyncableService(const base::Closure& on_changed_callback) { 295 void CreateSyncableService(const base::Closure& on_changed_callback) {
296 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 296 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
297 // These services are deleted in DestroySyncableService(). 297 // These services are deleted in DestroySyncableService().
298 backend_.reset(new MockAutofillBackend( 298 backend_.reset(new MockAutofillBackend(
299 GetDatabase(), on_changed_callback)); 299 GetDatabase(), on_changed_callback));
300 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( 300 AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
301 this, backend_.get()); 301 this, backend_.get());
302 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( 302 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
303 this, backend_.get(), "en-US"); 303 this, backend_.get(), "en-US");
304 304
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 virtual void SetUp() OVERRIDE { 504 virtual void SetUp() OVERRIDE {
505 AbstractProfileSyncServiceTest::SetUp(); 505 AbstractProfileSyncServiceTest::SetUp();
506 profile_.reset(new ProfileMock()); 506 profile_.reset(new ProfileMock());
507 profile_->CreateRequestContext(); 507 profile_->CreateRequestContext();
508 web_database_.reset(new WebDatabaseFake(&autofill_table_)); 508 web_database_.reset(new WebDatabaseFake(&autofill_table_));
509 MockWebDataServiceWrapper* wrapper = 509 MockWebDataServiceWrapper* wrapper =
510 static_cast<MockWebDataServiceWrapper*>( 510 static_cast<MockWebDataServiceWrapper*>(
511 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( 511 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse(
512 profile_.get(), BuildMockWebDataServiceWrapper)); 512 profile_.get(), BuildMockWebDataServiceWrapper));
513 web_data_service_ = 513 web_data_service_ =
514 static_cast<WebDataServiceFake*>(wrapper->GetAutofillWebData().get()); 514 static_cast<WebDataServiceFake*>(wrapper->GetAutofillWebData());
515 web_data_service_->SetDatabase(web_database_.get()); 515 web_data_service_->SetDatabase(web_database_.get());
516 516
517 MockPersonalDataManagerService* personal_data_manager_service = 517 MockPersonalDataManagerService* personal_data_manager_service =
518 static_cast<MockPersonalDataManagerService*>( 518 static_cast<MockPersonalDataManagerService*>(
519 autofill::PersonalDataManagerFactory::GetInstance() 519 autofill::PersonalDataManagerFactory::GetInstance()
520 ->SetTestingFactoryAndUse( 520 ->SetTestingFactoryAndUse(
521 profile_.get(), MockPersonalDataManagerService::Build)); 521 profile_.get(), MockPersonalDataManagerService::Build));
522 personal_data_manager_ = 522 personal_data_manager_ =
523 personal_data_manager_service->GetPersonalDataManager(); 523 personal_data_manager_service->GetPersonalDataManager();
524 524
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 sync_service_->set_backend_init_callback(callback); 570 sync_service_->set_backend_init_callback(callback);
571 571
572 ProfileSyncComponentsFactoryMock* components = 572 ProfileSyncComponentsFactoryMock* components =
573 sync_service_->components_factory_mock(); 573 sync_service_->components_factory_mock();
574 DataTypeController* data_type_controller = 574 DataTypeController* data_type_controller =
575 factory->CreateDataTypeController(components, 575 factory->CreateDataTypeController(components,
576 profile_.get(), 576 profile_.get(),
577 sync_service_); 577 sync_service_);
578 factory->SetExpectation(components, 578 factory->SetExpectation(components,
579 sync_service_, 579 sync_service_,
580 web_data_service_.get(), 580 web_data_service_,
581 data_type_controller); 581 data_type_controller);
582 582
583 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _, _)). 583 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _, _)).
584 WillOnce(ReturnNewDataTypeManagerWithDebugListener( 584 WillOnce(ReturnNewDataTypeManagerWithDebugListener(
585 syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr()))); 585 syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr())));
586 586
587 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). 587 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()).
588 WillRepeatedly(Return(true)); 588 WillRepeatedly(Return(true));
589 589
590 // We need tokens to get the tests going 590 // We need tokens to get the tests going
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 return MakeAutofillEntry(name, value, time_shift, -1); 750 return MakeAutofillEntry(name, value, time_shift, -1);
751 } 751 }
752 752
753 friend class AddAutofillHelper<AutofillEntry>; 753 friend class AddAutofillHelper<AutofillEntry>;
754 friend class AddAutofillHelper<AutofillProfile>; 754 friend class AddAutofillHelper<AutofillProfile>;
755 friend class FakeServerUpdater; 755 friend class FakeServerUpdater;
756 756
757 scoped_ptr<ProfileMock> profile_; 757 scoped_ptr<ProfileMock> profile_;
758 AutofillTableMock autofill_table_; 758 AutofillTableMock autofill_table_;
759 scoped_ptr<WebDatabaseFake> web_database_; 759 scoped_ptr<WebDatabaseFake> web_database_;
760 scoped_refptr<WebDataServiceFake> web_data_service_; 760 WebDataServiceFake* web_data_service_;
761 MockPersonalDataManager* personal_data_manager_; 761 MockPersonalDataManager* personal_data_manager_;
762 syncer::DataTypeAssociationStats association_stats_; 762 syncer::DataTypeAssociationStats association_stats_;
763 base::WeakPtrFactory<DataTypeDebugInfoListener> debug_ptr_factory_; 763 base::WeakPtrFactory<DataTypeDebugInfoListener> debug_ptr_factory_;
764 }; 764 };
765 765
766 template <class T> 766 template <class T>
767 class AddAutofillHelper { 767 class AddAutofillHelper {
768 public: 768 public:
769 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, 769 AddAutofillHelper(ProfileSyncServiceAutofillTest* test,
770 const std::vector<T>& entries) 770 const std::vector<T>& entries)
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 928
929 std::set<string16> values_set; 929 std::set<string16> values_set;
930 for (size_t i = 0; i < values1.size(); ++i) 930 for (size_t i = 0; i < values1.size(); ++i)
931 values_set.insert(values1[i]); 931 values_set.insert(values1[i]);
932 for (size_t i = 0; i < values2.size(); ++i) 932 for (size_t i = 0; i < values2.size(); ++i)
933 if (values_set.find(values2[i]) == values_set.end()) 933 if (values_set.find(values2[i]) == values_set.end())
934 return false; 934 return false;
935 return true; 935 return true;
936 } 936 }
937 937
938 }; 938 }; // namespace
939 939
940 // TODO(skrul): Test abort startup. 940 // TODO(skrul): Test abort startup.
941 // TODO(skrul): Test processing of cloud changes. 941 // TODO(skrul): Test processing of cloud changes.
942 // TODO(tim): Add autofill data type controller test, and a case to cover 942 // TODO(tim): Add autofill data type controller test, and a case to cover
943 // waiting for the PersonalDataManager. 943 // waiting for the PersonalDataManager.
944 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { 944 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) {
945 // Don't create the root autofill node so startup fails. 945 // Don't create the root autofill node so startup fails.
946 StartSyncService(base::Closure(), true, syncer::AUTOFILL); 946 StartSyncService(base::Closure(), true, syncer::AUTOFILL);
947 EXPECT_TRUE(sync_service_->HasUnrecoverableError()); 947 EXPECT_TRUE(sync_service_->HasUnrecoverableError());
948 } 948 }
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 std::vector<AutofillEntry> sync_entries; 1402 std::vector<AutofillEntry> sync_entries;
1403 std::vector<AutofillProfile> sync_profiles; 1403 std::vector<AutofillProfile> sync_profiles;
1404 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1404 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1405 EXPECT_EQ(3U, sync_entries.size()); 1405 EXPECT_EQ(3U, sync_entries.size());
1406 EXPECT_EQ(0U, sync_profiles.size()); 1406 EXPECT_EQ(0U, sync_profiles.size());
1407 for (size_t i = 0; i < sync_entries.size(); i++) { 1407 for (size_t i = 0; i < sync_entries.size(); i++) {
1408 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1408 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1409 << ", " << sync_entries[i].key().value(); 1409 << ", " << sync_entries[i].key().value();
1410 } 1410 }
1411 } 1411 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_components_factory_impl.cc ('k') | chrome/browser/sync/test/integration/autofill_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698