| OLD | NEW |
| 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 "grit/component_scaled_resources.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 // TODO(blundell): Eliminate the need for this conditional include. | |
| 16 // crbug.com/328150 | |
| 17 #if !defined(OS_IOS) | |
| 18 #include "grit/webkit_resources.h" | |
| 19 #endif | |
| 20 | |
| 21 using base::ASCIIToUTF16; | 16 using base::ASCIIToUTF16; |
| 22 | 17 |
| 23 namespace autofill { | 18 namespace autofill { |
| 24 namespace { | 19 namespace { |
| 25 | 20 |
| 26 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card
_numbers.htm | 21 // From https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card
_numbers.htm |
| 27 const char* const kValidNumbers[] = { | 22 const char* const kValidNumbers[] = { |
| 28 "378282246310005", | 23 "378282246310005", |
| 29 "3714 4963 5398 431", | 24 "3714 4963 5398 431", |
| 30 "3787-3449-3671-000", | 25 "3787-3449-3671-000", |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 b.set_origin("banana"); | 156 b.set_origin("banana"); |
| 162 EXPECT_EQ(0, a.Compare(b)); | 157 EXPECT_EQ(0, a.Compare(b)); |
| 163 | 158 |
| 164 // Different values produce non-zero results. | 159 // Different values produce non-zero results. |
| 165 test::SetCreditCardInfo(&a, "Jimmy", NULL, NULL, NULL); | 160 test::SetCreditCardInfo(&a, "Jimmy", NULL, NULL, NULL); |
| 166 test::SetCreditCardInfo(&b, "Ringo", NULL, NULL, NULL); | 161 test::SetCreditCardInfo(&b, "Ringo", NULL, NULL, NULL); |
| 167 EXPECT_GT(0, a.Compare(b)); | 162 EXPECT_GT(0, a.Compare(b)); |
| 168 EXPECT_LT(0, b.Compare(a)); | 163 EXPECT_LT(0, b.Compare(a)); |
| 169 } | 164 } |
| 170 | 165 |
| 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) | |
| 175 // Test we get the correct icon for each card type. | 166 // Test we get the correct icon for each card type. |
| 176 TEST(CreditCardTest, IconResourceId) { | 167 TEST(CreditCardTest, IconResourceId) { |
| 177 EXPECT_EQ(IDR_AUTOFILL_CC_AMEX, | 168 EXPECT_EQ(IDR_AUTOFILL_CC_AMEX, |
| 178 CreditCard::IconResourceId(kAmericanExpressCard)); | 169 CreditCard::IconResourceId(kAmericanExpressCard)); |
| 179 EXPECT_EQ(IDR_AUTOFILL_CC_DINERS, | 170 EXPECT_EQ(IDR_AUTOFILL_CC_DINERS, |
| 180 CreditCard::IconResourceId(kDinersCard)); | 171 CreditCard::IconResourceId(kDinersCard)); |
| 181 EXPECT_EQ(IDR_AUTOFILL_CC_DISCOVER, | 172 EXPECT_EQ(IDR_AUTOFILL_CC_DISCOVER, |
| 182 CreditCard::IconResourceId(kDiscoverCard)); | 173 CreditCard::IconResourceId(kDiscoverCard)); |
| 183 EXPECT_EQ(IDR_AUTOFILL_CC_JCB, | 174 EXPECT_EQ(IDR_AUTOFILL_CC_JCB, |
| 184 CreditCard::IconResourceId(kJCBCard)); | 175 CreditCard::IconResourceId(kJCBCard)); |
| 185 EXPECT_EQ(IDR_AUTOFILL_CC_MASTERCARD, | 176 EXPECT_EQ(IDR_AUTOFILL_CC_MASTERCARD, |
| 186 CreditCard::IconResourceId(kMasterCard)); | 177 CreditCard::IconResourceId(kMasterCard)); |
| 187 EXPECT_EQ(IDR_AUTOFILL_CC_VISA, | 178 EXPECT_EQ(IDR_AUTOFILL_CC_VISA, |
| 188 CreditCard::IconResourceId(kVisaCard)); | 179 CreditCard::IconResourceId(kVisaCard)); |
| 189 } | 180 } |
| 190 #endif // !defined(OS_IOS) | |
| 191 | 181 |
| 192 TEST(CreditCardTest, UpdateFromImportedCard) { | 182 TEST(CreditCardTest, UpdateFromImportedCard) { |
| 193 CreditCard original_card(base::GenerateGUID(), "https://www.example.com"); | 183 CreditCard original_card(base::GenerateGUID(), "https://www.example.com"); |
| 194 test::SetCreditCardInfo( | 184 test::SetCreditCardInfo( |
| 195 &original_card, "John Dillinger", "123456789012", "09", "2017"); | 185 &original_card, "John Dillinger", "123456789012", "09", "2017"); |
| 196 | 186 |
| 197 CreditCard a = original_card; | 187 CreditCard a = original_card; |
| 198 | 188 |
| 199 // The new card has a different name, expiration date, and origin. | 189 // The new card has a different name, expiration date, and origin. |
| 200 CreditCard b = a; | 190 CreditCard b = a; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 520 |
| 531 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 521 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 532 base::string16 card_number = ASCIIToUTF16(test_cases[i].card_number); | 522 base::string16 card_number = ASCIIToUTF16(test_cases[i].card_number); |
| 533 SCOPED_TRACE(card_number); | 523 SCOPED_TRACE(card_number); |
| 534 EXPECT_EQ(test_cases[i].type, CreditCard::GetCreditCardType(card_number)); | 524 EXPECT_EQ(test_cases[i].type, CreditCard::GetCreditCardType(card_number)); |
| 535 EXPECT_EQ(test_cases[i].is_valid, IsValidCreditCardNumber(card_number)); | 525 EXPECT_EQ(test_cases[i].is_valid, IsValidCreditCardNumber(card_number)); |
| 536 } | 526 } |
| 537 } | 527 } |
| 538 | 528 |
| 539 } // namespace autofill | 529 } // namespace autofill |
| OLD | NEW |