| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 if (test_cases[i].second_card_record_type == CreditCard::MASKED_SERVER_CARD) | 240 if (test_cases[i].second_card_record_type == CreditCard::MASKED_SERVER_CARD) |
| 241 b.SetTypeForMaskedCard(test_cases[i].second_card_type); | 241 b.SetTypeForMaskedCard(test_cases[i].second_card_type); |
| 242 | 242 |
| 243 EXPECT_EQ(test_cases[i].is_local_duplicate, | 243 EXPECT_EQ(test_cases[i].is_local_duplicate, |
| 244 a.IsLocalDuplicateOfServerCard(b)) << " when comparing cards " | 244 a.IsLocalDuplicateOfServerCard(b)) << " when comparing cards " |
| 245 << a.Label() << " and " << b.Label(); | 245 << a.Label() << " and " << b.Label(); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 TEST(CreditCardTest, HasSameNumberAs) { |
| 250 CreditCard a(base::GenerateGUID(), std::string()); |
| 251 CreditCard b(base::GenerateGUID(), std::string()); |
| 252 |
| 253 // Empty cards have the same empty number. |
| 254 EXPECT_TRUE(a.HasSameNumberAs(b)); |
| 255 EXPECT_TRUE(b.HasSameNumberAs(a)); |
| 256 |
| 257 // Same number. |
| 258 a.set_record_type(CreditCard::LOCAL_CARD); |
| 259 a.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); |
| 260 a.set_record_type(CreditCard::LOCAL_CARD); |
| 261 b.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); |
| 262 EXPECT_TRUE(a.HasSameNumberAs(b)); |
| 263 EXPECT_TRUE(b.HasSameNumberAs(a)); |
| 264 |
| 265 // Local cards shouldn't match even if the last 4 are the same. |
| 266 a.set_record_type(CreditCard::LOCAL_CARD); |
| 267 a.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); |
| 268 a.set_record_type(CreditCard::LOCAL_CARD); |
| 269 b.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111222222221111")); |
| 270 EXPECT_FALSE(a.HasSameNumberAs(b)); |
| 271 EXPECT_FALSE(b.HasSameNumberAs(a)); |
| 272 |
| 273 // Likewise if one is an unmasked server card. |
| 274 a.set_record_type(CreditCard::FULL_SERVER_CARD); |
| 275 EXPECT_FALSE(a.HasSameNumberAs(b)); |
| 276 EXPECT_FALSE(b.HasSameNumberAs(a)); |
| 277 |
| 278 // But if one is a masked card, then they should. |
| 279 b.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| 280 EXPECT_TRUE(a.HasSameNumberAs(b)); |
| 281 EXPECT_TRUE(b.HasSameNumberAs(a)); |
| 282 } |
| 283 |
| 249 TEST(CreditCardTest, Compare) { | 284 TEST(CreditCardTest, Compare) { |
| 250 CreditCard a(base::GenerateGUID(), std::string()); | 285 CreditCard a(base::GenerateGUID(), std::string()); |
| 251 CreditCard b(base::GenerateGUID(), std::string()); | 286 CreditCard b(base::GenerateGUID(), std::string()); |
| 252 | 287 |
| 253 // Empty cards are the same. | 288 // Empty cards are the same. |
| 254 EXPECT_EQ(0, a.Compare(b)); | 289 EXPECT_EQ(0, a.Compare(b)); |
| 255 | 290 |
| 256 // GUIDs don't count. | 291 // GUIDs don't count. |
| 257 a.set_guid(base::GenerateGUID()); | 292 a.set_guid(base::GenerateGUID()); |
| 258 b.set_guid(base::GenerateGUID()); | 293 b.set_guid(base::GenerateGUID()); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 base::string16 card_number = base::ASCIIToUTF16("test"); | 703 base::string16 card_number = base::ASCIIToUTF16("test"); |
| 669 int month = 1; | 704 int month = 1; |
| 670 int year = 3000; | 705 int year = 3000; |
| 671 CreditCard card(card_number, month, year); | 706 CreditCard card(card_number, month, year); |
| 672 EXPECT_EQ(card_number, card.number()); | 707 EXPECT_EQ(card_number, card.number()); |
| 673 EXPECT_EQ(month, card.expiration_month()); | 708 EXPECT_EQ(month, card.expiration_month()); |
| 674 EXPECT_EQ(year, card.expiration_year()); | 709 EXPECT_EQ(year, card.expiration_year()); |
| 675 } | 710 } |
| 676 | 711 |
| 677 } // namespace autofill | 712 } // namespace autofill |
| OLD | NEW |