Commit bc18f3cd authored by sebsg's avatar sebsg Committed by Commit Bot

[Autofill] Add unsupported types for validation.

This handles the types for which autofill won't offer validation, e.g.
Names.

Bug: 748223
Change-Id: I7bbee81d8eebfd843d962cf5eaa446e0f0b6e334
Reviewed-on: https://chromium-review.googlesource.com/598456Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491464}
parent 8f9bfb60
...@@ -720,6 +720,10 @@ void AutofillProfile::RecordAndLogUse() { ...@@ -720,6 +720,10 @@ void AutofillProfile::RecordAndLogUse() {
AutofillProfile::ValidityState AutofillProfile::GetValidityState( AutofillProfile::ValidityState AutofillProfile::GetValidityState(
ServerFieldType type) { ServerFieldType type) {
// Return valid for types that autofill does not validate.
if (!IsValidationSupportedForType(type))
return UNSUPPORTED;
if (!base::ContainsKey(validity_states_, type)) if (!base::ContainsKey(validity_states_, type))
return UNVALIDATED; return UNVALIDATED;
...@@ -728,6 +732,10 @@ AutofillProfile::ValidityState AutofillProfile::GetValidityState( ...@@ -728,6 +732,10 @@ AutofillProfile::ValidityState AutofillProfile::GetValidityState(
void AutofillProfile::SetValidityState(ServerFieldType type, void AutofillProfile::SetValidityState(ServerFieldType type,
ValidityState validity) { ValidityState validity) {
// Do not save validity of unsupported types.
if (!IsValidationSupportedForType(type))
return;
std::map<ServerFieldType, ValidityState>::iterator it = std::map<ServerFieldType, ValidityState>::iterator it =
validity_states_.find(type); validity_states_.find(type);
...@@ -738,6 +746,21 @@ void AutofillProfile::SetValidityState(ServerFieldType type, ...@@ -738,6 +746,21 @@ void AutofillProfile::SetValidityState(ServerFieldType type,
} }
} }
bool AutofillProfile::IsValidationSupportedForType(ServerFieldType type) {
switch (type) {
case ADDRESS_HOME_STATE:
case ADDRESS_HOME_ZIP:
case ADDRESS_HOME_COUNTRY:
case ADDRESS_HOME_CITY:
case ADDRESS_HOME_DEPENDENT_LOCALITY:
case EMAIL_ADDRESS:
case PHONE_HOME_WHOLE_NUMBER:
return true;
default:
return false;
}
}
// static // static
void AutofillProfile::CreateInferredLabelsHelper( void AutofillProfile::CreateInferredLabelsHelper(
const std::vector<AutofillProfile*>& profiles, const std::vector<AutofillProfile*>& profiles,
......
...@@ -49,6 +49,9 @@ class AutofillProfile : public AutofillDataModel { ...@@ -49,6 +49,9 @@ class AutofillProfile : public AutofillDataModel {
// The field is valid. // The field is valid.
VALID, VALID,
// The validation for the field is unsupported.
UNSUPPORTED,
}; };
AutofillProfile(const std::string& guid, const std::string& origin); AutofillProfile(const std::string& guid, const std::string& origin);
...@@ -206,6 +209,9 @@ class AutofillProfile : public AutofillDataModel { ...@@ -206,6 +209,9 @@ class AutofillProfile : public AutofillDataModel {
// Sets the validity state of the specified autofill type. // Sets the validity state of the specified autofill type.
void SetValidityState(ServerFieldType type, ValidityState validity); void SetValidityState(ServerFieldType type, ValidityState validity);
// Returns whether autofill does the validation of the specified |type|.
bool IsValidationSupportedForType(ServerFieldType type);
private: private:
typedef std::vector<const FormGroup*> FormGroupList; typedef std::vector<const FormGroup*> FormGroupList;
......
...@@ -1105,15 +1105,35 @@ TEST(AutofillProfileTest, ValidityStates) { ...@@ -1105,15 +1105,35 @@ TEST(AutofillProfileTest, ValidityStates) {
// The default validity state should be UNVALIDATED. // The default validity state should be UNVALIDATED.
EXPECT_EQ(AutofillProfile::UNVALIDATED, EXPECT_EQ(AutofillProfile::UNVALIDATED,
profile.GetValidityState(ADDRESS_HOME_LINE1)); profile.GetValidityState(ADDRESS_HOME_COUNTRY));
// Make sure setting the validity state works. // Make sure setting the validity state works.
profile.SetValidityState(ADDRESS_HOME_LINE1, AutofillProfile::VALID); profile.SetValidityState(ADDRESS_HOME_COUNTRY, AutofillProfile::VALID);
profile.SetValidityState(ADDRESS_HOME_CITY, AutofillProfile::INVALID); profile.SetValidityState(ADDRESS_HOME_CITY, AutofillProfile::INVALID);
EXPECT_EQ(AutofillProfile::VALID, EXPECT_EQ(AutofillProfile::VALID,
profile.GetValidityState(ADDRESS_HOME_LINE1)); profile.GetValidityState(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(AutofillProfile::INVALID, EXPECT_EQ(AutofillProfile::INVALID,
profile.GetValidityState(ADDRESS_HOME_CITY)); profile.GetValidityState(ADDRESS_HOME_CITY));
} }
TEST(AutofillProfileTest, ValidityStates_UnsupportedTypes) {
AutofillProfile profile;
// The validity state of unsupported types should be UNSUPPORTED.
EXPECT_EQ(AutofillProfile::UNSUPPORTED,
profile.GetValidityState(ADDRESS_HOME_LINE1));
// Make sure setting the validity state of an unsupported type does nothing.
profile.SetValidityState(ADDRESS_HOME_LINE1, AutofillProfile::VALID);
profile.SetValidityState(ADDRESS_HOME_LINE2, AutofillProfile::INVALID);
profile.SetValidityState(PHONE_HOME_CITY_AND_NUMBER,
AutofillProfile::UNVALIDATED);
EXPECT_EQ(AutofillProfile::UNSUPPORTED,
profile.GetValidityState(ADDRESS_HOME_LINE1));
EXPECT_EQ(AutofillProfile::UNSUPPORTED,
profile.GetValidityState(ADDRESS_HOME_LINE2));
EXPECT_EQ(AutofillProfile::UNSUPPORTED,
profile.GetValidityState(PHONE_HOME_CITY_AND_NUMBER));
}
} // namespace autofill } // namespace autofill
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment