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

Side by Side Diff: components/autofill/core/browser/autofill_field_unittest.cc

Issue 1639563002: [Autofill] Fill from the last digits when filling a phone number with a maximum length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 11 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 252
253 // Credit card related field. 253 // Credit card related field.
254 field.set_heuristic_type(CREDIT_CARD_NUMBER); 254 field.set_heuristic_type(CREDIT_CARD_NUMBER);
255 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US", 255 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US",
256 "en-US", &field); 256 "en-US", &field);
257 257
258 // Verify that the field is filled. 258 // Verify that the field is filled.
259 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value); 259 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value);
260 } 260 }
261 261
262 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for
263 // phone numbers with 10 or 11 digits.
262 TEST(AutofillFieldTest, FillPhoneNumber) { 264 TEST(AutofillFieldTest, FillPhoneNumber) {
263 AutofillField field; 265 typedef struct {
264 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); 266 HtmlFieldType field_type;
267 size_t field_max_length;
268 std::string value_to_fill;
269 std::string expected_value;
265 270
266 // Fill with a non-phone number; should fill normally. 271 } TestCase;
267 AutofillField::FillFormField(
268 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field);
269 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value);
270 272
271 // Fill with a phone number; should fill just the prefix. 273 TestCase test_cases[] = {
272 AutofillField::FillFormField( 274 // Filling a phone type field with text should fill the text as is.
273 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); 275 {HTML_TYPE_TEL, /* default value */ 0, "Oh hai", "Oh hai"},
274 EXPECT_EQ(ASCIIToUTF16("555"), field.value); 276 // Filling a prefix type field with a phone number of 7 digits should just
277 // fill the prefix.
278 {HTML_TYPE_TEL_LOCAL_PREFIX, /* default value */ 0, "5551234", "555"},
279 // Filling a suffix type field with a phone number of 7 digits should just
280 // fill the suffix.
281 {HTML_TYPE_TEL_LOCAL_SUFFIX, /* default value */ 0, "5551234", "1234"},
282 // Filling a phone type field with a max length of 3 with a phone number
283 // of
284 // 7 digits should fill only the prefix.
285 {HTML_TYPE_TEL, 3, "5551234", "555"},
286 // Filling a phone type field with a max length of 4 with a phone number
287 // of
288 // 7 digits should fill only the suffix.
289 {HTML_TYPE_TEL, 4, "5551234", "1234"},
290 // Filling a phone type field with a max length of 10 with a phone number
291 // including the country code should fill the phone number without the
292 // country code.
293 {HTML_TYPE_TEL, 10, "15141254578", "5141254578"},
294 // Filling a phone type field with a max length of 5 with a phone number
295 // should fill with the last 5 digits of that phone number.
296 {HTML_TYPE_TEL, 5, "5141254578", "54578"}};
275 297
276 // Now reset the type, and set a max-length instead. 298 for (TestCase test_case : test_cases) {
277 field.SetHtmlType(HTML_TYPE_UNSPECIFIED, HtmlFieldMode()); 299 AutofillField field;
278 field.set_heuristic_type(PHONE_HOME_NUMBER); 300 field.SetHtmlType(test_case.field_type, HtmlFieldMode());
279 field.max_length = 4; 301 field.max_length = test_case.field_max_length;
280 302
281 // Fill with a phone-number; should fill just the suffix. 303 AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill),
282 AutofillField::FillFormField( 304 "en-US", "en-US", &field);
283 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); 305 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value);
284 EXPECT_EQ(ASCIIToUTF16("1234"), field.value); 306 }
285 } 307 }
286 308
287 TEST(AutofillFieldTest, FillSelectControlByValue) { 309 TEST(AutofillFieldTest, FillSelectControlByValue) {
288 std::vector<const char*> kOptions = { 310 std::vector<const char*> kOptions = {
289 "Eenie", "Meenie", "Miney", "Mo", 311 "Eenie", "Meenie", "Miney", "Mo",
290 }; 312 };
291 AutofillField field(GenerateSelectFieldWithOptions(kOptions, kOptions.size()), 313 AutofillField field(GenerateSelectFieldWithOptions(kOptions, kOptions.size()),
292 base::string16()); 314 base::string16());
293 315
294 // Set semantically empty contents for each option, so that only the values 316 // Set semantically empty contents for each option, so that only the values
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 index = kBadIndex; 823 index = kBadIndex;
802 ret = AutofillField::FindValueInSelectControl( 824 ret = AutofillField::FindValueInSelectControl(
803 field, UTF8ToUTF16("NoVaScOtIa"), &index); 825 field, UTF8ToUTF16("NoVaScOtIa"), &index);
804 EXPECT_TRUE(ret); 826 EXPECT_TRUE(ret);
805 EXPECT_EQ(2U, index); 827 EXPECT_EQ(2U, index);
806 } 828 }
807 } 829 }
808 830
809 } // namespace 831 } // namespace
810 } // namespace autofill 832 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698