| 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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 void CheckSuggestions(int expected_page_id, | 694 void CheckSuggestions(int expected_page_id, |
| 695 const Suggestion& suggestion0, | 695 const Suggestion& suggestion0, |
| 696 const Suggestion& suggestion1, | 696 const Suggestion& suggestion1, |
| 697 const Suggestion& suggestion2) { | 697 const Suggestion& suggestion2) { |
| 698 std::vector<Suggestion> suggestion_vector; | 698 std::vector<Suggestion> suggestion_vector; |
| 699 suggestion_vector.push_back(suggestion0); | 699 suggestion_vector.push_back(suggestion0); |
| 700 suggestion_vector.push_back(suggestion1); | 700 suggestion_vector.push_back(suggestion1); |
| 701 suggestion_vector.push_back(suggestion2); | 701 suggestion_vector.push_back(suggestion2); |
| 702 CheckSuggestions(expected_page_id, 3, &suggestion_vector[0]); | 702 CheckSuggestions(expected_page_id, 3, &suggestion_vector[0]); |
| 703 } | 703 } |
| 704 // Check that the autofill suggestions were sent, and that they match a page |
| 705 // but contain no results. |
| 704 void CheckNoSuggestions(int expected_page_id) { | 706 void CheckNoSuggestions(int expected_page_id) { |
| 705 EXPECT_TRUE(on_suggestions_returned_seen()); | |
| 706 CheckSuggestions(expected_page_id, 0, nullptr); | 707 CheckSuggestions(expected_page_id, 0, nullptr); |
| 707 } | 708 } |
| 709 // Check that the autofill suggestions were sent, and that they match a page |
| 710 // and contain a specific number of suggestions. |
| 711 void CheckSuggestionCount(int expected_page_id, |
| 712 size_t expected_num_suggestions) { |
| 713 // Ensure that these results are from the most recent query. |
| 714 EXPECT_TRUE(on_suggestions_returned_seen_); |
| 715 |
| 716 EXPECT_EQ(expected_page_id, query_id_); |
| 717 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); |
| 718 } |
| 708 | 719 |
| 709 bool on_query_seen() const { | 720 bool on_query_seen() const { |
| 710 return on_query_seen_; | 721 return on_query_seen_; |
| 711 } | 722 } |
| 712 | 723 |
| 713 bool on_suggestions_returned_seen() const { | 724 bool on_suggestions_returned_seen() const { |
| 714 return on_suggestions_returned_seen_; | 725 return on_suggestions_returned_seen_; |
| 715 } | 726 } |
| 716 | 727 |
| 717 private: | 728 private: |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 "2017"); | 965 "2017"); |
| 955 card->SetTypeForMaskedCard(kVisaCard); | 966 card->SetTypeForMaskedCard(kVisaCard); |
| 956 | 967 |
| 957 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) | 968 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) |
| 958 .Times(AtLeast(1)); | 969 .Times(AtLeast(1)); |
| 959 autofill_manager_->FillOrPreviewCreditCardForm( | 970 autofill_manager_->FillOrPreviewCreditCardForm( |
| 960 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | 971 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, |
| 961 form->fields[0], *card); | 972 form->fields[0], *card); |
| 962 } | 973 } |
| 963 | 974 |
| 975 // Convenience method for using and retrieving a mock autocomplete history |
| 976 // manager. |
| 977 MockAutocompleteHistoryManager* RecreateMockAutocompleteHistoryManager() { |
| 978 MockAutocompleteHistoryManager* manager = new |
| 979 MockAutocompleteHistoryManager(autofill_driver_.get(), |
| 980 autofill_manager_->client()); |
| 981 autofill_manager_->autocomplete_history_manager_.reset(manager); |
| 982 return manager; |
| 983 } |
| 984 |
| 964 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. | 985 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. |
| 965 CardUnmaskDelegate* full_card_unmask_delegate() { | 986 CardUnmaskDelegate* full_card_unmask_delegate() { |
| 966 DCHECK(autofill_manager_->full_card_request_); | 987 DCHECK(autofill_manager_->full_card_request_); |
| 967 return static_cast<CardUnmaskDelegate*>( | 988 return static_cast<CardUnmaskDelegate*>( |
| 968 autofill_manager_->full_card_request_.get()); | 989 autofill_manager_->full_card_request_.get()); |
| 969 } | 990 } |
| 970 | 991 |
| 971 protected: | 992 protected: |
| 972 base::MessageLoop message_loop_; | 993 base::MessageLoop message_loop_; |
| 973 MockAutofillClient autofill_client_; | 994 MockAutofillClient autofill_client_; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 form2.fields.push_back(field); | 1076 form2.fields.push_back(field); |
| 1056 | 1077 |
| 1057 forms.clear(); | 1078 forms.clear(); |
| 1058 forms.push_back(form2); | 1079 forms.push_back(form2); |
| 1059 FormsSeen(forms); | 1080 FormsSeen(forms); |
| 1060 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", | 1081 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", |
| 1061 0 /* FORMS_LOADED */, 2); | 1082 0 /* FORMS_LOADED */, 2); |
| 1062 download_manager_->VerifyLastQueriedForms(forms); | 1083 download_manager_->VerifyLastQueriedForms(forms); |
| 1063 } | 1084 } |
| 1064 | 1085 |
| 1065 // Test that no suggestions are returned for a field with an unrecognized | 1086 // Test that no autofill suggestions are returned for a field with an |
| 1066 // autocomplete attribute. | 1087 // unrecognized autocomplete attribute. |
| 1067 TEST_F(AutofillManagerTest, GetProfileSuggestions_UnrecognizedAttribute) { | 1088 TEST_F(AutofillManagerTest, GetProfileSuggestions_UnrecognizedAttribute) { |
| 1089 // Set up our form data. |
| 1068 FormData form; | 1090 FormData form; |
| 1069 form.name = ASCIIToUTF16("MyForm"); | 1091 form.name = ASCIIToUTF16("MyForm"); |
| 1070 form.origin = GURL("https://myform.com/form.html"); | 1092 form.origin = GURL("https://myform.com/form.html"); |
| 1071 form.action = GURL("https://myform.com/submit.html"); | 1093 form.action = GURL("https://myform.com/submit.html"); |
| 1072 FormFieldData field; | 1094 FormFieldData field; |
| 1073 // Set a valid autocomplete attribute for the first name. | 1095 // Set a valid autocomplete attribute for the first name. |
| 1074 test::CreateTestFormField("First name", "firstname", "", "text", &field); | 1096 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| 1075 field.autocomplete_attribute = "given-name"; | 1097 field.autocomplete_attribute = "given-name"; |
| 1076 form.fields.push_back(field); | 1098 form.fields.push_back(field); |
| 1077 // Set no autocomplete attribute for the middle name. | 1099 // Set no autocomplete attribute for the middle name. |
| 1078 test::CreateTestFormField("Middle name", "middle", "", "text", &field); | 1100 test::CreateTestFormField("Middle name", "middle", "", "text", &field); |
| 1079 field.autocomplete_attribute = ""; | 1101 field.autocomplete_attribute = ""; |
| 1080 form.fields.push_back(field); | 1102 form.fields.push_back(field); |
| 1081 // Set an unrecognized autocomplete attribute for the last name. | 1103 // Set an unrecognized autocomplete attribute for the last name. |
| 1082 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | 1104 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 1083 field.autocomplete_attribute = "unrecognized"; | 1105 field.autocomplete_attribute = "unrecognized"; |
| 1084 form.fields.push_back(field); | 1106 form.fields.push_back(field); |
| 1085 std::vector<FormData> forms(1, form); | 1107 std::vector<FormData> forms(1, form); |
| 1086 FormsSeen(forms); | 1108 FormsSeen(forms); |
| 1087 | 1109 |
| 1088 // Suggestions should be returned for the first two fields | 1110 // Ensure that autocomplete manager is not called for suggestions either. |
| 1111 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 1112 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); |
| 1113 |
| 1114 // Suggestions should be returned for the first two fields. |
| 1089 GetAutofillSuggestions(form, form.fields[0]); | 1115 GetAutofillSuggestions(form, form.fields[0]); |
| 1090 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 1116 external_delegate_->CheckSuggestionCount(kDefaultPageID, 2); |
| 1091 GetAutofillSuggestions(form, form.fields[1]); | 1117 GetAutofillSuggestions(form, form.fields[1]); |
| 1092 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 1118 external_delegate_->CheckSuggestionCount(kDefaultPageID, 2); |
| 1093 | 1119 |
| 1094 // Suggestions should not be returned for the third field because of its | 1120 // No suggestions should not be provided for the third field because of its |
| 1095 // unrecognized autocomplete attribute. | 1121 // unrecognized autocomplete attribute. |
| 1096 GetAutofillSuggestions(form, form.fields[2]); | 1122 GetAutofillSuggestions(form, form.fields[2]); |
| 1097 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1123 external_delegate_->CheckNoSuggestions(kDefaultPageID); |
| 1098 } | 1124 } |
| 1099 | 1125 |
| 1100 // Test that no suggestions are returned when there are less than three fields | 1126 // Test that no suggestions are returned when there are less than three fields |
| 1101 // and none of them have an autocomplete attribute. | 1127 // and none of them have an autocomplete attribute. |
| 1102 TEST_F(AutofillManagerTest, GetProfileSuggestions_SmallFormNoAutocomplete) { | 1128 TEST_F(AutofillManagerTest, GetProfileSuggestions_SmallFormNoAutocomplete) { |
| 1129 // Set up our form data. |
| 1103 FormData form; | 1130 FormData form; |
| 1104 form.name = ASCIIToUTF16("MyForm"); | 1131 form.name = ASCIIToUTF16("MyForm"); |
| 1105 form.origin = GURL("https://myform.com/form.html"); | 1132 form.origin = GURL("https://myform.com/form.html"); |
| 1106 form.action = GURL("https://myform.com/submit.html"); | 1133 form.action = GURL("https://myform.com/submit.html"); |
| 1107 FormFieldData field; | 1134 FormFieldData field; |
| 1108 test::CreateTestFormField("First Name", "firstname", "", "text", &field); | 1135 test::CreateTestFormField("First Name", "firstname", "", "text", &field); |
| 1109 form.fields.push_back(field); | 1136 form.fields.push_back(field); |
| 1110 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | 1137 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 1111 form.fields.push_back(field); | 1138 form.fields.push_back(field); |
| 1112 | 1139 |
| 1113 std::vector<FormData> forms(1, form); | 1140 std::vector<FormData> forms(1, form); |
| 1114 FormsSeen(forms); | 1141 FormsSeen(forms); |
| 1115 | 1142 |
| 1143 // Ensure that autocomplete manager is called for both fields. |
| 1144 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 1145 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(2); |
| 1146 |
| 1116 GetAutofillSuggestions(form, form.fields[0]); | 1147 GetAutofillSuggestions(form, form.fields[0]); |
| 1117 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1148 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1118 | 1149 |
| 1119 GetAutofillSuggestions(form, form.fields[1]); | 1150 GetAutofillSuggestions(form, form.fields[1]); |
| 1120 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1151 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1121 } | 1152 } |
| 1122 | 1153 |
| 1123 // Test that for form with two fields with one that has an autocomplete | 1154 // Test that for form with two fields with one that has an autocomplete |
| 1124 // attribute, suggestions are only made for the one that has the attribute. | 1155 // attribute, suggestions are only made for the one that has the attribute. |
| 1125 TEST_F(AutofillManagerTest, | 1156 TEST_F(AutofillManagerTest, |
| 1126 GetProfileSuggestions_SmallFormWithOneAutocomplete) { | 1157 GetProfileSuggestions_SmallFormWithOneAutocomplete) { |
| 1158 // Set up our form data. |
| 1127 FormData form; | 1159 FormData form; |
| 1128 form.name = ASCIIToUTF16("MyForm"); | 1160 form.name = ASCIIToUTF16("MyForm"); |
| 1129 form.origin = GURL("https://myform.com/form.html"); | 1161 form.origin = GURL("https://myform.com/form.html"); |
| 1130 form.action = GURL("https://myform.com/submit.html"); | 1162 form.action = GURL("https://myform.com/submit.html"); |
| 1131 FormFieldData field; | 1163 FormFieldData field; |
| 1132 test::CreateTestFormField("First Name", "firstname", "", "text", &field); | 1164 test::CreateTestFormField("First Name", "firstname", "", "text", &field); |
| 1133 field.autocomplete_attribute = "given-name"; | 1165 field.autocomplete_attribute = "given-name"; |
| 1134 form.fields.push_back(field); | 1166 form.fields.push_back(field); |
| 1135 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | 1167 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 1136 field.autocomplete_attribute = ""; | 1168 field.autocomplete_attribute = ""; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1149 // Check that there are no suggestions for the field without the autocomplete | 1181 // Check that there are no suggestions for the field without the autocomplete |
| 1150 // attribute. | 1182 // attribute. |
| 1151 GetAutofillSuggestions(form, form.fields[1]); | 1183 GetAutofillSuggestions(form, form.fields[1]); |
| 1152 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1184 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1153 } | 1185 } |
| 1154 | 1186 |
| 1155 // Test that for a form with two fields with autocomplete attributes, | 1187 // Test that for a form with two fields with autocomplete attributes, |
| 1156 // suggestions are made for both fields. | 1188 // suggestions are made for both fields. |
| 1157 TEST_F(AutofillManagerTest, | 1189 TEST_F(AutofillManagerTest, |
| 1158 GetProfileSuggestions_SmallFormWithTwoAutocomplete) { | 1190 GetProfileSuggestions_SmallFormWithTwoAutocomplete) { |
| 1191 // Set up our form data. |
| 1159 FormData form; | 1192 FormData form; |
| 1160 form.name = ASCIIToUTF16("MyForm"); | 1193 form.name = ASCIIToUTF16("MyForm"); |
| 1161 form.origin = GURL("https://myform.com/form.html"); | 1194 form.origin = GURL("https://myform.com/form.html"); |
| 1162 form.action = GURL("https://myform.com/submit.html"); | 1195 form.action = GURL("https://myform.com/submit.html"); |
| 1163 FormFieldData field; | 1196 FormFieldData field; |
| 1164 test::CreateTestFormField("First Name", "firstname", "", "text", &field); | 1197 test::CreateTestFormField("First Name", "firstname", "", "text", &field); |
| 1165 field.autocomplete_attribute = "given-name"; | 1198 field.autocomplete_attribute = "given-name"; |
| 1166 form.fields.push_back(field); | 1199 form.fields.push_back(field); |
| 1167 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | 1200 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 1168 field.autocomplete_attribute = "family-name"; | 1201 field.autocomplete_attribute = "family-name"; |
| 1169 form.fields.push_back(field); | 1202 form.fields.push_back(field); |
| 1170 | 1203 |
| 1171 std::vector<FormData> forms(1, form); | 1204 std::vector<FormData> forms(1, form); |
| 1172 FormsSeen(forms); | 1205 FormsSeen(forms); |
| 1173 | 1206 |
| 1174 GetAutofillSuggestions(form, form.fields[0]); | 1207 GetAutofillSuggestions(form, form.fields[0]); |
| 1175 external_delegate_->CheckSuggestions( | 1208 external_delegate_->CheckSuggestions( |
| 1176 kDefaultPageID, Suggestion("Charles", "Charles Hardin Holley", "", 1), | 1209 kDefaultPageID, Suggestion("Charles", "Charles Hardin Holley", "", 1), |
| 1177 Suggestion("Elvis", "Elvis Aaron Presley", "", 2)); | 1210 Suggestion("Elvis", "Elvis Aaron Presley", "", 2)); |
| 1178 | 1211 |
| 1179 GetAutofillSuggestions(form, form.fields[1]); | 1212 GetAutofillSuggestions(form, form.fields[1]); |
| 1180 external_delegate_->CheckSuggestions( | 1213 external_delegate_->CheckSuggestions( |
| 1181 kDefaultPageID, Suggestion("Holley", "Charles Hardin Holley", "", 1), | 1214 kDefaultPageID, Suggestion("Holley", "Charles Hardin Holley", "", 1), |
| 1182 Suggestion("Presley", "Elvis Aaron Presley", "", 2)); | 1215 Suggestion("Presley", "Elvis Aaron Presley", "", 2)); |
| 1183 } | 1216 } |
| 1184 | 1217 |
| 1185 // Test that we return all address profile suggestions when all form fields are | 1218 // Test that we return all address profile suggestions when all form fields are |
| 1186 // empty. | 1219 // empty. |
| 1187 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 1220 TEST_F(AutofillManagerTest, GetProfileSuggestions_EmptyValue) { |
| 1188 // Set up our form data. | 1221 // Set up our form data. |
| 1189 FormData form; | 1222 FormData form; |
| 1190 test::CreateTestAddressFormData(&form); | 1223 test::CreateTestAddressFormData(&form); |
| 1191 std::vector<FormData> forms(1, form); | 1224 std::vector<FormData> forms(1, form); |
| 1192 FormsSeen(forms); | 1225 FormsSeen(forms); |
| 1193 | 1226 |
| 1194 const FormFieldData& field = form.fields[0]; | 1227 const FormFieldData& field = form.fields[0]; |
| 1195 GetAutofillSuggestions(form, field); | 1228 GetAutofillSuggestions(form, field); |
| 1196 | 1229 |
| 1197 // Test that we sent the right values to the external delegate. Inferred | 1230 // Test that we sent the right values to the external delegate. Inferred |
| 1198 // labels include full first relevant field, which in this case is the | 1231 // labels include full first relevant field, which in this case is the |
| 1199 // address line 1. | 1232 // address line 1. |
| 1200 external_delegate_->CheckSuggestions( | 1233 external_delegate_->CheckSuggestions( |
| 1201 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 1234 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 1202 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 1235 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 1203 } | 1236 } |
| 1204 | 1237 |
| 1205 // Test that we return only matching address profile suggestions when the | 1238 // Test that we return only matching address profile suggestions when the |
| 1206 // selected form field has been partially filled out. | 1239 // selected form field has been partially filled out. |
| 1207 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 1240 TEST_F(AutofillManagerTest, GetProfileSuggestions_MatchCharacter) { |
| 1208 // Set up our form data. | 1241 // Set up our form data. |
| 1209 FormData form; | 1242 FormData form; |
| 1210 test::CreateTestAddressFormData(&form); | 1243 test::CreateTestAddressFormData(&form); |
| 1211 std::vector<FormData> forms(1, form); | 1244 std::vector<FormData> forms(1, form); |
| 1212 FormsSeen(forms); | 1245 FormsSeen(forms); |
| 1213 | 1246 |
| 1214 FormFieldData field; | 1247 FormFieldData field; |
| 1215 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); | 1248 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); |
| 1216 GetAutofillSuggestions(form, field); | 1249 GetAutofillSuggestions(form, field); |
| 1217 | 1250 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); | 1322 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); |
| 1290 GetAutofillSuggestions(form, field); | 1323 GetAutofillSuggestions(form, field); |
| 1291 | 1324 |
| 1292 // Test that we sent the right values to the external delegate. No labels. | 1325 // Test that we sent the right values to the external delegate. No labels. |
| 1293 external_delegate_->CheckSuggestions( | 1326 external_delegate_->CheckSuggestions( |
| 1294 kDefaultPageID, | 1327 kDefaultPageID, |
| 1295 Suggestion("Elvis", "" /* no label */, "", 1)); | 1328 Suggestion("Elvis", "" /* no label */, "", 1)); |
| 1296 } | 1329 } |
| 1297 | 1330 |
| 1298 // Test that we return no suggestions when the form has no relevant fields. | 1331 // Test that we return no suggestions when the form has no relevant fields. |
| 1299 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { | 1332 TEST_F(AutofillManagerTest, GetProfileSuggestions_UnknownFields) { |
| 1300 // Set up our form data. | 1333 // Set up our form data. |
| 1301 FormData form; | 1334 FormData form; |
| 1302 form.name = ASCIIToUTF16("MyForm"); | 1335 form.name = ASCIIToUTF16("MyForm"); |
| 1303 form.origin = GURL("http://myform.com/form.html"); | 1336 form.origin = GURL("http://myform.com/form.html"); |
| 1304 form.action = GURL("http://myform.com/submit.html"); | 1337 form.action = GURL("http://myform.com/submit.html"); |
| 1305 | 1338 |
| 1306 FormFieldData field; | 1339 FormFieldData field; |
| 1307 test::CreateTestFormField("Username", "username", "", "text", &field); | 1340 test::CreateTestFormField("Username", "username", "", "text", &field); |
| 1308 form.fields.push_back(field); | 1341 form.fields.push_back(field); |
| 1309 test::CreateTestFormField("Password", "password", "", "password", &field); | 1342 test::CreateTestFormField("Password", "password", "", "password", &field); |
| 1310 form.fields.push_back(field); | 1343 form.fields.push_back(field); |
| 1311 test::CreateTestFormField("Quest", "quest", "", "quest", &field); | 1344 test::CreateTestFormField("Quest", "quest", "", "quest", &field); |
| 1312 form.fields.push_back(field); | 1345 form.fields.push_back(field); |
| 1313 test::CreateTestFormField("Color", "color", "", "text", &field); | 1346 test::CreateTestFormField("Color", "color", "", "text", &field); |
| 1314 form.fields.push_back(field); | 1347 form.fields.push_back(field); |
| 1315 | 1348 |
| 1316 std::vector<FormData> forms(1, form); | 1349 std::vector<FormData> forms(1, form); |
| 1317 FormsSeen(forms); | 1350 FormsSeen(forms); |
| 1318 | 1351 |
| 1319 GetAutofillSuggestions(form, field); | 1352 GetAutofillSuggestions(form, field); |
| 1320 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1353 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1321 } | 1354 } |
| 1322 | 1355 |
| 1323 // Test that we cull duplicate profile suggestions. | 1356 // Test that we cull duplicate profile suggestions. |
| 1324 TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) { | 1357 TEST_F(AutofillManagerTest, GetProfileSuggestions_WithDuplicates) { |
| 1325 // Set up our form data. | 1358 // Set up our form data. |
| 1326 FormData form; | 1359 FormData form; |
| 1327 test::CreateTestAddressFormData(&form); | 1360 test::CreateTestAddressFormData(&form); |
| 1328 std::vector<FormData> forms(1, form); | 1361 std::vector<FormData> forms(1, form); |
| 1329 FormsSeen(forms); | 1362 FormsSeen(forms); |
| 1330 | 1363 |
| 1331 // Add a duplicate profile. | 1364 // Add a duplicate profile. |
| 1332 AutofillProfile* duplicate_profile = | 1365 AutofillProfile* duplicate_profile = |
| 1333 new AutofillProfile( | 1366 new AutofillProfile( |
| 1334 *(autofill_manager_->GetProfileWithGUID( | 1367 *(autofill_manager_->GetProfileWithGUID( |
| 1335 "00000000-0000-0000-0000-000000000001"))); | 1368 "00000000-0000-0000-0000-000000000001"))); |
| 1336 autofill_manager_->AddProfile(duplicate_profile); | 1369 autofill_manager_->AddProfile(duplicate_profile); |
| 1337 | 1370 |
| 1338 const FormFieldData& field = form.fields[0]; | 1371 const FormFieldData& field = form.fields[0]; |
| 1339 GetAutofillSuggestions(form, field); | 1372 GetAutofillSuggestions(form, field); |
| 1340 | 1373 |
| 1341 // Test that we sent the right values to the external delegate. | 1374 // Test that we sent the right values to the external delegate. |
| 1342 external_delegate_->CheckSuggestions( | 1375 external_delegate_->CheckSuggestions( |
| 1343 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 1376 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 1344 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 1377 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 1345 } | 1378 } |
| 1346 | 1379 |
| 1347 // Test that we return no suggestions when autofill is disabled. | 1380 // Test that we return no suggestions when autofill is disabled. |
| 1348 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { | 1381 TEST_F(AutofillManagerTest, GetProfileSuggestions_AutofillDisabledByUser) { |
| 1349 // Set up our form data. | 1382 // Set up our form data. |
| 1350 FormData form; | 1383 FormData form; |
| 1351 test::CreateTestAddressFormData(&form); | 1384 test::CreateTestAddressFormData(&form); |
| 1352 std::vector<FormData> forms(1, form); | 1385 std::vector<FormData> forms(1, form); |
| 1353 FormsSeen(forms); | 1386 FormsSeen(forms); |
| 1354 | 1387 |
| 1355 // Disable Autofill. | 1388 // Disable Autofill. |
| 1356 autofill_manager_->set_autofill_enabled(false); | 1389 autofill_manager_->set_autofill_enabled(false); |
| 1357 | 1390 |
| 1358 const FormFieldData& field = form.fields[0]; | 1391 const FormFieldData& field = form.fields[0]; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 // Test that we sent the right value to the external delegate. | 1492 // Test that we sent the right value to the external delegate. |
| 1460 external_delegate_->CheckSuggestions( | 1493 external_delegate_->CheckSuggestions( |
| 1461 kDefaultPageID, Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" | 1494 kDefaultPageID, Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1462 "3123", | 1495 "3123", |
| 1463 "08/17", kMasterCard, | 1496 "08/17", kMasterCard, |
| 1464 autofill_manager_->GetPackedCreditCardID(7))); | 1497 autofill_manager_->GetPackedCreditCardID(7))); |
| 1465 } | 1498 } |
| 1466 | 1499 |
| 1467 // Test that we return only matching credit card profile suggestions when the | 1500 // Test that we return only matching credit card profile suggestions when the |
| 1468 // selected form field has been partially filled out. | 1501 // selected form field has been partially filled out. |
| 1469 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 1502 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) { |
| 1470 // Set up our form data. | 1503 // Set up our form data. |
| 1471 FormData form; | 1504 FormData form; |
| 1472 CreateTestCreditCardFormData(&form, true, false); | 1505 CreateTestCreditCardFormData(&form, true, false); |
| 1473 std::vector<FormData> forms(1, form); | 1506 std::vector<FormData> forms(1, form); |
| 1474 FormsSeen(forms); | 1507 FormsSeen(forms); |
| 1475 | 1508 |
| 1476 FormFieldData field; | 1509 FormFieldData field; |
| 1477 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); | 1510 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
| 1478 GetAutofillSuggestions(form, field); | 1511 GetAutofillSuggestions(form, field); |
| 1479 | 1512 |
| 1480 // Test that we sent the right values to the external delegate. | 1513 // Test that we sent the right values to the external delegate. |
| 1481 external_delegate_->CheckSuggestions( | 1514 external_delegate_->CheckSuggestions( |
| 1482 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" | 1515 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1483 "3456", | 1516 "3456", |
| 1484 "04/99", kVisaCard, | 1517 "04/99", kVisaCard, |
| 1485 autofill_manager_->GetPackedCreditCardID(4))); | 1518 autofill_manager_->GetPackedCreditCardID(4))); |
| 1486 } | 1519 } |
| 1487 | 1520 |
| 1488 // Test that we return credit card profile suggestions when the selected form | 1521 // Test that we return credit card profile suggestions when the selected form |
| 1489 // field is not the credit card number field. | 1522 // field is not the credit card number field. |
| 1490 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 1523 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) { |
| 1491 // Set up our form data. | 1524 // Set up our form data. |
| 1492 FormData form; | 1525 FormData form; |
| 1493 CreateTestCreditCardFormData(&form, true, false); | 1526 CreateTestCreditCardFormData(&form, true, false); |
| 1494 std::vector<FormData> forms(1, form); | 1527 std::vector<FormData> forms(1, form); |
| 1495 FormsSeen(forms); | 1528 FormsSeen(forms); |
| 1496 | 1529 |
| 1497 const FormFieldData& field = form.fields[0]; | 1530 const FormFieldData& field = form.fields[0]; |
| 1498 GetAutofillSuggestions(form, field); | 1531 GetAutofillSuggestions(form, field); |
| 1499 | 1532 |
| 1500 #if defined(OS_ANDROID) | 1533 #if defined(OS_ANDROID) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1513 external_delegate_->CheckSuggestions( | 1546 external_delegate_->CheckSuggestions( |
| 1514 kDefaultPageID, | 1547 kDefaultPageID, |
| 1515 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 1548 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
| 1516 autofill_manager_->GetPackedCreditCardID(4)), | 1549 autofill_manager_->GetPackedCreditCardID(4)), |
| 1517 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 1550 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
| 1518 autofill_manager_->GetPackedCreditCardID(5))); | 1551 autofill_manager_->GetPackedCreditCardID(5))); |
| 1519 } | 1552 } |
| 1520 | 1553 |
| 1521 // Test that we return a warning explaining that credit card profile suggestions | 1554 // Test that we return a warning explaining that credit card profile suggestions |
| 1522 // are unavailable when the form is not secure. | 1555 // are unavailable when the form is not secure. |
| 1523 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 1556 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonHTTPS) { |
| 1524 // Set up our form data. | 1557 // Set up our form data. |
| 1525 FormData form; | 1558 FormData form; |
| 1526 CreateTestCreditCardFormData(&form, false, false); | 1559 CreateTestCreditCardFormData(&form, false, false); |
| 1527 std::vector<FormData> forms(1, form); | 1560 std::vector<FormData> forms(1, form); |
| 1528 FormsSeen(forms); | 1561 FormsSeen(forms); |
| 1529 | 1562 |
| 1530 const FormFieldData& field = form.fields[0]; | 1563 const FormFieldData& field = form.fields[0]; |
| 1531 GetAutofillSuggestions(form, field); | 1564 GetAutofillSuggestions(form, field); |
| 1532 | 1565 |
| 1533 // Test that we sent the right values to the external delegate. | 1566 // Test that we sent the right values to the external delegate. |
| 1534 external_delegate_->CheckSuggestions( | 1567 external_delegate_->CheckSuggestions( |
| 1535 kDefaultPageID, | 1568 kDefaultPageID, |
| 1536 Suggestion( | 1569 Suggestion( |
| 1537 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 1570 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 1538 "", "", -1)); | 1571 "", "", -1)); |
| 1539 | 1572 |
| 1540 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1573 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1541 personal_data_.ClearCreditCards(); | 1574 personal_data_.ClearCreditCards(); |
| 1542 GetAutofillSuggestions(form, field); | 1575 GetAutofillSuggestions(form, field); |
| 1543 // Autocomplete suggestions are queried, but not Autofill. | 1576 // Autocomplete suggestions are queried, but not Autofill. |
| 1544 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1577 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1545 } | 1578 } |
| 1546 | 1579 |
| 1547 // Test that we return all credit card suggestions in the case that two cards | 1580 // Test that we return all credit card suggestions in the case that two cards |
| 1548 // have the same obfuscated number. | 1581 // have the same obfuscated number. |
| 1549 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { | 1582 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1550 // Add a credit card with the same obfuscated number as Elvis's. | 1583 // Add a credit card with the same obfuscated number as Elvis's. |
| 1551 // |credit_card| will be owned by the mock PersonalDataManager. | 1584 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1552 CreditCard* credit_card = new CreditCard; | 1585 CreditCard* credit_card = new CreditCard; |
| 1553 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 1586 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 1554 "5231567890123456", // Mastercard | 1587 "5231567890123456", // Mastercard |
| 1555 "05", "2999"); | 1588 "05", "2999"); |
| 1556 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1589 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1557 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1590 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 1558 autofill_manager_->AddCreditCard(credit_card); | 1591 autofill_manager_->AddCreditCard(credit_card); |
| 1559 | 1592 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 field.is_autofilled = true; | 1753 field.is_autofilled = true; |
| 1721 field.value = ASCIIToUTF16("Elvis"); | 1754 field.value = ASCIIToUTF16("Elvis"); |
| 1722 GetAutofillSuggestions(form, field); | 1755 GetAutofillSuggestions(form, field); |
| 1723 | 1756 |
| 1724 // Test that we sent the right values to the external delegate. | 1757 // Test that we sent the right values to the external delegate. |
| 1725 external_delegate_->CheckSuggestions( | 1758 external_delegate_->CheckSuggestions( |
| 1726 kDefaultPageID, | 1759 kDefaultPageID, |
| 1727 Suggestion("Elvis", "", "", 1)); | 1760 Suggestion("Elvis", "", "", 1)); |
| 1728 } | 1761 } |
| 1729 | 1762 |
| 1730 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { | 1763 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { |
| 1731 // Set up our form data. | 1764 // Set up our form data. |
| 1732 FormData form; | 1765 FormData form; |
| 1733 test::CreateTestAddressFormData(&form); | 1766 test::CreateTestAddressFormData(&form); |
| 1734 std::vector<FormData> forms(1, form); | 1767 std::vector<FormData> forms(1, form); |
| 1735 FormsSeen(forms); | 1768 FormsSeen(forms); |
| 1736 | 1769 |
| 1737 AutofillProfile* profile = new AutofillProfile; | 1770 AutofillProfile* profile = new AutofillProfile; |
| 1738 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1771 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1739 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), | 1772 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), |
| 1740 "en-US"); | 1773 "en-US"); |
| 1741 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 1774 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1742 ASCIIToUTF16("1800PRAIRIE")); | 1775 ASCIIToUTF16("1800PRAIRIE")); |
| 1743 autofill_manager_->AddProfile(profile); | 1776 autofill_manager_->AddProfile(profile); |
| 1744 | 1777 |
| 1745 const FormFieldData& field = form.fields[9]; | 1778 const FormFieldData& field = form.fields[9]; |
| 1746 GetAutofillSuggestions(form, field); | 1779 GetAutofillSuggestions(form, field); |
| 1747 | 1780 |
| 1748 // Test that we sent the right values to the external delegate. Inferred | 1781 // Test that we sent the right values to the external delegate. Inferred |
| 1749 // labels include the most private field of those that would be filled. | 1782 // labels include the most private field of those that would be filled. |
| 1750 external_delegate_->CheckSuggestions( | 1783 external_delegate_->CheckSuggestions( |
| 1751 kDefaultPageID, | 1784 kDefaultPageID, |
| 1752 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE | 1785 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE |
| 1753 Suggestion("23456789012", "123 Apple St.", "", 2), | 1786 Suggestion("23456789012", "123 Apple St.", "", 2), |
| 1754 Suggestion("12345678901", "3734 Elvis Presley Blvd.", "", 3)); | 1787 Suggestion("12345678901", "3734 Elvis Presley Blvd.", "", 3)); |
| 1755 } | 1788 } |
| 1756 | 1789 |
| 1757 TEST_F(AutofillManagerTest, GetProfileSuggestionsForPhonePrefixOrSuffix) { | 1790 TEST_F(AutofillManagerTest, GetProfileSuggestions_ForPhonePrefixOrSuffix) { |
| 1758 // Set up our form data. | 1791 // Set up our form data. |
| 1759 FormData form; | 1792 FormData form; |
| 1760 form.name = ASCIIToUTF16("MyForm"); | 1793 form.name = ASCIIToUTF16("MyForm"); |
| 1761 form.origin = GURL("http://myform.com/form.html"); | 1794 form.origin = GURL("http://myform.com/form.html"); |
| 1762 form.action = GURL("http://myform.com/submit.html"); | 1795 form.action = GURL("http://myform.com/submit.html"); |
| 1763 | 1796 |
| 1764 struct { | 1797 struct { |
| 1765 const char* const label; | 1798 const char* const label; |
| 1766 const char* const name; | 1799 const char* const name; |
| 1767 size_t max_length; | 1800 size_t max_length; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 number_field->value.clear(); | 1896 number_field->value.clear(); |
| 1864 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); | 1897 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); |
| 1865 | 1898 |
| 1866 // When part of the section is Autofilled, only fill the initiating field. | 1899 // When part of the section is Autofilled, only fill the initiating field. |
| 1867 month_field->is_autofilled = true; | 1900 month_field->is_autofilled = true; |
| 1868 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); | 1901 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); |
| 1869 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); | 1902 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); |
| 1870 } | 1903 } |
| 1871 | 1904 |
| 1872 // Test that we correctly fill a credit card form. | 1905 // Test that we correctly fill a credit card form. |
| 1873 TEST_F(AutofillManagerTest, FillCreditCardForm) { | 1906 TEST_F(AutofillManagerTest, FillCreditCardForm_Simple) { |
| 1874 // Set up our form data. | 1907 // Set up our form data. |
| 1875 FormData form; | 1908 FormData form; |
| 1876 CreateTestCreditCardFormData(&form, true, false); | 1909 CreateTestCreditCardFormData(&form, true, false); |
| 1877 std::vector<FormData> forms(1, form); | 1910 std::vector<FormData> forms(1, form); |
| 1878 FormsSeen(forms); | 1911 FormsSeen(forms); |
| 1879 | 1912 |
| 1880 const char guid[] = "00000000-0000-0000-0000-000000000004"; | 1913 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 1881 int response_page_id = 0; | 1914 int response_page_id = 0; |
| 1882 FormData response_data; | 1915 FormData response_data; |
| 1883 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1916 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1884 MakeFrontendID(guid, std::string()), | 1917 MakeFrontendID(guid, std::string()), |
| 1885 &response_page_id, &response_data); | 1918 &response_page_id, &response_data); |
| 1886 ExpectFilledCreditCardFormElvis( | 1919 ExpectFilledCreditCardFormElvis( |
| 1887 response_page_id, response_data, kDefaultPageID, false); | 1920 response_page_id, response_data, kDefaultPageID, false); |
| 1888 } | 1921 } |
| 1889 | 1922 |
| 1890 // Test that whitespace is stripped from the credit card number. | 1923 // Test that whitespace is stripped from the credit card number. |
| 1891 TEST_F(AutofillManagerTest, FillCreditCardFormStripCardNumberWhitespace) { | 1924 TEST_F(AutofillManagerTest, FillCreditCardForm_StripCardNumberWhitespace) { |
| 1892 // Same as the SetUp(), but generate Elvis card with whitespace in credit | 1925 // Same as the SetUp(), but generate Elvis card with whitespace in credit |
| 1893 // card number. | 1926 // card number. |
| 1894 personal_data_.CreateTestCreditCardWithWhitespace(); | 1927 personal_data_.CreateTestCreditCardWithWhitespace(); |
| 1895 // Set up our form data. | 1928 // Set up our form data. |
| 1896 FormData form; | 1929 FormData form; |
| 1897 CreateTestCreditCardFormData(&form, true, false); | 1930 CreateTestCreditCardFormData(&form, true, false); |
| 1898 std::vector<FormData> forms(1, form); | 1931 std::vector<FormData> forms(1, form); |
| 1899 FormsSeen(forms); | 1932 FormsSeen(forms); |
| 1900 | 1933 |
| 1901 const char guid[] = "00000000-0000-0000-0000-000000000008"; | 1934 const char guid[] = "00000000-0000-0000-0000-000000000008"; |
| 1902 int response_page_id = 0; | 1935 int response_page_id = 0; |
| 1903 FormData response_data; | 1936 FormData response_data; |
| 1904 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1937 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1905 MakeFrontendID(guid, std::string()), | 1938 MakeFrontendID(guid, std::string()), |
| 1906 &response_page_id, &response_data); | 1939 &response_page_id, &response_data); |
| 1907 ExpectFilledCreditCardFormElvis(response_page_id, response_data, | 1940 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 1908 kDefaultPageID, false); | 1941 kDefaultPageID, false); |
| 1909 } | 1942 } |
| 1910 | 1943 |
| 1911 // Test that separator characters are stripped from the credit card number. | 1944 // Test that separator characters are stripped from the credit card number. |
| 1912 TEST_F(AutofillManagerTest, FillCreditCardFormStripCardNumberSeparators) { | 1945 TEST_F(AutofillManagerTest, FillCreditCardForm_StripCardNumberSeparators) { |
| 1913 // Same as the SetUp(), but generate Elvis card with separator characters in | 1946 // Same as the SetUp(), but generate Elvis card with separator characters in |
| 1914 // credit card number. | 1947 // credit card number. |
| 1915 personal_data_.CreateTestCreditCardWithSeparators(); | 1948 personal_data_.CreateTestCreditCardWithSeparators(); |
| 1916 // Set up our form data. | 1949 // Set up our form data. |
| 1917 FormData form; | 1950 FormData form; |
| 1918 CreateTestCreditCardFormData(&form, true, false); | 1951 CreateTestCreditCardFormData(&form, true, false); |
| 1919 std::vector<FormData> forms(1, form); | 1952 std::vector<FormData> forms(1, form); |
| 1920 FormsSeen(forms); | 1953 FormsSeen(forms); |
| 1921 | 1954 |
| 1922 const char guid[] = "00000000-0000-0000-0000-000000000009"; | 1955 const char guid[] = "00000000-0000-0000-0000-000000000009"; |
| 1923 int response_page_id = 0; | 1956 int response_page_id = 0; |
| 1924 FormData response_data; | 1957 FormData response_data; |
| 1925 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1958 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1926 MakeFrontendID(guid, std::string()), | 1959 MakeFrontendID(guid, std::string()), |
| 1927 &response_page_id, &response_data); | 1960 &response_page_id, &response_data); |
| 1928 ExpectFilledCreditCardFormElvis(response_page_id, response_data, | 1961 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 1929 kDefaultPageID, false); | 1962 kDefaultPageID, false); |
| 1930 } | 1963 } |
| 1931 | 1964 |
| 1932 // Test that we correctly fill a credit card form with month input type. | 1965 // Test that we correctly fill a credit card form with month input type. |
| 1933 // 1. year empty, month empty | 1966 // 1. year empty, month empty |
| 1934 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { | 1967 TEST_F(AutofillManagerTest, FillCreditCardForm_NoYearNoMonth) { |
| 1935 // Same as the SetUp(), but generate 4 credit cards with year month | 1968 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1936 // combination. | 1969 // combination. |
| 1937 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); | 1970 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); |
| 1938 // Set up our form data. | 1971 // Set up our form data. |
| 1939 FormData form; | 1972 FormData form; |
| 1940 CreateTestCreditCardFormData(&form, true, true); | 1973 CreateTestCreditCardFormData(&form, true, true); |
| 1941 std::vector<FormData> forms(1, form); | 1974 std::vector<FormData> forms(1, form); |
| 1942 FormsSeen(forms); | 1975 FormsSeen(forms); |
| 1943 | 1976 |
| 1944 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1977 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1945 int response_page_id = 0; | 1978 int response_page_id = 0; |
| 1946 FormData response_data; | 1979 FormData response_data; |
| 1947 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1980 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1948 MakeFrontendID(guid, std::string()), | 1981 MakeFrontendID(guid, std::string()), |
| 1949 &response_page_id, &response_data); | 1982 &response_page_id, &response_data); |
| 1950 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1983 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1951 kDefaultPageID, false, "", ""); | 1984 kDefaultPageID, false, "", ""); |
| 1952 } | 1985 } |
| 1953 | 1986 |
| 1954 | 1987 |
| 1955 // Test that we correctly fill a credit card form with month input type. | 1988 // Test that we correctly fill a credit card form with month input type. |
| 1956 // 2. year empty, month non-empty | 1989 // 2. year empty, month non-empty |
| 1957 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { | 1990 TEST_F(AutofillManagerTest, FillCreditCardForm_NoYearMonth) { |
| 1958 // Same as the SetUp(), but generate 4 credit cards with year month | 1991 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1959 // combination. | 1992 // combination. |
| 1960 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); | 1993 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); |
| 1961 // Set up our form data. | 1994 // Set up our form data. |
| 1962 FormData form; | 1995 FormData form; |
| 1963 CreateTestCreditCardFormData(&form, true, true); | 1996 CreateTestCreditCardFormData(&form, true, true); |
| 1964 std::vector<FormData> forms(1, form); | 1997 std::vector<FormData> forms(1, form); |
| 1965 FormsSeen(forms); | 1998 FormsSeen(forms); |
| 1966 | 1999 |
| 1967 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2000 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1968 int response_page_id = 0; | 2001 int response_page_id = 0; |
| 1969 FormData response_data; | 2002 FormData response_data; |
| 1970 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2003 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1971 MakeFrontendID(guid, std::string()), | 2004 MakeFrontendID(guid, std::string()), |
| 1972 &response_page_id, &response_data); | 2005 &response_page_id, &response_data); |
| 1973 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 2006 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1974 kDefaultPageID, false, "", "04"); | 2007 kDefaultPageID, false, "", "04"); |
| 1975 } | 2008 } |
| 1976 | 2009 |
| 1977 // Test that we correctly fill a credit card form with month input type. | 2010 // Test that we correctly fill a credit card form with month input type. |
| 1978 // 3. year non-empty, month empty | 2011 // 3. year non-empty, month empty |
| 1979 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { | 2012 TEST_F(AutofillManagerTest, FillCreditCardForm_YearNoMonth) { |
| 1980 // Same as the SetUp(), but generate 4 credit cards with year month | 2013 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1981 // combination. | 2014 // combination. |
| 1982 personal_data_.CreateTestCreditCardsYearAndMonth("2999", ""); | 2015 personal_data_.CreateTestCreditCardsYearAndMonth("2999", ""); |
| 1983 // Set up our form data. | 2016 // Set up our form data. |
| 1984 FormData form; | 2017 FormData form; |
| 1985 CreateTestCreditCardFormData(&form, true, true); | 2018 CreateTestCreditCardFormData(&form, true, true); |
| 1986 std::vector<FormData> forms(1, form); | 2019 std::vector<FormData> forms(1, form); |
| 1987 FormsSeen(forms); | 2020 FormsSeen(forms); |
| 1988 | 2021 |
| 1989 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2022 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1990 int response_page_id = 0; | 2023 int response_page_id = 0; |
| 1991 FormData response_data; | 2024 FormData response_data; |
| 1992 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2025 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1993 MakeFrontendID(guid, std::string()), | 2026 MakeFrontendID(guid, std::string()), |
| 1994 &response_page_id, &response_data); | 2027 &response_page_id, &response_data); |
| 1995 ExpectFilledCreditCardYearMonthWithYearMonth( | 2028 ExpectFilledCreditCardYearMonthWithYearMonth( |
| 1996 response_page_id, response_data, kDefaultPageID, false, "2999", ""); | 2029 response_page_id, response_data, kDefaultPageID, false, "2999", ""); |
| 1997 } | 2030 } |
| 1998 | 2031 |
| 1999 // Test that we correctly fill a credit card form with month input type. | 2032 // Test that we correctly fill a credit card form with month input type. |
| 2000 // 4. year non-empty, month empty | 2033 // 4. year non-empty, month empty |
| 2001 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { | 2034 TEST_F(AutofillManagerTest, FillCreditCardForm_YearMonth) { |
| 2002 // Same as the SetUp(), but generate 4 credit cards with year month | 2035 // Same as the SetUp(), but generate 4 credit cards with year month |
| 2003 // combination. | 2036 // combination. |
| 2004 personal_data_.ClearCreditCards(); | 2037 personal_data_.ClearCreditCards(); |
| 2005 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); | 2038 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); |
| 2006 // Set up our form data. | 2039 // Set up our form data. |
| 2007 FormData form; | 2040 FormData form; |
| 2008 CreateTestCreditCardFormData(&form, true, true); | 2041 CreateTestCreditCardFormData(&form, true, true); |
| 2009 std::vector<FormData> forms(1, form); | 2042 std::vector<FormData> forms(1, form); |
| 2010 FormsSeen(forms); | 2043 FormsSeen(forms); |
| 2011 | 2044 |
| 2012 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2045 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 2013 int response_page_id = 0; | 2046 int response_page_id = 0; |
| 2014 FormData response_data; | 2047 FormData response_data; |
| 2015 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2048 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2016 MakeFrontendID(guid, std::string()), | 2049 MakeFrontendID(guid, std::string()), |
| 2017 &response_page_id, &response_data); | 2050 &response_page_id, &response_data); |
| 2018 ExpectFilledCreditCardYearMonthWithYearMonth( | 2051 ExpectFilledCreditCardYearMonthWithYearMonth( |
| 2019 response_page_id, response_data, kDefaultPageID, false, "2999", "04"); | 2052 response_page_id, response_data, kDefaultPageID, false, "2999", "04"); |
| 2020 } | 2053 } |
| 2021 | 2054 |
| 2022 // Test that we correctly fill a credit card form with first and last cardholder | 2055 // Test that we correctly fill a credit card form with first and last cardholder |
| 2023 // name. | 2056 // name. |
| 2024 TEST_F(AutofillManagerTest, FillCreditCardFormSplitName) { | 2057 TEST_F(AutofillManagerTest, FillCreditCardForm_SplitName) { |
| 2025 // Set up our form data. | 2058 // Set up our form data. |
| 2026 FormData form; | 2059 FormData form; |
| 2027 form.name = ASCIIToUTF16("MyForm"); | 2060 form.name = ASCIIToUTF16("MyForm"); |
| 2028 form.origin = GURL("https://myform.com/form.html"); | 2061 form.origin = GURL("https://myform.com/form.html"); |
| 2029 form.action = GURL("https://myform.com/submit.html"); | 2062 form.action = GURL("https://myform.com/submit.html"); |
| 2030 | 2063 |
| 2031 FormFieldData field; | 2064 FormFieldData field; |
| 2032 test::CreateTestFormField("Card Name", "cardname", "", "text", &field); | 2065 test::CreateTestFormField("Card Name", "cardname", "", "text", &field); |
| 2033 form.fields.push_back(field); | 2066 form.fields.push_back(field); |
| 2034 test::CreateTestFormField("Last Name", "cardlastname", "", "text", &field); | 2067 test::CreateTestFormField("Last Name", "cardlastname", "", "text", &field); |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2959 EXPECT_EQ(0, personal_data_.num_times_save_imported_profile_called()); | 2992 EXPECT_EQ(0, personal_data_.num_times_save_imported_profile_called()); |
| 2960 } | 2993 } |
| 2961 | 2994 |
| 2962 // Test that when Autocomplete is enabled and Autofill is disabled, form | 2995 // Test that when Autocomplete is enabled and Autofill is disabled, form |
| 2963 // submissions are still received by AutocompleteHistoryManager. | 2996 // submissions are still received by AutocompleteHistoryManager. |
| 2964 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { | 2997 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { |
| 2965 TestAutofillClient client; | 2998 TestAutofillClient client; |
| 2966 autofill_manager_.reset( | 2999 autofill_manager_.reset( |
| 2967 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 3000 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 2968 autofill_manager_->set_autofill_enabled(false); | 3001 autofill_manager_->set_autofill_enabled(false); |
| 2969 autofill_manager_->autocomplete_history_manager_.reset( | |
| 2970 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | |
| 2971 | 3002 |
| 2972 // Set up our form data. | 3003 // Set up our form data. |
| 2973 FormData form; | 3004 FormData form; |
| 2974 test::CreateTestAddressFormData(&form); | 3005 test::CreateTestAddressFormData(&form); |
| 2975 MockAutocompleteHistoryManager* m = static_cast< | 3006 |
| 2976 MockAutocompleteHistoryManager*>( | 3007 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 2977 autofill_manager_->autocomplete_history_manager_.get()); | |
| 2978 EXPECT_CALL(*m, OnWillSubmitForm(_)); | 3008 EXPECT_CALL(*m, OnWillSubmitForm(_)); |
| 2979 FormSubmitted(form); | 3009 FormSubmitted(form); |
| 2980 } | 3010 } |
| 2981 | 3011 |
| 2982 // Test that when Autofill is disabled, Autocomplete suggestions are still | 3012 // Test that when Autofill is disabled, Autocomplete suggestions are still |
| 2983 // queried. | 3013 // queried. |
| 2984 TEST_F(AutofillManagerTest, AutocompleteSuggestions_SomeWhenAutofillDisabled) { | 3014 TEST_F(AutofillManagerTest, AutocompleteSuggestions_SomeWhenAutofillDisabled) { |
| 2985 TestAutofillClient client; | 3015 TestAutofillClient client; |
| 2986 autofill_manager_.reset( | 3016 autofill_manager_.reset( |
| 2987 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 3017 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 2988 autofill_manager_->set_autofill_enabled(false); | 3018 autofill_manager_->set_autofill_enabled(false); |
| 2989 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 3019 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 2990 | 3020 |
| 2991 // Set up our form data. | 3021 // Set up our form data. |
| 2992 FormData form; | 3022 FormData form; |
| 2993 test::CreateTestAddressFormData(&form); | 3023 test::CreateTestAddressFormData(&form); |
| 2994 std::vector<FormData> forms(1, form); | 3024 std::vector<FormData> forms(1, form); |
| 2995 FormsSeen(forms); | 3025 FormsSeen(forms); |
| 2996 const FormFieldData& field = form.fields[0]; | 3026 const FormFieldData& field = form.fields[0]; |
| 2997 | 3027 |
| 2998 // Expect Autocomplete manager to be called for suggestions. | 3028 // Expect Autocomplete manager to be called for suggestions. |
| 2999 autofill_manager_->autocomplete_history_manager_.reset( | 3029 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3000 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | 3030 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)); |
| 3001 MockAutocompleteHistoryManager* m = static_cast< | |
| 3002 MockAutocompleteHistoryManager*>( | |
| 3003 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3004 EXPECT_CALL(*m, | |
| 3005 OnGetAutocompleteSuggestions(_, _, _, _)); | |
| 3006 | 3031 |
| 3007 GetAutofillSuggestions(form, field); | 3032 GetAutofillSuggestions(form, field); |
| 3008 } | 3033 } |
| 3009 | 3034 |
| 3010 // Test that when Autofill is disabled and the field should not autocomplete, | 3035 // Test that when Autofill is disabled and the field should not autocomplete, |
| 3011 // autocomplete is not queried for suggestions. | 3036 // autocomplete is not queried for suggestions. |
| 3012 TEST_F(AutofillManagerTest, | 3037 TEST_F(AutofillManagerTest, |
| 3013 AutocompleteSuggestions_AutofillDisabledAndFieldShouldNotAutocomplete) { | 3038 AutocompleteSuggestions_AutofillDisabledAndFieldShouldNotAutocomplete) { |
| 3014 TestAutofillClient client; | 3039 TestAutofillClient client; |
| 3015 autofill_manager_.reset( | 3040 autofill_manager_.reset( |
| 3016 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 3041 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 3017 autofill_manager_->set_autofill_enabled(false); | 3042 autofill_manager_->set_autofill_enabled(false); |
| 3018 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 3043 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 3019 | 3044 |
| 3020 // Set up our form data. | 3045 // Set up our form data. |
| 3021 FormData form; | 3046 FormData form; |
| 3022 test::CreateTestAddressFormData(&form); | 3047 test::CreateTestAddressFormData(&form); |
| 3023 std::vector<FormData> forms(1, form); | 3048 std::vector<FormData> forms(1, form); |
| 3024 FormsSeen(forms); | 3049 FormsSeen(forms); |
| 3025 FormFieldData field = form.fields[0]; | 3050 FormFieldData field = form.fields[0]; |
| 3026 field.should_autocomplete = false; | 3051 field.should_autocomplete = false; |
| 3027 | 3052 |
| 3028 // Autocomplete manager is not called for suggestions. | 3053 // Autocomplete manager is not called for suggestions. |
| 3029 autofill_manager_->autocomplete_history_manager_.reset( | 3054 |
| 3030 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | 3055 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3031 MockAutocompleteHistoryManager* m = static_cast< | 3056 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); |
| 3032 MockAutocompleteHistoryManager*>( | |
| 3033 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3034 EXPECT_CALL(*m, | |
| 3035 OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); | |
| 3036 | 3057 |
| 3037 GetAutofillSuggestions(form, field); | 3058 GetAutofillSuggestions(form, field); |
| 3038 } | 3059 } |
| 3039 | 3060 |
| 3040 // Test that we do not query for Autocomplete suggestions when there are | 3061 // Test that we do not query for Autocomplete suggestions when there are |
| 3041 // Autofill suggestions available. | 3062 // Autofill suggestions available. |
| 3042 TEST_F(AutofillManagerTest, AutocompleteSuggestions_NoneWhenAutofillPresent) { | 3063 TEST_F(AutofillManagerTest, AutocompleteSuggestions_NoneWhenAutofillPresent) { |
| 3043 // Set up our form data. | 3064 // Set up our form data. |
| 3044 FormData form; | 3065 FormData form; |
| 3045 test::CreateTestAddressFormData(&form); | 3066 test::CreateTestAddressFormData(&form); |
| 3046 std::vector<FormData> forms(1, form); | 3067 std::vector<FormData> forms(1, form); |
| 3047 FormsSeen(forms); | 3068 FormsSeen(forms); |
| 3048 | 3069 |
| 3049 const FormFieldData& field = form.fields[0]; | 3070 const FormFieldData& field = form.fields[0]; |
| 3050 | 3071 |
| 3051 // Autocomplete manager is not called for suggestions. | 3072 // Autocomplete manager is not called for suggestions. |
| 3052 autofill_manager_->autocomplete_history_manager_.reset( | 3073 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3053 new MockAutocompleteHistoryManager(autofill_driver_.get(), | 3074 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); |
| 3054 autofill_manager_->client())); | |
| 3055 MockAutocompleteHistoryManager* m = static_cast< | |
| 3056 MockAutocompleteHistoryManager*>( | |
| 3057 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3058 EXPECT_CALL(*m, | |
| 3059 OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); | |
| 3060 | 3075 |
| 3061 GetAutofillSuggestions(form, field); | 3076 GetAutofillSuggestions(form, field); |
| 3062 | 3077 |
| 3063 // Test that we sent the right values to the external delegate. Inferred | 3078 // Test that we sent the right values to the external delegate. Inferred |
| 3064 // labels include full first relevant field, which in this case is the | 3079 // labels include full first relevant field, which in this case is the |
| 3065 // address line 1. | 3080 // address line 1. |
| 3066 external_delegate_->CheckSuggestions( | 3081 external_delegate_->CheckSuggestions( |
| 3067 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 3082 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 3068 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 3083 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 3069 } | 3084 } |
| 3070 | 3085 |
| 3071 // Test that we query for Autocomplete suggestions when there are no Autofill | 3086 // Test that we query for Autocomplete suggestions when there are no Autofill |
| 3072 // suggestions available. | 3087 // suggestions available. |
| 3073 TEST_F(AutofillManagerTest, AutocompleteSuggestions_SomeWhenAutofillEmpty) { | 3088 TEST_F(AutofillManagerTest, AutocompleteSuggestions_SomeWhenAutofillEmpty) { |
| 3074 // Set up our form data. | 3089 // Set up our form data. |
| 3075 FormData form; | 3090 FormData form; |
| 3076 test::CreateTestAddressFormData(&form); | 3091 test::CreateTestAddressFormData(&form); |
| 3077 std::vector<FormData> forms(1, form); | 3092 std::vector<FormData> forms(1, form); |
| 3078 FormsSeen(forms); | 3093 FormsSeen(forms); |
| 3079 | 3094 |
| 3080 // No suggestions matching "donkey". | 3095 // No suggestions matching "donkey". |
| 3081 FormFieldData field; | 3096 FormFieldData field; |
| 3082 test::CreateTestFormField("Email", "email", "donkey", "email", &field); | 3097 test::CreateTestFormField("Email", "email", "donkey", "email", &field); |
| 3083 | 3098 |
| 3084 // Autocomplete manager is called for suggestions because Autofill is empty. | 3099 // Autocomplete manager is called for suggestions because Autofill is empty. |
| 3085 autofill_manager_->autocomplete_history_manager_.reset( | 3100 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3086 new MockAutocompleteHistoryManager(autofill_driver_.get(), | 3101 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)); |
| 3087 autofill_manager_->client())); | |
| 3088 MockAutocompleteHistoryManager* m = static_cast< | |
| 3089 MockAutocompleteHistoryManager*>( | |
| 3090 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3091 EXPECT_CALL(*m, | |
| 3092 OnGetAutocompleteSuggestions(_, _, _, _)); | |
| 3093 | 3102 |
| 3094 GetAutofillSuggestions(form, field); | 3103 GetAutofillSuggestions(form, field); |
| 3095 } | 3104 } |
| 3096 | 3105 |
| 3097 // Test that when Autofill is disabled and the field is a credit card name | 3106 // Test that when Autofill is disabled and the field is a credit card name |
| 3098 // field, | 3107 // field, |
| 3099 // autocomplete is queried for suggestions. | 3108 // autocomplete is queried for suggestions. |
| 3100 TEST_F(AutofillManagerTest, | 3109 TEST_F(AutofillManagerTest, |
| 3101 AutocompleteSuggestions_CreditCardNameFieldShouldAutocomplete) { | 3110 AutocompleteSuggestions_CreditCardNameFieldShouldAutocomplete) { |
| 3102 TestAutofillClient client; | 3111 TestAutofillClient client; |
| 3103 autofill_manager_.reset( | 3112 autofill_manager_.reset( |
| 3104 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 3113 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 3105 autofill_manager_->set_autofill_enabled(false); | 3114 autofill_manager_->set_autofill_enabled(false); |
| 3106 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 3115 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 3107 | 3116 |
| 3108 // Set up our form data. | 3117 // Set up our form data. |
| 3109 FormData form; | 3118 FormData form; |
| 3110 CreateTestCreditCardFormData(&form, false, false); | 3119 CreateTestCreditCardFormData(&form, false, false); |
| 3111 std::vector<FormData> forms(1, form); | 3120 std::vector<FormData> forms(1, form); |
| 3112 FormsSeen(forms); | 3121 FormsSeen(forms); |
| 3113 // The first field is "Name on card", which should autocomplete. | 3122 // The first field is "Name on card", which should autocomplete. |
| 3114 FormFieldData field = form.fields[0]; | 3123 FormFieldData field = form.fields[0]; |
| 3115 field.should_autocomplete = true; | 3124 field.should_autocomplete = true; |
| 3116 | 3125 |
| 3117 // Autocomplete manager is not called for suggestions. | 3126 // Autocomplete manager is not called for suggestions. |
| 3118 autofill_manager_->autocomplete_history_manager_.reset( | 3127 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3119 new MockAutocompleteHistoryManager(autofill_driver_.get(), | |
| 3120 autofill_manager_->client())); | |
| 3121 MockAutocompleteHistoryManager* m = | |
| 3122 static_cast<MockAutocompleteHistoryManager*>( | |
| 3123 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3124 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)); | 3128 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)); |
| 3125 | 3129 |
| 3126 GetAutofillSuggestions(form, field); | 3130 GetAutofillSuggestions(form, field); |
| 3127 } | 3131 } |
| 3128 | 3132 |
| 3129 // Test that when Autofill is disabled and the field is a credit card number | 3133 // Test that when Autofill is disabled and the field is a credit card number |
| 3130 // field, autocomplete is not queried for suggestions. | 3134 // field, autocomplete is not queried for suggestions. |
| 3131 TEST_F(AutofillManagerTest, | 3135 TEST_F(AutofillManagerTest, |
| 3132 AutocompleteSuggestions_CreditCardNumberShouldNotAutocomplete) { | 3136 AutocompleteSuggestions_CreditCardNumberShouldNotAutocomplete) { |
| 3133 TestAutofillClient client; | 3137 TestAutofillClient client; |
| 3134 autofill_manager_.reset( | 3138 autofill_manager_.reset( |
| 3135 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 3139 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 3136 autofill_manager_->set_autofill_enabled(false); | 3140 autofill_manager_->set_autofill_enabled(false); |
| 3137 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 3141 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 3138 | 3142 |
| 3139 // Set up our form data. | 3143 // Set up our form data. |
| 3140 FormData form; | 3144 FormData form; |
| 3141 CreateTestCreditCardFormData(&form, false, false); | 3145 CreateTestCreditCardFormData(&form, false, false); |
| 3142 std::vector<FormData> forms(1, form); | 3146 std::vector<FormData> forms(1, form); |
| 3143 FormsSeen(forms); | 3147 FormsSeen(forms); |
| 3144 // The second field is "Card Number", which should not autocomplete. | 3148 // The second field is "Card Number", which should not autocomplete. |
| 3145 FormFieldData field = form.fields[1]; | 3149 FormFieldData field = form.fields[1]; |
| 3146 field.should_autocomplete = true; | 3150 field.should_autocomplete = true; |
| 3147 | 3151 |
| 3148 // Autocomplete manager is not called for suggestions. | 3152 // Autocomplete manager is not called for suggestions. |
| 3149 autofill_manager_->autocomplete_history_manager_.reset( | 3153 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3150 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | |
| 3151 MockAutocompleteHistoryManager* m = | |
| 3152 static_cast<MockAutocompleteHistoryManager*>( | |
| 3153 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3154 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); | 3154 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); |
| 3155 | 3155 |
| 3156 GetAutofillSuggestions(form, field); | 3156 GetAutofillSuggestions(form, field); |
| 3157 } | 3157 } |
| 3158 | 3158 |
| 3159 // Test that we do not query for Autocomplete suggestions when there are no | 3159 // Test that we do not query for Autocomplete suggestions when there are no |
| 3160 // Autofill suggestions available, and that the field should not autocomplete. | 3160 // Autofill suggestions available, and that the field should not autocomplete. |
| 3161 TEST_F( | 3161 TEST_F( |
| 3162 AutofillManagerTest, | 3162 AutofillManagerTest, |
| 3163 AutocompleteSuggestions_NoneWhenAutofillEmptyFieldShouldNotAutocomplete) { | 3163 AutocompleteSuggestions_NoneWhenAutofillEmptyFieldShouldNotAutocomplete) { |
| 3164 // Set up our form data. | 3164 // Set up our form data. |
| 3165 FormData form; | 3165 FormData form; |
| 3166 test::CreateTestAddressFormData(&form); | 3166 test::CreateTestAddressFormData(&form); |
| 3167 std::vector<FormData> forms(1, form); | 3167 std::vector<FormData> forms(1, form); |
| 3168 FormsSeen(forms); | 3168 FormsSeen(forms); |
| 3169 | 3169 |
| 3170 // No suggestions matching "donkey". | 3170 // No suggestions matching "donkey". |
| 3171 FormFieldData field; | 3171 FormFieldData field; |
| 3172 field.should_autocomplete = false; | 3172 field.should_autocomplete = false; |
| 3173 test::CreateTestFormField("Email", "email", "donkey", "email", &field); | 3173 test::CreateTestFormField("Email", "email", "donkey", "email", &field); |
| 3174 | 3174 |
| 3175 // Autocomplete manager is not called for suggestions. | 3175 // Autocomplete manager is not called for suggestions. |
| 3176 autofill_manager_->autocomplete_history_manager_.reset( | 3176 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3177 new MockAutocompleteHistoryManager(autofill_driver_.get(), | 3177 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); |
| 3178 autofill_manager_->client())); | |
| 3179 MockAutocompleteHistoryManager* m = static_cast< | |
| 3180 MockAutocompleteHistoryManager*>( | |
| 3181 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3182 EXPECT_CALL(*m, | |
| 3183 OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); | |
| 3184 | 3178 |
| 3185 GetAutofillSuggestions(form, field); | 3179 GetAutofillSuggestions(form, field); |
| 3186 } | 3180 } |
| 3187 | 3181 |
| 3188 TEST_F(AutofillManagerTest, AutocompleteOffRespectedForAutocomplete) { | 3182 TEST_F(AutofillManagerTest, AutocompleteOffRespectedForAutocomplete) { |
| 3189 TestAutofillClient client; | 3183 TestAutofillClient client; |
| 3190 autofill_manager_.reset( | 3184 autofill_manager_.reset( |
| 3191 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 3185 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 3192 autofill_manager_->set_autofill_enabled(false); | 3186 autofill_manager_->set_autofill_enabled(false); |
| 3193 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 3187 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 3194 | 3188 |
| 3195 autofill_manager_->autocomplete_history_manager_.reset( | 3189 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 3196 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | 3190 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); |
| 3197 MockAutocompleteHistoryManager* m = static_cast< | |
| 3198 MockAutocompleteHistoryManager*>( | |
| 3199 autofill_manager_->autocomplete_history_manager_.get()); | |
| 3200 EXPECT_CALL(*m, | |
| 3201 OnGetAutocompleteSuggestions(_, _, _, _)).Times(0); | |
| 3202 | 3191 |
| 3203 // Set up our form data. | 3192 // Set up our form data. |
| 3204 FormData form; | 3193 FormData form; |
| 3205 test::CreateTestAddressFormData(&form); | 3194 test::CreateTestAddressFormData(&form); |
| 3206 std::vector<FormData> forms(1, form); | 3195 std::vector<FormData> forms(1, form); |
| 3207 FormsSeen(forms); | 3196 FormsSeen(forms); |
| 3208 FormFieldData* field = &form.fields[0]; | 3197 FormFieldData* field = &form.fields[0]; |
| 3209 field->should_autocomplete = false; | 3198 field->should_autocomplete = false; |
| 3210 GetAutofillSuggestions(form, *field); | 3199 GetAutofillSuggestions(form, *field); |
| 3211 } | 3200 } |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4118 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 4107 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 4119 | 4108 |
| 4120 // Suggestions should still be returned for the third field because it is a | 4109 // Suggestions should still be returned for the third field because it is a |
| 4121 // credit card field. | 4110 // credit card field. |
| 4122 GetAutofillSuggestions(form, form.fields[2]); | 4111 GetAutofillSuggestions(form, form.fields[2]); |
| 4123 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 4112 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 4124 } | 4113 } |
| 4125 | 4114 |
| 4126 // Test to verify suggestions appears for forms having credit card number split | 4115 // Test to verify suggestions appears for forms having credit card number split |
| 4127 // across fields. | 4116 // across fields. |
| 4128 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { | 4117 TEST_F(AutofillManagerTest, |
| 4118 GetCreditCardSuggestions_ForNumberSpitAcrossFields) { |
| 4129 // Set up our form data with credit card number split across fields. | 4119 // Set up our form data with credit card number split across fields. |
| 4130 FormData form; | 4120 FormData form; |
| 4131 form.name = ASCIIToUTF16("MyForm"); | 4121 form.name = ASCIIToUTF16("MyForm"); |
| 4132 form.origin = GURL("https://myform.com/form.html"); | 4122 form.origin = GURL("https://myform.com/form.html"); |
| 4133 form.action = GURL("https://myform.com/submit.html"); | 4123 form.action = GURL("https://myform.com/submit.html"); |
| 4134 | 4124 |
| 4135 FormFieldData name_field; | 4125 FormFieldData name_field; |
| 4136 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", | 4126 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", |
| 4137 &name_field); | 4127 &name_field); |
| 4138 form.fields.push_back(name_field); | 4128 form.fields.push_back(name_field); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4175 external_delegate_->CheckSuggestions( | 4165 external_delegate_->CheckSuggestions( |
| 4176 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" | 4166 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 4177 "3456", | 4167 "3456", |
| 4178 "04/99", kVisaCard, | 4168 "04/99", kVisaCard, |
| 4179 autofill_manager_->GetPackedCreditCardID(4))); | 4169 autofill_manager_->GetPackedCreditCardID(4))); |
| 4180 } | 4170 } |
| 4181 | 4171 |
| 4182 // Test that inputs detected to be CVC inputs are forced to | 4172 // Test that inputs detected to be CVC inputs are forced to |
| 4183 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. | 4173 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. |
| 4184 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { | 4174 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { |
| 4185 autofill_manager_->autocomplete_history_manager_.reset( | |
| 4186 new MockAutocompleteHistoryManager(autofill_driver_.get(), | |
| 4187 &autofill_client_)); | |
| 4188 FormData form_seen_by_ahm; | 4175 FormData form_seen_by_ahm; |
| 4189 MockAutocompleteHistoryManager* mock_ahm = | 4176 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 4190 static_cast<MockAutocompleteHistoryManager*>( | 4177 EXPECT_CALL(*m, OnWillSubmitForm(_)).WillOnce(SaveArg<0>(&form_seen_by_ahm)); |
| 4191 autofill_manager_->autocomplete_history_manager_.get()); | |
| 4192 EXPECT_CALL(*mock_ahm, OnWillSubmitForm(_)) | |
| 4193 .WillOnce(SaveArg<0>(&form_seen_by_ahm)); | |
| 4194 | 4178 |
| 4195 FormData form; | 4179 FormData form; |
| 4196 form.name = ASCIIToUTF16("MyForm"); | 4180 form.name = ASCIIToUTF16("MyForm"); |
| 4197 form.origin = GURL("http://myform.com/form.html"); | 4181 form.origin = GURL("http://myform.com/form.html"); |
| 4198 form.action = GURL("http://myform.com/submit.html"); | 4182 form.action = GURL("http://myform.com/submit.html"); |
| 4199 | 4183 |
| 4200 struct { | 4184 struct { |
| 4201 const char* label; | 4185 const char* label; |
| 4202 const char* name; | 4186 const char* name; |
| 4203 const char* value; | 4187 const char* value; |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5228 FormsSeen(mixed_forms); | 5212 FormsSeen(mixed_forms); |
| 5229 | 5213 |
| 5230 // Suggestions should always be displayed. | 5214 // Suggestions should always be displayed. |
| 5231 for (const FormFieldData& field : mixed_form.fields) { | 5215 for (const FormFieldData& field : mixed_form.fields) { |
| 5232 GetAutofillSuggestions(mixed_form, field); | 5216 GetAutofillSuggestions(mixed_form, field); |
| 5233 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5217 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5234 } | 5218 } |
| 5235 } | 5219 } |
| 5236 | 5220 |
| 5237 } // namespace autofill | 5221 } // namespace autofill |
| OLD | NEW |