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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 int MakeFrontendID(const SuggestionBackendID& cc_sid, | 692 int MakeFrontendID(const SuggestionBackendID& cc_sid, |
726 const SuggestionBackendID& profile_sid) const { | 693 const SuggestionBackendID& profile_sid) const { |
727 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); | 694 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); |
728 } | 695 } |
729 | 696 |
730 bool WillFillCreditCardNumber(const FormData& form, | 697 bool WillFillCreditCardNumber(const FormData& form, |
731 const FormFieldData& field) { | 698 const FormFieldData& field) { |
732 return autofill_manager_->WillFillCreditCardNumber(form, field); | 699 return autofill_manager_->WillFillCreditCardNumber(form, field); |
733 } | 700 } |
734 | 701 |
702 // Populates |form| with data corresponding to a simple credit card form. | |
703 // Note that this actually appends fields to the form data, which can be | |
704 // useful for building up more complex test forms. | |
705 void CreateTestCreditCardFormData(FormData* form, | |
706 bool is_https, | |
707 bool use_month_type) { | |
708 form->name = ASCIIToUTF16("MyForm"); | |
709 if (is_https) { | |
710 form->origin = GURL("https://myform.com/form.html"); | |
711 form->action = GURL("https://myform.com/submit.html"); | |
712 } else { | |
713 form->origin = GURL("http://myform.com/form.html"); | |
714 form->action = GURL("http://myform.com/submit.html"); | |
715 autofill_client_.SetContextSecurity(false); | |
sigbjorn
2015/05/15 08:38:28
This line is the reason for moving this function i
| |
716 } | |
717 form->user_submitted = true; | |
718 | |
719 FormFieldData field; | |
720 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | |
721 form->fields.push_back(field); | |
722 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | |
723 form->fields.push_back(field); | |
724 if (use_month_type) { | |
725 test::CreateTestFormField( | |
726 "Expiration Date", "ccmonth", "", "month", &field); | |
727 form->fields.push_back(field); | |
728 } else { | |
729 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", | |
730 &field); | |
731 form->fields.push_back(field); | |
732 test::CreateTestFormField("", "ccyear", "", "text", &field); | |
733 form->fields.push_back(field); | |
734 } | |
735 } | |
736 | |
737 // Tests if credit card data gets saved | |
738 void TestSaveCreditCards(bool is_https) { | |
739 // Set up our form data. | |
740 FormData form; | |
741 CreateTestCreditCardFormData(&form, is_https, false); | |
742 std::vector<FormData> forms(1, form); | |
743 FormsSeen(forms); | |
744 | |
745 // Edit the data, and submit | |
746 form.fields[1].value = ASCIIToUTF16("4111111111111111"); | |
747 form.fields[2].value = ASCIIToUTF16("11"); | |
748 form.fields[3].value = ASCIIToUTF16("2017"); | |
749 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(1); | |
750 FormSubmitted(form); | |
751 } | |
752 | |
735 protected: | 753 protected: |
736 base::MessageLoop message_loop_; | 754 base::MessageLoop message_loop_; |
737 MockAutofillClient autofill_client_; | 755 MockAutofillClient autofill_client_; |
738 scoped_ptr<MockAutofillDriver> autofill_driver_; | 756 scoped_ptr<MockAutofillDriver> autofill_driver_; |
739 scoped_ptr<TestAutofillManager> autofill_manager_; | 757 scoped_ptr<TestAutofillManager> autofill_manager_; |
740 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | 758 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; |
741 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 759 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
742 TestPersonalDataManager personal_data_; | 760 TestPersonalDataManager personal_data_; |
743 }; | 761 }; |
744 | 762 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 // Test that we sent the right values to the external delegate. | 990 // Test that we sent the right values to the external delegate. |
973 external_delegate_->CheckSuggestions( | 991 external_delegate_->CheckSuggestions( |
974 kDefaultPageID, | 992 kDefaultPageID, |
975 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 993 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
976 autofill_manager_->GetPackedCreditCardID(4)), | 994 autofill_manager_->GetPackedCreditCardID(4)), |
977 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 995 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
978 autofill_manager_->GetPackedCreditCardID(5))); | 996 autofill_manager_->GetPackedCreditCardID(5))); |
979 } | 997 } |
980 | 998 |
981 // Test that we return a warning explaining that credit card profile suggestions | 999 // Test that we return a warning explaining that credit card profile suggestions |
982 // are unavailable when the form is not https. | 1000 // are unavailable when the form is not secure. |
983 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 1001 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
984 // Set up our form data. | 1002 // Set up our form data. |
985 FormData form; | 1003 FormData form; |
986 CreateTestCreditCardFormData(&form, false, false); | 1004 CreateTestCreditCardFormData(&form, false, false); |
987 std::vector<FormData> forms(1, form); | 1005 std::vector<FormData> forms(1, form); |
988 FormsSeen(forms); | 1006 FormsSeen(forms); |
989 | 1007 |
990 const FormFieldData& field = form.fields[0]; | 1008 const FormFieldData& field = form.fields[0]; |
991 GetAutofillSuggestions(form, field); | 1009 GetAutofillSuggestions(form, field); |
992 | 1010 |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2620 | 2638 |
2621 // Set the address field's value back to the default value. | 2639 // Set the address field's value back to the default value. |
2622 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); | 2640 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); |
2623 | 2641 |
2624 // Simulate form submission. We should not call into the PDM to try to save | 2642 // Simulate form submission. We should not call into the PDM to try to save |
2625 // the filled data, since the filled form is effectively missing an address. | 2643 // the filled data, since the filled form is effectively missing an address. |
2626 FormSubmitted(response_data); | 2644 FormSubmitted(response_data); |
2627 EXPECT_EQ(1, personal_data_.num_times_save_imported_profile_called()); | 2645 EXPECT_EQ(1, personal_data_.num_times_save_imported_profile_called()); |
2628 } | 2646 } |
2629 | 2647 |
2648 // Tests that credit card data are saved for forms on https | |
2649 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTPS) { | |
2650 TestSaveCreditCards(true); | |
2651 } | |
2652 | |
2653 // Tests that credit card data are saved for forms on http | |
2654 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTP) { | |
2655 TestSaveCreditCards(false); | |
2656 } | |
2657 | |
2630 // Checks that resetting the auxiliary profile enabled preference does the right | 2658 // Checks that resetting the auxiliary profile enabled preference does the right |
2631 // thing on all platforms. | 2659 // thing on all platforms. |
2632 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { | 2660 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { |
2633 PrefService* prefs = autofill_client_.GetPrefs(); | 2661 PrefService* prefs = autofill_client_.GetPrefs(); |
2634 #if defined(OS_MACOSX) | 2662 #if defined(OS_MACOSX) |
2635 // Auxiliary profiles is implemented on Mac only. | 2663 // Auxiliary profiles is implemented on Mac only. |
2636 // OSX: This preference exists for legacy reasons. It is no longer used. | 2664 // OSX: This preference exists for legacy reasons. It is no longer used. |
2637 ASSERT_TRUE( | 2665 ASSERT_TRUE( |
2638 prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled)); | 2666 prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled)); |
2639 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, | 2667 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3247 form.fields[i].value = ASCIIToUTF16("Texas"); | 3275 form.fields[i].value = ASCIIToUTF16("Texas"); |
3248 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) | 3276 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) |
3249 form.fields[i].value = ASCIIToUTF16("77401"); | 3277 form.fields[i].value = ASCIIToUTF16("77401"); |
3250 else if (form.fields[i].name == ASCIIToUTF16("country")) | 3278 else if (form.fields[i].name == ASCIIToUTF16("country")) |
3251 form.fields[i].value = ASCIIToUTF16("US"); | 3279 form.fields[i].value = ASCIIToUTF16("US"); |
3252 } | 3280 } |
3253 autofill_manager_->OnFormSubmitted(form); | 3281 autofill_manager_->OnFormSubmitted(form); |
3254 } | 3282 } |
3255 | 3283 |
3256 } // namespace autofill | 3284 } // namespace autofill |
OLD | NEW |