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

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

Issue 12213077: [Autofill] Credit Card validation for rAc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address line 2 is always valid. Created 7 years, 10 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/time.h"
Ilya Sherman 2013/02/11 05:39:51 nit: No longer needed?
groby-ooo-7-16 2013/02/11 22:47:53 Done.
5 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/validation.h" 7 #include "chrome/browser/autofill/validation.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 namespace { 10 namespace {
10 11
12 // Test data for expiration date validation.
13 struct DateTestData {
14 const char* const value; // Expiration date.
15 int digits; // Number of expected digits for expiration year.
16 };
Ilya Sherman 2013/02/11 05:39:51 nit: No longer used?
groby-ooo-7-16 2013/02/11 22:47:53 Done.
17
11 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card _numbers.htm 18 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card _numbers.htm
12 const char* const kValidNumbers[] = { 19 const char* const kValidNumbers[] = {
13 "378282246310005", 20 "378282246310005",
14 "3714 4963 5398 431", 21 "3714 4963 5398 431",
15 "3787-3449-3671-000", 22 "3787-3449-3671-000",
16 "5610591081018250", 23 "5610591081018250",
17 "3056 9309 0259 04", 24 "3056 9309 0259 04",
18 "3852-0000-0232-37", 25 "3852-0000-0232-37",
19 "6011111111111117", 26 "6011111111111117",
20 "6011 0009 9013 9424", 27 "6011 0009 9013 9424",
21 "3530-1113-3330-0000", 28 "3530-1113-3330-0000",
22 "3566002020360505", 29 "3566002020360505",
23 "5555 5555 5555 4444", 30 "5555 5555 5555 4444",
24 "5105-1051-0510-5100", 31 "5105-1051-0510-5100",
25 "4111111111111111", 32 "4111111111111111",
26 "4012 8888 8888 1881", 33 "4012 8888 8888 1881",
27 "4222-2222-2222-2", 34 "4222-2222-2222-2",
28 "5019717010103742", 35 "5019717010103742",
29 "6331101999990016", 36 "6331101999990016",
30 }; 37 };
31 const char* const kInvalidNumbers[] = { 38 const char* const kInvalidNumbers[] = {
32 "4111 1111 112", /* too short */ 39 "4111 1111 112", /* too short */
33 "41111111111111111115", /* too long */ 40 "41111111111111111115", /* too long */
34 "4111-1111-1111-1110", /* wrong Luhn checksum */ 41 "4111-1111-1111-1110", /* wrong Luhn checksum */
35 "3056 9309 0259 04aa", /* non-digit characters */ 42 "3056 9309 0259 04aa", /* non-digit characters */
36 }; 43 };
37 44 const char* const kValidCSC[] = {
45 "323", // 3-digit CSC.
46 "3234", // 4-digit CSC.
47 };
48 const char* const kInvalidCSC[] = {
49 "32", // CSC too short.
50 "12345", // CSC too long.
51 "asd", // non-numeric CSC.
52 };
38 } // namespace 53 } // namespace
39 54
40 TEST(AutofillValidation, IsValidCreditCardNumber) { 55 TEST(AutofillValidation, IsValidCreditCardNumber) {
41 for (size_t i = 0; i < arraysize(kValidNumbers); ++i) { 56 for (size_t i = 0; i < arraysize(kValidNumbers); ++i) {
42 SCOPED_TRACE(kValidNumbers[i]); 57 SCOPED_TRACE(kValidNumbers[i]);
43 EXPECT_TRUE( 58 EXPECT_TRUE(
44 autofill::IsValidCreditCardNumber(ASCIIToUTF16(kValidNumbers[i]))); 59 autofill::IsValidCreditCardNumber(ASCIIToUTF16(kValidNumbers[i])));
45 } 60 }
46 for (size_t i = 0; i < arraysize(kInvalidNumbers); ++i) { 61 for (size_t i = 0; i < arraysize(kInvalidNumbers); ++i) {
47 SCOPED_TRACE(kInvalidNumbers[i]); 62 SCOPED_TRACE(kInvalidNumbers[i]);
48 EXPECT_FALSE( 63 EXPECT_FALSE(
49 autofill::IsValidCreditCardNumber(ASCIIToUTF16(kInvalidNumbers[i]))); 64 autofill::IsValidCreditCardNumber(ASCIIToUTF16(kInvalidNumbers[i])));
50 } 65 }
51 } 66 }
67
68 TEST(AutofillValidation, IsValidCreditCardCSC) {
69 for (size_t i = 0; i < arraysize(kValidCSC); ++i) {
70 SCOPED_TRACE(kValidCSC[i]);
71 EXPECT_TRUE(
72 autofill::IsValidCreditCardCSC(ASCIIToUTF16(kValidCSC[i])));
73 }
74 for (size_t i = 0; i < arraysize(kInvalidCSC); ++i) {
75 SCOPED_TRACE(kInvalidCSC[i]);
76 EXPECT_FALSE(
77 autofill::IsValidCreditCardCSC(ASCIIToUTF16(kInvalidCSC[i])));
78 }
79 }
80
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698