diff options
author | Takano.Naoki@gmail.com <Takano.Naoki@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-28 05:17:00 +0000 |
---|---|---|
committer | Takano.Naoki@gmail.com <Takano.Naoki@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-28 05:17:00 +0000 |
commit | 4f551f22a4aca62ad1865d503b20f381bd405ae1 (patch) | |
tree | 37f25148119cdfd44659948d328187fd8bd9a65f | |
parent | 48e747e7e08eecd8fc4c0b04a6e43802d995e3a4 (diff) | |
download | chromium_src-4f551f22a4aca62ad1865d503b20f381bd405ae1.zip chromium_src-4f551f22a4aca62ad1865d503b20f381bd405ae1.tar.gz chromium_src-4f551f22a4aca62ad1865d503b20f381bd405ae1.tar.bz2 |
Added <cc>:3 - <phone>:10 matching pattern for phone field.
To detect 3 country code number and 10 phone number combination, added the matching pattern in phone field.
BUG=76331
TEST=Run 13_register_supershuttle.com.html
Review URL: http://codereview.chromium.org/7239019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90716 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 45 insertions, 3 deletions
diff --git a/chrome/browser/autofill/phone_field.cc b/chrome/browser/autofill/phone_field.cc index 7a064dd..f9fc036 100644 --- a/chrome/browser/autofill/phone_field.cc +++ b/chrome/browser/autofill/phone_field.cc @@ -98,6 +98,10 @@ PhoneField::Parser PhoneField::phone_field_grammars_[] = { { PhoneField::REGEX_AREA, PhoneField::FIELD_AREA_CODE, 0 }, { PhoneField::REGEX_PHONE, PhoneField::FIELD_PHONE, 0 }, { PhoneField::REGEX_SEPARATOR, FIELD_NONE, 0 }, + // Phone: <cc>:3 - <phone>:10 (Ext: <ext>)? + { PhoneField::REGEX_PHONE, PhoneField::FIELD_COUNTRY_CODE, 3 }, + { PhoneField::REGEX_PHONE, PhoneField::FIELD_PHONE, 10 }, + { PhoneField::REGEX_SEPARATOR, FIELD_NONE, 0 }, // Phone: <phone> (Ext: <ext>)? { PhoneField::REGEX_PHONE, PhoneField::FIELD_PHONE, 0 }, { PhoneField::REGEX_SEPARATOR, FIELD_NONE, 0 }, @@ -159,15 +163,21 @@ bool PhoneField::ClassifyField(FieldTypeMap* map) const { number_->GetCountryCodeType(), map); } + + AutofillFieldType field_number_type = number_->GetNumberType(); if (parsed_phone_fields_[FIELD_AREA_CODE] != NULL) { ok = ok && AddClassification(parsed_phone_fields_[FIELD_AREA_CODE], number_->GetCityCodeType(), map); + } else if (parsed_phone_fields_[FIELD_COUNTRY_CODE] != NULL) { + // Only if we can find country code without city code, it means the phone + // number include city code. + field_number_type = number_->GetCityAndNumberType(); } // We tag the prefix as PHONE_HOME_NUMBER, then when filling the form // we fill only the prefix depending on the size of the input field. ok = ok && AddClassification(parsed_phone_fields_[FIELD_PHONE], - number_->GetNumberType(), + field_number_type, map); // We tag the suffix as PHONE_HOME_NUMBER, then when filling the form // we fill only the suffix depending on the size of the input field. diff --git a/chrome/browser/autofill/phone_field.h b/chrome/browser/autofill/phone_field.h index e85182a..947178c 100644 --- a/chrome/browser/autofill/phone_field.h +++ b/chrome/browser/autofill/phone_field.h @@ -44,6 +44,7 @@ class PhoneField : public FormField { FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseOneLineFax); FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseTwoLineFax); FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartFaxNumberPrefixSuffix); + FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, CountryAndCityAndPhoneNumber); PhoneField(); diff --git a/chrome/browser/autofill/phone_field_unittest.cc b/chrome/browser/autofill/phone_field_unittest.cc index c48b4c7..5366426 100644 --- a/chrome/browser/autofill/phone_field_unittest.cc +++ b/chrome/browser/autofill/phone_field_unittest.cc @@ -391,3 +391,34 @@ TEST_F(PhoneFieldTest, ThreePartFaxNumberPrefixSuffix) { field_type_map_.find(ASCIIToUTF16("suffix1")) != field_type_map_.end()); EXPECT_EQ(PHONE_FAX_NUMBER, field_type_map_[ASCIIToUTF16("suffix1")]); } + +TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) { + // Phone in format <country code>:3 - <city and number>:10 + // The |maxlength| is considered, otherwise it's too broad. + list_.push_back( + new AutofillField(webkit_glue::FormField(ASCIIToUTF16("Phone Number"), + ASCIIToUTF16("CountryCode"), + string16(), + ASCIIToUTF16("text"), + 3, + false), + ASCIIToUTF16("country"))); + list_.push_back( + new AutofillField(webkit_glue::FormField(ASCIIToUTF16("Phone Number"), + ASCIIToUTF16("PhoneNumber"), + string16(), + ASCIIToUTF16("text"), + 10, + false), + ASCIIToUTF16("phone"))); + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner, false)); + ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("country")) != field_type_map_.end()); + EXPECT_EQ(PHONE_HOME_COUNTRY_CODE, field_type_map_[ASCIIToUTF16("country")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("phone")) != field_type_map_.end()); + EXPECT_EQ(PHONE_HOME_CITY_AND_NUMBER, field_type_map_[ASCIIToUTF16("phone")]); +} diff --git a/chrome/test/data/autofill/heuristics/output/13_register_supershuttle.com.out b/chrome/test/data/autofill/heuristics/output/13_register_supershuttle.com.out index e32e8cb..b2492c1 100644 --- a/chrome/test/data/autofill/heuristics/output/13_register_supershuttle.com.out +++ b/chrome/test/data/autofill/heuristics/output/13_register_supershuttle.com.out @@ -3,5 +3,5 @@ EMAIL_ADDRESS NAME_FIRST NAME_LAST PHONE_HOME_WHOLE_NUMBER -PHONE_HOME_WHOLE_NUMBER -PHONE_HOME_WHOLE_NUMBER +PHONE_HOME_COUNTRY_CODE +PHONE_HOME_CITY_AND_NUMBER |