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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | |
18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "base/tuple.h" | 22 #include "base/tuple.h" |
22 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 23 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
23 #include "components/autofill/core/browser/autofill_manager.h" | 24 #include "components/autofill/core/browser/autofill_manager.h" |
24 #include "components/autofill/core/browser/autofill_metrics.h" | 25 #include "components/autofill/core/browser/autofill_metrics.h" |
25 #include "components/autofill/core/browser/autofill_profile.h" | 26 #include "components/autofill/core/browser/autofill_profile.h" |
26 #include "components/autofill/core/browser/autofill_test_utils.h" | 27 #include "components/autofill/core/browser/autofill_test_utils.h" |
27 #include "components/autofill/core/browser/credit_card.h" | 28 #include "components/autofill/core/browser/credit_card.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 "Expiration Date", "ccmonth", "", "month", &field); | 207 "Expiration Date", "ccmonth", "", "month", &field); |
207 form->fields.push_back(field); | 208 form->fields.push_back(field); |
208 } else { | 209 } else { |
209 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); | 210 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
210 form->fields.push_back(field); | 211 form->fields.push_back(field); |
211 test::CreateTestFormField("", "ccyear", "", "text", &field); | 212 test::CreateTestFormField("", "ccyear", "", "text", &field); |
212 form->fields.push_back(field); | 213 form->fields.push_back(field); |
213 } | 214 } |
214 } | 215 } |
215 | 216 |
217 // Helper function to create a form with credit card number spits across 4 input | |
218 // fields. | |
219 void CreateTestCreditCardFormWithNumberSplitAcrossFields(FormData* form) { | |
220 CreateTestCreditCardFormData(form, true, false); | |
221 | |
222 // Remove existing card number field. | |
223 form->fields.erase(form->fields.begin() + 1); | |
224 | |
225 // Add new 4 |card_number_field|s to the |form|. | |
226 FormFieldData card_number_field; | |
227 card_number_field.max_length = 4; | |
228 test::CreateTestFormField( | |
229 "Card Number", "cardnumber_1", "", "text", &card_number_field); | |
230 form->fields.insert(form->fields.begin() + 1, card_number_field); | |
231 | |
232 test::CreateTestFormField("", "cardnumber_2", "", "text", &card_number_field); | |
233 form->fields.insert(form->fields.begin() + 2, card_number_field); | |
234 | |
235 test::CreateTestFormField("", "cardnumber_3", "", "text", &card_number_field); | |
236 form->fields.insert(form->fields.begin() + 3, card_number_field); | |
237 | |
238 test::CreateTestFormField("", "cardnumber_4", "", "text", &card_number_field); | |
239 form->fields.insert(form->fields.begin() + 4, card_number_field); | |
240 } | |
Ilya Sherman
2014/10/30 01:00:58
Please remove this helper function.
Pritam Nikam
2014/10/30 05:57:18
Done.
Merge within test |GetCreditCardSuggestions
| |
241 | |
216 void ExpectFilledField(const char* expected_label, | 242 void ExpectFilledField(const char* expected_label, |
217 const char* expected_name, | 243 const char* expected_name, |
218 const char* expected_value, | 244 const char* expected_value, |
219 const char* expected_form_control_type, | 245 const char* expected_form_control_type, |
220 const FormFieldData& field) { | 246 const FormFieldData& field) { |
221 SCOPED_TRACE(expected_label); | 247 SCOPED_TRACE(expected_label); |
222 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 248 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
223 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 249 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
224 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 250 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
225 EXPECT_EQ(expected_form_control_type, field.form_control_type); | 251 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 | 917 // Test that we return only matching credit card profile suggestions when the |
892 // selected form field has been partially filled out. | 918 // selected form field has been partially filled out. |
893 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 919 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
894 // Set up our form data. | 920 // Set up our form data. |
895 FormData form; | 921 FormData form; |
896 CreateTestCreditCardFormData(&form, true, false); | 922 CreateTestCreditCardFormData(&form, true, false); |
897 std::vector<FormData> forms(1, form); | 923 std::vector<FormData> forms(1, form); |
898 FormsSeen(forms); | 924 FormsSeen(forms); |
899 | 925 |
900 FormFieldData field; | 926 FormFieldData field; |
901 test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field); | 927 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
902 GetAutofillSuggestions(form, field); | 928 GetAutofillSuggestions(form, field); |
903 | 929 |
904 // No suggestions provided, so send an empty vector as the results. | 930 // No suggestions provided, so send an empty vector as the results. |
905 // This triggers the combined message send. | 931 // This triggers the combined message send. |
906 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 932 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
907 | 933 |
908 // Test that we sent the right values to the external delegate. | 934 // Test that we sent the right values to the external delegate. |
909 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | 935 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; |
910 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | 936 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; |
911 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | 937 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; |
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2981 FormData form; | 3007 FormData form; |
2982 test::CreateTestAddressFormData(&form); | 3008 test::CreateTestAddressFormData(&form); |
2983 std::vector<FormData> forms(1, form); | 3009 std::vector<FormData> forms(1, form); |
2984 FormsSeen(forms); | 3010 FormsSeen(forms); |
2985 const FormFieldData& field = form.fields[0]; | 3011 const FormFieldData& field = form.fields[0]; |
2986 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3012 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2987 | 3013 |
2988 EXPECT_TRUE(external_delegate_->on_query_seen()); | 3014 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2989 } | 3015 } |
2990 | 3016 |
3017 // Test to verify suggestions appears for forms having credit card number split | |
3018 // across fields. | |
3019 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { | |
3020 // Set up our form data with credit card number split across fields. | |
3021 FormData form; | |
3022 CreateTestCreditCardFormWithNumberSplitAcrossFields(&form); | |
3023 std::vector<FormData> forms(1, form); | |
3024 FormsSeen(forms); | |
3025 | |
3026 // Fill the credit card details. | |
3027 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); | |
3028 GUIDPair empty(std::string(), 0); | |
3029 int response_page_id = 0; | |
3030 FormData response_data; | |
3031 FillAutofillFormDataAndSaveResults(kDefaultPageID, | |
3032 form, | |
3033 *form.fields.begin(), | |
3034 PackGUIDs(guid, empty), | |
3035 &response_page_id, | |
3036 &response_data); | |
3037 | |
3038 ASSERT_EQ(7U, response_data.fields.size()); | |
3039 | |
3040 // Verify whether suggestions are populated correctly for one of the middle | |
3041 // credit card number fields. | |
3042 FormFieldData number_field = response_data.fields[3]; | |
3043 | |
3044 // Suggested card number 4234-5678-9012-3456. | |
3045 EXPECT_TRUE(StartsWith(number_field.value, ASCIIToUTF16("9012"), false)); | |
3046 } | |
Ilya Sherman
2014/10/30 01:00:58
Hmm, this test appears to test that if a suggestio
Pritam Nikam
2014/10/30 05:57:18
Done.
I've restored the GetAutofillSuggestions()
| |
3047 | |
2991 } // namespace autofill | 3048 } // namespace autofill |
OLD | NEW |