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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 "Expiration Date", "ccmonth", "", "month", &field); | 206 "Expiration Date", "ccmonth", "", "month", &field); |
207 form->fields.push_back(field); | 207 form->fields.push_back(field); |
208 } else { | 208 } else { |
209 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); | 209 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
210 form->fields.push_back(field); | 210 form->fields.push_back(field); |
211 test::CreateTestFormField("", "ccyear", "", "text", &field); | 211 test::CreateTestFormField("", "ccyear", "", "text", &field); |
212 form->fields.push_back(field); | 212 form->fields.push_back(field); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 // Helper function to create a form with credit card number spits across 4 input | |
217 // fields. | |
218 void CreateTestCreditCardFormWithNumberSplitAcrossFields(FormData* form) { | |
219 CreateTestCreditCardFormData(form, true, false); | |
220 | |
221 // Remove existing card number field. | |
222 form->fields.erase(form->fields.begin() + 1); | |
223 | |
224 // Add new 4 |card_number_field|s to the |form|. | |
225 FormFieldData card_number_field; | |
226 card_number_field.max_length = 4; | |
227 test::CreateTestFormField( | |
228 "Card Number", "cardnumber_1", "", "text", &card_number_field); | |
229 form->fields.insert(form->fields.begin() + 1, card_number_field); | |
230 | |
231 test::CreateTestFormField("", "cardnumber_2", "", "text", &card_number_field); | |
232 form->fields.insert(form->fields.begin() + 2, card_number_field); | |
233 | |
234 test::CreateTestFormField("", "cardnumber_3", "", "text", &card_number_field); | |
235 form->fields.insert(form->fields.begin() + 3, card_number_field); | |
236 | |
237 test::CreateTestFormField("", "cardnumber_4", "", "text", &card_number_field); | |
238 form->fields.insert(form->fields.begin() + 4, card_number_field); | |
239 } | |
240 | |
216 void ExpectFilledField(const char* expected_label, | 241 void ExpectFilledField(const char* expected_label, |
217 const char* expected_name, | 242 const char* expected_name, |
218 const char* expected_value, | 243 const char* expected_value, |
219 const char* expected_form_control_type, | 244 const char* expected_form_control_type, |
220 const FormFieldData& field) { | 245 const FormFieldData& field) { |
221 SCOPED_TRACE(expected_label); | 246 SCOPED_TRACE(expected_label); |
222 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 247 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
223 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 248 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
224 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 249 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
225 EXPECT_EQ(expected_form_control_type, field.form_control_type); | 250 EXPECT_EQ(expected_form_control_type, field.form_control_type); |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 // Test that we return only matching credit card profile suggestions when the | 916 // Test that we return only matching credit card profile suggestions when the |
892 // selected form field has been partially filled out. | 917 // selected form field has been partially filled out. |
893 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 918 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
894 // Set up our form data. | 919 // Set up our form data. |
895 FormData form; | 920 FormData form; |
896 CreateTestCreditCardFormData(&form, true, false); | 921 CreateTestCreditCardFormData(&form, true, false); |
897 std::vector<FormData> forms(1, form); | 922 std::vector<FormData> forms(1, form); |
898 FormsSeen(forms); | 923 FormsSeen(forms); |
899 | 924 |
900 FormFieldData field; | 925 FormFieldData field; |
901 test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field); | 926 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
902 GetAutofillSuggestions(form, field); | 927 GetAutofillSuggestions(form, field); |
903 | 928 |
904 // No suggestions provided, so send an empty vector as the results. | 929 // No suggestions provided, so send an empty vector as the results. |
905 // This triggers the combined message send. | 930 // This triggers the combined message send. |
906 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 931 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
907 | 932 |
908 // Test that we sent the right values to the external delegate. | 933 // Test that we sent the right values to the external delegate. |
909 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | 934 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; |
910 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | 935 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; |
911 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | 936 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; |
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2981 FormData form; | 3006 FormData form; |
2982 test::CreateTestAddressFormData(&form); | 3007 test::CreateTestAddressFormData(&form); |
2983 std::vector<FormData> forms(1, form); | 3008 std::vector<FormData> forms(1, form); |
2984 FormsSeen(forms); | 3009 FormsSeen(forms); |
2985 const FormFieldData& field = form.fields[0]; | 3010 const FormFieldData& field = form.fields[0]; |
2986 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3011 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2987 | 3012 |
2988 EXPECT_TRUE(external_delegate_->on_query_seen()); | 3013 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2989 } | 3014 } |
2990 | 3015 |
3016 // Test to verify suggestions appears for forms having credit card number split | |
3017 // across fields. | |
3018 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { | |
3019 // Set up our form data with credit card number split across fields. | |
3020 FormData form; | |
3021 CreateTestCreditCardFormWithNumberSplitAcrossFields(&form); | |
3022 std::vector<FormData> forms(1, form); | |
3023 FormsSeen(forms); | |
3024 | |
3025 // Fill the credit card details. | |
3026 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); | |
3027 GUIDPair empty(std::string(), 0); | |
3028 int response_page_id = 0; | |
3029 FormData response_data; | |
3030 FillAutofillFormDataAndSaveResults(kDefaultPageID, | |
3031 form, | |
3032 *form.fields.begin(), | |
3033 PackGUIDs(guid, empty), | |
3034 &response_page_id, | |
3035 &response_data); | |
3036 | |
3037 ASSERT_EQ(7U, response_data.fields.size()); | |
3038 | |
3039 // Verify whether suggestions for credit card number spilt across 4 fields | |
3040 // getting populated correctly. | |
Ilya Sherman
2014/10/28 21:48:40
nit: "getting" -> "are"
Pritam Nikam
2014/10/29 08:38:16
Done.
| |
3041 const size_t starts_at = 1; | |
3042 const size_t total_number_fields = 4; | |
3043 for (size_t i = starts_at; i < (starts_at + total_number_fields); ++i) { | |
Ilya Sherman
2014/10/28 21:48:40
Please unroll this loop, so have four repeated set
Pritam Nikam
2014/10/29 08:38:16
Done.
| |
3044 FormFieldData number_field = response_data.fields[i]; | |
3045 | |
3046 // Enforce 'max-length' constraint on |number_field|. | |
3047 size_t length = (number_field.max_length < number_field.value.size()) | |
3048 ? number_field.max_length | |
3049 : number_field.value.size(); | |
Ilya Sherman
2014/10/28 21:48:40
You shouldn't need to do this. Just check that th
Pritam Nikam
2014/10/29 08:38:16
Done.
| |
3050 base::string16 card_number = number_field.value.substr(0, length); | |
3051 number_field.value = card_number; | |
3052 | |
3053 // Get the suggestions for credit card |number_field|. | |
3054 GetAutofillSuggestions(form, number_field); | |
3055 | |
3056 // No suggestions provided, so send an empty vector as the results. | |
3057 // This triggers the combined message send. | |
3058 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3059 | |
3060 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | |
3061 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | |
3062 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | |
3063 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; | |
3064 external_delegate_->CheckSuggestions(kDefaultPageID, | |
3065 arraysize(expected_values), | |
3066 expected_values, | |
3067 expected_labels, | |
3068 expected_icons, | |
3069 expected_unique_ids); | |
3070 } | |
3071 } | |
3072 | |
2991 } // namespace autofill | 3073 } // namespace autofill |
OLD | NEW |