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

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: Nits 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 // Credit card related field. 259 // Credit card related field.
260 field.set_heuristic_type(CREDIT_CARD_NUMBER); 260 field.set_heuristic_type(CREDIT_CARD_NUMBER);
261 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US", 261 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US",
262 "en-US", &field); 262 "en-US", &field);
263 263
264 // Verify that the field is filled. 264 // Verify that the field is filled.
265 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value); 265 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value);
266 } 266 }
267 267
268 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for
269 // phone numbers with 10 or 11 digits.
268 TEST_F(AutofillFieldTest, FillPhoneNumber) { 270 TEST_F(AutofillFieldTest, FillPhoneNumber) {
269 AutofillField field; 271 typedef struct {
270 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); 272 HtmlFieldType field_type;
273 size_t field_max_length;
274 std::string value_to_fill;
275 std::string expected_value;
271 276
272 // Fill with a non-phone number; should fill normally. 277 } TestCase;
273 AutofillField::FillFormField(
274 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field);
275 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value);
276 278
277 // Fill with a phone number; should fill just the prefix. 279 TestCase test_cases[] = {
278 AutofillField::FillFormField( 280 // Filling a phone type field with text should fill the text as is.
279 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); 281 {HTML_TYPE_TEL, /* default value */ 0, "Oh hai", "Oh hai"},
280 EXPECT_EQ(ASCIIToUTF16("555"), field.value); 282 // Filling a prefix type field with a phone number of 7 digits should just
283 // fill the prefix.
284 {HTML_TYPE_TEL_LOCAL_PREFIX, /* default value */ 0, "5551234", "555"},
285 // Filling a suffix type field with a phone number of 7 digits should just
286 // fill the suffix.
287 {HTML_TYPE_TEL_LOCAL_SUFFIX, /* default value */ 0, "5551234", "1234"},
288 // Filling a phone type field with a max length of 3 with a phone number
289 // of
290 // 7 digits should fill only the prefix.
291 {HTML_TYPE_TEL, 3, "5551234", "555"},
292 // Filling a phone type field with a max length of 4 with a phone number
293 // of
294 // 7 digits should fill only the suffix.
295 {HTML_TYPE_TEL, 4, "5551234", "1234"},
296 // Filling a phone type field with a max length of 10 with a phone number
297 // including the country code should fill the phone number without the
298 // country code.
299 {HTML_TYPE_TEL, 10, "15141254578", "5141254578"},
300 // Filling a phone type field with a max length of 5 with a phone number
301 // should fill with the last 5 digits of that phone number.
302 {HTML_TYPE_TEL, 5, "5141254578", "54578"}};
281 303
282 // Now reset the type, and set a max-length instead. 304 for (TestCase test_case : test_cases) {
283 field.SetHtmlType(HTML_TYPE_UNSPECIFIED, HtmlFieldMode()); 305 AutofillField field;
284 field.set_heuristic_type(PHONE_HOME_NUMBER); 306 field.SetHtmlType(test_case.field_type, HtmlFieldMode());
285 field.max_length = 4; 307 field.max_length = test_case.field_max_length;
286 308
287 // Fill with a phone-number; should fill just the suffix. 309 AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill),
288 AutofillField::FillFormField( 310 "en-US", "en-US", &field);
289 field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); 311 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value);
290 EXPECT_EQ(ASCIIToUTF16("1234"), field.value); 312 }
291 } 313 }
292 314
293 TEST_F(AutofillFieldTest, FillSelectControlByValue) { 315 TEST_F(AutofillFieldTest, FillSelectControlByValue) {
294 std::vector<const char*> kOptions = { 316 std::vector<const char*> kOptions = {
295 "Eenie", "Meenie", "Miney", "Mo", 317 "Eenie", "Meenie", "Miney", "Mo",
296 }; 318 };
297 AutofillField field(GenerateSelectFieldWithOptions(kOptions, kOptions.size()), 319 AutofillField field(GenerateSelectFieldWithOptions(kOptions, kOptions.size()),
298 base::string16()); 320 base::string16());
299 321
300 // Set semantically empty contents for each option, so that only the values 322 // Set semantically empty contents for each option, so that only the values
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 index = kBadIndex; 832 index = kBadIndex;
811 ret = AutofillField::FindValueInSelectControl( 833 ret = AutofillField::FindValueInSelectControl(
812 field, UTF8ToUTF16("NoVaScOtIa"), &index); 834 field, UTF8ToUTF16("NoVaScOtIa"), &index);
813 EXPECT_TRUE(ret); 835 EXPECT_TRUE(ret);
814 EXPECT_EQ(2U, index); 836 EXPECT_EQ(2U, index);
815 } 837 }
816 } 838 }
817 839
818 } // namespace 840 } // namespace
819 } // namespace autofill 841 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_field.cc ('k') | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698