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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 "Expiration Date", "ccmonth", "", "month", &field); | 205 "Expiration Date", "ccmonth", "", "month", &field); |
206 form->fields.push_back(field); | 206 form->fields.push_back(field); |
207 } else { | 207 } else { |
208 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); | 208 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
209 form->fields.push_back(field); | 209 form->fields.push_back(field); |
210 test::CreateTestFormField("", "ccyear", "", "text", &field); | 210 test::CreateTestFormField("", "ccyear", "", "text", &field); |
211 form->fields.push_back(field); | 211 form->fields.push_back(field); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
| 215 // Helper function to create a form with credit card number spits across 4 input |
| 216 // fields. |
| 217 void CreateTestCreditCardFormWithNumberSplitAcrossFields(FormData* form) { |
| 218 CreateTestCreditCardFormData(form, true, false); |
| 219 |
| 220 // Remove existing card number field. |
| 221 form->fields.erase(form->fields.begin() + 1); |
| 222 |
| 223 // Add new 4 |card_number_field|s to the |form|. |
| 224 FormFieldData card_number_field; |
| 225 card_number_field.max_length = 4; |
| 226 test::CreateTestFormField( |
| 227 "Card Number", "cardnumber_1", "", "text", &card_number_field); |
| 228 form->fields.insert(form->fields.begin() + 1, card_number_field); |
| 229 |
| 230 test::CreateTestFormField("", "cardnumber_2", "", "text", &card_number_field); |
| 231 form->fields.insert(form->fields.begin() + 2, card_number_field); |
| 232 |
| 233 test::CreateTestFormField("", "cardnumber_3", "", "text", &card_number_field); |
| 234 form->fields.insert(form->fields.begin() + 3, card_number_field); |
| 235 |
| 236 test::CreateTestFormField("", "cardnumber_4", "", "text", &card_number_field); |
| 237 form->fields.insert(form->fields.begin() + 4, card_number_field); |
| 238 } |
| 239 |
215 void ExpectFilledField(const char* expected_label, | 240 void ExpectFilledField(const char* expected_label, |
216 const char* expected_name, | 241 const char* expected_name, |
217 const char* expected_value, | 242 const char* expected_value, |
218 const char* expected_form_control_type, | 243 const char* expected_form_control_type, |
219 const FormFieldData& field) { | 244 const FormFieldData& field) { |
220 SCOPED_TRACE(expected_label); | 245 SCOPED_TRACE(expected_label); |
221 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 246 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
222 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 247 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
223 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 248 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
224 EXPECT_EQ(expected_form_control_type, field.form_control_type); | 249 EXPECT_EQ(expected_form_control_type, field.form_control_type); |
(...skipping 2687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2912 FormData form; | 2937 FormData form; |
2913 test::CreateTestAddressFormData(&form); | 2938 test::CreateTestAddressFormData(&form); |
2914 std::vector<FormData> forms(1, form); | 2939 std::vector<FormData> forms(1, form); |
2915 FormsSeen(forms); | 2940 FormsSeen(forms); |
2916 const FormFieldData& field = form.fields[0]; | 2941 const FormFieldData& field = form.fields[0]; |
2917 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2942 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2918 | 2943 |
2919 EXPECT_TRUE(external_delegate_->on_query_seen()); | 2944 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2920 } | 2945 } |
2921 | 2946 |
| 2947 // Test to verify suggestions appears for forms having credit card number split |
| 2948 // across fields. |
| 2949 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { |
| 2950 // Set up our form data with credit card number split across fields. |
| 2951 FormData form; |
| 2952 CreateTestCreditCardFormWithNumberSplitAcrossFields(&form); |
| 2953 std::vector<FormData> forms(1, form); |
| 2954 FormsSeen(forms); |
| 2955 |
| 2956 // Fill the credit card details. |
| 2957 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); |
| 2958 GUIDPair empty(std::string(), 0); |
| 2959 int response_page_id = 0; |
| 2960 FormData response_data; |
| 2961 FillAutofillFormDataAndSaveResults(kDefaultPageID, |
| 2962 form, |
| 2963 *form.fields.begin(), |
| 2964 PackGUIDs(guid, empty), |
| 2965 &response_page_id, |
| 2966 &response_data); |
| 2967 |
| 2968 ASSERT_EQ(7U, response_data.fields.size()); |
| 2969 |
| 2970 // Verify whether suggestions for credit card number spilt across 4 fields |
| 2971 // getting populated correctly. |
| 2972 const size_t starts_at = 1; |
| 2973 const size_t total_number_fields = 4; |
| 2974 for (size_t i = starts_at; i < (starts_at + total_number_fields); ++i) { |
| 2975 FormFieldData number_field = response_data.fields[i]; |
| 2976 |
| 2977 // Enforce 'max-length' constraint on |number_field|. |
| 2978 size_t length = (number_field.max_length < number_field.value.size()) |
| 2979 ? number_field.max_length |
| 2980 : number_field.value.size(); |
| 2981 base::string16 card_number = number_field.value.substr(0, length); |
| 2982 number_field.value = card_number; |
| 2983 |
| 2984 // Get the suggestions for credit card |number_field|. |
| 2985 GetAutofillSuggestions(form, number_field); |
| 2986 |
| 2987 // No suggestions provided, so send an empty vector as the results. |
| 2988 // This triggers the combined message send. |
| 2989 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 2990 |
| 2991 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; |
| 2992 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; |
| 2993 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; |
| 2994 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; |
| 2995 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 2996 arraysize(expected_values), |
| 2997 expected_values, |
| 2998 expected_labels, |
| 2999 expected_icons, |
| 3000 expected_unique_ids); |
| 3001 } |
| 3002 } |
| 3003 |
2922 } // namespace autofill | 3004 } // namespace autofill |
OLD | NEW |