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 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 // Test that we return only matching credit card profile suggestions when the | 892 // Test that we return only matching credit card profile suggestions when the |
892 // selected form field has been partially filled out. | 893 // selected form field has been partially filled out. |
893 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 894 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
894 // Set up our form data. | 895 // Set up our form data. |
895 FormData form; | 896 FormData form; |
896 CreateTestCreditCardFormData(&form, true, false); | 897 CreateTestCreditCardFormData(&form, true, false); |
897 std::vector<FormData> forms(1, form); | 898 std::vector<FormData> forms(1, form); |
898 FormsSeen(forms); | 899 FormsSeen(forms); |
899 | 900 |
900 FormFieldData field; | 901 FormFieldData field; |
901 test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field); | 902 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
902 GetAutofillSuggestions(form, field); | 903 GetAutofillSuggestions(form, field); |
903 | 904 |
904 // No suggestions provided, so send an empty vector as the results. | 905 // No suggestions provided, so send an empty vector as the results. |
905 // This triggers the combined message send. | 906 // This triggers the combined message send. |
906 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 907 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
907 | 908 |
908 // Test that we sent the right values to the external delegate. | 909 // Test that we sent the right values to the external delegate. |
909 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | 910 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; |
910 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | 911 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; |
911 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | 912 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; |
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2981 FormData form; | 2982 FormData form; |
2982 test::CreateTestAddressFormData(&form); | 2983 test::CreateTestAddressFormData(&form); |
2983 std::vector<FormData> forms(1, form); | 2984 std::vector<FormData> forms(1, form); |
2984 FormsSeen(forms); | 2985 FormsSeen(forms); |
2985 const FormFieldData& field = form.fields[0]; | 2986 const FormFieldData& field = form.fields[0]; |
2986 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2987 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2987 | 2988 |
2988 EXPECT_TRUE(external_delegate_->on_query_seen()); | 2989 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2989 } | 2990 } |
2990 | 2991 |
2992 // Test to verify suggestions appears for forms having credit card number split | |
2993 // across fields. | |
2994 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { | |
2995 // Set up our form data with credit card number split across fields. | |
2996 FormData form; | |
2997 CreateTestCreditCardFormData(&form, true, false); | |
Ilya Sherman
2014/10/30 22:58:55
Please remove this call as well, and instead const
Pritam Nikam
2014/10/31 06:59:33
Done.
| |
2998 | |
2999 // Remove existing card number field. | |
3000 form.fields.erase(form.fields.begin() + 1); | |
3001 | |
3002 // Add new 4 |card_number_field|s to the |form|. | |
3003 FormFieldData card_number_field; | |
3004 card_number_field.max_length = 4; | |
3005 test::CreateTestFormField( | |
3006 "Card Number", "cardnumber_1", "", "text", &card_number_field); | |
3007 form.fields.insert(form.fields.begin() + 1, card_number_field); | |
3008 | |
3009 test::CreateTestFormField("", "cardnumber_2", "", "text", &card_number_field); | |
3010 form.fields.insert(form.fields.begin() + 2, card_number_field); | |
3011 | |
3012 test::CreateTestFormField("", "cardnumber_3", "", "text", &card_number_field); | |
3013 form.fields.insert(form.fields.begin() + 3, card_number_field); | |
3014 | |
3015 test::CreateTestFormField("", "cardnumber_4", "", "text", &card_number_field); | |
3016 form.fields.insert(form.fields.begin() + 4, card_number_field); | |
3017 | |
3018 std::vector<FormData> forms(1, form); | |
3019 FormsSeen(forms); | |
3020 | |
3021 // Fill the credit card details. | |
Ilya Sherman
2014/10/30 22:58:55
I'm still not sure why you're filling the form as
Pritam Nikam
2014/10/31 06:59:33
Yes, you are right, we do have testcases for the f
Ilya Sherman
2014/10/31 22:49:59
Hmm, do we really need the field to be autofilled?
| |
3022 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); | |
3023 GUIDPair empty(std::string(), 0); | |
3024 int response_page_id = 0; | |
3025 FormData response_data; | |
3026 FillAutofillFormDataAndSaveResults(kDefaultPageID, | |
3027 form, | |
3028 *form.fields.begin(), | |
3029 PackGUIDs(guid, empty), | |
3030 &response_page_id, | |
3031 &response_data); | |
3032 | |
3033 ASSERT_EQ(7U, response_data.fields.size()); | |
3034 | |
3035 // Verify whether suggestions are populated correctly for one of the middle | |
3036 // credit card number fields. | |
3037 FormFieldData number_field = response_data.fields[3]; | |
3038 | |
3039 // Suggested card number 4234-5678-9012-3456. | |
3040 EXPECT_TRUE(StartsWith(number_field.value, ASCIIToUTF16("9012"), false)); | |
3041 | |
3042 // Get the suggestions for credit card |number_field|. | |
3043 GetAutofillSuggestions(form, number_field); | |
3044 | |
3045 // No suggestions provided, so send an empty vector as the results. | |
3046 // This triggers the combined message send. | |
3047 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | |
3048 | |
3049 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | |
3050 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | |
3051 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | |
3052 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; | |
3053 external_delegate_->CheckSuggestions(kDefaultPageID, | |
3054 arraysize(expected_values), | |
3055 expected_values, | |
3056 expected_labels, | |
3057 expected_icons, | |
3058 expected_unique_ids); | |
3059 } | |
3060 | |
2991 } // namespace autofill | 3061 } // namespace autofill |
OLD | NEW |