diff options
author | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-26 19:40:21 +0000 |
---|---|---|
committer | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-26 19:40:21 +0000 |
commit | 38a5d30fe85cdfcbe6665b5c016a666b23cb0a68 (patch) | |
tree | 893522ceb4247673728ce272e25004303f27d79d /components | |
parent | 05cad834c79b4d172f527d1592699cb0a6646845 (diff) | |
download | chromium_src-38a5d30fe85cdfcbe6665b5c016a666b23cb0a68.zip chromium_src-38a5d30fe85cdfcbe6665b5c016a666b23cb0a68.tar.gz chromium_src-38a5d30fe85cdfcbe6665b5c016a666b23cb0a68.tar.bz2 |
Do not suggest invalid address in interactive autocomplete
If a user saved an invalid address in chrome://settings/autofillEditAddress,
then interactive autocomplete should not suggest it as one of the shipping
or billing options. Also, it should not suggest an email associated with an
invalid address.
TEST=AutofillDialogControllerTest.SuggestValidAddress
TEST=AutofillDialogControllerTest.DoNotSuggestInvalidAddress
TEST=AutofillDialogControllerTest.DoNotSuggestEmailFromIncompleteProfile
TEST=AutofillDialogControllerTest.DoNotSuggestEmailFromInvalidProfile
BUG=247205
Review URL: https://chromiumcodereview.appspot.com/17151009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
4 files changed, 66 insertions, 7 deletions
diff --git a/components/autofill/core/browser/autofill_profile.cc b/components/autofill/core/browser/autofill_profile.cc index aa57b28..54a0d24 100644 --- a/components/autofill/core/browser/autofill_profile.cc +++ b/components/autofill/core/browser/autofill_profile.cc @@ -22,6 +22,7 @@ #include "components/autofill/core/browser/contact_info.h" #include "components/autofill/core/browser/phone_number.h" #include "components/autofill/core/browser/phone_number_i18n.h" +#include "components/autofill/core/browser/validation.h" #include "components/autofill/core/common/form_field_data.h" #include "grit/component_strings.h" #include "ui/base/l10n/l10n_util.h" @@ -415,6 +416,35 @@ bool AutofillProfile::IsEmpty(const std::string& app_locale) const { return types.empty(); } +bool AutofillProfile::IsPresentButInvalid(AutofillFieldType type) const { + std::string country = UTF16ToUTF8(GetRawInfo(ADDRESS_HOME_COUNTRY)); + base::string16 data = GetRawInfo(type); + switch (type) { + case ADDRESS_HOME_STATE: + if (!data.empty() && country == "US" && !autofill::IsValidState(data)) + return true; + break; + + case ADDRESS_HOME_ZIP: + if (!data.empty() && country == "US" && !autofill::IsValidZip(data)) + return true; + break; + + case PHONE_HOME_WHOLE_NUMBER: { + if (!data.empty() && !i18n::PhoneObject(data, country).IsValidNumber()) + return true; + break; + } + + default: + NOTREACHED(); + break; + } + + return false; +} + + int AutofillProfile::Compare(const AutofillProfile& profile) const { const AutofillFieldType single_value_types[] = { COMPANY_NAME, ADDRESS_HOME_LINE1, diff --git a/components/autofill/core/browser/autofill_profile.h b/components/autofill/core/browser/autofill_profile.h index c01b0f1..49a488f 100644 --- a/components/autofill/core/browser/autofill_profile.h +++ b/components/autofill/core/browser/autofill_profile.h @@ -85,6 +85,10 @@ class AutofillProfile : public AutofillDataModel { // Returns true if there are no values (field types) set. bool IsEmpty(const std::string& app_locale) const; + // Returns true if the |type| of data in this profile is present, but invalid. + // Otherwise returns false. + bool IsPresentButInvalid(AutofillFieldType type) const; + // Comparison for Sync. Returns 0 if the profile is the same as |this|, // or < 0, or > 0 if it is different. The implied ordering can be used for // culling duplicates. The ordering is based on collation order of the diff --git a/components/autofill/core/browser/autofill_profile_unittest.cc b/components/autofill/core/browser/autofill_profile_unittest.cc index f419e4f..1b7cfc7 100644 --- a/components/autofill/core/browser/autofill_profile_unittest.cc +++ b/components/autofill/core/browser/autofill_profile_unittest.cc @@ -895,4 +895,34 @@ TEST(AutofillProfileTest, FillByContents) { EXPECT_EQ(ASCIIToUTF16("2"), field.value); } +TEST(AutofillProfileTest, IsPresentButInvalid) { + AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); + EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_STATE)); + EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)); + EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); + + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); + EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_STATE)); + EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)); + EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); + + profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C")); + EXPECT_TRUE(profile.IsPresentButInvalid(ADDRESS_HOME_STATE)); + + profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); + EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_STATE)); + + profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90")); + EXPECT_TRUE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)); + + profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("90210")); + EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)); + + profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("310")); + EXPECT_TRUE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); + + profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("(310) 310-6000")); + EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); +} + } // namespace autofill diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc index f8eb6c1..b3ea877 100644 --- a/components/autofill/core/browser/personal_data_manager.cc +++ b/components/autofill/core/browser/personal_data_manager.cc @@ -708,16 +708,11 @@ bool PersonalDataManager::IsValidLearnableProfile( return false; // Reject profiles with invalid US state information. - base::string16 state = profile.GetRawInfo(ADDRESS_HOME_STATE); - if (profile.GetRawInfo(ADDRESS_HOME_COUNTRY) == ASCIIToUTF16("US") && - !state.empty() && !IsValidState(state)) { + if (profile.IsPresentButInvalid(ADDRESS_HOME_STATE)) return false; - } // Reject profiles with invalid US zip information. - base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); - if (profile.GetRawInfo(ADDRESS_HOME_COUNTRY) == ASCIIToUTF16("US") && - !zip.empty() && !autofill::IsValidZip(zip)) + if (profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)) return false; return true; |