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

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

Issue 2029403003: [Autofill] Truncate expiration year based on prediction and max length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
« no previous file with comments | « components/autofill/core/browser/autofill_field.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 AutofillField field; 323 AutofillField field;
324 field.SetHtmlType(test_case.field_type, HtmlFieldMode()); 324 field.SetHtmlType(test_case.field_type, HtmlFieldMode());
325 field.max_length = test_case.field_max_length; 325 field.max_length = test_case.field_max_length;
326 326
327 AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill), 327 AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill),
328 "en-US", "en-US", &field); 328 "en-US", "en-US", &field);
329 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value); 329 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value);
330 } 330 }
331 } 331 }
332 332
333 TEST_F(AutofillFieldTest, FillExpirationYearInput) {
334 typedef struct {
335 HtmlFieldType field_type;
336 size_t field_max_length;
337 std::string value_to_fill;
338 std::string expected_value;
339
340 } TestCase;
341
342 TestCase test_cases[] = {
343 // A field predicted as a 2 digits expiration year should fill the last 2
344 // digits of the expiration year if the field has an unspecified max
345 // length (0) or if it's greater than 1.
346 {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, /* default value */ 0, "2023",
347 "23"},
348 {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, 2, "2023", "23"},
349 {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, 12, "2023", "23"},
350 // A field predicted as a 2 digits expiration year should fill the last
351 // digit of the expiration year if the field has a max length of 1.
352 {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, 1, "2023", "3"},
353 // A field predicted as a 4 digits expiration year should fill the 4
354 // digits of the expiration year if the field has an unspecified max
355 // length (0) or if it's greater than 3 .
356 {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, /* default value */ 0, "2023",
357 "2023"},
358 {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 4, "2023", "2023"},
359 {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 12, "2023", "2023"},
360 // A field predicted as a 4 digits expiration year should fill the last 2
361 // digits of the expiration year if the field has a max length of 2.
362 {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 2, "2023", "23"},
363 // A field predicted as a 4 digits expiration year should fill the last
364 // digit of the expiration year if the field has a max length of 1.
365 {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 1, "2023", "3"},
366 };
367
368 for (TestCase test_case : test_cases) {
369 AutofillField field;
370 field.form_control_type = "input";
371 field.SetHtmlType(test_case.field_type, HtmlFieldMode());
372 field.max_length = test_case.field_max_length;
373
374 AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill),
375 "en-US", "en-US", &field);
376 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value);
377 }
378 }
379
333 TEST_F(AutofillFieldTest, FillSelectControlByValue) { 380 TEST_F(AutofillFieldTest, FillSelectControlByValue) {
334 std::vector<const char*> kOptions = { 381 std::vector<const char*> kOptions = {
335 "Eenie", "Meenie", "Miney", "Mo", 382 "Eenie", "Meenie", "Miney", "Mo",
336 }; 383 };
337 384
338 AutofillField field; 385 AutofillField field;
339 test::CreateTestSelectField(kOptions, &field); 386 test::CreateTestSelectField(kOptions, &field);
340 387
341 // Set semantically empty contents for each option, so that only the values 388 // Set semantically empty contents for each option, so that only the values
342 // can be used for matching. 389 // can be used for matching.
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 bool has_filled = AutofillField::FillFormField( 944 bool has_filled = AutofillField::FillFormField(
898 field, ASCIIToUTF16(test_case.value_to_fill), "en-US", "en-US", &field); 945 field, ASCIIToUTF16(test_case.value_to_fill), "en-US", "en-US", &field);
899 946
900 EXPECT_EQ(test_case.should_fill, has_filled); 947 EXPECT_EQ(test_case.should_fill, has_filled);
901 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value); 948 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value);
902 } 949 }
903 } 950 }
904 951
905 } // namespace 952 } // namespace
906 } // namespace autofill 953 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698