Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "components/autofill/core/browser/autofill_download_manager.h" | 24 #include "components/autofill/core/browser/autofill_download_manager.h" |
| 25 #include "components/autofill/core/browser/autofill_manager.h" | 25 #include "components/autofill/core/browser/autofill_manager.h" |
| 26 #include "components/autofill/core/browser/autofill_profile.h" | 26 #include "components/autofill/core/browser/autofill_profile.h" |
| 27 #include "components/autofill/core/browser/autofill_test_utils.h" | 27 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 28 #include "components/autofill/core/browser/credit_card.h" | 28 #include "components/autofill/core/browser/credit_card.h" |
| 29 #include "components/autofill/core/browser/personal_data_manager.h" | 29 #include "components/autofill/core/browser/personal_data_manager.h" |
| 30 #include "components/autofill/core/browser/popup_item_ids.h" | 30 #include "components/autofill/core/browser/popup_item_ids.h" |
| 31 #include "components/autofill/core/browser/test_autofill_client.h" | 31 #include "components/autofill/core/browser/test_autofill_client.h" |
| 32 #include "components/autofill/core/browser/test_autofill_driver.h" | 32 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 33 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 33 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 34 #include "components/autofill/core/browser/validation.h" | |
| 34 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 35 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 35 #include "components/autofill/core/common/autofill_pref_names.h" | 36 #include "components/autofill/core/common/autofill_pref_names.h" |
| 36 #include "components/autofill/core/common/autofill_switches.h" | 37 #include "components/autofill/core/common/autofill_switches.h" |
| 37 #include "components/autofill/core/common/form_data.h" | 38 #include "components/autofill/core/common/form_data.h" |
| 38 #include "components/autofill/core/common/form_field_data.h" | 39 #include "components/autofill/core/common/form_field_data.h" |
| 39 #include "grit/components_strings.h" | 40 #include "grit/components_strings.h" |
| 40 #include "net/url_request/url_request_test_util.h" | 41 #include "net/url_request/url_request_test_util.h" |
| 41 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 } | 143 } |
| 143 | 144 |
| 144 void ClearAutofillProfiles() { | 145 void ClearAutofillProfiles() { |
| 145 web_profiles_.clear(); | 146 web_profiles_.clear(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void ClearCreditCards() { | 149 void ClearCreditCards() { |
| 149 local_credit_cards_.clear(); | 150 local_credit_cards_.clear(); |
| 150 } | 151 } |
| 151 | 152 |
| 153 // Create Elvis card with whitespace in the credit card number. | |
| 154 void CreateTestCreditCardWithWhitespace() { | |
| 155 ClearCreditCards(); | |
| 156 CreditCard* credit_card = new CreditCard; | |
| 157 test::SetCreditCardInfo(credit_card, "Elvis Presley", | |
| 158 "4234 5678 9012 3456", // Visa | |
| 159 "04", "2012"); | |
| 160 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | |
| 161 local_credit_cards_.push_back(credit_card); | |
| 162 } | |
| 163 | |
| 164 // Create Elvis card with separator characters in the credit card number. | |
| 165 void CreateTestCreditCardWithSeparators() { | |
| 166 ClearCreditCards(); | |
| 167 CreditCard* credit_card = new CreditCard; | |
| 168 test::SetCreditCardInfo(credit_card, "Elvis Presley", | |
| 169 "4234-5678-9012-3456", // Visa | |
| 170 "04", "2012"); | |
| 171 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | |
| 172 local_credit_cards_.push_back(credit_card); | |
| 173 } | |
| 174 | |
| 152 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { | 175 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { |
| 153 ClearCreditCards(); | 176 ClearCreditCards(); |
| 154 CreditCard* credit_card = new CreditCard; | 177 CreditCard* credit_card = new CreditCard; |
| 155 test::SetCreditCardInfo(credit_card, "Miku Hatsune", | 178 test::SetCreditCardInfo(credit_card, "Miku Hatsune", |
| 156 "4234567890654321", // Visa | 179 "4234567890654321", // Visa |
| 157 month, year); | 180 month, year); |
| 158 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 181 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 159 local_credit_cards_.push_back(credit_card); | 182 local_credit_cards_.push_back(credit_card); |
| 160 } | 183 } |
| 161 | 184 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 179 profile = new AutofillProfile; | 202 profile = new AutofillProfile; |
| 180 test::SetProfileInfo( | 203 test::SetProfileInfo( |
| 181 profile, "", "", "", "", "", "", "", "", "", "", "", ""); | 204 profile, "", "", "", "", "", "", "", "", "", "", "", ""); |
| 182 profile->set_guid("00000000-0000-0000-0000-000000000003"); | 205 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 183 profiles->push_back(profile); | 206 profiles->push_back(profile); |
| 184 } | 207 } |
| 185 | 208 |
| 186 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { | 209 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { |
| 187 CreditCard* credit_card = new CreditCard; | 210 CreditCard* credit_card = new CreditCard; |
| 188 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 211 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 189 "4234 5678 9012 3456", // Visa | 212 "4234567890123456", // Visa |
|
bondd
2015/10/22 17:10:02
Removed spaces because they're tested explicitly e
| |
| 190 "04", "2012"); | 213 "04", "2012"); |
| 191 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 214 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 192 credit_cards->push_back(credit_card); | 215 credit_cards->push_back(credit_card); |
| 193 | 216 |
| 194 credit_card = new CreditCard; | 217 credit_card = new CreditCard; |
| 195 test::SetCreditCardInfo(credit_card, "Buddy Holly", | 218 test::SetCreditCardInfo(credit_card, "Buddy Holly", |
| 196 "5187654321098765", // Mastercard | 219 "5187654321098765", // Mastercard |
| 197 "10", "2014"); | 220 "10", "2014"); |
| 198 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 221 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 199 credit_cards->push_back(credit_card); | 222 credit_cards->push_back(credit_card); |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 bool WillFillCreditCardNumber(const FormData& form, | 740 bool WillFillCreditCardNumber(const FormData& form, |
| 718 const FormFieldData& field) { | 741 const FormFieldData& field) { |
| 719 return autofill_manager_->WillFillCreditCardNumber(form, field); | 742 return autofill_manager_->WillFillCreditCardNumber(form, field); |
| 720 } | 743 } |
| 721 | 744 |
| 722 // Populates |form| with data corresponding to a simple credit card form. | 745 // Populates |form| with data corresponding to a simple credit card form. |
| 723 // Note that this actually appends fields to the form data, which can be | 746 // Note that this actually appends fields to the form data, which can be |
| 724 // useful for building up more complex test forms. | 747 // useful for building up more complex test forms. |
| 725 void CreateTestCreditCardFormData(FormData* form, | 748 void CreateTestCreditCardFormData(FormData* form, |
| 726 bool is_https, | 749 bool is_https, |
| 750 bool cc_autocomplete_off, | |
|
Evan Stade
2015/10/22 23:02:43
am I missing something? When is this ever true?
a
bondd
2015/10/23 03:32:35
It was called via TestSaveCreditCards, but you are
| |
| 727 bool use_month_type) { | 751 bool use_month_type) { |
| 728 form->name = ASCIIToUTF16("MyForm"); | 752 form->name = ASCIIToUTF16("MyForm"); |
| 729 if (is_https) { | 753 if (is_https) { |
| 730 form->origin = GURL("https://myform.com/form.html"); | 754 form->origin = GURL("https://myform.com/form.html"); |
| 731 form->action = GURL("https://myform.com/submit.html"); | 755 form->action = GURL("https://myform.com/submit.html"); |
| 732 } else { | 756 } else { |
| 733 form->origin = GURL("http://myform.com/form.html"); | 757 form->origin = GURL("http://myform.com/form.html"); |
| 734 form->action = GURL("http://myform.com/submit.html"); | 758 form->action = GURL("http://myform.com/submit.html"); |
| 735 autofill_client_.set_is_context_secure(false); | 759 autofill_client_.set_is_context_secure(false); |
| 736 } | 760 } |
| 737 | 761 |
| 738 FormFieldData field; | 762 FormFieldData field; |
| 739 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | 763 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 740 form->fields.push_back(field); | 764 form->fields.push_back(field); |
| 741 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 765 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 766 if (cc_autocomplete_off) | |
| 767 field.should_autocomplete = false; | |
| 742 form->fields.push_back(field); | 768 form->fields.push_back(field); |
| 743 if (use_month_type) { | 769 if (use_month_type) { |
| 744 test::CreateTestFormField( | 770 test::CreateTestFormField( |
| 745 "Expiration Date", "ccmonth", "", "month", &field); | 771 "Expiration Date", "ccmonth", "", "month", &field); |
| 746 form->fields.push_back(field); | 772 form->fields.push_back(field); |
| 747 } else { | 773 } else { |
| 748 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", | 774 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", |
| 749 &field); | 775 &field); |
| 750 form->fields.push_back(field); | 776 form->fields.push_back(field); |
| 751 test::CreateTestFormField("", "ccyear", "", "text", &field); | 777 test::CreateTestFormField("", "ccyear", "", "text", &field); |
| 752 form->fields.push_back(field); | 778 form->fields.push_back(field); |
| 753 } | 779 } |
| 754 } | 780 } |
| 755 | 781 |
| 756 // Tests if credit card data gets saved | 782 // Tests if credit card data gets saved. |
| 757 void TestSaveCreditCards(bool is_https) { | 783 void TestSaveCreditCards(bool is_https, bool cc_autocomplete_off) { |
| 758 // Set up our form data. | 784 // Set up our form data. |
| 759 FormData form; | 785 FormData form; |
| 760 CreateTestCreditCardFormData(&form, is_https, false); | 786 CreateTestCreditCardFormData(&form, is_https, cc_autocomplete_off, false); |
| 761 std::vector<FormData> forms(1, form); | 787 std::vector<FormData> forms(1, form); |
| 762 FormsSeen(forms); | 788 FormsSeen(forms); |
| 763 | 789 |
| 764 // Edit the data, and submit | 790 // Edit the data, and submit. |
| 765 form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 791 form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 766 form.fields[2].value = ASCIIToUTF16("11"); | 792 form.fields[2].value = ASCIIToUTF16("11"); |
| 767 form.fields[3].value = ASCIIToUTF16("2017"); | 793 form.fields[3].value = ASCIIToUTF16("2017"); |
| 768 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(1); | 794 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(1); |
| 769 FormSubmitted(form); | 795 FormSubmitted(form); |
| 770 } | 796 } |
| 771 | 797 |
| 772 void PrepareForRealPanResponse(FormData* form, CreditCard* card) { | 798 void PrepareForRealPanResponse(FormData* form, CreditCard* card) { |
| 773 // This line silences the warning from RealPanWalletClient about matching | 799 // This line silences the warning from RealPanWalletClient about matching |
| 774 // sync and wallet server types. | 800 // sync and wallet server types. |
| 775 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 801 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 776 "sync-url", "https://google.com"); | 802 "sync-url", "https://google.com"); |
| 777 | 803 |
| 778 CreateTestCreditCardFormData(form, true, false); | 804 CreateTestCreditCardFormData(form, true, false, false); |
| 779 FormsSeen(std::vector<FormData>(1, *form)); | 805 FormsSeen(std::vector<FormData>(1, *form)); |
| 780 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); | 806 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 781 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", | 807 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", |
| 782 "2017"); | 808 "2017"); |
| 783 card->SetTypeForMaskedCard(kVisaCard); | 809 card->SetTypeForMaskedCard(kVisaCard); |
| 784 | 810 |
| 785 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(0); | 811 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(0); |
| 786 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) | 812 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) |
| 787 .Times(AtLeast(1)); | 813 .Times(AtLeast(1)); |
| 788 autofill_manager_->FillOrPreviewCreditCardForm( | 814 autofill_manager_->FillOrPreviewCreditCardForm( |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 const FormFieldData& field = form.fields[0]; | 1101 const FormFieldData& field = form.fields[0]; |
| 1076 GetAutofillSuggestions(form, field); | 1102 GetAutofillSuggestions(form, field); |
| 1077 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1103 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1078 } | 1104 } |
| 1079 | 1105 |
| 1080 // Test that we return all credit card profile suggestions when all form fields | 1106 // Test that we return all credit card profile suggestions when all form fields |
| 1081 // are empty. | 1107 // are empty. |
| 1082 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 1108 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
| 1083 // Set up our form data. | 1109 // Set up our form data. |
| 1084 FormData form; | 1110 FormData form; |
| 1085 CreateTestCreditCardFormData(&form, true, false); | 1111 CreateTestCreditCardFormData(&form, true, false, false); |
| 1086 std::vector<FormData> forms(1, form); | 1112 std::vector<FormData> forms(1, form); |
| 1087 FormsSeen(forms); | 1113 FormsSeen(forms); |
| 1088 | 1114 |
| 1089 FormFieldData field = form.fields[1]; | 1115 FormFieldData field = form.fields[1]; |
| 1090 GetAutofillSuggestions(form, field); | 1116 GetAutofillSuggestions(form, field); |
| 1091 | 1117 |
| 1092 // Test that we sent the right values to the external delegate. | 1118 // Test that we sent the right values to the external delegate. |
| 1093 external_delegate_->CheckSuggestions( | 1119 external_delegate_->CheckSuggestions( |
| 1094 kDefaultPageID, | 1120 kDefaultPageID, |
| 1095 Suggestion( | 1121 Suggestion( |
| 1096 "Visa\xC2\xA0\xE2\x8B\xAF" | 1122 "Visa\xC2\xA0\xE2\x8B\xAF" |
| 1097 "3456", | 1123 "3456", |
| 1098 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), | 1124 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1099 Suggestion( | 1125 Suggestion( |
| 1100 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1126 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1101 "8765", | 1127 "8765", |
| 1102 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1128 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); |
| 1103 } | 1129 } |
| 1104 | 1130 |
| 1105 // Test that we return only matching credit card profile suggestions when the | 1131 // Test that we return only matching credit card profile suggestions when the |
| 1106 // selected form field has been partially filled out. | 1132 // selected form field has been partially filled out. |
| 1107 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 1133 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
| 1108 // Set up our form data. | 1134 // Set up our form data. |
| 1109 FormData form; | 1135 FormData form; |
| 1110 CreateTestCreditCardFormData(&form, true, false); | 1136 CreateTestCreditCardFormData(&form, true, false, false); |
| 1111 std::vector<FormData> forms(1, form); | 1137 std::vector<FormData> forms(1, form); |
| 1112 FormsSeen(forms); | 1138 FormsSeen(forms); |
| 1113 | 1139 |
| 1114 FormFieldData field; | 1140 FormFieldData field; |
| 1115 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); | 1141 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
| 1116 GetAutofillSuggestions(form, field); | 1142 GetAutofillSuggestions(form, field); |
| 1117 | 1143 |
| 1118 // Test that we sent the right values to the external delegate. | 1144 // Test that we sent the right values to the external delegate. |
| 1119 external_delegate_->CheckSuggestions( | 1145 external_delegate_->CheckSuggestions( |
| 1120 kDefaultPageID, | 1146 kDefaultPageID, |
| 1121 Suggestion( | 1147 Suggestion( |
| 1122 "Visa\xC2\xA0\xE2\x8B\xAF" | 1148 "Visa\xC2\xA0\xE2\x8B\xAF" |
| 1123 "3456", | 1149 "3456", |
| 1124 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); | 1150 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); |
| 1125 } | 1151 } |
| 1126 | 1152 |
| 1127 // Test that we return credit card profile suggestions when the selected form | 1153 // Test that we return credit card profile suggestions when the selected form |
| 1128 // field is not the credit card number field. | 1154 // field is not the credit card number field. |
| 1129 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 1155 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { |
| 1130 // Set up our form data. | 1156 // Set up our form data. |
| 1131 FormData form; | 1157 FormData form; |
| 1132 CreateTestCreditCardFormData(&form, true, false); | 1158 CreateTestCreditCardFormData(&form, true, false, false); |
| 1133 std::vector<FormData> forms(1, form); | 1159 std::vector<FormData> forms(1, form); |
| 1134 FormsSeen(forms); | 1160 FormsSeen(forms); |
| 1135 | 1161 |
| 1136 const FormFieldData& field = form.fields[0]; | 1162 const FormFieldData& field = form.fields[0]; |
| 1137 GetAutofillSuggestions(form, field); | 1163 GetAutofillSuggestions(form, field); |
| 1138 | 1164 |
| 1139 #if defined(OS_ANDROID) | 1165 #if defined(OS_ANDROID) |
| 1140 static const char* kVisaSuggestion = | 1166 static const char* kVisaSuggestion = |
| 1141 "Visa\xC2\xA0\xE2\x8B\xAF" | 1167 "Visa\xC2\xA0\xE2\x8B\xAF" |
| 1142 "3456"; | 1168 "3456"; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1155 autofill_manager_->GetPackedCreditCardID(4)), | 1181 autofill_manager_->GetPackedCreditCardID(4)), |
| 1156 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 1182 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
| 1157 autofill_manager_->GetPackedCreditCardID(5))); | 1183 autofill_manager_->GetPackedCreditCardID(5))); |
| 1158 } | 1184 } |
| 1159 | 1185 |
| 1160 // Test that we return a warning explaining that credit card profile suggestions | 1186 // Test that we return a warning explaining that credit card profile suggestions |
| 1161 // are unavailable when the form is not secure. | 1187 // are unavailable when the form is not secure. |
| 1162 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 1188 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
| 1163 // Set up our form data. | 1189 // Set up our form data. |
| 1164 FormData form; | 1190 FormData form; |
| 1165 CreateTestCreditCardFormData(&form, false, false); | 1191 CreateTestCreditCardFormData(&form, false, false, false); |
| 1166 std::vector<FormData> forms(1, form); | 1192 std::vector<FormData> forms(1, form); |
| 1167 FormsSeen(forms); | 1193 FormsSeen(forms); |
| 1168 | 1194 |
| 1169 const FormFieldData& field = form.fields[0]; | 1195 const FormFieldData& field = form.fields[0]; |
| 1170 GetAutofillSuggestions(form, field); | 1196 GetAutofillSuggestions(form, field); |
| 1171 | 1197 |
| 1172 // Test that we sent the right values to the external delegate. | 1198 // Test that we sent the right values to the external delegate. |
| 1173 external_delegate_->CheckSuggestions( | 1199 external_delegate_->CheckSuggestions( |
| 1174 kDefaultPageID, | 1200 kDefaultPageID, |
| 1175 Suggestion( | 1201 Suggestion( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1189 // |credit_card| will be owned by the mock PersonalDataManager. | 1215 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1190 CreditCard* credit_card = new CreditCard; | 1216 CreditCard* credit_card = new CreditCard; |
| 1191 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 1217 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 1192 "5231567890123456", // Mastercard | 1218 "5231567890123456", // Mastercard |
| 1193 "05", "2012"); | 1219 "05", "2012"); |
| 1194 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1220 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1195 autofill_manager_->AddCreditCard(credit_card); | 1221 autofill_manager_->AddCreditCard(credit_card); |
| 1196 | 1222 |
| 1197 // Set up our form data. | 1223 // Set up our form data. |
| 1198 FormData form; | 1224 FormData form; |
| 1199 CreateTestCreditCardFormData(&form, true, false); | 1225 CreateTestCreditCardFormData(&form, true, false, false); |
| 1200 std::vector<FormData> forms(1, form); | 1226 std::vector<FormData> forms(1, form); |
| 1201 FormsSeen(forms); | 1227 FormsSeen(forms); |
| 1202 | 1228 |
| 1203 FormFieldData field = form.fields[1]; | 1229 FormFieldData field = form.fields[1]; |
| 1204 GetAutofillSuggestions(form, field); | 1230 GetAutofillSuggestions(form, field); |
| 1205 | 1231 |
| 1206 // Test that we sent the right values to the external delegate. | 1232 // Test that we sent the right values to the external delegate. |
| 1207 external_delegate_->CheckSuggestions( | 1233 external_delegate_->CheckSuggestions( |
| 1208 kDefaultPageID, | 1234 kDefaultPageID, |
| 1209 Suggestion( | 1235 Suggestion( |
| 1210 "Visa\xC2\xA0\xE2\x8B\xAF" | 1236 "Visa\xC2\xA0\xE2\x8B\xAF" |
| 1211 "3456", | 1237 "3456", |
| 1212 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), | 1238 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1213 Suggestion( | 1239 Suggestion( |
| 1214 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1240 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1215 "8765", | 1241 "8765", |
| 1216 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5)), | 1242 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5)), |
| 1217 Suggestion( | 1243 Suggestion( |
| 1218 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1244 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1219 "3456", | 1245 "3456", |
| 1220 "05/12", kMasterCard, autofill_manager_->GetPackedCreditCardID(7))); | 1246 "05/12", kMasterCard, autofill_manager_->GetPackedCreditCardID(7))); |
| 1221 } | 1247 } |
| 1222 | 1248 |
| 1223 // Test that we return profile and credit card suggestions for combined forms. | 1249 // Test that we return profile and credit card suggestions for combined forms. |
| 1224 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1250 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 1225 // Set up our form data. | 1251 // Set up our form data. |
| 1226 FormData form; | 1252 FormData form; |
| 1227 test::CreateTestAddressFormData(&form); | 1253 test::CreateTestAddressFormData(&form); |
| 1228 CreateTestCreditCardFormData(&form, true, false); | 1254 CreateTestCreditCardFormData(&form, true, false, false); |
| 1229 std::vector<FormData> forms(1, form); | 1255 std::vector<FormData> forms(1, form); |
| 1230 FormsSeen(forms); | 1256 FormsSeen(forms); |
| 1231 | 1257 |
| 1232 FormFieldData field = form.fields[0]; | 1258 FormFieldData field = form.fields[0]; |
| 1233 GetAutofillSuggestions(form, field); | 1259 GetAutofillSuggestions(form, field); |
| 1234 | 1260 |
| 1235 // Test that we sent the right address suggestions to the external delegate. | 1261 // Test that we sent the right address suggestions to the external delegate. |
| 1236 external_delegate_->CheckSuggestions( | 1262 external_delegate_->CheckSuggestions( |
| 1237 kDefaultPageID, | 1263 kDefaultPageID, |
| 1238 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), | 1264 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1256 } | 1282 } |
| 1257 | 1283 |
| 1258 // Test that for non-https forms with both address and credit card fields, we | 1284 // Test that for non-https forms with both address and credit card fields, we |
| 1259 // only return address suggestions. Instead of credit card suggestions, we | 1285 // only return address suggestions. Instead of credit card suggestions, we |
| 1260 // should return a warning explaining that credit card profile suggestions are | 1286 // should return a warning explaining that credit card profile suggestions are |
| 1261 // unavailable when the form is not https. | 1287 // unavailable when the form is not https. |
| 1262 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1288 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1263 // Set up our form data. | 1289 // Set up our form data. |
| 1264 FormData form; | 1290 FormData form; |
| 1265 test::CreateTestAddressFormData(&form); | 1291 test::CreateTestAddressFormData(&form); |
| 1266 CreateTestCreditCardFormData(&form, false, false); | 1292 CreateTestCreditCardFormData(&form, false, false, false); |
| 1267 std::vector<FormData> forms(1, form); | 1293 std::vector<FormData> forms(1, form); |
| 1268 FormsSeen(forms); | 1294 FormsSeen(forms); |
| 1269 | 1295 |
| 1270 FormFieldData field = form.fields[0]; | 1296 FormFieldData field = form.fields[0]; |
| 1271 GetAutofillSuggestions(form, field); | 1297 GetAutofillSuggestions(form, field); |
| 1272 | 1298 |
| 1273 // Test that we sent the right suggestions to the external delegate. | 1299 // Test that we sent the right suggestions to the external delegate. |
| 1274 external_delegate_->CheckSuggestions( | 1300 external_delegate_->CheckSuggestions( |
| 1275 kDefaultPageID, | 1301 kDefaultPageID, |
| 1276 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), | 1302 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1471 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, | 1497 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, |
| 1472 false); | 1498 false); |
| 1473 | 1499 |
| 1474 EXPECT_EQ(1U, profile->use_count()); | 1500 EXPECT_EQ(1U, profile->use_count()); |
| 1475 EXPECT_NE(base::Time(), profile->use_date()); | 1501 EXPECT_NE(base::Time(), profile->use_date()); |
| 1476 } | 1502 } |
| 1477 | 1503 |
| 1478 TEST_F(AutofillManagerTest, WillFillCreditCardNumber) { | 1504 TEST_F(AutofillManagerTest, WillFillCreditCardNumber) { |
| 1479 // Set up our form data. | 1505 // Set up our form data. |
| 1480 FormData form; | 1506 FormData form; |
| 1481 CreateTestCreditCardFormData(&form, true, false); | 1507 CreateTestCreditCardFormData(&form, true, false, false); |
| 1482 std::vector<FormData> forms(1, form); | 1508 std::vector<FormData> forms(1, form); |
| 1483 FormsSeen(forms); | 1509 FormsSeen(forms); |
| 1484 | 1510 |
| 1485 FormFieldData* number_field = nullptr; | 1511 FormFieldData* number_field = nullptr; |
| 1486 FormFieldData* name_field = nullptr; | 1512 FormFieldData* name_field = nullptr; |
| 1487 FormFieldData* month_field = nullptr; | 1513 FormFieldData* month_field = nullptr; |
| 1488 for (size_t i = 0; i < form.fields.size(); ++i) { | 1514 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 1489 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) | 1515 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) |
| 1490 number_field = &form.fields[i]; | 1516 number_field = &form.fields[i]; |
| 1491 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) | 1517 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1518 // When part of the section is Autofilled, only fill the initiating field. | 1544 // When part of the section is Autofilled, only fill the initiating field. |
| 1519 month_field->is_autofilled = true; | 1545 month_field->is_autofilled = true; |
| 1520 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); | 1546 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); |
| 1521 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); | 1547 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
| 1522 } | 1548 } |
| 1523 | 1549 |
| 1524 // Test that we correctly fill a credit card form. | 1550 // Test that we correctly fill a credit card form. |
| 1525 TEST_F(AutofillManagerTest, FillCreditCardForm) { | 1551 TEST_F(AutofillManagerTest, FillCreditCardForm) { |
| 1526 // Set up our form data. | 1552 // Set up our form data. |
| 1527 FormData form; | 1553 FormData form; |
| 1528 CreateTestCreditCardFormData(&form, true, false); | 1554 CreateTestCreditCardFormData(&form, true, false, false); |
| 1529 std::vector<FormData> forms(1, form); | 1555 std::vector<FormData> forms(1, form); |
| 1530 FormsSeen(forms); | 1556 FormsSeen(forms); |
| 1531 | 1557 |
| 1532 const char guid[] = "00000000-0000-0000-0000-000000000004"; | 1558 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 1533 int response_page_id = 0; | 1559 int response_page_id = 0; |
| 1534 FormData response_data; | 1560 FormData response_data; |
| 1535 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1561 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1536 MakeFrontendID(guid, std::string()), | 1562 MakeFrontendID(guid, std::string()), |
| 1537 &response_page_id, &response_data); | 1563 &response_page_id, &response_data); |
| 1538 ExpectFilledCreditCardFormElvis( | 1564 ExpectFilledCreditCardFormElvis( |
| 1539 response_page_id, response_data, kDefaultPageID, false); | 1565 response_page_id, response_data, kDefaultPageID, false); |
| 1540 } | 1566 } |
| 1541 | 1567 |
| 1568 // Test that whitespace is stripped from the credit card number. | |
| 1569 TEST_F(AutofillManagerTest, FillCreditCardFormStripCardNumberWhitespace) { | |
| 1570 // Same as the SetUp(), but generate Elvis card with whitespace in credit | |
| 1571 // card number. | |
| 1572 personal_data_.CreateTestCreditCardWithWhitespace(); | |
| 1573 // Set up our form data. | |
| 1574 FormData form; | |
| 1575 CreateTestCreditCardFormData(&form, true, false, false); | |
| 1576 std::vector<FormData> forms(1, form); | |
| 1577 FormsSeen(forms); | |
| 1578 | |
| 1579 const char guid[] = "00000000-0000-0000-0000-000000000008"; | |
| 1580 int response_page_id = 0; | |
| 1581 FormData response_data; | |
| 1582 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | |
| 1583 MakeFrontendID(guid, std::string()), | |
| 1584 &response_page_id, &response_data); | |
| 1585 ExpectFilledCreditCardFormElvis(response_page_id, response_data, | |
| 1586 kDefaultPageID, false); | |
| 1587 } | |
| 1588 | |
| 1589 // Test that separator characters are stripped from the credit card number. | |
| 1590 TEST_F(AutofillManagerTest, FillCreditCardFormStripCardNumberSeparators) { | |
| 1591 // Same as the SetUp(), but generate Elvis card with separator characters in | |
| 1592 // credit card number. | |
| 1593 personal_data_.CreateTestCreditCardWithSeparators(); | |
| 1594 // Set up our form data. | |
| 1595 FormData form; | |
| 1596 CreateTestCreditCardFormData(&form, true, false, false); | |
| 1597 std::vector<FormData> forms(1, form); | |
| 1598 FormsSeen(forms); | |
| 1599 | |
| 1600 const char guid[] = "00000000-0000-0000-0000-000000000009"; | |
| 1601 int response_page_id = 0; | |
| 1602 FormData response_data; | |
| 1603 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | |
| 1604 MakeFrontendID(guid, std::string()), | |
| 1605 &response_page_id, &response_data); | |
| 1606 ExpectFilledCreditCardFormElvis(response_page_id, response_data, | |
| 1607 kDefaultPageID, false); | |
| 1608 } | |
| 1609 | |
| 1542 // Test that we correctly fill a credit card form with month input type. | 1610 // Test that we correctly fill a credit card form with month input type. |
| 1543 // 1. year empty, month empty | 1611 // 1. year empty, month empty |
| 1544 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { | 1612 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { |
| 1545 // Same as the SetUp(), but generate 4 credit cards with year month | 1613 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1546 // combination. | 1614 // combination. |
| 1547 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); | 1615 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); |
| 1548 // Set up our form data. | 1616 // Set up our form data. |
| 1549 FormData form; | 1617 FormData form; |
| 1550 CreateTestCreditCardFormData(&form, true, true); | 1618 CreateTestCreditCardFormData(&form, true, false, true); |
| 1551 std::vector<FormData> forms(1, form); | 1619 std::vector<FormData> forms(1, form); |
| 1552 FormsSeen(forms); | 1620 FormsSeen(forms); |
| 1553 | 1621 |
| 1554 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1622 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1555 int response_page_id = 0; | 1623 int response_page_id = 0; |
| 1556 FormData response_data; | 1624 FormData response_data; |
| 1557 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1625 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1558 MakeFrontendID(guid, std::string()), | 1626 MakeFrontendID(guid, std::string()), |
| 1559 &response_page_id, &response_data); | 1627 &response_page_id, &response_data); |
| 1560 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1628 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1561 kDefaultPageID, false, "", ""); | 1629 kDefaultPageID, false, "", ""); |
| 1562 } | 1630 } |
| 1563 | 1631 |
| 1564 | 1632 |
| 1565 // Test that we correctly fill a credit card form with month input type. | 1633 // Test that we correctly fill a credit card form with month input type. |
| 1566 // 2. year empty, month non-empty | 1634 // 2. year empty, month non-empty |
| 1567 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { | 1635 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { |
| 1568 // Same as the SetUp(), but generate 4 credit cards with year month | 1636 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1569 // combination. | 1637 // combination. |
| 1570 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); | 1638 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); |
| 1571 // Set up our form data. | 1639 // Set up our form data. |
| 1572 FormData form; | 1640 FormData form; |
| 1573 CreateTestCreditCardFormData(&form, true, true); | 1641 CreateTestCreditCardFormData(&form, true, false, true); |
| 1574 std::vector<FormData> forms(1, form); | 1642 std::vector<FormData> forms(1, form); |
| 1575 FormsSeen(forms); | 1643 FormsSeen(forms); |
| 1576 | 1644 |
| 1577 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1645 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1578 int response_page_id = 0; | 1646 int response_page_id = 0; |
| 1579 FormData response_data; | 1647 FormData response_data; |
| 1580 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1648 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1581 MakeFrontendID(guid, std::string()), | 1649 MakeFrontendID(guid, std::string()), |
| 1582 &response_page_id, &response_data); | 1650 &response_page_id, &response_data); |
| 1583 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1651 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1584 kDefaultPageID, false, "", "04"); | 1652 kDefaultPageID, false, "", "04"); |
| 1585 } | 1653 } |
| 1586 | 1654 |
| 1587 // Test that we correctly fill a credit card form with month input type. | 1655 // Test that we correctly fill a credit card form with month input type. |
| 1588 // 3. year non-empty, month empty | 1656 // 3. year non-empty, month empty |
| 1589 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { | 1657 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { |
| 1590 // Same as the SetUp(), but generate 4 credit cards with year month | 1658 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1591 // combination. | 1659 // combination. |
| 1592 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); | 1660 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); |
| 1593 // Set up our form data. | 1661 // Set up our form data. |
| 1594 FormData form; | 1662 FormData form; |
| 1595 CreateTestCreditCardFormData(&form, true, true); | 1663 CreateTestCreditCardFormData(&form, true, false, true); |
| 1596 std::vector<FormData> forms(1, form); | 1664 std::vector<FormData> forms(1, form); |
| 1597 FormsSeen(forms); | 1665 FormsSeen(forms); |
| 1598 | 1666 |
| 1599 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1667 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1600 int response_page_id = 0; | 1668 int response_page_id = 0; |
| 1601 FormData response_data; | 1669 FormData response_data; |
| 1602 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1670 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1603 MakeFrontendID(guid, std::string()), | 1671 MakeFrontendID(guid, std::string()), |
| 1604 &response_page_id, &response_data); | 1672 &response_page_id, &response_data); |
| 1605 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1673 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1606 kDefaultPageID, false, "2012", ""); | 1674 kDefaultPageID, false, "2012", ""); |
| 1607 } | 1675 } |
| 1608 | 1676 |
| 1609 // Test that we correctly fill a credit card form with month input type. | 1677 // Test that we correctly fill a credit card form with month input type. |
| 1610 // 4. year non-empty, month empty | 1678 // 4. year non-empty, month empty |
| 1611 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { | 1679 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { |
| 1612 // Same as the SetUp(), but generate 4 credit cards with year month | 1680 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1613 // combination. | 1681 // combination. |
| 1614 personal_data_.ClearCreditCards(); | 1682 personal_data_.ClearCreditCards(); |
| 1615 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); | 1683 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); |
| 1616 // Set up our form data. | 1684 // Set up our form data. |
| 1617 FormData form; | 1685 FormData form; |
| 1618 CreateTestCreditCardFormData(&form, true, true); | 1686 CreateTestCreditCardFormData(&form, true, false, true); |
| 1619 std::vector<FormData> forms(1, form); | 1687 std::vector<FormData> forms(1, form); |
| 1620 FormsSeen(forms); | 1688 FormsSeen(forms); |
| 1621 | 1689 |
| 1622 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1690 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1623 int response_page_id = 0; | 1691 int response_page_id = 0; |
| 1624 FormData response_data; | 1692 FormData response_data; |
| 1625 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1693 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1626 MakeFrontendID(guid, std::string()), | 1694 MakeFrontendID(guid, std::string()), |
| 1627 &response_page_id, &response_data); | 1695 &response_page_id, &response_data); |
| 1628 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1696 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1629 kDefaultPageID, false, "2012", "04"); | 1697 kDefaultPageID, false, "2012", "04"); |
| 1630 } | 1698 } |
| 1631 | 1699 |
| 1632 // Test that we correctly fill a combined address and credit card form. | 1700 // Test that we correctly fill a combined address and credit card form. |
| 1633 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { | 1701 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { |
| 1634 // Set up our form data. | 1702 // Set up our form data. |
| 1635 FormData form; | 1703 FormData form; |
| 1636 test::CreateTestAddressFormData(&form); | 1704 test::CreateTestAddressFormData(&form); |
| 1637 CreateTestCreditCardFormData(&form, true, false); | 1705 CreateTestCreditCardFormData(&form, true, false, false); |
| 1638 std::vector<FormData> forms(1, form); | 1706 std::vector<FormData> forms(1, form); |
| 1639 FormsSeen(forms); | 1707 FormsSeen(forms); |
| 1640 | 1708 |
| 1641 // First fill the address data. | 1709 // First fill the address data. |
| 1642 const char guid[] = "00000000-0000-0000-0000-000000000001"; | 1710 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 1643 int response_page_id = 0; | 1711 int response_page_id = 0; |
| 1644 FormData response_data; | 1712 FormData response_data; |
| 1645 { | 1713 { |
| 1646 SCOPED_TRACE("Address"); | 1714 SCOPED_TRACE("Address"); |
| 1647 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1715 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1976 false); | 2044 false); |
| 1977 } | 2045 } |
| 1978 | 2046 |
| 1979 // Test that we correctly fill a previously auto-filled form. | 2047 // Test that we correctly fill a previously auto-filled form. |
| 1980 TEST_F(AutofillManagerTest, FillAutofilledForm) { | 2048 TEST_F(AutofillManagerTest, FillAutofilledForm) { |
| 1981 // Set up our form data. | 2049 // Set up our form data. |
| 1982 FormData form; | 2050 FormData form; |
| 1983 test::CreateTestAddressFormData(&form); | 2051 test::CreateTestAddressFormData(&form); |
| 1984 // Mark one of the address fields as autofilled. | 2052 // Mark one of the address fields as autofilled. |
| 1985 form.fields[4].is_autofilled = true; | 2053 form.fields[4].is_autofilled = true; |
| 1986 CreateTestCreditCardFormData(&form, true, false); | 2054 CreateTestCreditCardFormData(&form, true, false, false); |
| 1987 std::vector<FormData> forms(1, form); | 2055 std::vector<FormData> forms(1, form); |
| 1988 FormsSeen(forms); | 2056 FormsSeen(forms); |
| 1989 | 2057 |
| 1990 // First fill the address data. | 2058 // First fill the address data. |
| 1991 const char guid[] = "00000000-0000-0000-0000-000000000001"; | 2059 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 1992 int response_page_id = 0; | 2060 int response_page_id = 0; |
| 1993 FormData response_data; | 2061 FormData response_data; |
| 1994 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2062 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1995 MakeFrontendID(std::string(), guid), | 2063 MakeFrontendID(std::string(), guid), |
| 1996 &response_page_id, &response_data); | 2064 &response_page_id, &response_data); |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2588 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); | 2656 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); |
| 2589 | 2657 |
| 2590 // Simulate form submission. We should not call into the PDM to try to save | 2658 // Simulate form submission. We should not call into the PDM to try to save |
| 2591 // the filled data, since the filled form is effectively missing an address. | 2659 // the filled data, since the filled form is effectively missing an address. |
| 2592 FormSubmitted(response_data); | 2660 FormSubmitted(response_data); |
| 2593 EXPECT_EQ(1, personal_data_.num_times_save_imported_profile_called()); | 2661 EXPECT_EQ(1, personal_data_.num_times_save_imported_profile_called()); |
| 2594 } | 2662 } |
| 2595 | 2663 |
| 2596 // Tests that credit card data are saved for forms on https | 2664 // Tests that credit card data are saved for forms on https |
| 2597 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTPS) { | 2665 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTPS) { |
| 2598 TestSaveCreditCards(true); | 2666 TestSaveCreditCards(true, false); |
| 2599 } | 2667 } |
| 2600 | 2668 |
| 2601 // Tests that credit card data are saved for forms on http | 2669 // Tests that credit card data are saved for forms on http |
| 2602 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTP) { | 2670 TEST_F(AutofillManagerTest, ImportFormDataCreditCardHTTP) { |
| 2603 TestSaveCreditCards(false); | 2671 TestSaveCreditCards(false, false); |
| 2672 } | |
| 2673 | |
| 2674 // Tests that credit card data are saved when autocomplete=off for CC field. | |
| 2675 TEST_F(AutofillManagerTest, CreditCardSavedWhenAutocompleteOff) { | |
| 2676 TestSaveCreditCards(false, true); | |
| 2677 } | |
| 2678 | |
| 2679 // Tests that credit card data are not saved when CC number does not pass the | |
| 2680 // Luhn test. | |
| 2681 TEST_F(AutofillManagerTest, InvalidCreditCardNumberIsNotSaved) { | |
| 2682 // Set up our form data. | |
| 2683 FormData form; | |
| 2684 CreateTestCreditCardFormData(&form, true, false, false); | |
| 2685 std::vector<FormData> forms(1, form); | |
| 2686 FormsSeen(forms); | |
| 2687 | |
| 2688 // Edit the data, and submit. | |
| 2689 std::string card("4408041234567890"); | |
| 2690 ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); | |
| 2691 form.fields[1].value = ASCIIToUTF16(card); | |
| 2692 form.fields[2].value = ASCIIToUTF16("11"); | |
| 2693 form.fields[3].value = ASCIIToUTF16("2017"); | |
| 2694 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(0); | |
| 2695 FormSubmitted(form); | |
| 2604 } | 2696 } |
| 2605 | 2697 |
| 2606 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { | 2698 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { |
| 2607 FormData form; | 2699 FormData form; |
| 2608 form.name = ASCIIToUTF16("MyForm"); | 2700 form.name = ASCIIToUTF16("MyForm"); |
| 2609 form.origin = GURL("http://myform.com/form.html"); | 2701 form.origin = GURL("http://myform.com/form.html"); |
| 2610 form.action = GURL("http://myform.com/submit.html"); | 2702 form.action = GURL("http://myform.com/submit.html"); |
| 2611 | 2703 |
| 2612 std::vector<ServerFieldTypeSet> expected_types; | 2704 std::vector<ServerFieldTypeSet> expected_types; |
| 2613 std::vector<base::string16> expected_values; | 2705 std::vector<base::string16> expected_values; |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3218 | 3310 |
| 3219 // Verify that typing "pres" will match "Elvis Presley" when substring matching | 3311 // Verify that typing "pres" will match "Elvis Presley" when substring matching |
| 3220 // is enabled. | 3312 // is enabled. |
| 3221 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) { | 3313 TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) { |
| 3222 // Token matching is currently behind a flag. | 3314 // Token matching is currently behind a flag. |
| 3223 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 3315 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3224 switches::kEnableSuggestionsWithSubstringMatch); | 3316 switches::kEnableSuggestionsWithSubstringMatch); |
| 3225 | 3317 |
| 3226 // Set up our form data. | 3318 // Set up our form data. |
| 3227 FormData form; | 3319 FormData form; |
| 3228 CreateTestCreditCardFormData(&form, true, false); | 3320 CreateTestCreditCardFormData(&form, true, false, false); |
| 3229 std::vector<FormData> forms(1, form); | 3321 std::vector<FormData> forms(1, form); |
| 3230 FormsSeen(forms); | 3322 FormsSeen(forms); |
| 3231 | 3323 |
| 3232 FormFieldData field; | 3324 FormFieldData field; |
| 3233 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", | 3325 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", |
| 3234 &field); | 3326 &field); |
| 3235 GetAutofillSuggestions(form, field); | 3327 GetAutofillSuggestions(form, field); |
| 3236 | 3328 |
| 3237 #if defined(OS_ANDROID) | 3329 #if defined(OS_ANDROID) |
| 3238 static const char* kVisaSuggestion = | 3330 static const char* kVisaSuggestion = |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 3249 | 3341 |
| 3250 // Verify that typing "lvis" will not match any of the credit card name when | 3342 // Verify that typing "lvis" will not match any of the credit card name when |
| 3251 // substring matching is enabled. | 3343 // substring matching is enabled. |
| 3252 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) { | 3344 TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) { |
| 3253 // Token matching is currently behind a flag. | 3345 // Token matching is currently behind a flag. |
| 3254 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 3346 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3255 switches::kEnableSuggestionsWithSubstringMatch); | 3347 switches::kEnableSuggestionsWithSubstringMatch); |
| 3256 | 3348 |
| 3257 // Set up our form data. | 3349 // Set up our form data. |
| 3258 FormData form; | 3350 FormData form; |
| 3259 CreateTestCreditCardFormData(&form, true, false); | 3351 CreateTestCreditCardFormData(&form, true, false, false); |
| 3260 std::vector<FormData> forms(1, form); | 3352 std::vector<FormData> forms(1, form); |
| 3261 FormsSeen(forms); | 3353 FormsSeen(forms); |
| 3262 | 3354 |
| 3263 FormFieldData field; | 3355 FormFieldData field; |
| 3264 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", | 3356 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", |
| 3265 &field); | 3357 &field); |
| 3266 GetAutofillSuggestions(form, field); | 3358 GetAutofillSuggestions(form, field); |
| 3267 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 3359 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3268 } | 3360 } |
| 3269 | 3361 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3308 | 3400 |
| 3309 external_delegate_->CheckSuggestions( | 3401 external_delegate_->CheckSuggestions( |
| 3310 kDefaultPageID, | 3402 kDefaultPageID, |
| 3311 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", | 3403 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", |
| 3312 1), | 3404 1), |
| 3313 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", | 3405 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", |
| 3314 2)); | 3406 2)); |
| 3315 } | 3407 } |
| 3316 | 3408 |
| 3317 } // namespace autofill | 3409 } // namespace autofill |
| OLD | NEW |