summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 23:09:59 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 23:09:59 +0000
commit81c58a8782d3bfc4ee6cc719348343bba59ce650 (patch)
treeff4ab1ccace8d40990803615b828c43034aad521 /chrome/browser/autofill
parenta187253e60e728614c730b7e568369d1bc1da07a (diff)
downloadchromium_src-81c58a8782d3bfc4ee6cc719348343bba59ce650.zip
chromium_src-81c58a8782d3bfc4ee6cc719348343bba59ce650.tar.gz
chromium_src-81c58a8782d3bfc4ee6cc719348343bba59ce650.tar.bz2
Revert 51903 - 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 TBR=dhollowa@chromium.org Review URL: http://codereview.chromium.org/2904005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51910 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc23
-rw-r--r--chrome/browser/autofill/personal_data_manager_unittest.cc126
2 files changed, 13 insertions, 136 deletions
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index f2d16dd..c138e5c 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -27,18 +27,6 @@ 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() {
@@ -252,11 +240,6 @@ 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);
@@ -322,12 +305,6 @@ 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 0dbb566..c709f09 100644
--- a/chrome/browser/autofill/personal_data_manager_unittest.cc
+++ b/chrome/browser/autofill/personal_data_manager_unittest.cc
@@ -257,94 +257,6 @@ 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,
@@ -467,17 +379,11 @@ 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.
@@ -514,18 +420,12 @@ TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) {
}
TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
- 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"));
+ 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);
// This will verify that the web database has been loaded and the notification
// sent out.
@@ -535,14 +435,14 @@ TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
// The message loop will exit when the mock observer is notified.
MessageLoop::current()->Run();
- // Add the test credit cards to the database.
+ // Add the test profiles to the database.
std::vector<CreditCard> update;
- 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);
+ update.push_back(profile0);
+ update.push_back(profile1);
+ update.push_back(profile2);
+ update.push_back(profile3);
+ update.push_back(profile4);
+ update.push_back(profile5);
personal_data_->SetCreditCards(&update);
const std::vector<CreditCard*>& results = personal_data_->credit_cards();