Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 6033010: Support autocompletion for HTMl5 tags:"email", "month" and "tel". (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix merge error. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/credit_card.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 void ClearAutoFillProfiles() { 85 void ClearAutoFillProfiles() {
86 web_profiles_.reset(); 86 web_profiles_.reset();
87 } 87 }
88 88
89 void ClearCreditCards() { 89 void ClearCreditCards() {
90 credit_cards_.reset(); 90 credit_cards_.reset();
91 } 91 }
92 92
93 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) {
94 ClearCreditCards();
95 CreditCard* credit_card = new CreditCard;
96 autofill_test::SetCreditCardInfo(credit_card, "Miku", "Miku Hatsune",
97 "4234567890654321", // Visa
98 month, year);
99 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
100 credit_cards_->push_back(credit_card);
101 }
102
93 private: 103 private:
94 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { 104 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) {
95 AutoFillProfile* profile = new AutoFillProfile; 105 AutoFillProfile* profile = new AutoFillProfile;
96 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron", 106 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron",
97 "Presley", "theking@gmail.com", "RCA", 107 "Presley", "theking@gmail.com", "RCA",
98 "3734 Elvis Presley Blvd.", "Apt. 10", 108 "3734 Elvis Presley Blvd.", "Apt. 10",
99 "Memphis", "Tennessee", "38116", "USA", 109 "Memphis", "Tennessee", "38116", "USA",
100 "12345678901", ""); 110 "12345678901", "");
101 profile->set_guid("00000000-0000-0000-0000-000000000001"); 111 profile->set_guid("00000000-0000-0000-0000-000000000001");
102 profiles->push_back(profile); 112 profiles->push_back(profile);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 form->fields.push_back(field); 187 form->fields.push_back(field);
178 autofill_test::CreateTestFormField( 188 autofill_test::CreateTestFormField(
179 "Phone Number", "phonenumber", "", "text", &field); 189 "Phone Number", "phonenumber", "", "text", &field);
180 form->fields.push_back(field); 190 form->fields.push_back(field);
181 autofill_test::CreateTestFormField( 191 autofill_test::CreateTestFormField(
182 "Fax", "fax", "", "text", &field); 192 "Fax", "fax", "", "text", &field);
183 form->fields.push_back(field); 193 form->fields.push_back(field);
184 autofill_test::CreateTestFormField( 194 autofill_test::CreateTestFormField(
185 "Email", "email", "", "text", &field); 195 "Email", "email", "", "text", &field);
186 form->fields.push_back(field); 196 form->fields.push_back(field);
197 autofill_test::CreateTestFormField(
198 "Email", "email2", "", "email", &field);
199 form->fields.push_back(field);
200 autofill_test::CreateTestFormField(
201 "Phone Number", "phonenumber2", "", "tel", &field);
202 form->fields.push_back(field);
187 } 203 }
188 204
189 // Populates |form| with data corresponding to a simple credit card form. 205 // Populates |form| with data corresponding to a simple credit card form.
190 // Note that this actually appends fields to the form data, which can be useful 206 // Note that this actually appends fields to the form data, which can be useful
191 // for building up more complex test forms. 207 // for building up more complex test forms.
192 void CreateTestCreditCardFormData(FormData* form, bool is_https) { 208 void CreateTestCreditCardFormData(FormData* form,
209 bool is_https,
210 bool use_month_type) {
193 form->name = ASCIIToUTF16("MyForm"); 211 form->name = ASCIIToUTF16("MyForm");
194 form->method = ASCIIToUTF16("POST"); 212 form->method = ASCIIToUTF16("POST");
195 if (is_https) { 213 if (is_https) {
196 form->origin = GURL("https://myform.com/form.html"); 214 form->origin = GURL("https://myform.com/form.html");
197 form->action = GURL("https://myform.com/submit.html"); 215 form->action = GURL("https://myform.com/submit.html");
198 } else { 216 } else {
199 form->origin = GURL("http://myform.com/form.html"); 217 form->origin = GURL("http://myform.com/form.html");
200 form->action = GURL("http://myform.com/submit.html"); 218 form->action = GURL("http://myform.com/submit.html");
201 } 219 }
202 form->user_submitted = true; 220 form->user_submitted = true;
203 221
204 FormField field; 222 FormField field;
205 autofill_test::CreateTestFormField( 223 autofill_test::CreateTestFormField(
206 "Name on Card", "nameoncard", "", "text", &field); 224 "Name on Card", "nameoncard", "", "text", &field);
207 form->fields.push_back(field); 225 form->fields.push_back(field);
208 autofill_test::CreateTestFormField( 226 autofill_test::CreateTestFormField(
209 "Card Number", "cardnumber", "", "text", &field); 227 "Card Number", "cardnumber", "", "text", &field);
210 form->fields.push_back(field); 228 form->fields.push_back(field);
211 autofill_test::CreateTestFormField( 229 if (use_month_type) {
212 "Expiration Date", "ccmonth", "", "text", &field); 230 autofill_test::CreateTestFormField(
213 form->fields.push_back(field); 231 "Expiration Date", "ccmonth", "", "month", &field);
214 autofill_test::CreateTestFormField( 232 form->fields.push_back(field);
215 "", "ccyear", "", "text", &field); 233 } else {
216 form->fields.push_back(field); 234 autofill_test::CreateTestFormField(
235 "Expiration Date", "ccmonth", "", "text", &field);
236 form->fields.push_back(field);
237 autofill_test::CreateTestFormField(
238 "", "ccyear", "", "text", &field);
239 form->fields.push_back(field);
240 }
217 } 241 }
218 242
219 void ExpectSuggestions(int page_id, 243 void ExpectSuggestions(int page_id,
220 const std::vector<string16>& values, 244 const std::vector<string16>& values,
221 const std::vector<string16>& labels, 245 const std::vector<string16>& labels,
222 const std::vector<string16>& icons, 246 const std::vector<string16>& icons,
223 const std::vector<int>& unique_ids, 247 const std::vector<int>& unique_ids,
224 int expected_page_id, 248 int expected_page_id,
225 size_t expected_num_suggestions, 249 size_t expected_num_suggestions,
226 const string16 expected_values[], 250 const string16 expected_values[],
(...skipping 10 matching lines...) Expand all
237 EXPECT_EQ(expected_values[i], values[i]); 261 EXPECT_EQ(expected_values[i], values[i]);
238 EXPECT_EQ(expected_labels[i], labels[i]); 262 EXPECT_EQ(expected_labels[i], labels[i]);
239 EXPECT_EQ(expected_icons[i], icons[i]); 263 EXPECT_EQ(expected_icons[i], icons[i]);
240 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); 264 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]);
241 } 265 }
242 } 266 }
243 267
244 // Verifies that the |filled_form| has been filled with the given data. 268 // Verifies that the |filled_form| has been filled with the given data.
245 // Verifies address fields if |has_address_fields| is true, and verifies 269 // Verifies address fields if |has_address_fields| is true, and verifies
246 // credit card fields if |has_credit_card_fields| is true. Verifies both if both 270 // credit card fields if |has_credit_card_fields| is true. Verifies both if both
247 // are true. 271 // are true. |use_month_type| is used for credit card input month type.
248 void ExpectFilledForm(int page_id, 272 void ExpectFilledForm(int page_id,
249 const FormData& filled_form, 273 const FormData& filled_form,
250 int expected_page_id, 274 int expected_page_id,
251 const char* first, 275 const char* first,
252 const char* middle, 276 const char* middle,
253 const char* last, 277 const char* last,
254 const char* address1, 278 const char* address1,
255 const char* address2, 279 const char* address2,
256 const char* city, 280 const char* city,
257 const char* state, 281 const char* state,
258 const char* postal_code, 282 const char* postal_code,
259 const char* country, 283 const char* country,
260 const char* phone, 284 const char* phone,
261 const char* fax, 285 const char* fax,
262 const char* email, 286 const char* email,
263 const char* name_on_card, 287 const char* name_on_card,
264 const char* card_number, 288 const char* card_number,
265 const char* expiration_month, 289 const char* expiration_month,
266 const char* expiration_year, 290 const char* expiration_year,
267 bool has_address_fields, 291 bool has_address_fields,
268 bool has_credit_card_fields) { 292 bool has_credit_card_fields,
293 bool use_month_type) {
269 // The number of fields in the address and credit card forms created above. 294 // The number of fields in the address and credit card forms created above.
270 const size_t kAddressFormSize = 12; 295 const size_t kAddressFormSize = 14;
271 const size_t kCreditCardFormSize = 4; 296 const size_t kCreditCardFormSize = use_month_type ? 3 : 4;
272 297
273 EXPECT_EQ(expected_page_id, page_id); 298 EXPECT_EQ(expected_page_id, page_id);
274 EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name); 299 EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name);
275 EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method); 300 EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method);
276 if (has_credit_card_fields) { 301 if (has_credit_card_fields) {
277 EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin); 302 EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin);
278 EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action); 303 EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action);
279 } else { 304 } else {
280 EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin); 305 EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin);
281 EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action); 306 EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); 345 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8]));
321 autofill_test::CreateTestFormField( 346 autofill_test::CreateTestFormField(
322 "Phone Number", "phonenumber", phone, "text", &field); 347 "Phone Number", "phonenumber", phone, "text", &field);
323 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); 348 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9]));
324 autofill_test::CreateTestFormField( 349 autofill_test::CreateTestFormField(
325 "Fax", "fax", fax, "text", &field); 350 "Fax", "fax", fax, "text", &field);
326 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); 351 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10]));
327 autofill_test::CreateTestFormField( 352 autofill_test::CreateTestFormField(
328 "Email", "email", email, "text", &field); 353 "Email", "email", email, "text", &field);
329 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); 354 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11]));
355 autofill_test::CreateTestFormField(
356 "Email", "email2", email, "email", &field);
357 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[12]));
358 autofill_test::CreateTestFormField(
359 "Phone Number", "phonenumber2", phone, "tel", &field);
360 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[13]));
330 } 361 }
331 362
332 if (has_credit_card_fields) { 363 if (has_credit_card_fields) {
333 size_t offset = has_address_fields? kAddressFormSize : 0; 364 size_t offset = has_address_fields? kAddressFormSize : 0;
334 autofill_test::CreateTestFormField( 365 autofill_test::CreateTestFormField(
335 "Name on Card", "nameoncard", name_on_card, "text", &field); 366 "Name on Card", "nameoncard", name_on_card, "text", &field);
336 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); 367 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0]));
337 autofill_test::CreateTestFormField( 368 autofill_test::CreateTestFormField(
338 "Card Number", "cardnumber", card_number, "text", &field); 369 "Card Number", "cardnumber", card_number, "text", &field);
339 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); 370 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1]));
340 autofill_test::CreateTestFormField( 371 if (use_month_type) {
341 "Expiration Date", "ccmonth", expiration_month, "text", &field); 372 std::string exp_year = expiration_year;
342 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); 373 std::string exp_month = expiration_month;
343 autofill_test::CreateTestFormField( 374 std::string date;
344 "", "ccyear", expiration_year, "text", &field); 375 if (!exp_year.empty() && !exp_month.empty())
345 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); 376 date = exp_year + "-" + exp_month;
377 autofill_test::CreateTestFormField(
378 "Expiration Date", "ccmonth", date.c_str(), "month", &field);
379 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2]));
380 } else {
381 autofill_test::CreateTestFormField(
382 "Expiration Date", "ccmonth", expiration_month, "text", &field);
383 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2]));
384 autofill_test::CreateTestFormField(
385 "", "ccyear", expiration_year, "text", &field);
386 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3]));
387 }
346 } 388 }
347 } 389 }
348 390
349 void ExpectFilledAddressFormElvis(int page_id, 391 void ExpectFilledAddressFormElvis(int page_id,
350 const FormData& filled_form, 392 const FormData& filled_form,
351 int expected_page_id, 393 int expected_page_id,
352 bool has_credit_card_fields) { 394 bool has_credit_card_fields) {
353 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", 395 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron",
354 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", 396 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis",
355 "Tennessee", "38116", "USA", "12345678901", "", 397 "Tennessee", "38116", "USA", "12345678901", "",
356 "theking@gmail.com", "", "", "", "", true, 398 "theking@gmail.com", "", "", "", "", true,
357 has_credit_card_fields); 399 has_credit_card_fields, false);
358 } 400 }
359 401
360 void ExpectFilledCreditCardFormElvis(int page_id, 402 void ExpectFilledCreditCardFormElvis(int page_id,
361 const FormData& filled_form, 403 const FormData& filled_form,
362 int expected_page_id, 404 int expected_page_id,
363 bool has_address_fields) { 405 bool has_address_fields) {
364 ExpectFilledForm(page_id, filled_form, expected_page_id, 406 ExpectFilledForm(page_id, filled_form, expected_page_id,
365 "", "", "", "", "", "", "", "", "", "", "", "", 407 "", "", "", "", "", "", "", "", "", "", "", "",
366 "Elvis Presley", "4234567890123456", "04", "2012", 408 "Elvis Presley", "4234567890123456", "04", "2012",
367 has_address_fields, true); 409 has_address_fields, true, false);
410 }
411
412 void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id,
413 const FormData& filled_form,
414 int expected_page_id,
415 bool has_address_fields,
416 const char* year,
417 const char* month) {
418 ExpectFilledForm(page_id, filled_form, expected_page_id,
419 "", "", "", "", "", "", "", "", "", "", "", "",
420 "Miku Hatsune", "4234567890654321", month, year,
421 has_address_fields, true, true);
368 } 422 }
369 423
370 class TestAutoFillManager : public AutoFillManager { 424 class TestAutoFillManager : public AutoFillManager {
371 public: 425 public:
372 TestAutoFillManager(TabContents* tab_contents, 426 TestAutoFillManager(TabContents* tab_contents,
373 TestPersonalDataManager* personal_manager) 427 TestPersonalDataManager* personal_manager)
374 : AutoFillManager(tab_contents, personal_manager), 428 : AutoFillManager(tab_contents, personal_manager),
375 autofill_enabled_(true) { 429 autofill_enabled_(true) {
376 test_personal_data_ = personal_manager; 430 test_personal_data_ = personal_manager;
377 } 431 }
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 test_personal_data_->ClearAutoFillProfiles(); 815 test_personal_data_->ClearAutoFillProfiles();
762 GetAutoFillSuggestions(form, field); 816 GetAutoFillSuggestions(form, field);
763 EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); 817 EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
764 } 818 }
765 819
766 // Test that we return all credit card profile suggestions when all form fields 820 // Test that we return all credit card profile suggestions when all form fields
767 // are empty. 821 // are empty.
768 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { 822 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
769 // Set up our form data. 823 // Set up our form data.
770 FormData form; 824 FormData form;
771 CreateTestCreditCardFormData(&form, true); 825 CreateTestCreditCardFormData(&form, true, false);
772 std::vector<FormData> forms(1, form); 826 std::vector<FormData> forms(1, form);
773 FormsSeen(forms); 827 FormsSeen(forms);
774 828
775 FormField field = form.fields[1]; 829 FormField field = form.fields[1];
776 GetAutoFillSuggestions(form, field); 830 GetAutoFillSuggestions(form, field);
777 831
778 // No suggestions provided, so send an empty vector as the results. 832 // No suggestions provided, so send an empty vector as the results.
779 // This triggers the combined message send. 833 // This triggers the combined message send.
780 AutocompleteSuggestionsReturned(std::vector<string16>()); 834 AutocompleteSuggestionsReturned(std::vector<string16>());
781 835
(...skipping 22 matching lines...) Expand all
804 ExpectSuggestions(page_id, values, labels, icons, unique_ids, 858 ExpectSuggestions(page_id, values, labels, icons, unique_ids,
805 kDefaultPageID, arraysize(expected_values), expected_values, 859 kDefaultPageID, arraysize(expected_values), expected_values,
806 expected_labels, expected_icons, expected_unique_ids); 860 expected_labels, expected_icons, expected_unique_ids);
807 } 861 }
808 862
809 // Test that we return only matching credit card profile suggestions when the 863 // Test that we return only matching credit card profile suggestions when the
810 // selected form field has been partially filled out. 864 // selected form field has been partially filled out.
811 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { 865 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
812 // Set up our form data. 866 // Set up our form data.
813 FormData form; 867 FormData form;
814 CreateTestCreditCardFormData(&form, true); 868 CreateTestCreditCardFormData(&form, true, false);
815 std::vector<FormData> forms(1, form); 869 std::vector<FormData> forms(1, form);
816 FormsSeen(forms); 870 FormsSeen(forms);
817 871
818 FormField field; 872 FormField field;
819 autofill_test::CreateTestFormField( 873 autofill_test::CreateTestFormField(
820 "Card Number", "cardnumber", "4", "text", &field); 874 "Card Number", "cardnumber", "4", "text", &field);
821 GetAutoFillSuggestions(form, field); 875 GetAutoFillSuggestions(form, field);
822 876
823 // No suggestions provided, so send an empty vector as the results. 877 // No suggestions provided, so send an empty vector as the results.
824 // This triggers the combined message send. 878 // This triggers the combined message send.
(...skipping 15 matching lines...) Expand all
840 ExpectSuggestions(page_id, values, labels, icons, unique_ids, 894 ExpectSuggestions(page_id, values, labels, icons, unique_ids,
841 kDefaultPageID, arraysize(expected_values), expected_values, 895 kDefaultPageID, arraysize(expected_values), expected_values,
842 expected_labels, expected_icons, expected_unique_ids); 896 expected_labels, expected_icons, expected_unique_ids);
843 } 897 }
844 898
845 // Test that we return credit card profile suggestions when the selected form 899 // Test that we return credit card profile suggestions when the selected form
846 // field is not the credit card number field. 900 // field is not the credit card number field.
847 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { 901 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
848 // Set up our form data. 902 // Set up our form data.
849 FormData form; 903 FormData form;
850 CreateTestCreditCardFormData(&form, true); 904 CreateTestCreditCardFormData(&form, true, false);
851 std::vector<FormData> forms(1, form); 905 std::vector<FormData> forms(1, form);
852 FormsSeen(forms); 906 FormsSeen(forms);
853 907
854 const FormField& field = form.fields[0]; 908 const FormField& field = form.fields[0];
855 GetAutoFillSuggestions(form, field); 909 GetAutoFillSuggestions(form, field);
856 910
857 // No suggestions provided, so send an empty vector as the results. 911 // No suggestions provided, so send an empty vector as the results.
858 // This triggers the combined message send. 912 // This triggers the combined message send.
859 AutocompleteSuggestionsReturned(std::vector<string16>()); 913 AutocompleteSuggestionsReturned(std::vector<string16>());
860 914
(...skipping 22 matching lines...) Expand all
883 ExpectSuggestions(page_id, values, labels, icons, unique_ids, 937 ExpectSuggestions(page_id, values, labels, icons, unique_ids,
884 kDefaultPageID, arraysize(expected_values), expected_values, 938 kDefaultPageID, arraysize(expected_values), expected_values,
885 expected_labels, expected_icons, expected_unique_ids); 939 expected_labels, expected_icons, expected_unique_ids);
886 } 940 }
887 941
888 // Test that we return a warning explaining that credit card profile suggestions 942 // Test that we return a warning explaining that credit card profile suggestions
889 // are unavailable when the form is not https. 943 // are unavailable when the form is not https.
890 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { 944 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
891 // Set up our form data. 945 // Set up our form data.
892 FormData form; 946 FormData form;
893 CreateTestCreditCardFormData(&form, false); 947 CreateTestCreditCardFormData(&form, false, false);
894 std::vector<FormData> forms(1, form); 948 std::vector<FormData> forms(1, form);
895 FormsSeen(forms); 949 FormsSeen(forms);
896 950
897 const FormField& field = form.fields[0]; 951 const FormField& field = form.fields[0];
898 GetAutoFillSuggestions(form, field); 952 GetAutoFillSuggestions(form, field);
899 953
900 // No suggestions provided, so send an empty vector as the results. 954 // No suggestions provided, so send an empty vector as the results.
901 // This triggers the combined message send. 955 // This triggers the combined message send.
902 AutocompleteSuggestionsReturned(std::vector<string16>()); 956 AutocompleteSuggestionsReturned(std::vector<string16>());
903 957
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 test_personal_data_->ClearCreditCards(); 1002 test_personal_data_->ClearCreditCards();
949 GetAutoFillSuggestions(form, field); 1003 GetAutoFillSuggestions(form, field);
950 EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); 1004 EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
951 } 1005 }
952 1006
953 // Test that we return profile and credit card suggestions for combined forms. 1007 // Test that we return profile and credit card suggestions for combined forms.
954 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { 1008 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
955 // Set up our form data. 1009 // Set up our form data.
956 FormData form; 1010 FormData form;
957 CreateTestAddressFormData(&form); 1011 CreateTestAddressFormData(&form);
958 CreateTestCreditCardFormData(&form, true); 1012 CreateTestCreditCardFormData(&form, true, false);
959 std::vector<FormData> forms(1, form); 1013 std::vector<FormData> forms(1, form);
960 FormsSeen(forms); 1014 FormsSeen(forms);
961 1015
962 FormField field = form.fields[0]; 1016 FormField field = form.fields[0];
963 GetAutoFillSuggestions(form, field); 1017 GetAutoFillSuggestions(form, field);
964 1018
965 // No suggestions provided, so send an empty vector as the results. 1019 // No suggestions provided, so send an empty vector as the results.
966 // This triggers the combined message send. 1020 // This triggers the combined message send.
967 AutocompleteSuggestionsReturned(std::vector<string16>()); 1021 AutocompleteSuggestionsReturned(std::vector<string16>());
968 1022
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 } 1076 }
1023 1077
1024 // Test that for non-https forms with both address and credit card fields, we 1078 // Test that for non-https forms with both address and credit card fields, we
1025 // only return address suggestions. Instead of credit card suggestions, we 1079 // only return address suggestions. Instead of credit card suggestions, we
1026 // should return a warning explaining that credit card profile suggestions are 1080 // should return a warning explaining that credit card profile suggestions are
1027 // unavailable when the form is not https. 1081 // unavailable when the form is not https.
1028 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { 1082 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
1029 // Set up our form data. 1083 // Set up our form data.
1030 FormData form; 1084 FormData form;
1031 CreateTestAddressFormData(&form); 1085 CreateTestAddressFormData(&form);
1032 CreateTestCreditCardFormData(&form, false); 1086 CreateTestCreditCardFormData(&form, false, false);
1033 std::vector<FormData> forms(1, form); 1087 std::vector<FormData> forms(1, form);
1034 FormsSeen(forms); 1088 FormsSeen(forms);
1035 1089
1036 FormField field = form.fields[0]; 1090 FormField field = form.fields[0];
1037 GetAutoFillSuggestions(form, field); 1091 GetAutoFillSuggestions(form, field);
1038 1092
1039 // No suggestions provided, so send an empty vector as the results. 1093 // No suggestions provided, so send an empty vector as the results.
1040 // This triggers the combined message send. 1094 // This triggers the combined message send.
1041 AutocompleteSuggestionsReturned(std::vector<string16>()); 1095 AutocompleteSuggestionsReturned(std::vector<string16>());
1042 1096
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 int page_id = 0; 1336 int page_id = 0;
1283 FormData results; 1337 FormData results;
1284 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1338 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1285 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); 1339 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
1286 } 1340 }
1287 1341
1288 // Test that we correctly fill a credit card form. 1342 // Test that we correctly fill a credit card form.
1289 TEST_F(AutoFillManagerTest, FillCreditCardForm) { 1343 TEST_F(AutoFillManagerTest, FillCreditCardForm) {
1290 // Set up our form data. 1344 // Set up our form data.
1291 FormData form; 1345 FormData form;
1292 CreateTestCreditCardFormData(&form, true); 1346 CreateTestCreditCardFormData(&form, true, false);
1293 std::vector<FormData> forms(1, form); 1347 std::vector<FormData> forms(1, form);
1294 FormsSeen(forms); 1348 FormsSeen(forms);
1295 1349
1296 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); 1350 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
1297 FillAutoFillFormData( 1351 FillAutoFillFormData(
1298 kDefaultPageID, form, *form.fields.begin(), 1352 kDefaultPageID, form, *form.fields.begin(),
1299 autofill_manager_->PackGUIDs(guid, std::string())); 1353 autofill_manager_->PackGUIDs(guid, std::string()));
1300 1354
1301 int page_id = 0; 1355 int page_id = 0;
1302 FormData results; 1356 FormData results;
1303 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1357 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1304 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); 1358 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false);
1305 } 1359 }
1306 1360
1361 // Test that we correctly fill a credit card form with month input type.
1362 // 1. year empty, month empty
1363 TEST_F(AutoFillManagerTest, FillCreditCardFormNoYearNoMonth) {
1364 // Same as the SetUp(), but generate 4 credit cards with year month
1365 // combination.
1366 test_personal_data_->CreateTestCreditCardsYearAndMonth("", "");
1367 // Set up our form data.
1368 FormData form;
1369 CreateTestCreditCardFormData(&form, true, true);
1370 std::vector<FormData> forms(1, form);
1371 FormsSeen(forms);
1372
1373 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku")->guid();
1374 FillAutoFillFormData(
1375 kDefaultPageID, form, *form.fields.begin(),
1376 autofill_manager_->PackGUIDs(guid, std::string()));
1377
1378 int page_id = 0;
1379 FormData results;
1380 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1381 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results,
1382 kDefaultPageID, false, "", "");
1383 }
1384
1385
1386 // Test that we correctly fill a credit card form with month input type.
1387 // 2. year empty, month non-empty
1388 TEST_F(AutoFillManagerTest, FillCreditCardFormNoYearMonth) {
1389 // Same as the SetUp(), but generate 4 credit cards with year month
1390 // combination.
1391 test_personal_data_->CreateTestCreditCardsYearAndMonth("", "04");
1392 // Set up our form data.
1393 FormData form;
1394 CreateTestCreditCardFormData(&form, true, true);
1395 std::vector<FormData> forms(1, form);
1396 FormsSeen(forms);
1397
1398 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku")->guid();
1399 FillAutoFillFormData(
1400 kDefaultPageID, form, *form.fields.begin(),
1401 autofill_manager_->PackGUIDs(guid, std::string()));
1402
1403 int page_id = 0;
1404 FormData results;
1405 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1406 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results,
1407 kDefaultPageID, false, "", "04");
1408 }
1409
1410 // Test that we correctly fill a credit card form with month input type.
1411 // 3. year non-empty, month empty
1412 TEST_F(AutoFillManagerTest, FillCreditCardFormYearNoMonth) {
1413 // Same as the SetUp(), but generate 4 credit cards with year month
1414 // combination.
1415 test_personal_data_->CreateTestCreditCardsYearAndMonth("2012", "");
1416 // Set up our form data.
1417 FormData form;
1418 CreateTestCreditCardFormData(&form, true, true);
1419 std::vector<FormData> forms(1, form);
1420 FormsSeen(forms);
1421
1422 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku")->guid();
1423 FillAutoFillFormData(
1424 kDefaultPageID, form, *form.fields.begin(),
1425 autofill_manager_->PackGUIDs(guid, std::string()));
1426
1427 int page_id = 0;
1428 FormData results;
1429 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1430 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results,
1431 kDefaultPageID, false, "2012", "");
1432 }
1433
1434 // Test that we correctly fill a credit card form with month input type.
1435 // 4. year non-empty, month empty
1436 TEST_F(AutoFillManagerTest, FillCreditCardFormYearMonth) {
1437 // Same as the SetUp(), but generate 4 credit cards with year month
1438 // combination.
1439 test_personal_data_->ClearCreditCards();
1440 test_personal_data_->CreateTestCreditCardsYearAndMonth("2012", "04");
1441 // Set up our form data.
1442 FormData form;
1443 CreateTestCreditCardFormData(&form, true, true);
1444 std::vector<FormData> forms(1, form);
1445 FormsSeen(forms);
1446
1447 std::string guid = autofill_manager_->GetLabeledCreditCard("Miku")->guid();
1448 FillAutoFillFormData(
1449 kDefaultPageID, form, *form.fields.begin(),
1450 autofill_manager_->PackGUIDs(guid, std::string()));
1451
1452 int page_id = 0;
1453 FormData results;
1454 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1455 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results,
1456 kDefaultPageID, false, "2012", "04");
1457 }
1458
1307 // Test that we correctly fill a combined address and credit card form. 1459 // Test that we correctly fill a combined address and credit card form.
1308 TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) { 1460 TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) {
1309 // Set up our form data. 1461 // Set up our form data.
1310 FormData form; 1462 FormData form;
1311 CreateTestAddressFormData(&form); 1463 CreateTestAddressFormData(&form);
1312 CreateTestCreditCardFormData(&form, true); 1464 CreateTestCreditCardFormData(&form, true, false);
1313 std::vector<FormData> forms(1, form); 1465 std::vector<FormData> forms(1, form);
1314 FormsSeen(forms); 1466 FormsSeen(forms);
1315 1467
1316 // First fill the address data. 1468 // First fill the address data.
1317 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); 1469 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
1318 FillAutoFillFormData( 1470 FillAutoFillFormData(
1319 kDefaultPageID, form, form.fields[0], 1471 kDefaultPageID, form, form.fields[0],
1320 autofill_manager_->PackGUIDs(std::string(), guid)); 1472 autofill_manager_->PackGUIDs(std::string(), guid));
1321 1473
1322 int page_id = 0; 1474 int page_id = 0;
(...skipping 19 matching lines...) Expand all
1342 } 1494 }
1343 } 1495 }
1344 1496
1345 // Test that we correctly fill a previously auto-filled form. 1497 // Test that we correctly fill a previously auto-filled form.
1346 TEST_F(AutoFillManagerTest, FillAutoFilledForm) { 1498 TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
1347 // Set up our form data. 1499 // Set up our form data.
1348 FormData form; 1500 FormData form;
1349 CreateTestAddressFormData(&form); 1501 CreateTestAddressFormData(&form);
1350 // Mark one of the address fields as autofilled. 1502 // Mark one of the address fields as autofilled.
1351 form.fields[4].set_autofilled(true); 1503 form.fields[4].set_autofilled(true);
1352 CreateTestCreditCardFormData(&form, true); 1504 CreateTestCreditCardFormData(&form, true, false);
1353 std::vector<FormData> forms(1, form); 1505 std::vector<FormData> forms(1, form);
1354 FormsSeen(forms); 1506 FormsSeen(forms);
1355 1507
1356 // First fill the address data. 1508 // First fill the address data.
1357 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); 1509 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
1358 FillAutoFillFormData( 1510 FillAutoFillFormData(
1359 kDefaultPageID, form, *form.fields.begin(), 1511 kDefaultPageID, form, *form.fields.begin(),
1360 autofill_manager_->PackGUIDs(std::string(), guid)); 1512 autofill_manager_->PackGUIDs(std::string(), guid));
1361 1513
1362 int page_id = 0; 1514 int page_id = 0;
1363 FormData results; 1515 FormData results;
1364 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1516 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1365 { 1517 {
1366 SCOPED_TRACE("Address"); 1518 SCOPED_TRACE("Address");
1367 ExpectFilledForm(page_id, results, kDefaultPageID, 1519 ExpectFilledForm(page_id, results, kDefaultPageID,
1368 "Elvis", "", "", "", "", "", "", "", "", "", "", "", 1520 "Elvis", "", "", "", "", "", "", "", "", "", "", "",
1369 "", "", "", "", true, true); 1521 "", "", "", "", true, true, false);
1370 } 1522 }
1371 1523
1372 // Now fill the credit card data. 1524 // Now fill the credit card data.
1373 const int kPageID2 = 2; 1525 const int kPageID2 = 2;
1374 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); 1526 guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
1375 FillAutoFillFormData( 1527 FillAutoFillFormData(
1376 kPageID2, form, form.fields.back(), 1528 kPageID2, form, form.fields.back(),
1377 autofill_manager_->PackGUIDs(guid, std::string())); 1529 autofill_manager_->PackGUIDs(guid, std::string()));
1378 1530
1379 page_id = 0; 1531 page_id = 0;
(...skipping 15 matching lines...) Expand all
1395 FillAutoFillFormData( 1547 FillAutoFillFormData(
1396 kPageID3, form, *form.fields.rbegin(), 1548 kPageID3, form, *form.fields.rbegin(),
1397 autofill_manager_->PackGUIDs(guid, std::string())); 1549 autofill_manager_->PackGUIDs(guid, std::string()));
1398 1550
1399 page_id = 0; 1551 page_id = 0;
1400 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1552 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1401 { 1553 {
1402 SCOPED_TRACE("Credit card 2"); 1554 SCOPED_TRACE("Credit card 2");
1403 ExpectFilledForm(page_id, results, kPageID3, 1555 ExpectFilledForm(page_id, results, kPageID3,
1404 "", "", "", "", "", "", "", "", "", "", "", "", 1556 "", "", "", "", "", "", "", "", "", "", "", "",
1405 "", "", "", "2012", true, true); 1557 "", "", "", "2012", true, true, false);
1406 } 1558 }
1407 } 1559 }
1408 1560
1409 // Test that we correctly fill a phone number split across multiple fields. 1561 // Test that we correctly fill a phone number split across multiple fields.
1410 TEST_F(AutoFillManagerTest, FillPhoneNumber) { 1562 TEST_F(AutoFillManagerTest, FillPhoneNumber) {
1411 // Set up our form data. 1563 // Set up our form data.
1412 FormData form; 1564 FormData form;
1413 form.name = ASCIIToUTF16("MyPhoneForm"); 1565 form.name = ASCIIToUTF16("MyPhoneForm");
1414 form.method = ASCIIToUTF16("POST"); 1566 form.method = ASCIIToUTF16("POST");
1415 form.origin = GURL("http://myform.com/phone_form.html"); 1567 form.origin = GURL("http://myform.com/phone_form.html");
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 #else 1731 #else
1580 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( 1732 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
1581 prefs::kAutoFillAuxiliaryProfilesEnabled)); 1733 prefs::kAutoFillAuxiliaryProfilesEnabled));
1582 profile()->GetPrefs()->SetBoolean( 1734 profile()->GetPrefs()->SetBoolean(
1583 prefs::kAutoFillAuxiliaryProfilesEnabled, true); 1735 prefs::kAutoFillAuxiliaryProfilesEnabled, true);
1584 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); 1736 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled);
1585 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( 1737 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
1586 prefs::kAutoFillAuxiliaryProfilesEnabled)); 1738 prefs::kAutoFillAuxiliaryProfilesEnabled));
1587 #endif 1739 #endif
1588 } 1740 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/credit_card.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698