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/phone_field.h" | 5 #include "components/autofill/core/browser/phone_field.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 TEST_F(PhoneFieldTest, NonParse) { | 72 TEST_F(PhoneFieldTest, NonParse) { |
73 list_.push_back(new AutofillField); | 73 list_.push_back(new AutofillField); |
74 AutofillScanner scanner(list_.get()); | 74 AutofillScanner scanner(list_.get()); |
75 field_ = Parse(&scanner); | 75 field_ = Parse(&scanner); |
76 ASSERT_EQ(nullptr, field_.get()); | 76 ASSERT_EQ(nullptr, field_.get()); |
77 } | 77 } |
78 | 78 |
79 TEST_F(PhoneFieldTest, ParseOneLinePhone) { | 79 TEST_F(PhoneFieldTest, ParseOneLinePhone) { |
80 FormFieldData field; | 80 FormFieldData field; |
81 | 81 |
82 for (size_t i = 0; i < arraysize(kFieldTypes); ++i) { | 82 for (const char* field_type : kFieldTypes) { |
83 Clear(); | 83 Clear(); |
84 | 84 |
85 field.form_control_type = kFieldTypes[i]; | 85 field.form_control_type = field_type; |
86 field.label = ASCIIToUTF16("Phone"); | 86 field.label = ASCIIToUTF16("Phone"); |
87 field.name = ASCIIToUTF16("phone"); | 87 field.name = ASCIIToUTF16("phone"); |
88 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone1"))); | 88 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone1"))); |
89 | 89 |
90 AutofillScanner scanner(list_.get()); | 90 AutofillScanner scanner(list_.get()); |
91 field_ = Parse(&scanner); | 91 field_ = Parse(&scanner); |
92 ASSERT_NE(nullptr, field_.get()); | 92 ASSERT_NE(nullptr, field_.get()); |
93 field_->AddClassifications(&field_candidates_map_); | 93 field_->AddClassifications(&field_candidates_map_); |
94 CheckField("phone1", PHONE_HOME_WHOLE_NUMBER); | 94 CheckField("phone1", PHONE_HOME_WHOLE_NUMBER); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 TEST_F(PhoneFieldTest, ParseTwoLinePhone) { | 98 TEST_F(PhoneFieldTest, ParseTwoLinePhone) { |
99 FormFieldData field; | 99 FormFieldData field; |
100 | 100 |
101 for (size_t i = 0; i < arraysize(kFieldTypes); ++i) { | 101 for (const char* field_type : kFieldTypes) { |
102 Clear(); | 102 Clear(); |
103 | 103 |
104 field.form_control_type = kFieldTypes[i]; | 104 field.form_control_type = field_type; |
105 field.label = ASCIIToUTF16("Area Code"); | 105 field.label = ASCIIToUTF16("Area Code"); |
106 field.name = ASCIIToUTF16("area code"); | 106 field.name = ASCIIToUTF16("area code"); |
107 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1"))); | 107 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1"))); |
108 | 108 |
109 field.label = ASCIIToUTF16("Phone"); | 109 field.label = ASCIIToUTF16("Phone"); |
110 field.name = ASCIIToUTF16("phone"); | 110 field.name = ASCIIToUTF16("phone"); |
111 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone2"))); | 111 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone2"))); |
112 | 112 |
113 AutofillScanner scanner(list_.get()); | 113 AutofillScanner scanner(list_.get()); |
114 field_ = Parse(&scanner); | 114 field_ = Parse(&scanner); |
115 ASSERT_NE(nullptr, field_.get()); | 115 ASSERT_NE(nullptr, field_.get()); |
116 field_->AddClassifications(&field_candidates_map_); | 116 field_->AddClassifications(&field_candidates_map_); |
117 CheckField("areacode1", PHONE_HOME_CITY_CODE); | 117 CheckField("areacode1", PHONE_HOME_CITY_CODE); |
118 CheckField("phone2", PHONE_HOME_NUMBER); | 118 CheckField("phone2", PHONE_HOME_NUMBER); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 TEST_F(PhoneFieldTest, ThreePartPhoneNumber) { | 122 TEST_F(PhoneFieldTest, ThreePartPhoneNumber) { |
123 // Phone in format <field> - <field> - <field> could be either | 123 // Phone in format <field> - <field> - <field> could be either |
124 // <area code> - <prefix> - <suffix>, or | 124 // <area code> - <prefix> - <suffix>, or |
125 // <country code> - <area code> - <phone>. The only distinguishing feature is | 125 // <country code> - <area code> - <phone>. The only distinguishing feature is |
126 // size: <prefix> is no bigger than 3 characters, and <suffix> is no bigger | 126 // size: <prefix> is no bigger than 3 characters, and <suffix> is no bigger |
127 // than 4. | 127 // than 4. |
128 FormFieldData field; | 128 FormFieldData field; |
129 | 129 |
130 for (size_t i = 0; i < arraysize(kFieldTypes); ++i) { | 130 for (const char* field_type : kFieldTypes) { |
131 Clear(); | 131 Clear(); |
132 | 132 |
133 field.form_control_type = kFieldTypes[i]; | 133 field.form_control_type = field_type; |
134 field.label = ASCIIToUTF16("Phone:"); | 134 field.label = ASCIIToUTF16("Phone:"); |
135 field.name = ASCIIToUTF16("dayphone1"); | 135 field.name = ASCIIToUTF16("dayphone1"); |
136 field.max_length = 0; | 136 field.max_length = 0; |
137 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1"))); | 137 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1"))); |
138 | 138 |
139 field.label = ASCIIToUTF16("-"); | 139 field.label = ASCIIToUTF16("-"); |
140 field.name = ASCIIToUTF16("dayphone2"); | 140 field.name = ASCIIToUTF16("dayphone2"); |
141 field.max_length = 3; | 141 field.max_length = 3; |
142 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2"))); | 142 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2"))); |
143 | 143 |
(...skipping 17 matching lines...) Expand all Loading... |
161 EXPECT_TRUE(base::ContainsKey(field_candidates_map_, ASCIIToUTF16("ext4"))); | 161 EXPECT_TRUE(base::ContainsKey(field_candidates_map_, ASCIIToUTF16("ext4"))); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 // This scenario of explicitly labeled "prefix" and "suffix" phone numbers | 165 // This scenario of explicitly labeled "prefix" and "suffix" phone numbers |
166 // encountered in http://crbug.com/40694 with page | 166 // encountered in http://crbug.com/40694 with page |
167 // https://www.wrapables.com/jsp/Signup.jsp. | 167 // https://www.wrapables.com/jsp/Signup.jsp. |
168 TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix) { | 168 TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix) { |
169 FormFieldData field; | 169 FormFieldData field; |
170 | 170 |
171 for (size_t i = 0; i < arraysize(kFieldTypes); ++i) { | 171 for (const char* field_type : kFieldTypes) { |
172 Clear(); | 172 Clear(); |
173 | 173 |
174 field.form_control_type = kFieldTypes[i]; | 174 field.form_control_type = field_type; |
175 field.label = ASCIIToUTF16("Phone:"); | 175 field.label = ASCIIToUTF16("Phone:"); |
176 field.name = ASCIIToUTF16("area"); | 176 field.name = ASCIIToUTF16("area"); |
177 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1"))); | 177 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1"))); |
178 | 178 |
179 field.label = base::string16(); | 179 field.label = base::string16(); |
180 field.name = ASCIIToUTF16("prefix"); | 180 field.name = ASCIIToUTF16("prefix"); |
181 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2"))); | 181 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2"))); |
182 | 182 |
183 field.label = base::string16(); | 183 field.label = base::string16(); |
184 field.name = ASCIIToUTF16("suffix"); | 184 field.name = ASCIIToUTF16("suffix"); |
185 list_.push_back(new AutofillField(field, ASCIIToUTF16("suffix3"))); | 185 list_.push_back(new AutofillField(field, ASCIIToUTF16("suffix3"))); |
186 | 186 |
187 AutofillScanner scanner(list_.get()); | 187 AutofillScanner scanner(list_.get()); |
188 field_ = Parse(&scanner); | 188 field_ = Parse(&scanner); |
189 ASSERT_NE(nullptr, field_.get()); | 189 ASSERT_NE(nullptr, field_.get()); |
190 field_->AddClassifications(&field_candidates_map_); | 190 field_->AddClassifications(&field_candidates_map_); |
191 CheckField("areacode1", PHONE_HOME_CITY_CODE); | 191 CheckField("areacode1", PHONE_HOME_CITY_CODE); |
192 CheckField("prefix2", PHONE_HOME_NUMBER); | 192 CheckField("prefix2", PHONE_HOME_NUMBER); |
193 CheckField("suffix3", PHONE_HOME_NUMBER); | 193 CheckField("suffix3", PHONE_HOME_NUMBER); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2) { | 197 TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2) { |
198 FormFieldData field; | 198 FormFieldData field; |
199 | 199 |
200 for (size_t i = 0; i < arraysize(kFieldTypes); ++i) { | 200 for (const char* field_type : kFieldTypes) { |
201 Clear(); | 201 Clear(); |
202 | 202 |
203 field.form_control_type = kFieldTypes[i]; | 203 field.form_control_type = field_type; |
204 field.label = ASCIIToUTF16("("); | 204 field.label = ASCIIToUTF16("("); |
205 field.name = ASCIIToUTF16("phone1"); | 205 field.name = ASCIIToUTF16("phone1"); |
206 field.max_length = 3; | 206 field.max_length = 3; |
207 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone1"))); | 207 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone1"))); |
208 | 208 |
209 field.label = ASCIIToUTF16(")"); | 209 field.label = ASCIIToUTF16(")"); |
210 field.name = ASCIIToUTF16("phone2"); | 210 field.name = ASCIIToUTF16("phone2"); |
211 field.max_length = 3; | 211 field.max_length = 3; |
212 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone2"))); | 212 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone2"))); |
213 | 213 |
(...skipping 10 matching lines...) Expand all Loading... |
224 CheckField("phone2", PHONE_HOME_NUMBER); | 224 CheckField("phone2", PHONE_HOME_NUMBER); |
225 CheckField("phone3", PHONE_HOME_NUMBER); | 225 CheckField("phone3", PHONE_HOME_NUMBER); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) { | 229 TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) { |
230 // Phone in format <country code>:3 - <city and number>:10 | 230 // Phone in format <country code>:3 - <city and number>:10 |
231 // The |maxlength| is considered, otherwise it's too broad. | 231 // The |maxlength| is considered, otherwise it's too broad. |
232 FormFieldData field; | 232 FormFieldData field; |
233 | 233 |
234 for (size_t i = 0; i < arraysize(kFieldTypes); ++i) { | 234 for (const char* field_type : kFieldTypes) { |
235 Clear(); | 235 Clear(); |
236 | 236 |
237 field.form_control_type = kFieldTypes[i]; | 237 field.form_control_type = field_type; |
238 field.label = ASCIIToUTF16("Phone Number"); | 238 field.label = ASCIIToUTF16("Phone Number"); |
239 field.name = ASCIIToUTF16("CountryCode"); | 239 field.name = ASCIIToUTF16("CountryCode"); |
240 field.max_length = 3; | 240 field.max_length = 3; |
241 list_.push_back(new AutofillField(field, ASCIIToUTF16("country"))); | 241 list_.push_back(new AutofillField(field, ASCIIToUTF16("country"))); |
242 | 242 |
243 field.label = ASCIIToUTF16("Phone Number"); | 243 field.label = ASCIIToUTF16("Phone Number"); |
244 field.name = ASCIIToUTF16("PhoneNumber"); | 244 field.name = ASCIIToUTF16("PhoneNumber"); |
245 field.max_length = 10; | 245 field.max_length = 10; |
246 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone"))); | 246 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone"))); |
247 | 247 |
248 AutofillScanner scanner(list_.get()); | 248 AutofillScanner scanner(list_.get()); |
249 field_ = Parse(&scanner); | 249 field_ = Parse(&scanner); |
250 ASSERT_NE(nullptr, field_.get()); | 250 ASSERT_NE(nullptr, field_.get()); |
251 field_->AddClassifications(&field_candidates_map_); | 251 field_->AddClassifications(&field_candidates_map_); |
252 CheckField("country", PHONE_HOME_COUNTRY_CODE); | 252 CheckField("country", PHONE_HOME_COUNTRY_CODE); |
253 CheckField("phone", PHONE_HOME_CITY_AND_NUMBER); | 253 CheckField("phone", PHONE_HOME_CITY_AND_NUMBER); |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 } // namespace autofill | 257 } // namespace autofill |
OLD | NEW |