diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 22:11:12 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 22:11:12 +0000 |
commit | 24086521ed9ed4a23459a80fe75dbfe2d5d04f76 (patch) | |
tree | 84729fd7177cf5d310b311edb86e853d320dceb3 /chrome/browser/autofill | |
parent | 2f0e64ee55903b85df568529d7fe315a5fe4ff08 (diff) | |
download | chromium_src-24086521ed9ed4a23459a80fe75dbfe2d5d04f76.zip chromium_src-24086521ed9ed4a23459a80fe75dbfe2d5d04f76.tar.gz chromium_src-24086521ed9ed4a23459a80fe75dbfe2d5d04f76.tar.bz2 |
AutoFill Empty profiles and credit cards should not be saved
Changes PersonalDataManager to filter out empty profiles and credit card information before saving to the database.
BUG=47742
TEST=PersonalDataManagerTest.SetEmptyProfile, PersonalDataManagerTest.SetEmptyCreditCard
Review URL: http://codereview.chromium.org/2897005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.cc | 23 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager_unittest.cc | 126 |
2 files changed, 136 insertions, 13 deletions
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc index 9e85f88..69ade7b 100644 --- a/chrome/browser/autofill/personal_data_manager.cc +++ b/chrome/browser/autofill/personal_data_manager.cc @@ -27,6 +27,18 @@ const int kMinImportSize = 3; const char kUnlabeled[] = "Unlabeled"; +bool IsEmptyProfile(const AutoFillProfile& profile) { + FieldTypeSet types; + profile.GetAvailableFieldTypes(&types); + return types.empty(); +} + +bool IsEmptyCreditCard(const CreditCard& credit_card) { + FieldTypeSet types; + credit_card.GetAvailableFieldTypes(&types); + return types.empty() && credit_card.billing_address().empty(); +} + } // namespace PersonalDataManager::~PersonalDataManager() { @@ -237,6 +249,11 @@ void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { if (profile_->IsOffTheRecord()) return; + // Remove empty profiles from input. + profiles->erase( + std::remove_if(profiles->begin(), profiles->end(), IsEmptyProfile), + profiles->end()); + SetUniqueProfileLabels(profiles); WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); @@ -302,6 +319,12 @@ void PersonalDataManager::SetCreditCards( if (profile_->IsOffTheRecord()) return; + // Remove empty credit cards from input. + credit_cards->erase( + std::remove_if( + credit_cards->begin(), credit_cards->end(), IsEmptyCreditCard), + credit_cards->end()); + SetUniqueCreditCardLabels(credit_cards); WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc index c709f09..0dbb566 100644 --- a/chrome/browser/autofill/personal_data_manager_unittest.cc +++ b/chrome/browser/autofill/personal_data_manager_unittest.cc @@ -257,6 +257,94 @@ TEST_F(PersonalDataManagerTest, SetCreditCards) { EXPECT_EQ(creditcard2, *results3.at(1)); } +TEST_F(PersonalDataManagerTest, SetEmptyProfile) { + AutoFillProfile profile0(string16(), 0); + autofill_unittest::SetProfileInfo(&profile0, + "", "", "", "", "", "", "", "", "", "", "", "", "", ""); + + // This will verify that the web database has been loaded and the notification + // sent out. + EXPECT_CALL(personal_data_observer_, + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); + + // The message loop will exit when the mock observer is notified. + MessageLoop::current()->Run(); + + // Add the three test profiles to the database. + std::vector<AutoFillProfile> update; + update.push_back(profile0); + personal_data_->SetProfiles(&update); + + // The PersonalDataManager will update the unique IDs when saving the + // profiles, so we have to update the expectations. + profile0.set_unique_id(update[0].unique_id()); + + // Check the local store of profiles, not yet saved to the web database. + const std::vector<AutoFillProfile*>& results1 = personal_data_->profiles(); + ASSERT_EQ(0U, results1.size()); + + // Reset the PersonalDataManager. This tests that the personal data was saved + // to the web database, and that we can load the profiles from the web + // database. + ResetPersonalDataManager(); + + // This will verify that the web database has been loaded and the notification + // sent out. + EXPECT_CALL(personal_data_observer_, + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); + + // The message loop will exit when the PersonalDataLoadedObserver is notified. + MessageLoop::current()->Run(); + + // Verify that we've loaded the profiles from the web database. + const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); + ASSERT_EQ(0U, results2.size()); +} + +TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { + CreditCard creditcard0(string16(), 0); + autofill_unittest::SetCreditCardInfo(&creditcard0, + "", "", "", "", "", "", ""); + + // This will verify that the web database has been loaded and the notification + // sent out. + EXPECT_CALL(personal_data_observer_, + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); + + // The message loop will exit when the mock observer is notified. + MessageLoop::current()->Run(); + + // Add the empty credit card to the database. + std::vector<CreditCard> update; + update.push_back(creditcard0); + personal_data_->SetCreditCards(&update); + + // The PersonalDataManager will update the unique IDs when saving the + // credit cards, so we have to update the expectations. + creditcard0.set_unique_id(update[0].unique_id()); + + // Check the local store of credit cards, not yet saved to the web database. + const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); + ASSERT_EQ(0U, results1.size()); + + // Reset the PersonalDataManager. This tests that the personal data was saved + // to the web database, and that we can load the credit cards from the web + // database. + ResetPersonalDataManager(); + + // This will verify that the web database has been loaded and the notification + // sent out. + EXPECT_CALL(personal_data_observer_, + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); + + // The message loop will exit when the PersonalDataLoadedObserver is notified. + MessageLoop::current()->Run(); + + // Verify that we've loaded the credit cards from the web database. + const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); + ASSERT_EQ(0U, results2.size()); +} + TEST_F(PersonalDataManagerTest, Refresh) { AutoFillProfile profile0(string16(), 0); autofill_unittest::SetProfileInfo(&profile0, @@ -379,11 +467,17 @@ TEST_F(PersonalDataManagerTest, ImportFormData) { TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) { AutoFillProfile profile0(ASCIIToUTF16("Home"), 0); + profile0.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John")); AutoFillProfile profile1(ASCIIToUTF16("Home"), 0); + profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Paul")); AutoFillProfile profile2(ASCIIToUTF16("Home"), 0); + profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Ringo")); AutoFillProfile profile3(ASCIIToUTF16("NotHome"), 0); + profile3.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Other")); AutoFillProfile profile4(ASCIIToUTF16("Work"), 0); + profile4.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Ozzy")); AutoFillProfile profile5(ASCIIToUTF16("Work"), 0); + profile5.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Dio")); // This will verify that the web database has been loaded and the notification // sent out. @@ -420,12 +514,18 @@ TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) { } TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { - CreditCard profile0(ASCIIToUTF16("Home"), 0); - CreditCard profile1(ASCIIToUTF16("Home"), 0); - CreditCard profile2(ASCIIToUTF16("Home"), 0); - CreditCard profile3(ASCIIToUTF16("NotHome"), 0); - CreditCard profile4(ASCIIToUTF16("Work"), 0); - CreditCard profile5(ASCIIToUTF16("Work"), 0); + CreditCard credit_card0(ASCIIToUTF16("Home"), 0); + credit_card0.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("John")); + CreditCard credit_card1(ASCIIToUTF16("Home"), 0); + credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Paul")); + CreditCard credit_card2(ASCIIToUTF16("Home"), 0); + credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Ringo")); + CreditCard credit_card3(ASCIIToUTF16("NotHome"), 0); + credit_card3.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Other")); + CreditCard credit_card4(ASCIIToUTF16("Work"), 0); + credit_card4.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Ozzy")); + CreditCard credit_card5(ASCIIToUTF16("Work"), 0); + credit_card5.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Dio")); // This will verify that the web database has been loaded and the notification // sent out. @@ -435,14 +535,14 @@ TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { // The message loop will exit when the mock observer is notified. MessageLoop::current()->Run(); - // Add the test profiles to the database. + // Add the test credit cards to the database. std::vector<CreditCard> update; - update.push_back(profile0); - update.push_back(profile1); - update.push_back(profile2); - update.push_back(profile3); - update.push_back(profile4); - update.push_back(profile5); + update.push_back(credit_card0); + update.push_back(credit_card1); + update.push_back(credit_card2); + update.push_back(credit_card3); + update.push_back(credit_card4); + update.push_back(credit_card5); personal_data_->SetCreditCards(&update); const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |