Commit f15bb2fd authored by Hui(Andy) Wu's avatar Hui(Andy) Wu Committed by Commit Bot

[Autofill] Increase heuristics' CITY_AND_NUMBER field length expectation.

One of the heristics rules is to capture a case like below:
country-code(max_length=3), number-field(max_length=10).

The first field will be country code and second and will be CITY_AND_NUMBER.

This fails to capture some sites where they expect a longer length, where
they expect people to put more formatting(or they do it for user), like
instead of 5141231234, they expect (514)-123-1234.

An example would be https://shop.lululemon.com/.

This change increase autofill's heuristic expectation of length to 14 for
this case.

Change-Id: I89e08d1fce9c033d3076bc75971e762d8cdf3035
Reviewed-on: https://chromium-review.googlesource.com/804358Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521716}
parent 6e0ab6ae
......@@ -119,7 +119,7 @@ const PhoneField::Parser PhoneField::kPhoneFieldGrammars[] = {
{REGEX_SEPARATOR, FIELD_NONE, 0},
// Phone: <cc>:3 - <phone>:10 (Ext: <ext>)?
{REGEX_PHONE, FIELD_COUNTRY_CODE, 3},
{REGEX_PHONE, FIELD_PHONE, 10},
{REGEX_PHONE, FIELD_PHONE, 14},
{REGEX_SEPARATOR, FIELD_NONE, 0},
// Ext: <ext>
{REGEX_EXTENSION, FIELD_EXTENSION, 0},
......@@ -145,16 +145,15 @@ std::unique_ptr<FormField> PhoneField::Parse(AutofillScanner* scanner) {
// Attempt to parse according to the next grammar.
for (; i < arraysize(kPhoneFieldGrammars) &&
kPhoneFieldGrammars[i].regex != REGEX_SEPARATOR; ++i) {
if (!ParsePhoneField(
scanner,
GetRegExp(kPhoneFieldGrammars[i].regex),
&parsed_fields[kPhoneFieldGrammars[i].phone_part]))
kPhoneFieldGrammars[i].regex != REGEX_SEPARATOR;
++i) {
if (!ParsePhoneField(scanner, GetRegExp(kPhoneFieldGrammars[i].regex),
&parsed_fields[kPhoneFieldGrammars[i].phone_part]))
break;
if (kPhoneFieldGrammars[i].max_size &&
(!parsed_fields[kPhoneFieldGrammars[i].phone_part]->max_length ||
kPhoneFieldGrammars[i].max_size <
parsed_fields[kPhoneFieldGrammars[i].phone_part]->max_length)) {
kPhoneFieldGrammars[i].max_size <
parsed_fields[kPhoneFieldGrammars[i].phone_part]->max_length)) {
break;
}
}
......@@ -201,8 +200,7 @@ std::unique_ptr<FormField> PhoneField::Parse(AutofillScanner* scanner) {
// Now look for an extension.
// The extension is not actually used, so this just eats the field so other
// parsers do not mistaken it for something else.
ParsePhoneField(scanner,
kPhoneExtensionRe,
ParsePhoneField(scanner, kPhoneExtensionRe,
&phone_field->parsed_phone_fields_[FIELD_EXTENSION]);
return std::move(phone_field);
......@@ -290,8 +288,7 @@ std::string PhoneField::GetRegExp(RegexType regex_id) {
bool PhoneField::ParsePhoneField(AutofillScanner* scanner,
const std::string& regex,
AutofillField** field) {
return ParseFieldSpecifics(scanner,
base::UTF8ToUTF16(regex),
return ParseFieldSpecifics(scanner, base::UTF8ToUTF16(regex),
MATCH_DEFAULT | MATCH_TELEPHONE | MATCH_NUMBER,
field);
}
......
......@@ -42,6 +42,8 @@ class PhoneField : public FormField {
FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix);
FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2);
FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, CountryAndCityAndPhoneNumber);
FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest,
CountryAndCityAndPhoneNumberWithLongerMaxLength);
// This is for easy description of the possible parsing paths of the phone
// fields.
......
......@@ -25,9 +25,7 @@ namespace autofill {
namespace {
const char* const kFieldTypes[] = {
"text",
"tel",
"number",
"text", "tel", "number",
};
} // namespace
......@@ -270,4 +268,36 @@ TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) {
}
}
TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumberWithLongerMaxLength) {
// Phone in format <country code>:3 - <city and number>:14
// The |maxlength| is considered, otherwise it's too broad.
FormFieldData field;
for (const char* field_type : kFieldTypes) {
Clear();
field.form_control_type = field_type;
field.label = ASCIIToUTF16("Phone Number");
field.name = ASCIIToUTF16("CountryCode");
field.max_length = 3;
list_.push_back(
std::make_unique<AutofillField>(field, ASCIIToUTF16("country")));
// Verify if websites expect a longer formatted number like:
// (514)-123-1234, autofill is able to classify correctly.
field.label = ASCIIToUTF16("Phone Number");
field.name = ASCIIToUTF16("PhoneNumber");
field.max_length = 14;
list_.push_back(
std::make_unique<AutofillField>(field, ASCIIToUTF16("phone")));
AutofillScanner scanner(list_);
field_ = Parse(&scanner);
ASSERT_NE(nullptr, field_.get());
field_->AddClassifications(&field_candidates_map_);
CheckField("country", PHONE_HOME_COUNTRY_CODE);
CheckField("phone", PHONE_HOME_CITY_AND_NUMBER);
}
}
} // 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