summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/address_field_unittest.cc6
-rw-r--r--chrome/browser/autofill/autofill_profile_unittest.cc5
-rw-r--r--chrome/browser/autofill/credit_card_unittest.cc6
-rw-r--r--chrome/browser/autofill/form_field.cc7
-rw-r--r--chrome/browser/autofill/form_field.h5
-rw-r--r--chrome/browser/autofill/form_structure_unittest.cc88
-rw-r--r--chrome/browser/autofill/name_field.cc4
7 files changed, 111 insertions, 10 deletions
diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc
index 5f87684..7f1c368 100644
--- a/chrome/browser/autofill/address_field_unittest.cc
+++ b/chrome/browser/autofill/address_field_unittest.cc
@@ -93,8 +93,8 @@ TEST_F(AddressFieldTest, ParseTwoLineAddress) {
WebKit::WebInputElement::Text),
ASCIIToUTF16("addr1")));
list_.push_back(
- new AutoFillField(webkit_glue::FormField(ASCIIToUTF16(""),
- ASCIIToUTF16(""),
+ new AutoFillField(webkit_glue::FormField(string16(),
+ string16(),
string16(),
ASCIIToUTF16("text"),
WebKit::WebInputElement::Text),
@@ -123,7 +123,7 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressEcml) {
WebKit::WebInputElement::Text),
ASCIIToUTF16("addr1")));
list_.push_back(
- new AutoFillField(webkit_glue::FormField(ASCIIToUTF16(""),
+ new AutoFillField(webkit_glue::FormField(string16(),
kEcmlShipToAddress2,
string16(),
ASCIIToUTF16("text"),
diff --git a/chrome/browser/autofill/autofill_profile_unittest.cc b/chrome/browser/autofill/autofill_profile_unittest.cc
index 3a1e086..f3ead65 100644
--- a/chrome/browser/autofill/autofill_profile_unittest.cc
+++ b/chrome/browser/autofill/autofill_profile_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/basictypes.h"
+#include "base/string16.h"
#include "chrome/browser/autofill/autofill_common_unittest.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,7 +16,7 @@ TEST(AutoFillProfileTest, PreviewSummaryString) {
// Case 0/null: ""
AutoFillProfile profile0(string16(), 0);
string16 summary0 = profile0.PreviewSummary();
- EXPECT_EQ(summary0, string16(ASCIIToUTF16("")));
+ EXPECT_EQ(summary0, string16());
// Case 0/empty: ""
AutoFillProfile profile00(string16(), 0);
@@ -35,7 +36,7 @@ TEST(AutoFillProfileTest, PreviewSummaryString) {
"12345678910",
"01987654321");
string16 summary00 = profile00.PreviewSummary();
- EXPECT_EQ(summary00, string16(ASCIIToUTF16("")));
+ EXPECT_EQ(summary00, string16());
// Case 1: "<address>"
AutoFillProfile profile1(string16(), 0);
diff --git a/chrome/browser/autofill/credit_card_unittest.cc b/chrome/browser/autofill/credit_card_unittest.cc
index 72b2a993..53df1fc 100644
--- a/chrome/browser/autofill/credit_card_unittest.cc
+++ b/chrome/browser/autofill/credit_card_unittest.cc
@@ -16,7 +16,7 @@ TEST(CreditCardTest, PreviewSummaryString) {
// Case 0: empty credit card.
CreditCard credit_card0(string16(), 0);
string16 summary0 = credit_card0.PreviewSummary();
- EXPECT_EQ(summary0, string16(ASCIIToUTF16("")));
+ EXPECT_EQ(summary0, string16());
// Case 00: Empty credit card with empty strings.
CreditCard credit_card00(string16(), 0);
@@ -32,7 +32,7 @@ TEST(CreditCardTest, PreviewSummaryString) {
"Chicago",
"Indianapolis");
string16 summary00 = credit_card00.PreviewSummary();
- EXPECT_EQ(summary00, string16(ASCIIToUTF16("")));
+ EXPECT_EQ(summary00, string16());
// Case 1: No credit card number.
CreditCard credit_card1(string16(), 0);
@@ -48,7 +48,7 @@ TEST(CreditCardTest, PreviewSummaryString) {
"Chicago",
"Indianapolis");
string16 summary1 = credit_card1.PreviewSummary();
- EXPECT_EQ(summary1, string16(ASCIIToUTF16("")));
+ EXPECT_EQ(summary1, string16());
// Case 2: No month.
CreditCard credit_card2(string16(), 0);
diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc
index 85ac648..93788f9 100644
--- a/chrome/browser/autofill/form_field.cc
+++ b/chrome/browser/autofill/form_field.cc
@@ -110,6 +110,13 @@ bool FormField::ParseText(std::vector<AutoFillField*>::const_iterator* iter,
}
// static
+bool FormField::ParseEmptyText(
+ std::vector<AutoFillField*>::const_iterator* iter,
+ AutoFillField** dest) {
+ return ParseText(iter, ASCIIToUTF16("^$"), dest, false);
+}
+
+// static
bool FormField::ParseLabelText(
std::vector<AutoFillField*>::const_iterator* iter,
const string16& pattern,
diff --git a/chrome/browser/autofill/form_field.h b/chrome/browser/autofill/form_field.h
index d702719..1dac100 100644
--- a/chrome/browser/autofill/form_field.h
+++ b/chrome/browser/autofill/form_field.h
@@ -104,6 +104,11 @@ class FormField {
const string16& pattern,
AutoFillField** dest);
+ // Attempts to parse a text field with an empty name or label. Returns true
+ // on success and fills |dest| with a pointer to the field.
+ static bool ParseEmptyText(std::vector<AutoFillField*>::const_iterator* iter,
+ AutoFillField** dest);
+
// Attempts to parse a text field label with the given pattern. Returns true
// on success and fills |dest| with a pointer to the field.
static bool ParseLabelText(std::vector<AutoFillField*>::const_iterator* iter,
diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc
index 6c61a158..1245229 100644
--- a/chrome/browser/autofill/form_structure_unittest.cc
+++ b/chrome/browser/autofill/form_structure_unittest.cc
@@ -167,6 +167,7 @@ TEST(FormStructureTest, Heuristics) {
// Compute heuristic types.
form_structure->GetHeuristicAutoFillTypes();
+ ASSERT_EQ(8U, form_structure->field_count());
// Check that heuristics are no longer UNKNOWN_TYPE.
// First name.
@@ -273,6 +274,7 @@ TEST(FormStructureTest, HeuristicsSample8) {
// Compute heuristic types.
form_structure->GetHeuristicAutoFillTypes();
+ ASSERT_EQ(9U, form_structure->field_count());
// Check that heuristics are no longer UNKNOWN_TYPE.
// First name.
@@ -296,4 +298,90 @@ TEST(FormStructureTest, HeuristicsSample8) {
form_structure->field(8)->heuristic_type());
}
+TEST(FormStructureTest, HeuristicsSample6) {
+ scoped_ptr<FormStructure> form_structure;
+ webkit_glue::FormFieldValues values;
+
+ values.method = ASCIIToUTF16("post");
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("E-mail address"),
+ ASCIIToUTF16("email"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Full name"),
+ ASCIIToUTF16("name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Company"),
+ ASCIIToUTF16("company"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Address"),
+ ASCIIToUTF16("address"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("City"),
+ ASCIIToUTF16("city"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ // TODO(jhawkins): Add state select control.
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Zip Code"),
+ ASCIIToUTF16("Home.PostalCode"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ // TODO(jhawkins): Phone number.
+ values.elements.push_back(
+ webkit_glue::FormField(string16(),
+ ASCIIToUTF16("Submit"),
+ ASCIIToUTF16("continue"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit));
+ form_structure.reset(new FormStructure(values));
+ EXPECT_TRUE(form_structure->IsAutoFillable());
+
+ // Check that heuristics are initialized as UNKNOWN_TYPE.
+ std::vector<AutoFillField*>::const_iterator iter;
+ size_t i;
+ for (iter = form_structure->begin(), i = 0;
+ iter != form_structure->end();
+ ++iter, ++i) {
+ // Expect last element to be NULL.
+ if (i == form_structure->field_count()) {
+ ASSERT_EQ(static_cast<AutoFillField*>(NULL), *iter);
+ } else {
+ ASSERT_NE(static_cast<AutoFillField*>(NULL), *iter);
+ EXPECT_EQ(UNKNOWN_TYPE, (*iter)->heuristic_type());
+ }
+ }
+
+ // Compute heuristic types.
+ form_structure->GetHeuristicAutoFillTypes();
+ ASSERT_EQ(6U, form_structure->field_count());
+
+ // Check that heuristics are no longer UNKNOWN_TYPE.
+ // Email.
+ EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type());
+ // Full name.
+ EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type());
+ // Company
+ EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
+ // Address.
+ EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type());
+ // City.
+ EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
+ // Zip.
+ EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type());
+}
+
} // namespace
diff --git a/chrome/browser/autofill/name_field.cc b/chrome/browser/autofill/name_field.cc
index 7798b27..38c3c33 100644
--- a/chrome/browser/autofill/name_field.cc
+++ b/chrome/browser/autofill/name_field.cc
@@ -44,8 +44,8 @@ FirstLastNameField* FirstLastNameField::Parse1(
AutoFillField* next;
if (ParseText(&q, ASCIIToUTF16("^name"), &v.first_name_) &&
- ParseText(&q, ASCIIToUTF16(""), &next)) {
- if (ParseText(&q, ASCIIToUTF16(""), &v.last_name_)) {
+ ParseEmptyText(&q, &next)) {
+ if (ParseEmptyText(&q, &v.last_name_)) {
// There are three name fields; assume that the middle one is a
// middle initial (it is, at least, on SmithsonianCheckout.html).
v.middle_name_ = next;