diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-29 22:27:16 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-29 22:27:16 +0000 |
commit | 3bb80e49ebd2f095b829e27135962a0aa4591e87 (patch) | |
tree | cce992fadfc3f39a776154372e0d8cf38bdd416e | |
parent | c8965289996843e686084e86036db4cfe5b1713f (diff) | |
download | chromium_src-3bb80e49ebd2f095b829e27135962a0aa4591e87.zip chromium_src-3bb80e49ebd2f095b829e27135962a0aa4591e87.tar.gz chromium_src-3bb80e49ebd2f095b829e27135962a0aa4591e87.tar.bz2 |
Once a form has been partially autofilled, autofill should only update fields one at a time.
BUG=63437, 62638
TEST=unit_tests --gtest_filter=AutoFillManagerTest.*
Review URL: http://codereview.chromium.org/5334005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67599 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 1951 insertions, 1476 deletions
diff --git a/chrome/browser/autocomplete_history_manager_unittest.cc b/chrome/browser/autocomplete_history_manager_unittest.cc index b1ef109..409225f2 100644 --- a/chrome/browser/autocomplete_history_manager_unittest.cc +++ b/chrome/browser/autocomplete_history_manager_unittest.cc @@ -58,7 +58,8 @@ TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { ASCIIToUTF16("ccnum"), ASCIIToUTF16("4012888888881881"), ASCIIToUTF16("text"), - 20); + 20, + false); form.fields.push_back(valid_cc); EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); @@ -81,7 +82,8 @@ TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { ASCIIToUTF16("ccnum"), ASCIIToUTF16("4580123456789012"), ASCIIToUTF16("text"), - 20); + 20, + false); form.fields.push_back(invalid_cc); EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); @@ -101,7 +103,8 @@ TEST_F(AutocompleteHistoryManagerTest, SSNValue) { ASCIIToUTF16("ssn"), ASCIIToUTF16("078-05-1120"), ASCIIToUTF16("text"), - 20); + 20, + false); form.fields.push_back(ssn); EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc index 51509f7..d6a42db 100644 --- a/chrome/browser/autofill/address_field_unittest.cc +++ b/chrome/browser/autofill/address_field_unittest.cc @@ -46,7 +46,8 @@ TEST_F(AddressFieldTest, ParseOneLineAddress) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -66,7 +67,8 @@ TEST_F(AddressFieldTest, ParseOneLineAddressBilling) { ASCIIToUTF16("billingAddress"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -86,7 +88,8 @@ TEST_F(AddressFieldTest, ParseOneLineAddressShipping) { ASCIIToUTF16("shippingAddress"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -107,7 +110,8 @@ TEST_F(AddressFieldTest, ParseOneLineAddressEcml) { ASCIIToUTF16(kEcmlShipToAddress1), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -127,14 +131,16 @@ TEST_F(AddressFieldTest, ParseTwoLineAddress) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), string16(), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -157,21 +163,24 @@ TEST_F(AddressFieldTest, ParseThreeLineAddress) { ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line3"), ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -197,7 +206,8 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressEcml) { ASCIIToUTF16(kEcmlShipToAddress1), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField( @@ -205,7 +215,8 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressEcml) { ASCIIToUTF16(kEcmlShipToAddress2), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -228,7 +239,8 @@ TEST_F(AddressFieldTest, ParseCity) { ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("city1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -248,7 +260,8 @@ TEST_F(AddressFieldTest, ParseCityEcml) { ASCIIToUTF16(kEcmlShipToCity), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("city1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -268,7 +281,8 @@ TEST_F(AddressFieldTest, ParseState) { ASCIIToUTF16("state"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("state1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -289,7 +303,8 @@ TEST_F(AddressFieldTest, ParseStateEcml) { ASCIIToUTF16(kEcmlShipToStateProv), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("state1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -309,7 +324,8 @@ TEST_F(AddressFieldTest, ParseZip) { ASCIIToUTF16("zip"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("zip1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -330,7 +346,8 @@ TEST_F(AddressFieldTest, ParseZipEcml) { ASCIIToUTF16(kEcmlShipToPostalCode), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("zip1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -352,7 +369,8 @@ TEST_F(AddressFieldTest, ParseStateAndZipOneLabel) { ASCIIToUTF16("state"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("state"))); list_.push_back( new AutoFillField( @@ -361,7 +379,8 @@ TEST_F(AddressFieldTest, ParseStateAndZipOneLabel) { ASCIIToUTF16("zip"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("zip"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -384,7 +403,8 @@ TEST_F(AddressFieldTest, ParseCountry) { ASCIIToUTF16("country"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("country1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -404,7 +424,8 @@ TEST_F(AddressFieldTest, ParseCountryEcml) { ASCIIToUTF16(kEcmlShipToCountry), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("country1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -424,14 +445,16 @@ TEST_F(AddressFieldTest, ParseTwoLineAddressMissingLabel) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("bogus"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("addr2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -454,7 +477,8 @@ TEST_F(AddressFieldTest, ParseCompany) { ASCIIToUTF16("company"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("company1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -475,7 +499,8 @@ TEST_F(AddressFieldTest, ParseCompanyEcml) { ASCIIToUTF16(kEcmlShipToCompanyName), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("company1"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/autofill/autofill_common_test.cc b/chrome/browser/autofill/autofill_common_test.cc index c4c8482..32041cc 100644 --- a/chrome/browser/autofill/autofill_common_test.cc +++ b/chrome/browser/autofill/autofill_common_test.cc @@ -21,7 +21,8 @@ void CreateTestFormField(const char* label, const char* type, webkit_glue::FormField* field) { *field = webkit_glue::FormField(ASCIIToUTF16(label), ASCIIToUTF16(name), - ASCIIToUTF16(value), ASCIIToUTF16(type), 0); + ASCIIToUTF16(value), ASCIIToUTF16(type), 0, + false); } inline void check_and_set( diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc index deb9b49..68173c6 100644 --- a/chrome/browser/autofill/autofill_download_unittest.cc +++ b/chrome/browser/autofill/autofill_download_unittest.cc @@ -101,37 +101,44 @@ TEST(AutoFillDownloadTest, QueryAndUploadTest) { ASCIIToUTF16("username"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), ASCIIToUTF16("email2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), ASCIIToUTF16("password"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); FormStructure *form_structure = new FormStructure(form); ScopedVector<FormStructure> form_structures; @@ -142,22 +149,26 @@ TEST(AutoFillDownloadTest, QueryAndUploadTest) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address2"), ASCIIToUTF16("address2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("city"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); 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 42051f7..e04fe1f 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -72,6 +72,51 @@ void RemoveDuplicateElements( unique_ids->assign(unique_ids_copy.begin(), unique_ids_copy.end()); } +// Precondition: |form_structure| and |form| should correspond to the same +// logical form. Returns true if the relevant portion of |form| is auto-filled. +// If |is_filling_credit_card|, the relevant portion is the credit card portion; +// otherwise it is the address and contact info portion. +bool FormIsAutoFilled(const FormStructure* form_structure, + const webkit_glue::FormData& form, + bool is_filling_credit_card) { + // TODO(isherman): It would be nice to share most of this code with the loop + // in |FillAutoFillFormData()|, but I don't see a particularly clean way to do + // that. + + // The list of fields in |form_structure| and |form.fields| often match + // directly and we can fill these corresponding fields; however, when the + // |form_structure| and |form.fields| do not match directly we search + // ahead in the |form_structure| for the matching field. + for (size_t i = 0, j = 0; + i < form_structure->field_count() && j < form.fields.size(); + j++) { + size_t k = i; + + // Search forward in the |form_structure| for a corresponding field. + while (k < form_structure->field_count() && + *form_structure->field(k) != form.fields[j]) { + k++; + } + + // If we didn't find a match, continue on to the next |form| field. + if (k >= form_structure->field_count()) + continue; + + AutoFillType autofill_type(form_structure->field(k)->type()); + bool is_credit_card_field = + autofill_type.group() == AutoFillType::CREDIT_CARD; + if (is_filling_credit_card == is_credit_card_field && + form.fields[j].is_autofilled()) + return true; + + // We found a matching field in the |form_structure| so we + // proceed to the next |form| field, and the next |form_structure|. + ++i; + } + + return false; +} + bool FormIsHTTPS(FormStructure* form) { return form->source_url().SchemeIs(chrome::kHttpsScheme); } @@ -145,61 +190,38 @@ void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) { ParseForms(forms); } -bool AutoFillManager::GetAutoFillSuggestions(bool field_autofilled, +bool AutoFillManager::GetAutoFillSuggestions(const FormData& form, const FormField& field) { - if (!IsAutoFillEnabled()) - return false; - - RenderViewHost* host = tab_contents_->render_view_host(); - if (!host) - return false; - - if (personal_data_->profiles().empty() && - personal_data_->credit_cards().empty()) - return false; - - // Loops through the cached FormStructures looking for the FormStructure that - // contains |field| and the associated AutoFillFieldType. - FormStructure* form = NULL; + RenderViewHost* host = NULL; + FormStructure* form_structure = NULL; AutoFillField* autofill_field = NULL; - for (std::vector<FormStructure*>::iterator form_iter = - form_structures_.begin(); - form_iter != form_structures_.end() && !autofill_field; ++form_iter) { - form = *form_iter; - - // Don't send suggestions for forms that aren't auto-fillable. - if (!form->IsAutoFillable(false)) - continue; + if (!GetHost(personal_data_->profiles(), + personal_data_->credit_cards(), + &host) || + !FindCachedFormAndField(form, field, &form_structure, &autofill_field)) + return false; - for (std::vector<AutoFillField*>::const_iterator iter = form->begin(); - iter != form->end(); ++iter) { - // The field list is terminated with a NULL AutoFillField, so don't try to - // dereference it. - if (!*iter) - break; + DCHECK(host); + DCHECK(form_structure); + DCHECK(autofill_field); - if ((**iter) == field) { - autofill_field = *iter; - break; - } - } - } - - if (!autofill_field) + // Don't send suggestions for forms that aren't auto-fillable. + if (!form_structure->IsAutoFillable(false)) return false; std::vector<string16> values; std::vector<string16> labels; std::vector<string16> icons; std::vector<int> unique_ids; - AutoFillType type(autofill_field->type()); - if (type.group() == AutoFillType::CREDIT_CARD) { + AutoFillType type(autofill_field->type()); + bool is_filling_credit_card = (type.group() == AutoFillType::CREDIT_CARD); + if (is_filling_credit_card) { GetCreditCardSuggestions( - form, field, type, &values, &labels, &icons, &unique_ids); + form_structure, field, type, &values, &labels, &icons, &unique_ids); } else { GetProfileSuggestions( - form, field, type, &values, &labels, &icons, &unique_ids); + form_structure, field, type, &values, &labels, &icons, &unique_ids); } DCHECK_EQ(values.size(), labels.size()); @@ -210,23 +232,16 @@ bool AutoFillManager::GetAutoFillSuggestions(bool field_autofilled, if (values.empty()) return false; - // Don't provide AutoFill suggestions when AutoFill is disabled, but provide a - // warning to the user. - if (!form->IsAutoFillable(true)) { - values.assign( - 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); - labels.assign(1, string16()); - icons.assign(1, string16()); - unique_ids.assign(1, -1); - host->AutoFillSuggestionsReturned(values, labels, icons, unique_ids); - return true; - } - - // Don't provide credit card suggestions for non-HTTPS pages, but provide a - // warning to the user. - if (!FormIsHTTPS(form) && type.group() == AutoFillType::CREDIT_CARD) { - values.assign( - 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION)); + // Don't provide AutoFill suggestions when AutoFill is disabled, and don't + // provide credit card suggestions for non-HTTPS pages. However, provide a + // warning to the user in these cases. + int warning = 0; + if (!form_structure->IsAutoFillable(true)) + warning = IDS_AUTOFILL_WARNING_FORM_DISABLED; + else if (is_filling_credit_card && !FormIsHTTPS(form_structure)) + warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; + if (warning) { + values.assign(1, l10n_util::GetStringUTF16(warning)); labels.assign(1, string16()); icons.assign(1, string16()); unique_ids.assign(1, -1); @@ -235,10 +250,10 @@ bool AutoFillManager::GetAutoFillSuggestions(bool field_autofilled, } // If the form is auto-filled and the renderer is querying for suggestions, - // then the user is editing the value of a field. In this case, mimick - // autocomplete. In particular, don't display labels, as that information is + // then the user is editing the value of a field. In this case, mimick + // autocomplete. In particular, don't display labels, as that information is // redundant. In addition, remove duplicate values. - if (field_autofilled) { + if (FormIsAutoFilled(form_structure, form, is_filling_credit_card)) { RemoveDuplicateElements(&values, &unique_ids); labels.assign(values.size(), string16()); icons.assign(values.size(), string16()); @@ -250,39 +265,20 @@ bool AutoFillManager::GetAutoFillSuggestions(bool field_autofilled, bool AutoFillManager::FillAutoFillFormData(int query_id, const FormData& form, + const FormField& field, int unique_id) { - if (!IsAutoFillEnabled()) - return false; - - RenderViewHost* host = tab_contents_->render_view_host(); - if (!host) - return false; - const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); - - // No data to return if the profiles are empty. - if (profiles.empty() && credit_cards.empty()) - return false; - - // Find the FormStructure that corresponds to |form|. - FormData result = form; + RenderViewHost* host = NULL; FormStructure* form_structure = NULL; - for (std::vector<FormStructure*>::const_iterator iter = - form_structures_.begin(); - iter != form_structures_.end(); ++iter) { - if (**iter == form) { - form_structure = *iter; - break; - } - } - - if (!form_structure) + AutoFillField* autofill_field = NULL; + if (!GetHost(profiles, credit_cards, &host) || + !FindCachedFormAndField(form, field, &form_structure, &autofill_field)) return false; - // No data to return if there are no auto-fillable fields. - if (!form_structure->autofill_count()) - return false; + DCHECK(host); + DCHECK(form_structure); + DCHECK(autofill_field); // Unpack the |unique_id| into component parts. std::string cc_guid; @@ -319,6 +315,30 @@ bool AutoFillManager::FillAutoFillFormData(int query_id, if (!profile && !credit_card) return false; + FormData result = form; + + // If the form is auto-filled, we should fill |field| but not the rest of the + // form. + if (FormIsAutoFilled(form_structure, form, (credit_card != NULL))) { + for (std::vector<FormField>::iterator iter = result.fields.begin(); + iter != result.fields.end(); ++iter) { + if ((*iter) == field) { + AutoFillType autofill_type(autofill_field->type()); + if (credit_card && + autofill_type.group() == AutoFillType::CREDIT_CARD) { + FillCreditCardFormField(credit_card, autofill_type, &(*iter)); + } else if (profile && + autofill_type.group() != AutoFillType::CREDIT_CARD) { + FillFormField(profile, autofill_type, &(*iter)); + } + break; + } + } + + host->AutoFillFormDataFilled(query_id, result); + return true; + } + // The list of fields in |form_structure| and |result.fields| often match // directly and we can fill these corresponding fields; however, when the // |form_structure| and |result.fields| do not match directly we search @@ -346,7 +366,8 @@ bool AutoFillManager::FillAutoFillFormData(int query_id, if (credit_card && autofill_type.group() == AutoFillType::CREDIT_CARD) { FillCreditCardFormField(credit_card, autofill_type, &result.fields[j]); - } else if (profile) { + } else if (profile && + autofill_type.group() != AutoFillType::CREDIT_CARD) { FillFormField(profile, autofill_type, &result.fields[j]); } @@ -488,6 +509,67 @@ AutoFillManager::AutoFillManager(TabContents* tab_contents, DCHECK(tab_contents); } +bool AutoFillManager::GetHost(const std::vector<AutoFillProfile*>& profiles, + const std::vector<CreditCard*>& credit_cards, + RenderViewHost** host) { + if (!IsAutoFillEnabled()) + return false; + + // No autofill data to return if the profiles are empty. + if (profiles.empty() && credit_cards.empty()) + return false; + + *host = tab_contents_->render_view_host(); + if (!(*host)) + return false; + + return true; +} + +bool AutoFillManager::FindCachedFormAndField(const FormData& form, + const FormField& field, + FormStructure** form_structure, + AutoFillField** autofill_field) { + // Find the FormStructure that corresponds to |form|. + *form_structure = NULL; + for (std::vector<FormStructure*>::const_iterator iter = + form_structures_.begin(); + iter != form_structures_.end(); ++iter) { + if (**iter == form) { + *form_structure = *iter; + break; + } + } + + if (!(*form_structure)) + return false; + + // No data to return if there are no auto-fillable fields. + if (!(*form_structure)->autofill_count()) + return false; + + // Find the AutoFillField that corresponds to |field|. + *autofill_field = NULL; + for (std::vector<AutoFillField*>::const_iterator iter = + (*form_structure)->begin(); + iter != (*form_structure)->end(); ++iter) { + // The field list is terminated with a NULL AutoFillField, so don't try to + // dereference it. + if (!*iter) + break; + + if ((**iter) == field) { + *autofill_field = *iter; + break; + } + } + + if (!(*autofill_field)) + return false; + + return true; +} + void AutoFillManager::GetProfileSuggestions(FormStructure* form, const FormField& field, AutoFillType type, @@ -561,6 +643,7 @@ void AutoFillManager::FillCreditCardFormField(const CreditCard* credit_card, AutoFillType type, webkit_glue::FormField* field) { DCHECK(credit_card); + DCHECK(type.group() == AutoFillType::CREDIT_CARD); DCHECK(field); if (field->form_control_type() == ASCIIToUTF16("select-one")) @@ -573,6 +656,7 @@ void AutoFillManager::FillFormField(const AutoFillProfile* profile, AutoFillType type, webkit_glue::FormField* field) { DCHECK(profile); + DCHECK(type.group() != AutoFillType::CREDIT_CARD); DCHECK(field); if (type.subgroup() == AutoFillType::PHONE_NUMBER) { diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index 835f643..791d171 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -50,10 +50,11 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill, // RenderViewHostDelegate::AutoFill implementation: virtual void FormSubmitted(const webkit_glue::FormData& form); virtual void FormsSeen(const std::vector<webkit_glue::FormData>& forms); - virtual bool GetAutoFillSuggestions(bool field_autofilled, + virtual bool GetAutoFillSuggestions(const webkit_glue::FormData& form, const webkit_glue::FormField& field); virtual bool FillAutoFillFormData(int query_id, const webkit_glue::FormData& form, + const webkit_glue::FormField& field, int unique_id); virtual void ShowAutoFillDialog(); @@ -106,6 +107,21 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill, void UnpackGUIDs(int id, std::string* cc_guid, std::string* profile_guid); private: + // Fills |host| with the RenderViewHost for this tab. + // Returns false if AutoFill is disabled or if the host is unavailable. + bool GetHost(const std::vector<AutoFillProfile*>& profiles, + const std::vector<CreditCard*>& credit_cards, + RenderViewHost** host) WARN_UNUSED_RESULT; + + // Fills |form_structure| and |autofill_field| with the cached elements + // corresponding to |form| and |field|. Returns false if the cached elements + // were not found. + bool FindCachedFormAndField( + const webkit_glue::FormData& form, + const webkit_glue::FormField& field, + FormStructure** form_structure, + AutoFillField** autofill_field) WARN_UNUSED_RESULT; + // Returns a list of values from the stored profiles that match |type| and the // value of |field| and returns the labels of the matching profiles. |labels| // is filled with the Profile label. @@ -190,6 +206,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill, FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillCreditCardForm); FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressForm); FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressAndCreditCardForm); + FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAutoFilledForm); FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillPhoneNumber); FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesRemoveField); FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesAddField); diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index 228bbdb..506c7cb 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -32,6 +32,13 @@ #include "webkit/glue/form_field.h" using webkit_glue::FormData; +using webkit_glue::FormField; + +namespace { + +// The page ID sent to the AutoFillManager from the RenderView, used to send +// an IPC message back to the renderer. +const int kDefaultPageID = 137; typedef Tuple5<int, std::vector<string16>, @@ -53,8 +60,17 @@ class TestPersonalDataManager : public PersonalDataManager { AutoFillProfile* GetLabeledProfile(const char* label) { for (std::vector<AutoFillProfile *>::iterator it = web_profiles_.begin(); it != web_profiles_.end(); ++it) { - if (!(*it)->Label().compare(ASCIIToUTF16(label))) - return *it; + if (!(*it)->Label().compare(ASCIIToUTF16(label))) + return *it; + } + return NULL; + } + + CreditCard* GetLabeledCreditCard(const char* label) { + for (std::vector<CreditCard *>::iterator it = credit_cards_.begin(); + it != credit_cards_.end(); ++it) { + if (!(*it)->Label().compare(ASCIIToUTF16(label))) + return *it; } return NULL; } @@ -118,62 +134,6 @@ class TestPersonalDataManager : public PersonalDataManager { DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); }; -class TestAutoFillManager : public AutoFillManager { - public: - TestAutoFillManager(TabContents* tab_contents, - TestPersonalDataManager* personal_manager) - : AutoFillManager(tab_contents, NULL), - autofill_enabled_(true) { - test_personal_data_ = personal_manager; - set_personal_data_manager(personal_manager); - // Download manager requests are disabled for purposes of this unit-test. - // These request are tested in autofill_download_unittest.cc. - set_disable_download_manager_requests(true); - } - - virtual bool IsAutoFillEnabled() const { return autofill_enabled_; } - - void set_autofill_enabled(bool autofill_enabled) { - autofill_enabled_ = autofill_enabled; - } - - AutoFillProfile* GetLabeledProfile(const char* label) { - return test_personal_data_->GetLabeledProfile(label); - } - - void AddProfile(AutoFillProfile* profile) { - test_personal_data_->AddProfile(profile); - } - - int GetPackedCreditCardID(int credit_card_id) { - return PackGUIDs(IDToGUID(credit_card_id), std::string()); - } - - protected: - virtual int GUIDToID(const std::string& guid) OVERRIDE { - if (guid.empty()) - return 0; - - int id; - EXPECT_TRUE(base::StringToInt(guid.substr(guid.rfind("-") + 1), &id)); - return id; - } - - virtual const std::string IDToGUID(int id) OVERRIDE { - EXPECT_TRUE(id >= 0); - if (id <= 0) - return std::string(); - - return base::StringPrintf("00000000-0000-0000-0000-%012d", id); - } - - private: - TestPersonalDataManager* test_personal_data_; - bool autofill_enabled_; - - DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); -}; - // Populates |form| with data corresponding to a simple address form. // Note that this actually appends fields to the form data, which can be useful // for building up more complex test forms. @@ -184,7 +144,7 @@ void CreateTestAddressFormData(FormData* form) { form->action = GURL("http://myform.com/submit.html"); form->user_submitted = true; - webkit_glue::FormField field; + FormField field; autofill_test::CreateTestFormField( "First Name", "firstname", "", "text", &field); form->fields.push_back(field); @@ -216,6 +176,9 @@ void CreateTestAddressFormData(FormData* form) { "Phone Number", "phonenumber", "", "text", &field); form->fields.push_back(field); autofill_test::CreateTestFormField( + "Fax", "fax", "", "text", &field); + form->fields.push_back(field); + autofill_test::CreateTestFormField( "Email", "email", "", "text", &field); form->fields.push_back(field); } @@ -235,7 +198,7 @@ void CreateTestCreditCardFormData(FormData* form, bool is_https) { } form->user_submitted = true; - webkit_glue::FormField field; + FormField field; autofill_test::CreateTestFormField( "Name on Card", "nameoncard", "", "text", &field); form->fields.push_back(field); @@ -250,6 +213,218 @@ void CreateTestCreditCardFormData(FormData* form, bool is_https) { form->fields.push_back(field); } +void ExpectSuggestions(int page_id, + const std::vector<string16>& values, + const std::vector<string16>& labels, + const std::vector<string16>& icons, + const std::vector<int>& unique_ids, + int expected_page_id, + size_t expected_num_suggestions, + const string16 expected_values[], + const string16 expected_labels[], + const string16 expected_icons[], + const int expected_unique_ids[]) { + EXPECT_EQ(expected_page_id, page_id); + ASSERT_EQ(expected_num_suggestions, values.size()); + ASSERT_EQ(expected_num_suggestions, labels.size()); + ASSERT_EQ(expected_num_suggestions, icons.size()); + ASSERT_EQ(expected_num_suggestions, unique_ids.size()); + for (size_t i = 0; i < expected_num_suggestions; ++i) { + SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); + EXPECT_EQ(expected_values[i], values[i]); + EXPECT_EQ(expected_labels[i], labels[i]); + EXPECT_EQ(expected_icons[i], icons[i]); + EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); + } +} + +// Verifies that the |filled_form| has been filled with the given data. +// Verifies address fields if |has_address_fields| is true, and verifies +// credit card fields if |has_credit_card_fields| is true. Verifies both if both +// are true. +void ExpectFilledForm(int page_id, + const FormData& filled_form, + int expected_page_id, + const char* first, + const char* middle, + const char* last, + const char* address1, + const char* address2, + const char* city, + const char* state, + const char* postal_code, + const char* country, + const char* phone, + const char* fax, + const char* email, + const char* name_on_card, + const char* card_number, + const char* expiration_month, + const char* expiration_year, + bool has_address_fields, + bool has_credit_card_fields) { + // The number of fields in the address and credit card forms created above. + const size_t kAddressFormSize = 12; + const size_t kCreditCardFormSize = 4; + + EXPECT_EQ(expected_page_id, page_id); + EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name); + EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method); + if (has_credit_card_fields) { + EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin); + EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action); + } else { + EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin); + EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action); + } + EXPECT_TRUE(filled_form.user_submitted); + + size_t form_size = 0; + if (has_address_fields) + form_size += kAddressFormSize; + if (has_credit_card_fields) + form_size += kCreditCardFormSize; + ASSERT_EQ(form_size, filled_form.fields.size()); + + FormField field; + if (has_address_fields) { + autofill_test::CreateTestFormField( + "First Name", "firstname", first, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[0])); + autofill_test::CreateTestFormField( + "Middle Name", "middlename", middle, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[1])); + autofill_test::CreateTestFormField( + "Last Name", "lastname", last, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[2])); + autofill_test::CreateTestFormField( + "Address Line 1", "addr1", address1, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[3])); + autofill_test::CreateTestFormField( + "Address Line 2", "addr2", address2, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[4])); + autofill_test::CreateTestFormField( + "City", "city", city, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[5])); + autofill_test::CreateTestFormField( + "State", "state", state, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[6])); + autofill_test::CreateTestFormField( + "Postal Code", "zipcode", postal_code, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[7])); + autofill_test::CreateTestFormField( + "Country", "country", country, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); + autofill_test::CreateTestFormField( + "Phone Number", "phonenumber", phone, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); + autofill_test::CreateTestFormField( + "Fax", "fax", fax, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); + autofill_test::CreateTestFormField( + "Email", "email", email, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); + } + + if (has_credit_card_fields) { + size_t offset = has_address_fields? kAddressFormSize : 0; + autofill_test::CreateTestFormField( + "Name on Card", "nameoncard", name_on_card, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); + autofill_test::CreateTestFormField( + "Card Number", "cardnumber", card_number, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); + autofill_test::CreateTestFormField( + "Expiration Date", "ccmonth", expiration_month, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); + autofill_test::CreateTestFormField( + "", "ccyear", expiration_year, "text", &field); + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); + } +} + +void ExpectFilledAddressFormElvis(int page_id, + const FormData& filled_form, + int expected_page_id, + bool has_credit_card_fields) { + ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", + "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", + "Tennessee", "38116", "USA", "12345678901", "", + "theking@gmail.com", "", "", "", "", true, + has_credit_card_fields); +} + +void ExpectFilledCreditCardFormElvis(int page_id, + const FormData& filled_form, + int expected_page_id, + bool has_address_fields) { + ExpectFilledForm(page_id, filled_form, expected_page_id, + "", "", "", "", "", "", "", "", "", "", "", "", + "Elvis Presley", "4234567890123456", "04", "2012", + has_address_fields, true); +} + +} // namespace + +class TestAutoFillManager : public AutoFillManager { + public: + TestAutoFillManager(TabContents* tab_contents, + TestPersonalDataManager* personal_manager) + : AutoFillManager(tab_contents, NULL), + autofill_enabled_(true) { + test_personal_data_ = personal_manager; + set_personal_data_manager(personal_manager); + // Download manager requests are disabled for purposes of this unit test. + // These requests are tested in autofill_download_unittest.cc. + set_disable_download_manager_requests(true); + } + + virtual bool IsAutoFillEnabled() const { return autofill_enabled_; } + + void set_autofill_enabled(bool autofill_enabled) { + autofill_enabled_ = autofill_enabled; + } + + AutoFillProfile* GetLabeledProfile(const char* label) { + return test_personal_data_->GetLabeledProfile(label); + } + + CreditCard* GetLabeledCreditCard(const char* label) { + return test_personal_data_->GetLabeledCreditCard(label); + } + + void AddProfile(AutoFillProfile* profile) { + test_personal_data_->AddProfile(profile); + } + + int GetPackedCreditCardID(int credit_card_id) { + return PackGUIDs(IDToGUID(credit_card_id), std::string()); + } + + virtual int GUIDToID(const std::string& guid) OVERRIDE { + if (guid.empty()) + return 0; + + int id; + EXPECT_TRUE(base::StringToInt(guid.substr(guid.rfind("-") + 1), &id)); + return id; + } + + virtual const std::string IDToGUID(int id) OVERRIDE { + EXPECT_TRUE(id >= 0); + if (id <= 0) + return std::string(); + + return base::StringPrintf("00000000-0000-0000-0000-%012d", id); + } + + private: + TestPersonalDataManager* test_personal_data_; + bool autofill_enabled_; + + DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); +}; + class AutoFillManagerTest : public RenderViewHostTestHarness { public: AutoFillManagerTest() {} @@ -321,23 +496,15 @@ class AutoFillManagerTest : public RenderViewHostTestHarness { // Test that we return all address profile suggestions when all form fields are // empty. TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -351,43 +518,38 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); - ASSERT_EQ(2U, labels.size()); - // Inferred labels now include full first relevant field, which in this case - // the address #1. - EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); - EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); - EXPECT_EQ(2, unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("Elvis"), + ASCIIToUTF16("Charles") + }; + // Inferred labels include full first relevant field, which in this case is + // the address line 1. + string16 expected_labels[] = { + ASCIIToUTF16("3734 Elvis Presley Blvd."), + ASCIIToUTF16("123 Apple St.") + }; + string16 expected_icons[] = {string16(), string16()}; + int expected_unique_ids[] = {1, 2}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we return only matching address profile suggestions when the // selected form field has been partially filled out. TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "E", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + FormField field; + autofill_test::CreateTestFormField("First Name", "firstname", "E", "text", + &field); + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -401,19 +563,19 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(1U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - ASSERT_EQ(1U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); - ASSERT_EQ(1U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - ASSERT_EQ(1U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); + + string16 expected_values[] = {ASCIIToUTF16("Elvis")}; + string16 expected_labels[] = {ASCIIToUTF16("3734 Elvis Presley Blvd.")}; + string16 expected_icons[] = {string16()}; + int expected_unique_ids[] = {1}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we return no suggestions when the form has no relevant fields. TEST_F(AutoFillManagerTest, GetProfileSuggestionsUnknownFields) { + // Set up our form data. FormData form; form.name = ASCIIToUTF16("MyForm"); form.method = ASCIIToUTF16("POST"); @@ -421,81 +583,54 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsUnknownFields) { form.action = GURL("http://myform.com/submit.html"); form.user_submitted = true; - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "Username", "username", "", "text", &field); + FormField field; + autofill_test::CreateTestFormField("Username", "username", "", "text", + &field); form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Password", "password", "", "password", &field); + autofill_test::CreateTestFormField("Password", "password", "", "password", + &field); form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Quest", "quest", "", "quest", &field); + autofill_test::CreateTestFormField("Quest", "quest", "", "quest", &field); form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Color", "color", "", "text", &field); + autofill_test::CreateTestFormField("Color", "color", "", "text", &field); form.fields.push_back(field); - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - autofill_test::CreateTestFormField( - "Username", "username", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_FALSE( - autofill_manager_->GetAutoFillSuggestions(false, field)); + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); } // Test that we return no suggestions when autofill is disabled. TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, form); autofill_manager_->FormsSeen(forms); // Disable AutoFill. autofill_manager_->set_autofill_enabled(false); - // 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; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); } // Test that we return a warning explaining that autofill suggestions are // unavailable when the form method is GET rather than POST. TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); form.method = ASCIIToUTF16("GET"); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -509,23 +644,23 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(1U, values.size()); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED), - values[0]); - ASSERT_EQ(1U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - ASSERT_EQ(1U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - ASSERT_EQ(1U, unique_ids.size()); - EXPECT_EQ(-1, unique_ids[0]); + + string16 expected_values[] = { + l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED) + }; + string16 expected_labels[] = {string16()}; + string16 expected_icons[] = {string16()}; + int expected_unique_ids[] = {-1}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); // Now add some Autocomplete suggestions. We should return the autocomplete // suggestions and the warning; these will be culled by the renderer. process()->sink().ClearMessages(); const int kPageID2 = 2; rvh()->ResetAutoFillState(kPageID2); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); std::vector<string16> suggestions; suggestions.push_back(ASCIIToUTF16("Jay")); @@ -534,50 +669,36 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) { EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID2, page_id); - ASSERT_EQ(3U, values.size()); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED), - values[0]); - EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]); - EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]); - ASSERT_EQ(3U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - EXPECT_EQ(string16(), labels[1]); - EXPECT_EQ(string16(), labels[2]); - ASSERT_EQ(3U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - EXPECT_EQ(string16(), icons[2]); - ASSERT_EQ(3U, unique_ids.size()); - EXPECT_EQ(-1, unique_ids[0]); - EXPECT_EQ(0, unique_ids[1]); - EXPECT_EQ(0, unique_ids[2]); + + string16 expected_values2[] = { + l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED), + ASCIIToUTF16("Jay"), + ASCIIToUTF16("Jason") + }; + string16 expected_labels2[] = {string16(), string16(), string16()}; + string16 expected_icons2[] = {string16(), string16(), string16()}; + int expected_unique_ids2[] = {-1, 0, 0}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kPageID2, arraysize(expected_values2), expected_values2, + expected_labels2, expected_icons2, expected_unique_ids2); // Now clear the test profiles and try again -- we shouldn't return a warning. test_personal_data_->ClearAutoFillProfiles(); - EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); + EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); } // Test that we return all credit card profile suggestions when all form fields // are empty. TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { + // Set up our form data. FormData form; CreateTestCreditCardFormData(&form, true); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "Card Number", "cardnumber", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + FormField field = form.fields[1]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -591,41 +712,39 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); - EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); - ASSERT_EQ(2U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); - EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); - EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(5), unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("************3456"), + ASCIIToUTF16("************8765") + }; + string16 expected_labels[] = {ASCIIToUTF16("*3456"), ASCIIToUTF16("*8765")}; + string16 expected_icons[] = { + ASCIIToUTF16("visaCC"), + ASCIIToUTF16("masterCardCC") + }; + int expected_unique_ids[] = { + autofill_manager_->GetPackedCreditCardID(4), + autofill_manager_->GetPackedCreditCardID(5) + }; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we return only matching credit card profile suggestions when the // selected form field has been partially filled out. TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { + // Set up our form data. FormData form; CreateTestCreditCardFormData(&form, true); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; + FormField field; autofill_test::CreateTestFormField( "Card Number", "cardnumber", "4", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -639,37 +758,28 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(1U, values.size()); - EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); - ASSERT_EQ(1U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); - ASSERT_EQ(1U, icons.size()); - EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); - ASSERT_EQ(1U, unique_ids.size()); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]); + + string16 expected_values[] = {ASCIIToUTF16("************3456")}; + string16 expected_labels[] = {ASCIIToUTF16("*3456")}; + string16 expected_icons[] = {ASCIIToUTF16("visaCC")}; + int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we return credit card profile suggestions when the selected form // field is not the credit card number field. TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { + // Set up our form data. FormData form; CreateTestCreditCardFormData(&form, true); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "Name on Card", "nameoncard", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -683,41 +793,37 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); - ASSERT_EQ(2U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); - EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); - EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(5), unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("Elvis Presley"), + ASCIIToUTF16("Buddy Holly") + }; + string16 expected_labels[] = {ASCIIToUTF16("*3456"), ASCIIToUTF16("*8765")}; + string16 expected_icons[] = { + ASCIIToUTF16("visaCC"), + ASCIIToUTF16("masterCardCC") + }; + int expected_unique_ids[] = { + autofill_manager_->GetPackedCreditCardID(4), + autofill_manager_->GetPackedCreditCardID(5) + }; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we return a warning explaining that credit card profile suggestions // are unavailable when the form is not https. TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { + // Set up our form data. FormData form; CreateTestCreditCardFormData(&form, false); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "Card Number", "cardnumber", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -731,23 +837,23 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(1U, values.size()); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), - values[0]); - ASSERT_EQ(1U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - ASSERT_EQ(1U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - ASSERT_EQ(1U, unique_ids.size()); - EXPECT_EQ(-1, unique_ids[0]); + + string16 expected_values[] = { + l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION) + }; + string16 expected_labels[] = {string16()}; + string16 expected_icons[] = {string16()}; + int expected_unique_ids[] = {-1}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); // Now add some Autocomplete suggestions. We should show the autocomplete // suggestions and the warning. process()->sink().ClearMessages(); const int kPageID2 = 2; rvh()->ResetAutoFillState(kPageID2); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); std::vector<string16> suggestions; suggestions.push_back(ASCIIToUTF16("Jay")); @@ -756,50 +862,35 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID2, page_id); - ASSERT_EQ(3U, values.size()); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), - values[0]); - EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]); - EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]); - ASSERT_EQ(3U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - EXPECT_EQ(string16(), labels[1]); - EXPECT_EQ(string16(), labels[2]); - ASSERT_EQ(3U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - EXPECT_EQ(string16(), icons[2]); - ASSERT_EQ(3U, unique_ids.size()); - EXPECT_EQ(-1, unique_ids[0]); - EXPECT_EQ(0, unique_ids[1]); - EXPECT_EQ(0, unique_ids[2]); + string16 expected_values2[] = { + l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), + ASCIIToUTF16("Jay"), + ASCIIToUTF16("Jason") + }; + string16 expected_labels2[] = {string16(), string16(), string16()}; + string16 expected_icons2[] = {string16(), string16(), string16()}; + int expected_unique_ids2[] = {-1, 0, 0}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kPageID2, arraysize(expected_values2), expected_values2, + expected_labels2, expected_icons2, expected_unique_ids2); // Clear the test credit cards and try again -- we shouldn't return a warning. test_personal_data_->ClearCreditCards(); - EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); + EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); } // Test that we return profile and credit card suggestions for combined forms. TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); CreateTestCreditCardFormData(&form, true); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + FormField field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -813,27 +904,27 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); - ASSERT_EQ(2U, labels.size()); - // Inferred labels now include full first relevant field, which in this case - // the address #1. - EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); - EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); - EXPECT_EQ(2, unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("Elvis"), + ASCIIToUTF16("Charles") + }; + string16 expected_labels[] = { + ASCIIToUTF16("3734 Elvis Presley Blvd."), + ASCIIToUTF16("123 Apple St.") + }; + string16 expected_icons[] = {string16(), string16()}; + int expected_unique_ids[] = {1, 2}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); process()->sink().ClearMessages(); + const int kPageID2 = 2; autofill_test::CreateTestFormField( "Card Number", "cardnumber", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + rvh()->ResetAutoFillState(kPageID2); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -843,19 +934,23 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { page_id = 0; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); - EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); - ASSERT_EQ(2U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); - EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); - EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(4), unique_ids[0]); - EXPECT_EQ(autofill_manager_->GetPackedCreditCardID(5), unique_ids[1]); + + string16 expected_values2[] = { + ASCIIToUTF16("************3456"), + ASCIIToUTF16("************8765") + }; + string16 expected_labels2[] = {ASCIIToUTF16("*3456"), ASCIIToUTF16("*8765")}; + string16 expected_icons2[] = { + ASCIIToUTF16("visaCC"), + ASCIIToUTF16("masterCardCC") + }; + int expected_unique_ids2[] = { + autofill_manager_->GetPackedCreditCardID(4), + autofill_manager_->GetPackedCreditCardID(5) + }; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kPageID2, arraysize(expected_values2), expected_values2, + expected_labels2, expected_icons2, expected_unique_ids2); } // Test that for non-https forms with both address and credit card fields, we @@ -863,24 +958,16 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { // should return a warning explaining that credit card profile suggestions are // unavailable when the form is not https. TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); CreateTestCreditCardFormData(&form, false); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + FormField field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -894,27 +981,27 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); - ASSERT_EQ(2U, labels.size()); - // Inferred labels now include full first relevant field, which in this case - // the address #1. - EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); - EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); - EXPECT_EQ(2, unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("Elvis"), + ASCIIToUTF16("Charles") + }; + string16 expected_labels[] = { + ASCIIToUTF16("3734 Elvis Presley Blvd."), + ASCIIToUTF16("123 Apple St.") + }; + string16 expected_icons[] = {string16(), string16()}; + int expected_unique_ids[] = {1, 2}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); process()->sink().ClearMessages(); autofill_test::CreateTestFormField( "Card Number", "cardnumber", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const int kPageID2 = 2; + rvh()->ResetAutoFillState(kPageID2); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -923,41 +1010,33 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { // Test that we sent the right message to the renderer. EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(1U, values.size()); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), - values[0]); - ASSERT_EQ(1U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - ASSERT_EQ(1U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - ASSERT_EQ(1U, unique_ids.size()); - EXPECT_EQ(-1, unique_ids[0]); + + string16 expected_values2[] = { + l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION) + }; + string16 expected_labels2[] = {string16()}; + string16 expected_icons2[] = {string16()}; + int expected_unique_ids2[] = {-1}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kPageID2, arraysize(expected_values2), expected_values2, + expected_labels2, expected_icons2, expected_unique_ids2); // Clear the test credit cards and try again -- we shouldn't return a warning. test_personal_data_->ClearCreditCards(); - EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); + EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); } // Test that we correctly combine autofill and autocomplete suggestions. TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // Add some Autocomplete suggestions. // This triggers the combined message send. @@ -976,49 +1055,40 @@ TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(4U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); - EXPECT_EQ(ASCIIToUTF16("Jay"), values[2]); - EXPECT_EQ(ASCIIToUTF16("Jason"), values[3]); - ASSERT_EQ(4U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); - EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); - EXPECT_EQ(string16(), labels[2]); - EXPECT_EQ(string16(), labels[3]); - ASSERT_EQ(4U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - EXPECT_EQ(string16(), icons[2]); - EXPECT_EQ(string16(), icons[3]); - ASSERT_EQ(4U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); - EXPECT_EQ(2, unique_ids[1]); - EXPECT_EQ(0, unique_ids[2]); - EXPECT_EQ(0, unique_ids[3]); + + string16 expected_values[] = { + ASCIIToUTF16("Elvis"), + ASCIIToUTF16("Charles"), + ASCIIToUTF16("Jay"), + ASCIIToUTF16("Jason") + }; + string16 expected_labels[] = { + ASCIIToUTF16("3734 Elvis Presley Blvd."), + ASCIIToUTF16("123 Apple St."), + string16(), + string16() + }; + string16 expected_icons[] = {string16(), string16(), string16(), string16()}; + int expected_unique_ids[] = {1, 2, 0, 0}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we return autocomplete-like suggestions when trying to autofill -// already filled fields. -TEST_F(AutoFillManagerTest, GetFieldSuggestionsFieldIsAutoFilled) { +// already filled forms. +TEST_F(AutoFillManagerTest, GetFieldSuggestionsWhenFormIsAutoFilled) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field)); + // Mark one of the fields as filled. + form.fields[2].set_autofilled(true); + const FormField& field = form.fields[0]; + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -1032,41 +1102,33 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsFieldIsAutoFilled) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); - ASSERT_EQ(2U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - EXPECT_EQ(string16(), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); - EXPECT_EQ(2, unique_ids[1]); + string16 expected_values[] = { + ASCIIToUTF16("Elvis"), + ASCIIToUTF16("Charles") + }; + string16 expected_labels[] = {string16(), string16()}; + string16 expected_icons[] = {string16(), string16()}; + int expected_unique_ids[] = {1, 2}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that nothing breaks when there are autocomplete suggestions but no // autofill suggestions. TEST_F(AutoFillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { + // Set up our form data. FormData form; CreateTestAddressFormData(&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; - - webkit_glue::FormField field; + FormField field; autofill_test::CreateTestFormField( "Some Field", "somefield", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(true, field)); + form.fields.push_back(field); + std::vector<FormData> forms(1, form); + autofill_manager_->FormsSeen(forms); + + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); // Add some Autocomplete suggestions. // This triggers the combined message send. @@ -1083,30 +1145,26 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - ASSERT_EQ(2U, labels.size()); - EXPECT_EQ(ASCIIToUTF16("one"), values[0]); - EXPECT_EQ(string16(), labels[0]); - EXPECT_EQ(ASCIIToUTF16("two"), values[1]); - EXPECT_EQ(string16(), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(0, unique_ids[0]); - EXPECT_EQ(0, unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("one"), + ASCIIToUTF16("two") + }; + string16 expected_labels[] = {string16(), string16()}; + string16 expected_icons[] = {string16(), string16()}; + int expected_unique_ids[] = {0, 0}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we do not return duplicate values drawn from multiple profiles when // filling an already filled field. TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) { + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, form); autofill_manager_->FormsSeen(forms); // |profile| will be owned by the mock PersonalDataManager. @@ -1116,15 +1174,10 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) { profile->set_guid("00000000-0000-0000-0000-000000000101"); autofill_manager_->AddProfile(profile); - // 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; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - rvh()->ResetAutoFillState(kPageID); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field)); + FormField& field = form.fields[0]; + field.set_autofilled(true); + rvh()->ResetAutoFillState(kDefaultPageID); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); // No suggestions provided, so send an empty vector as the results. // This triggers the combined message send. @@ -1138,296 +1191,173 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) { std::vector<int> unique_ids; EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, &unique_ids)); - EXPECT_EQ(kPageID, page_id); - ASSERT_EQ(2U, values.size()); - EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); - EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); - ASSERT_EQ(2U, labels.size()); - EXPECT_EQ(string16(), labels[0]); - EXPECT_EQ(string16(), labels[1]); - ASSERT_EQ(2U, icons.size()); - EXPECT_EQ(string16(), icons[0]); - EXPECT_EQ(string16(), icons[1]); - ASSERT_EQ(2U, unique_ids.size()); - EXPECT_EQ(1, unique_ids[0]); - EXPECT_EQ(2, unique_ids[1]); + + string16 expected_values[] = { + ASCIIToUTF16("Elvis"), + ASCIIToUTF16("Charles") + }; + string16 expected_labels[] = {string16(), string16()}; + string16 expected_icons[] = {string16(), string16()}; + int expected_unique_ids[] = {1, 2}; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); } // Test that we correctly fill an address form. TEST_F(AutoFillManagerTest, FillAddressForm) { - // |profile| will be owned by the mock PersonalDataManager. - AutoFillProfile* profile = new AutoFillProfile; - autofill_test::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely", - "flatlander@gmail.com", "MCA", - "916 16th St.", "Apt. 6", "Lubbock", - "Texas", "79401", "USA", - "12345678901", ""); - profile->set_guid("00000000-0000-0000-0000-000000000007"); - autofill_manager_->AddProfile(profile); - + // Set up our form data. FormData form; CreateTestAddressFormData(&form); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; + std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - kPageID, form, autofill_manager_->PackGUIDs(std::string(), - profile->guid()))); + kDefaultPageID, form, form.fields[0], + autofill_manager_->PackGUIDs(std::string(), guid))); 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(11U, results.fields.size()); - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "Joe", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "Ely", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); - autofill_test::CreateTestFormField( - "Address Line 1", "addr1", "916 16th St.", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); - autofill_test::CreateTestFormField( - "Address Line 2", "addr2", "Apt. 6", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4])); - autofill_test::CreateTestFormField( - "City", "city", "Lubbock", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5])); - autofill_test::CreateTestFormField( - "State", "state", "Texas", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6])); - autofill_test::CreateTestFormField( - "Postal Code", "zipcode", "79401", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7])); - autofill_test::CreateTestFormField( - "Country", "country", "USA", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8])); - autofill_test::CreateTestFormField( - "Phone Number", "phonenumber", "12345678901", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9])); - autofill_test::CreateTestFormField( - "Email", "email", "flatlander@gmail.com", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10])); + ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); } // Test that we correctly fill a credit card form. TEST_F(AutoFillManagerTest, FillCreditCardForm) { + // Set up our form data. FormData form; CreateTestCreditCardFormData(&form, true); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, 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; + std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - kPageID, form, - autofill_manager_->PackGUIDs("00000000-0000-0000-0000-000000000004", - std::string()))); + kDefaultPageID, form, *form.fields.begin(), + autofill_manager_->PackGUIDs(guid, std::string()))); 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("https://myform.com/form.html"), results.origin); - EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); - ASSERT_EQ(4U, results.fields.size()); - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "Name on Card", "nameoncard", "Elvis Presley", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); - autofill_test::CreateTestFormField( - "Card Number", "cardnumber", "4234567890123456", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); - autofill_test::CreateTestFormField( - "Expiration Date", "ccmonth", "04", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); - autofill_test::CreateTestFormField( - "", "ccyear", "2012", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); + ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); } // Test that we correctly fill a combined address and credit card form. TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) { - // |profile| will be owned by the mock PersonalDataManager. - AutoFillProfile* profile = new AutoFillProfile; - autofill_test::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely", - "flatlander@gmail.com", "MCA", - "916 16th St.", "Apt. 6", "Lubbock", - "Texas", "79401", "USA", - "12345678901", ""); - profile->set_guid("00000000-0000-0000-0000-000000000008"); - autofill_manager_->AddProfile(profile); - + // Set up our form data. FormData form; CreateTestAddressFormData(&form); CreateTestCreditCardFormData(&form, true); - - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, form); autofill_manager_->FormsSeen(forms); // First fill the address data. - // The page ID sent to the AutoFillManager from the RenderView, used to send - // an IPC message back to the renderer. - const int kPageID = 1; + std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - kPageID, form, - autofill_manager_->PackGUIDs(std::string(), - "00000000-0000-0000-0000-000000000008"))); + kDefaultPageID, form, form.fields[0], + autofill_manager_->PackGUIDs(std::string(), guid))); 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("https://myform.com/form.html"), results.origin); - EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); - ASSERT_EQ(15U, results.fields.size()); - - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "Joe", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "Ely", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); - autofill_test::CreateTestFormField( - "Address Line 1", "addr1", "916 16th St.", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); - autofill_test::CreateTestFormField( - "Address Line 2", "addr2", "Apt. 6", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4])); - autofill_test::CreateTestFormField( - "City", "city", "Lubbock", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5])); - autofill_test::CreateTestFormField( - "State", "state", "Texas", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6])); - autofill_test::CreateTestFormField( - "Postal Code", "zipcode", "79401", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7])); - autofill_test::CreateTestFormField( - "Country", "country", "USA", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8])); - autofill_test::CreateTestFormField( - "Phone Number", "phonenumber", "12345678901", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9])); - autofill_test::CreateTestFormField( - "Email", "email", "flatlander@gmail.com", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10])); - autofill_test::CreateTestFormField( - "Name on Card", "nameoncard", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11])); - autofill_test::CreateTestFormField( - "Card Number", "cardnumber", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12])); - autofill_test::CreateTestFormField( - "Expiration Date", "ccmonth", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13])); - autofill_test::CreateTestFormField( - "", "ccyear", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14])); + { + SCOPED_TRACE("Address"); + ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, true); + } // Now fill the credit card data. process()->sink().ClearMessages(); + const int kPageID2 = 2; + guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - kPageID, form, - autofill_manager_->PackGUIDs("00000000-0000-0000-0000-000000000004", - std::string()))); + kPageID2, form, form.fields.back(), + autofill_manager_->PackGUIDs(guid, std::string()))); + + page_id = 0; + EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); + { + SCOPED_TRACE("Credit card"); + ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); + } +} +// Test that we correctly fill a previously auto-filled form. +TEST_F(AutoFillManagerTest, FillAutoFilledForm) { + // Set up our form data. + FormData form; + CreateTestAddressFormData(&form); + // Mark one of the address fields as autofilled. + form.fields[4].set_autofilled(true); + CreateTestCreditCardFormData(&form, true); + std::vector<FormData> forms(1, form); + autofill_manager_->FormsSeen(forms); + + // First fill the address data. + std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); + EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( + kDefaultPageID, form, *form.fields.begin(), + autofill_manager_->PackGUIDs(std::string(), guid))); + + int page_id = 0; + FormData results; + EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); + { + SCOPED_TRACE("Address"); + ExpectFilledForm(page_id, results, kDefaultPageID, + "Elvis", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", true, true); + } + + // Now fill the credit card data. + process()->sink().ClearMessages(); + const int kPageID2 = 2; + guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); + EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( + kPageID2, form, form.fields.back(), + autofill_manager_->PackGUIDs(guid, std::string()))); page_id = 0; EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); - EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); - EXPECT_EQ(ASCIIToUTF16("POST"), results.method); - EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); - EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); - ASSERT_EQ(15U, results.fields.size()); + { + SCOPED_TRACE("Credit card 1"); + ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); + } - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); - autofill_test::CreateTestFormField( - "Address Line 1", "addr1", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); - autofill_test::CreateTestFormField( - "Address Line 2", "addr2", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4])); - autofill_test::CreateTestFormField( - "City", "city", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[5])); - autofill_test::CreateTestFormField( - "State", "state", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[6])); - autofill_test::CreateTestFormField( - "Postal Code", "zipcode", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[7])); - autofill_test::CreateTestFormField( - "Country", "country", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[8])); - autofill_test::CreateTestFormField( - "Phone Number", "phonenumber", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[9])); - autofill_test::CreateTestFormField( - "Email", "email", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[10])); - autofill_test::CreateTestFormField( - "Name on Card", "nameoncard", "Elvis Presley", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[11])); - autofill_test::CreateTestFormField( - "Card Number", "cardnumber", "4234567890123456", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[12])); - autofill_test::CreateTestFormField( - "Expiration Date", "ccmonth", "04", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[13])); - autofill_test::CreateTestFormField( - "", "ccyear", "2012", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14])); + // Now set the credit card fields to also be auto-filled, and try again to + // fill the credit card data + for (std::vector<FormField>::iterator iter = form.fields.begin(); + iter != form.fields.end(); + ++iter){ + iter->set_autofilled(true); + } + + process()->sink().ClearMessages(); + const int kPageID3 = 3; + EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( + kPageID3, form, *form.fields.rbegin(), + autofill_manager_->PackGUIDs(guid, std::string()))); + + page_id = 0; + EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); + { + SCOPED_TRACE("Credit card 2"); + ExpectFilledForm(page_id, results, kPageID3, + "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "2012", true, true); + } } // Test that we correctly fill a phone number split across multiple fields. TEST_F(AutoFillManagerTest, FillPhoneNumber) { + // Set up our form data. FormData form; - form.name = ASCIIToUTF16("MyPhoneForm"); form.method = ASCIIToUTF16("POST"); form.origin = GURL("http://myform.com/phone_form.html"); form.action = GURL("http://myform.com/phone_submit.html"); form.user_submitted = true; - webkit_glue::FormField field; - + FormField field; autofill_test::CreateTestFormField( "country code", "country code", "", "text", &field); field.set_max_length(1); @@ -1449,13 +1379,11 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) { field.set_max_length(3); form.fields.push_back(field); - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, form); autofill_manager_->FormsSeen(forms); AutoFillProfile *work_profile = autofill_manager_->GetLabeledProfile("Work"); - EXPECT_TRUE(work_profile != NULL); + ASSERT_TRUE(work_profile != NULL); const AutoFillType phone_type(PHONE_HOME_NUMBER); string16 saved_phone = work_profile->GetFieldText(phone_type); @@ -1468,7 +1396,7 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) { int page_id = 100 - i; process()->sink().ClearMessages(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - page_id, form, + page_id, form, *form.fields.begin(), autofill_manager_->PackGUIDs(std::string(), work_profile->guid()))); page_id = 0; FormData results; @@ -1489,139 +1417,61 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) { // Test that we can still fill a form when a field has been removed from it. TEST_F(AutoFillManagerTest, FormChangesRemoveField) { + // Set up our form data. 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"); - form.user_submitted = true; + CreateTestAddressFormData(&form); - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "", "text", &field); - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "", "text", &field); - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Phone Number", "phonenumber", "", "text", &field); - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Email", "email", "", "text", &field); - form.fields.push_back(field); + // Add a field -- we'll remove it again later. + FormField field; + autofill_test::CreateTestFormField("Some", "field", "", "text", &field); + form.fields.insert(form.fields.begin() + 3, field); - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, form); autofill_manager_->FormsSeen(forms); - // Now, after the call to |FormsSeen| we remove the phone number field before - // filling. + // Now, after the call to |FormsSeen|, we remove the field before filling. form.fields.erase(form.fields.begin() + 3); - // The page ID sent to the AutoFillManager from the RenderView, used to send - // an IPC message back to the renderer. - const int kPageID = 1; + std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - kPageID, form, - autofill_manager_->PackGUIDs(std::string(), - "00000000-0000-0000-0000-000000000001"))); + kDefaultPageID, form, form.fields[0], + autofill_manager_->PackGUIDs(std::string(), guid))); 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); - EXPECT_TRUE(results.user_submitted); - ASSERT_EQ(4U, results.fields.size()); - - autofill_test::CreateTestFormField( - "First Name", "firstname", "Elvis", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "Aaron", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "Presley", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); - autofill_test::CreateTestFormField( - "Email", "email", "theking@gmail.com", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); + ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); } // Test that we can still fill a form when a field has been added to it. TEST_F(AutoFillManagerTest, FormChangesAddField) { + // The offset of the fax field in the address form. + const int kFaxFieldOffset = 10; + + // Set up our form data. 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"); - form.user_submitted = true; + CreateTestAddressFormData(&form); - webkit_glue::FormField field; - autofill_test::CreateTestFormField( - "First Name", "firstname", "", "text", &field); - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "", "text", &field); - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "", "text", &field); - // Note: absent phone number. Adding this below. - form.fields.push_back(field); - autofill_test::CreateTestFormField( - "Email", "email", "", "text", &field); - form.fields.push_back(field); + // Remove the fax field -- we'll add it back later. + std::vector<FormField>::iterator pos = form.fields.begin() + kFaxFieldOffset; + FormField field = *pos; + pos = form.fields.erase(pos); - // Set up our FormStructures. - std::vector<FormData> forms; - forms.push_back(form); + std::vector<FormData> forms(1, form); autofill_manager_->FormsSeen(forms); - // Now, after the call to |FormsSeen| we add the phone number field before - // filling. - autofill_test::CreateTestFormField( - "Phone Number", "phonenumber", "", "text", &field); - form.fields.insert(form.fields.begin() + 3, field); + // Now, after the call to |FormsSeen|, we restore the field before filling. + form.fields.insert(pos, field); - // The page ID sent to the AutoFillManager from the RenderView, used to send - // an IPC message back to the renderer. - const int kPageID = 1; + std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( - kPageID, form, - autofill_manager_->PackGUIDs(std::string(), - "00000000-0000-0000-0000-000000000001"))); + kDefaultPageID, form, form.fields[0], + autofill_manager_->PackGUIDs(std::string(), guid))); 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); - EXPECT_TRUE(results.user_submitted); - ASSERT_EQ(5U, results.fields.size()); - - autofill_test::CreateTestFormField( - "First Name", "firstname", "Elvis", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[0])); - autofill_test::CreateTestFormField( - "Middle Name", "middlename", "Aaron", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[1])); - autofill_test::CreateTestFormField( - "Last Name", "lastname", "Presley", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[2])); - autofill_test::CreateTestFormField( - "Phone Number", "phonenumber", "", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[3])); - autofill_test::CreateTestFormField( - "Email", "email", "theking@gmail.com", "text", &field); - EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[4])); + ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); } TEST_F(AutoFillManagerTest, HiddenFields) { @@ -1632,7 +1482,7 @@ TEST_F(AutoFillManagerTest, HiddenFields) { form.action = GURL("http://myform.com/submit.html"); form.user_submitted = true; - webkit_glue::FormField field; + FormField field; autofill_test::CreateTestFormField( "E-mail", "one", "one", "hidden", &field); form.fields.push_back(field); @@ -1643,7 +1493,7 @@ TEST_F(AutoFillManagerTest, HiddenFields) { "E-mail", "three", "three", "hidden", &field); form.fields.push_back(field); - // Set up our FormStructures. + // Set up our form data. std::vector<FormData> forms; forms.push_back(form); autofill_manager_->FormsSeen(forms); diff --git a/chrome/browser/autofill/credit_card_field_unittest.cc b/chrome/browser/autofill/credit_card_field_unittest.cc index c333032..8c41b4f 100644 --- a/chrome/browser/autofill/credit_card_field_unittest.cc +++ b/chrome/browser/autofill/credit_card_field_unittest.cc @@ -46,14 +46,16 @@ TEST_F(CreditCardFieldTest, ParseCreditCardNoNumber) { ASCIIToUTF16("ccmonth"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("year1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -67,7 +69,8 @@ TEST_F(CreditCardFieldTest, ParseCreditCardNoDate) { ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -81,21 +84,24 @@ TEST_F(CreditCardFieldTest, ParseMiniumCreditCard) { ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("year1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -120,7 +126,8 @@ TEST_F(CreditCardFieldTest, ParseMiniumCreditCardEcml) { ASCIIToUTF16(kEcmlCardNumber), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField( @@ -128,7 +135,8 @@ TEST_F(CreditCardFieldTest, ParseMiniumCreditCardEcml) { ASCIIToUTF16(kEcmlCardExpireMonth), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField( @@ -136,7 +144,8 @@ TEST_F(CreditCardFieldTest, ParseMiniumCreditCardEcml) { ASCIIToUTF16(kEcmlCardExpireYear), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("year1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -161,35 +170,40 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCard) { ASCIIToUTF16("name on card"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("year1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("cvc1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -220,14 +234,16 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCardEcml) { ASCIIToUTF16(kEcmlCardHolder), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16(kEcmlCardNumber), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number1"))); list_.push_back( new AutoFillField( @@ -235,7 +251,8 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCardEcml) { ASCIIToUTF16(kEcmlCardExpireMonth), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month1"))); list_.push_back( new AutoFillField( @@ -243,7 +260,8 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCardEcml) { ASCIIToUTF16(kEcmlCardExpireYear), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("year1"))); list_.push_back( new AutoFillField( @@ -251,7 +269,8 @@ TEST_F(CreditCardFieldTest, ParseFullCreditCardEcml) { ASCIIToUTF16(kEcmlCardVerification), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("cvc1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -282,14 +301,16 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear) { ASCIIToUTF16("Name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("Card"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number"))); list_.push_back( new AutoFillField( @@ -297,7 +318,8 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear) { ASCIIToUTF16("ExpDate"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month"))); list_.push_back( new AutoFillField( @@ -305,7 +327,8 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear) { ASCIIToUTF16("ExpDate"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("year"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -333,14 +356,16 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear2) { ASCIIToUTF16("Name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("Card"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("number"))); list_.push_back( new AutoFillField( @@ -348,7 +373,8 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear2) { ASCIIToUTF16("ExpDate"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("month"))); list_.push_back( new AutoFillField( @@ -356,7 +382,8 @@ TEST_F(CreditCardFieldTest, ParseExpMonthYear2) { ASCIIToUTF16("ExpDate"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), 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 0ba21c0..724456a 100644 --- a/chrome/browser/autofill/fax_field_unittest.cc +++ b/chrome/browser/autofill/fax_field_unittest.cc @@ -46,7 +46,8 @@ TEST_F(FaxFieldTest, ParseOneLineFax) { ASCIIToUTF16("faxnumber"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), 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 4097a69..96d8fff 100644 --- a/chrome/browser/autofill/form_structure_unittest.cc +++ b/chrome/browser/autofill/form_structure_unittest.cc @@ -48,17 +48,20 @@ TEST(FormStructureTest, FieldCount) { ASCIIToUTF16("username"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), ASCIIToUTF16("password"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); FormStructure form_structure(form); // All fields are counted. @@ -72,22 +75,26 @@ TEST(FormStructureTest, AutoFillCount) { ASCIIToUTF16("username"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), ASCIIToUTF16("password"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("state"), ASCIIToUTF16("state"), string16(), ASCIIToUTF16("select-one"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); FormStructure form_structure(form); // Only text and select fields that are heuristically matched are counted. @@ -113,12 +120,14 @@ TEST(FormStructureTest, HasAutoFillableValues) { ASCIIToUTF16("Submit1"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit2"), ASCIIToUTF16("dummy value"), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->HasAutoFillableValues()); @@ -127,12 +136,14 @@ TEST(FormStructureTest, HasAutoFillableValues) { ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("state"), ASCIIToUTF16("state"), string16(), ASCIIToUTF16("select-one"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->HasAutoFillableValues()); @@ -141,12 +152,14 @@ TEST(FormStructureTest, HasAutoFillableValues) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Dear"), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->HasAutoFillableValues()); @@ -157,12 +170,14 @@ TEST(FormStructureTest, HasAutoFillableValues) { ASCIIToUTF16("Field1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Field2"), ASCIIToUTF16("dummy value"), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->HasAutoFillableValues()); @@ -172,7 +187,8 @@ TEST(FormStructureTest, HasAutoFillableValues) { ASCIIToUTF16("fullname"), ASCIIToUTF16("John Dear"), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->HasAutoFillableValues()); } @@ -187,17 +203,20 @@ TEST(FormStructureTest, IsAutoFillable) { ASCIIToUTF16("username"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), ASCIIToUTF16("password"), string16(), ASCIIToUTF16("password"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable(true)); @@ -206,12 +225,14 @@ TEST(FormStructureTest, IsAutoFillable) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable(true)); @@ -220,7 +241,8 @@ TEST(FormStructureTest, IsAutoFillable) { ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); @@ -252,47 +274,56 @@ TEST(FormStructureTest, HeuristicsContactInfo) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), ASCIIToUTF16("fax"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), ASCIIToUTF16("zipcode"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); @@ -330,87 +361,104 @@ TEST(FormStructureTest, HeuristicsHiddenFields) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden1"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden2"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden3"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden4"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), ASCIIToUTF16("fax"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden5"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden6"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden7"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), ASCIIToUTF16("zipcode"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("hidden8"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); @@ -449,61 +497,71 @@ TEST(FormStructureTest, HeuristicsSample8) { ASCIIToUTF16("bill.first"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Your Last Name:"), ASCIIToUTF16("bill.last"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street Address Line 1:"), ASCIIToUTF16("bill.street1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street Address Line 2:"), ASCIIToUTF16("bill.street2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City:"), ASCIIToUTF16("bill.city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("State (U.S.):"), ASCIIToUTF16("bill.state"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Zip/Postal Code:"), ASCIIToUTF16("BillTo.PostalCode"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Country:"), ASCIIToUTF16("bill.country"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Phone Number:"), ASCIIToUTF16("BillTo.Phone"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(10U, form_structure->field_count()); @@ -543,45 +601,52 @@ TEST(FormStructureTest, HeuristicsSample6) { ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Full name"), ASCIIToUTF16("name"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Company"), ASCIIToUTF16("company"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); // TODO(jhawkins): Add state select control. form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Zip Code"), ASCIIToUTF16("Home.PostalCode"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); // TODO(jhawkins): Phone number. form.fields.push_back( webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), ASCIIToUTF16("continue"), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(7U, form_structure->field_count()); @@ -615,47 +680,56 @@ TEST(FormStructureTest, HeuristicsLabelsOnly) { string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), string16(), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(9U, form_structure->field_count()); @@ -691,32 +765,38 @@ TEST(FormStructureTest, HeuristicsCreditCardInfo) { ASCIIToUTF16("name on card"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(6U, form_structure->field_count()); @@ -746,39 +826,46 @@ TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { ASCIIToUTF16("name on card"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); // 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"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(7U, form_structure->field_count()); @@ -811,25 +898,29 @@ TEST(FormStructureTest, ThreeAddressLines) { ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line3"), ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(4U, form_structure->field_count()); @@ -857,25 +948,29 @@ TEST(FormStructureTest, BillingAndShippingAddresses) { ASCIIToUTF16("shipping.address.addressLine1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("shipping.address.addressLine2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line1"), ASCIIToUTF16("billing.address.addressLine1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("billing.address.addressLine2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(4U, form_structure->field_count()); @@ -907,25 +1002,29 @@ TEST(FormStructureTest, ThreeAddressLinesExpedia) { ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Suite or Apt:"), ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street address second line"), ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City:"), ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(4U, form_structure->field_count()); @@ -954,19 +1053,22 @@ TEST(FormStructureTest, TwoAddressLinesEbay) { ASCIIToUTF16("address1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Floor number, suite number, etc"), ASCIIToUTF16("address2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(3U, form_structure->field_count()); @@ -990,19 +1092,22 @@ TEST(FormStructureTest, HeuristicsStateWithProvince) { ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address Line2"), ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("State/Province/Region"), ASCIIToUTF16("State"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(3U, form_structure->field_count()); @@ -1027,67 +1132,78 @@ TEST(FormStructureTest, HeuristicsWithBilling) { ASCIIToUTF16("editBillingAddress$firstNameBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Last Name*:"), ASCIIToUTF16("editBillingAddress$lastNameBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Company Name:"), ASCIIToUTF16("editBillingAddress$companyBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address*:"), ASCIIToUTF16("editBillingAddress$addressLine1Box"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Apt/Suite :"), ASCIIToUTF16("editBillingAddress$addressLine2Box"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City*:"), ASCIIToUTF16("editBillingAddress$cityBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("State/Province*:"), ASCIIToUTF16("editBillingAddress$stateDropDown"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Country*:"), ASCIIToUTF16("editBillingAddress$countryDropDown"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Postal Code*:"), ASCIIToUTF16("editBillingAddress$zipCodeBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Phone*:"), ASCIIToUTF16("editBillingAddress$phoneBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Email Address*:"), ASCIIToUTF16("email$emailBox"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(11U, form_structure->field_count()); @@ -1118,25 +1234,29 @@ TEST(FormStructureTest, ThreePartPhoneNumber) { ASCIIToUTF16("dayphone1"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone2"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone3"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("ext.:"), ASCIIToUTF16("dayphone4"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); ASSERT_EQ(4U, form_structure->field_count()); @@ -1162,52 +1282,62 @@ TEST(FormStructureTest, MatchSpecificInputTypes) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), ASCIIToUTF16("email"), string16(), ASCIIToUTF16("email"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), ASCIIToUTF16("number"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Country"), ASCIIToUTF16("country"), string16(), ASCIIToUTF16("select-one"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), ASCIIToUTF16("fax"), string16(), ASCIIToUTF16("tel"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), ASCIIToUTF16("radio"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("checkbox"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("State"), ASCIIToUTF16("state"), string16(), ASCIIToUTF16("hidden"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); @@ -1246,27 +1376,32 @@ TEST(FormStructureTest, HeuristicsInfernoCC) { ASCIIToUTF16("name_on_card"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("billing_address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Date"), ASCIIToUTF16("expiration_month"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Year"), ASCIIToUTF16("expiration_year"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); @@ -1295,32 +1430,38 @@ TEST(FormStructureTest, CVCCodeClash) { ASCIIToUTF16("ccnumber"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First name"), ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last name"), ASCIIToUTF16("last_name"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration date"), ASCIIToUTF16("ccexpiresmonth"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16(""), ASCIIToUTF16("ccexpiresyear"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("cvc number"), ASCIIToUTF16("csc"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable(true)); @@ -1350,27 +1491,32 @@ TEST(FormStructureTest, EncodeQueryRequest) { ASCIIToUTF16("name_on_card"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("billing_address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Date"), ASCIIToUTF16("expiration_month"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Expiration Year"), ASCIIToUTF16("expiration_year"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); ScopedVector<FormStructure> forms; forms.push_back(new FormStructure(form)); std::vector<std::string> encoded_signatures; @@ -1404,7 +1550,8 @@ TEST(FormStructureTest, EncodeQueryRequest) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); } forms.push_back(new FormStructure(form)); @@ -1436,7 +1583,8 @@ TEST(FormStructureTest, EncodeQueryRequest) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); } forms.push_back(new FormStructure(form)); @@ -1466,49 +1614,56 @@ TEST(FormStructureTest, EncodeUploadRequest) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(NAME_FIRST); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(NAME_LAST); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), ASCIIToUTF16("email"), string16(), ASCIIToUTF16("email"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(EMAIL_ADDRESS); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), ASCIIToUTF16("number"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(PHONE_HOME_WHOLE_NUMBER); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Country"), ASCIIToUTF16("country"), string16(), ASCIIToUTF16("select-one"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), ASCIIToUTF16("fax"), string16(), ASCIIToUTF16("tel"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(PHONE_FAX_WHOLE_NUMBER); form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), ASCIIToUTF16("radio"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(ADDRESS_HOME_LINE1); form_structure.reset(new FormStructure(form)); @@ -1544,7 +1699,8 @@ TEST(FormStructureTest, EncodeUploadRequest) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(ADDRESS_HOME_LINE1); possible_field_types.back().insert(ADDRESS_HOME_LINE2); @@ -1588,7 +1744,8 @@ TEST(FormStructureTest, EncodeUploadRequest) { ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"), - 0)); + 0, + false)); possible_field_types.push_back(FieldTypeSet()); possible_field_types.back().insert(ADDRESS_HOME_LINE1); possible_field_types.back().insert(ADDRESS_HOME_LINE2); diff --git a/chrome/browser/autofill/name_field_unittest.cc b/chrome/browser/autofill/name_field_unittest.cc index 03cbec3..ce64c5f 100644 --- a/chrome/browser/autofill/name_field_unittest.cc +++ b/chrome/browser/autofill/name_field_unittest.cc @@ -32,21 +32,24 @@ TEST_F(NameFieldTest, FirstMiddleLast) { ASCIIToUTF16("First"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Middle Name"), ASCIIToUTF16("Middle"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("Last"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -70,21 +73,24 @@ TEST_F(NameFieldTest, FirstMiddleLast2) { ASCIIToUTF16("firstName"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("middleName"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("lastName"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -108,14 +114,16 @@ TEST_F(NameFieldTest, FirstLast) { ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("last_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -136,14 +144,16 @@ TEST_F(NameFieldTest, FirstLast2) { ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("last_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -164,21 +174,24 @@ TEST_F(NameFieldTest, FirstLastMiddleWithSpaces) { ASCIIToUTF16("first name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Middle Name"), ASCIIToUTF16("middle name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("last name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -202,14 +215,16 @@ TEST_F(NameFieldTest, FirstLastEmpty) { ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("last_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -230,21 +245,24 @@ TEST_F(NameFieldTest, FirstMiddleLastEmpty) { ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("middle_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("last_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -268,21 +286,24 @@ TEST_F(NameFieldTest, MiddleInitial) { ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("MI"), ASCIIToUTF16("middle_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"), ASCIIToUTF16("last_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -306,14 +327,16 @@ TEST_F(NameFieldTest, MiddleInitialNoLastName) { ASCIIToUTF16("first_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("MI"), ASCIIToUTF16("middle_name"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -329,21 +352,24 @@ TEST_F(NameFieldTest, MiddleInitialAtEnd) { ASCIIToUTF16("XXXnameXXXfirst"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("XXXnameXXXmi"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("XXXnameXXXlast"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -367,7 +393,8 @@ TEST_F(NameFieldTest, ECMLNoName) { ASCIIToUTF16("ecom_shipto_postal_company"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("field1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -381,14 +408,16 @@ TEST_F(NameFieldTest, ECMLMiddleInitialNoLastName) { ASCIIToUTF16("ecom_shipto_postal_name_first"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back(new AutoFillField( webkit_glue::FormField(ASCIIToUTF16("Middle"), ASCIIToUTF16("ecom_shipto_postal_name_middle"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -402,21 +431,24 @@ TEST_F(NameFieldTest, ECMLFirstMiddleLast) { ASCIIToUTF16("ecom_shipto_postal_name_first"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name1"))); list_.push_back(new AutoFillField( webkit_glue::FormField(string16(), ASCIIToUTF16("ecom_shipto_postal_name_middle"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name2"))); list_.push_back(new AutoFillField( webkit_glue::FormField(string16(), ASCIIToUTF16("ecom_shipto_postal_name_last"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("name3"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/autofill/phone_field_unittest.cc b/chrome/browser/autofill/phone_field_unittest.cc index ce0ae48..e79d64a 100644 --- a/chrome/browser/autofill/phone_field_unittest.cc +++ b/chrome/browser/autofill/phone_field_unittest.cc @@ -46,7 +46,8 @@ TEST_F(PhoneFieldTest, ParseOneLinePhone) { ASCIIToUTF16("phone"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -64,7 +65,8 @@ TEST_F(PhoneFieldTest, ParseOneLinePhoneEcml) { ASCIIToUTF16(kEcmlShipToPhone), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -82,14 +84,16 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhone) { ASCIIToUTF16("area code"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16("phone"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -111,14 +115,16 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlShipTo) { ASCIIToUTF16(kEcmlShipToPostalCode), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16(kEcmlShipToPhone), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -140,14 +146,16 @@ TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlBillTo) { ASCIIToUTF16(kEcmlBillToPostalCode), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"), ASCIIToUTF16(kEcmlBillToPhone), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("phone1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -168,28 +176,32 @@ TEST_F(PhoneFieldTest, ThreePartPhoneNumber) { ASCIIToUTF16("dayphone1"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone2"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("prefix1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone3"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("suffix1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("ext.:"), ASCIIToUTF16("dayphone4"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("ext1"))); list_.push_back(NULL); iter_ = list_.begin(); @@ -216,21 +228,24 @@ TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix) { ASCIIToUTF16("area"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("areacode1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("prefix"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("prefix1"))); list_.push_back( new AutoFillField(webkit_glue::FormField(string16(), ASCIIToUTF16("suffix"), string16(), ASCIIToUTF16("text"), - 0), + 0, + false), ASCIIToUTF16("suffix1"))); list_.push_back(NULL); iter_ = list_.begin(); diff --git a/chrome/browser/chromeos/login/account_creation_view.cc b/chrome/browser/chromeos/login/account_creation_view.cc index 0719c4e..a748155 100644 --- a/chrome/browser/chromeos/login/account_creation_view.cc +++ b/chrome/browser/chromeos/login/account_creation_view.cc @@ -54,13 +54,14 @@ class AccountCreationTabContents : public WizardWebPageViewTabContents, virtual void FormsSeen(const std::vector<FormData>& forms) { } - virtual bool GetAutoFillSuggestions(bool field_autofilled, + virtual bool GetAutoFillSuggestions(const webkit_glue::FormData& form, const webkit_glue::FormField& field) { return false; } virtual bool FillAutoFillFormData(int query_id, const webkit_glue::FormData& form, + const webkit_glue::FormField& field, int unique_id) { return false; } diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 547150f..18d4639 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -59,6 +59,7 @@ using base::TimeDelta; using webkit_glue::FormData; +using webkit_glue::FormField; using webkit_glue::PasswordForm; using webkit_glue::PasswordFormDomManager; using webkit_glue::PasswordFormFillData; @@ -1700,8 +1701,9 @@ void RenderViewHost::OnMsgShouldCloseACK(bool proceed) { } } -void RenderViewHost::OnQueryFormFieldAutoFill( - int query_id, bool field_autofilled, const webkit_glue::FormField& field) { +void RenderViewHost::OnQueryFormFieldAutoFill(int query_id, + const FormData& form, + const FormField& field) { ResetAutoFillState(query_id); // We first query the autofill delegate for suggestions. We keep track of the @@ -1709,9 +1711,8 @@ void RenderViewHost::OnQueryFormFieldAutoFill( // suggestions. RenderViewHostDelegate::AutoFill* autofill_delegate = delegate_->GetAutoFillDelegate(); - if (autofill_delegate) { - autofill_delegate->GetAutoFillSuggestions(field_autofilled, field); - } + if (autofill_delegate) + autofill_delegate->GetAutoFillSuggestions(form, field); // Now query the Autocomplete delegate for suggestions. These will be combined // with the saved autofill suggestions in |AutocompleteSuggestionsReturned()|. @@ -1759,13 +1760,14 @@ void RenderViewHost::OnShowAutoFillDialog() { void RenderViewHost::OnFillAutoFillFormData(int query_id, const FormData& form, + const FormField& field, int unique_id) { RenderViewHostDelegate::AutoFill* autofill_delegate = delegate_->GetAutoFillDelegate(); if (!autofill_delegate) return; - autofill_delegate->FillAutoFillFormData(query_id, form, unique_id); + autofill_delegate->FillAutoFillFormData(query_id, form, field, unique_id); } void RenderViewHost::OnDidFillAutoFillFormData() { diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 19b2b17..be5a7f0 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -673,7 +673,7 @@ class RenderViewHost : public RenderWidgetHost { void OnInstallApplication(const WebApplicationInfo& info); void OnMsgShouldCloseACK(bool proceed); void OnQueryFormFieldAutoFill(int request_id, - bool form_autofilled, + const webkit_glue::FormData& form, const webkit_glue::FormField& field); void OnDidShowAutoFillSuggestions(); void OnRemoveAutocompleteEntry(const string16& field_name, @@ -681,6 +681,7 @@ class RenderViewHost : public RenderWidgetHost { void OnShowAutoFillDialog(); void OnFillAutoFillFormData(int query_id, const webkit_glue::FormData& form, + const webkit_glue::FormField& field, int unique_id); void OnDidFillAutoFillFormData(); diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index b49002b..184a472 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -555,21 +555,22 @@ class RenderViewHostDelegate { // frame. virtual void FormsSeen(const std::vector<webkit_glue::FormData>& forms) = 0; - // Called to retrieve a list of AutoFill suggestions from the web database - // given the name of the field, whether it is auto-filled, and what the user - // has already typed in it. If there is a warning to be returned to the - // user, it is stored into |values|, with corresponding unique id -1. + // Called to retrieve a list of AutoFill suggestions for the portion of the + // |form| containing |field|, given the current state of the |form|. // Returns true to indicate that RenderViewHost::AutoFillSuggestionsReturned // has been called. virtual bool GetAutoFillSuggestions( - bool field_autofilled, + const webkit_glue::FormData& form, const webkit_glue::FormField& field) = 0; - // Called to fill the FormData object with AutoFill profile information that - // matches the |value|, |unique_id| key. Returns true to indicate that - // RenderViewHost::AutoFillFormDataFilled has been called. + // Called to fill the |form| with AutoFill profile information that matches + // the |unique_id| key. If the portion of the form containing |field| has + // been autofilled already, only fills |field|. + // Returns true to indicate that RenderViewHost::AutoFillFormDataFilled + // has been called. virtual bool FillAutoFillFormData(int query_id, const webkit_glue::FormData& form, + const webkit_glue::FormField& field, int unique_id) = 0; // Called when the user selects the 'AutoFill Options...' suggestions in the diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc index 2b4401c..81f34b4 100644 --- a/chrome/browser/webdata/web_data_service_unittest.cc +++ b/chrome/browser/webdata/web_data_service_unittest.cc @@ -143,7 +143,8 @@ class WebDataServiceAutofillTest : public WebDataServiceTest { name, value, string16(), - 0)); + 0, + false)); } string16 name1_; diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index a49b7ee..3ac4d2b 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -637,7 +637,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes)); std::vector<string16> v; for (int i = 0; i < 5; i++) { @@ -646,7 +647,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), string16(), - 0), + 0, + false), &changes)); } for (int i = 0; i < 3; i++) { @@ -655,7 +657,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Sutter"), string16(), - 0), + 0, + false), &changes)); } for (int i = 0; i < 2; i++) { @@ -664,7 +667,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green"), string16(), - 0), + 0, + false), &changes)); } @@ -678,7 +682,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), string16(), - 0), + 0, + false), &pair_id, &count)); EXPECT_EQ(5, count); EXPECT_NE(0, pair_id); @@ -690,7 +695,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Name"), ASCIIToUTF16("clark kent"), string16(), - 0), + 0, + false), &pair_id, &count)); EXPECT_EQ(0, count); @@ -699,7 +705,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green"), string16(), - 0), + 0, + false), &pair_id, &count)); EXPECT_EQ(2, count); @@ -764,7 +771,8 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), string16(), - 0), + 0, + false), &pair_id, &count)); EXPECT_EQ(0, count); @@ -778,25 +786,29 @@ TEST_F(WebDatabaseTest, Autofill) { ASCIIToUTF16("blank"), string16(), string16(), - 0), + 0, + false), &changes)); EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), ASCIIToUTF16(" "), string16(), - 0), + 0, + false), &changes)); EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), ASCIIToUTF16(" "), string16(), - 0), + 0, + false), &changes)); EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(), ASCIIToUTF16("blank"), kValue, string16(), - 0), + 0, + false), &changes)); // They should be stored normally as the DB layer does not check for empty @@ -831,7 +843,8 @@ TEST_F(WebDatabaseTest, Autofill_RemoveBetweenChanges) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, t1)); EXPECT_TRUE(db.AddFormFieldValueTime( @@ -839,7 +852,8 @@ TEST_F(WebDatabaseTest, Autofill_RemoveBetweenChanges) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, t2)); @@ -874,7 +888,8 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, t1)); ASSERT_EQ(1U, changes.size()); @@ -889,7 +904,8 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, t2)); ASSERT_EQ(1U, changes.size()); @@ -912,7 +928,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateOneWithOneTimestamp) { ASCIIToUTF16("foo"), ASCIIToUTF16("bar"), string16(), - 0); + 0, + false); int64 pair_id; int count; ASSERT_TRUE(db.GetIDAndCountOfFormElement(field, &pair_id, &count)); @@ -938,7 +955,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateOneWithTwoTimestamps) { ASCIIToUTF16("foo"), ASCIIToUTF16("bar"), string16(), - 0); + 0, + false); int64 pair_id; int count; ASSERT_TRUE(db.GetIDAndCountOfFormElement(field, &pair_id, &count)); @@ -981,10 +999,11 @@ TEST_F(WebDatabaseTest, Autofill_UpdateTwo) { ASSERT_TRUE(db.UpdateAutofillEntries(entries)); FormField field0(string16(), - ASCIIToUTF16("foo"), - ASCIIToUTF16("bar0"), - string16(), - 0); + ASCIIToUTF16("foo"), + ASCIIToUTF16("bar0"), + string16(), + 0, + false); int64 pair_id; int count; ASSERT_TRUE(db.GetIDAndCountOfFormElement(field0, &pair_id, &count)); @@ -992,10 +1011,11 @@ TEST_F(WebDatabaseTest, Autofill_UpdateTwo) { EXPECT_EQ(1, count); FormField field1(string16(), - ASCIIToUTF16("foo"), - ASCIIToUTF16("bar1"), - string16(), - 0); + ASCIIToUTF16("foo"), + ASCIIToUTF16("bar1"), + string16(), + 0, + false); ASSERT_TRUE(db.GetIDAndCountOfFormElement(field1, &pair_id, &count)); EXPECT_LE(0, pair_id); EXPECT_EQ(2, count); @@ -1012,7 +1032,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateReplace) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes)); AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); @@ -1041,7 +1062,8 @@ TEST_F(WebDatabaseTest, Autofill_UpdateDontReplace) { existing.key().name(), existing.key().value(), string16(), - 0), + 0, + false), &changes, t)); AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2)); @@ -1073,22 +1095,26 @@ TEST_F(WebDatabaseTest, Autofill_AddFormFieldValues) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Joe"), string16(), - 0)); + 0, + false)); elements.push_back(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Jane"), string16(), - 0)); + 0, + false)); elements.push_back(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), string16(), - 0)); + 0, + false)); elements.push_back(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jones"), string16(), - 0)); + 0, + false)); std::vector<AutofillChange> changes; db.AddFormFieldValuesTime(elements, &changes, t); @@ -1723,7 +1749,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_OneResult) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, Time::FromTimeT(start))); timestamps1.push_back(Time::FromTimeT(start)); @@ -1767,7 +1794,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoDistinct) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, Time::FromTimeT(start))); timestamps1.push_back(Time::FromTimeT(start)); @@ -1782,7 +1810,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoDistinct) { ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"), string16(), - 0), + 0, + false), &changes, Time::FromTimeT(start))); timestamps2.push_back(Time::FromTimeT(start)); @@ -1830,7 +1859,8 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoSame) { ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"), string16(), - 0), + 0, + false), &changes, Time::FromTimeT(start))); timestamps.push_back(Time::FromTimeT(start)); diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc index 3842fbd..1df6c3a 100644 --- a/chrome/common/render_messages.cc +++ b/chrome/common/render_messages.cc @@ -95,6 +95,7 @@ void ParamTraits<webkit_glue::FormField>::Write(Message* m, WriteParam(m, p.value()); WriteParam(m, p.form_control_type()); WriteParam(m, p.max_length()); + WriteParam(m, p.is_autofilled()); WriteParam(m, p.option_strings()); } @@ -102,12 +103,14 @@ bool ParamTraits<webkit_glue::FormField>::Read(const Message* m, void** iter, param_type* p) { string16 label, name, value, form_control_type; int max_length = 0; + bool is_autofilled; std::vector<string16> options; 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, &max_length); + result = result && ReadParam(m, iter, &is_autofilled); result = result && ReadParam(m, iter, &options); if (!result) return false; @@ -117,6 +120,7 @@ bool ParamTraits<webkit_glue::FormField>::Read(const Message* m, void** iter, p->set_value(value); p->set_form_control_type(form_control_type); p->set_max_length(max_length); + p->set_autofilled(is_autofilled); p->set_option_strings(options); return true; } diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 53fc70b..690667d 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -2099,7 +2099,7 @@ IPC_BEGIN_MESSAGES(ViewHost) // Queries the browser for AutoFill suggestions for a form input field. IPC_MESSAGE_ROUTED3(ViewHostMsg_QueryFormFieldAutoFill, int /* id of this message */, - bool /* field autofilled */, + webkit_glue::FormData /* the form */, webkit_glue::FormField /* the form field */) // Sent when the popup with AutoFill suggestions for a form is shown. @@ -2107,9 +2107,10 @@ IPC_BEGIN_MESSAGES(ViewHost) // Instructs the browser to fill in the values for a form using AutoFill // profile data. - IPC_MESSAGE_ROUTED3(ViewHostMsg_FillAutoFillFormData, + IPC_MESSAGE_ROUTED4(ViewHostMsg_FillAutoFillFormData, int /* id of this message */, webkit_glue::FormData /* the form */, + webkit_glue::FormField /* the form field */, int /* profile unique ID */) // Sent when a form is previewed or filled with AutoFill suggestions. diff --git a/chrome/renderer/autofill_helper.cc b/chrome/renderer/autofill_helper.cc index 2f8b146..f7fd7a2 100644 --- a/chrome/renderer/autofill_helper.cc +++ b/chrome/renderer/autofill_helper.cc @@ -34,18 +34,6 @@ namespace { // (so to avoid sending long strings through IPC). const size_t kMaximumTextSizeForAutoFill = 1000; - -// |node| must correspond to a form field. -// Returns true if |node| is auto-filled. -bool NodeIsAutoFilled(const WebKit::WebNode& node) { - const WebFormControlElement& element = - reinterpret_cast<const WebFormControlElement&>(node); - - WebInputElement input_element = - const_cast<WebFormControlElement&>(element).to<WebInputElement>(); - return input_element.isAutofilled(); -} - } // namespace AutoFillHelper::AutoFillHelper(RenderView* render_view) @@ -58,8 +46,8 @@ AutoFillHelper::AutoFillHelper(RenderView* render_view) suggestions_options_index_(-1) { } -void AutoFillHelper::RemoveAutocompleteSuggestion( - const WebKit::WebString& name, const WebKit::WebString& value) { +void AutoFillHelper::RemoveAutocompleteSuggestion(const WebString& name, + const WebString& value) { // The index of clear & options will have shifted down. if (suggestions_clear_index_ != -1) suggestions_clear_index_--; @@ -192,6 +180,8 @@ void AutoFillHelper::FormDataFilled(int query_id, void AutoFillHelper::DidSelectAutoFillSuggestion(const WebNode& node, int unique_id) { + DCHECK_GE(unique_id, 0); + DidClearAutoFillSelection(node); FillAutoFillFormData(node, unique_id, AUTOFILL_PREVIEW); } @@ -303,20 +293,13 @@ void AutoFillHelper::QueryAutoFillSuggestions( autofill_query_node_ = node; display_warning_if_disabled_ = display_warning_if_disabled; - const WebFormControlElement& element = node.toConst<WebFormControlElement>(); + webkit_glue::FormData form; webkit_glue::FormField field; - FormManager::WebFormControlElementToFormField( - element, FormManager::EXTRACT_VALUE, &field); - - // WebFormControlElementToFormField does not scrape the DOM for the field - // label, so find the label here. - // TODO(jhawkins): Add form and field identities so we can use the cached form - // data in FormManager. - field.set_label(FormManager::LabelForElement(element)); + if (!FindFormAndFieldForNode(node, &form, &field)) + return; - bool field_autofilled = NodeIsAutoFilled(node); render_view_->Send(new ViewHostMsg_QueryFormFieldAutoFill( - render_view_->routing_id(), autofill_query_id_, field_autofilled, field)); + render_view_->routing_id(), autofill_query_id_, form, field)); } void AutoFillHelper::FillAutoFillFormData(const WebNode& node, @@ -326,15 +309,14 @@ void AutoFillHelper::FillAutoFillFormData(const WebNode& node, autofill_query_id_ = query_counter++; webkit_glue::FormData form; - const WebInputElement element = node.toConst<WebInputElement>(); - if (!form_manager_.FindFormWithFormControlElement( - element, FormManager::REQUIRE_NONE, &form)) + webkit_glue::FormField field; + if (!FindFormAndFieldForNode(node, &form, &field)) return; autofill_action_ = action; - was_query_node_autofilled_ = element.isAutofilled(); + was_query_node_autofilled_ = field.is_autofilled(); render_view_->Send(new ViewHostMsg_FillAutoFillFormData( - render_view_->routing_id(), autofill_query_id_, form, unique_id)); + render_view_->routing_id(), autofill_query_id_, form, field, unique_id)); } void AutoFillHelper::SendForms(WebFrame* frame) { @@ -360,3 +342,25 @@ void AutoFillHelper::SendForms(WebFrame* frame) { forms)); } } + +bool AutoFillHelper::FindFormAndFieldForNode(const WebNode& node, + webkit_glue::FormData* form, + webkit_glue::FormField* field) { + const WebInputElement& element = node.toConst<WebInputElement>(); + if (!form_manager_.FindFormWithFormControlElement(element, + FormManager::REQUIRE_NONE, + form)) + return false; + + FormManager::WebFormControlElementToFormField(element, + FormManager::EXTRACT_VALUE, + field); + + // WebFormControlElementToFormField does not scrape the DOM for the field + // label, so find the label here. + // TODO(jhawkins): Add form and field identities so we can use the cached form + // data in FormManager. + field->set_label(FormManager::LabelForElement(element)); + + return true; +} diff --git a/chrome/renderer/autofill_helper.h b/chrome/renderer/autofill_helper.h index 67b137c..c948bcf 100644 --- a/chrome/renderer/autofill_helper.h +++ b/chrome/renderer/autofill_helper.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "chrome/renderer/form_manager.h" #include "chrome/renderer/page_click_listener.h" #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" @@ -130,6 +131,13 @@ class AutoFillHelper : public PageClickListener { // Scans the given frame for forms and sends them up to the browser. void SendForms(WebKit::WebFrame* frame); + // Fills |form| and |field| with the FormData and FormField corresponding to + // |node|. Returns true if the data was found; and false otherwise. + bool FindFormAndFieldForNode( + const WebKit::WebNode& node, + webkit_glue::FormData* form, + webkit_glue::FormField* field) WARN_UNUSED_RESULT; + // Weak reference. RenderView* render_view_; diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc index e6c1c9a..f9dd782 100644 --- a/chrome/renderer/form_manager.cc +++ b/chrome/renderer/form_manager.cc @@ -311,6 +311,7 @@ void FormManager::WebFormControlElementToFormField( if (element.formControlType() == WebString::fromUTF8("text")) { const WebInputElement& input_element = element.toConst<WebInputElement>(); field->set_max_length(input_element.maxLength()); + field->set_autofilled(input_element.isAutofilled()); } if (!(extract_mask & EXTRACT_VALUE)) diff --git a/chrome/renderer/form_manager_browsertest.cc b/chrome/renderer/form_manager_browsertest.cc index c1d421c..15f5ce6 100644 --- a/chrome/renderer/form_manager_browsertest.cc +++ b/chrome/renderer/form_manager_browsertest.cc @@ -71,25 +71,29 @@ TEST_F(FormManagerTest, WebFormElementToFormData) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("notvisible"), ASCIIToUTF16("apple"), ASCIIToUTF16("hidden"), - 0))); + 0, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } TEST_F(FormManagerTest, ExtractForms) { @@ -120,19 +124,22 @@ TEST_F(FormManagerTest, ExtractForms) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -170,19 +177,22 @@ TEST_F(FormManagerTest, ExtractMultipleForms) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); // Second form. @@ -197,19 +207,22 @@ TEST_F(FormManagerTest, ExtractMultipleForms) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields2[2]); } @@ -270,19 +283,22 @@ TEST_F(FormManagerTest, GetFormsAutocomplete) { ASCIIToUTF16("middlename"), ASCIIToUTF16("Jack"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -316,19 +332,22 @@ TEST_F(FormManagerTest, GetFormsElementsEnabled) { ASCIIToUTF16("middlename"), ASCIIToUTF16("Jack"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("submit"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -368,19 +387,22 @@ TEST_F(FormManagerTest, FindForm) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -424,43 +446,50 @@ TEST_F(FormManagerTest, FillForm) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("imhidden"), string16(), ASCIIToUTF16("hidden"), - 0), + 0, + false), fields[2]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("notempty"), ASCIIToUTF16("Hi"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[3]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("noautocomplete"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[4]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("notenabled"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[5]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[6]); // Fill the form. @@ -551,43 +580,50 @@ TEST_F(FormManagerTest, PreviewForm) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("imhidden"), string16(), ASCIIToUTF16("hidden"), - 0), + 0, + false), fields[2]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("notempty"), ASCIIToUTF16("Hi"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[3]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("noautocomplete"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[4]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("notenabled"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[5]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[6]); // Preview the form. @@ -694,19 +730,22 @@ TEST_F(FormManagerTest, Labels) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } TEST_F(FormManagerTest, LabelsWithSpans) { @@ -740,19 +779,22 @@ TEST_F(FormManagerTest, LabelsWithSpans) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test is different from FormManagerTest.Labels in that the label elements @@ -792,19 +834,22 @@ TEST_F(FormManagerTest, InvalidLabels) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test has three form control elements, only one of which has a label @@ -843,19 +888,22 @@ TEST_F(FormManagerTest, OneLabelElementFirstControlElementDisabled) { ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -889,19 +937,22 @@ TEST_F(FormManagerTest, LabelsInferredFromText) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -935,17 +986,20 @@ TEST_F(FormManagerTest, LabelsInferredFromTextHidden) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("hidden"), - 0))); + 0, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("hidden"), - 0))); + 0, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } TEST_F(FormManagerTest, LabelsInferredFromParagraph) { @@ -978,19 +1032,22 @@ TEST_F(FormManagerTest, LabelsInferredFromParagraph) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1035,19 +1092,22 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCell) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1111,19 +1171,22 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1180,19 +1243,22 @@ TEST_F(FormManagerTest, LabelsInferredFromTableEmptyTDs) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("*Last Name"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Milton"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1236,19 +1302,22 @@ TEST_F(FormManagerTest, LabelsInferredFromTableLabels) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1294,19 +1363,22 @@ TEST_F(FormManagerTest, LabelsInferredFromTableTDInterveningElements) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1367,19 +1439,22 @@ TEST_F(FormManagerTest, LabelsInferredFromDefinitionList) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1413,19 +1488,22 @@ TEST_F(FormManagerTest, LabelsInferredWithSameName) { ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Address Line 2:"), ASCIIToUTF16("Address"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1469,37 +1547,43 @@ TEST_F(FormManagerTest, LabelsInferredWithImageTags) { ASCIIToUTF16("dayphone1"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone2"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone3"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[2]); EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), ASCIIToUTF16("dayphone4"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[3]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("dummy"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[4]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[5]); } @@ -1539,19 +1623,22 @@ TEST_F(FormManagerTest, LabelsInferredFromDivTable) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); } @@ -1591,19 +1678,22 @@ TEST_F(FormManagerTest, FillFormMaxLength) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - 5), + 5, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - 5), + 5, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); // Fill the form. @@ -1625,19 +1715,22 @@ TEST_F(FormManagerTest, FillFormMaxLength) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Broth"), ASCIIToUTF16("text"), - 5))); + 5, + false))); EXPECT_TRUE(fields2[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonat"), ASCIIToUTF16("text"), - 5))); + 5, + false))); EXPECT_TRUE(fields2[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test uses negative values of the maxlength attribute for input elements. @@ -1679,19 +1772,22 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); // Fill the form. @@ -1714,19 +1810,22 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test sends a FormData object to FillForm with more fields than are in @@ -1765,28 +1864,32 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) { ASCIIToUTF16("prefix"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength); + kDefaultMaxLength, + false); form->fields.insert(form->fields.begin(), field1); FormField field2(string16(), ASCIIToUTF16("hidden"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength); + kDefaultMaxLength, + false); form->fields.insert(form->fields.begin() + 2, field2); FormField field3(string16(), ASCIIToUTF16("second"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength); + kDefaultMaxLength, + false); form->fields.insert(form->fields.begin() + 4, field3); FormField field4(string16(), ASCIIToUTF16("postfix"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength); + kDefaultMaxLength, + false); form->fields.insert(form->fields.begin() + 6, field4); // Fill the form. @@ -1817,22 +1920,26 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("middlename"), ASCIIToUTF16("Joseph"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test sends a FormData object to FillForm with fewer fields than are in @@ -1895,42 +2002,50 @@ TEST_F(FormManagerTest, FillFormFewerFormDataFields) { ASCIIToUTF16("prefix"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("hidden"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("middlename"), ASCIIToUTF16("Joseph"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("second"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[5].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[6].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("postfix"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[7].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test sends a FormData object to FillForm with a field changed from @@ -1990,22 +2105,26 @@ TEST_F(FormManagerTest, FillFormChangedFormDataFields) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } // This test sends a FormData object to FillForm with fewer fields than are in @@ -2062,27 +2181,32 @@ TEST_F(FormManagerTest, FillFormExtraFieldInCache) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Brother"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("middlename"), ASCIIToUTF16("Joseph"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Jonathan"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("postfix"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } TEST_F(FormManagerTest, FillFormEmptyName) { @@ -2121,19 +2245,22 @@ TEST_F(FormManagerTest, FillFormEmptyName) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); // Fill the form. @@ -2155,19 +2282,22 @@ TEST_F(FormManagerTest, FillFormEmptyName) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Wyatt"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Earp"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields2[2]); } @@ -2213,19 +2343,22 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) { ASCIIToUTF16("apple"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("banana"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); // Fill the form. @@ -2247,19 +2380,22 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) { ASCIIToUTF16("apple"), ASCIIToUTF16("Red"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("banana"), ASCIIToUTF16("Yellow"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields2[2]); } @@ -2299,31 +2435,36 @@ TEST_F(FormManagerTest, ThreePartPhone) { ASCIIToUTF16("dayphone1"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone2"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone3"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[2]); EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), ASCIIToUTF16("dayphone4"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[3]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[4]); } @@ -2366,45 +2507,52 @@ TEST_F(FormManagerTest, MaxLengthFields) { ASCIIToUTF16("dayphone1"), string16(), ASCIIToUTF16("text"), - 3), + 3, + false), fields[0]); EXPECT_EQ(FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone2"), string16(), ASCIIToUTF16("text"), - 3), + 3, + false), fields[1]); EXPECT_EQ(FormField(ASCIIToUTF16("-"), ASCIIToUTF16("dayphone3"), string16(), ASCIIToUTF16("text"), - 4), + 4, + false), fields[2]); EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), ASCIIToUTF16("dayphone4"), string16(), ASCIIToUTF16("text"), - 5), + 5, + false), fields[3]); // When unspecified |size|, default is returned. EXPECT_EQ(FormField(string16(), ASCIIToUTF16("default1"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[4]); // When invalid |size|, default is returned. EXPECT_EQ(FormField(string16(), ASCIIToUTF16("invalid1"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[5]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("reply-send"), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[6]); } @@ -2450,19 +2598,22 @@ TEST_F(FormManagerTest, FillFormNonEmptyField) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields[2]); // Fill the form. @@ -2484,19 +2635,22 @@ TEST_F(FormManagerTest, FillFormNonEmptyField) { ASCIIToUTF16("firstname"), ASCIIToUTF16("Wyatt"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[0]); EXPECT_EQ(FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Earp"), ASCIIToUTF16("text"), - kDefaultMaxLength), + kDefaultMaxLength, + false), fields2[1]); EXPECT_EQ(FormField(string16(), string16(), ASCIIToUTF16("Send"), ASCIIToUTF16("submit"), - 0), + 0, + false), fields2[2]); // Verify that the cursor position has been updated. @@ -2557,37 +2711,43 @@ TEST_F(FormManagerTest, ClearFormWithNode) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("noAC"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[3].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("notenabled"), ASCIIToUTF16("no clear"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[4].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("notvisible"), ASCIIToUTF16("apple"), ASCIIToUTF16("hidden"), - 0))); + 0, + false))); EXPECT_TRUE(fields2[5].StrictlyEqualsHack( FormField(string16(), string16(), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); // Verify that the cursor position has been updated. EXPECT_EQ(0, firstname.selectionStart()); @@ -2650,25 +2810,29 @@ TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields2[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("state"), ASCIIToUTF16("?"), ASCIIToUTF16("select-one"), - 0))); + 0, + false))); EXPECT_TRUE(fields2[3].StrictlyEqualsHack( FormField(string16(), string16(), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); // Verify that the cursor position has been updated. EXPECT_EQ(0, firstname.selectionStart()); @@ -2900,19 +3064,22 @@ TEST_F(FormManagerTest, LabelsHiddenFields) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("hidden"), - 0))); + 0, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("hidden"), - 0))); + 0, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } TEST_F(FormManagerTest, LabelForElementHidden) { @@ -2978,25 +3145,29 @@ TEST_F(FormManagerTest, SelectOneAsText) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("country"), ASCIIToUTF16("Albania"), ASCIIToUTF16("select-one"), - 0))); + 0, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); form.fields.clear(); // Extract the country select-one value as value. @@ -3014,25 +3185,29 @@ TEST_F(FormManagerTest, SelectOneAsText) { ASCIIToUTF16("firstname"), ASCIIToUTF16("John"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), ASCIIToUTF16("Smith"), ASCIIToUTF16("text"), - kDefaultMaxLength))); + kDefaultMaxLength, + false))); EXPECT_TRUE(fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("country"), ASCIIToUTF16("AL"), ASCIIToUTF16("select-one"), - 0))); + 0, + false))); EXPECT_TRUE(fields[3].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("reply-send"), string16(), ASCIIToUTF16("submit"), - 0))); + 0, + false))); } } // namespace diff --git a/chrome/renderer/password_autocomplete_manager_unittest.cc b/chrome/renderer/password_autocomplete_manager_unittest.cc index 1539757..b4ba36c 100644 --- a/chrome/renderer/password_autocomplete_manager_unittest.cc +++ b/chrome/renderer/password_autocomplete_manager_unittest.cc @@ -76,10 +76,10 @@ class PasswordAutocompleteManagerTest : public RenderViewTest { fill_data_.basic_data.fields.push_back( FormField(string16(), ASCIIToUTF16(kUsernameName), - username1_, string16(), 0)); + username1_, string16(), 0, false)); fill_data_.basic_data.fields.push_back( FormField(string16(), ASCIIToUTF16(kPasswordName), - password1_, string16(), 0)); + password1_, string16(), 0, false)); fill_data_.additional_logins[username2_] = password2_; fill_data_.additional_logins[username3_] = password3_; diff --git a/chrome/renderer/render_view_browsertest.cc b/chrome/renderer/render_view_browsertest.cc index 5e9360a..59bbe6e 100644 --- a/chrome/renderer/render_view_browsertest.cc +++ b/chrome/renderer/render_view_browsertest.cc @@ -1038,19 +1038,22 @@ TEST_F(RenderViewTest, SendForms) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))) << forms[0].fields[0]; + kDefaultMaxLength, + false))) << forms[0].fields[0]; EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))) << forms[0].fields[1]; + kDefaultMaxLength, + false))) << forms[0].fields[1]; EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("hidden"), - 0))) << forms[0].fields[2]; + 0, + false))) << forms[0].fields[2]; // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of // fields. @@ -1081,19 +1084,22 @@ TEST_F(RenderViewTest, SendForms) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))) << form2.fields[0]; + kDefaultMaxLength, + false))) << form2.fields[0]; EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))) << form2.fields[1]; + kDefaultMaxLength, + false))) << form2.fields[1]; EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("lastname"), string16(), ASCIIToUTF16("hidden"), - 0))) << form2.fields[2]; + 0, + false))) << form2.fields[2]; } TEST_F(RenderViewTest, FillFormElement) { @@ -1122,13 +1128,15 @@ TEST_F(RenderViewTest, FillFormElement) { ASCIIToUTF16("firstname"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))) << forms[0].fields[0]; + kDefaultMaxLength, + false))) << forms[0].fields[0]; EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( FormField(string16(), ASCIIToUTF16("middlename"), string16(), ASCIIToUTF16("text"), - kDefaultMaxLength))) << forms[0].fields[1]; + kDefaultMaxLength, + false))) << forms[0].fields[1]; // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected // field. diff --git a/chrome/test/live_sync/live_autofill_sync_test.h b/chrome/test/live_sync/live_autofill_sync_test.h index e5eca52..7f09ce5 100644 --- a/chrome/test/live_sync/live_autofill_sync_test.h +++ b/chrome/test/live_sync/live_autofill_sync_test.h @@ -168,7 +168,8 @@ class LiveAutofillSyncTest : public LiveSyncTest { (*i).name(), (*i).value(), string16(), - 0)); + 0, + false)); } WaitableEvent done_event(false, false); diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc index ee28766..bcc9926 100644 --- a/webkit/glue/form_field.cc +++ b/webkit/glue/form_field.cc @@ -20,13 +20,15 @@ using WebKit::WebVector; namespace webkit_glue { FormField::FormField() - : max_length_(0) { + : max_length_(0), + is_autofilled_(false) { } // TODO(jhawkins): This constructor should probably be deprecated and the // functionality moved to FormManager. FormField::FormField(WebFormControlElement element) - : max_length_(0) { + : max_length_(0), + is_autofilled_(false) { name_ = element.nameForAutofill(); // TODO(jhawkins): Extract the field label. For now we just use the field @@ -38,6 +40,7 @@ FormField::FormField(WebFormControlElement element) const WebInputElement& input_element = element.toConst<WebInputElement>(); value_ = input_element.value(); max_length_ = input_element.size(); + is_autofilled_ = input_element.isAutofilled(); } else if (form_control_type_ == ASCIIToUTF16("select-one")) { WebSelectElement select_element = element.to<WebSelectElement>(); value_ = select_element.value(); @@ -58,12 +61,14 @@ FormField::FormField(const string16& label, const string16& name, const string16& value, const string16& form_control_type, - int max_length) + int max_length, + bool is_autofilled) : label_(label), name_(name), value_(value), form_control_type_(form_control_type), - max_length_(max_length) { + max_length_(max_length), + is_autofilled_(is_autofilled) { } FormField::~FormField() { diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h index 0a22ea6..23b7380 100644 --- a/webkit/glue/form_field.h +++ b/webkit/glue/form_field.h @@ -21,7 +21,8 @@ class FormField { const string16& name, const string16& value, const string16& form_control_type, - int max_length); + int max_length, + bool is_autofilled); virtual ~FormField(); const string16& label() const { return label_; } @@ -29,6 +30,8 @@ class FormField { const string16& value() const { return value_; } const string16& form_control_type() const { return form_control_type_; } int max_length() const { return max_length_; } + bool is_autofilled() const { return is_autofilled_; } + // Returns option string for elements for which they make sense (select-one, // for example) for the rest of elements return an empty array. const std::vector<string16>& option_strings() const { @@ -42,6 +45,7 @@ class FormField { form_control_type_ = form_control_type; } void set_max_length(int max_length) { max_length_ = max_length; } + void set_autofilled(bool is_autofilled) { is_autofilled_ = is_autofilled; } void set_option_strings(const std::vector<string16>& strings) { option_strings_ = strings; } @@ -63,6 +67,7 @@ class FormField { string16 value_; string16 form_control_type_; int max_length_; + bool is_autofilled_; std::vector<string16> option_strings_; }; diff --git a/webkit/glue/password_form_dom_manager.cc b/webkit/glue/password_form_dom_manager.cc index adbb8dd..97f3eef 100644 --- a/webkit/glue/password_form_dom_manager.cc +++ b/webkit/glue/password_form_dom_manager.cc @@ -40,23 +40,25 @@ void PasswordFormDomManager::InitFillData( // Fill basic form data. result->basic_data.origin = form_on_page.origin; result->basic_data.action = form_on_page.action; - // TODO(jhawkins): Is it right to use an empty string for the form control - // type? I don't think the password autocomplete really cares, but we should - // correct this anyway. - // TODO(dhollowa): Similarly, |size| ideally should be set from the form - // control itself. But it is currently unused. + // Three of the parameters below are set to default values because they are + // currently not used by the password autocomplete code: + // * The form control type is initialized to an empty string. + // * The field |max_length| is initialized to 0. + // * The field autofilled state is initialized to false. result->basic_data.fields.push_back( FormField(string16(), form_on_page.username_element, preferred_match->username_value, string16(), - 0)); + 0, + false)); result->basic_data.fields.push_back( FormField(string16(), form_on_page.password_element, preferred_match->password_value, string16(), - 0)); + 0, + false)); result->wait_for_username = wait_for_username_before_autofill; // Copy additional username/value pairs. diff --git a/webkit/glue/webpasswordautocompletelistener_unittest.cc b/webkit/glue/webpasswordautocompletelistener_unittest.cc index 5de593c..2eeb890 100644 --- a/webkit/glue/webpasswordautocompletelistener_unittest.cc +++ b/webkit/glue/webpasswordautocompletelistener_unittest.cc @@ -104,12 +104,14 @@ class PasswordManagerAutocompleteTests : public testing::Test { string16(), username1_, string16(), - 0)); + 0, + false)); data_.basic_data.fields.push_back(FormField(string16(), string16(), password1_, string16(), - 0)); + 0, + false)); data_.additional_logins[username2_] = password2_; username_delegate_ = new TestWebInputElementDelegate(); |