Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Side by Side Diff: chrome/browser/autofill/phone_field_unittest.cc

Issue 7892048: Autofill: Remove fax number completely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/phone_field.cc ('k') | chrome/browser/autofill/phone_number.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/autofill_field.h" 8 #include "chrome/browser/autofill/autofill_field.h"
9 #include "chrome/browser/autofill/autofill_scanner.h" 9 #include "chrome/browser/autofill/autofill_scanner.h"
10 #include "chrome/browser/autofill/phone_field.h" 10 #include "chrome/browser/autofill/phone_field.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end()); 190 field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
191 EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("phone1")]); 191 EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("phone1")]);
192 ASSERT_TRUE( 192 ASSERT_TRUE(
193 field_type_map_.find(ASCIIToUTF16("phone2")) != field_type_map_.end()); 193 field_type_map_.find(ASCIIToUTF16("phone2")) != field_type_map_.end());
194 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone2")]); 194 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone2")]);
195 ASSERT_TRUE( 195 ASSERT_TRUE(
196 field_type_map_.find(ASCIIToUTF16("phone3")) != field_type_map_.end()); 196 field_type_map_.find(ASCIIToUTF16("phone3")) != field_type_map_.end());
197 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone3")]); 197 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone3")]);
198 } 198 }
199 199
200 TEST_F(PhoneFieldTest, ParseOneLineFax) {
201 webkit_glue::FormField field;
202 field.form_control_type = ASCIIToUTF16("text");
203
204 field.label = ASCIIToUTF16("Fax");
205 field.name = ASCIIToUTF16("fax");
206 list_.push_back(new AutofillField(field, ASCIIToUTF16("fax1")));
207
208 AutofillScanner scanner(list_.get());
209 field_.reset(Parse(&scanner));
210 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
211 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
212 ASSERT_TRUE(
213 field_type_map_.find(ASCIIToUTF16("fax1")) != field_type_map_.end());
214 EXPECT_EQ(PHONE_FAX_WHOLE_NUMBER, field_type_map_[ASCIIToUTF16("fax1")]);
215 }
216
217 TEST_F(PhoneFieldTest, ParseTwoLineFax) {
218 webkit_glue::FormField field;
219 field.form_control_type = ASCIIToUTF16("text");
220
221 field.label = ASCIIToUTF16("Area Code");
222 field.name = ASCIIToUTF16("area code");
223 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1")));
224
225 field.label = ASCIIToUTF16("Fax");
226 field.name = ASCIIToUTF16("fax");
227 list_.push_back(new AutofillField(field, ASCIIToUTF16("fax2")));
228
229 AutofillScanner scanner(list_.get());
230 field_.reset(Parse(&scanner));
231 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
232 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
233 ASSERT_TRUE(
234 field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
235 // It should be FAX, based on the other phone in the group.
236 EXPECT_EQ(PHONE_FAX_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
237 ASSERT_TRUE(
238 field_type_map_.find(ASCIIToUTF16("fax2")) != field_type_map_.end());
239 EXPECT_EQ(PHONE_FAX_NUMBER, field_type_map_[ASCIIToUTF16("fax2")]);
240 }
241
242 TEST_F(PhoneFieldTest, ThreePartFaxNumberPrefixSuffix) {
243 webkit_glue::FormField field;
244 field.form_control_type = ASCIIToUTF16("text");
245
246 field.label = ASCIIToUTF16("Fax:");
247 field.name = ASCIIToUTF16("area");
248 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1")));
249
250 field.label = string16();
251 field.name = ASCIIToUTF16("prefix");
252 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2")));
253
254 field.label = string16();
255 field.name = ASCIIToUTF16("suffix");
256 list_.push_back(new AutofillField(field, ASCIIToUTF16("suffix3")));
257
258 AutofillScanner scanner(list_.get());
259 field_.reset(Parse(&scanner));
260 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
261 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
262 ASSERT_TRUE(
263 field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
264 EXPECT_EQ(PHONE_FAX_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
265 ASSERT_TRUE(
266 field_type_map_.find(ASCIIToUTF16("prefix2")) != field_type_map_.end());
267 EXPECT_EQ(PHONE_FAX_NUMBER, field_type_map_[ASCIIToUTF16("prefix2")]);
268 ASSERT_TRUE(
269 field_type_map_.find(ASCIIToUTF16("suffix3")) != field_type_map_.end());
270 EXPECT_EQ(PHONE_FAX_NUMBER, field_type_map_[ASCIIToUTF16("suffix3")]);
271 }
272
273 TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) { 200 TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) {
274 // Phone in format <country code>:3 - <city and number>:10 201 // Phone in format <country code>:3 - <city and number>:10
275 // The |maxlength| is considered, otherwise it's too broad. 202 // The |maxlength| is considered, otherwise it's too broad.
276 webkit_glue::FormField field; 203 webkit_glue::FormField field;
277 field.form_control_type = ASCIIToUTF16("text"); 204 field.form_control_type = ASCIIToUTF16("text");
278 205
279 field.label = ASCIIToUTF16("Phone Number"); 206 field.label = ASCIIToUTF16("Phone Number");
280 field.name = ASCIIToUTF16("CountryCode"); 207 field.name = ASCIIToUTF16("CountryCode");
281 field.max_length = 3; 208 field.max_length = 3;
282 list_.push_back(new AutofillField(field, ASCIIToUTF16("country"))); 209 list_.push_back(new AutofillField(field, ASCIIToUTF16("country")));
283 210
284 field.label = ASCIIToUTF16("Phone Number"); 211 field.label = ASCIIToUTF16("Phone Number");
285 field.name = ASCIIToUTF16("PhoneNumber"); 212 field.name = ASCIIToUTF16("PhoneNumber");
286 field.max_length = 10; 213 field.max_length = 10;
287 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone"))); 214 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone")));
288 215
289 AutofillScanner scanner(list_.get()); 216 AutofillScanner scanner(list_.get());
290 field_.reset(Parse(&scanner)); 217 field_.reset(Parse(&scanner));
291 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get()); 218 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
292 ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); 219 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
293 ASSERT_TRUE( 220 ASSERT_TRUE(
294 field_type_map_.find(ASCIIToUTF16("country")) != field_type_map_.end()); 221 field_type_map_.find(ASCIIToUTF16("country")) != field_type_map_.end());
295 EXPECT_EQ(PHONE_HOME_COUNTRY_CODE, field_type_map_[ASCIIToUTF16("country")]); 222 EXPECT_EQ(PHONE_HOME_COUNTRY_CODE, field_type_map_[ASCIIToUTF16("country")]);
296 ASSERT_TRUE( 223 ASSERT_TRUE(
297 field_type_map_.find(ASCIIToUTF16("phone")) != field_type_map_.end()); 224 field_type_map_.find(ASCIIToUTF16("phone")) != field_type_map_.end());
298 EXPECT_EQ(PHONE_HOME_CITY_AND_NUMBER, field_type_map_[ASCIIToUTF16("phone")]); 225 EXPECT_EQ(PHONE_HOME_CITY_AND_NUMBER, field_type_map_[ASCIIToUTF16("phone")]);
299 } 226 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_field.cc ('k') | chrome/browser/autofill/phone_number.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698