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