summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 20:47:02 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 20:47:02 +0000
commit718b1465c8916ac5b912ee57d6448ff8d772e414 (patch)
tree9a945b87509044d1f294117fce5db59c8089afb8
parentb4df7a890a13b1fcb6433957ead464b0a11bc6bb (diff)
downloadchromium_src-718b1465c8916ac5b912ee57d6448ff8d772e414.zip
chromium_src-718b1465c8916ac5b912ee57d6448ff8d772e414.tar.gz
chromium_src-718b1465c8916ac5b912ee57d6448ff8d772e414.tar.bz2
AutoFill address filling when labels are missing.
When labels are missing but 'name' attributes are set we now fill addresses correctly. BUG=38320 TEST=AddressFieldTest, FormStructureTest, manual testing with cc.html (attached). Review URL: http://codereview.chromium.org/1517019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43755 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/address_field.cc5
-rw-r--r--chrome/browser/autofill/address_field_unittest.cc30
-rw-r--r--chrome/browser/autofill/form_field.cc61
-rw-r--r--chrome/browser/autofill/form_field.h8
4 files changed, 88 insertions, 16 deletions
diff --git a/chrome/browser/autofill/address_field.cc b/chrome/browser/autofill/address_field.cc
index 2c94af8..9567966 100644
--- a/chrome/browser/autofill/address_field.cc
+++ b/chrome/browser/autofill/address_field.cc
@@ -213,10 +213,11 @@ bool AddressField::ParseAddressLines(
pattern = GetEcmlPattern(kEcmlShipToAddress2,
kEcmlBillToAddress2, '|');
} else {
- pattern = ASCIIToUTF16("^$|address|address2|street|street_line2|addr2");
+ pattern = ASCIIToUTF16("address|address2|street|street_line2|addr2");
}
- ParseText(iter, pattern, &address_field->address2_);
+ if (!ParseEmptyText(iter, &address_field->address2_))
+ ParseText(iter, pattern, &address_field->address2_);
return true;
}
diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc
index 322e697..2d98fd0 100644
--- a/chrome/browser/autofill/address_field_unittest.cc
+++ b/chrome/browser/autofill/address_field_unittest.cc
@@ -286,4 +286,34 @@ TEST_F(AddressFieldTest, ParseCountryEcml) {
EXPECT_EQ(ADDRESS_HOME_COUNTRY, field_type_map_[ASCIIToUTF16("country1")]);
}
+TEST_F(AddressFieldTest, ParseTwoLineAddressMissingLabel) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"),
+ ASCIIToUTF16("address"),
+ string16(),
+ ASCIIToUTF16("text")),
+ ASCIIToUTF16("addr1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(string16(),
+ ASCIIToUTF16("bogus"),
+ string16(),
+ ASCIIToUTF16("text")),
+ ASCIIToUTF16("addr2")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(AddressField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
+ EXPECT_EQ(kShippingAddress, field_->FindType());
+ EXPECT_TRUE(field_->IsFullAddress());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
+ EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
+ ASSERT_FALSE(
+ field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end());
+ // The second line of the address should not match if |name| is set but
+ // |label| is empty.
+ EXPECT_NE(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]);
+}
+
} // namespace
diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc
index 93788f9..0c59e40 100644
--- a/chrome/browser/autofill/form_field.cc
+++ b/chrome/browser/autofill/form_field.cc
@@ -47,24 +47,15 @@ class EmailField : public FormField {
bool FormField::Match(AutoFillField* field,
const string16& pattern,
bool match_label_only) {
- WebKit::WebRegularExpression re(WebKit::WebString(pattern),
- WebKit::WebTextCaseInsensitive);
-
if (match_label_only) {
- // TODO(jhawkins): Remove StringToLowerASCII. WebRegularExpression needs to
- // be fixed to take WebTextCaseInsensitive into account.
- if (re.match(WebKit::WebString(StringToLowerASCII(field->label()))) != -1) {
+ if (MatchLabel(field, pattern)) {
return true;
}
} else {
// For now, we apply the same pattern to the field's label and the field's
// name. Matching the name is a bit of a long shot for many patterns, but
// it generally doesn't hurt to try.
- //
- // TODO(jhawkins): Remove StringToLowerASCII. WebRegularExpression needs to
- // be fixed to take WebTextCaseInsensitive into account.
- if (re.match(WebKit::WebString(StringToLowerASCII(field->label()))) != -1 ||
- re.match(WebKit::WebString(StringToLowerASCII(field->name()))) != -1) {
+ if (MatchLabel(field, pattern) || MatchName(field, pattern)) {
return true;
}
}
@@ -73,6 +64,28 @@ bool FormField::Match(AutoFillField* field,
}
// static
+bool FormField::MatchName(AutoFillField* field, const string16& pattern) {
+ // TODO(jhawkins): Remove StringToLowerASCII. WebRegularExpression needs to
+ // be fixed to take WebTextCaseInsensitive into account.
+ WebKit::WebRegularExpression re(WebKit::WebString(pattern),
+ WebKit::WebTextCaseInsensitive);
+ bool match = re.match(
+ WebKit::WebString(StringToLowerASCII(field->name()))) != -1;
+ return match;
+}
+
+// static
+bool FormField::MatchLabel(AutoFillField* field, const string16& pattern) {
+ // TODO(jhawkins): Remove StringToLowerASCII. WebRegularExpression needs to
+ // be fixed to take WebTextCaseInsensitive into account.
+ WebKit::WebRegularExpression re(WebKit::WebString(pattern),
+ WebKit::WebTextCaseInsensitive);
+ bool match = re.match(
+ WebKit::WebString(StringToLowerASCII(field->label()))) != -1;
+ return match;
+}
+
+// static
FormField* FormField::ParseFormField(
std::vector<AutoFillField*>::const_iterator* iter,
bool is_ecml) {
@@ -113,7 +126,7 @@ bool FormField::ParseText(std::vector<AutoFillField*>::const_iterator* iter,
bool FormField::ParseEmptyText(
std::vector<AutoFillField*>::const_iterator* iter,
AutoFillField** dest) {
- return ParseText(iter, ASCIIToUTF16("^$"), dest, false);
+ return ParseLabelAndName(iter, ASCIIToUTF16("^$"), dest);
}
// static
@@ -134,7 +147,27 @@ bool FormField::ParseText(std::vector<AutoFillField*>::const_iterator* iter,
return false;
if (Match(field, pattern, match_label_only)) {
- *dest = field;
+ if (dest)
+ *dest = field;
+ (*iter)++;
+ return true;
+ }
+
+ return false;
+}
+
+// static
+bool FormField::ParseLabelAndName(
+ std::vector<AutoFillField*>::const_iterator* iter,
+ const string16& pattern,
+ AutoFillField** dest) {
+ AutoFillField* field = **iter;
+ if (!field)
+ return false;
+
+ if (MatchLabel(field, pattern) && MatchName(field, pattern)) {
+ if (dest)
+ *dest = field;
(*iter)++;
return true;
}
@@ -145,7 +178,7 @@ bool FormField::ParseText(std::vector<AutoFillField*>::const_iterator* iter,
// static
bool FormField::ParseEmpty(std::vector<AutoFillField*>::const_iterator* iter) {
// TODO(jhawkins): Handle select fields.
- return ParseText(iter, ASCIIToUTF16("^$"));
+ return ParseLabelAndName(iter, ASCIIToUTF16("^$"), NULL);
}
// static
diff --git a/chrome/browser/autofill/form_field.h b/chrome/browser/autofill/form_field.h
index 1dac100..2e01791 100644
--- a/chrome/browser/autofill/form_field.h
+++ b/chrome/browser/autofill/form_field.h
@@ -140,6 +140,14 @@ class FormField {
const string16& pattern,
AutoFillField** dest,
bool match_label_only);
+
+ // For empty strings we need to test that both label and name are empty.
+ static bool ParseLabelAndName(
+ std::vector<AutoFillField*>::const_iterator* iter,
+ const string16& pattern,
+ AutoFillField** dest);
+ static bool MatchName(AutoFillField* field, const string16& pattern);
+ static bool MatchLabel(AutoFillField* field, const string16& pattern);
};
class FormFieldSet : public std::vector<FormField*> {