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

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

Issue 172473002: Move many of the Autofill unittests into components_unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/guid.h" 6 #include "base/guid.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/core/browser/autofill_test_utils.h" 8 #include "components/autofill/core/browser/autofill_test_utils.h"
9 #include "components/autofill/core/browser/autofill_type.h" 9 #include "components/autofill/core/browser/autofill_type.h"
10 #include "components/autofill/core/browser/credit_card.h" 10 #include "components/autofill/core/browser/credit_card.h"
11 #include "components/autofill/core/browser/validation.h" 11 #include "components/autofill/core/browser/validation.h"
12 #include "components/autofill/core/common/form_field_data.h" 12 #include "components/autofill/core/common/form_field_data.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 // TODO(blundell): Eliminate the need for this conditional include.
16 // crbug.com/328150
17 #if !defined(OS_IOS)
13 #include "grit/webkit_resources.h" 18 #include "grit/webkit_resources.h"
14 #include "testing/gtest/include/gtest/gtest.h" 19 #endif
15 20
16 using base::ASCIIToUTF16; 21 using base::ASCIIToUTF16;
17 22
18 namespace autofill { 23 namespace autofill {
19 namespace { 24 namespace {
20 25
21 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card _numbers.htm 26 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card _numbers.htm
22 const char* const kValidNumbers[] = { 27 const char* const kValidNumbers[] = {
23 "378282246310005", 28 "378282246310005",
24 "3714 4963 5398 431", 29 "3714 4963 5398 431",
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 b.set_origin("banana"); 161 b.set_origin("banana");
157 EXPECT_EQ(0, a.Compare(b)); 162 EXPECT_EQ(0, a.Compare(b));
158 163
159 // Different values produce non-zero results. 164 // Different values produce non-zero results.
160 test::SetCreditCardInfo(&a, "Jimmy", NULL, NULL, NULL); 165 test::SetCreditCardInfo(&a, "Jimmy", NULL, NULL, NULL);
161 test::SetCreditCardInfo(&b, "Ringo", NULL, NULL, NULL); 166 test::SetCreditCardInfo(&b, "Ringo", NULL, NULL, NULL);
162 EXPECT_GT(0, a.Compare(b)); 167 EXPECT_GT(0, a.Compare(b));
163 EXPECT_LT(0, b.Compare(a)); 168 EXPECT_LT(0, b.Compare(a));
164 } 169 }
165 170
171 // TODO(blundell): Either move these resources out of webkit_resources or
172 // this test into //components/autofill/content/browser to eliminate the
173 // need for this ifdef-ing. crbug.com/328150
174 #if !defined(OS_IOS)
166 // Test we get the correct icon for each card type. 175 // Test we get the correct icon for each card type.
167 TEST(CreditCardTest, IconResourceId) { 176 TEST(CreditCardTest, IconResourceId) {
168 EXPECT_EQ(IDR_AUTOFILL_CC_AMEX, 177 EXPECT_EQ(IDR_AUTOFILL_CC_AMEX,
169 CreditCard::IconResourceId(kAmericanExpressCard)); 178 CreditCard::IconResourceId(kAmericanExpressCard));
170 EXPECT_EQ(IDR_AUTOFILL_CC_DINERS, 179 EXPECT_EQ(IDR_AUTOFILL_CC_DINERS,
171 CreditCard::IconResourceId(kDinersCard)); 180 CreditCard::IconResourceId(kDinersCard));
172 EXPECT_EQ(IDR_AUTOFILL_CC_DISCOVER, 181 EXPECT_EQ(IDR_AUTOFILL_CC_DISCOVER,
173 CreditCard::IconResourceId(kDiscoverCard)); 182 CreditCard::IconResourceId(kDiscoverCard));
174 EXPECT_EQ(IDR_AUTOFILL_CC_JCB, 183 EXPECT_EQ(IDR_AUTOFILL_CC_JCB,
175 CreditCard::IconResourceId(kJCBCard)); 184 CreditCard::IconResourceId(kJCBCard));
176 EXPECT_EQ(IDR_AUTOFILL_CC_MASTERCARD, 185 EXPECT_EQ(IDR_AUTOFILL_CC_MASTERCARD,
177 CreditCard::IconResourceId(kMasterCard)); 186 CreditCard::IconResourceId(kMasterCard));
178 EXPECT_EQ(IDR_AUTOFILL_CC_VISA, 187 EXPECT_EQ(IDR_AUTOFILL_CC_VISA,
179 CreditCard::IconResourceId(kVisaCard)); 188 CreditCard::IconResourceId(kVisaCard));
180 } 189 }
190 #endif // !defined(OS_IOS)
181 191
182 TEST(CreditCardTest, UpdateFromImportedCard) { 192 TEST(CreditCardTest, UpdateFromImportedCard) {
183 CreditCard original_card(base::GenerateGUID(), "https://www.example.com"); 193 CreditCard original_card(base::GenerateGUID(), "https://www.example.com");
184 test::SetCreditCardInfo( 194 test::SetCreditCardInfo(
185 &original_card, "John Dillinger", "123456789012", "09", "2017"); 195 &original_card, "John Dillinger", "123456789012", "09", "2017");
186 196
187 CreditCard a = original_card; 197 CreditCard a = original_card;
188 198
189 // The new card has a different name, expiration date, and origin. 199 // The new card has a different name, expiration date, and origin.
190 CreditCard b = a; 200 CreditCard b = a;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 530
521 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 531 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
522 base::string16 card_number = ASCIIToUTF16(test_cases[i].card_number); 532 base::string16 card_number = ASCIIToUTF16(test_cases[i].card_number);
523 SCOPED_TRACE(card_number); 533 SCOPED_TRACE(card_number);
524 EXPECT_EQ(test_cases[i].type, CreditCard::GetCreditCardType(card_number)); 534 EXPECT_EQ(test_cases[i].type, CreditCard::GetCreditCardType(card_number));
525 EXPECT_EQ(test_cases[i].is_valid, IsValidCreditCardNumber(card_number)); 535 EXPECT_EQ(test_cases[i].is_valid, IsValidCreditCardNumber(card_number));
526 } 536 }
527 } 537 }
528 538
529 } // namespace autofill 539 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698