summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-05 03:52:18 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-05 03:52:18 +0000
commit0b5847613b590cfd093ab20ecbb2d87d11d4674c (patch)
tree8a10c39a0ed1df17e7146563798d71f588ef6e41
parent6e34d720634708776fdba6deaa68a1a1133c21e2 (diff)
downloadchromium_src-0b5847613b590cfd093ab20ecbb2d87d11d4674c.zip
chromium_src-0b5847613b590cfd093ab20ecbb2d87d11d4674c.tar.gz
chromium_src-0b5847613b590cfd093ab20ecbb2d87d11d4674c.tar.bz2
[Mac] Autofill: Avoid aggregating duplicates of AddressBook profiles
BUG=98969 TEST=unit_tests --gtest_filter=PersonalDataManagerTest.AggregateExistingAuxiliaryProfile Review URL: http://codereview.chromium.org/8139018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104058 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_profile.cc20
-rw-r--r--chrome/browser/autofill/personal_data_manager.h2
-rw-r--r--chrome/browser/autofill/personal_data_manager_unittest.cc58
3 files changed, 78 insertions, 2 deletions
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc
index f456d7c..5f9ac5e 100644
--- a/chrome/browser/autofill/autofill_profile.cc
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -529,9 +529,25 @@ bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile) const {
for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end();
++iter) {
- if (StringToLowerASCII(GetInfo(*iter)) !=
- StringToLowerASCII(profile.GetInfo(*iter)))
+ if (*iter == NAME_FULL) {
+ // Ignore the compound "full name" field type. We are only interested in
+ // comparing the constituent parts. For example, if |this| has a middle
+ // name saved, but |profile| lacks one, |profile| could still be a subset
+ // of |this|.
+ continue;
+ } else if (AutofillType(*iter).group() == AutofillType::PHONE_HOME) {
+ // Phone numbers should be canonicalized prior to being compared.
+ if (*iter != PHONE_HOME_WHOLE_NUMBER) {
+ continue;
+ } else if (!autofill_i18n::PhoneNumbersMatch(GetInfo(*iter),
+ profile.GetInfo(*iter),
+ CountryCode())) {
+ return false;
+ }
+ } else if (StringToLowerASCII(GetInfo(*iter)) !=
+ StringToLowerASCII(profile.GetInfo(*iter))) {
return false;
+ }
}
return true;
diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h
index 7878669..d812d87 100644
--- a/chrome/browser/autofill/personal_data_manager.h
+++ b/chrome/browser/autofill/personal_data_manager.h
@@ -148,6 +148,8 @@ class PersonalDataManager
// PersonalDataManager.
FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FirstMiddleLast);
FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtStartup);
+ FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest,
+ AggregateExistingAuxiliaryProfile);
friend class PersonalDataManagerFactory;
friend class PersonalDataManagerTest;
friend class scoped_ptr<PersonalDataManager>;
diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc
index c98918e..b442d98 100644
--- a/chrome/browser/autofill/personal_data_manager_unittest.cc
+++ b/chrome/browser/autofill/personal_data_manager_unittest.cc
@@ -1184,6 +1184,64 @@ TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) {
ASSERT_EQ(0U, credit_cards.size());
}
+TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) {
+ // Simulate having access to an auxiliary profile.
+ // |auxiliary_profile| will be owned by |personal_data_|.
+ AutofillProfile* auxiliary_profile = new AutofillProfile;
+ autofill_test::SetProfileInfo(auxiliary_profile,
+ "Tester", "Frederick", "McAddressBookTesterson",
+ "tester@example.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco",
+ "CA", "94102", "USA", "1.415.888.9999");
+ ScopedVector<AutofillProfile>& auxiliary_profiles =
+ personal_data_->auxiliary_profiles_;
+ auxiliary_profiles.push_back(auxiliary_profile);
+
+ // Simulate a form submission with a subset of the info.
+ // Note that the phone number format is different from the saved format.
+ FormData form;
+ webkit_glue::FormField field;
+ autofill_test::CreateTestFormField(
+ "First name:", "first_name", "Tester", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Last name:", "last_name", "McAddressBookTesterson", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Email:", "email", "tester@example.com", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Address:", "address1", "1 Main", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "City:", "city", "San Francisco", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "State:", "state", "CA", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Zip:", "zip", "94102", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Phone:", "phone", "4158889999", "text", &field);
+ form.fields.push_back(field);
+
+ FormStructure form_structure(form);
+ form_structure.DetermineHeuristicTypes();
+ const CreditCard* imported_credit_card;
+ EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
+ &imported_credit_card));
+ EXPECT_FALSE(imported_credit_card);
+
+ // Note: No refresh.
+
+ // Expect no change.
+ const std::vector<AutofillProfile*>& web_profiles =
+ personal_data_->web_profiles();
+ EXPECT_EQ(0U, web_profiles.size());
+ ASSERT_EQ(1U, auxiliary_profiles.size());
+ EXPECT_EQ(0, auxiliary_profile->Compare(*auxiliary_profiles[0]));
+}
+
TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) {
FormData form1;