diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autofill/address_field_unittest.cc | 57 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_download_unittest.cc | 33 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 39 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 10 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/autofill/credit_card_field_unittest.cc | 81 | ||||
-rw-r--r-- | chrome/browser/autofill/fax_field_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/autofill/form_structure_unittest.cc | 289 | ||||
-rw-r--r-- | chrome/browser/autofill/name_field_unittest.cc | 39 | ||||
-rw-r--r-- | chrome/browser/autofill/phone_field.cc | 20 | ||||
-rw-r--r-- | chrome/browser/autofill/phone_field_unittest.cc | 69 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 78 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 4 | ||||
-rw-r--r-- | chrome/renderer/form_manager.cc | 23 | ||||
-rw-r--r-- | chrome/renderer/form_manager_unittest.cc | 654 |
16 files changed, 1042 insertions, 362 deletions
diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc index 8b82dda..7e3c2dd 100644 --- a/chrome/browser/autofill/address_field_unittest.cc +++ b/chrome/browser/autofill/address_field_unittest.cc @@ -44,7 +44,8 @@ TEST_F(AddressFieldTest, ParseOneLineAddress) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -63,7 +64,8 @@ TEST_F(AddressFieldTest, ParseOneLineAddressEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"), kEcmlShipToAddress1, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -82,13 +84,15 @@ TEST_F(AddressFieldTest, ParseTwoLineAddress) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), string16(), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -110,19 +114,22 @@ TEST_F(AddressFieldTest, ParseThreeLineAddress) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line1"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line3"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -146,13 +153,15 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"), kEcmlShipToAddress1, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), kEcmlShipToAddress2, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -174,7 +183,8 @@ TEST_F(AddressFieldTest, ParseCity) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("city1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -193,7 +203,8 @@ TEST_F(AddressFieldTest, ParseCityEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("City"), kEcmlShipToCity, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("city1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -212,7 +223,8 @@ TEST_F(AddressFieldTest, ParseState) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("State"), ASCIIToUTF16("state"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("state1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -231,7 +243,8 @@ TEST_F(AddressFieldTest, ParseStateEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("State"), kEcmlShipToStateProv, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("state1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -250,7 +263,8 @@ TEST_F(AddressFieldTest, ParseZip) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Zip"), ASCIIToUTF16("zip"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("zip1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -269,7 +283,8 @@ TEST_F(AddressFieldTest, ParseZipEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Zip"), kEcmlShipToPostalCode, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("zip1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -288,7 +303,8 @@ TEST_F(AddressFieldTest, ParseCountry) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Country"), ASCIIToUTF16("country"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("country1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -307,7 +323,8 @@ TEST_F(AddressFieldTest, ParseCountryEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Country"), kEcmlShipToCountry, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("country1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -326,13 +343,15 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressMissingLabel) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("bogus"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("addr2"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc index 085059f..3074ecd 100644 --- a/chrome/browser/autofill/autofill_download_unittest.cc +++ b/chrome/browser/autofill/autofill_download_unittest.cc @@ -98,31 +98,38 @@ TEST(AutoFillDownloadTest, QueryAndUploadTest) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), ASCIIToUTF16("username"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), ASCIIToUTF16("email"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), ASCIIToUTF16("email2"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), - ASCIIToUTF16("password"))); + ASCIIToUTF16("password"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); FormStructure *form_structure = new FormStructure(form); ScopedVector<FormStructure> form_structures; @@ -132,19 +139,23 @@ TEST(AutoFillDownloadTest, QueryAndUploadTest) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address"), ASCIIToUTF16("address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address2"), ASCIIToUTF16("address2"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("city"), ASCIIToUTF16("address2"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure = new FormStructure(form); form_structures.push_back(form_structure); diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 8ba0030..5c49249 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -27,6 +27,12 @@ namespace { // The rate for positive/negative matches potentially could be different. const double kAutoFillPositiveUploadRateDefaultValue = 0.01; const double kAutoFillNegativeUploadRateDefaultValue = 0.01; + +// Size and offset of the prefix and suffix portions of phone numbers. +const int kAutoFillPhoneNumberPrefixOffset = 0; +const int kAutoFillPhoneNumberPrefixCount = 3; +const int kAutoFillPhoneNumberSuffixOffset = 3; +const int kAutoFillPhoneNumberSuffixCount = 4; } // namespace // TODO(jhawkins): Maybe this should be in a grd file? @@ -239,7 +245,7 @@ bool AutoFillManager::FillAutoFillFormData(int query_id, result.fields[i].set_value( credit_card->GetFieldText(autofill_type)); } else if (profile) { - result.fields[i].set_value(profile->GetFieldText(autofill_type)); + FillFormField(profile, autofill_type, &result.fields[i]); } } } @@ -459,3 +465,34 @@ void AutoFillManager::GetCreditCardSuggestions(const FormField& field, } } } + +void AutoFillManager::FillFormField(const AutoFillProfile* profile, + AutoFillType type, + webkit_glue::FormField* field) { + DCHECK(profile); + DCHECK(field); + + if (type.subgroup() == AutoFillType::PHONE_NUMBER) { + FillPhoneNumberField(profile, field); + } else { + field->set_value(profile->GetFieldText(type)); + } +} + +void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile, + webkit_glue::FormField* field) { + // If we are filling a phone number, check to see if the size field + // matches the "prefix" or "suffix" sizes and fill accordingly. + string16 number = profile->GetFieldText(AutoFillType(PHONE_HOME_NUMBER)); + if (field->size() == kAutoFillPhoneNumberPrefixCount) { + number = number.substr(kAutoFillPhoneNumberPrefixOffset, + kAutoFillPhoneNumberPrefixCount); + field->set_value(number); + } else if (field->size() == kAutoFillPhoneNumberSuffixCount) { + number = number.substr(kAutoFillPhoneNumberSuffixOffset, + kAutoFillPhoneNumberSuffixCount); + field->set_value(number); + } else { + field->set_value(number); + } +} diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index 0a7a523..c33ae7e 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -115,6 +115,16 @@ 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 |profile|. + void FillFormField(const AutoFillProfile* profile, + AutoFillType type, + webkit_glue::FormField* field); + + // Set |field| argument's value for phone number based on contents of the + // |profile|. + void FillPhoneNumberField(const AutoFillProfile* profile, + webkit_glue::FormField* field); + // The TabContents hosting this AutoFillManager. // Weak reference. // May not be NULL. diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index 1997a3c..cbb050a 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -95,7 +95,7 @@ void CreateTestFormField(const char* label, const char* type, webkit_glue::FormField* field) { *field = webkit_glue::FormField(ASCIIToUTF16(label), ASCIIToUTF16(name), - ASCIIToUTF16(value), ASCIIToUTF16(type)); + ASCIIToUTF16(value), ASCIIToUTF16(type), 0); } void CreateTestFormData(FormData* form) { diff --git a/chrome/browser/autofill/credit_card_field_unittest.cc b/chrome/browser/autofill/credit_card_field_unittest.cc index e972c62..684ac78 100644 --- a/chrome/browser/autofill/credit_card_field_unittest.cc +++ b/chrome/browser/autofill/credit_card_field_unittest.cc @@ -44,13 +44,15 @@ TEST_F(CreditCardFieldTest, ParseCreditCardNoNumber) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -63,7 +65,8 @@ TEST_F(CreditCardFieldTest, ParseCreditCardNoDate) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -76,19 +79,22 @@ TEST_F(CreditCardFieldTest, ParseMiniumCreditCard) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -112,19 +118,22 @@ TEST_F(CreditCardFieldTest, ParseMiniumCreditCardEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), kEcmlCardNumber, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), kEcmlCardExpireMonth, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), kEcmlCardExpireYear, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -148,31 +157,36 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCard) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), ASCIIToUTF16("name on card"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("cvc1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -203,31 +217,36 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCardEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), kEcmlCardHolder, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), kEcmlCardNumber, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), kEcmlCardExpireMonth, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), kEcmlCardExpireYear, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Verification"), kEcmlCardVerification, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("cvc1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -258,27 +277,31 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), ASCIIToUTF16("Name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("Card"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number"))); list_.push_back( new AutoFillField( webkit_glue::FormField(ASCIIToUTF16("ExpDate Month / Year"), ASCIIToUTF16("ExpDate"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month"))); list_.push_back( new AutoFillField( webkit_glue::FormField(ASCIIToUTF16("ExpDate Month / Year"), ASCIIToUTF16("ExpDate"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -305,27 +328,31 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear2) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), ASCIIToUTF16("Name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("Card"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("number"))); list_.push_back( new AutoFillField( webkit_glue::FormField(ASCIIToUTF16("Expiration date Month / Year"), ASCIIToUTF16("ExpDate"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("month"))); list_.push_back( new AutoFillField( webkit_glue::FormField(ASCIIToUTF16("Expiration date Month / Year"), ASCIIToUTF16("ExpDate"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("year"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/autofill/fax_field_unittest.cc b/chrome/browser/autofill/fax_field_unittest.cc index 4cccac4..258f8d0 100644 --- a/chrome/browser/autofill/fax_field_unittest.cc +++ b/chrome/browser/autofill/fax_field_unittest.cc @@ -44,7 +44,8 @@ TEST_F(FaxFieldTest, ParseOneLineFax) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Fax"), ASCIIToUTF16("faxnumber"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("fax1"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc index 1286f9a..f8f8f87 100644 --- a/chrome/browser/autofill/form_structure_unittest.cc +++ b/chrome/browser/autofill/form_structure_unittest.cc @@ -43,15 +43,18 @@ TEST(FormStructureTest, FieldCount) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), ASCIIToUTF16("username"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), - ASCIIToUTF16("password"))); + ASCIIToUTF16("password"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); FormStructure form_structure(form); // All fields are counted. @@ -64,19 +67,23 @@ TEST(FormStructureTest, AutoFillCount) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), ASCIIToUTF16("username"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), - ASCIIToUTF16("password"))); + ASCIIToUTF16("password"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("state"), ASCIIToUTF16("state"), string16(), - ASCIIToUTF16("select-one"))); + ASCIIToUTF16("select-one"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); FormStructure form_structure(form); // Only text and select fields that are heuristically matched are counted. @@ -89,19 +96,23 @@ TEST(FormStructureTest, ConvertToFormData) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), ASCIIToUTF16("username"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), - ASCIIToUTF16("password"))); + ASCIIToUTF16("password"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("state"), ASCIIToUTF16("state"), string16(), - ASCIIToUTF16("select"))); + ASCIIToUTF16("select"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); FormStructure form_structure(form); FormData converted = form_structure.ConvertToFormData(); @@ -117,11 +128,13 @@ TEST(FormStructureTest, HasAutoFillableValues) { form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit1"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit2"), ASCIIToUTF16("dummy value"), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->HasAutoFillableValues()); @@ -129,11 +142,13 @@ TEST(FormStructureTest, HasAutoFillableValues) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Email"), ASCIIToUTF16("email"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("state"), ASCIIToUTF16("state"), string16(), - ASCIIToUTF16("select-one"))); + ASCIIToUTF16("select-one"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->HasAutoFillableValues()); @@ -141,11 +156,13 @@ TEST(FormStructureTest, HasAutoFillableValues) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Dear"), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->HasAutoFillableValues()); @@ -155,11 +172,13 @@ TEST(FormStructureTest, HasAutoFillableValues) { form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Field1"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Field2"), ASCIIToUTF16("dummy value"), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->HasAutoFillableValues()); @@ -168,7 +187,8 @@ TEST(FormStructureTest, HasAutoFillableValues) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Full Name"), ASCIIToUTF16("fullname"), ASCIIToUTF16("John Dear"), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->HasAutoFillableValues()); } @@ -182,15 +202,18 @@ TEST(FormStructureTest, IsAutoFillable) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), ASCIIToUTF16("username"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), - ASCIIToUTF16("password"))); + ASCIIToUTF16("password"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable()); @@ -198,11 +221,13 @@ TEST(FormStructureTest, IsAutoFillable) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable()); @@ -210,7 +235,8 @@ TEST(FormStructureTest, IsAutoFillable) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Email"), ASCIIToUTF16("email"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); @@ -239,39 +265,48 @@ TEST(FormStructureTest, HeuristicsContactInfo) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), ASCIIToUTF16("email"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), ASCIIToUTF16("fax"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), ASCIIToUTF16("zipcode"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); @@ -309,52 +344,62 @@ TEST(FormStructureTest, HeuristicsSample8) { webkit_glue::FormField(ASCIIToUTF16("Your First Name:"), ASCIIToUTF16("bill.first"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Your Last Name:"), ASCIIToUTF16("bill.last"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street Address Line 1:"), ASCIIToUTF16("bill.street1"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street Address Line 2:"), ASCIIToUTF16("bill.street2"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City:"), ASCIIToUTF16("bill.city"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("State (U.S.):"), ASCIIToUTF16("bill.state"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Zip/Postal Code:"), ASCIIToUTF16("BillTo.PostalCode"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Country:"), ASCIIToUTF16("bill.country"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Phone Number:"), ASCIIToUTF16("BillTo.Phone"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(10U, form_structure->field_count()); @@ -392,39 +437,46 @@ TEST(FormStructureTest, HeuristicsSample6) { webkit_glue::FormField(ASCIIToUTF16("E-mail address"), ASCIIToUTF16("email"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Full name"), ASCIIToUTF16("name"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Company"), ASCIIToUTF16("company"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); // TODO(jhawkins): Add state select control. form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Zip Code"), ASCIIToUTF16("Home.PostalCode"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); // TODO(jhawkins): Phone number. form.fields.push_back( webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), ASCIIToUTF16("continue"), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(7U, form_structure->field_count()); @@ -457,39 +509,48 @@ TEST(FormStructureTest, HeuristicsLabelsOnly) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), string16(), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(9U, form_structure->field_count()); @@ -524,27 +585,33 @@ TEST(FormStructureTest, HeuristicsCreditCardInfo) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), ASCIIToUTF16("name on card"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(6U, form_structure->field_count()); @@ -574,33 +641,40 @@ TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), ASCIIToUTF16("name on card"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); // This is not a field we know how to process. But we should skip over it // and process the other fields in the card block. form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Type"), ASCIIToUTF16("card_type"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), - ASCIIToUTF16("submit"))); + ASCIIToUTF16("submit"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(7U, form_structure->field_count()); @@ -633,22 +707,26 @@ TEST(FormStructureTest, ThreeAddressLines) { webkit_glue::FormField(ASCIIToUTF16("Address Line1"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line3"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(4U, form_structure->field_count()); @@ -673,17 +751,20 @@ TEST(FormStructureTest, HeuristicsStateWithProvince) { webkit_glue::FormField(ASCIIToUTF16("Address Line1"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("State/Province/Region"), ASCIIToUTF16("State"), string16(), - ASCIIToUTF16("text"))); + ASCIIToUTF16("text"), + 0)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); ASSERT_EQ(3U, form_structure->field_count()); @@ -697,4 +778,50 @@ TEST(FormStructureTest, HeuristicsStateWithProvince) { EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); } +TEST(FormStructureTest, ThreePartPhoneNumber) { + scoped_ptr<FormStructure> form_structure; + FormData form; + + form.method = ASCIIToUTF16("post"); + form.fields.push_back( + webkit_glue::FormField(ASCIIToUTF16("Phone:"), + ASCIIToUTF16("dayphone1"), + string16(), + ASCIIToUTF16("text"), + 0)); + form.fields.push_back( + webkit_glue::FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone2"), + string16(), + ASCIIToUTF16("text"), + 0)); + form.fields.push_back( + webkit_glue::FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone3"), + string16(), + ASCIIToUTF16("text"), + 0)); + form.fields.push_back( + webkit_glue::FormField(ASCIIToUTF16("ext.:"), + ASCIIToUTF16("dayphone4"), + string16(), + ASCIIToUTF16("text"), + 0)); + form_structure.reset(new FormStructure(form)); + EXPECT_TRUE(form_structure->IsAutoFillable()); + ASSERT_EQ(4U, form_structure->field_count()); + ASSERT_EQ(3U, form_structure->autofill_count()); + + // Area code. + EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); + // Phone number suffix. + EXPECT_EQ(PHONE_HOME_NUMBER, + form_structure->field(1)->heuristic_type()); + // Phone number suffix. + EXPECT_EQ(PHONE_HOME_NUMBER, + form_structure->field(2)->heuristic_type()); + // Unknown. + EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); +} + } // namespace diff --git a/chrome/browser/autofill/name_field_unittest.cc b/chrome/browser/autofill/name_field_unittest.cc index 438bef3..11e453e 100644 --- a/chrome/browser/autofill/name_field_unittest.cc +++ b/chrome/browser/autofill/name_field_unittest.cc @@ -30,19 +30,22 @@ TEST_F(NameFieldTest, FirstMiddleLast) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("First"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Middle Name"), ASCIIToUTF16("Middle"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("Last"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -65,19 +68,22 @@ TEST_F(NameFieldTest, FirstMiddleLast2) { new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("firstName"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("middleName"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("lastName"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -100,13 +106,15 @@ TEST_F(NameFieldTest, FirstLast) { new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("first_name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("last_name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -126,13 +134,15 @@ TEST_F(NameFieldTest, FirstLast2) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("first_name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("last_name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -152,19 +162,22 @@ TEST_F(NameFieldTest, FirstLastMiddleWithSpaces) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("first name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Middle Name"), ASCIIToUTF16("middle name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("last name"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/autofill/phone_field.cc b/chrome/browser/autofill/phone_field.cc index dfecceb..6092fe4 100644 --- a/chrome/browser/autofill/phone_field.cc +++ b/chrome/browser/autofill/phone_field.cc @@ -99,9 +99,23 @@ bool PhoneField::GetFieldInfo(FieldTypeMap* field_type_map) const { ok = Add(field_type_map, area_code_, AutoFillType(PHONE_HOME_CITY_CODE)); DCHECK(ok); - // NOTE: we ignore the prefix/suffix thing here. - ok = ok && Add(field_type_map, phone_, AutoFillType(PHONE_HOME_NUMBER)); - DCHECK(ok); + if (prefix_ != NULL) { + // 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 && Add(field_type_map, + prefix_, + AutoFillType(PHONE_HOME_NUMBER)); + DCHECK(ok); + // 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. + ok = ok && Add(field_type_map, + phone_, + AutoFillType(PHONE_HOME_NUMBER)); + DCHECK(ok); + } else { + ok = ok && Add(field_type_map, phone_, AutoFillType(PHONE_HOME_NUMBER)); + DCHECK(ok); + } } else { ok = Add(field_type_map, phone_, AutoFillType(PHONE_HOME_WHOLE_NUMBER)); DCHECK(ok); diff --git a/chrome/browser/autofill/phone_field_unittest.cc b/chrome/browser/autofill/phone_field_unittest.cc index f2fa01f..bf7d9fb 100644 --- a/chrome/browser/autofill/phone_field_unittest.cc +++ b/chrome/browser/autofill/phone_field_unittest.cc @@ -44,7 +44,8 @@ TEST_F(PhoneFieldTest, ParseOneLinePhone) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -61,7 +62,8 @@ TEST_F(PhoneFieldTest, ParseOneLinePhoneEcml) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), kEcmlShipToPhone, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -78,13 +80,15 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhone) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Area Code"), ASCIIToUTF16("area code"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -104,13 +108,15 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlShipTo) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Area Code"), kEcmlShipToPostalCode, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), kEcmlShipToPhone, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -130,13 +136,15 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlBillTo) { new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Area Code"), kEcmlBillToPostalCode, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), kEcmlBillToPhone, string16(), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -151,4 +159,49 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlBillTo) { EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]); } +TEST_F(PhoneFieldTest, ThreePartPhoneNumber) { + list_.push_back( + new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone:"), + ASCIIToUTF16("dayphone1"), + string16(), + ASCIIToUTF16("text"), + 0), + ASCIIToUTF16("areacode1"))); + list_.push_back( + new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone2"), + string16(), + ASCIIToUTF16("text"), + 0), + ASCIIToUTF16("prefix1"))); + list_.push_back( + new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone3"), + string16(), + ASCIIToUTF16("text"), + 0), + ASCIIToUTF16("suffix1"))); + list_.push_back( + new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("ext.:"), + ASCIIToUTF16("dayphone4"), + string16(), + ASCIIToUTF16("text"), + 0), + ASCIIToUTF16("ext1"))); + list_.push_back(NULL); + iter_ = list_.begin(); + field_.reset(PhoneField::Parse(&iter_, false)); + ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get()); + ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end()); + EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("prefix1")) != field_type_map_.end()); + EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("prefix1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("suffix1")) != field_type_map_.end()); + EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("suffix1")]); +} + } // namespace diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc index c11d4b7..0dc7df3 100644 --- a/chrome/browser/webdata/web_data_service_unittest.cc +++ b/chrome/browser/webdata/web_data_service_unittest.cc @@ -133,7 +133,8 @@ class WebDataServiceAutofillTest : public WebDataServiceTest { webkit_glue::FormField(string16(), name, value, - string16())); + string16(), + 0)); } string16 name1_; diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index e1b58c5..6e7e523 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -479,7 +479,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes)); std::vector<string16> v; for (int i = 0; i < 5; i++) { @@ -487,7 +488,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), - string16()), + string16(), + 0), &changes)); } for (int i = 0; i < 3; i++) { @@ -495,7 +497,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Sutter"), - string16()), + string16(), + 0), &changes)); } for (int i = 0; i < 2; i++) { @@ -503,7 +506,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green"), - string16()), + string16(), + 0), &changes)); } @@ -516,7 +520,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), - string16()), + string16(), + 0), &pair_id, &count)); EXPECT_EQ(5, count); EXPECT_NE(0, pair_id); @@ -527,7 +532,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("clark kent"), - string16()), + string16(), + 0), &pair_id, &count)); EXPECT_EQ(0, count); @@ -535,7 +541,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green"), - string16()), + string16(), + 0), &pair_id, &count)); EXPECT_EQ(2, count); @@ -599,7 +606,8 @@ TEST_F(WebDatabaseTest, Autofill) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), - string16()), + string16(), + 0), &pair_id, &count)); EXPECT_EQ(0, count); @@ -612,22 +620,26 @@ TEST_F(WebDatabaseTest, Autofill) { EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), string16(), - string16()), + string16(), + 0), &changes)); EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), ASCIIToUTF16(" "), - string16()), + string16(), + 0), &changes)); EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), ASCIIToUTF16(" "), - string16()), + string16(), + 0), &changes)); EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), kValue, - string16()), + string16(), + 0), &changes)); // They should be stored normally as the DB layer does not check for empty @@ -661,14 +673,16 @@ TEST_F(WebDatabaseTest, Autofill_RemoveBetweenChanges) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, t1)); EXPECT_TRUE(db.AddFormFieldValueTime( FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, t2)); @@ -702,7 +716,8 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, t1)); ASSERT_EQ(1U, changes.size()); @@ -716,7 +731,8 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, t2)); ASSERT_EQ(1U, changes.size()); @@ -738,7 +754,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateOneWithOneTimestamp) { FormField field(string16(), ASCIIToUTF16("foo"), ASCIIToUTF16("bar"), - string16()); + string16(), + 0); int64 pair_id; int count; ASSERT_TRUE(db.GetIDAndCountOfFormElement(field, &pair_id, &count)); @@ -763,7 +780,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateOneWithTwoTimestamps) { FormField field(string16(), ASCIIToUTF16("foo"), ASCIIToUTF16("bar"), - string16()); + string16(), + 0); int64 pair_id; int count; ASSERT_TRUE(db.GetIDAndCountOfFormElement(field, &pair_id, &count)); @@ -808,7 +826,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateTwo) { FormField field0(string16(), ASCIIToUTF16("foo"), ASCIIToUTF16("bar0"), - string16()); + string16(), + 0); int64 pair_id; int count; ASSERT_TRUE(db.GetIDAndCountOfFormElement(field0, &pair_id, &count)); @@ -818,7 +837,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateTwo) { FormField field1(string16(), ASCIIToUTF16("foo"), ASCIIToUTF16("bar1"), - string16()); + string16(), + 0); ASSERT_TRUE(db.GetIDAndCountOfFormElement(field1, &pair_id, &count)); EXPECT_LE(0, pair_id); EXPECT_EQ(2, count); @@ -834,7 +854,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateReplace) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes)); AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); @@ -862,7 +883,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateDontReplace) { FormField(string16(), existing.key().name(), existing.key().value(), - string16()), + string16(), + 0), &changes, t)); AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2)); @@ -1231,7 +1253,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_OneResult) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, Time::FromTimeT(start))); timestamps1.push_back(Time::FromTimeT(start)); @@ -1274,7 +1297,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoDistinct) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, Time::FromTimeT(start))); timestamps1.push_back(Time::FromTimeT(start)); @@ -1288,7 +1312,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoDistinct) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), - string16()), + string16(), + 0), &changes, Time::FromTimeT(start))); timestamps2.push_back(Time::FromTimeT(start)); @@ -1335,7 +1360,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoSame) { FormField(string16(), ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), - string16()), + string16(), + 0), &changes, Time::FromTimeT(start))); timestamps.push_back(Time::FromTimeT(start)); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 14fc353..ca7659d 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -863,13 +863,16 @@ struct ParamTraits<webkit_glue::FormField> { WriteParam(m, p.name()); WriteParam(m, p.value()); WriteParam(m, p.form_control_type()); + WriteParam(m, p.size()); } static bool Read(const Message* m, void** iter, param_type* p) { string16 label, name, value, form_control_type; + int size = 0; bool result = ReadParam(m, iter, &label); result = result && ReadParam(m, iter, &name); result = result && ReadParam(m, iter, &value); result = result && ReadParam(m, iter, &form_control_type); + result = result && ReadParam(m, iter, &size); if (!result) return false; @@ -877,6 +880,7 @@ struct ParamTraits<webkit_glue::FormField> { p->set_name(name); p->set_value(value); p->set_form_control_type(form_control_type); + p->set_size(size); return true; } static void Log(const param_type& p, std::wstring* l) { diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc index ebdccbc..12b6353 100644 --- a/chrome/renderer/form_manager.cc +++ b/chrome/renderer/form_manager.cc @@ -102,6 +102,11 @@ void FormManager::WebFormControlElementToFormField( field->set_name(element.nameForAutofill()); field->set_form_control_type(element.formControlType()); + if (element.formControlType() == WebString::fromUTF8("text")) { + const WebInputElement& input_element = element.toConst<WebInputElement>(); + field->set_size(input_element.size()); + } + if (!get_value) return; @@ -586,6 +591,24 @@ string16 FormManager::InferLabelForElement( } } } + + // Look for text node prior to <img> tag. + // Eg. Some Text<img/><input ...> + if (inferred_label.empty()) { + while (inferred_label.empty() && !previous.isNull()) { + if (previous.isTextNode()) { + inferred_label = previous.nodeValue(); + TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); + } else if (previous.isElementNode()) { + WebElement element = previous.to<WebElement>(); + if (!element.hasTagName("img")) + break; + } else { + break; + } + previous = previous.previousSibling(); + } + } } // If we didn't find paragraph, check for table cell case. diff --git a/chrome/renderer/form_manager_unittest.cc b/chrome/renderer/form_manager_unittest.cc index 2a5ca77..74d25be 100644 --- a/chrome/renderer/form_manager_unittest.cc +++ b/chrome/renderer/form_manager_unittest.cc @@ -55,18 +55,21 @@ TEST_F(FormManagerTest, WebFormElementToFormData) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, ExtractForms) { @@ -96,18 +99,21 @@ TEST_F(FormManagerTest, ExtractForms) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, ExtractMultipleForms) { @@ -141,13 +147,15 @@ TEST_F(FormManagerTest, ExtractMultipleForms) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[1]); + ASCIIToUTF16("submit"), + 0), + fields[1]); // Second form. const FormData& form2 = forms[1]; @@ -160,12 +168,14 @@ TEST_F(FormManagerTest, ExtractMultipleForms) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("second"), ASCIIToUTF16("Submit"), - ASCIIToUTF16("submit")), + ASCIIToUTF16("submit"), + 0), fields2[1]); } @@ -221,13 +231,15 @@ TEST_F(FormManagerTest, GetFormsAutocomplete) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[1]); + ASCIIToUTF16("submit"), + 0), + fields[1]); } TEST_F(FormManagerTest, GetFormsElementsEnabled) { @@ -258,13 +270,15 @@ TEST_F(FormManagerTest, GetFormsElementsEnabled) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("submit"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[1]); + ASCIIToUTF16("submit"), + 0), + fields[1]); } TEST_F(FormManagerTest, FindForm) { @@ -302,18 +316,21 @@ TEST_F(FormManagerTest, FindForm) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, FillForm) { @@ -351,18 +368,21 @@ TEST_F(FormManagerTest, FillForm) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); // Fill the form. form.fields[0].set_value(ASCIIToUTF16("Wyatt")); @@ -382,17 +402,20 @@ TEST_F(FormManagerTest, FillForm) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Wyatt"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Earp"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), + ASCIIToUTF16("submit"), + 0), fields2[2]); } @@ -450,18 +473,21 @@ TEST_F(FormManagerTest, Labels) { EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, LabelsWithSpans) { @@ -493,18 +519,21 @@ TEST_F(FormManagerTest, LabelsWithSpans) { EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } // This test is different from FormManagerTest.Labels in that the label elements @@ -540,18 +569,21 @@ TEST_F(FormManagerTest, InvalidLabels) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } // This test has three form control elements, only one of which has a label @@ -588,18 +620,21 @@ TEST_F(FormManagerTest, OneLabelElementFirstControlElementDisabled) { EXPECT_EQ(FormField(ASCIIToUTF16("Middle name:"), ASCIIToUTF16("middlename"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, LabelsInferredFromText) { @@ -631,18 +666,21 @@ TEST_F(FormManagerTest, LabelsInferredFromText) { EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, LabelsInferredFromParagraph) { @@ -674,18 +712,21 @@ TEST_F(FormManagerTest, LabelsInferredFromParagraph) { EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, LabelsInferredFromTableCell) { @@ -728,18 +769,21 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCell) { EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { @@ -801,21 +845,24 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { EXPECT_EQ(FormField(ASCIIToUTF16("First name:"), ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); } -TEST_F(FormManagerTest, InferredLabelsWithSameName) { +TEST_F(FormManagerTest, LabelsInferredWithSameName) { LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" " Address Line 1:" " <INPUT type=\"text\" name=\"Address\"/>" @@ -844,18 +891,95 @@ TEST_F(FormManagerTest, InferredLabelsWithSameName) { EXPECT_EQ(FormField(ASCIIToUTF16("Address Line 1:"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Address Line 2:"), ASCIIToUTF16("Address"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); +} + +TEST_F(FormManagerTest, LabelsInferredWithImageTags) { + LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" + " Phone:" + " <input type=\"text\" name=\"dayphone1\">" + " <img/>" + " -" + " <img/>" + " <input type=\"text\" name=\"dayphone2\">" + " <img/>" + " -" + " <img/>" + " <input type=\"text\" name=\"dayphone3\">" + " ext.:" + " <input type=\"text\" name=\"dayphone4\">" + " <input type=\"text\" name=\"dummy\">" + " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" + "</FORM>"); + + WebFrame* frame = GetMainFrame(); + ASSERT_NE(static_cast<WebFrame*>(NULL), frame); + + WebVector<WebFormElement> forms; + frame->forms(forms); + ASSERT_EQ(1U, forms.size()); + + FormData form; + EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], + FormManager::REQUIRE_NONE, + true, + &form)); + EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); + EXPECT_EQ(GURL(frame->url()), form.origin); + EXPECT_EQ(GURL("http://cnn.com"), form.action); + + const std::vector<FormField>& fields = form.fields; + ASSERT_EQ(6U, fields.size()); + EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), + ASCIIToUTF16("dayphone1"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[0]); + EXPECT_EQ(FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone2"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[1]); + EXPECT_EQ(FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone3"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[2]); + EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), + ASCIIToUTF16("dayphone4"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[3]); + EXPECT_EQ(FormField(string16(), + ASCIIToUTF16("dummy"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[4]); + EXPECT_EQ(FormField(string16(), + ASCIIToUTF16("reply-send"), + ASCIIToUTF16("Send"), + ASCIIToUTF16("submit"), + 0), + fields[5]); } TEST_F(FormManagerTest, FillFormMaxLength) { @@ -893,18 +1017,21 @@ TEST_F(FormManagerTest, FillFormMaxLength) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); // Fill the form. form.fields[0].set_value(ASCIIToUTF16("Brother")); @@ -925,19 +1052,22 @@ TEST_F(FormManagerTest, FillFormMaxLength) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Broth"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[0]); EXPECT_EQ(ASCIIToUTF16("Broth"), fields2[0].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonat"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[1]); EXPECT_EQ(ASCIIToUTF16("Jonat"), fields2[1].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), + ASCIIToUTF16("submit"), + 0), fields2[2]); } @@ -979,18 +1109,21 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); // Fill the form. form.fields[0].set_value(ASCIIToUTF16("Brother")); @@ -1012,19 +1145,22 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[0]); EXPECT_EQ(ASCIIToUTF16("Brother"), fields2[0].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[1]); EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields2[1].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), + ASCIIToUTF16("submit"), + 0), fields2[2]); } @@ -1063,25 +1199,29 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) { FormField field1(string16(), ASCIIToUTF16("prefix"), string16(), - ASCIIToUTF16("text")); + ASCIIToUTF16("text"), + 0); form->fields.insert(form->fields.begin(), field1); FormField field2(string16(), ASCIIToUTF16("hidden"), string16(), - ASCIIToUTF16("text")); + ASCIIToUTF16("text"), + 0); form->fields.insert(form->fields.begin() + 2, field2); FormField field3(string16(), ASCIIToUTF16("second"), string16(), - ASCIIToUTF16("text")); + ASCIIToUTF16("text"), + 0); form->fields.insert(form->fields.begin() + 4, field3); FormField field4(string16(), ASCIIToUTF16("postfix"), string16(), - ASCIIToUTF16("text")); + ASCIIToUTF16("text"), + 0); form->fields.insert(form->fields.begin() + 6, field4); // Fill the form. @@ -1113,26 +1253,30 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("middlename"), ASCIIToUTF16("Joseph"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), - ASCIIToUTF16("text")), - fields[2]); + ASCIIToUTF16("text"), + 0), + fields[2]); EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[3]); + ASCIIToUTF16("submit"), + 0), + fields[3]); } // This test sends a FormData object to FillForm with fewer fields than are in @@ -1196,50 +1340,58 @@ TEST_F(FormManagerTest, FillFormFewerFormDataFields) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("prefix"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(string16(), fields[0].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(ASCIIToUTF16("Brother"), fields[1].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("hidden"), string16(), - ASCIIToUTF16("text")), - fields[2]); + ASCIIToUTF16("text"), + 0), + fields[2]); EXPECT_EQ(string16(), fields[2].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("middlename"), ASCIIToUTF16("Joseph"), - ASCIIToUTF16("text")), - fields[3]); + ASCIIToUTF16("text"), + 0), + fields[3]); EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[3].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("second"), string16(), - ASCIIToUTF16("text")), - fields[4]); + ASCIIToUTF16("text"), + 0), + fields[4]); EXPECT_EQ(string16(), fields[4].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), - ASCIIToUTF16("text")), - fields[5]); + ASCIIToUTF16("text"), + 0), + fields[5]); EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[5].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("postfix"), string16(), - ASCIIToUTF16("text")), - fields[6]); + ASCIIToUTF16("text"), + 0), + fields[6]); EXPECT_EQ(string16(), fields[6].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[7]); + ASCIIToUTF16("submit"), + 0), + fields[7]); } // This test sends a FormData object to FillForm with fewer fields than are in @@ -1297,32 +1449,37 @@ TEST_F(FormManagerTest, FillFormExtraFieldInCache) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("middlename"), ASCIIToUTF16("Joseph"), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), - ASCIIToUTF16("text")), - fields[2]); + ASCIIToUTF16("text"), + 0), + fields[2]); EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("postfix"), string16(), - ASCIIToUTF16("text")), - fields[3]); + ASCIIToUTF16("text"), + 0), + fields[3]); EXPECT_EQ(string16(), fields[3].value()); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[4]); + ASCIIToUTF16("submit"), + 0), + fields[4]); } TEST_F(FormManagerTest, FillFormEmptyName) { @@ -1360,18 +1517,21 @@ TEST_F(FormManagerTest, FillFormEmptyName) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); // Fill the form. form.fields[0].set_value(ASCIIToUTF16("Wyatt")); @@ -1391,17 +1551,20 @@ TEST_F(FormManagerTest, FillFormEmptyName) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Wyatt"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Earp"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), + ASCIIToUTF16("submit"), + 0), fields2[2]); } @@ -1446,18 +1609,21 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("apple"), string16(), - ASCIIToUTF16("text")), - fields[0]); + ASCIIToUTF16("text"), + 0), + fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("banana"), string16(), - ASCIIToUTF16("text")), - fields[1]); + ASCIIToUTF16("text"), + 0), + fields[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), - fields[2]); + ASCIIToUTF16("submit"), + 0), + fields[2]); // Fill the form. form.fields[0].set_value(ASCIIToUTF16("Red")); @@ -1477,18 +1643,166 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) { EXPECT_EQ(FormField(string16(), ASCIIToUTF16("apple"), ASCIIToUTF16("Red"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("banana"), ASCIIToUTF16("Yellow"), - ASCIIToUTF16("text")), + ASCIIToUTF16("text"), + 0), fields2[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), - ASCIIToUTF16("submit")), + ASCIIToUTF16("submit"), + 0), fields2[2]); } +TEST_F(FormManagerTest, ThreePartPhone) { + LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" + " Phone:" + " <input type=\"text\" name=\"dayphone1\">" + " -" + " <input type=\"text\" name=\"dayphone2\">" + " -" + " <input type=\"text\" name=\"dayphone3\">" + " ext.:" + " <input type=\"text\" name=\"dayphone4\">" + " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" + "</FORM>"); + + + WebFrame* frame = GetMainFrame(); + ASSERT_NE(static_cast<WebFrame*>(NULL), frame); + + WebVector<WebFormElement> forms; + frame->forms(forms); + ASSERT_EQ(1U, forms.size()); + + FormData form; + EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], + FormManager::REQUIRE_NONE, + true, + &form)); + EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); + EXPECT_EQ(GURL(frame->url()), form.origin); + EXPECT_EQ(GURL("http://cnn.com"), form.action); + + const std::vector<FormField>& fields = form.fields; + ASSERT_EQ(5U, fields.size()); + EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), + ASCIIToUTF16("dayphone1"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[0]); + EXPECT_EQ(FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone2"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[1]); + EXPECT_EQ(FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone3"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[2]); + EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), + ASCIIToUTF16("dayphone4"), + string16(), + ASCIIToUTF16("text"), + 0), + fields[3]); + EXPECT_EQ(FormField(string16(), + ASCIIToUTF16("reply-send"), + ASCIIToUTF16("Send"), + ASCIIToUTF16("submit"), + 0), + fields[4]); +} + + +TEST_F(FormManagerTest, SizeFields) { + LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" + " Phone:" + " <input type=\"text\" size=\"3\" name=\"dayphone1\">" + " -" + " <input type=\"text\" size=\"3\" name=\"dayphone2\">" + " -" + " <input type=\"text\" size=\"4\" name=\"dayphone3\">" + " ext.:" + " <input type=\"text\" size=\"5\" name=\"dayphone4\">" + " <input type=\"text\" name=\"default1\">" + " <input type=\"text\" size=\"-1\" name=\"invalid1\">" + " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" + "</FORM>"); + + + WebFrame* frame = GetMainFrame(); + ASSERT_NE(static_cast<WebFrame*>(NULL), frame); + + WebVector<WebFormElement> forms; + frame->forms(forms); + ASSERT_EQ(1U, forms.size()); + + FormData form; + EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], + FormManager::REQUIRE_NONE, + true, + &form)); + EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); + EXPECT_EQ(GURL(frame->url()), form.origin); + EXPECT_EQ(GURL("http://cnn.com"), form.action); + + const std::vector<FormField>& fields = form.fields; + ASSERT_EQ(7U, fields.size()); + EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), + ASCIIToUTF16("dayphone1"), + string16(), + ASCIIToUTF16("text"), + 3), + fields[0]); + EXPECT_EQ(FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone2"), + string16(), + ASCIIToUTF16("text"), + 3), + fields[1]); + EXPECT_EQ(FormField(ASCIIToUTF16("-"), + ASCIIToUTF16("dayphone3"), + string16(), + ASCIIToUTF16("text"), + 4), + fields[2]); + EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), + ASCIIToUTF16("dayphone4"), + string16(), + ASCIIToUTF16("text"), + 5), + fields[3]); + // When unspecified |size|, default is 20. + EXPECT_EQ(FormField(string16(), + ASCIIToUTF16("default1"), + string16(), + ASCIIToUTF16("text"), + 20), + fields[4]); + // When invalid |size| same value is returned. + EXPECT_EQ(FormField(string16(), + ASCIIToUTF16("invalid1"), + string16(), + ASCIIToUTF16("text"), + -1), + fields[5]); + EXPECT_EQ(FormField(string16(), + ASCIIToUTF16("reply-send"), + ASCIIToUTF16("Send"), + ASCIIToUTF16("submit"), + 0), + fields[6]); +} + } // namespace |