diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 17:33:55 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 17:33:55 +0000 |
commit | 5f5c76db9f2e1f0597028b17613a47418a92a050 (patch) | |
tree | 5e67d2128ffa556d077be4d807318ac5c97721c0 /chrome/browser/autofill | |
parent | 54faad92c35775369abca4308d7d0326c6b2ec88 (diff) | |
download | chromium_src-5f5c76db9f2e1f0597028b17613a47418a92a050.zip chromium_src-5f5c76db9f2e1f0597028b17613a47418a92a050.tar.gz chromium_src-5f5c76db9f2e1f0597028b17613a47418a92a050.tar.bz2 |
AutoFill: Fix two heuristic issues with nrm.org.
* Parse state before zip, as they may share one label.
* Try to parse the current TD for text when parsing table labels.
BUG=61442
TEST=FormManagerTest.LabelsInferredFromTablTDInterveningElements,
AddressFieldTest.ParseStateAndZipOneLabel
Review URL: http://codereview.chromium.org/4249002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64761 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/address_field.cc | 8 | ||||
-rw-r--r-- | chrome/browser/autofill/address_field.h | 4 | ||||
-rw-r--r-- | chrome/browser/autofill/address_field_unittest.cc | 34 |
3 files changed, 41 insertions, 5 deletions
diff --git a/chrome/browser/autofill/address_field.cc b/chrome/browser/autofill/address_field.cc index 52e5193..41a1a1d 100644 --- a/chrome/browser/autofill/address_field.cc +++ b/chrome/browser/autofill/address_field.cc @@ -91,12 +91,10 @@ AddressField* AddressField::Parse( if (ParseCompany(&q, is_ecml, address_field.get()) || ParseAddressLines(&q, is_ecml, address_field.get()) || ParseCity(&q, is_ecml, address_field.get()) || + ParseState(&q, is_ecml, address_field.get()) || ParseZipCode(&q, is_ecml, address_field.get()) || ParseCountry(&q, is_ecml, address_field.get())) { continue; - } else if ((!address_field->state_ || address_field->state_->IsEmpty()) && - address_field->ParseState(&q, is_ecml, address_field.get())) { - continue; } else if (ParseText(&q, ASCIIToUTF16("attention|attn.")) || ParseText(&q, ASCIIToUTF16("province|region|other"))) { // We ignore the following: @@ -339,9 +337,13 @@ bool AddressField::ParseCity( return true; } +// static bool AddressField::ParseState( std::vector<AutoFillField*>::const_iterator* iter, bool is_ecml, AddressField* address_field) { + if (address_field->state_) + return false; + string16 pattern; if (is_ecml) pattern = GetEcmlPattern(kEcmlShipToStateProv, kEcmlBillToStateProv, '|'); diff --git a/chrome/browser/autofill/address_field.h b/chrome/browser/autofill/address_field.h index 6b93ead..51dd105 100644 --- a/chrome/browser/autofill/address_field.h +++ b/chrome/browser/autofill/address_field.h @@ -44,8 +44,8 @@ class AddressField : public FormField { bool is_ecml, AddressField* address_field); static bool ParseCity(std::vector<AutoFillField*>::const_iterator* iter, bool is_ecml, AddressField* address_field); - bool ParseState(std::vector<AutoFillField*>::const_iterator* iter, - bool is_ecml, AddressField* address_field); + static bool ParseState(std::vector<AutoFillField*>::const_iterator* iter, + bool is_ecml, AddressField* address_field); // Looks for an address type in the given text, which the caller must // convert to lowercase. diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc index 5477b11..51509f7 100644 --- a/chrome/browser/autofill/address_field_unittest.cc +++ b/chrome/browser/autofill/address_field_unittest.cc @@ -344,6 +344,40 @@ TEST_F(AddressFieldTest, ParseZipEcml) { EXPECT_EQ(ADDRESS_HOME_ZIP, field_type_map_[ASCIIToUTF16("zip1")]); } +TEST_F(AddressFieldTest, ParseStateAndZipOneLabel) { + list_.push_back( + new AutoFillField( + webkit_glue::FormField( + ASCIIToUTF16("State/Province, Zip/Postal Code"), + ASCIIToUTF16("state"), + string16(), + ASCIIToUTF16("text"), + 0), + ASCIIToUTF16("state"))); + list_.push_back( + new AutoFillField( + webkit_glue::FormField( + ASCIIToUTF16("State/Province, Zip/Postal Code"), + ASCIIToUTF16("zip"), + string16(), + ASCIIToUTF16("text"), + 0), + ASCIIToUTF16("zip"))); + list_.push_back(NULL); + iter_ = list_.begin(); + field_.reset(AddressField::Parse(&iter_, false)); + ASSERT_NE(static_cast<AddressField*>(NULL), field_.get()); + EXPECT_EQ(kGenericAddress, field_->FindType()); + EXPECT_FALSE(field_->IsFullAddress()); + ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("state")) != field_type_map_.end()); + EXPECT_EQ(ADDRESS_HOME_STATE, field_type_map_[ASCIIToUTF16("state")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("zip")) != field_type_map_.end()); + EXPECT_EQ(ADDRESS_HOME_ZIP, field_type_map_[ASCIIToUTF16("zip")]); +} + TEST_F(AddressFieldTest, ParseCountry) { list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Country"), |