| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { | 702 TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { |
| 703 base::string16 card_number = base::ASCIIToUTF16("test"); | 703 base::string16 card_number = base::ASCIIToUTF16("test"); |
| 704 int month = 1; | 704 int month = 1; |
| 705 int year = 3000; | 705 int year = 3000; |
| 706 CreditCard card(card_number, month, year); | 706 CreditCard card(card_number, month, year); |
| 707 EXPECT_EQ(card_number, card.number()); | 707 EXPECT_EQ(card_number, card.number()); |
| 708 EXPECT_EQ(month, card.expiration_month()); | 708 EXPECT_EQ(month, card.expiration_month()); |
| 709 EXPECT_EQ(year, card.expiration_year()); | 709 EXPECT_EQ(year, card.expiration_year()); |
| 710 } | 710 } |
| 711 | 711 |
| 712 TEST(CreditCardTest, IsExpired) { |
| 713 typedef struct { |
| 714 int current_month; |
| 715 int current_year; |
| 716 int card_expiration_month; |
| 717 int card_expiration_year; |
| 718 bool is_expired; |
| 719 } TestCase; |
| 720 |
| 721 TestCase test_cases[] = {// Card expired by a month. |
| 722 {3, 2016, 2, 2016, true}, |
| 723 // Card expired by a year. |
| 724 {3, 2016, 3, 2015, true}, |
| 725 // Card expired by both month and year. |
| 726 {3, 2016, 4, 2015, true}, |
| 727 // Card not expired. |
| 728 {3, 2016, 4, 2016, false}, |
| 729 // Card expired at the end of the month. |
| 730 {3, 2016, 3, 2016, false}, |
| 731 // Card expired - end of year edge case. |
| 732 {1, 2017, 12, 2016, true}, |
| 733 // Card not expired - end of year edge case. |
| 734 {12, 2016, 12, 2016, false}, |
| 735 // Card not expired if it has no expiration. |
| 736 {12, 2016, 0, 0, false}}; |
| 737 |
| 738 for (TestCase test_case : test_cases) { |
| 739 CreditCard card(base::ASCIIToUTF16("1234123412341234"), |
| 740 test_case.card_expiration_month, |
| 741 test_case.card_expiration_year); |
| 742 |
| 743 base::Time::Exploded exploded; |
| 744 exploded.month = test_case.current_month; |
| 745 exploded.year = test_case.current_year; |
| 746 |
| 747 EXPECT_EQ(test_case.is_expired, card.IsExpired(exploded)); |
| 748 } |
| 749 } |
| 750 |
| 712 } // namespace autofill | 751 } // namespace autofill |
| OLD | NEW |