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

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

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix Created 3 years, 7 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 "components/autofill/core/browser/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // Adds three local cards to the |personal_data_|. The three cards are 203 // Adds three local cards to the |personal_data_|. The three cards are
204 // different: two are from different companies and the third doesn't have a 204 // different: two are from different companies and the third doesn't have a
205 // number. All three have different owners and credit card number. This allows 205 // number. All three have different owners and credit card number. This allows
206 // to test the suggestions based on name as well as on credit card number. 206 // to test the suggestions based on name as well as on credit card number.
207 void SetupReferenceLocalCreditCards() { 207 void SetupReferenceLocalCreditCards() {
208 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 208 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
209 209
210 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", 210 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15",
211 "https://www.example.com"); 211 "https://www.example.com");
212 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", 212 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow",
213 "347666888555" /* American Express */, "04", 213 "347666888555" /* American Express */, "04", "2999",
214 "2999"); 214 "1");
215 credit_card0.set_use_count(3); 215 credit_card0.set_use_count(3);
216 credit_card0.set_use_date(AutofillClock::Now() - 216 credit_card0.set_use_date(AutofillClock::Now() -
217 base::TimeDelta::FromDays(1)); 217 base::TimeDelta::FromDays(1));
218 personal_data_->AddCreditCard(credit_card0); 218 personal_data_->AddCreditCard(credit_card0);
219 219
220 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", 220 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
221 "https://www.example.com"); 221 "https://www.example.com");
222 credit_card1.set_use_count(300); 222 credit_card1.set_use_count(300);
223 credit_card1.set_use_date(AutofillClock::Now() - 223 credit_card1.set_use_date(AutofillClock::Now() -
224 base::TimeDelta::FromDays(10)); 224 base::TimeDelta::FromDays(10));
225 test::SetCreditCardInfo(&credit_card1, "John Dillinger", 225 test::SetCreditCardInfo(&credit_card1, "John Dillinger",
226 "423456789012" /* Visa */, "01", "2999"); 226 "423456789012" /* Visa */, "01", "2999", "1");
227 personal_data_->AddCreditCard(credit_card1); 227 personal_data_->AddCreditCard(credit_card1);
228 228
229 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 229 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
230 "https://www.example.com"); 230 "https://www.example.com");
231 credit_card2.set_use_count(1); 231 credit_card2.set_use_count(1);
232 credit_card2.set_use_date(AutofillClock::Now() - 232 credit_card2.set_use_date(AutofillClock::Now() -
233 base::TimeDelta::FromDays(1)); 233 base::TimeDelta::FromDays(1));
234 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", 234 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker",
235 "518765432109" /* Mastercard */, "12", "2999"); 235 "518765432109" /* Mastercard */, "12", "2999", "1");
236 personal_data_->AddCreditCard(credit_card2); 236 personal_data_->AddCreditCard(credit_card2);
237 237
238 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 238 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
239 .WillOnce(QuitMainMessageLoop()); 239 .WillOnce(QuitMainMessageLoop());
240 base::RunLoop().Run(); 240 base::RunLoop().Run();
241 241
242 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 242 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
243 } 243 }
244 244
245 // Helper methods that simply forward the call to the private member (to avoid 245 // Helper methods that simply forward the call to the private member (to avoid
(...skipping 28 matching lines...) Expand all
274 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 274 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
275 personal_data_->SaveImportedCreditCard(*imported_credit_card); 275 personal_data_->SaveImportedCreditCard(*imported_credit_card);
276 276
277 // Verify that the web database has been updated and the notification sent. 277 // Verify that the web database has been updated and the notification sent.
278 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 278 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
279 .WillOnce(QuitMainMessageLoop()); 279 .WillOnce(QuitMainMessageLoop());
280 base::RunLoop().Run(); 280 base::RunLoop().Run();
281 281
282 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 282 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
283 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month, 283 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month,
284 exp_cc_year); 284 exp_cc_year, "");
285 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 285 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
286 ASSERT_EQ(1U, results.size()); 286 ASSERT_EQ(1U, results.size());
287 EXPECT_EQ(0, expected.Compare(*results[0])); 287 EXPECT_EQ(0, expected.Compare(*results[0]));
288 } 288 }
289 289
290 // The temporary directory should be deleted at the end to ensure that 290 // The temporary directory should be deleted at the end to ensure that
291 // files are not used anymore and deletion succeeds. 291 // files are not used anymore and deletion succeeds.
292 base::ScopedTempDir temp_dir_; 292 base::ScopedTempDir temp_dir_;
293 base::MessageLoopForUI message_loop_; 293 base::MessageLoopForUI message_loop_;
294 std::unique_ptr<PrefService> prefs_; 294 std::unique_ptr<PrefService> prefs_;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // database. 496 // database.
497 ResetPersonalDataManager(USER_MODE_NORMAL); 497 ResetPersonalDataManager(USER_MODE_NORMAL);
498 498
499 // Verify that we've loaded the profiles from the web database. 499 // Verify that we've loaded the profiles from the web database.
500 ExpectSameElements(profiles, personal_data_->GetProfiles()); 500 ExpectSameElements(profiles, personal_data_->GetProfiles());
501 } 501 }
502 502
503 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { 503 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) {
504 EnableWalletCardImport(); 504 EnableWalletCardImport();
505 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); 505 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com");
506 test::SetCreditCardInfo(&credit_card0, 506 test::SetCreditCardInfo(&credit_card0, "John Dillinger",
507 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); 507 "423456789012" /* Visa */, "01", "2999", "1");
508 508
509 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); 509 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com");
510 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", 510 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker",
511 "518765432109" /* Mastercard */, "12", "2999"); 511 "518765432109" /* Mastercard */, "12", "2999", "1");
512 512
513 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); 513 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com");
514 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow", 514 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow",
515 "347666888555" /* American Express */, "04", "2999"); 515 "347666888555" /* American Express */, "04", "2999",
516 "1");
516 517
517 // Add two test credit cards to the database. 518 // Add two test credit cards to the database.
518 personal_data_->AddCreditCard(credit_card0); 519 personal_data_->AddCreditCard(credit_card0);
519 personal_data_->AddCreditCard(credit_card1); 520 personal_data_->AddCreditCard(credit_card1);
520 521
521 // Verify that the web database has been updated and the notification sent. 522 // Verify that the web database has been updated and the notification sent.
522 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 523 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
523 .WillOnce(QuitMainMessageLoop()); 524 .WillOnce(QuitMainMessageLoop());
524 base::RunLoop().Run(); 525 base::RunLoop().Run();
525 526
(...skipping 25 matching lines...) Expand all
551 552
552 // Verify that we've loaded the credit cards from the web database. 553 // Verify that we've loaded the credit cards from the web database.
553 cards.clear(); 554 cards.clear();
554 cards.push_back(&credit_card0); 555 cards.push_back(&credit_card0);
555 cards.push_back(&credit_card2); 556 cards.push_back(&credit_card2);
556 ExpectSameElements(cards, personal_data_->GetCreditCards()); 557 ExpectSameElements(cards, personal_data_->GetCreditCards());
557 558
558 // Add a full server card. 559 // Add a full server card.
559 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); 560 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com");
560 test::SetCreditCardInfo(&credit_card3, "Jane Doe", 561 test::SetCreditCardInfo(&credit_card3, "Jane Doe",
561 "4111111111111111" /* Visa */, "04", "2999"); 562 "4111111111111111" /* Visa */, "04", "2999", "1");
562 credit_card3.set_record_type(CreditCard::FULL_SERVER_CARD); 563 credit_card3.set_record_type(CreditCard::FULL_SERVER_CARD);
563 credit_card3.set_server_id("server_id"); 564 credit_card3.set_server_id("server_id");
564 565
565 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 566 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
566 .WillOnce(QuitMainMessageLoop()); 567 .WillOnce(QuitMainMessageLoop());
567 568
568 personal_data_->AddFullServerCreditCard(credit_card3); 569 personal_data_->AddFullServerCreditCard(credit_card3);
569 base::RunLoop().Run(); 570 base::RunLoop().Run();
570 571
571 cards.push_back(&credit_card3); 572 cards.push_back(&credit_card3);
(...skipping 19 matching lines...) Expand all
591 592
592 // Test that a new credit card has its basic information set. 593 // Test that a new credit card has its basic information set.
593 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { 594 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) {
594 // Create the test clock and set the time to a specific value. 595 // Create the test clock and set the time to a specific value.
595 TestAutofillClock test_clock; 596 TestAutofillClock test_clock;
596 test_clock.SetNow(kArbitraryTime); 597 test_clock.SetNow(kArbitraryTime);
597 598
598 // Add a credit card to the database. 599 // Add a credit card to the database.
599 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); 600 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com");
600 test::SetCreditCardInfo(&credit_card, "John Dillinger", 601 test::SetCreditCardInfo(&credit_card, "John Dillinger",
601 "423456789012" /* Visa */, "01", "2999"); 602 "423456789012" /* Visa */, "01", "2999", "1");
602 personal_data_->AddCreditCard(credit_card); 603 personal_data_->AddCreditCard(credit_card);
603 604
604 // Reload the database. 605 // Reload the database.
605 ResetPersonalDataManager(USER_MODE_NORMAL); 606 ResetPersonalDataManager(USER_MODE_NORMAL);
606 607
607 // Verify the addition. 608 // Verify the addition.
608 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 609 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
609 ASSERT_EQ(1U, results.size()); 610 ASSERT_EQ(1U, results.size());
610 EXPECT_EQ(0, credit_card.Compare(*results[0])); 611 EXPECT_EQ(0, credit_card.Compare(*results[0]));
611 612
612 // Make sure the use count and use date were set. 613 // Make sure the use count and use date were set.
613 EXPECT_EQ(1U, results[0]->use_count()); 614 EXPECT_EQ(1U, results[0]->use_count());
614 EXPECT_EQ(kArbitraryTime, results[0]->use_date()); 615 EXPECT_EQ(kArbitraryTime, results[0]->use_date());
615 EXPECT_EQ(kArbitraryTime, results[0]->modification_date()); 616 EXPECT_EQ(kArbitraryTime, results[0]->modification_date());
616 } 617 }
617 618
618 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { 619 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) {
619 // Start with unverified data. 620 // Start with unverified data.
620 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 621 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
621 test::SetProfileInfo(&profile, 622 test::SetProfileInfo(&profile,
622 "Marion", "Mitchell", "Morrison", 623 "Marion", "Mitchell", "Morrison",
623 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 624 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
624 "91601", "US", "12345678910"); 625 "91601", "US", "12345678910");
625 EXPECT_FALSE(profile.IsVerified()); 626 EXPECT_FALSE(profile.IsVerified());
626 627
627 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); 628 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/");
628 test::SetCreditCardInfo(&credit_card, 629 test::SetCreditCardInfo(&credit_card, "John Dillinger",
629 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); 630 "423456789012" /* Visa */, "01", "2999", "1");
630 EXPECT_FALSE(credit_card.IsVerified()); 631 EXPECT_FALSE(credit_card.IsVerified());
631 632
632 // Add the data to the database. 633 // Add the data to the database.
633 personal_data_->AddProfile(profile); 634 personal_data_->AddProfile(profile);
634 personal_data_->AddCreditCard(credit_card); 635 personal_data_->AddCreditCard(credit_card);
635 636
636 // Verify that the web database has been updated and the notification sent. 637 // Verify that the web database has been updated and the notification sent.
637 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 638 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
638 .WillOnce(QuitMainMessageLoop()); 639 .WillOnce(QuitMainMessageLoop());
639 base::RunLoop().Run(); 640 base::RunLoop().Run();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( 702 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
702 switches::kDisableOfferStoreUnmaskedWalletCards)); 703 switches::kDisableOfferStoreUnmaskedWalletCards));
703 #else 704 #else
704 base::CommandLine::ForCurrentProcess()->AppendSwitch( 705 base::CommandLine::ForCurrentProcess()->AppendSwitch(
705 switches::kDisableOfferStoreUnmaskedWalletCards); 706 switches::kDisableOfferStoreUnmaskedWalletCards);
706 #endif 707 #endif
707 708
708 std::vector<CreditCard> server_cards; 709 std::vector<CreditCard> server_cards;
709 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 710 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
710 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 711 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
711 "347666888555" /* American Express */, "04", "2999"); 712 "347666888555" /* American Express */, "04", "2999",
713 "1");
712 test::SetServerCreditCards(autofill_table_, server_cards); 714 test::SetServerCreditCards(autofill_table_, server_cards);
713 personal_data_->Refresh(); 715 personal_data_->Refresh();
714 716
715 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 717 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
716 .WillOnce(QuitMainMessageLoop()); 718 .WillOnce(QuitMainMessageLoop());
717 base::RunLoop().Run(); 719 base::RunLoop().Run();
718 720
719 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); 721 ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
720 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, 722 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD,
721 personal_data_->GetCreditCards()[0]->record_type()); 723 personal_data_->GetCreditCards()[0]->record_type());
722 } 724 }
723 725
724 // Makes sure that full cards are only added as masked card when full PAN 726 // Makes sure that full cards are only added as masked card when full PAN
725 // storage is disabled. 727 // storage is disabled.
726 TEST_F(PersonalDataManagerTest, AddFullCardAsMaskedCard) { 728 TEST_F(PersonalDataManagerTest, AddFullCardAsMaskedCard) {
727 // On Linux this should be disabled automatically. Elsewhere, only if the 729 // On Linux this should be disabled automatically. Elsewhere, only if the
728 // flag is passed. 730 // flag is passed.
729 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 731 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
730 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( 732 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
731 switches::kDisableOfferStoreUnmaskedWalletCards)); 733 switches::kDisableOfferStoreUnmaskedWalletCards));
732 #else 734 #else
733 base::CommandLine::ForCurrentProcess()->AppendSwitch( 735 base::CommandLine::ForCurrentProcess()->AppendSwitch(
734 switches::kDisableOfferStoreUnmaskedWalletCards); 736 switches::kDisableOfferStoreUnmaskedWalletCards);
735 #endif 737 #endif
736 738
737 CreditCard server_card(CreditCard::FULL_SERVER_CARD, "c789"); 739 CreditCard server_card(CreditCard::FULL_SERVER_CARD, "c789");
738 test::SetCreditCardInfo(&server_card, "Clyde Barrow", 740 test::SetCreditCardInfo(&server_card, "Clyde Barrow",
739 "347666888555" /* American Express */, "04", "2999"); 741 "347666888555" /* American Express */, "04", "2999",
742 "1");
740 743
741 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 744 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
742 .WillOnce(QuitMainMessageLoop()); 745 .WillOnce(QuitMainMessageLoop());
743 746
744 personal_data_->AddFullServerCreditCard(server_card); 747 personal_data_->AddFullServerCreditCard(server_card);
745 748
746 base::RunLoop().Run(); 749 base::RunLoop().Run();
747 750
748 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); 751 ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
749 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, 752 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD,
(...skipping 10 matching lines...) Expand all
760 EXPECT_EQ(should_offer, OfferStoreUnmaskedCards()); 763 EXPECT_EQ(should_offer, OfferStoreUnmaskedCards());
761 } 764 }
762 765
763 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards. 766 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards.
764 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { 767 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) {
765 EnableWalletCardImport(); 768 EnableWalletCardImport();
766 769
767 std::vector<CreditCard> server_cards; 770 std::vector<CreditCard> server_cards;
768 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 771 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
769 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 772 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
770 "9012" /* Visa */, "01", "2999"); 773 "9012" /* Visa */, "01", "2999", "1");
771 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 774 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
772 775
773 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); 776 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
774 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", 777 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker",
775 "2109" /* Mastercard */, "12", "2999"); 778 "2109" /* Mastercard */, "12", "2999", "1");
776 server_cards.back().SetNetworkForMaskedCard(kMasterCard); 779 server_cards.back().SetNetworkForMaskedCard(kMasterCard);
777 780
778 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 781 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
779 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 782 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
780 "347666888555" /* American Express */, "04", "2999"); 783 "347666888555" /* American Express */, "04", "2999",
784 "1");
781 785
782 test::SetServerCreditCards(autofill_table_, server_cards); 786 test::SetServerCreditCards(autofill_table_, server_cards);
783 personal_data_->Refresh(); 787 personal_data_->Refresh();
784 788
785 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 789 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
786 .WillOnce(QuitMainMessageLoop()); 790 .WillOnce(QuitMainMessageLoop());
787 base::RunLoop().Run(); 791 base::RunLoop().Run();
788 792
789 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 793 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
790 794
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 841 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
838 "91601", "US", "12345678910"); 842 "91601", "US", "12345678910");
839 843
840 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 844 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
841 test::SetProfileInfo(&profile1, 845 test::SetProfileInfo(&profile1,
842 "Josephine", "Alicia", "Saenz", 846 "Josephine", "Alicia", "Saenz",
843 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", 847 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
844 "US", "19482937549"); 848 "US", "19482937549");
845 849
846 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); 850 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com");
847 test::SetCreditCardInfo(&credit_card0, 851 test::SetCreditCardInfo(&credit_card0, "John Dillinger",
848 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); 852 "423456789012" /* Visa */, "01", "2999", "1");
849 853
850 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); 854 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com");
851 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", 855 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker",
852 "518765432109" /* Mastercard */, "12", "2999"); 856 "518765432109" /* Mastercard */, "12", "2999", "1");
853 857
854 // Add two test profiles to the database. 858 // Add two test profiles to the database.
855 personal_data_->AddProfile(profile0); 859 personal_data_->AddProfile(profile0);
856 personal_data_->AddProfile(profile1); 860 personal_data_->AddProfile(profile1);
857 861
858 // Verify that the web database has been updated and the notification sent. 862 // Verify that the web database has been updated and the notification sent.
859 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 863 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
860 .WillOnce(QuitMainMessageLoop()); 864 .WillOnce(QuitMainMessageLoop());
861 base::RunLoop().Run(); 865 base::RunLoop().Run();
862 866
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 // database. 984 // database.
981 ResetPersonalDataManager(USER_MODE_NORMAL); 985 ResetPersonalDataManager(USER_MODE_NORMAL);
982 986
983 // Verify that we've loaded the profiles from the web database. 987 // Verify that we've loaded the profiles from the web database.
984 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 988 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
985 ASSERT_EQ(0U, results2.size()); 989 ASSERT_EQ(0U, results2.size());
986 } 990 }
987 991
988 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { 992 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) {
989 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); 993 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com");
990 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); 994 test::SetCreditCardInfo(&credit_card0, "", "", "", "", "");
991 995
992 // Add the empty credit card to the database. 996 // Add the empty credit card to the database.
993 personal_data_->AddCreditCard(credit_card0); 997 personal_data_->AddCreditCard(credit_card0);
994 998
995 // Note: no refresh here. 999 // Note: no refresh here.
996 1000
997 // Reset the PersonalDataManager. This tests that the personal data was saved 1001 // Reset the PersonalDataManager. This tests that the personal data was saved
998 // to the web database, and that we can load the credit cards from the web 1002 // to the web database, and that we can load the credit cards from the web
999 // database. 1003 // database.
1000 ResetPersonalDataManager(USER_MODE_NORMAL); 1004 ResetPersonalDataManager(USER_MODE_NORMAL);
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2222 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2219 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2223 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2220 2224
2221 // Verify that the web database has been updated and the notification sent. 2225 // Verify that the web database has been updated and the notification sent.
2222 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2226 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2223 .WillOnce(QuitMainMessageLoop()); 2227 .WillOnce(QuitMainMessageLoop());
2224 base::RunLoop().Run(); 2228 base::RunLoop().Run();
2225 2229
2226 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2230 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2227 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2231 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2228 "2999"); 2232 "2999", ""); // Imported cards have not billing info.
2229 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2233 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2230 ASSERT_EQ(1U, results.size()); 2234 ASSERT_EQ(1U, results.size());
2231 EXPECT_EQ(0, expected.Compare(*results[0])); 2235 EXPECT_EQ(0, expected.Compare(*results[0]));
2232 } 2236 }
2233 2237
2234 // Tests that an invalid credit card is not extracted. 2238 // Tests that an invalid credit card is not extracted.
2235 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { 2239 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) {
2236 FormData form; 2240 FormData form;
2237 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", 2241 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02",
2238 "2999"); 2242 "2999");
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2290 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2287 2291
2288 // Verify that the web database has been updated and the notification sent. 2292 // Verify that the web database has been updated and the notification sent.
2289 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2293 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2290 .WillOnce(QuitMainMessageLoop()); 2294 .WillOnce(QuitMainMessageLoop());
2291 base::RunLoop().Run(); 2295 base::RunLoop().Run();
2292 2296
2293 // See that the invalid option text was converted to the right value. 2297 // See that the invalid option text was converted to the right value.
2294 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2298 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2295 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", 2299 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02",
2296 "2999"); 2300 "2999", ""); // Imported cards have not billing info.
2297 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2301 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2298 ASSERT_EQ(1U, results.size()); 2302 ASSERT_EQ(1U, results.size());
2299 EXPECT_EQ(0, expected.Compare(*results[0])); 2303 EXPECT_EQ(0, expected.Compare(*results[0]));
2300 } 2304 }
2301 2305
2302 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { 2306 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) {
2303 // Start with a single valid credit card form. 2307 // Start with a single valid credit card form.
2304 FormData form1; 2308 FormData form1;
2305 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2309 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2306 "2999"); 2310 "2999");
2307 2311
2308 FormStructure form_structure1(form1); 2312 FormStructure form_structure1(form1);
2309 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); 2313 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2310 std::unique_ptr<CreditCard> imported_credit_card; 2314 std::unique_ptr<CreditCard> imported_credit_card;
2311 bool imported_credit_card_matches_masked_server_credit_card; 2315 bool imported_credit_card_matches_masked_server_credit_card;
2312 EXPECT_TRUE(ImportCreditCard( 2316 EXPECT_TRUE(ImportCreditCard(
2313 form_structure1, false, &imported_credit_card, 2317 form_structure1, false, &imported_credit_card,
2314 &imported_credit_card_matches_masked_server_credit_card)); 2318 &imported_credit_card_matches_masked_server_credit_card));
2315 ASSERT_TRUE(imported_credit_card); 2319 ASSERT_TRUE(imported_credit_card);
2316 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2320 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2317 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2321 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2318 2322
2319 // Verify that the web database has been updated and the notification sent. 2323 // Verify that the web database has been updated and the notification sent.
2320 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2324 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2321 .WillOnce(QuitMainMessageLoop()); 2325 .WillOnce(QuitMainMessageLoop());
2322 base::RunLoop().Run(); 2326 base::RunLoop().Run();
2323 2327
2324 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2328 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2325 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2329 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2326 "2999"); 2330 "2999", ""); // Imported cards have not billing info.
2327 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2331 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2328 ASSERT_EQ(1U, results.size()); 2332 ASSERT_EQ(1U, results.size());
2329 EXPECT_EQ(0, expected.Compare(*results[0])); 2333 EXPECT_EQ(0, expected.Compare(*results[0]));
2330 2334
2331 // Add a second different valid credit card. 2335 // Add a second different valid credit card.
2332 FormData form2; 2336 FormData form2;
2333 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); 2337 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999");
2334 2338
2335 FormStructure form_structure2(form2); 2339 FormStructure form_structure2(form2);
2336 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); 2340 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2337 std::unique_ptr<CreditCard> imported_credit_card2; 2341 std::unique_ptr<CreditCard> imported_credit_card2;
2338 EXPECT_TRUE(ImportCreditCard( 2342 EXPECT_TRUE(ImportCreditCard(
2339 form_structure2, false, &imported_credit_card2, 2343 form_structure2, false, &imported_credit_card2,
2340 &imported_credit_card_matches_masked_server_credit_card)); 2344 &imported_credit_card_matches_masked_server_credit_card));
2341 ASSERT_TRUE(imported_credit_card2); 2345 ASSERT_TRUE(imported_credit_card2);
2342 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2346 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2343 personal_data_->SaveImportedCreditCard(*imported_credit_card2); 2347 personal_data_->SaveImportedCreditCard(*imported_credit_card2);
2344 2348
2345 // Verify that the web database has been updated and the notification sent. 2349 // Verify that the web database has been updated and the notification sent.
2346 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2350 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2347 .WillOnce(QuitMainMessageLoop()); 2351 .WillOnce(QuitMainMessageLoop());
2348 base::RunLoop().Run(); 2352 base::RunLoop().Run();
2349 2353
2350 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2354 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2351 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999"); 2355 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999",
2356 ""); // Imported cards have not billing info.
2352 std::vector<CreditCard*> cards; 2357 std::vector<CreditCard*> cards;
2353 cards.push_back(&expected); 2358 cards.push_back(&expected);
2354 cards.push_back(&expected2); 2359 cards.push_back(&expected2);
2355 ExpectSameElements(cards, personal_data_->GetCreditCards()); 2360 ExpectSameElements(cards, personal_data_->GetCreditCards());
2356 } 2361 }
2357 2362
2358 // This form has the expiration year as one field with MM/YY. 2363 // This form has the expiration year as one field with MM/YY.
2359 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) { 2364 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) {
2360 FormData form; 2365 FormData form;
2361 FormFieldData field; 2366 FormFieldData field;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 } 2437 }
2433 2438
2434 // Tests that a credit card is extracted because it only matches a masked server 2439 // Tests that a credit card is extracted because it only matches a masked server
2435 // card. 2440 // card.
2436 TEST_F(PersonalDataManagerTest, 2441 TEST_F(PersonalDataManagerTest,
2437 ImportCreditCard_DuplicateServerCards_MaskedCard) { 2442 ImportCreditCard_DuplicateServerCards_MaskedCard) {
2438 // Add a masked server card. 2443 // Add a masked server card.
2439 std::vector<CreditCard> server_cards; 2444 std::vector<CreditCard> server_cards;
2440 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 2445 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
2441 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 2446 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
2442 "1111" /* Visa */, "01", "2999"); 2447 "1111" /* Visa */, "01", "2999", "");
2443 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 2448 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
2444 test::SetServerCreditCards(autofill_table_, server_cards); 2449 test::SetServerCreditCards(autofill_table_, server_cards);
2445 2450
2446 // Type the same data as the masked card into a form. 2451 // Type the same data as the masked card into a form.
2447 FormData form; 2452 FormData form;
2448 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", 2453 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01",
2449 "2999"); 2454 "2999");
2450 2455
2451 // The card should be offered to be saved locally because it only matches the 2456 // The card should be offered to be saved locally because it only matches the
2452 // masked server card. 2457 // masked server card.
(...skipping 15 matching lines...) Expand all
2468 } 2473 }
2469 2474
2470 // Tests that a credit card is not extracted because it matches a full server 2475 // Tests that a credit card is not extracted because it matches a full server
2471 // card. 2476 // card.
2472 TEST_F(PersonalDataManagerTest, 2477 TEST_F(PersonalDataManagerTest,
2473 ImportCreditCard_DuplicateServerCards_FullCard) { 2478 ImportCreditCard_DuplicateServerCards_FullCard) {
2474 // Add a full server card. 2479 // Add a full server card.
2475 std::vector<CreditCard> server_cards; 2480 std::vector<CreditCard> server_cards;
2476 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 2481 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
2477 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 2482 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
2478 "347666888555" /* American Express */, "04", "2999"); 2483 "347666888555" /* American Express */, "04", "2999",
2484 ""); // Imported cards have not billing info.
2479 test::SetServerCreditCards(autofill_table_, server_cards); 2485 test::SetServerCreditCards(autofill_table_, server_cards);
2480 2486
2481 // Type the same data as the unmasked card into a form. 2487 // Type the same data as the unmasked card into a form.
2482 FormData form; 2488 FormData form;
2483 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); 2489 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999");
2484 2490
2485 // The card should not be offered to be saved locally because it only matches 2491 // The card should not be offered to be saved locally because it only matches
2486 // the full server card. 2492 // the full server card.
2487 FormStructure form_structure(form); 2493 FormStructure form_structure(form);
2488 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); 2494 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
(...skipping 22 matching lines...) Expand all
2511 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2517 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2512 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2518 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2513 2519
2514 // Verify that the web database has been updated and the notification sent. 2520 // Verify that the web database has been updated and the notification sent.
2515 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2521 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2516 .WillOnce(QuitMainMessageLoop()); 2522 .WillOnce(QuitMainMessageLoop());
2517 base::RunLoop().Run(); 2523 base::RunLoop().Run();
2518 2524
2519 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2525 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2520 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2526 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2521 "2998"); 2527 "2998", ""); // Imported cards have not billing info.
2522 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2528 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2523 ASSERT_EQ(1U, results.size()); 2529 ASSERT_EQ(1U, results.size());
2524 EXPECT_EQ(0, expected.Compare(*results[0])); 2530 EXPECT_EQ(0, expected.Compare(*results[0]));
2525 2531
2526 // Add a second different valid credit card where the year is different but 2532 // Add a second different valid credit card where the year is different but
2527 // the credit card number matches. 2533 // the credit card number matches.
2528 FormData form2; 2534 FormData form2;
2529 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", 2535 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01",
2530 /* different year */ "2999"); 2536 /* different year */ "2999");
2531 2537
2532 FormStructure form_structure2(form2); 2538 FormStructure form_structure2(form2);
2533 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); 2539 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2534 std::unique_ptr<CreditCard> imported_credit_card2; 2540 std::unique_ptr<CreditCard> imported_credit_card2;
2535 EXPECT_TRUE(ImportCreditCard( 2541 EXPECT_TRUE(ImportCreditCard(
2536 form_structure2, false, &imported_credit_card2, 2542 form_structure2, false, &imported_credit_card2,
2537 &imported_credit_card_matches_masked_server_credit_card)); 2543 &imported_credit_card_matches_masked_server_credit_card));
2538 EXPECT_FALSE(imported_credit_card2); 2544 EXPECT_FALSE(imported_credit_card2);
2539 2545
2540 // Verify that the web database has been updated and the notification sent. 2546 // Verify that the web database has been updated and the notification sent.
2541 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2547 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2542 .WillOnce(QuitMainMessageLoop()); 2548 .WillOnce(QuitMainMessageLoop());
2543 base::RunLoop().Run(); 2549 base::RunLoop().Run();
2544 2550
2545 // Expect that the newer information is saved. In this case the year is 2551 // Expect that the newer information is saved. In this case the year is
2546 // updated to "2999". 2552 // updated to "2999".
2547 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2553 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2548 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2554 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2549 "2999"); 2555 "2999", ""); // Imported cards have not billing info.
2550 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2556 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2551 ASSERT_EQ(1U, results2.size()); 2557 ASSERT_EQ(1U, results2.size());
2552 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2558 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2553 } 2559 }
2554 2560
2555 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { 2561 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) {
2556 // Start with a single valid credit card form. 2562 // Start with a single valid credit card form.
2557 FormData form1; 2563 FormData form1;
2558 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2564 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2559 "2998"); 2565 "2998");
2560 2566
2561 FormStructure form_structure1(form1); 2567 FormStructure form_structure1(form1);
2562 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); 2568 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2563 std::unique_ptr<CreditCard> imported_credit_card; 2569 std::unique_ptr<CreditCard> imported_credit_card;
2564 bool imported_credit_card_matches_masked_server_credit_card; 2570 bool imported_credit_card_matches_masked_server_credit_card;
2565 EXPECT_TRUE(ImportCreditCard( 2571 EXPECT_TRUE(ImportCreditCard(
2566 form_structure1, false, &imported_credit_card, 2572 form_structure1, false, &imported_credit_card,
2567 &imported_credit_card_matches_masked_server_credit_card)); 2573 &imported_credit_card_matches_masked_server_credit_card));
2568 ASSERT_TRUE(imported_credit_card); 2574 ASSERT_TRUE(imported_credit_card);
2569 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2575 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2570 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2576 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2571 2577
2572 // Verify that the web database has been updated and the notification sent. 2578 // Verify that the web database has been updated and the notification sent.
2573 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2579 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2574 .WillOnce(QuitMainMessageLoop()); 2580 .WillOnce(QuitMainMessageLoop());
2575 base::RunLoop().Run(); 2581 base::RunLoop().Run();
2576 2582
2577 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2583 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2578 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2584 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2579 "2998"); 2585 "2998", ""); // Imported cards have not billing info.
2580 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2586 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2581 ASSERT_EQ(1U, results.size()); 2587 ASSERT_EQ(1U, results.size());
2582 EXPECT_EQ(0, expected.Compare(*results[0])); 2588 EXPECT_EQ(0, expected.Compare(*results[0]));
2583 2589
2584 // Add a second different valid credit card where the year is different but 2590 // Add a second different valid credit card where the year is different but
2585 // the credit card number matches. 2591 // the credit card number matches.
2586 FormData form2; 2592 FormData form2;
2587 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", 2593 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01",
2588 /* different year */ "2999"); 2594 /* different year */ "2999");
2589 2595
(...skipping 10 matching lines...) Expand all
2600 2606
2601 // Verify that the web database has been updated and the notification sent. 2607 // Verify that the web database has been updated and the notification sent.
2602 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2608 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2603 .WillOnce(QuitMainMessageLoop()); 2609 .WillOnce(QuitMainMessageLoop());
2604 base::RunLoop().Run(); 2610 base::RunLoop().Run();
2605 2611
2606 // Expect that the newer information is saved. In this case the year is 2612 // Expect that the newer information is saved. In this case the year is
2607 // updated to "2999". 2613 // updated to "2999".
2608 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2614 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2609 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2615 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2610 "2999"); 2616 "2999", ""); // Imported cards have not billing info.
2611 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2617 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2612 ASSERT_EQ(1U, results2.size()); 2618 ASSERT_EQ(1U, results2.size());
2613 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2619 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2614 } 2620 }
2615 2621
2616 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { 2622 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) {
2617 // Start with a single valid credit card form. 2623 // Start with a single valid credit card form.
2618 FormData form1; 2624 FormData form1;
2619 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2625 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2620 "2998"); 2626 "2998");
2621 2627
2622 FormStructure form_structure1(form1); 2628 FormStructure form_structure1(form1);
2623 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); 2629 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2624 std::unique_ptr<CreditCard> imported_credit_card; 2630 std::unique_ptr<CreditCard> imported_credit_card;
2625 bool imported_credit_card_matches_masked_server_credit_card; 2631 bool imported_credit_card_matches_masked_server_credit_card;
2626 EXPECT_TRUE(ImportCreditCard( 2632 EXPECT_TRUE(ImportCreditCard(
2627 form_structure1, false, &imported_credit_card, 2633 form_structure1, false, &imported_credit_card,
2628 &imported_credit_card_matches_masked_server_credit_card)); 2634 &imported_credit_card_matches_masked_server_credit_card));
2629 ASSERT_TRUE(imported_credit_card); 2635 ASSERT_TRUE(imported_credit_card);
2630 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2636 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2631 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2637 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2632 2638
2633 // Verify that the web database has been updated and the notification sent. 2639 // Verify that the web database has been updated and the notification sent.
2634 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2640 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2635 .WillOnce(QuitMainMessageLoop()); 2641 .WillOnce(QuitMainMessageLoop());
2636 base::RunLoop().Run(); 2642 base::RunLoop().Run();
2637 2643
2638 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2644 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2639 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2645 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2640 "2998"); 2646 "2998", ""); // Imported cards have not billing info.
2641 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2647 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2642 ASSERT_EQ(1U, results.size()); 2648 ASSERT_EQ(1U, results.size());
2643 EXPECT_EQ(0, expected.Compare(*results[0])); 2649 EXPECT_EQ(0, expected.Compare(*results[0]));
2644 2650
2645 // Add a second credit card with no number. 2651 // Add a second credit card with no number.
2646 FormData form2; 2652 FormData form2;
2647 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", 2653 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01",
2648 "2999"); 2654 "2999");
2649 2655
2650 FormStructure form_structure2(form2); 2656 FormStructure form_structure2(form2);
2651 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); 2657 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2652 std::unique_ptr<CreditCard> imported_credit_card2; 2658 std::unique_ptr<CreditCard> imported_credit_card2;
2653 EXPECT_FALSE(ImportCreditCard( 2659 EXPECT_FALSE(ImportCreditCard(
2654 form_structure2, false, &imported_credit_card2, 2660 form_structure2, false, &imported_credit_card2,
2655 &imported_credit_card_matches_masked_server_credit_card)); 2661 &imported_credit_card_matches_masked_server_credit_card));
2656 EXPECT_FALSE(imported_credit_card2); 2662 EXPECT_FALSE(imported_credit_card2);
2657 2663
2658 // Since no refresh is expected, reload the data from the database to make 2664 // Since no refresh is expected, reload the data from the database to make
2659 // sure no changes were written out. 2665 // sure no changes were written out.
2660 ResetPersonalDataManager(USER_MODE_NORMAL); 2666 ResetPersonalDataManager(USER_MODE_NORMAL);
2661 2667
2662 // No change is expected. 2668 // No change is expected.
2663 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2669 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2664 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2670 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2665 "2998"); 2671 "2998", "");
2666 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2672 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2667 ASSERT_EQ(1U, results2.size()); 2673 ASSERT_EQ(1U, results2.size());
2668 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2674 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2669 } 2675 }
2670 2676
2671 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { 2677 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) {
2672 // Start with a single valid credit card form. 2678 // Start with a single valid credit card form.
2673 FormData form1; 2679 FormData form1;
2674 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2680 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2675 "2999"); 2681 "2999");
2676 2682
2677 FormStructure form_structure1(form1); 2683 FormStructure form_structure1(form1);
2678 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); 2684 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */);
2679 std::unique_ptr<CreditCard> imported_credit_card; 2685 std::unique_ptr<CreditCard> imported_credit_card;
2680 bool imported_credit_card_matches_masked_server_credit_card; 2686 bool imported_credit_card_matches_masked_server_credit_card;
2681 EXPECT_TRUE(ImportCreditCard( 2687 EXPECT_TRUE(ImportCreditCard(
2682 form_structure1, false, &imported_credit_card, 2688 form_structure1, false, &imported_credit_card,
2683 &imported_credit_card_matches_masked_server_credit_card)); 2689 &imported_credit_card_matches_masked_server_credit_card));
2684 ASSERT_TRUE(imported_credit_card); 2690 ASSERT_TRUE(imported_credit_card);
2685 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card); 2691 EXPECT_FALSE(imported_credit_card_matches_masked_server_credit_card);
2686 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2692 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2687 2693
2688 // Verify that the web database has been updated and the notification sent. 2694 // Verify that the web database has been updated and the notification sent.
2689 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2695 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2690 .WillOnce(QuitMainMessageLoop()); 2696 .WillOnce(QuitMainMessageLoop());
2691 base::RunLoop().Run(); 2697 base::RunLoop().Run();
2692 2698
2693 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2699 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2694 test::SetCreditCardInfo(&expected, 2700 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2695 "Biggie Smalls", "4111111111111111", "01", "2999"); 2701 "2999", "");
2696 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2702 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2697 ASSERT_EQ(1U, results.size()); 2703 ASSERT_EQ(1U, results.size());
2698 EXPECT_EQ(0, expected.Compare(*results[0])); 2704 EXPECT_EQ(0, expected.Compare(*results[0]));
2699 2705
2700 // Add a second different valid credit card where the name is missing but 2706 // Add a second different valid credit card where the name is missing but
2701 // the credit card number matches. 2707 // the credit card number matches.
2702 FormData form2; 2708 FormData form2;
2703 AddFullCreditCardForm(&form2, /* missing name */ nullptr, 2709 AddFullCreditCardForm(&form2, /* missing name */ nullptr,
2704 "4111-1111-1111-1111", "01", "2999"); 2710 "4111-1111-1111-1111", "01", "2999");
2705 2711
2706 FormStructure form_structure2(form2); 2712 FormStructure form_structure2(form2);
2707 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); 2713 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */);
2708 std::unique_ptr<CreditCard> imported_credit_card2; 2714 std::unique_ptr<CreditCard> imported_credit_card2;
2709 EXPECT_TRUE(ImportCreditCard( 2715 EXPECT_TRUE(ImportCreditCard(
2710 form_structure2, false, &imported_credit_card2, 2716 form_structure2, false, &imported_credit_card2,
2711 &imported_credit_card_matches_masked_server_credit_card)); 2717 &imported_credit_card_matches_masked_server_credit_card));
2712 EXPECT_FALSE(imported_credit_card2); 2718 EXPECT_FALSE(imported_credit_card2);
2713 2719
2714 // Since no refresh is expected, reload the data from the database to make 2720 // Since no refresh is expected, reload the data from the database to make
2715 // sure no changes were written out. 2721 // sure no changes were written out.
2716 ResetPersonalDataManager(USER_MODE_NORMAL); 2722 ResetPersonalDataManager(USER_MODE_NORMAL);
2717 2723
2718 // No change is expected. 2724 // No change is expected.
2719 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2725 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2720 test::SetCreditCardInfo(&expected2, 2726 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2721 "Biggie Smalls", "4111111111111111", "01", "2999"); 2727 "2999", "");
2722 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2728 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2723 ASSERT_EQ(1U, results2.size()); 2729 ASSERT_EQ(1U, results2.size());
2724 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2730 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2725 2731
2726 // Add a third credit card where the expiration date is missing. 2732 // Add a third credit card where the expiration date is missing.
2727 FormData form3; 2733 FormData form3;
2728 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", 2734 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444",
2729 /* no month */ nullptr, 2735 /* no month */ nullptr,
2730 /* no year */ nullptr); 2736 /* no year */ nullptr);
2731 2737
2732 FormStructure form_structure3(form3); 2738 FormStructure form_structure3(form3);
2733 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */); 2739 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */);
2734 std::unique_ptr<CreditCard> imported_credit_card3; 2740 std::unique_ptr<CreditCard> imported_credit_card3;
2735 EXPECT_FALSE(ImportCreditCard( 2741 EXPECT_FALSE(ImportCreditCard(
2736 form_structure3, false, &imported_credit_card3, 2742 form_structure3, false, &imported_credit_card3,
2737 &imported_credit_card_matches_masked_server_credit_card)); 2743 &imported_credit_card_matches_masked_server_credit_card));
2738 ASSERT_FALSE(imported_credit_card3); 2744 ASSERT_FALSE(imported_credit_card3);
2739 2745
2740 // Since no refresh is expected, reload the data from the database to make 2746 // Since no refresh is expected, reload the data from the database to make
2741 // sure no changes were written out. 2747 // sure no changes were written out.
2742 ResetPersonalDataManager(USER_MODE_NORMAL); 2748 ResetPersonalDataManager(USER_MODE_NORMAL);
2743 2749
2744 // No change is expected. 2750 // No change is expected.
2745 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); 2751 CreditCard expected3(base::GenerateGUID(), "https://www.example.com");
2746 test::SetCreditCardInfo(&expected3, 2752 test::SetCreditCardInfo(&expected3, "Biggie Smalls", "4111111111111111", "01",
2747 "Biggie Smalls", "4111111111111111", "01", "2999"); 2753 "2999", "");
2748 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); 2754 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards();
2749 ASSERT_EQ(1U, results3.size()); 2755 ASSERT_EQ(1U, results3.size());
2750 EXPECT_EQ(0, expected3.Compare(*results3[0])); 2756 EXPECT_EQ(0, expected3.Compare(*results3[0]));
2751 } 2757 }
2752 2758
2753 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInOld) { 2759 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInOld) {
2754 // Start with a single valid credit card stored via the preferences. 2760 // Start with a single valid credit card stored via the preferences.
2755 // Note the empty name. 2761 // Note the empty name.
2756 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); 2762 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com");
2757 test::SetCreditCardInfo(&saved_credit_card, "", "4111111111111111" /* Visa */, 2763 test::SetCreditCardInfo(&saved_credit_card, "", "4111111111111111" /* Visa */,
2758 "01", "2998"); 2764 "01", "2998", "1");
2759 personal_data_->AddCreditCard(saved_credit_card); 2765 personal_data_->AddCreditCard(saved_credit_card);
2760 2766
2761 // Verify that the web database has been updated and the notification sent. 2767 // Verify that the web database has been updated and the notification sent.
2762 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2768 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2763 .WillOnce(QuitMainMessageLoop()); 2769 .WillOnce(QuitMainMessageLoop());
2764 base::RunLoop().Run(); 2770 base::RunLoop().Run();
2765 2771
2766 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); 2772 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards();
2767 ASSERT_EQ(1U, results1.size()); 2773 ASSERT_EQ(1U, results1.size());
2768 EXPECT_EQ(saved_credit_card, *results1[0]); 2774 EXPECT_EQ(saved_credit_card, *results1[0]);
(...skipping 15 matching lines...) Expand all
2784 2790
2785 // Verify that the web database has been updated and the notification sent. 2791 // Verify that the web database has been updated and the notification sent.
2786 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2792 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2787 .WillOnce(QuitMainMessageLoop()); 2793 .WillOnce(QuitMainMessageLoop());
2788 base::RunLoop().Run(); 2794 base::RunLoop().Run();
2789 2795
2790 // Expect that the newer information is saved. In this case the year is 2796 // Expect that the newer information is saved. In this case the year is
2791 // added to the existing credit card. 2797 // added to the existing credit card.
2792 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2798 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2793 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2799 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2794 "2999"); 2800 "2999", "1");
2795 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2801 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2796 ASSERT_EQ(1U, results2.size()); 2802 ASSERT_EQ(1U, results2.size());
2797 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2803 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2798 } 2804 }
2799 2805
2800 // We allow the user to store a credit card number with separators via the UI. 2806 // We allow the user to store a credit card number with separators via the UI.
2801 // We should not try to re-aggregate the same card with the separators stripped. 2807 // We should not try to re-aggregate the same card with the separators stripped.
2802 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) { 2808 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) {
2803 // Start with a single valid credit card stored via the preferences. 2809 // Start with a single valid credit card stored via the preferences.
2804 // Note the separators in the credit card number. 2810 // Note the separators in the credit card number.
2805 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); 2811 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com");
2806 test::SetCreditCardInfo(&saved_credit_card, 2812 test::SetCreditCardInfo(&saved_credit_card, "Biggie Smalls",
2807 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 2813 "4111 1111 1111 1111" /* Visa */, "01", "2999", "");
2808 personal_data_->AddCreditCard(saved_credit_card); 2814 personal_data_->AddCreditCard(saved_credit_card);
2809 2815
2810 // Verify that the web database has been updated and the notification sent. 2816 // Verify that the web database has been updated and the notification sent.
2811 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2817 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2812 .WillOnce(QuitMainMessageLoop()); 2818 .WillOnce(QuitMainMessageLoop());
2813 base::RunLoop().Run(); 2819 base::RunLoop().Run();
2814 2820
2815 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); 2821 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards();
2816 ASSERT_EQ(1U, results1.size()); 2822 ASSERT_EQ(1U, results1.size());
2817 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); 2823 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0]));
(...skipping 22 matching lines...) Expand all
2840 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); 2846 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0]));
2841 } 2847 }
2842 2848
2843 // Ensure that if a verified credit card already exists, aggregated credit cards 2849 // Ensure that if a verified credit card already exists, aggregated credit cards
2844 // cannot modify it in any way. 2850 // cannot modify it in any way.
2845 TEST_F(PersonalDataManagerTest, 2851 TEST_F(PersonalDataManagerTest,
2846 ImportCreditCard_ExistingVerifiedCardWithConflict) { 2852 ImportCreditCard_ExistingVerifiedCardWithConflict) {
2847 // Start with a verified credit card. 2853 // Start with a verified credit card.
2848 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); 2854 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin);
2849 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", 2855 test::SetCreditCardInfo(&credit_card, "Biggie Smalls",
2850 "4111 1111 1111 1111" /* Visa */, "01", "2998"); 2856 "4111 1111 1111 1111" /* Visa */, "01", "2998", "");
2851 EXPECT_TRUE(credit_card.IsVerified()); 2857 EXPECT_TRUE(credit_card.IsVerified());
2852 2858
2853 // Add the credit card to the database. 2859 // Add the credit card to the database.
2854 personal_data_->AddCreditCard(credit_card); 2860 personal_data_->AddCreditCard(credit_card);
2855 2861
2856 // Verify that the web database has been updated and the notification sent. 2862 // Verify that the web database has been updated and the notification sent.
2857 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2863 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2858 .WillOnce(QuitMainMessageLoop()); 2864 .WillOnce(QuitMainMessageLoop());
2859 base::RunLoop().Run(); 2865 base::RunLoop().Run();
2860 2866
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2936 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 2942 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
2937 "San Francisco", "California", "94102", NULL, NULL); 2943 "San Francisco", "California", "94102", NULL, NULL);
2938 const std::vector<AutofillProfile*>& results_addr = 2944 const std::vector<AutofillProfile*>& results_addr =
2939 personal_data_->GetProfiles(); 2945 personal_data_->GetProfiles();
2940 ASSERT_EQ(1U, results_addr.size()); 2946 ASSERT_EQ(1U, results_addr.size());
2941 EXPECT_EQ(0, expected_address.Compare(*results_addr[0])); 2947 EXPECT_EQ(0, expected_address.Compare(*results_addr[0]));
2942 2948
2943 // Test that the credit card has also been saved. 2949 // Test that the credit card has also been saved.
2944 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); 2950 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com");
2945 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", 2951 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111",
2946 "01", "2999"); 2952 "01", "2999", "");
2947 const std::vector<CreditCard*>& results_cards = 2953 const std::vector<CreditCard*>& results_cards =
2948 personal_data_->GetCreditCards(); 2954 personal_data_->GetCreditCards();
2949 ASSERT_EQ(1U, results_cards.size()); 2955 ASSERT_EQ(1U, results_cards.size());
2950 EXPECT_EQ(0, expected_card.Compare(*results_cards[0])); 2956 EXPECT_EQ(0, expected_card.Compare(*results_cards[0]));
2951 } 2957 }
2952 2958
2953 // Test that a form with two address sections and a credit card section does not 2959 // Test that a form with two address sections and a credit card section does not
2954 // import the address but does import the credit card. 2960 // import the address but does import the credit card.
2955 TEST_F(PersonalDataManagerTest, ImportFormData_TwoAddressesOneCreditCard) { 2961 TEST_F(PersonalDataManagerTest, ImportFormData_TwoAddressesOneCreditCard) {
2956 FormData form; 2962 FormData form;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3010 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3016 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3011 .WillOnce(QuitMainMessageLoop()); 3017 .WillOnce(QuitMainMessageLoop());
3012 base::RunLoop().Run(); 3018 base::RunLoop().Run();
3013 3019
3014 // Test that both addresses have been saved. 3020 // Test that both addresses have been saved.
3015 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 3021 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
3016 3022
3017 // Test that the credit card has been saved. 3023 // Test that the credit card has been saved.
3018 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); 3024 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com");
3019 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", 3025 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111",
3020 "01", "2999"); 3026 "01", "2999", "");
3021 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 3027 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
3022 ASSERT_EQ(1U, results.size()); 3028 ASSERT_EQ(1U, results.size());
3023 EXPECT_EQ(0, expected_card.Compare(*results[0])); 3029 EXPECT_EQ(0, expected_card.Compare(*results[0]));
3024 } 3030 }
3025 3031
3026 // Ensure that verified profiles can be saved via SaveImportedProfile, 3032 // Ensure that verified profiles can be saved via SaveImportedProfile,
3027 // overwriting existing unverified profiles. 3033 // overwriting existing unverified profiles.
3028 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { 3034 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) {
3029 // Start with an unverified profile. 3035 // Start with an unverified profile.
3030 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); 3036 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, 3071 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
3066 base::ASCIIToUTF16("+1 234-567-8910")); 3072 base::ASCIIToUTF16("+1 234-567-8910"));
3067 EXPECT_EQ(0, expected.Compare(*results[0])) 3073 EXPECT_EQ(0, expected.Compare(*results[0]))
3068 << "result = {" << *results[0] << "} | expected = {" << expected << "}"; 3074 << "result = {" << *results[0] << "} | expected = {" << expected << "}";
3069 } 3075 }
3070 3076
3071 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. 3077 // Ensure that verified credit cards can be saved via SaveImportedCreditCard.
3072 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { 3078 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) {
3073 // Start with a verified credit card. 3079 // Start with a verified credit card.
3074 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); 3080 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin);
3075 test::SetCreditCardInfo(&credit_card, 3081 test::SetCreditCardInfo(&credit_card, "Biggie Smalls",
3076 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 3082 "4111 1111 1111 1111" /* Visa */, "01", "2999", "");
3077 EXPECT_TRUE(credit_card.IsVerified()); 3083 EXPECT_TRUE(credit_card.IsVerified());
3078 3084
3079 // Add the credit card to the database. 3085 // Add the credit card to the database.
3080 personal_data_->AddCreditCard(credit_card); 3086 personal_data_->AddCreditCard(credit_card);
3081 3087
3082 // Verify that the web database has been updated and the notification sent. 3088 // Verify that the web database has been updated and the notification sent.
3083 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3089 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3084 .WillOnce(QuitMainMessageLoop()); 3090 .WillOnce(QuitMainMessageLoop());
3085 base::RunLoop().Run(); 3091 base::RunLoop().Run();
3086 3092
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3180 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); 3186 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
3181 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); 3187 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
3182 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); 3188 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
3183 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); 3189 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
3184 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); 3190 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
3185 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); 3191 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
3186 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); 3192 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
3187 3193
3188 // Test with credit card information also stored. 3194 // Test with credit card information also stored.
3189 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); 3195 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com");
3190 test::SetCreditCardInfo(&credit_card, 3196 test::SetCreditCardInfo(&credit_card, "John Dillinger",
3191 "John Dillinger", "423456789012" /* Visa */, 3197 "423456789012" /* Visa */, "01", "2999", "");
3192 "01", "2999");
3193 personal_data_->AddCreditCard(credit_card); 3198 personal_data_->AddCreditCard(credit_card);
3194 3199
3195 // Verify that the web database has been updated and the notification sent. 3200 // Verify that the web database has been updated and the notification sent.
3196 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3201 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3197 .WillOnce(QuitMainMessageLoop()); 3202 .WillOnce(QuitMainMessageLoop());
3198 base::RunLoop().Run(); 3203 base::RunLoop().Run();
3199 3204
3200 personal_data_->GetNonEmptyTypes(&non_empty_types); 3205 personal_data_->GetNonEmptyTypes(&non_empty_types);
3201 EXPECT_EQ(29U, non_empty_types.size()); 3206 EXPECT_EQ(29U, non_empty_types.size());
3202 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); 3207 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3234 ASSERT_TRUE(personal_data_->GetProfiles().empty()); 3239 ASSERT_TRUE(personal_data_->GetProfiles().empty());
3235 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); 3240 ASSERT_TRUE(personal_data_->GetCreditCards().empty());
3236 3241
3237 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com"); 3242 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com");
3238 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", 3243 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com",
3239 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", 3244 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014",
3240 "US", "(800) 275-2273"); 3245 "US", "(800) 275-2273");
3241 personal_data_->AddProfile(steve_jobs); 3246 personal_data_->AddProfile(steve_jobs);
3242 3247
3243 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); 3248 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com");
3244 test::SetCreditCardInfo( 3249 test::SetCreditCardInfo(&bill_gates, "William H. Gates", "5555555555554444",
3245 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); 3250 "1", "2020", "1");
3246 personal_data_->AddCreditCard(bill_gates); 3251 personal_data_->AddCreditCard(bill_gates);
3247 3252
3248 // The personal data manager should be able to read existing profiles in an 3253 // The personal data manager should be able to read existing profiles in an
3249 // off-the-record context. 3254 // off-the-record context.
3250 ResetPersonalDataManager(USER_MODE_INCOGNITO); 3255 ResetPersonalDataManager(USER_MODE_INCOGNITO);
3251 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); 3256 ASSERT_EQ(1U, personal_data_->GetProfiles().size());
3252 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); 3257 ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
3253 3258
3254 // No adds, saves, or updates should take effect. 3259 // No adds, saves, or updates should take effect.
3255 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); 3260 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0);
3256 3261
3257 // Add profiles or credit card shouldn't work. 3262 // Add profiles or credit card shouldn't work.
3258 personal_data_->AddProfile(test::GetFullProfile()); 3263 personal_data_->AddProfile(test::GetFullProfile());
3259 3264
3260 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); 3265 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com");
3261 test::SetCreditCardInfo( 3266 test::SetCreditCardInfo(&larry_page, "Lawrence Page", "4111111111111111",
3262 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); 3267 "10", "2025", "1");
3263 personal_data_->AddCreditCard(larry_page); 3268 personal_data_->AddCreditCard(larry_page);
3264 3269
3265 ResetPersonalDataManager(USER_MODE_INCOGNITO); 3270 ResetPersonalDataManager(USER_MODE_INCOGNITO);
3266 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); 3271 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
3267 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); 3272 EXPECT_EQ(1U, personal_data_->GetCreditCards().size());
3268 3273
3269 // Saving or creating profiles from imported profiles shouldn't work. 3274 // Saving or creating profiles from imported profiles shouldn't work.
3270 steve_jobs.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Steve")); 3275 steve_jobs.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Steve"));
3271 personal_data_->SaveImportedProfile(steve_jobs); 3276 personal_data_->SaveImportedProfile(steve_jobs);
3272 3277
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 // Test that a masked server card is not suggested if more that six numbers have 3617 // Test that a masked server card is not suggested if more that six numbers have
3613 // been typed in the field. 3618 // been typed in the field.
3614 TEST_F(PersonalDataManagerTest, 3619 TEST_F(PersonalDataManagerTest,
3615 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { 3620 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) {
3616 EnableWalletCardImport(); 3621 EnableWalletCardImport();
3617 3622
3618 // Add a masked server card. 3623 // Add a masked server card.
3619 std::vector<CreditCard> server_cards; 3624 std::vector<CreditCard> server_cards;
3620 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); 3625 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459"));
3621 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", 3626 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12",
3622 "2999"); 3627 "2999", "1");
3623 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 3628 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3624 3629
3625 test::SetServerCreditCards(autofill_table_, server_cards); 3630 test::SetServerCreditCards(autofill_table_, server_cards);
3626 personal_data_->Refresh(); 3631 personal_data_->Refresh();
3627 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3632 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3628 .WillOnce(QuitMainMessageLoop()); 3633 .WillOnce(QuitMainMessageLoop());
3629 base::RunLoop().Run(); 3634 base::RunLoop().Run();
3630 3635
3631 std::vector<Suggestion> suggestions = 3636 std::vector<Suggestion> suggestions =
3632 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), 3637 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER),
(...skipping 30 matching lines...) Expand all
3663 // Test that local and server cards are ordered as expected. 3668 // Test that local and server cards are ordered as expected.
3664 TEST_F(PersonalDataManagerTest, 3669 TEST_F(PersonalDataManagerTest,
3665 GetCreditCardSuggestions_LocalAndServerCardsRanking) { 3670 GetCreditCardSuggestions_LocalAndServerCardsRanking) {
3666 EnableWalletCardImport(); 3671 EnableWalletCardImport();
3667 SetupReferenceLocalCreditCards(); 3672 SetupReferenceLocalCreditCards();
3668 3673
3669 // Add some server cards. 3674 // Add some server cards.
3670 std::vector<CreditCard> server_cards; 3675 std::vector<CreditCard> server_cards;
3671 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); 3676 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459"));
3672 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", 3677 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12",
3673 "2999"); 3678 "2999", "1");
3674 server_cards.back().set_use_count(2); 3679 server_cards.back().set_use_count(2);
3675 server_cards.back().set_use_date(AutofillClock::Now() - 3680 server_cards.back().set_use_date(AutofillClock::Now() -
3676 base::TimeDelta::FromDays(1)); 3681 base::TimeDelta::FromDays(1));
3677 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 3682 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3678 3683
3679 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); 3684 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460"));
3680 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", 3685 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12",
3681 "2999"); 3686 "2999", "1");
3682 server_cards.back().set_use_count(6); 3687 server_cards.back().set_use_count(6);
3683 server_cards.back().set_use_date(AutofillClock::Now() - 3688 server_cards.back().set_use_date(AutofillClock::Now() -
3684 base::TimeDelta::FromDays(1)); 3689 base::TimeDelta::FromDays(1));
3685 3690
3686 test::SetServerCreditCards(autofill_table_, server_cards); 3691 test::SetServerCreditCards(autofill_table_, server_cards);
3687 personal_data_->Refresh(); 3692 personal_data_->Refresh();
3688 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3693 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3689 .WillOnce(QuitMainMessageLoop()); 3694 .WillOnce(QuitMainMessageLoop());
3690 base::RunLoop().Run(); 3695 base::RunLoop().Run();
3691 3696
(...skipping 13 matching lines...) Expand all
3705 3710
3706 // Test that expired cards are ordered by frecency and are always suggested 3711 // Test that expired cards are ordered by frecency and are always suggested
3707 // after non expired cards even if they have a higher frecency score. 3712 // after non expired cards even if they have a higher frecency score.
3708 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) { 3713 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) {
3709 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3714 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3710 3715
3711 // Add a never used non expired credit card. 3716 // Add a never used non expired credit card.
3712 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B", 3717 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B",
3713 "https://www.example.com"); 3718 "https://www.example.com");
3714 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker", 3719 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker",
3715 "518765432109" /* Mastercard */, "04", "2999"); 3720 "518765432109" /* Mastercard */, "04", "2999", "1");
3716 personal_data_->AddCreditCard(credit_card0); 3721 personal_data_->AddCreditCard(credit_card0);
3717 3722
3718 // Add an expired card with a higher frecency score. 3723 // Add an expired card with a higher frecency score.
3719 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15", 3724 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15",
3720 "https://www.example.com"); 3725 "https://www.example.com");
3721 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", 3726 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
3722 "347666888555" /* American Express */, "04", "1999"); 3727 "347666888555" /* American Express */, "04", "1999",
3728 "1");
3723 credit_card1.set_use_count(300); 3729 credit_card1.set_use_count(300);
3724 credit_card1.set_use_date(AutofillClock::Now() - 3730 credit_card1.set_use_date(AutofillClock::Now() -
3725 base::TimeDelta::FromDays(10)); 3731 base::TimeDelta::FromDays(10));
3726 personal_data_->AddCreditCard(credit_card1); 3732 personal_data_->AddCreditCard(credit_card1);
3727 3733
3728 // Add an expired card with a lower frecency score. 3734 // Add an expired card with a lower frecency score.
3729 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", 3735 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B",
3730 "https://www.example.com"); 3736 "https://www.example.com");
3731 credit_card2.set_use_count(3); 3737 credit_card2.set_use_count(3);
3732 credit_card2.set_use_date(AutofillClock::Now() - 3738 credit_card2.set_use_date(AutofillClock::Now() -
3733 base::TimeDelta::FromDays(1)); 3739 base::TimeDelta::FromDays(1));
3734 test::SetCreditCardInfo(&credit_card2, "John Dillinger", 3740 test::SetCreditCardInfo(&credit_card2, "John Dillinger",
3735 "423456789012" /* Visa */, "01", "1998"); 3741 "423456789012" /* Visa */, "01", "1998", "1");
3736 personal_data_->AddCreditCard(credit_card2); 3742 personal_data_->AddCreditCard(credit_card2);
3737 3743
3738 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3744 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3739 .WillOnce(QuitMainMessageLoop()); 3745 .WillOnce(QuitMainMessageLoop());
3740 base::RunLoop().Run(); 3746 base::RunLoop().Run();
3741 3747
3742 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3748 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3743 3749
3744 std::vector<Suggestion> suggestions = 3750 std::vector<Suggestion> suggestions =
3745 personal_data_->GetCreditCardSuggestions( 3751 personal_data_->GetCreditCardSuggestions(
(...skipping 11 matching lines...) Expand all
3757 3763
3758 // Test that a card that doesn't have a number is not shown in the suggestions 3764 // Test that a card that doesn't have a number is not shown in the suggestions
3759 // when querying credit cards by their number. 3765 // when querying credit cards by their number.
3760 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { 3766 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) {
3761 // Create one normal credit card and one credit card with the number missing. 3767 // Create one normal credit card and one credit card with the number missing.
3762 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3768 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3763 3769
3764 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", 3770 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15",
3765 "https://www.example.com"); 3771 "https://www.example.com");
3766 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", 3772 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow",
3767 "347666888555" /* American Express */, "04", "2999"); 3773 "347666888555" /* American Express */, "04", "2999",
3774 "1");
3768 credit_card0.set_use_count(3); 3775 credit_card0.set_use_count(3);
3769 credit_card0.set_use_date(AutofillClock::Now() - 3776 credit_card0.set_use_date(AutofillClock::Now() -
3770 base::TimeDelta::FromDays(1)); 3777 base::TimeDelta::FromDays(1));
3771 personal_data_->AddCreditCard(credit_card0); 3778 personal_data_->AddCreditCard(credit_card0);
3772 3779
3773 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", 3780 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
3774 "https://www.example.com"); 3781 "https://www.example.com");
3775 credit_card1.set_use_count(300); 3782 credit_card1.set_use_count(300);
3776 credit_card1.set_use_date(AutofillClock::Now() - 3783 credit_card1.set_use_date(AutofillClock::Now() -
3777 base::TimeDelta::FromDays(10)); 3784 base::TimeDelta::FromDays(10));
3778 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); 3785 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999",
3786 "1");
3779 personal_data_->AddCreditCard(credit_card1); 3787 personal_data_->AddCreditCard(credit_card1);
3780 3788
3781 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3789 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3782 .WillOnce(QuitMainMessageLoop()); 3790 .WillOnce(QuitMainMessageLoop());
3783 base::RunLoop().Run(); 3791 base::RunLoop().Run();
3784 3792
3785 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); 3793 ASSERT_EQ(2U, personal_data_->GetCreditCards().size());
3786 3794
3787 // Sublabel is expiration date when filling card number. The second card 3795 // Sublabel is expiration date when filling card number. The second card
3788 // doesn't have a number so it should not be included in the suggestions. 3796 // doesn't have a number so it should not be included in the suggestions.
(...skipping 14 matching lines...) Expand all
3803 SetupReferenceLocalCreditCards(); 3811 SetupReferenceLocalCreditCards();
3804 3812
3805 // Add some server cards. If there are local dupes, the locals should be 3813 // Add some server cards. If there are local dupes, the locals should be
3806 // hidden. 3814 // hidden.
3807 std::vector<CreditCard> server_cards; 3815 std::vector<CreditCard> server_cards;
3808 // This server card matches a local card, except the local card is missing the 3816 // This server card matches a local card, except the local card is missing the
3809 // number. This should count as a dupe and thus not be shown in the 3817 // number. This should count as a dupe and thus not be shown in the
3810 // suggestions since the locally saved card takes precedence. 3818 // suggestions since the locally saved card takes precedence.
3811 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 3819 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
3812 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 3820 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
3813 "9012" /* Visa */, "01", "2999"); 3821 "9012" /* Visa */, "01", "2999", "1");
3814 server_cards.back().set_use_count(2); 3822 server_cards.back().set_use_count(2);
3815 server_cards.back().set_use_date(AutofillClock::Now() - 3823 server_cards.back().set_use_date(AutofillClock::Now() -
3816 base::TimeDelta::FromDays(15)); 3824 base::TimeDelta::FromDays(15));
3817 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 3825 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3818 3826
3819 // This server card is identical to a local card, but has a different 3827 // This server card is identical to a local card, but has a different
3820 // card type. Not a dupe and therefore both should appear in the suggestions. 3828 // card type. Not a dupe and therefore both should appear in the suggestions.
3821 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); 3829 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
3822 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", 3830 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12",
3823 "2999"); 3831 "2999", "1");
3824 server_cards.back().set_use_count(3); 3832 server_cards.back().set_use_count(3);
3825 server_cards.back().set_use_date(AutofillClock::Now() - 3833 server_cards.back().set_use_date(AutofillClock::Now() -
3826 base::TimeDelta::FromDays(15)); 3834 base::TimeDelta::FromDays(15));
3827 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 3835 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3828 3836
3829 // This unmasked server card is an exact dupe of a local card. Therefore only 3837 // This unmasked server card is an exact dupe of a local card. Therefore only
3830 // this card should appear in the suggestions as full server cards have 3838 // this card should appear in the suggestions as full server cards have
3831 // precedence over local cards. 3839 // precedence over local cards.
3832 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 3840 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
3833 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3841 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3834 "347666888555" /* American Express */, "04", "2999"); 3842 "347666888555" /* American Express */, "04", "2999",
3843 "1");
3835 server_cards.back().set_use_count(1); 3844 server_cards.back().set_use_count(1);
3836 server_cards.back().set_use_date(AutofillClock::Now() - 3845 server_cards.back().set_use_date(AutofillClock::Now() -
3837 base::TimeDelta::FromDays(15)); 3846 base::TimeDelta::FromDays(15));
3838 3847
3839 test::SetServerCreditCards(autofill_table_, server_cards); 3848 test::SetServerCreditCards(autofill_table_, server_cards);
3840 personal_data_->Refresh(); 3849 personal_data_->Refresh();
3841 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3850 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3842 .WillOnce(QuitMainMessageLoop()); 3851 .WillOnce(QuitMainMessageLoop());
3843 base::RunLoop().Run(); 3852 base::RunLoop().Run();
3844 3853
(...skipping 29 matching lines...) Expand all
3874 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { 3883 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) {
3875 EnableWalletCardImport(); 3884 EnableWalletCardImport();
3876 SetupReferenceLocalCreditCards(); 3885 SetupReferenceLocalCreditCards();
3877 3886
3878 // Add a duplicate server card. 3887 // Add a duplicate server card.
3879 std::vector<CreditCard> server_cards; 3888 std::vector<CreditCard> server_cards;
3880 // This unmasked server card is an exact dupe of a local card. Therefore only 3889 // This unmasked server card is an exact dupe of a local card. Therefore only
3881 // the local card should appear in the suggestions. 3890 // the local card should appear in the suggestions.
3882 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 3891 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
3883 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3892 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3884 "347666888555" /* American Express */, "04", "2999"); 3893 "347666888555" /* American Express */, "04", "2999",
3894 "1");
3885 3895
3886 test::SetServerCreditCards(autofill_table_, server_cards); 3896 test::SetServerCreditCards(autofill_table_, server_cards);
3887 personal_data_->Refresh(); 3897 personal_data_->Refresh();
3888 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3898 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3889 .WillOnce(QuitMainMessageLoop()); 3899 .WillOnce(QuitMainMessageLoop());
3890 base::RunLoop().Run(); 3900 base::RunLoop().Run();
3891 3901
3892 std::vector<Suggestion> suggestions = 3902 std::vector<Suggestion> suggestions =
3893 personal_data_->GetCreditCardSuggestions( 3903 personal_data_->GetCreditCardSuggestions(
3894 AutofillType(CREDIT_CARD_NAME_FULL), 3904 AutofillType(CREDIT_CARD_NAME_FULL),
3895 /* field_contents= */ base::string16()); 3905 /* field_contents= */ base::string16());
3896 ASSERT_EQ(3U, suggestions.size()); 3906 ASSERT_EQ(3U, suggestions.size());
3897 3907
3898 // Add a second dupe local card to make sure a full server card can be a dupe 3908 // Add a second dupe local card to make sure a full server card can be a dupe
3899 // of more than one local card. 3909 // of more than one local card.
3900 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B", 3910 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B",
3901 "https://www.example.com"); 3911 "https://www.example.com");
3902 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", ""); 3912 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", "", "");
3903 personal_data_->AddCreditCard(credit_card3); 3913 personal_data_->AddCreditCard(credit_card3);
3904 3914
3905 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3915 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3906 .WillOnce(QuitMainMessageLoop()); 3916 .WillOnce(QuitMainMessageLoop());
3907 base::RunLoop().Run(); 3917 base::RunLoop().Run();
3908 3918
3909 suggestions = personal_data_->GetCreditCardSuggestions( 3919 suggestions = personal_data_->GetCreditCardSuggestions(
3910 AutofillType(CREDIT_CARD_NAME_FULL), 3920 AutofillType(CREDIT_CARD_NAME_FULL),
3911 /* field_contents= */ base::string16()); 3921 /* field_contents= */ base::string16());
3912 ASSERT_EQ(3U, suggestions.size()); 3922 ASSERT_EQ(3U, suggestions.size());
3913 } 3923 }
3914 3924
3915 // Tests that only the full server card is kept when deduping with a local 3925 // Tests that only the full server card is kept when deduping with a local
3916 // duplicate of it. 3926 // duplicate of it.
3917 TEST_F(PersonalDataManagerTest, 3927 TEST_F(PersonalDataManagerTest,
3918 DedupeCreditCardToSuggest_FullServerShadowsLocal) { 3928 DedupeCreditCardToSuggest_FullServerShadowsLocal) {
3919 std::list<CreditCard*> credit_cards; 3929 std::list<CreditCard*> credit_cards;
3920 3930
3921 // Create 3 different local credit cards. 3931 // Create 3 different local credit cards.
3922 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 3932 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
3923 "https://www.example.com"); 3933 "https://www.example.com");
3924 test::SetCreditCardInfo(&local_card, "Homer Simpson", 3934 test::SetCreditCardInfo(&local_card, "Homer Simpson",
3925 "423456789012" /* Visa */, "01", "2999"); 3935 "423456789012" /* Visa */, "01", "2999", "1");
3926 local_card.set_use_count(3); 3936 local_card.set_use_count(3);
3927 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); 3937 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
3928 credit_cards.push_back(&local_card); 3938 credit_cards.push_back(&local_card);
3929 3939
3930 // Create a full server card that is a duplicate of one of the local cards. 3940 // Create a full server card that is a duplicate of one of the local cards.
3931 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); 3941 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789");
3932 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", 3942 test::SetCreditCardInfo(&full_server_card, "Homer Simpson",
3933 "423456789012" /* Visa */, "01", "2999"); 3943 "423456789012" /* Visa */, "01", "2999", "1");
3934 full_server_card.set_use_count(1); 3944 full_server_card.set_use_count(1);
3935 full_server_card.set_use_date(AutofillClock::Now() - 3945 full_server_card.set_use_date(AutofillClock::Now() -
3936 base::TimeDelta::FromDays(15)); 3946 base::TimeDelta::FromDays(15));
3937 credit_cards.push_back(&full_server_card); 3947 credit_cards.push_back(&full_server_card);
3938 3948
3939 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); 3949 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
3940 ASSERT_EQ(1U, credit_cards.size()); 3950 ASSERT_EQ(1U, credit_cards.size());
3941 3951
3942 const CreditCard* deduped_card(credit_cards.front()); 3952 const CreditCard* deduped_card(credit_cards.front());
3943 EXPECT_TRUE(*deduped_card == full_server_card); 3953 EXPECT_TRUE(*deduped_card == full_server_card);
3944 } 3954 }
3945 3955
3946 // Tests that only the local card is kept when deduping with a masked server 3956 // Tests that only the local card is kept when deduping with a masked server
3947 // duplicate of it. 3957 // duplicate of it.
3948 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) { 3958 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) {
3949 std::list<CreditCard*> credit_cards; 3959 std::list<CreditCard*> credit_cards;
3950 3960
3951 CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B", 3961 CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B",
3952 "https://www.example.com"); 3962 "https://www.example.com");
3953 local_card.set_use_count(300); 3963 local_card.set_use_count(300);
3954 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(10)); 3964 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(10));
3955 test::SetCreditCardInfo(&local_card, "Homer Simpson", 3965 test::SetCreditCardInfo(&local_card, "Homer Simpson",
3956 "423456789012" /* Visa */, "01", "2999"); 3966 "423456789012" /* Visa */, "01", "2999", "1");
3957 credit_cards.push_back(&local_card); 3967 credit_cards.push_back(&local_card);
3958 3968
3959 // Create a masked server card that is a duplicate of a local card. 3969 // Create a masked server card that is a duplicate of a local card.
3960 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); 3970 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123");
3961 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, 3971 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */,
3962 "01", "2999"); 3972 "01", "2999", "1");
3963 masked_card.set_use_count(2); 3973 masked_card.set_use_count(2);
3964 masked_card.set_use_date(AutofillClock::Now() - 3974 masked_card.set_use_date(AutofillClock::Now() -
3965 base::TimeDelta::FromDays(15)); 3975 base::TimeDelta::FromDays(15));
3966 masked_card.SetNetworkForMaskedCard(kVisaCard); 3976 masked_card.SetNetworkForMaskedCard(kVisaCard);
3967 credit_cards.push_back(&masked_card); 3977 credit_cards.push_back(&masked_card);
3968 3978
3969 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); 3979 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
3970 ASSERT_EQ(1U, credit_cards.size()); 3980 ASSERT_EQ(1U, credit_cards.size());
3971 3981
3972 const CreditCard* deduped_card(credit_cards.front()); 3982 const CreditCard* deduped_card(credit_cards.front());
3973 EXPECT_TRUE(*deduped_card == local_card); 3983 EXPECT_TRUE(*deduped_card == local_card);
3974 } 3984 }
3975 3985
3976 // Tests that identical full server and masked credit cards are not deduped. 3986 // Tests that identical full server and masked credit cards are not deduped.
3977 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { 3987 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) {
3978 std::list<CreditCard*> credit_cards; 3988 std::list<CreditCard*> credit_cards;
3979 3989
3980 // Create a full server card that is a duplicate of one of the local cards. 3990 // Create a full server card that is a duplicate of one of the local cards.
3981 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); 3991 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789");
3982 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", 3992 test::SetCreditCardInfo(&full_server_card, "Homer Simpson",
3983 "423456789012" /* Visa */, "01", "2999"); 3993 "423456789012" /* Visa */, "01", "2999", "1");
3984 full_server_card.set_use_count(1); 3994 full_server_card.set_use_count(1);
3985 full_server_card.set_use_date(AutofillClock::Now() - 3995 full_server_card.set_use_date(AutofillClock::Now() -
3986 base::TimeDelta::FromDays(15)); 3996 base::TimeDelta::FromDays(15));
3987 credit_cards.push_back(&full_server_card); 3997 credit_cards.push_back(&full_server_card);
3988 3998
3989 // Create a masked server card that is a duplicate of a local card. 3999 // Create a masked server card that is a duplicate of a local card.
3990 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); 4000 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123");
3991 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, 4001 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */,
3992 "01", "2999"); 4002 "01", "2999", "1");
3993 masked_card.set_use_count(2); 4003 masked_card.set_use_count(2);
3994 masked_card.set_use_date(AutofillClock::Now() - 4004 masked_card.set_use_date(AutofillClock::Now() -
3995 base::TimeDelta::FromDays(15)); 4005 base::TimeDelta::FromDays(15));
3996 masked_card.SetNetworkForMaskedCard(kVisaCard); 4006 masked_card.SetNetworkForMaskedCard(kVisaCard);
3997 credit_cards.push_back(&masked_card); 4007 credit_cards.push_back(&masked_card);
3998 4008
3999 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); 4009 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
4000 EXPECT_EQ(2U, credit_cards.size()); 4010 EXPECT_EQ(2U, credit_cards.size());
4001 } 4011 }
4002 4012
4003 // Tests that slightly different local, full server, and masked credit cards are 4013 // Tests that slightly different local, full server, and masked credit cards are
4004 // not deduped. 4014 // not deduped.
4005 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { 4015 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) {
4006 std::list<CreditCard*> credit_cards; 4016 std::list<CreditCard*> credit_cards;
4007 4017
4008 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 4018 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
4009 "https://www.example.com"); 4019 "https://www.example.com");
4010 credit_card2.set_use_count(1); 4020 credit_card2.set_use_count(1);
4011 credit_card2.set_use_date(AutofillClock::Now() - 4021 credit_card2.set_use_date(AutofillClock::Now() -
4012 base::TimeDelta::FromDays(1)); 4022 base::TimeDelta::FromDays(1));
4013 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", 4023 test::SetCreditCardInfo(&credit_card2, "Homer Simpson",
4014 "518765432109" /* Mastercard */, "", ""); 4024 "518765432109" /* Mastercard */, "", "", "");
4015 credit_cards.push_back(&credit_card2); 4025 credit_cards.push_back(&credit_card2);
4016 4026
4017 // Create a masked server card that is slightly different of the local card. 4027 // Create a masked server card that is slightly different of the local card.
4018 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); 4028 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456");
4019 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); 4029 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999",
4030 "1");
4020 credit_card4.set_use_count(3); 4031 credit_card4.set_use_count(3);
4021 credit_card4.set_use_date(AutofillClock::Now() - 4032 credit_card4.set_use_date(AutofillClock::Now() -
4022 base::TimeDelta::FromDays(15)); 4033 base::TimeDelta::FromDays(15));
4023 credit_card4.SetNetworkForMaskedCard(kVisaCard); 4034 credit_card4.SetNetworkForMaskedCard(kVisaCard);
4024 credit_cards.push_back(&credit_card4); 4035 credit_cards.push_back(&credit_card4);
4025 4036
4026 // Create a full server card that is slightly different of the two other 4037 // Create a full server card that is slightly different of the two other
4027 // cards. 4038 // cards.
4028 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); 4039 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789");
4029 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", 4040 test::SetCreditCardInfo(&credit_card5, "Homer Simpson",
4030 "347666888555" /* American Express */, "04", "2999"); 4041 "347666888555" /* American Express */, "04", "2999",
4042 "1");
4031 credit_card5.set_use_count(1); 4043 credit_card5.set_use_count(1);
4032 credit_card5.set_use_date(AutofillClock::Now() - 4044 credit_card5.set_use_date(AutofillClock::Now() -
4033 base::TimeDelta::FromDays(15)); 4045 base::TimeDelta::FromDays(15));
4034 credit_cards.push_back(&credit_card5); 4046 credit_cards.push_back(&credit_card5);
4035 4047
4036 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); 4048 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
4037 EXPECT_EQ(3U, credit_cards.size()); 4049 EXPECT_EQ(3U, credit_cards.size());
4038 } 4050 }
4039 4051
4040 TEST_F(PersonalDataManagerTest, RecordUseOf) { 4052 TEST_F(PersonalDataManagerTest, RecordUseOf) {
4041 // Create the test clock and set the time to a specific value. 4053 // Create the test clock and set the time to a specific value.
4042 TestAutofillClock test_clock; 4054 TestAutofillClock test_clock;
4043 test_clock.SetNow(kArbitraryTime); 4055 test_clock.SetNow(kArbitraryTime);
4044 4056
4045 AutofillProfile profile(test::GetFullProfile()); 4057 AutofillProfile profile(test::GetFullProfile());
4046 EXPECT_EQ(1U, profile.use_count()); 4058 EXPECT_EQ(1U, profile.use_count());
4047 EXPECT_EQ(kArbitraryTime, profile.use_date()); 4059 EXPECT_EQ(kArbitraryTime, profile.use_date());
4048 EXPECT_EQ(kArbitraryTime, profile.modification_date()); 4060 EXPECT_EQ(kArbitraryTime, profile.modification_date());
4049 personal_data_->AddProfile(profile); 4061 personal_data_->AddProfile(profile);
4050 4062
4051 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); 4063 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com");
4052 test::SetCreditCardInfo(&credit_card, "John Dillinger", 4064 test::SetCreditCardInfo(&credit_card, "John Dillinger",
4053 "423456789012" /* Visa */, "01", "2999"); 4065 "423456789012" /* Visa */, "01", "2999", "1");
4054 EXPECT_EQ(1U, credit_card.use_count()); 4066 EXPECT_EQ(1U, credit_card.use_count());
4055 EXPECT_EQ(kArbitraryTime, credit_card.use_date()); 4067 EXPECT_EQ(kArbitraryTime, credit_card.use_date());
4056 EXPECT_EQ(kArbitraryTime, credit_card.modification_date()); 4068 EXPECT_EQ(kArbitraryTime, credit_card.modification_date());
4057 personal_data_->AddCreditCard(credit_card); 4069 personal_data_->AddCreditCard(credit_card);
4058 4070
4059 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4071 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4060 .WillOnce(QuitMainMessageLoop()); 4072 .WillOnce(QuitMainMessageLoop());
4061 base::RunLoop().Run(); 4073 base::RunLoop().Run();
4062 4074
4063 // Set the current time to another value. 4075 // Set the current time to another value.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4099 EXPECT_EQ(kSomeLaterTime, added_card->use_date()); 4111 EXPECT_EQ(kSomeLaterTime, added_card->use_date());
4100 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); 4112 EXPECT_EQ(kArbitraryTime, added_card->modification_date());
4101 } 4113 }
4102 4114
4103 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { 4115 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
4104 EnableWalletCardImport(); 4116 EnableWalletCardImport();
4105 4117
4106 std::vector<CreditCard> server_cards; 4118 std::vector<CreditCard> server_cards;
4107 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4119 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4108 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4120 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4109 "9012" /* Visa */, "01", "2999"); 4121 "9012" /* Visa */, "01", "2999", "1");
4110 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 4122 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4111 4123
4112 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); 4124 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
4113 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", 4125 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker",
4114 "4444" /* Mastercard */, "12", "2999"); 4126 "4444" /* Mastercard */, "12", "2999", "1");
4115 server_cards.back().SetNetworkForMaskedCard(kMasterCard); 4127 server_cards.back().SetNetworkForMaskedCard(kMasterCard);
4116 4128
4117 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 4129 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
4118 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 4130 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
4119 "347666888555" /* American Express */, "04", "2999"); 4131 "347666888555" /* American Express */, "04", "2999",
4132 "1");
4120 4133
4121 // Create the test clock and set the time to a specific value. 4134 // Create the test clock and set the time to a specific value.
4122 TestAutofillClock test_clock; 4135 TestAutofillClock test_clock;
4123 test_clock.SetNow(kArbitraryTime); 4136 test_clock.SetNow(kArbitraryTime);
4124 4137
4125 test::SetServerCreditCards(autofill_table_, server_cards); 4138 test::SetServerCreditCards(autofill_table_, server_cards);
4126 personal_data_->Refresh(); 4139 personal_data_->Refresh();
4127 4140
4128 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4141 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4129 .WillOnce(QuitMainMessageLoop()); 4142 .WillOnce(QuitMainMessageLoop());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4221 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 4234 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
4222 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); 4235 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count());
4223 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); 4236 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date());
4224 } 4237 }
4225 4238
4226 TEST_F(PersonalDataManagerTest, ClearAllServerData) { 4239 TEST_F(PersonalDataManagerTest, ClearAllServerData) {
4227 // Add a server card. 4240 // Add a server card.
4228 std::vector<CreditCard> server_cards; 4241 std::vector<CreditCard> server_cards;
4229 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4242 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4230 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4243 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4231 "9012" /* Visa */, "01", "2999"); 4244 "9012" /* Visa */, "01", "2999", "1");
4232 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 4245 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4233 test::SetServerCreditCards(autofill_table_, server_cards); 4246 test::SetServerCreditCards(autofill_table_, server_cards);
4234 personal_data_->Refresh(); 4247 personal_data_->Refresh();
4235 4248
4236 // Need to set the google services username 4249 // Need to set the google services username
4237 EnableWalletCardImport(); 4250 EnableWalletCardImport();
4238 4251
4239 // The card and profile should be there. 4252 // The card and profile should be there.
4240 ResetPersonalDataManager(USER_MODE_NORMAL); 4253 ResetPersonalDataManager(USER_MODE_NORMAL);
4241 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); 4254 EXPECT_FALSE(personal_data_->GetCreditCards().empty());
4242 4255
4243 personal_data_->ClearAllServerData(); 4256 personal_data_->ClearAllServerData();
4244 4257
4245 // Reload the database, everything should be gone. 4258 // Reload the database, everything should be gone.
4246 ResetPersonalDataManager(USER_MODE_NORMAL); 4259 ResetPersonalDataManager(USER_MODE_NORMAL);
4247 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); 4260 EXPECT_TRUE(personal_data_->GetCreditCards().empty());
4248 } 4261 }
4249 4262
4250 TEST_F(PersonalDataManagerTest, AllowDuplicateMaskedServerCard) { 4263 TEST_F(PersonalDataManagerTest, AllowDuplicateMaskedServerCard) {
4251 EnableWalletCardImport(); 4264 EnableWalletCardImport();
4252 4265
4253 std::vector<CreditCard> server_cards; 4266 std::vector<CreditCard> server_cards;
4254 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4267 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4255 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4268 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4256 "1881" /* Visa */, "01", "2999"); 4269 "1881" /* Visa */, "01", "2999", "");
4257 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 4270 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4258 4271
4259 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 4272 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
4260 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 4273 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
4261 "347666888555" /* American Express */, "04", "2999"); 4274 "347666888555" /* American Express */, "04", "2999",
4275 "");
4262 4276
4263 test::SetServerCreditCards(autofill_table_, server_cards); 4277 test::SetServerCreditCards(autofill_table_, server_cards);
4264 personal_data_->Refresh(); 4278 personal_data_->Refresh();
4265 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4279 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4266 .WillOnce(QuitMainMessageLoop()); 4280 .WillOnce(QuitMainMessageLoop());
4267 base::RunLoop().Run(); 4281 base::RunLoop().Run();
4268 4282
4269 // A valid credit card form. A user re-enters one of their masked cards. 4283 // A valid credit card form. A user re-enters one of their masked cards.
4270 // We should offer to save locally so that user can fill future credit card 4284 // We should offer to save locally so that user can fill future credit card
4271 // forms without unmasking. 4285 // forms without unmasking.
(...skipping 21 matching lines...) Expand all
4293 EXPECT_TRUE(imported_credit_card_matches_masked_server_credit_card); 4307 EXPECT_TRUE(imported_credit_card_matches_masked_server_credit_card);
4294 personal_data_->SaveImportedCreditCard(*imported_credit_card); 4308 personal_data_->SaveImportedCreditCard(*imported_credit_card);
4295 4309
4296 // Verify that the web database has been updated and the notification sent. 4310 // Verify that the web database has been updated and the notification sent.
4297 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4311 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4298 .WillOnce(QuitMainMessageLoop()); 4312 .WillOnce(QuitMainMessageLoop());
4299 base::RunLoop().Run(); 4313 base::RunLoop().Run();
4300 4314
4301 CreditCard local_card(base::GenerateGUID(), "https://www.example.com"); 4315 CreditCard local_card(base::GenerateGUID(), "https://www.example.com");
4302 test::SetCreditCardInfo(&local_card, "John Dillinger", "4012888888881881", 4316 test::SetCreditCardInfo(&local_card, "John Dillinger", "4012888888881881",
4303 "01", "2999"); 4317 "01", "2999", "");
4304 const std::vector<CreditCard*>& results = 4318 const std::vector<CreditCard*>& results =
4305 personal_data_->GetLocalCreditCards(); 4319 personal_data_->GetLocalCreditCards();
4306 ASSERT_EQ(1U, results.size()); 4320 ASSERT_EQ(1U, results.size());
4307 EXPECT_EQ(0, local_card.Compare(*results[0])); 4321 EXPECT_EQ(0, local_card.Compare(*results[0]));
4308 EXPECT_EQ(3U, personal_data_->GetCreditCards().size()); 4322 EXPECT_EQ(3U, personal_data_->GetCreditCards().size());
4309 } 4323 }
4310 4324
4311 TEST_F(PersonalDataManagerTest, DontDuplicateFullServerCard) { 4325 TEST_F(PersonalDataManagerTest, DontDuplicateFullServerCard) {
4312 EnableWalletCardImport(); 4326 EnableWalletCardImport();
4313 4327
4314 std::vector<CreditCard> server_cards; 4328 std::vector<CreditCard> server_cards;
4315 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4329 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4316 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4330 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4317 "1881" /* Visa */, "01", "2999"); 4331 "1881" /* Visa */, "01", "2999", "1");
4318 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 4332 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4319 4333
4320 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 4334 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
4321 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 4335 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
4322 "347666888555" /* American Express */, "04", "2999"); 4336 "347666888555" /* American Express */, "04", "2999",
4337 "1");
4323 4338
4324 test::SetServerCreditCards(autofill_table_, server_cards); 4339 test::SetServerCreditCards(autofill_table_, server_cards);
4325 personal_data_->Refresh(); 4340 personal_data_->Refresh();
4326 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4341 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4327 .WillOnce(QuitMainMessageLoop()); 4342 .WillOnce(QuitMainMessageLoop());
4328 base::RunLoop().Run(); 4343 base::RunLoop().Run();
4329 4344
4330 // A user re-types (or fills with) an unmasked card. Don't offer to save 4345 // A user re-types (or fills with) an unmasked card. Don't offer to save
4331 // here, either. Since it's unmasked, we know for certain that it's the same 4346 // here, either. Since it's unmasked, we know for certain that it's the same
4332 // card. 4347 // card.
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
5133 "bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.", 5148 "bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
5134 "", "Springfield", "IL", "91601", "", ""); 5149 "", "Springfield", "IL", "91601", "", "");
5135 profile6.set_use_count(10); 5150 profile6.set_use_count(10);
5136 profile6.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); 5151 profile6.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1));
5137 5152
5138 // Add three credit cards. Give them a frecency score so that they are 5153 // Add three credit cards. Give them a frecency score so that they are
5139 // suggested in order (1, 2, 3). This will ensure a deterministic order for 5154 // suggested in order (1, 2, 3). This will ensure a deterministic order for
5140 // verifying results. 5155 // verifying results.
5141 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); 5156 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com");
5142 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", 5157 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
5143 "347666888555" /* American Express */, "04", "2999"); 5158 "347666888555" /* American Express */, "04", "2999",
5159 "1");
5144 credit_card1.set_use_count(10); 5160 credit_card1.set_use_count(10);
5145 5161
5146 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); 5162 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com");
5147 test::SetCreditCardInfo(&credit_card2, "John Dillinger", 5163 test::SetCreditCardInfo(&credit_card2, "John Dillinger",
5148 "423456789012" /* Visa */, "01", "2999"); 5164 "423456789012" /* Visa */, "01", "2999", "1");
5149 credit_card2.set_use_count(5); 5165 credit_card2.set_use_count(5);
5150 5166
5151 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); 5167 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com");
5152 test::SetCreditCardInfo(&credit_card3, "Bonnie Parker", 5168 test::SetCreditCardInfo(&credit_card3, "Bonnie Parker",
5153 "518765432109" /* Mastercard */, "12", "2999"); 5169 "518765432109" /* Mastercard */, "12", "2999", "1");
5154 credit_card3.set_use_count(1); 5170 credit_card3.set_use_count(1);
5155 5171
5156 // Associate the first card with profile1. 5172 // Associate the first card with profile1.
5157 credit_card1.set_billing_address_id(profile1.guid()); 5173 credit_card1.set_billing_address_id(profile1.guid());
5158 // Associate the second card with profile4. 5174 // Associate the second card with profile4.
5159 credit_card2.set_billing_address_id(profile4.guid()); 5175 credit_card2.set_billing_address_id(profile4.guid());
5160 // Associate the third card with profile6. 5176 // Associate the third card with profile6.
5161 credit_card3.set_billing_address_id(profile6.guid()); 5177 credit_card3.set_billing_address_id(profile6.guid());
5162 5178
5163 personal_data_->AddProfile(profile1); 5179 personal_data_->AddProfile(profile1);
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
5924 GetServerProfiles.back().SetRawInfo(NAME_FULL, 5940 GetServerProfiles.back().SetRawInfo(NAME_FULL,
5925 base::ASCIIToUTF16("John Doe")); 5941 base::ASCIIToUTF16("John Doe"));
5926 GetServerProfiles.back().set_use_count(100); 5942 GetServerProfiles.back().set_use_count(100);
5927 autofill_table_->SetServerProfiles(GetServerProfiles); 5943 autofill_table_->SetServerProfiles(GetServerProfiles);
5928 5944
5929 // Add a server and a local card that have the server address as billing 5945 // Add a server and a local card that have the server address as billing
5930 // address. 5946 // address.
5931 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 5947 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
5932 "https://www.example.com"); 5948 "https://www.example.com");
5933 test::SetCreditCardInfo(&local_card, "Clyde Barrow", 5949 test::SetCreditCardInfo(&local_card, "Clyde Barrow",
5934 "347666888555" /* American Express */, "04", "2999"); 5950 "347666888555" /* American Express */, "04", "2999",
5951 "1");
5935 local_card.set_billing_address_id(kServerAddressId); 5952 local_card.set_billing_address_id(kServerAddressId);
5936 personal_data_->AddCreditCard(local_card); 5953 personal_data_->AddCreditCard(local_card);
5937 5954
5938 std::vector<CreditCard> server_cards; 5955 std::vector<CreditCard> server_cards;
5939 server_cards.push_back( 5956 server_cards.push_back(
5940 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 5957 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
5941 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 5958 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
5942 "1111" /* Visa */, "01", "2999"); 5959 "1111" /* Visa */, "01", "2999", "1");
5943 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 5960 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
5944 server_cards.back().set_billing_address_id(kServerAddressId); 5961 server_cards.back().set_billing_address_id(kServerAddressId);
5945 test::SetServerCreditCards(autofill_table_, server_cards); 5962 test::SetServerCreditCards(autofill_table_, server_cards);
5946 5963
5947 // Make sure everything is setup correctly. 5964 // Make sure everything is setup correctly.
5948 personal_data_->Refresh(); 5965 personal_data_->Refresh();
5949 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 5966 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
5950 .WillOnce(QuitMainMessageLoop()); 5967 .WillOnce(QuitMainMessageLoop());
5951 base::RunLoop().Run(); 5968 base::RunLoop().Run();
5952 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 5969 EXPECT_EQ(1U, personal_data_->web_profiles().size());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
6032 GetServerProfiles.back().SetRawInfo(NAME_FULL, 6049 GetServerProfiles.back().SetRawInfo(NAME_FULL,
6033 base::ASCIIToUTF16("John Doe")); 6050 base::ASCIIToUTF16("John Doe"));
6034 GetServerProfiles.back().set_use_count(100); 6051 GetServerProfiles.back().set_use_count(100);
6035 autofill_table_->SetServerProfiles(GetServerProfiles); 6052 autofill_table_->SetServerProfiles(GetServerProfiles);
6036 6053
6037 // Add a server and a local card that have the server address as billing 6054 // Add a server and a local card that have the server address as billing
6038 // address. 6055 // address.
6039 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 6056 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
6040 "https://www.example.com"); 6057 "https://www.example.com");
6041 test::SetCreditCardInfo(&local_card, "Clyde Barrow", 6058 test::SetCreditCardInfo(&local_card, "Clyde Barrow",
6042 "347666888555" /* American Express */, "04", "2999"); 6059 "347666888555" /* American Express */, "04", "2999",
6060 "1");
6043 local_card.set_billing_address_id(kServerAddressId); 6061 local_card.set_billing_address_id(kServerAddressId);
6044 personal_data_->AddCreditCard(local_card); 6062 personal_data_->AddCreditCard(local_card);
6045 6063
6046 std::vector<CreditCard> server_cards; 6064 std::vector<CreditCard> server_cards;
6047 server_cards.push_back( 6065 server_cards.push_back(
6048 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 6066 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
6049 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6067 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6050 "1111" /* Visa */, "01", "2999"); 6068 "1111" /* Visa */, "01", "2999", "1");
6051 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 6069 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6052 server_cards.back().set_billing_address_id(kServerAddressId); 6070 server_cards.back().set_billing_address_id(kServerAddressId);
6053 test::SetServerCreditCards(autofill_table_, server_cards); 6071 test::SetServerCreditCards(autofill_table_, server_cards);
6054 6072
6055 // Make sure everything is setup correctly. 6073 // Make sure everything is setup correctly.
6056 personal_data_->Refresh(); 6074 personal_data_->Refresh();
6057 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6075 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6058 .WillOnce(QuitMainMessageLoop()); 6076 .WillOnce(QuitMainMessageLoop());
6059 base::RunLoop().Run(); 6077 base::RunLoop().Run();
6060 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 6078 EXPECT_EQ(1U, personal_data_->web_profiles().size());
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
6207 GetServerProfiles.back().SetRawInfo(NAME_FULL, 6225 GetServerProfiles.back().SetRawInfo(NAME_FULL,
6208 base::ASCIIToUTF16("John Doe")); 6226 base::ASCIIToUTF16("John Doe"));
6209 GetServerProfiles.back().set_use_count(200); 6227 GetServerProfiles.back().set_use_count(200);
6210 autofill_table_->SetServerProfiles(GetServerProfiles); 6228 autofill_table_->SetServerProfiles(GetServerProfiles);
6211 6229
6212 // Add a server and a local card that have the first and second Wallet address 6230 // Add a server and a local card that have the first and second Wallet address
6213 // as a billing address. 6231 // as a billing address.
6214 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 6232 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
6215 "https://www.example.com"); 6233 "https://www.example.com");
6216 test::SetCreditCardInfo(&local_card, "Clyde Barrow", 6234 test::SetCreditCardInfo(&local_card, "Clyde Barrow",
6217 "347666888555" /* American Express */, "04", "2999"); 6235 "347666888555" /* American Express */, "04", "2999",
6236 "1");
6218 local_card.set_billing_address_id(kServerAddressId); 6237 local_card.set_billing_address_id(kServerAddressId);
6219 personal_data_->AddCreditCard(local_card); 6238 personal_data_->AddCreditCard(local_card);
6220 6239
6221 std::vector<CreditCard> server_cards; 6240 std::vector<CreditCard> server_cards;
6222 server_cards.push_back( 6241 server_cards.push_back(
6223 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 6242 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
6224 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6243 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6225 "1111" /* Visa */, "01", "2999"); 6244 "1111" /* Visa */, "01", "2999", "1");
6226 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 6245 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6227 server_cards.back().set_billing_address_id(kServerAddressId2); 6246 server_cards.back().set_billing_address_id(kServerAddressId2);
6228 test::SetServerCreditCards(autofill_table_, server_cards); 6247 test::SetServerCreditCards(autofill_table_, server_cards);
6229 6248
6230 // Make sure everything is setup correctly. 6249 // Make sure everything is setup correctly.
6231 personal_data_->Refresh(); 6250 personal_data_->Refresh();
6232 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6251 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6233 .WillOnce(QuitMainMessageLoop()); 6252 .WillOnce(QuitMainMessageLoop());
6234 base::RunLoop().Run(); 6253 base::RunLoop().Run();
6235 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 6254 EXPECT_EQ(1U, personal_data_->web_profiles().size());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
6312 GetServerProfiles.back().SetRawInfo(NAME_FULL, 6331 GetServerProfiles.back().SetRawInfo(NAME_FULL,
6313 base::ASCIIToUTF16("John Doe")); 6332 base::ASCIIToUTF16("John Doe"));
6314 GetServerProfiles.back().set_use_count(100); 6333 GetServerProfiles.back().set_use_count(100);
6315 autofill_table_->SetServerProfiles(GetServerProfiles); 6334 autofill_table_->SetServerProfiles(GetServerProfiles);
6316 6335
6317 // Add a server card that have the server address as billing address. 6336 // Add a server card that have the server address as billing address.
6318 std::vector<CreditCard> server_cards; 6337 std::vector<CreditCard> server_cards;
6319 server_cards.push_back( 6338 server_cards.push_back(
6320 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 6339 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
6321 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6340 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6322 "1111" /* Visa */, "01", "2999"); 6341 "1111" /* Visa */, "01", "2999", "1");
6323 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 6342 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6324 server_cards.back().set_billing_address_id(kServerAddressId); 6343 server_cards.back().set_billing_address_id(kServerAddressId);
6325 test::SetServerCreditCards(autofill_table_, server_cards); 6344 test::SetServerCreditCards(autofill_table_, server_cards);
6326 6345
6327 // Make sure everything is setup correctly. 6346 // Make sure everything is setup correctly.
6328 personal_data_->Refresh(); 6347 personal_data_->Refresh();
6329 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6348 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6330 .WillOnce(QuitMainMessageLoop()); 6349 .WillOnce(QuitMainMessageLoop());
6331 base::RunLoop().Run(); 6350 base::RunLoop().Run();
6332 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); 6351 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size());
(...skipping 17 matching lines...) Expand all
6350 std::vector<AutofillProfile*> profiles = 6369 std::vector<AutofillProfile*> profiles =
6351 personal_data_->GetProfilesToSuggest(); 6370 personal_data_->GetProfilesToSuggest();
6352 ASSERT_EQ(1U, profiles.size()); 6371 ASSERT_EQ(1U, profiles.size());
6353 EXPECT_EQ(profiles[0]->guid(), 6372 EXPECT_EQ(profiles[0]->guid(),
6354 personal_data_->GetCreditCards()[0]->billing_address_id()); 6373 personal_data_->GetCreditCards()[0]->billing_address_id());
6355 6374
6356 // Add a new server card that has the same billing address as the old one. 6375 // Add a new server card that has the same billing address as the old one.
6357 server_cards.push_back( 6376 server_cards.push_back(
6358 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); 6377 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2"));
6359 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6378 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6360 "1112" /* Visa */, "01", "2888"); 6379 "1112" /* Visa */, "01", "2888", "1");
6361 server_cards.back().SetNetworkForMaskedCard(kVisaCard); 6380 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6362 server_cards.back().set_billing_address_id(kServerAddressId); 6381 server_cards.back().set_billing_address_id(kServerAddressId);
6363 test::SetServerCreditCards(autofill_table_, server_cards); 6382 test::SetServerCreditCards(autofill_table_, server_cards);
6364 6383
6365 // Make sure everything is setup correctly. 6384 // Make sure everything is setup correctly.
6366 personal_data_->Refresh(); 6385 personal_data_->Refresh();
6367 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6386 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6368 .WillOnce(QuitMainMessageLoop()); 6387 .WillOnce(QuitMainMessageLoop());
6369 base::RunLoop().Run(); 6388 base::RunLoop().Run();
6370 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 6389 EXPECT_EQ(1U, personal_data_->web_profiles().size());
(...skipping 24 matching lines...) Expand all
6395 // to the converted address. 6414 // to the converted address.
6396 EXPECT_EQ(profiles[0]->guid(), 6415 EXPECT_EQ(profiles[0]->guid(),
6397 personal_data_->GetCreditCards()[0]->billing_address_id()); 6416 personal_data_->GetCreditCards()[0]->billing_address_id());
6398 // Make sure that the billing address id of the new server card still refers 6417 // Make sure that the billing address id of the new server card still refers
6399 // to the converted address. 6418 // to the converted address.
6400 EXPECT_EQ(profiles[0]->guid(), 6419 EXPECT_EQ(profiles[0]->guid(),
6401 personal_data_->GetCreditCards()[1]->billing_address_id()); 6420 personal_data_->GetCreditCards()[1]->billing_address_id());
6402 } 6421 }
6403 6422
6404 } // namespace autofill 6423 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698