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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 form->fields.push_back(field); | 174 form->fields.push_back(field); |
175 autofill_test::CreateTestFormField( | 175 autofill_test::CreateTestFormField( |
176 "Phone Number", "phonenumber", "", "text", &field); | 176 "Phone Number", "phonenumber", "", "text", &field); |
177 form->fields.push_back(field); | 177 form->fields.push_back(field); |
178 autofill_test::CreateTestFormField( | 178 autofill_test::CreateTestFormField( |
179 "Fax", "fax", "", "text", &field); | 179 "Fax", "fax", "", "text", &field); |
180 form->fields.push_back(field); | 180 form->fields.push_back(field); |
181 autofill_test::CreateTestFormField( | 181 autofill_test::CreateTestFormField( |
182 "Email", "email", "", "text", &field); | 182 "Email", "email", "", "text", &field); |
183 form->fields.push_back(field); | 183 form->fields.push_back(field); |
184 } | 184 autofill_test::CreateTestFormField( |
| 185 "Email", "email2", "", "email", &field); |
| 186 form->fields.push_back(field); |
| 187 autofill_test::CreateTestFormField( |
| 188 "Phone Number", "phonenumber2", "", "tel", &field); |
| 189 form->fields.push_back(field); |
| 190 } |
185 | 191 |
186 // Populates |form| with data corresponding to a simple credit card form. | 192 // Populates |form| with data corresponding to a simple credit card form. |
187 // Note that this actually appends fields to the form data, which can be useful | 193 // Note that this actually appends fields to the form data, which can be useful |
188 // for building up more complex test forms. | 194 // for building up more complex test forms. |
189 void CreateTestCreditCardFormData(FormData* form, bool is_https) { | 195 void CreateTestCreditCardFormData(FormData* form, |
| 196 bool is_https, |
| 197 bool use_month_type) { |
190 form->name = ASCIIToUTF16("MyForm"); | 198 form->name = ASCIIToUTF16("MyForm"); |
191 form->method = ASCIIToUTF16("POST"); | 199 form->method = ASCIIToUTF16("POST"); |
192 if (is_https) { | 200 if (is_https) { |
193 form->origin = GURL("https://myform.com/form.html"); | 201 form->origin = GURL("https://myform.com/form.html"); |
194 form->action = GURL("https://myform.com/submit.html"); | 202 form->action = GURL("https://myform.com/submit.html"); |
195 } else { | 203 } else { |
196 form->origin = GURL("http://myform.com/form.html"); | 204 form->origin = GURL("http://myform.com/form.html"); |
197 form->action = GURL("http://myform.com/submit.html"); | 205 form->action = GURL("http://myform.com/submit.html"); |
198 } | 206 } |
199 form->user_submitted = true; | 207 form->user_submitted = true; |
200 | 208 |
201 FormField field; | 209 FormField field; |
202 autofill_test::CreateTestFormField( | 210 autofill_test::CreateTestFormField( |
203 "Name on Card", "nameoncard", "", "text", &field); | 211 "Name on Card", "nameoncard", "", "text", &field); |
204 form->fields.push_back(field); | 212 form->fields.push_back(field); |
205 autofill_test::CreateTestFormField( | 213 autofill_test::CreateTestFormField( |
206 "Card Number", "cardnumber", "", "text", &field); | 214 "Card Number", "cardnumber", "", "text", &field); |
207 form->fields.push_back(field); | 215 form->fields.push_back(field); |
208 autofill_test::CreateTestFormField( | 216 if (use_month_type) { |
209 "Expiration Date", "ccmonth", "", "text", &field); | 217 autofill_test::CreateTestFormField( |
210 form->fields.push_back(field); | 218 "Expiration Date", "ccmonth", "", "month", &field); |
211 autofill_test::CreateTestFormField( | 219 form->fields.push_back(field); |
212 "", "ccyear", "", "text", &field); | 220 } else { |
213 form->fields.push_back(field); | 221 autofill_test::CreateTestFormField( |
| 222 "Expiration Date", "ccmonth", "", "text", &field); |
| 223 form->fields.push_back(field); |
| 224 autofill_test::CreateTestFormField( |
| 225 "", "ccyear", "", "text", &field); |
| 226 form->fields.push_back(field); |
| 227 } |
214 } | 228 } |
215 | 229 |
216 void ExpectSuggestions(int page_id, | 230 void ExpectSuggestions(int page_id, |
217 const std::vector<string16>& values, | 231 const std::vector<string16>& values, |
218 const std::vector<string16>& labels, | 232 const std::vector<string16>& labels, |
219 const std::vector<string16>& icons, | 233 const std::vector<string16>& icons, |
220 const std::vector<int>& unique_ids, | 234 const std::vector<int>& unique_ids, |
221 int expected_page_id, | 235 int expected_page_id, |
222 size_t expected_num_suggestions, | 236 size_t expected_num_suggestions, |
223 const string16 expected_values[], | 237 const string16 expected_values[], |
(...skipping 10 matching lines...) Expand all Loading... |
234 EXPECT_EQ(expected_values[i], values[i]); | 248 EXPECT_EQ(expected_values[i], values[i]); |
235 EXPECT_EQ(expected_labels[i], labels[i]); | 249 EXPECT_EQ(expected_labels[i], labels[i]); |
236 EXPECT_EQ(expected_icons[i], icons[i]); | 250 EXPECT_EQ(expected_icons[i], icons[i]); |
237 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); | 251 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); |
238 } | 252 } |
239 } | 253 } |
240 | 254 |
241 // Verifies that the |filled_form| has been filled with the given data. | 255 // Verifies that the |filled_form| has been filled with the given data. |
242 // Verifies address fields if |has_address_fields| is true, and verifies | 256 // Verifies address fields if |has_address_fields| is true, and verifies |
243 // credit card fields if |has_credit_card_fields| is true. Verifies both if both | 257 // credit card fields if |has_credit_card_fields| is true. Verifies both if both |
244 // are true. | 258 // are true. |use_month_type| is used for credit card input month type. |
245 void ExpectFilledForm(int page_id, | 259 void ExpectFilledForm(int page_id, |
246 const FormData& filled_form, | 260 const FormData& filled_form, |
247 int expected_page_id, | 261 int expected_page_id, |
248 const char* first, | 262 const char* first, |
249 const char* middle, | 263 const char* middle, |
250 const char* last, | 264 const char* last, |
251 const char* address1, | 265 const char* address1, |
252 const char* address2, | 266 const char* address2, |
253 const char* city, | 267 const char* city, |
254 const char* state, | 268 const char* state, |
255 const char* postal_code, | 269 const char* postal_code, |
256 const char* country, | 270 const char* country, |
257 const char* phone, | 271 const char* phone, |
258 const char* fax, | 272 const char* fax, |
259 const char* email, | 273 const char* email, |
260 const char* name_on_card, | 274 const char* name_on_card, |
261 const char* card_number, | 275 const char* card_number, |
262 const char* expiration_month, | 276 const char* expiration_month, |
263 const char* expiration_year, | 277 const char* expiration_year, |
264 bool has_address_fields, | 278 bool has_address_fields, |
265 bool has_credit_card_fields) { | 279 bool has_credit_card_fields, |
| 280 int use_month_type) { |
266 // The number of fields in the address and credit card forms created above. | 281 // The number of fields in the address and credit card forms created above. |
267 const size_t kAddressFormSize = 12; | 282 const size_t kAddressFormSize = 14; |
268 const size_t kCreditCardFormSize = 4; | 283 const size_t kCreditCardFormSize = use_month_type ? 3 : 4; |
269 | 284 |
270 EXPECT_EQ(expected_page_id, page_id); | 285 EXPECT_EQ(expected_page_id, page_id); |
271 EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name); | 286 EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name); |
272 EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method); | 287 EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method); |
273 if (has_credit_card_fields) { | 288 if (has_credit_card_fields) { |
274 EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin); | 289 EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin); |
275 EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action); | 290 EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action); |
276 } else { | 291 } else { |
277 EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin); | 292 EXPECT_EQ(GURL("http://myform.com/form.html"), filled_form.origin); |
278 EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action); | 293 EXPECT_EQ(GURL("http://myform.com/submit.html"), filled_form.action); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); | 332 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); |
318 autofill_test::CreateTestFormField( | 333 autofill_test::CreateTestFormField( |
319 "Phone Number", "phonenumber", phone, "text", &field); | 334 "Phone Number", "phonenumber", phone, "text", &field); |
320 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); | 335 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); |
321 autofill_test::CreateTestFormField( | 336 autofill_test::CreateTestFormField( |
322 "Fax", "fax", fax, "text", &field); | 337 "Fax", "fax", fax, "text", &field); |
323 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); | 338 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); |
324 autofill_test::CreateTestFormField( | 339 autofill_test::CreateTestFormField( |
325 "Email", "email", email, "text", &field); | 340 "Email", "email", email, "text", &field); |
326 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); | 341 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); |
327 } | 342 autofill_test::CreateTestFormField( |
| 343 "Email", "email2", email, "email", &field); |
| 344 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[12])); |
| 345 autofill_test::CreateTestFormField( |
| 346 "Phone Number", "phonenumber2", phone, "tel", &field); |
| 347 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[13])); |
| 348 } |
328 | 349 |
329 if (has_credit_card_fields) { | 350 if (has_credit_card_fields) { |
330 size_t offset = has_address_fields? kAddressFormSize : 0; | 351 size_t offset = has_address_fields? kAddressFormSize : 0; |
331 autofill_test::CreateTestFormField( | 352 autofill_test::CreateTestFormField( |
332 "Name on Card", "nameoncard", name_on_card, "text", &field); | 353 "Name on Card", "nameoncard", name_on_card, "text", &field); |
333 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); | 354 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); |
334 autofill_test::CreateTestFormField( | 355 autofill_test::CreateTestFormField( |
335 "Card Number", "cardnumber", card_number, "text", &field); | 356 "Card Number", "cardnumber", card_number, "text", &field); |
336 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); | 357 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); |
337 autofill_test::CreateTestFormField( | 358 if (use_month_type) { |
338 "Expiration Date", "ccmonth", expiration_month, "text", &field); | 359 autofill_test::CreateTestFormField("Expiration Date", "ccmonth", |
339 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | 360 (expiration_year + std::string("-") + expiration_month).c_str(), |
340 autofill_test::CreateTestFormField( | 361 "month", &field); |
341 "", "ccyear", expiration_year, "text", &field); | 362 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); |
342 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); | 363 } else { |
| 364 autofill_test::CreateTestFormField( |
| 365 "Expiration Date", "ccmonth", expiration_month, "text", &field); |
| 366 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); |
| 367 autofill_test::CreateTestFormField( |
| 368 "", "ccyear", expiration_year, "text", &field); |
| 369 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); |
| 370 } |
343 } | 371 } |
344 } | 372 } |
345 | 373 |
346 void ExpectFilledAddressFormElvis(int page_id, | 374 void ExpectFilledAddressFormElvis(int page_id, |
347 const FormData& filled_form, | 375 const FormData& filled_form, |
348 int expected_page_id, | 376 int expected_page_id, |
349 bool has_credit_card_fields) { | 377 bool has_credit_card_fields) { |
350 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", | 378 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", |
351 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", | 379 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", |
352 "Tennessee", "38116", "USA", "12345678901", "", | 380 "Tennessee", "38116", "USA", "12345678901", "", |
353 "theking@gmail.com", "", "", "", "", true, | 381 "theking@gmail.com", "", "", "", "", true, |
354 has_credit_card_fields); | 382 has_credit_card_fields, false); |
355 } | 383 } |
356 | 384 |
357 void ExpectFilledCreditCardFormElvis(int page_id, | 385 void ExpectFilledCreditCardFormElvis(int page_id, |
358 const FormData& filled_form, | 386 const FormData& filled_form, |
359 int expected_page_id, | 387 int expected_page_id, |
360 bool has_address_fields) { | 388 bool has_address_fields, |
| 389 bool use_month_type) { |
361 ExpectFilledForm(page_id, filled_form, expected_page_id, | 390 ExpectFilledForm(page_id, filled_form, expected_page_id, |
362 "", "", "", "", "", "", "", "", "", "", "", "", | 391 "", "", "", "", "", "", "", "", "", "", "", "", |
363 "Elvis Presley", "4234567890123456", "04", "2012", | 392 "Elvis Presley", "4234567890123456", "04", "2012", |
364 has_address_fields, true); | 393 has_address_fields, true, use_month_type); |
365 } | 394 } |
366 | 395 |
367 class TestAutoFillManager : public AutoFillManager { | 396 class TestAutoFillManager : public AutoFillManager { |
368 public: | 397 public: |
369 TestAutoFillManager(TabContents* tab_contents, | 398 TestAutoFillManager(TabContents* tab_contents, |
370 TestPersonalDataManager* personal_manager) | 399 TestPersonalDataManager* personal_manager) |
371 : AutoFillManager(tab_contents, personal_manager), | 400 : AutoFillManager(tab_contents, personal_manager), |
372 autofill_enabled_(true) { | 401 autofill_enabled_(true) { |
373 test_personal_data_ = personal_manager; | 402 test_personal_data_ = personal_manager; |
374 } | 403 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 // Now clear the test profiles and try again -- we shouldn't return a warning. | 755 // Now clear the test profiles and try again -- we shouldn't return a warning. |
727 test_personal_data_->ClearAutoFillProfiles(); | 756 test_personal_data_->ClearAutoFillProfiles(); |
728 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 757 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
729 } | 758 } |
730 | 759 |
731 // Test that we return all credit card profile suggestions when all form fields | 760 // Test that we return all credit card profile suggestions when all form fields |
732 // are empty. | 761 // are empty. |
733 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 762 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
734 // Set up our form data. | 763 // Set up our form data. |
735 FormData form; | 764 FormData form; |
736 CreateTestCreditCardFormData(&form, true); | 765 CreateTestCreditCardFormData(&form, true, false); |
737 std::vector<FormData> forms(1, form); | 766 std::vector<FormData> forms(1, form); |
738 autofill_manager_->FormsSeen(forms); | 767 autofill_manager_->FormsSeen(forms); |
739 | 768 |
740 FormField field = form.fields[1]; | 769 FormField field = form.fields[1]; |
741 rvh()->ResetAutoFillState(kDefaultPageID); | 770 rvh()->ResetAutoFillState(kDefaultPageID); |
742 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 771 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
743 | 772 |
744 // No suggestions provided, so send an empty vector as the results. | 773 // No suggestions provided, so send an empty vector as the results. |
745 // This triggers the combined message send. | 774 // This triggers the combined message send. |
746 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 775 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
(...skipping 23 matching lines...) Expand all Loading... |
770 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 799 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
771 kDefaultPageID, arraysize(expected_values), expected_values, | 800 kDefaultPageID, arraysize(expected_values), expected_values, |
772 expected_labels, expected_icons, expected_unique_ids); | 801 expected_labels, expected_icons, expected_unique_ids); |
773 } | 802 } |
774 | 803 |
775 // Test that we return only matching credit card profile suggestions when the | 804 // Test that we return only matching credit card profile suggestions when the |
776 // selected form field has been partially filled out. | 805 // selected form field has been partially filled out. |
777 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 806 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
778 // Set up our form data. | 807 // Set up our form data. |
779 FormData form; | 808 FormData form; |
780 CreateTestCreditCardFormData(&form, true); | 809 CreateTestCreditCardFormData(&form, true, false); |
781 std::vector<FormData> forms(1, form); | 810 std::vector<FormData> forms(1, form); |
782 autofill_manager_->FormsSeen(forms); | 811 autofill_manager_->FormsSeen(forms); |
783 | 812 |
784 FormField field; | 813 FormField field; |
785 autofill_test::CreateTestFormField( | 814 autofill_test::CreateTestFormField( |
786 "Card Number", "cardnumber", "4", "text", &field); | 815 "Card Number", "cardnumber", "4", "text", &field); |
787 rvh()->ResetAutoFillState(kDefaultPageID); | 816 rvh()->ResetAutoFillState(kDefaultPageID); |
788 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 817 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
789 | 818 |
790 // No suggestions provided, so send an empty vector as the results. | 819 // No suggestions provided, so send an empty vector as the results. |
(...skipping 16 matching lines...) Expand all Loading... |
807 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 836 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
808 kDefaultPageID, arraysize(expected_values), expected_values, | 837 kDefaultPageID, arraysize(expected_values), expected_values, |
809 expected_labels, expected_icons, expected_unique_ids); | 838 expected_labels, expected_icons, expected_unique_ids); |
810 } | 839 } |
811 | 840 |
812 // Test that we return credit card profile suggestions when the selected form | 841 // Test that we return credit card profile suggestions when the selected form |
813 // field is not the credit card number field. | 842 // field is not the credit card number field. |
814 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 843 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { |
815 // Set up our form data. | 844 // Set up our form data. |
816 FormData form; | 845 FormData form; |
817 CreateTestCreditCardFormData(&form, true); | 846 CreateTestCreditCardFormData(&form, true, false); |
818 std::vector<FormData> forms(1, form); | 847 std::vector<FormData> forms(1, form); |
819 autofill_manager_->FormsSeen(forms); | 848 autofill_manager_->FormsSeen(forms); |
820 | 849 |
821 const FormField& field = form.fields[0]; | 850 const FormField& field = form.fields[0]; |
822 rvh()->ResetAutoFillState(kDefaultPageID); | 851 rvh()->ResetAutoFillState(kDefaultPageID); |
823 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 852 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
824 | 853 |
825 // No suggestions provided, so send an empty vector as the results. | 854 // No suggestions provided, so send an empty vector as the results. |
826 // This triggers the combined message send. | 855 // This triggers the combined message send. |
827 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 856 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
(...skipping 23 matching lines...) Expand all Loading... |
851 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 880 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
852 kDefaultPageID, arraysize(expected_values), expected_values, | 881 kDefaultPageID, arraysize(expected_values), expected_values, |
853 expected_labels, expected_icons, expected_unique_ids); | 882 expected_labels, expected_icons, expected_unique_ids); |
854 } | 883 } |
855 | 884 |
856 // Test that we return a warning explaining that credit card profile suggestions | 885 // Test that we return a warning explaining that credit card profile suggestions |
857 // are unavailable when the form is not https. | 886 // are unavailable when the form is not https. |
858 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 887 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
859 // Set up our form data. | 888 // Set up our form data. |
860 FormData form; | 889 FormData form; |
861 CreateTestCreditCardFormData(&form, false); | 890 CreateTestCreditCardFormData(&form, false, false); |
862 std::vector<FormData> forms(1, form); | 891 std::vector<FormData> forms(1, form); |
863 autofill_manager_->FormsSeen(forms); | 892 autofill_manager_->FormsSeen(forms); |
864 | 893 |
865 const FormField& field = form.fields[0]; | 894 const FormField& field = form.fields[0]; |
866 rvh()->ResetAutoFillState(kDefaultPageID); | 895 rvh()->ResetAutoFillState(kDefaultPageID); |
867 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 896 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
868 | 897 |
869 // No suggestions provided, so send an empty vector as the results. | 898 // No suggestions provided, so send an empty vector as the results. |
870 // This triggers the combined message send. | 899 // This triggers the combined message send. |
871 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 900 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 // Clear the test credit cards and try again -- we shouldn't return a warning. | 947 // Clear the test credit cards and try again -- we shouldn't return a warning. |
919 test_personal_data_->ClearCreditCards(); | 948 test_personal_data_->ClearCreditCards(); |
920 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 949 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
921 } | 950 } |
922 | 951 |
923 // Test that we return profile and credit card suggestions for combined forms. | 952 // Test that we return profile and credit card suggestions for combined forms. |
924 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { | 953 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { |
925 // Set up our form data. | 954 // Set up our form data. |
926 FormData form; | 955 FormData form; |
927 CreateTestAddressFormData(&form); | 956 CreateTestAddressFormData(&form); |
928 CreateTestCreditCardFormData(&form, true); | 957 CreateTestCreditCardFormData(&form, true, false); |
929 std::vector<FormData> forms(1, form); | 958 std::vector<FormData> forms(1, form); |
930 autofill_manager_->FormsSeen(forms); | 959 autofill_manager_->FormsSeen(forms); |
931 | 960 |
932 FormField field = form.fields[0]; | 961 FormField field = form.fields[0]; |
933 rvh()->ResetAutoFillState(kDefaultPageID); | 962 rvh()->ResetAutoFillState(kDefaultPageID); |
934 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 963 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
935 | 964 |
936 // No suggestions provided, so send an empty vector as the results. | 965 // No suggestions provided, so send an empty vector as the results. |
937 // This triggers the combined message send. | 966 // This triggers the combined message send. |
938 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 967 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 } | 1024 } |
996 | 1025 |
997 // Test that for non-https forms with both address and credit card fields, we | 1026 // Test that for non-https forms with both address and credit card fields, we |
998 // only return address suggestions. Instead of credit card suggestions, we | 1027 // only return address suggestions. Instead of credit card suggestions, we |
999 // should return a warning explaining that credit card profile suggestions are | 1028 // should return a warning explaining that credit card profile suggestions are |
1000 // unavailable when the form is not https. | 1029 // unavailable when the form is not https. |
1001 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1030 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
1002 // Set up our form data. | 1031 // Set up our form data. |
1003 FormData form; | 1032 FormData form; |
1004 CreateTestAddressFormData(&form); | 1033 CreateTestAddressFormData(&form); |
1005 CreateTestCreditCardFormData(&form, false); | 1034 CreateTestCreditCardFormData(&form, false, false); |
1006 std::vector<FormData> forms(1, form); | 1035 std::vector<FormData> forms(1, form); |
1007 autofill_manager_->FormsSeen(forms); | 1036 autofill_manager_->FormsSeen(forms); |
1008 | 1037 |
1009 FormField field = form.fields[0]; | 1038 FormField field = form.fields[0]; |
1010 rvh()->ResetAutoFillState(kDefaultPageID); | 1039 rvh()->ResetAutoFillState(kDefaultPageID); |
1011 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 1040 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
1012 | 1041 |
1013 // No suggestions provided, so send an empty vector as the results. | 1042 // No suggestions provided, so send an empty vector as the results. |
1014 // This triggers the combined message send. | 1043 // This triggers the combined message send. |
1015 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); | 1044 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 int page_id = 0; | 1290 int page_id = 0; |
1262 FormData results; | 1291 FormData results; |
1263 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1292 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1264 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 1293 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
1265 } | 1294 } |
1266 | 1295 |
1267 // Test that we correctly fill a credit card form. | 1296 // Test that we correctly fill a credit card form. |
1268 TEST_F(AutoFillManagerTest, FillCreditCardForm) { | 1297 TEST_F(AutoFillManagerTest, FillCreditCardForm) { |
1269 // Set up our form data. | 1298 // Set up our form data. |
1270 FormData form; | 1299 FormData form; |
1271 CreateTestCreditCardFormData(&form, true); | 1300 CreateTestCreditCardFormData(&form, true, false); |
1272 std::vector<FormData> forms(1, form); | 1301 std::vector<FormData> forms(1, form); |
1273 autofill_manager_->FormsSeen(forms); | 1302 autofill_manager_->FormsSeen(forms); |
1274 | 1303 |
| 1304 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); |
| 1305 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
| 1306 kDefaultPageID, form, *form.fields.begin(), |
| 1307 autofill_manager_->PackGUIDs(guid, std::string()))); |
| 1308 |
| 1309 int page_id = 0; |
| 1310 FormData results; |
| 1311 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
| 1312 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false, |
| 1313 false); |
| 1314 } |
| 1315 |
| 1316 // Test that we correctly fill a credit card form with month input type. |
| 1317 TEST_F(AutoFillManagerTest, FillCreditCardFormWithMonthInput) { |
| 1318 // Set up our form data. |
| 1319 FormData form; |
| 1320 CreateTestCreditCardFormData(&form, true, true); |
| 1321 std::vector<FormData> forms(1, form); |
| 1322 autofill_manager_->FormsSeen(forms); |
| 1323 |
1275 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); | 1324 std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); |
1276 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1325 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
1277 kDefaultPageID, form, *form.fields.begin(), | 1326 kDefaultPageID, form, *form.fields.begin(), |
1278 autofill_manager_->PackGUIDs(guid, std::string()))); | 1327 autofill_manager_->PackGUIDs(guid, std::string()))); |
1279 | 1328 |
1280 int page_id = 0; | 1329 int page_id = 0; |
1281 FormData results; | 1330 FormData results; |
1282 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1331 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1283 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); | 1332 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false, |
| 1333 true); |
1284 } | 1334 } |
1285 | 1335 |
1286 // Test that we correctly fill a combined address and credit card form. | 1336 // Test that we correctly fill a combined address and credit card form. |
1287 TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) { | 1337 TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) { |
1288 // Set up our form data. | 1338 // Set up our form data. |
1289 FormData form; | 1339 FormData form; |
1290 CreateTestAddressFormData(&form); | 1340 CreateTestAddressFormData(&form); |
1291 CreateTestCreditCardFormData(&form, true); | 1341 CreateTestCreditCardFormData(&form, true, false); |
1292 std::vector<FormData> forms(1, form); | 1342 std::vector<FormData> forms(1, form); |
1293 autofill_manager_->FormsSeen(forms); | 1343 autofill_manager_->FormsSeen(forms); |
1294 | 1344 |
1295 // First fill the address data. | 1345 // First fill the address data. |
1296 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); | 1346 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); |
1297 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1347 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
1298 kDefaultPageID, form, form.fields[0], | 1348 kDefaultPageID, form, form.fields[0], |
1299 autofill_manager_->PackGUIDs(std::string(), guid))); | 1349 autofill_manager_->PackGUIDs(std::string(), guid))); |
1300 | 1350 |
1301 int page_id = 0; | 1351 int page_id = 0; |
1302 FormData results; | 1352 FormData results; |
1303 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1353 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1304 { | 1354 { |
1305 SCOPED_TRACE("Address"); | 1355 SCOPED_TRACE("Address"); |
1306 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, true); | 1356 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, true); |
1307 } | 1357 } |
1308 | 1358 |
1309 // Now fill the credit card data. | 1359 // Now fill the credit card data. |
1310 process()->sink().ClearMessages(); | 1360 process()->sink().ClearMessages(); |
1311 const int kPageID2 = 2; | 1361 const int kPageID2 = 2; |
1312 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); | 1362 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); |
1313 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1363 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
1314 kPageID2, form, form.fields.back(), | 1364 kPageID2, form, form.fields.back(), |
1315 autofill_manager_->PackGUIDs(guid, std::string()))); | 1365 autofill_manager_->PackGUIDs(guid, std::string()))); |
1316 | 1366 |
1317 page_id = 0; | 1367 page_id = 0; |
1318 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1368 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1319 { | 1369 { |
1320 SCOPED_TRACE("Credit card"); | 1370 SCOPED_TRACE("Credit card"); |
1321 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); | 1371 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true, false); |
1322 } | 1372 } |
1323 } | 1373 } |
1324 | 1374 |
1325 // Test that we correctly fill a previously auto-filled form. | 1375 // Test that we correctly fill a previously auto-filled form. |
1326 TEST_F(AutoFillManagerTest, FillAutoFilledForm) { | 1376 TEST_F(AutoFillManagerTest, FillAutoFilledForm) { |
1327 // Set up our form data. | 1377 // Set up our form data. |
1328 FormData form; | 1378 FormData form; |
1329 CreateTestAddressFormData(&form); | 1379 CreateTestAddressFormData(&form); |
1330 // Mark one of the address fields as autofilled. | 1380 // Mark one of the address fields as autofilled. |
1331 form.fields[4].set_autofilled(true); | 1381 form.fields[4].set_autofilled(true); |
1332 CreateTestCreditCardFormData(&form, true); | 1382 CreateTestCreditCardFormData(&form, true, false); |
1333 std::vector<FormData> forms(1, form); | 1383 std::vector<FormData> forms(1, form); |
1334 autofill_manager_->FormsSeen(forms); | 1384 autofill_manager_->FormsSeen(forms); |
1335 | 1385 |
1336 // First fill the address data. | 1386 // First fill the address data. |
1337 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); | 1387 std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid(); |
1338 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1388 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
1339 kDefaultPageID, form, *form.fields.begin(), | 1389 kDefaultPageID, form, *form.fields.begin(), |
1340 autofill_manager_->PackGUIDs(std::string(), guid))); | 1390 autofill_manager_->PackGUIDs(std::string(), guid))); |
1341 | 1391 |
1342 int page_id = 0; | 1392 int page_id = 0; |
1343 FormData results; | 1393 FormData results; |
1344 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1394 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1345 { | 1395 { |
1346 SCOPED_TRACE("Address"); | 1396 SCOPED_TRACE("Address"); |
1347 ExpectFilledForm(page_id, results, kDefaultPageID, | 1397 ExpectFilledForm(page_id, results, kDefaultPageID, |
1348 "Elvis", "", "", "", "", "", "", "", "", "", "", "", | 1398 "Elvis", "", "", "", "", "", "", "", "", "", "", "", |
1349 "", "", "", "", true, true); | 1399 "", "", "", "", true, true, false); |
1350 } | 1400 } |
1351 | 1401 |
1352 // Now fill the credit card data. | 1402 // Now fill the credit card data. |
1353 process()->sink().ClearMessages(); | 1403 process()->sink().ClearMessages(); |
1354 const int kPageID2 = 2; | 1404 const int kPageID2 = 2; |
1355 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); | 1405 guid = autofill_manager_->GetLabeledCreditCard("First")->guid(); |
1356 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1406 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
1357 kPageID2, form, form.fields.back(), | 1407 kPageID2, form, form.fields.back(), |
1358 autofill_manager_->PackGUIDs(guid, std::string()))); | 1408 autofill_manager_->PackGUIDs(guid, std::string()))); |
1359 | 1409 |
1360 page_id = 0; | 1410 page_id = 0; |
1361 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1411 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1362 { | 1412 { |
1363 SCOPED_TRACE("Credit card 1"); | 1413 SCOPED_TRACE("Credit card 1"); |
1364 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); | 1414 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true, false); |
1365 } | 1415 } |
1366 | 1416 |
1367 // Now set the credit card fields to also be auto-filled, and try again to | 1417 // Now set the credit card fields to also be auto-filled, and try again to |
1368 // fill the credit card data | 1418 // fill the credit card data |
1369 for (std::vector<FormField>::iterator iter = form.fields.begin(); | 1419 for (std::vector<FormField>::iterator iter = form.fields.begin(); |
1370 iter != form.fields.end(); | 1420 iter != form.fields.end(); |
1371 ++iter){ | 1421 ++iter){ |
1372 iter->set_autofilled(true); | 1422 iter->set_autofilled(true); |
1373 } | 1423 } |
1374 | 1424 |
1375 process()->sink().ClearMessages(); | 1425 process()->sink().ClearMessages(); |
1376 const int kPageID3 = 3; | 1426 const int kPageID3 = 3; |
1377 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 1427 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
1378 kPageID3, form, *form.fields.rbegin(), | 1428 kPageID3, form, *form.fields.rbegin(), |
1379 autofill_manager_->PackGUIDs(guid, std::string()))); | 1429 autofill_manager_->PackGUIDs(guid, std::string()))); |
1380 | 1430 |
1381 page_id = 0; | 1431 page_id = 0; |
1382 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 1432 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
1383 { | 1433 { |
1384 SCOPED_TRACE("Credit card 2"); | 1434 SCOPED_TRACE("Credit card 2"); |
1385 ExpectFilledForm(page_id, results, kPageID3, | 1435 ExpectFilledForm(page_id, results, kPageID3, |
1386 "", "", "", "", "", "", "", "", "", "", "", "", | 1436 "", "", "", "", "", "", "", "", "", "", "", "", |
1387 "", "", "", "2012", true, true); | 1437 "", "", "", "2012", true, true, false); |
1388 } | 1438 } |
1389 } | 1439 } |
1390 | 1440 |
1391 // Test that we correctly fill a phone number split across multiple fields. | 1441 // Test that we correctly fill a phone number split across multiple fields. |
1392 TEST_F(AutoFillManagerTest, FillPhoneNumber) { | 1442 TEST_F(AutoFillManagerTest, FillPhoneNumber) { |
1393 // Set up our form data. | 1443 // Set up our form data. |
1394 FormData form; | 1444 FormData form; |
1395 form.name = ASCIIToUTF16("MyPhoneForm"); | 1445 form.name = ASCIIToUTF16("MyPhoneForm"); |
1396 form.method = ASCIIToUTF16("POST"); | 1446 form.method = ASCIIToUTF16("POST"); |
1397 form.origin = GURL("http://myform.com/phone_form.html"); | 1447 form.origin = GURL("http://myform.com/phone_form.html"); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1613 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1564 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1614 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1565 profile()->GetPrefs()->SetBoolean( | 1615 profile()->GetPrefs()->SetBoolean( |
1566 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1616 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
1567 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1617 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
1568 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1618 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1569 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1619 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1570 #endif | 1620 #endif |
1571 } | 1621 } |
1572 | 1622 |
OLD | NEW |