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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Add date formatter based on pattern Created 3 years, 11 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 3388 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 types.push_back(ADDRESS_HOME_CITY); 3399 types.push_back(ADDRESS_HOME_CITY);
3400 types.push_back(ADDRESS_HOME_STATE); 3400 types.push_back(ADDRESS_HOME_STATE);
3401 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( 3401 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions(
3402 AutofillType(ADDRESS_HOME_STREET_ADDRESS), base::ASCIIToUTF16("123"), 3402 AutofillType(ADDRESS_HOME_STREET_ADDRESS), base::ASCIIToUTF16("123"),
3403 false, types); 3403 false, types);
3404 ASSERT_EQ(2U, suggestions.size()); 3404 ASSERT_EQ(2U, suggestions.size());
3405 EXPECT_EQ(base::ASCIIToUTF16("Hollywood, CA"), suggestions[0].label); 3405 EXPECT_EQ(base::ASCIIToUTF16("Hollywood, CA"), suggestions[0].label);
3406 EXPECT_EQ(base::ASCIIToUTF16("Hollywood, TX"), suggestions[1].label); 3406 EXPECT_EQ(base::ASCIIToUTF16("Hollywood, TX"), suggestions[1].label);
3407 } 3407 }
3408 3408
3409 // Tests that GetProfileSuggestions orders its suggestions based on the frecency 3409 // Tests that GetProfileSuggestions orders its suggestions based on the
3410 // formula. 3410 // frequency formula.
3411 TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) { 3411 TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) {
3412 // Set up the profiles. They are named with number suffixes X so the X is the 3412 // Set up the profiles. They are named with number suffixes X so the X is the
3413 // order in which they should be ordered by frecency. 3413 // order in which they should be ordered by frequency.
3414 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); 3414 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com");
3415 test::SetProfileInfo(&profile3, "Marion3", "Mitchell", "Morrison", 3415 test::SetProfileInfo(&profile3, "Marion3", "Mitchell", "Morrison",
3416 "johnwayne@me.xyz", "Fox", 3416 "johnwayne@me.xyz", "Fox",
3417 "123 Zoo St.\nSecond Line\nThird line", "unit 5", 3417 "123 Zoo St.\nSecond Line\nThird line", "unit 5",
3418 "Hollywood", "CA", "91601", "US", "12345678910"); 3418 "Hollywood", "CA", "91601", "US", "12345678910");
3419 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); 3419 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
3420 profile3.set_use_count(5); 3420 profile3.set_use_count(5);
3421 personal_data_->AddProfile(profile3); 3421 personal_data_->AddProfile(profile3);
3422 3422
3423 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 3423 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 ASSERT_EQ(5U, suggestions.size()); 3607 ASSERT_EQ(5U, suggestions.size());
3608 3608
3609 // All cards should be ordered as expected. 3609 // All cards should be ordered as expected.
3610 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value); 3610 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value);
3611 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value); 3611 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value);
3612 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value); 3612 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value);
3613 EXPECT_EQ(ASCIIToUTF16("Emmet Dalton"), suggestions[3].value); 3613 EXPECT_EQ(ASCIIToUTF16("Emmet Dalton"), suggestions[3].value);
3614 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[4].value); 3614 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[4].value);
3615 } 3615 }
3616 3616
3617 // Test that expired cards are ordered by frecency and are always suggested 3617 // Test that expired cards are ordered by frequency and are always suggested
3618 // after non expired cards even if they have a higher frecency score. 3618 // after non expired cards even if they have a higher frequency score.
3619 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) { 3619 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) {
3620 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3620 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3621 3621
3622 // Add a never used non expired credit card. 3622 // Add a never used non expired credit card.
3623 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B", 3623 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B",
3624 "https://www.example.com"); 3624 "https://www.example.com");
3625 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker", 3625 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker",
3626 "518765432109" /* Mastercard */, "04", "2999"); 3626 "518765432109" /* Mastercard */, "04", "2999");
3627 personal_data_->AddCreditCard(credit_card0); 3627 personal_data_->AddCreditCard(credit_card0);
3628 3628
3629 // Add an expired card with a higher frecency score. 3629 // Add an expired card with a higher frequency score.
3630 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15", 3630 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15",
3631 "https://www.example.com"); 3631 "https://www.example.com");
3632 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", 3632 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
3633 "347666888555" /* American Express */, "04", "1999"); 3633 "347666888555" /* American Express */, "04", "1999");
3634 credit_card1.set_use_count(300); 3634 credit_card1.set_use_count(300);
3635 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); 3635 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10));
3636 personal_data_->AddCreditCard(credit_card1); 3636 personal_data_->AddCreditCard(credit_card1);
3637 3637
3638 // Add an expired card with a lower frecency score. 3638 // Add an expired card with a lower frequency score.
3639 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", 3639 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B",
3640 "https://www.example.com"); 3640 "https://www.example.com");
3641 credit_card2.set_use_count(3); 3641 credit_card2.set_use_count(3);
3642 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); 3642 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
3643 test::SetCreditCardInfo(&credit_card2, "John Dillinger", 3643 test::SetCreditCardInfo(&credit_card2, "John Dillinger",
3644 "423456789012" /* Visa */, "01", "1998"); 3644 "423456789012" /* Visa */, "01", "1998");
3645 personal_data_->AddCreditCard(credit_card2); 3645 personal_data_->AddCreditCard(credit_card2);
3646 3646
3647 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3647 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3648 .WillOnce(QuitMainMessageLoop()); 3648 .WillOnce(QuitMainMessageLoop());
3649 base::RunLoop().Run(); 3649 base::RunLoop().Run();
3650 3650
3651 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3651 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3652 3652
3653 std::vector<Suggestion> suggestions = 3653 std::vector<Suggestion> suggestions =
3654 personal_data_->GetCreditCardSuggestions( 3654 personal_data_->GetCreditCardSuggestions(
3655 AutofillType(CREDIT_CARD_NAME_FULL), 3655 AutofillType(CREDIT_CARD_NAME_FULL),
3656 /* field_contents= */ base::string16()); 3656 /* field_contents= */ base::string16());
3657 ASSERT_EQ(3U, suggestions.size()); 3657 ASSERT_EQ(3U, suggestions.size());
3658 3658
3659 // The never used non expired card should be suggested first. 3659 // The never used non expired card should be suggested first.
3660 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[0].value); 3660 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[0].value);
3661 3661
3662 // The expired cards should be sorted by frecency 3662 // The expired cards should be sorted by frequency
3663 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); 3663 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value);
3664 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[2].value); 3664 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[2].value);
3665 } 3665 }
3666 3666
3667 // Test that a card that doesn't have a number is not shown in the suggestions 3667 // Test that a card that doesn't have a number is not shown in the suggestions
3668 // when querying credit cards by their number. 3668 // when querying credit cards by their number.
3669 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { 3669 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) {
3670 // Create one normal credit card and one credit card with the number missing. 3670 // Create one normal credit card and one credit card with the number missing.
3671 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3671 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3672 3672
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3807 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3807 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3808 .WillOnce(QuitMainMessageLoop()); 3808 .WillOnce(QuitMainMessageLoop());
3809 base::RunLoop().Run(); 3809 base::RunLoop().Run();
3810 3810
3811 suggestions = personal_data_->GetCreditCardSuggestions( 3811 suggestions = personal_data_->GetCreditCardSuggestions(
3812 AutofillType(CREDIT_CARD_NAME_FULL), 3812 AutofillType(CREDIT_CARD_NAME_FULL),
3813 /* field_contents= */ base::string16()); 3813 /* field_contents= */ base::string16());
3814 ASSERT_EQ(3U, suggestions.size()); 3814 ASSERT_EQ(3U, suggestions.size());
3815 } 3815 }
3816 3816
3817 // Tests that credit card last used date suggestion can be generated correctly
3818 // in different variations and locales
3819
3817 // Tests that only the full server card is kept when deduping with a local 3820 // Tests that only the full server card is kept when deduping with a local
3818 // duplicate of it. 3821 // duplicate of it.
3819 TEST_F(PersonalDataManagerTest, 3822 TEST_F(PersonalDataManagerTest,
3820 DedupeCreditCardToSuggest_FullServerShadowsLocal) { 3823 DedupeCreditCardToSuggest_FullServerShadowsLocal) {
3821 std::list<CreditCard*> credit_cards; 3824 std::list<CreditCard*> credit_cards;
3822 3825
3823 // Create 3 different local credit cards. 3826 // Create 3 different local credit cards.
3824 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 3827 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
3825 "https://www.example.com"); 3828 "https://www.example.com");
3826 test::SetCreditCardInfo(&local_card, "Homer Simpson", 3829 test::SetCreditCardInfo(&local_card, "Homer Simpson",
(...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after
5639 EnableAutofillProfileCleanup(); 5642 EnableAutofillProfileCleanup();
5640 5643
5641 // The deduping routine should not be run. 5644 // The deduping routine should not be run.
5642 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); 5645 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine());
5643 5646
5644 // The two duplicate profiles should still be present. 5647 // The two duplicate profiles should still be present.
5645 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 5648 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
5646 } 5649 }
5647 5650
5648 } // namespace autofill 5651 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698