| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "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 <memory> | 10 #include <memory> |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // Reload the database. | 352 // Reload the database. |
| 353 ResetPersonalDataManager(USER_MODE_NORMAL); | 353 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 354 | 354 |
| 355 // Verify the addition. | 355 // Verify the addition. |
| 356 std::vector<AutofillProfile*> profiles; | 356 std::vector<AutofillProfile*> profiles; |
| 357 profiles.push_back(&profile0); | 357 profiles.push_back(&profile0); |
| 358 profiles.push_back(&profile1); | 358 profiles.push_back(&profile1); |
| 359 ExpectSameElements(profiles, personal_data_->GetProfiles()); | 359 ExpectSameElements(profiles, personal_data_->GetProfiles()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 // Test that a new profile has its basic information set. |
| 363 TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) { |
| 364 // Add a profile to the database. |
| 365 AutofillProfile profile(test::GetFullProfile()); |
| 366 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
| 367 personal_data_->AddProfile(profile); |
| 368 |
| 369 // Reload the database. |
| 370 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 371 |
| 372 // Verify the addition. |
| 373 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
| 374 ASSERT_EQ(1U, results.size()); |
| 375 EXPECT_EQ(0, profile.Compare(*results[0])); |
| 376 |
| 377 // Make sure the use count and use date were set. |
| 378 EXPECT_EQ(1U, results[0]->use_count()); |
| 379 EXPECT_NE(base::Time(), results[0]->use_date()); |
| 380 EXPECT_NE(base::Time(), results[0]->modification_date()); |
| 381 } |
| 382 |
| 362 TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) { | 383 TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) { |
| 363 EnableWalletCardImport(); | 384 EnableWalletCardImport(); |
| 364 | 385 |
| 365 std::vector<AutofillProfile> server_profiles; | 386 std::vector<AutofillProfile> server_profiles; |
| 366 server_profiles.push_back( | 387 server_profiles.push_back( |
| 367 AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123")); | 388 AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123")); |
| 368 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "", | 389 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "", |
| 369 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX", | 390 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX", |
| 370 "77401", "US", ""); | 391 "77401", "US", ""); |
| 371 // Wallet only provides a full name, so the above first and last names | 392 // Wallet only provides a full name, so the above first and last names |
| (...skipping 27 matching lines...) Expand all Loading... |
| 399 | 420 |
| 400 // Verify that the server profile's use date was updated. | 421 // Verify that the server profile's use date was updated. |
| 401 const AutofillProfile* server_profile = personal_data_->GetProfiles()[0]; | 422 const AutofillProfile* server_profile = personal_data_->GetProfiles()[0]; |
| 402 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 423 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 403 base::Time::Now() - server_profile->use_date()); | 424 base::Time::Now() - server_profile->use_date()); |
| 404 } | 425 } |
| 405 | 426 |
| 406 // Tests that SaveImportedProfile sets the modification date on new profiles. | 427 // Tests that SaveImportedProfile sets the modification date on new profiles. |
| 407 TEST_F(PersonalDataManagerTest, SaveImportedProfileSetModificationDate) { | 428 TEST_F(PersonalDataManagerTest, SaveImportedProfileSetModificationDate) { |
| 408 AutofillProfile profile(test::GetFullProfile()); | 429 AutofillProfile profile(test::GetFullProfile()); |
| 409 EXPECT_EQ(base::Time(), profile.modification_date()); | 430 EXPECT_NE(base::Time(), profile.modification_date()); |
| 410 | 431 |
| 411 personal_data_->SaveImportedProfile(profile); | 432 personal_data_->SaveImportedProfile(profile); |
| 412 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 433 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 413 ASSERT_EQ(1U, profiles.size()); | 434 ASSERT_EQ(1U, profiles.size()); |
| 414 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 435 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 415 base::Time::Now() - profiles[0]->modification_date()); | 436 base::Time::Now() - profiles[0]->modification_date()); |
| 416 } | 437 } |
| 417 | 438 |
| 418 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { | 439 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { |
| 419 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 440 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // database. | 542 // database. |
| 522 ResetPersonalDataManager(USER_MODE_NORMAL); | 543 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 523 | 544 |
| 524 // Verify that we've loaded the credit cards from the web database. | 545 // Verify that we've loaded the credit cards from the web database. |
| 525 cards.clear(); | 546 cards.clear(); |
| 526 cards.push_back(&credit_card0); | 547 cards.push_back(&credit_card0); |
| 527 cards.push_back(&credit_card2); | 548 cards.push_back(&credit_card2); |
| 528 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 549 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 529 } | 550 } |
| 530 | 551 |
| 552 // Test that a new credit card has its basic information set. |
| 553 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { |
| 554 // Add a credit to the database. |
| 555 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 556 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 557 "423456789012" /* Visa */, "01", "2999"); |
| 558 personal_data_->AddCreditCard(credit_card); |
| 559 |
| 560 // Reload the database. |
| 561 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 562 |
| 563 // Verify the addition. |
| 564 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 565 ASSERT_EQ(1U, results.size()); |
| 566 EXPECT_EQ(0, credit_card.Compare(*results[0])); |
| 567 |
| 568 // Make sure the use count and use date were set. |
| 569 EXPECT_EQ(1U, results[0]->use_count()); |
| 570 EXPECT_NE(base::Time(), results[0]->use_date()); |
| 571 EXPECT_NE(base::Time(), results[0]->modification_date()); |
| 572 } |
| 573 |
| 531 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { | 574 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { |
| 532 // Start with unverified data. | 575 // Start with unverified data. |
| 533 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); | 576 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); |
| 534 test::SetProfileInfo(&profile, | 577 test::SetProfileInfo(&profile, |
| 535 "Marion", "Mitchell", "Morrison", | 578 "Marion", "Mitchell", "Morrison", |
| 536 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 579 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 537 "91601", "US", "12345678910"); | 580 "91601", "US", "12345678910"); |
| 538 EXPECT_FALSE(profile.IsVerified()); | 581 EXPECT_FALSE(profile.IsVerified()); |
| 539 | 582 |
| 540 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); | 583 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| (...skipping 3118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 "347666888555" /* American Express */, "04", "3999"); | 3702 "347666888555" /* American Express */, "04", "3999"); |
| 3660 credit_card5.set_use_count(1); | 3703 credit_card5.set_use_count(1); |
| 3661 credit_card5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3704 credit_card5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 3662 credit_cards.push_back(&credit_card5); | 3705 credit_cards.push_back(&credit_card5); |
| 3663 | 3706 |
| 3664 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3707 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3665 EXPECT_EQ(3U, credit_cards.size()); | 3708 EXPECT_EQ(3U, credit_cards.size()); |
| 3666 } | 3709 } |
| 3667 | 3710 |
| 3668 TEST_F(PersonalDataManagerTest, RecordUseOf) { | 3711 TEST_F(PersonalDataManagerTest, RecordUseOf) { |
| 3712 base::Time creation_time = base::Time::FromTimeT(12345); |
| 3713 |
| 3669 AutofillProfile profile(test::GetFullProfile()); | 3714 AutofillProfile profile(test::GetFullProfile()); |
| 3670 EXPECT_EQ(0U, profile.use_count()); | 3715 profile.set_use_date(creation_time); |
| 3671 EXPECT_EQ(base::Time(), profile.use_date()); | 3716 profile.set_modification_date(creation_time); |
| 3672 EXPECT_EQ(base::Time(), profile.modification_date()); | 3717 EXPECT_EQ(1U, profile.use_count()); |
| 3718 EXPECT_EQ(creation_time, profile.use_date()); |
| 3719 EXPECT_EQ(creation_time, profile.modification_date()); |
| 3673 personal_data_->AddProfile(profile); | 3720 personal_data_->AddProfile(profile); |
| 3674 | 3721 |
| 3675 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 3722 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 3676 test::SetCreditCardInfo(&credit_card, "John Dillinger", | 3723 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 3677 "423456789012" /* Visa */, "01", "2999"); | 3724 "423456789012" /* Visa */, "01", "2999"); |
| 3678 EXPECT_EQ(0U, credit_card.use_count()); | 3725 credit_card.set_use_date(creation_time); |
| 3679 EXPECT_EQ(base::Time(), credit_card.use_date()); | 3726 credit_card.set_modification_date(creation_time); |
| 3680 EXPECT_EQ(base::Time(), credit_card.modification_date()); | 3727 EXPECT_EQ(1U, credit_card.use_count()); |
| 3728 EXPECT_EQ(creation_time, credit_card.use_date()); |
| 3729 EXPECT_EQ(creation_time, credit_card.modification_date()); |
| 3681 personal_data_->AddCreditCard(credit_card); | 3730 personal_data_->AddCreditCard(credit_card); |
| 3682 | 3731 |
| 3683 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3732 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3684 .WillOnce(QuitMainMessageLoop()); | 3733 .WillOnce(QuitMainMessageLoop()); |
| 3685 base::MessageLoop::current()->Run(); | 3734 base::MessageLoop::current()->Run(); |
| 3686 | 3735 |
| 3687 // Notify the PDM that the profile and credit card were used. | 3736 // Notify the PDM that the profile and credit card were used. |
| 3688 AutofillProfile* added_profile = | 3737 AutofillProfile* added_profile = |
| 3689 personal_data_->GetProfileByGUID(profile.guid()); | 3738 personal_data_->GetProfileByGUID(profile.guid()); |
| 3690 ASSERT_TRUE(added_profile); | 3739 ASSERT_TRUE(added_profile); |
| 3691 EXPECT_EQ(*added_profile, profile); | 3740 EXPECT_EQ(*added_profile, profile); |
| 3692 EXPECT_EQ(0U, added_profile->use_count()); | 3741 EXPECT_EQ(1U, added_profile->use_count()); |
| 3693 EXPECT_EQ(base::Time(), added_profile->use_date()); | 3742 EXPECT_EQ(creation_time, added_profile->use_date()); |
| 3694 EXPECT_NE(base::Time(), added_profile->modification_date()); | 3743 EXPECT_NE(creation_time, added_profile->modification_date()); |
| 3695 personal_data_->RecordUseOf(profile); | 3744 personal_data_->RecordUseOf(profile); |
| 3696 | 3745 |
| 3697 CreditCard* added_card = | 3746 CreditCard* added_card = |
| 3698 personal_data_->GetCreditCardByGUID(credit_card.guid()); | 3747 personal_data_->GetCreditCardByGUID(credit_card.guid()); |
| 3699 ASSERT_TRUE(added_card); | 3748 ASSERT_TRUE(added_card); |
| 3700 EXPECT_EQ(*added_card, credit_card); | 3749 EXPECT_EQ(*added_card, credit_card); |
| 3701 EXPECT_EQ(0U, added_card->use_count()); | 3750 EXPECT_EQ(1U, added_card->use_count()); |
| 3702 EXPECT_EQ(base::Time(), added_card->use_date()); | 3751 EXPECT_EQ(creation_time, added_card->use_date()); |
| 3703 EXPECT_NE(base::Time(), added_card->modification_date()); | 3752 EXPECT_NE(creation_time, added_card->modification_date()); |
| 3704 personal_data_->RecordUseOf(credit_card); | 3753 personal_data_->RecordUseOf(credit_card); |
| 3705 | 3754 |
| 3706 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3755 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3707 .WillOnce(QuitMainMessageLoop()); | 3756 .WillOnce(QuitMainMessageLoop()); |
| 3708 base::MessageLoop::current()->Run(); | 3757 base::MessageLoop::current()->Run(); |
| 3709 | 3758 |
| 3710 // Verify usage stats are updated. | 3759 // Verify usage stats are updated. |
| 3711 added_profile = personal_data_->GetProfileByGUID(profile.guid()); | 3760 added_profile = personal_data_->GetProfileByGUID(profile.guid()); |
| 3712 ASSERT_TRUE(added_profile); | 3761 ASSERT_TRUE(added_profile); |
| 3713 EXPECT_EQ(1U, added_profile->use_count()); | 3762 EXPECT_EQ(2U, added_profile->use_count()); |
| 3714 EXPECT_NE(base::Time(), added_profile->use_date()); | 3763 EXPECT_NE(creation_time, added_profile->use_date()); |
| 3715 EXPECT_NE(base::Time(), added_profile->modification_date()); | 3764 EXPECT_NE(creation_time, added_profile->modification_date()); |
| 3716 | 3765 |
| 3717 added_card = personal_data_->GetCreditCardByGUID(credit_card.guid()); | 3766 added_card = personal_data_->GetCreditCardByGUID(credit_card.guid()); |
| 3718 ASSERT_TRUE(added_card); | 3767 ASSERT_TRUE(added_card); |
| 3719 EXPECT_EQ(1U, added_card->use_count()); | 3768 EXPECT_EQ(2U, added_card->use_count()); |
| 3720 EXPECT_NE(base::Time(), added_card->use_date()); | 3769 EXPECT_NE(creation_time, added_card->use_date()); |
| 3721 EXPECT_NE(base::Time(), added_card->modification_date()); | 3770 EXPECT_NE(creation_time, added_card->modification_date()); |
| 3722 } | 3771 } |
| 3723 | 3772 |
| 3724 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { | 3773 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { |
| 3725 EnableWalletCardImport(); | 3774 EnableWalletCardImport(); |
| 3726 | 3775 |
| 3727 std::vector<CreditCard> server_cards; | 3776 std::vector<CreditCard> server_cards; |
| 3728 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 3777 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 3729 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 3778 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 3730 "9012" /* Visa */, "01", "2999"); | 3779 "9012" /* Visa */, "01", "2999"); |
| 3731 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3780 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3769 personal_data_->UpdateServerCreditCard(*unmasked_card); | 3818 personal_data_->UpdateServerCreditCard(*unmasked_card); |
| 3770 | 3819 |
| 3771 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3820 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3772 .WillOnce(QuitMainMessageLoop()); | 3821 .WillOnce(QuitMainMessageLoop()); |
| 3773 base::MessageLoop::current()->Run(); | 3822 base::MessageLoop::current()->Run(); |
| 3774 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3823 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3775 | 3824 |
| 3776 for (size_t i = 0; i < 3; ++i) | 3825 for (size_t i = 0; i < 3; ++i) |
| 3777 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); | 3826 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); |
| 3778 | 3827 |
| 3779 // For an unmasked card, usage data starts out as 1 and Now(). | 3828 // For an unmasked card, usage data starts out as 2 because of the unmasking |
| 3780 EXPECT_EQ(1U, personal_data_->GetCreditCards()[0]->use_count()); | 3829 // which is considered a use. |
| 3830 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); |
| 3781 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); | 3831 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); |
| 3782 | 3832 |
| 3783 EXPECT_EQ(0U, personal_data_->GetCreditCards()[1]->use_count()); | 3833 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); |
| 3784 EXPECT_EQ(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 3834 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); |
| 3785 | 3835 |
| 3786 // Having unmasked this card, usage stats should be 1 and Now(). | 3836 // Having unmasked this card, usage stats should be 2 and Now(). |
| 3787 EXPECT_EQ(1U, personal_data_->GetCreditCards()[2]->use_count()); | 3837 EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count()); |
| 3788 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); | 3838 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); |
| 3789 base::Time initial_use_date = personal_data_->GetCreditCards()[2]->use_date(); | 3839 base::Time initial_use_date = personal_data_->GetCreditCards()[2]->use_date(); |
| 3790 | 3840 |
| 3791 server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid()); | 3841 server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid()); |
| 3792 personal_data_->RecordUseOf(server_cards.back()); | 3842 personal_data_->RecordUseOf(server_cards.back()); |
| 3793 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3843 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3794 .WillOnce(QuitMainMessageLoop()); | 3844 .WillOnce(QuitMainMessageLoop()); |
| 3795 base::MessageLoop::current()->Run(); | 3845 base::MessageLoop::current()->Run(); |
| 3796 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3846 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3797 | 3847 |
| 3798 EXPECT_EQ(1U, personal_data_->GetCreditCards()[0]->use_count()); | 3848 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); |
| 3799 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); | 3849 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); |
| 3800 | 3850 |
| 3801 EXPECT_EQ(0U, personal_data_->GetCreditCards()[1]->use_count()); | 3851 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); |
| 3802 EXPECT_EQ(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 3852 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); |
| 3803 | 3853 |
| 3804 EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count()); | 3854 EXPECT_EQ(3U, personal_data_->GetCreditCards()[2]->use_count()); |
| 3805 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); | 3855 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); |
| 3806 // Time may or may not have elapsed between unmasking and RecordUseOf. | 3856 // Time may or may not have elapsed between unmasking and RecordUseOf. |
| 3807 EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date()); | 3857 EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date()); |
| 3808 | 3858 |
| 3809 // Can record usage stats on masked cards. | 3859 // Can record usage stats on masked cards. |
| 3810 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); | 3860 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); |
| 3811 personal_data_->RecordUseOf(server_cards[1]); | 3861 personal_data_->RecordUseOf(server_cards[1]); |
| 3812 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3862 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3813 .WillOnce(QuitMainMessageLoop()); | 3863 .WillOnce(QuitMainMessageLoop()); |
| 3814 base::MessageLoop::current()->Run(); | 3864 base::MessageLoop::current()->Run(); |
| 3815 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3865 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3816 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); | 3866 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count()); |
| 3817 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 3867 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); |
| 3818 | 3868 |
| 3819 // Upgrading to unmasked retains the usage stats (and increments them). | 3869 // Upgrading to unmasked retains the usage stats (and increments them). |
| 3820 CreditCard* unmasked_card2 = &server_cards[1]; | 3870 CreditCard* unmasked_card2 = &server_cards[1]; |
| 3821 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD); | 3871 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD); |
| 3822 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444")); | 3872 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444")); |
| 3823 personal_data_->UpdateServerCreditCard(*unmasked_card2); | 3873 personal_data_->UpdateServerCreditCard(*unmasked_card2); |
| 3824 | 3874 |
| 3825 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); | 3875 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); |
| 3826 personal_data_->RecordUseOf(server_cards[1]); | 3876 personal_data_->RecordUseOf(server_cards[1]); |
| 3827 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3877 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3828 .WillOnce(QuitMainMessageLoop()); | 3878 .WillOnce(QuitMainMessageLoop()); |
| 3829 base::MessageLoop::current()->Run(); | 3879 base::MessageLoop::current()->Run(); |
| 3830 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3880 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3831 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count()); | 3881 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); |
| 3832 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 3882 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); |
| 3833 } | 3883 } |
| 3834 | 3884 |
| 3835 TEST_F(PersonalDataManagerTest, ClearAllServerData) { | 3885 TEST_F(PersonalDataManagerTest, ClearAllServerData) { |
| 3836 // Add a server card. | 3886 // Add a server card. |
| 3837 std::vector<CreditCard> server_cards; | 3887 std::vector<CreditCard> server_cards; |
| 3838 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 3888 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 3839 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 3889 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 3840 "9012" /* Visa */, "01", "2999"); | 3890 "9012" /* Visa */, "01", "2999"); |
| 3841 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3891 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4104 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4154 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4105 base::Time::Now() - saved_profiles.front()->use_date()); | 4155 base::Time::Now() - saved_profiles.front()->use_date()); |
| 4106 } | 4156 } |
| 4107 | 4157 |
| 4108 // Erase the profiles for the next test. | 4158 // Erase the profiles for the next test. |
| 4109 ResetProfiles(); | 4159 ResetProfiles(); |
| 4110 } | 4160 } |
| 4111 } | 4161 } |
| 4112 | 4162 |
| 4113 } // namespace autofill | 4163 } // namespace autofill |
| OLD | NEW |