summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 21:56:18 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 21:56:18 +0000
commitdd1b4959032fd4684534ff07dab83f71391b36aa (patch)
treefe904cf6a90dcb7a1e3795fe3c203b86f2fdca0f
parentde49ea10c04eb354ab0187b8f98898c272660037 (diff)
downloadchromium_src-dd1b4959032fd4684534ff07dab83f71391b36aa.zip
chromium_src-dd1b4959032fd4684534ff07dab83f71391b36aa.tar.gz
chromium_src-dd1b4959032fd4684534ff07dab83f71391b36aa.tar.bz2
AutoFill fill billing address when credit card settings specify a billing address.
Fixes address type matching in |AddressField::AddressTypeFromText| method. Also, extends |AutoFillManager::FillAutoFillFormData| method to fill associated billing address when filling a credit card that has billing information set in preferences. Adds new unit test AutoFillManagerTest.FillCreditCardFormWithBilling and fixes others. BUG=44227 TEST=AddressFieldTest.ParseOneLineAddress, \ AddressFieldTest.ParseOneLineAddressBilling, \ AddressFieldTest.ParseOneLineAddressShipping, \ AutoFillManagerTest.FillCreditCardForm, \ AutoFillManagerTest.FillCreditCardFormWithBilling, \ FormStructureTest.HeuristicsSample8, \ and manual test with everything2.html bug file. Review URL: http://codereview.chromium.org/2078016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47731 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/address_field.cc16
-rw-r--r--chrome/browser/autofill/address_field_unittest.cc46
-rw-r--r--chrome/browser/autofill/autofill_manager.cc28
-rw-r--r--chrome/browser/autofill/autofill_manager.h8
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc163
-rw-r--r--chrome/browser/autofill/form_structure_unittest.cc12
-rw-r--r--chrome/renderer/form_manager_unittest.cc160
-rw-r--r--webkit/glue/form_field.cc13
-rw-r--r--webkit/glue/form_field.h8
9 files changed, 318 insertions, 136 deletions
diff --git a/chrome/browser/autofill/address_field.cc b/chrome/browser/autofill/address_field.cc
index 244a125..c2933d1 100644
--- a/chrome/browser/autofill/address_field.cc
+++ b/chrome/browser/autofill/address_field.cc
@@ -387,14 +387,20 @@ AddressType AddressField::AddressTypeFromText(const string16 &text) {
// Not all pages say "billing address" and "shipping address" explicitly;
// for example, Craft Catalog1.html has "Bill-to Address" and
// "Ship-to Address".
- size_t bill = text.find_last_of(ASCIIToUTF16("bill"));
- size_t ship = text.find_last_of(ASCIIToUTF16("ship"));
+ size_t bill = text.rfind(ASCIIToUTF16("bill"));
+ size_t ship = text.rfind(ASCIIToUTF16("ship"));
- if (bill != string16::npos && bill > ship)
+ if (bill == string16::npos && ship == string16::npos)
+ return kGenericAddress;
+
+ if (bill != string16::npos && ship == string16::npos)
return kBillingAddress;
- if (ship != string16::npos)
+ if (bill == string16::npos && ship != string16::npos)
return kShippingAddress;
- return kGenericAddress;
+ if (bill > ship)
+ return kBillingAddress;
+
+ return kShippingAddress;
}
diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc
index dbf282e..6af8c339 100644
--- a/chrome/browser/autofill/address_field_unittest.cc
+++ b/chrome/browser/autofill/address_field_unittest.cc
@@ -51,6 +51,46 @@ TEST_F(AddressFieldTest, ParseOneLineAddress) {
iter_ = list_.begin();
field_.reset(AddressField::Parse(&iter_, false));
ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
+ EXPECT_EQ(kGenericAddress, 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")]);
+}
+
+TEST_F(AddressFieldTest, ParseOneLineAddressBilling) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"),
+ ASCIIToUTF16("billingAddress"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("addr1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(AddressField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
+ EXPECT_EQ(kBillingAddress, 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")]);
+}
+
+TEST_F(AddressFieldTest, ParseOneLineAddressShipping) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"),
+ ASCIIToUTF16("shippingAddress"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("addr1")));
+ 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_));
@@ -98,7 +138,7 @@ TEST_F(AddressFieldTest, ParseTwoLineAddress) {
iter_ = list_.begin();
field_.reset(AddressField::Parse(&iter_, false));
ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
- EXPECT_EQ(kShippingAddress, field_->FindType());
+ EXPECT_EQ(kGenericAddress, field_->FindType());
EXPECT_TRUE(field_->IsFullAddress());
ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
ASSERT_TRUE(
@@ -135,7 +175,7 @@ TEST_F(AddressFieldTest, ParseThreeLineAddress) {
iter_ = list_.begin();
field_.reset(AddressField::Parse(&iter_, false));
ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
- EXPECT_EQ(kShippingAddress, field_->FindType());
+ EXPECT_EQ(kGenericAddress, field_->FindType());
EXPECT_TRUE(field_->IsFullAddress());
ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
ASSERT_TRUE(
@@ -357,7 +397,7 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressMissingLabel) {
iter_ = list_.begin();
field_.reset(AddressField::Parse(&iter_, false));
ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
- EXPECT_EQ(kShippingAddress, field_->FindType());
+ EXPECT_EQ(kGenericAddress, field_->FindType());
EXPECT_TRUE(field_->IsFullAddress());
ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
ASSERT_TRUE(
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 5c49249..c54d910 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -244,6 +244,9 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
autofill_type.group() == AutoFillType::CREDIT_CARD) {
result.fields[i].set_value(
credit_card->GetFieldText(autofill_type));
+ } else if (credit_card &&
+ autofill_type.group() == AutoFillType::ADDRESS_BILLING) {
+ FillBillingFormField(credit_card, autofill_type, &result.fields[i]);
} else if (profile) {
FillFormField(profile, autofill_type, &result.fields[i]);
}
@@ -466,6 +469,31 @@ void AutoFillManager::GetCreditCardSuggestions(const FormField& field,
}
}
+void AutoFillManager::FillBillingFormField(const CreditCard* credit_card,
+ AutoFillType type,
+ webkit_glue::FormField* field) {
+ DCHECK(credit_card);
+ DCHECK(type.group() == AutoFillType::ADDRESS_BILLING);
+ DCHECK(field);
+
+ string16 billing_address = credit_card->billing_address();
+ if (!billing_address.empty()) {
+ AutoFillProfile* profile = NULL;
+ const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles();
+ for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
+ iter != profiles.end(); ++iter) {
+ if ((*iter)->Label() == billing_address) {
+ profile = *iter;
+ break;
+ }
+ }
+
+ if (profile) {
+ FillFormField(profile, type, field);
+ }
+ }
+}
+
void AutoFillManager::FillFormField(const AutoFillProfile* profile,
AutoFillType type,
webkit_glue::FormField* field) {
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index c33ae7e..262a8a0 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -115,6 +115,14 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
std::vector<string16>* values,
std::vector<string16>* labels);
+ // Set |field| argument's value based on |type| and contents of the
+ // |credit_card|. The |type| field is expected to have main group type of
+ // ADDRESS_BILLING. The address information is retrieved from the billing
+ // profile asscociated with the |credit_card|, if there is one set.
+ void FillBillingFormField(const CreditCard* credit_card,
+ AutoFillType type,
+ webkit_glue::FormField* field);
+
// Set |field| argument's value based on |type| and contents of the |profile|.
void FillFormField(const AutoFillProfile* profile,
AutoFillType type,
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index cbb050a..dccba87 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -59,7 +59,7 @@ class TestPersonalDataManager : public PersonalDataManager {
CreditCard* credit_card = new CreditCard;
autofill_unittest::SetCreditCardInfo(credit_card, "First", "Elvis Presley",
"Visa", "1234567890123456", "04",
- "2012", "456", "", "");
+ "2012", "456", "Home", "");
credit_cards->push_back(credit_card);
credit_card = new CreditCard;
autofill_unittest::SetCreditCardInfo(credit_card, "Second", "Buddy Holly",
@@ -137,23 +137,43 @@ void CreateTestFormData(FormData* form) {
form->fields.push_back(field);
}
-void CreateTestFormDataWithValues(FormData* form) {
- CreateTestFormData(form);
- form->fields[0].set_value(ASCIIToUTF16("Elvis"));
- form->fields[1].set_value(ASCIIToUTF16("Aaron"));
- form->fields[2].set_value(ASCIIToUTF16("Presely"));
- form->fields[3].set_value(ASCIIToUTF16("3734 Elvis Presley Blvd."));
- form->fields[4].set_value(ASCIIToUTF16("Apt. 10"));
- form->fields[5].set_value(ASCIIToUTF16("Memphis"));
- form->fields[6].set_value(ASCIIToUTF16("Tennessee"));
- form->fields[7].set_value(ASCIIToUTF16("38116"));
- form->fields[8].set_value(ASCIIToUTF16("USA"));
- form->fields[9].set_value(ASCIIToUTF16("12345678901"));
- form->fields[10].set_value(ASCIIToUTF16("theking@gmail.com"));
- form->fields[11].set_value(ASCIIToUTF16("Elvis Presley"));
- form->fields[12].set_value(ASCIIToUTF16("1234567890123456"));
- form->fields[13].set_value(ASCIIToUTF16("04"));
- form->fields[14].set_value(ASCIIToUTF16("2012"));
+void CreateTestFormDataBilling(FormData* form) {
+ form->name = ASCIIToUTF16("MyForm");
+ form->method = ASCIIToUTF16("POST");
+ form->origin = GURL("http://myform.com/form.html");
+ form->action = GURL("http://myform.com/submit.html");
+
+ webkit_glue::FormField field;
+ CreateTestFormField("First Name", "firstname", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Middle Name", "middlename", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Last Name", "lastname", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Address Line 1", "billingAddr1", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Address Line 2", "billingAddr2", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("City", "billingCity", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("State", "billingState", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Postal Code", "billingZipcode", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Country", "billingCountry", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Phone Number", "phonenumber", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Email", "email", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field);
+ form->fields.push_back(field);
+ CreateTestFormField("", "ccyear", "", "text", &field);
+ form->fields.push_back(field);
}
class AutoFillManagerTest : public RenderViewHostTestHarness {
@@ -381,15 +401,9 @@ TEST_F(AutoFillManagerTest, FillCreditCardForm) {
// The page ID sent to the AutoFillManager from the RenderView, used to send
// an IPC message back to the renderer.
const int kPageID = 1;
-
- webkit_glue::FormField field;
- CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
-
- FormData values;
- CreateTestFormDataWithValues(&values);
EXPECT_TRUE(
autofill_manager_->FillAutoFillFormData(kPageID,
- values,
+ form,
ASCIIToUTF16("cardnumber"),
ASCIIToUTF16("First")));
@@ -401,38 +415,107 @@ TEST_F(AutoFillManagerTest, FillCreditCardForm) {
EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin);
EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action);
ASSERT_EQ(15U, results.fields.size());
+
+ webkit_glue::FormField field;
CreateTestFormField("First Name", "firstname", "", "text", &field);
- EXPECT_EQ(field, results.fields[0]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
CreateTestFormField("Middle Name", "middlename", "", "text", &field);
- EXPECT_EQ(field, results.fields[1]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
CreateTestFormField("Last Name", "lastname", "", "text", &field);
- EXPECT_EQ(field, results.fields[2]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
CreateTestFormField("Address Line 1", "addr1", "", "text", &field);
- EXPECT_EQ(field, results.fields[3]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
CreateTestFormField("Address Line 2", "addr2", "", "text", &field);
- EXPECT_EQ(field, results.fields[4]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4]));
CreateTestFormField("City", "city", "", "text", &field);
- EXPECT_EQ(field, results.fields[5]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5]));
CreateTestFormField("State", "state", "", "text", &field);
- EXPECT_EQ(field, results.fields[6]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6]));
CreateTestFormField("Postal Code", "zipcode", "", "text", &field);
- EXPECT_EQ(field, results.fields[7]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7]));
CreateTestFormField("Country", "country", "", "text", &field);
- EXPECT_EQ(field, results.fields[8]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8]));
CreateTestFormField("Phone Number", "phonenumber", "", "text", &field);
- EXPECT_EQ(field, results.fields[9]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9]));
CreateTestFormField("Email", "email", "", "text", &field);
- EXPECT_EQ(field, results.fields[10]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10]));
+ CreateTestFormField(
+ "Name on Card", "nameoncard", "Elvis Presley", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11]));
+ CreateTestFormField(
+ "Card Number", "cardnumber", "1234567890123456", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12]));
+ CreateTestFormField("Expiration Date", "ccmonth", "04", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13]));
+ CreateTestFormField("", "ccyear", "2012", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14]));
+}
+
+TEST_F(AutoFillManagerTest, FillCreditCardFormWithBilling) {
+ FormData form;
+ CreateTestFormDataBilling(&form);
+
+ // Set up our FormStructures.
+ std::vector<FormData> forms;
+ forms.push_back(form);
+ autofill_manager_->FormsSeen(forms);
+
+ // The page ID sent to the AutoFillManager from the RenderView, used to send
+ // an IPC message back to the renderer.
+ const int kPageID = 1;
+ EXPECT_TRUE(
+ autofill_manager_->FillAutoFillFormData(kPageID,
+ form,
+ ASCIIToUTF16("cardnumber"),
+ ASCIIToUTF16("First")));
+
+ int page_id = 0;
+ FormData results;
+ EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
+ EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name);
+ EXPECT_EQ(ASCIIToUTF16("POST"), results.method);
+ EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin);
+ EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action);
+ ASSERT_EQ(15U, results.fields.size());
+
+ webkit_glue::FormField field;
+ CreateTestFormField("First Name", "firstname", "", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0]));
+ CreateTestFormField("Middle Name", "middlename", "", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1]));
+ CreateTestFormField("Last Name", "lastname", "", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2]));
+ CreateTestFormField(
+ "Address Line 1", "billingAddr1", "3734 Elvis Presley Blvd.", "text",
+ &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3]));
+ CreateTestFormField(
+ "Address Line 2", "billingAddr2", "Apt. 10", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4]));
+ CreateTestFormField("City", "billingCity", "Memphis", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5]));
+ CreateTestFormField("State", "billingState", "Tennessee", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6]));
+ CreateTestFormField("Postal Code", "billingZipcode", "38116", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7]));
+ CreateTestFormField("Country", "billingCountry", "USA", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8]));
+ CreateTestFormField(
+ "Phone Number", "phonenumber", "", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9]));
+ CreateTestFormField(
+ "Email", "email", "", "text", &field);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10]));
CreateTestFormField(
"Name on Card", "nameoncard", "Elvis Presley", "text", &field);
- EXPECT_EQ(field, results.fields[11]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11]));
CreateTestFormField(
"Card Number", "cardnumber", "1234567890123456", "text", &field);
- EXPECT_EQ(field, results.fields[12]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12]));
CreateTestFormField("Expiration Date", "ccmonth", "04", "text", &field);
- EXPECT_EQ(field, results.fields[13]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13]));
CreateTestFormField("", "ccyear", "2012", "text", &field);
- EXPECT_EQ(field, results.fields[14]);
+ EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14]));
}
} // namespace
diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc
index 3dd8b49c..ed90de3 100644
--- a/chrome/browser/autofill/form_structure_unittest.cc
+++ b/chrome/browser/autofill/form_structure_unittest.cc
@@ -410,17 +410,17 @@ TEST(FormStructureTest, HeuristicsSample8) {
// Last name.
EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
// Address.
- EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type());
+ EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type());
// Address.
- EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type());
+ EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type());
// City.
- EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
+ EXPECT_EQ(ADDRESS_BILLING_CITY, form_structure->field(4)->heuristic_type());
// State.
- EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(5)->heuristic_type());
+ EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure->field(5)->heuristic_type());
// Zip.
- EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
+ EXPECT_EQ(ADDRESS_BILLING_ZIP, form_structure->field(6)->heuristic_type());
// Country.
- EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type());
+ EXPECT_EQ(ADDRESS_BILLING_COUNTRY, form_structure->field(7)->heuristic_type());
// Phone.
EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
form_structure->field(8)->heuristic_type());
diff --git a/chrome/renderer/form_manager_unittest.cc b/chrome/renderer/form_manager_unittest.cc
index 74d25be..01dc52a 100644
--- a/chrome/renderer/form_manager_unittest.cc
+++ b/chrome/renderer/form_manager_unittest.cc
@@ -56,13 +56,13 @@ TEST_F(FormManagerTest, WebFormElementToFormData) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -100,13 +100,13 @@ TEST_F(FormManagerTest, ExtractForms) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -148,7 +148,7 @@ TEST_F(FormManagerTest, ExtractMultipleForms) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -169,14 +169,14 @@ TEST_F(FormManagerTest, ExtractMultipleForms) {
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
- fields2[0]);
+ 20),
+ fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("second"),
ASCIIToUTF16("Submit"),
ASCIIToUTF16("submit"),
0),
- fields2[1]);
+ fields2[1]);
}
TEST_F(FormManagerTest, GetFormsAutocomplete) {
@@ -232,7 +232,7 @@ TEST_F(FormManagerTest, GetFormsAutocomplete) {
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply"),
@@ -271,7 +271,7 @@ TEST_F(FormManagerTest, GetFormsElementsEnabled) {
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("submit"),
@@ -317,13 +317,13 @@ TEST_F(FormManagerTest, FindForm) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -369,13 +369,13 @@ TEST_F(FormManagerTest, FillForm) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -403,20 +403,20 @@ TEST_F(FormManagerTest, FillForm) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Wyatt"),
ASCIIToUTF16("text"),
- 0),
- fields2[0]);
+ 20),
+ fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Earp"),
ASCIIToUTF16("text"),
- 0),
- fields2[1]);
+ 20),
+ fields2[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
ASCIIToUTF16("Send"),
ASCIIToUTF16("submit"),
0),
- fields2[2]);
+ fields2[2]);
}
TEST_F(FormManagerTest, Reset) {
@@ -474,13 +474,13 @@ TEST_F(FormManagerTest, Labels) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -520,13 +520,13 @@ TEST_F(FormManagerTest, LabelsWithSpans) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -570,13 +570,13 @@ TEST_F(FormManagerTest, InvalidLabels) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -621,13 +621,13 @@ TEST_F(FormManagerTest, OneLabelElementFirstControlElementDisabled) {
ASCIIToUTF16("middlename"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -667,13 +667,13 @@ TEST_F(FormManagerTest, LabelsInferredFromText) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -713,13 +713,13 @@ TEST_F(FormManagerTest, LabelsInferredFromParagraph) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -770,13 +770,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCell) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -846,13 +846,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -892,13 +892,13 @@ TEST_F(FormManagerTest, LabelsInferredWithSameName) {
ASCIIToUTF16("Address"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Address Line 2:"),
ASCIIToUTF16("Address"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -948,31 +948,31 @@ TEST_F(FormManagerTest, LabelsInferredWithImageTags) {
ASCIIToUTF16("dayphone1"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone2"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone3"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[2]);
EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"),
ASCIIToUTF16("dayphone4"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[3]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("dummy"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[4]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1018,13 +1018,13 @@ TEST_F(FormManagerTest, FillFormMaxLength) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1053,14 +1053,14 @@ TEST_F(FormManagerTest, FillFormMaxLength) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Broth"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[0]);
EXPECT_EQ(ASCIIToUTF16("Broth"), fields2[0].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonat"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[1]);
EXPECT_EQ(ASCIIToUTF16("Jonat"), fields2[1].value());
EXPECT_EQ(FormField(string16(),
@@ -1110,13 +1110,13 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1146,14 +1146,14 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[0]);
EXPECT_EQ(ASCIIToUTF16("Brother"), fields2[0].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[1]);
EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields2[1].value());
EXPECT_EQ(FormField(string16(),
@@ -1200,28 +1200,28 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) {
ASCIIToUTF16("prefix"),
string16(),
ASCIIToUTF16("text"),
- 0);
+ 20);
form->fields.insert(form->fields.begin(), field1);
FormField field2(string16(),
ASCIIToUTF16("hidden"),
string16(),
ASCIIToUTF16("text"),
- 0);
+ 20);
form->fields.insert(form->fields.begin() + 2, field2);
FormField field3(string16(),
ASCIIToUTF16("second"),
string16(),
ASCIIToUTF16("text"),
- 0);
+ 20);
form->fields.insert(form->fields.begin() + 4, field3);
FormField field4(string16(),
ASCIIToUTF16("postfix"),
string16(),
ASCIIToUTF16("text"),
- 0);
+ 20);
form->fields.insert(form->fields.begin() + 6, field4);
// Fill the form.
@@ -1254,21 +1254,21 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Joseph"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[2]);
EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
EXPECT_EQ(FormField(string16(),
@@ -1341,49 +1341,49 @@ TEST_F(FormManagerTest, FillFormFewerFormDataFields) {
ASCIIToUTF16("prefix"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(string16(), fields[0].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(ASCIIToUTF16("Brother"), fields[1].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("hidden"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[2]);
EXPECT_EQ(string16(), fields[2].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Joseph"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[3]);
EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[3].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("second"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[4]);
EXPECT_EQ(string16(), fields[4].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[5]);
EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[5].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("postfix"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[6]);
EXPECT_EQ(string16(), fields[6].value());
EXPECT_EQ(FormField(string16(),
@@ -1450,28 +1450,28 @@ TEST_F(FormManagerTest, FillFormExtraFieldInCache) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Joseph"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[2]);
EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("postfix"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[3]);
EXPECT_EQ(string16(), fields[3].value());
EXPECT_EQ(FormField(string16(),
@@ -1518,13 +1518,13 @@ TEST_F(FormManagerTest, FillFormEmptyName) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -1552,13 +1552,13 @@ TEST_F(FormManagerTest, FillFormEmptyName) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Wyatt"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Earp"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -1610,13 +1610,13 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) {
ASCIIToUTF16("apple"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("banana"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -1644,13 +1644,13 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) {
ASCIIToUTF16("apple"),
ASCIIToUTF16("Red"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("banana"),
ASCIIToUTF16("Yellow"),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields2[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -1696,25 +1696,25 @@ TEST_F(FormManagerTest, ThreePartPhone) {
ASCIIToUTF16("dayphone1"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone2"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[1]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone3"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[2]);
EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"),
ASCIIToUTF16("dayphone4"),
string16(),
ASCIIToUTF16("text"),
- 0),
+ 20),
fields[3]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc
index 250f04a..0d6ac1d 100644
--- a/webkit/glue/form_field.cc
+++ b/webkit/glue/form_field.cc
@@ -56,16 +56,25 @@ FormField::FormField(const string16& label,
bool FormField::operator==(const FormField& field) const {
// A FormField stores a value, but the value is not part of the identity of
- // the field, so we don't want to compare the values. Same goes for |size_|.
+ // the field, so we don't want to compare the values.
return (label_ == field.label_ &&
name_ == field.name_ &&
- form_control_type_ == field.form_control_type_);
+ form_control_type_ == field.form_control_type_ &&
+ size_ == field.size_);
}
bool FormField::operator!=(const FormField& field) const {
return !operator==(field);
}
+bool FormField::StrictlyEqualsHack(const FormField& field) const {
+ return (label_ == field.label_ &&
+ name_ == field.name_ &&
+ value_ == field.value_ &&
+ form_control_type_ == field.form_control_type_ &&
+ size_ == field.size_);
+}
+
std::ostream& operator<<(std::ostream& os, const FormField& field) {
return os
<< UTF16ToUTF8(field.label())
diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h
index b0e9dec..691d2af9 100644
--- a/webkit/glue/form_field.h
+++ b/webkit/glue/form_field.h
@@ -35,9 +35,17 @@ class FormField {
}
void set_size(int size) { size_ = size; }
+ // Equality tests for identity which does not include |value_| or |size_|.
+ // Use |StrictlyEqualsHack| method to test all members.
+ // TODO(dhollowa): These operators need to be revised when we implement field
+ // ids.
bool operator==(const FormField& field) const;
bool operator!=(const FormField& field) const;
+ // Test equality of all data members.
+ // TODO(dhollowa): This will be removed when we implement field ids.
+ bool StrictlyEqualsHack(const FormField& field) const;
+
private:
string16 label_;
string16 name_;