OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 test::SetCreditCardInfo(credit_card, "", "", "", ""); | 207 test::SetCreditCardInfo(credit_card, "", "", "", ""); |
208 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 208 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
209 credit_cards->push_back(credit_card); | 209 credit_cards->push_back(credit_card); |
210 } | 210 } |
211 | 211 |
212 size_t num_times_save_imported_profile_called_; | 212 size_t num_times_save_imported_profile_called_; |
213 | 213 |
214 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 214 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
215 }; | 215 }; |
216 | 216 |
217 // Populates |form| with data corresponding to a simple credit card form. | |
218 // Note that this actually appends fields to the form data, which can be useful | |
219 // for building up more complex test forms. | |
220 void CreateTestCreditCardFormData(FormData* form, | |
221 bool is_https, | |
222 bool use_month_type) { | |
223 form->name = ASCIIToUTF16("MyForm"); | |
224 if (is_https) { | |
225 form->origin = GURL("https://myform.com/form.html"); | |
226 form->action = GURL("https://myform.com/submit.html"); | |
227 } else { | |
228 form->origin = GURL("http://myform.com/form.html"); | |
229 form->action = GURL("http://myform.com/submit.html"); | |
230 } | |
231 form->user_submitted = true; | |
232 | |
233 FormFieldData field; | |
234 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | |
235 form->fields.push_back(field); | |
236 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | |
237 form->fields.push_back(field); | |
238 if (use_month_type) { | |
239 test::CreateTestFormField( | |
240 "Expiration Date", "ccmonth", "", "month", &field); | |
241 form->fields.push_back(field); | |
242 } else { | |
243 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); | |
244 form->fields.push_back(field); | |
245 test::CreateTestFormField("", "ccyear", "", "text", &field); | |
246 form->fields.push_back(field); | |
247 } | |
248 } | |
249 | |
250 void ExpectFilledField(const char* expected_label, | 217 void ExpectFilledField(const char* expected_label, |
251 const char* expected_name, | 218 const char* expected_name, |
252 const char* expected_value, | 219 const char* expected_value, |
253 const char* expected_form_control_type, | 220 const char* expected_form_control_type, |
254 const FormFieldData& field) { | 221 const FormFieldData& field) { |
255 SCOPED_TRACE(expected_label); | 222 SCOPED_TRACE(expected_label); |
256 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 223 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
257 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 224 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
258 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 225 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
259 EXPECT_EQ(expected_form_control_type, field.form_control_type); | 226 EXPECT_EQ(expected_form_control_type, field.form_control_type); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 int MakeFrontendID(const std::string& cc_sid, | 691 int MakeFrontendID(const std::string& cc_sid, |
725 const std::string& profile_sid) const { | 692 const std::string& profile_sid) const { |
726 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); | 693 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); |
727 } | 694 } |
728 | 695 |
729 bool WillFillCreditCardNumber(const FormData& form, | 696 bool WillFillCreditCardNumber(const FormData& form, |
730 const FormFieldData& field) { | 697 const FormFieldData& field) { |
731 return autofill_manager_->WillFillCreditCardNumber(form, field); | 698 return autofill_manager_->WillFillCreditCardNumber(form, field); |
732 } | 699 } |
733 | 700 |
| 701 // Populates |form| with data corresponding to a simple credit card form. |
| 702 // Note that this actually appends fields to the form data, which can be |
| 703 // useful for building up more complex test forms. |
| 704 void CreateTestCreditCardFormData(FormData* form, |
| 705 bool is_https, |
| 706 bool use_month_type) { |
| 707 form->name = ASCIIToUTF16("MyForm"); |
| 708 if (is_https) { |
| 709 form->origin = GURL("https://myform.com/form.html"); |
| 710 form->action = GURL("https://myform.com/submit.html"); |
| 711 } else { |
| 712 form->origin = GURL("http://myform.com/form.html"); |
| 713 form->action = GURL("http://myform.com/submit.html"); |
| 714 autofill_client_.set_is_context_secure(false); |
| 715 } |
| 716 form->user_submitted = true; |
| 717 |
| 718 FormFieldData field; |
| 719 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 720 form->fields.push_back(field); |
| 721 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 722 form->fields.push_back(field); |
| 723 if (use_month_type) { |
| 724 test::CreateTestFormField( |
| 725 "Expiration Date", "ccmonth", "", "month", &field); |
| 726 form->fields.push_back(field); |
| 727 } else { |
| 728 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", |
| 729 &field); |
| 730 form->fields.push_back(field); |
| 731 test::CreateTestFormField("", "ccyear", "", "text", &field); |
| 732 form->fields.push_back(field); |
| 733 } |
| 734 } |
| 735 |
| 736 // Tests if credit card data gets saved |
| 737 void TestSaveCreditCards(bool is_https) { |
| 738 // Set up our form data. |
| 739 FormData form; |
| 740 CreateTestCreditCardFormData(&form, is_https, false); |
| 741 std::vector<FormData> forms(1, form); |
| 742 FormsSeen(forms); |
| 743 |
| 744 // Edit the data, and submit |
| 745 form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 746 form.fields[2].value = ASCIIToUTF16("11"); |
| 747 form.fields[3].value = ASCIIToUTF16("2017"); |
| 748 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(1); |
| 749 FormSubmitted(form); |
| 750 } |
| 751 |
734 protected: | 752 protected: |
735 base::MessageLoop message_loop_; | 753 base::MessageLoop message_loop_; |
736 MockAutofillClient autofill_client_; | 754 MockAutofillClient autofill_client_; |
737 scoped_ptr<MockAutofillDriver> autofill_driver_; | 755 scoped_ptr<MockAutofillDriver> autofill_driver_; |
738 scoped_ptr<TestAutofillManager> autofill_manager_; | 756 scoped_ptr<TestAutofillManager> autofill_manager_; |
739 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | 757 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; |
740 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 758 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
741 TestPersonalDataManager personal_data_; | 759 TestPersonalDataManager personal_data_; |
742 }; | 760 }; |
743 | 761 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 // Test that we sent the right values to the external delegate. | 989 // Test that we sent the right values to the external delegate. |
972 external_delegate_->CheckSuggestions( | 990 external_delegate_->CheckSuggestions( |
973 kDefaultPageID, | 991 kDefaultPageID, |
974 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 992 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
975 autofill_manager_->GetPackedCreditCardID(4)), | 993 autofill_manager_->GetPackedCreditCardID(4)), |
976 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 994 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
977 autofill_manager_->GetPackedCreditCardID(5))); | 995 autofill_manager_->GetPackedCreditCardID(5))); |
978 } | 996 } |
979 | 997 |
980 // Test that we return a warning explaining that credit card profile suggestions | 998 // Test that we return a warning explaining that credit card profile suggestions |
981 // are unavailable when the form is not https. | 999 // are unavailable when the form is not secure. |
982 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 1000 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
983 // Set up our form data. | 1001 // Set up our form data. |
984 FormData form; | 1002 FormData form; |
985 CreateTestCreditCardFormData(&form, false, false); | 1003 CreateTestCreditCardFormData(&form, false, false); |
986 std::vector<FormData> forms(1, form); | 1004 std::vector<FormData> forms(1, form); |
987 FormsSeen(forms); | 1005 FormsSeen(forms); |
988 | 1006 |
989 const FormFieldData& field = form.fields[0]; | 1007 const FormFieldData& field = form.fields[0]; |
990 GetAutofillSuggestions(form, field); | 1008 GetAutofillSuggestions(form, field); |
991 | 1009 |
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 | 2458 |
2441 // Set the address field's value back to the default value. | 2459 // Set the address field's value back to the default value. |
2442 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); | 2460 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); |
2443 | 2461 |
2444 // Simulate form submission. We should not call into the PDM to try to save | 2462 // Simulate form submission. We should not call into the PDM to try to save |
2445 // the filled data, since the filled form is effectively missing an address. | 2463 // the filled data, since the filled form is effectively missing an address. |
2446 FormSubmitted(response_data); | 2464 FormSubmitted(response_data); |
2447 EXPECT_EQ(1, personal_data_.num_times_save_imported_profile_called()); | 2465 EXPECT_EQ(1, personal_data_.num_times_save_imported_profile_called()); |
2448 } | 2466 } |
2449 | 2467 |
| 2468 // Tests that credit card data are saved for forms on https |
| 2469 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTPS) { |
| 2470 TestSaveCreditCards(true); |
| 2471 } |
| 2472 |
| 2473 // Tests that credit card data are saved for forms on http |
| 2474 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTP) { |
| 2475 TestSaveCreditCards(false); |
| 2476 } |
| 2477 |
2450 // Checks that resetting the auxiliary profile enabled preference does the right | 2478 // Checks that resetting the auxiliary profile enabled preference does the right |
2451 // thing on all platforms. | 2479 // thing on all platforms. |
2452 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { | 2480 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { |
2453 PrefService* prefs = autofill_client_.GetPrefs(); | 2481 PrefService* prefs = autofill_client_.GetPrefs(); |
2454 #if defined(OS_MACOSX) | 2482 #if defined(OS_MACOSX) |
2455 // Auxiliary profiles is implemented on Mac only. | 2483 // Auxiliary profiles is implemented on Mac only. |
2456 // OSX: This preference exists for legacy reasons. It is no longer used. | 2484 // OSX: This preference exists for legacy reasons. It is no longer used. |
2457 ASSERT_TRUE( | 2485 ASSERT_TRUE( |
2458 prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled)); | 2486 prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled)); |
2459 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, | 2487 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3067 form.fields[i].value = ASCIIToUTF16("Texas"); | 3095 form.fields[i].value = ASCIIToUTF16("Texas"); |
3068 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) | 3096 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) |
3069 form.fields[i].value = ASCIIToUTF16("77401"); | 3097 form.fields[i].value = ASCIIToUTF16("77401"); |
3070 else if (form.fields[i].name == ASCIIToUTF16("country")) | 3098 else if (form.fields[i].name == ASCIIToUTF16("country")) |
3071 form.fields[i].value = ASCIIToUTF16("US"); | 3099 form.fields[i].value = ASCIIToUTF16("US"); |
3072 } | 3100 } |
3073 autofill_manager_->OnFormSubmitted(form); | 3101 autofill_manager_->OnFormSubmitted(form); |
3074 } | 3102 } |
3075 | 3103 |
3076 } // namespace autofill | 3104 } // namespace autofill |
OLD | NEW |