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

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

Issue 1808613004: Don't ever attempt to upload credit cards whose numbers match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 <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
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
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
OLDNEW
« no previous file with comments | « components/autofill/core/browser/credit_card.cc ('k') | components/autofill/core/browser/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698