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 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 const char* const name; | 1801 const char* const name; |
1802 size_t max_length; | 1802 size_t max_length; |
1803 const char* const autocomplete_attribute; | 1803 const char* const autocomplete_attribute; |
1804 } test_fields[] = {{"country code", "country_code", 1, "tel-country-code"}, | 1804 } test_fields[] = {{"country code", "country_code", 1, "tel-country-code"}, |
1805 {"area code", "area_code", 3, "tel-area-code"}, | 1805 {"area code", "area_code", 3, "tel-area-code"}, |
1806 {"phone", "phone_prefix", 3, "tel-local-prefix"}, | 1806 {"phone", "phone_prefix", 3, "tel-local-prefix"}, |
1807 {"-", "phone_suffix", 4, "tel-local-suffix"}, | 1807 {"-", "phone_suffix", 4, "tel-local-suffix"}, |
1808 {"Phone Extension", "ext", 5, "tel-extension"}}; | 1808 {"Phone Extension", "ext", 5, "tel-extension"}}; |
1809 | 1809 |
1810 FormFieldData field; | 1810 FormFieldData field; |
1811 for (const auto& test_field : test_fields) { | 1811 for (size_t i = 0; i < arraysize(test_fields); ++i) { |
1812 test::CreateTestFormField( | 1812 test::CreateTestFormField( |
1813 test_field.label, test_field.name, "", "text", &field); | 1813 test_fields[i].label, test_fields[i].name, "", "text", &field); |
1814 field.max_length = test_field.max_length; | 1814 field.max_length = test_fields[i].max_length; |
1815 field.autocomplete_attribute = std::string(); | 1815 field.autocomplete_attribute = std::string(); |
1816 form.fields.push_back(field); | 1816 form.fields.push_back(field); |
1817 } | 1817 } |
1818 | 1818 |
1819 std::vector<FormData> forms(1, form); | 1819 std::vector<FormData> forms(1, form); |
1820 FormsSeen(forms); | 1820 FormsSeen(forms); |
1821 | 1821 |
1822 AutofillProfile* profile = new AutofillProfile; | 1822 AutofillProfile* profile = new AutofillProfile; |
1823 profile->set_guid("00000000-0000-0000-0000-000000000104"); | 1823 profile->set_guid("00000000-0000-0000-0000-000000000104"); |
1824 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800FLOWERS")); | 1824 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800FLOWERS")); |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2780 } test_fields[] = { | 2780 } test_fields[] = { |
2781 { "country code", "country_code", 1, "tel-country-code" }, | 2781 { "country code", "country_code", 1, "tel-country-code" }, |
2782 { "area code", "area_code", 3, "tel-area-code" }, | 2782 { "area code", "area_code", 3, "tel-area-code" }, |
2783 { "phone", "phone_prefix", 3, "tel-local-prefix" }, | 2783 { "phone", "phone_prefix", 3, "tel-local-prefix" }, |
2784 { "-", "phone_suffix", 4, "tel-local-suffix" }, | 2784 { "-", "phone_suffix", 4, "tel-local-suffix" }, |
2785 { "Phone Extension", "ext", 3, "tel-extension" } | 2785 { "Phone Extension", "ext", 3, "tel-extension" } |
2786 }; | 2786 }; |
2787 | 2787 |
2788 FormFieldData field; | 2788 FormFieldData field; |
2789 const size_t default_max_length = field.max_length; | 2789 const size_t default_max_length = field.max_length; |
2790 for (const auto& test_field : test_fields) { | 2790 for (size_t i = 0; i < arraysize(test_fields); ++i) { |
2791 test::CreateTestFormField( | 2791 test::CreateTestFormField( |
2792 test_field.label, test_field.name, "", "text", &field); | 2792 test_fields[i].label, test_fields[i].name, "", "text", &field); |
2793 field.max_length = test_field.max_length; | 2793 field.max_length = test_fields[i].max_length; |
2794 field.autocomplete_attribute = std::string(); | 2794 field.autocomplete_attribute = std::string(); |
2795 form_with_us_number_max_length.fields.push_back(field); | 2795 form_with_us_number_max_length.fields.push_back(field); |
2796 | 2796 |
2797 field.max_length = default_max_length; | 2797 field.max_length = default_max_length; |
2798 field.autocomplete_attribute = test_field.autocomplete_attribute; | 2798 field.autocomplete_attribute = test_fields[i].autocomplete_attribute; |
2799 form_with_autocompletetype.fields.push_back(field); | 2799 form_with_autocompletetype.fields.push_back(field); |
2800 } | 2800 } |
2801 | 2801 |
2802 std::vector<FormData> forms; | 2802 std::vector<FormData> forms; |
2803 forms.push_back(form_with_us_number_max_length); | 2803 forms.push_back(form_with_us_number_max_length); |
2804 forms.push_back(form_with_autocompletetype); | 2804 forms.push_back(form_with_autocompletetype); |
2805 FormsSeen(forms); | 2805 FormsSeen(forms); |
2806 | 2806 |
2807 // We should be able to fill prefix and suffix fields for US numbers. | 2807 // We should be able to fill prefix and suffix fields for US numbers. |
2808 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( | 2808 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( |
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4181 FormData form; | 4181 FormData form; |
4182 form.name = ASCIIToUTF16("MyForm"); | 4182 form.name = ASCIIToUTF16("MyForm"); |
4183 form.origin = GURL("http://myform.com/form.html"); | 4183 form.origin = GURL("http://myform.com/form.html"); |
4184 form.action = GURL("http://myform.com/submit.html"); | 4184 form.action = GURL("http://myform.com/submit.html"); |
4185 | 4185 |
4186 struct { | 4186 struct { |
4187 const char* label; | 4187 const char* label; |
4188 const char* name; | 4188 const char* name; |
4189 const char* value; | 4189 const char* value; |
4190 ServerFieldType expected_field_type; | 4190 ServerFieldType expected_field_type; |
4191 } test_fields[] = { | 4191 } fields[] = { |
4192 {"Card number", "1", "4234-5678-9012-3456", CREDIT_CARD_NUMBER}, | 4192 {"Card number", "1", "4234-5678-9012-3456", CREDIT_CARD_NUMBER}, |
4193 {"Card verification code", "2", "123", CREDIT_CARD_VERIFICATION_CODE}, | 4193 {"Card verification code", "2", "123", CREDIT_CARD_VERIFICATION_CODE}, |
4194 {"expiration date", "3", "04/2020", CREDIT_CARD_EXP_4_DIGIT_YEAR}, | 4194 {"expiration date", "3", "04/2020", CREDIT_CARD_EXP_4_DIGIT_YEAR}, |
4195 }; | 4195 }; |
4196 | 4196 |
4197 for (const auto& test_field : test_fields) { | 4197 for (size_t i = 0; i < arraysize(fields); ++i) { |
4198 FormFieldData field; | 4198 FormFieldData field; |
4199 test::CreateTestFormField(test_field.label, test_field.name, | 4199 test::CreateTestFormField(fields[i].label, fields[i].name, fields[i].value, |
4200 test_field.value, "text", &field); | 4200 "text", &field); |
4201 form.fields.push_back(field); | 4201 form.fields.push_back(field); |
4202 } | 4202 } |
4203 | 4203 |
4204 std::vector<FormData> forms(1, form); | 4204 std::vector<FormData> forms(1, form); |
4205 FormsSeen(forms); | 4205 FormsSeen(forms); |
4206 FormSubmitted(form); | 4206 FormSubmitted(form); |
4207 | 4207 |
4208 EXPECT_EQ(form.fields.size(), form_seen_by_ahm.fields.size()); | 4208 EXPECT_EQ(form.fields.size(), form_seen_by_ahm.fields.size()); |
4209 ASSERT_EQ(arraysize(test_fields), form_seen_by_ahm.fields.size()); | 4209 ASSERT_EQ(arraysize(fields), form_seen_by_ahm.fields.size()); |
4210 for (size_t i = 0; i < arraysize(test_fields); ++i) { | 4210 for (size_t i = 0; i < arraysize(fields); ++i) { |
4211 EXPECT_EQ( | 4211 EXPECT_EQ(form_seen_by_ahm.fields[i].should_autocomplete, |
4212 form_seen_by_ahm.fields[i].should_autocomplete, | 4212 fields[i].expected_field_type != CREDIT_CARD_VERIFICATION_CODE); |
4213 test_fields[i].expected_field_type != CREDIT_CARD_VERIFICATION_CODE); | |
4214 } | 4213 } |
4215 } | 4214 } |
4216 | 4215 |
4217 TEST_F(AutofillManagerTest, DontOfferToSavePaymentsCard) { | 4216 TEST_F(AutofillManagerTest, DontOfferToSavePaymentsCard) { |
4218 FormData form; | 4217 FormData form; |
4219 CreditCard card; | 4218 CreditCard card; |
4220 PrepareForRealPanResponse(&form, &card); | 4219 PrepareForRealPanResponse(&form, &card); |
4221 | 4220 |
4222 // Manually fill out |form| so we can use it in OnFormSubmitted. | 4221 // Manually fill out |form| so we can use it in OnFormSubmitted. |
4223 for (size_t i = 0; i < form.fields.size(); ++i) { | 4222 for (size_t i = 0; i < form.fields.size(); ++i) { |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5215 FormsSeen(mixed_forms); | 5214 FormsSeen(mixed_forms); |
5216 | 5215 |
5217 // Suggestions should always be displayed. | 5216 // Suggestions should always be displayed. |
5218 for (const FormFieldData& field : mixed_form.fields) { | 5217 for (const FormFieldData& field : mixed_form.fields) { |
5219 GetAutofillSuggestions(mixed_form, field); | 5218 GetAutofillSuggestions(mixed_form, field); |
5220 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5219 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
5221 } | 5220 } |
5222 } | 5221 } |
5223 | 5222 |
5224 } // namespace autofill | 5223 } // namespace autofill |
OLD | NEW |