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

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

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 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/validation.cc ('k') | chrome/browser/autofill/wallet/cart.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/validation.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card _numbers.htm
12 const char* const kValidNumbers[] = {
13 "378282246310005",
14 "3714 4963 5398 431",
15 "3787-3449-3671-000",
16 "5610591081018250",
17 "3056 9309 0259 04",
18 "3852-0000-0232-37",
19 "6011111111111117",
20 "6011 0009 9013 9424",
21 "3530-1113-3330-0000",
22 "3566002020360505",
23 "5555 5555 5555 4444",
24 "5105-1051-0510-5100",
25 "4111111111111111",
26 "4012 8888 8888 1881",
27 "4222-2222-2222-2",
28 "5019717010103742",
29 "6331101999990016",
30 };
31 const char* const kInvalidNumbers[] = {
32 "4111 1111 112", /* too short */
33 "41111111111111111115", /* too long */
34 "4111-1111-1111-1110", /* wrong Luhn checksum */
35 "3056 9309 0259 04aa", /* non-digit characters */
36 };
37 const char* const kValidCreditCardSecurityCode[] = {
38 "323", // 3-digit CSC.
39 "3234", // 4-digit CSC.
40 };
41 const char* const kInvalidCreditCardSecurityCode[] = {
42 "32", // CSC too short.
43 "12345", // CSC too long.
44 "asd", // non-numeric CSC.
45 };
46 const char* const kValidEmailAddress[] = {
47 "user@example",
48 "user@example.com",
49 "user@subdomain.example.com",
50 "user+postfix@example.com",
51 };
52 const char* const kInvalidEmailAddress[] = {
53 "user",
54 "foo.com",
55 "user@",
56 "user@=example.com"
57 };
58 } // namespace
59
60 TEST(AutofillValidation, IsValidCreditCardNumber) {
61 for (size_t i = 0; i < arraysize(kValidNumbers); ++i) {
62 SCOPED_TRACE(kValidNumbers[i]);
63 EXPECT_TRUE(
64 autofill::IsValidCreditCardNumber(ASCIIToUTF16(kValidNumbers[i])));
65 }
66 for (size_t i = 0; i < arraysize(kInvalidNumbers); ++i) {
67 SCOPED_TRACE(kInvalidNumbers[i]);
68 EXPECT_FALSE(
69 autofill::IsValidCreditCardNumber(ASCIIToUTF16(kInvalidNumbers[i])));
70 }
71 }
72
73 TEST(AutofillValidation, IsValidCreditCardSecurityCode) {
74 for (size_t i = 0; i < arraysize(kValidCreditCardSecurityCode); ++i) {
75 SCOPED_TRACE(kValidCreditCardSecurityCode[i]);
76 EXPECT_TRUE(
77 autofill::IsValidCreditCardSecurityCode(
78 ASCIIToUTF16(kValidCreditCardSecurityCode[i])));
79 }
80 for (size_t i = 0; i < arraysize(kInvalidCreditCardSecurityCode); ++i) {
81 SCOPED_TRACE(kInvalidCreditCardSecurityCode[i]);
82 EXPECT_FALSE(
83 autofill::IsValidCreditCardSecurityCode(
84 ASCIIToUTF16(kInvalidCreditCardSecurityCode[i])));
85 }
86 }
87
88 TEST(AutofillValidation, IsValidEmailAddress) {
89 for (size_t i = 0; i < arraysize(kValidEmailAddress); ++i) {
90 SCOPED_TRACE(kValidEmailAddress[i]);
91 EXPECT_TRUE(
92 autofill::IsValidEmailAddress(ASCIIToUTF16(kValidEmailAddress[i])));
93 }
94 for (size_t i = 0; i < arraysize(kInvalidEmailAddress); ++i) {
95 SCOPED_TRACE(kInvalidEmailAddress[i]);
96 EXPECT_FALSE(
97 autofill::IsValidEmailAddress(ASCIIToUTF16(kInvalidEmailAddress[i])));
98 }
99 }
100
101
OLDNEW
« no previous file with comments | « chrome/browser/autofill/validation.cc ('k') | chrome/browser/autofill/wallet/cart.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698