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_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/autofill_type.h" | 10 #include "components/autofill/core/browser/autofill_type.h" |
11 #include "components/autofill/core/browser/field_types.h" | 11 #include "components/autofill/core/browser/field_types.h" |
| 12 #include "components/autofill/core/common/autofill_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 using base::ASCIIToUTF16; | 15 using base::ASCIIToUTF16; |
15 using base::UTF8ToUTF16; | 16 using base::UTF8ToUTF16; |
16 | 17 |
17 namespace autofill { | 18 namespace autofill { |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Returns a FormFieldData object corresponding to a <select> field populated | 21 // Returns a FormFieldData object corresponding to a <select> field populated |
21 // with the given |options|. | 22 // with the given |options|. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // Only server type is set. | 123 // Only server type is set. |
123 field.set_heuristic_type(UNKNOWN_TYPE); | 124 field.set_heuristic_type(UNKNOWN_TYPE); |
124 field.set_server_type(NAME_LAST); | 125 field.set_server_type(NAME_LAST); |
125 EXPECT_TRUE(field.IsFieldFillable()); | 126 EXPECT_TRUE(field.IsFieldFillable()); |
126 | 127 |
127 // Both types set. | 128 // Both types set. |
128 field.set_heuristic_type(NAME_FIRST); | 129 field.set_heuristic_type(NAME_FIRST); |
129 field.set_server_type(NAME_LAST); | 130 field.set_server_type(NAME_LAST); |
130 EXPECT_TRUE(field.IsFieldFillable()); | 131 EXPECT_TRUE(field.IsFieldFillable()); |
131 | 132 |
132 // Field has autocomplete="off" set. Chrome ignores the attribute. | 133 // Field has autocomplete="off" set. Since autofill was able to make a |
| 134 // prediction, it is still considered a fillable field. |
133 field.should_autocomplete = false; | 135 field.should_autocomplete = false; |
134 EXPECT_TRUE(field.IsFieldFillable()); | 136 EXPECT_TRUE(field.IsFieldFillable()); |
135 } | 137 } |
136 | 138 |
| 139 // Verify that non credit card related fields with the autocomplete attribute |
| 140 // set to off don't get filled on desktop. |
| 141 TEST(AutofillFieldTest, FillFormField_AutocompleteOff_AddressField) { |
| 142 AutofillField field; |
| 143 field.should_autocomplete = false; |
| 144 |
| 145 // Non credit card related field. |
| 146 AutofillField::FillFormField(field, ASCIIToUTF16("Test"), "en-US", "en-US", |
| 147 &field); |
| 148 |
| 149 // Verifiy that the field is filled on mobile but not on desktop. |
| 150 if (IsDesktopPlatform()) { |
| 151 EXPECT_EQ(base::string16(), field.value); |
| 152 } else { |
| 153 EXPECT_EQ(ASCIIToUTF16("Test"), field.value); |
| 154 } |
| 155 } |
| 156 |
| 157 // Verify that credit card related fields with the autocomplete attribute |
| 158 // set to off get filled. |
| 159 TEST(AutofillFieldTest, FillFormField_AutocompleteOff_CreditCardField) { |
| 160 AutofillField field; |
| 161 field.should_autocomplete = false; |
| 162 |
| 163 // Credit card related field. |
| 164 field.set_heuristic_type(CREDIT_CARD_NUMBER); |
| 165 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US", |
| 166 "en-US", &field); |
| 167 |
| 168 // Verify that the field is filled. |
| 169 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value); |
| 170 } |
| 171 |
137 TEST(AutofillFieldTest, FillPhoneNumber) { | 172 TEST(AutofillFieldTest, FillPhoneNumber) { |
138 AutofillField field; | 173 AutofillField field; |
139 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); | 174 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); |
140 | 175 |
141 // Fill with a non-phone number; should fill normally. | 176 // Fill with a non-phone number; should fill normally. |
142 AutofillField::FillFormField( | 177 AutofillField::FillFormField( |
143 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field); | 178 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field); |
144 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); | 179 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); |
145 | 180 |
146 // Fill with a phone number; should fill just the prefix. | 181 // Fill with a phone number; should fill just the prefix. |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 index = kBadIndex; | 724 index = kBadIndex; |
690 ret = AutofillField::FindValueInSelectControl( | 725 ret = AutofillField::FindValueInSelectControl( |
691 field, UTF8ToUTF16("NoVaScOtIa"), &index); | 726 field, UTF8ToUTF16("NoVaScOtIa"), &index); |
692 EXPECT_TRUE(ret); | 727 EXPECT_TRUE(ret); |
693 EXPECT_EQ(2U, index); | 728 EXPECT_EQ(2U, index); |
694 } | 729 } |
695 } | 730 } |
696 | 731 |
697 } // namespace | 732 } // namespace |
698 } // namespace autofill | 733 } // namespace autofill |
OLD | NEW |