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

Unified Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Fixed conflicts 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/personal_data_manager_unittest.cc
diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc
index 18bb0aebdd43692e5a59a927b3175659b6b0fd1f..351a838867c712bc716d2a3eafc6cfae01e668d3 100644
--- a/components/autofill/core/browser/personal_data_manager_unittest.cc
+++ b/components/autofill/core/browser/personal_data_manager_unittest.cc
@@ -17,8 +17,8 @@
#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
#include "base/guid.h"
+#include "base/i18n/time_formatting.h"
#include "base/memory/ptr_util.h"
-#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
@@ -44,8 +44,7 @@
#include "components/signin/core/browser/fake_signin_manager.h"
#include "components/signin/core/browser/test_signin_client.h"
#include "components/signin/core/common/signin_pref_names.h"
-#include "components/variations/entropy_provider.h"
-#include "components/variations/variations_associated_data.h"
+#include "components/variations/variations_params_manager.h"
#include "components/webdata/common/web_data_service_base.h"
#include "components/webdata/common/web_database_service.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -146,9 +145,6 @@ class PersonalDataManagerTest : public testing::Test {
test::DisableSystemServices(prefs_.get());
ResetPersonalDataManager(USER_MODE_NORMAL);
- // There are no field trials enabled by default.
- field_trial_list_.reset();
-
// Reset the deduping pref to its default value.
personal_data_->pref_service_->SetInteger(
prefs::kAutofillLastVersionDeduped, 0);
@@ -290,6 +286,46 @@ class PersonalDataManagerTest : public testing::Test {
ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
}
+ // Adds three local cards to the |personal_data_|. These cards are different:
+ // One was just added, one was already used in autofill, and the third was
+ // last used more than one year ago.
+ void SetupReferenceCreditCardsForLastUsedVariationTest() {
+ ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
+ base::Time cur_time = base::Time::Now();
+
+ // Test for added to chrome.
+ CreditCard credit_card0("1141084B-72D7-4B73-90CF-3D6AC154673B",
+ "https://www.example.com");
+ credit_card0.set_use_count(1);
+ credit_card0.set_use_date(cur_time - base::TimeDelta::FromDays(1));
+ test::SetCreditCardInfo(&credit_card0, "John Dillinger",
+ "423456789012" /* Visa */, "01", "2021");
+ personal_data_->AddCreditCard(credit_card0);
+
+ // Test for last used date.
+ CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15",
+ "https://www.example.com");
+ test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
+ "347666888555" /* American Express */, "04",
+ "2021");
+ credit_card1.set_use_count(10);
+ credit_card1.set_use_date(cur_time - base::TimeDelta::FromDays(10));
+ personal_data_->AddCreditCard(credit_card1);
+
+ // Test for last used more than one year ago.
+ CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
+ "https://www.example.com");
+ credit_card2.set_use_count(5);
+ credit_card2.set_use_date(cur_time - base::TimeDelta::FromDays(366));
+ test::SetCreditCardInfo(&credit_card2, "Bonnie Parker",
+ "518765432109" /* Mastercard */, "12", "2021");
+ personal_data_->AddCreditCard(credit_card2);
+
+ EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
+ .WillOnce(QuitMainMessageLoop());
+ base::RunLoop().Run();
+ }
+
// Helper methods that simply forward the call to the private member (to avoid
// having to friend every test that needs to access the private
// PersonalDataManager::ImportAddressProfile or ImportCreditCard).
@@ -303,28 +339,6 @@ class PersonalDataManagerTest : public testing::Test {
imported_credit_card);
}
- // Sets up the profile order field trial group and parameter. Sets up the
- // suggestions limit parameter to |limit_param|.
- void EnableAutofillProfileLimitFieldTrial(const std::string& limit_param) {
- DCHECK(!limit_param.empty());
-
- // Clear the existing |field_trial_list_| and variation parameters.
- field_trial_list_.reset(NULL);
- field_trial_list_.reset(
- new base::FieldTrialList(
- base::MakeUnique<metrics::SHA1EntropyProvider>("foo")));
- variations::testing::ClearAllVariationParams();
-
- std::map<std::string, std::string> params;
- params[kFrecencyFieldTrialLimitParam] = limit_param;
- variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN",
- params);
-
- field_trial_ = base::FieldTrialList::CreateFieldTrial(
- kFrecencyFieldTrialName, "LimitToN");
- field_trial_->group();
- }
-
void SubmitFormAndExpectImportedCardWithData(const FormData& form,
const char* exp_name,
const char* exp_cc_num,
@@ -364,8 +378,7 @@ class PersonalDataManagerTest : public testing::Test {
PersonalDataLoadedObserverMock personal_data_observer_;
std::unique_ptr<PersonalDataManager> personal_data_;
- std::unique_ptr<base::FieldTrialList> field_trial_list_;
- scoped_refptr<base::FieldTrial> field_trial_;
+ variations::testing::VariationParamsManager variation_params_;
};
TEST_F(PersonalDataManagerTest, AddProfile) {
@@ -3482,12 +3495,16 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions_NumberOfSuggestions) {
EXPECT_EQ(3U, suggestions.size());
// Verify that only two profiles are suggested.
- EnableAutofillProfileLimitFieldTrial("2");
+ variation_params_.SetVariationParams(
+ kFrecencyFieldTrialName,
+ {{kFrecencyFieldTrialLimitParam, "2"}});
suggestions = personal_data_->GetProfileSuggestions(
AutofillType(NAME_FIRST), base::string16(), false,
std::vector<ServerFieldType>());
EXPECT_EQ(2U, suggestions.size());
+
+ variation_params_.ClearAllVariationParams();
}
// Tests that GetProfileSuggestions returns the right number of profile
@@ -3495,7 +3512,9 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions_NumberOfSuggestions) {
// than three profiles.
TEST_F(PersonalDataManagerTest,
GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) {
- EnableAutofillProfileLimitFieldTrial("3");
+ variation_params_.SetVariationParams(
+ kFrecencyFieldTrialName,
+ {{kFrecencyFieldTrialLimitParam, "3"}});
// Set up 2 different profiles.
AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
@@ -3518,6 +3537,8 @@ TEST_F(PersonalDataManagerTest,
AutofillType(NAME_FIRST), base::string16(), false,
std::vector<ServerFieldType>());
EXPECT_EQ(2U, suggestions.size());
+
+ variation_params_.ClearAllVariationParams();
}
// Test that a masked server card is not suggested if more that six numbers have
@@ -3814,6 +3835,181 @@ TEST_F(PersonalDataManagerTest,
ASSERT_EQ(3U, suggestions.size());
}
+// Test that credit card last used date suggestion can be generated correctly
+// in variation 1: only show last used date.
+TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LastUsedDateOnly) {
+ SetupReferenceCreditCardsForLastUsedVariationTest();
+
+ variation_params_.SetVariationParamsWithFeatureAssociations(
+ kAutofillCreditCardLastUsedDateDisplay.name,
+ {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "false"},
+ {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "false"}},
+ {kAutofillCreditCardLastUsedDateDisplay.name});
+
+ const std::vector<CreditCard*> credit_cards =
+ personal_data_->GetCreditCards();
+ ASSERT_EQ(3U, credit_cards.size());
+
+ std::vector<Suggestion> suggestions =
+ personal_data_->GetCreditCardSuggestions(
+ AutofillType(CREDIT_CARD_NUMBER),
+ /* field_contents= */ base::string16());
+ ASSERT_EQ(3U, suggestions.size());
+
+ EXPECT_EQ(
+ ASCIIToUTF16("Last used: ") +
+ base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMdd"),
+ suggestions[0].label);
+
+#if defined(GOOGLE_CHROME_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Added to Chrome: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#elif defined(CHROMIUM_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Added to Chromium: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#endif
+
+ EXPECT_EQ(ASCIIToUTF16("Last used over a year ago"), suggestions[2].label);
+
+ variation_params_.ClearAllVariationParams();
+}
+
+// Test that credit card last used date suggestion can be generated correctly
+// in variation 2: show expiration date and last used date.
+TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpAndLastUsedDate) {
+ SetupReferenceCreditCardsForLastUsedVariationTest();
+
+ variation_params_.SetVariationParamsWithFeatureAssociations(
+ kAutofillCreditCardLastUsedDateDisplay.name,
+ {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "true"},
+ {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "false"}},
+ {kAutofillCreditCardLastUsedDateDisplay.name});
+
+ const std::vector<CreditCard*> credit_cards =
+ personal_data_->GetCreditCards();
+ ASSERT_EQ(3U, credit_cards.size());
+
+ std::vector<Suggestion> suggestions =
+ personal_data_->GetCreditCardSuggestions(
+ AutofillType(CREDIT_CARD_NUMBER),
+ /* field_contents= */ base::string16());
+ ASSERT_EQ(3U, suggestions.size());
+
+ EXPECT_EQ(
+ ASCIIToUTF16("Exp: 04/21, last used: ") +
+ base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMdd"),
+ suggestions[0].label);
+
+#if defined(GOOGLE_CHROME_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Exp: 01/21, added to Chrome: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#elif defined(CHROMIUM_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Exp: 01/21, added to Chromium: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#endif
+
+ EXPECT_EQ(ASCIIToUTF16("Exp: 12/21, last used over a year ago"),
+ suggestions[2].label);
+
+ variation_params_.ClearAllVariationParams();
+}
+
+// Test that credit card last used date suggestion can be generated correctly
+// in variation 3: show last used date detail.
+TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LastUsedDateDetail) {
+ SetupReferenceCreditCardsForLastUsedVariationTest();
+
+ variation_params_.SetVariationParamsWithFeatureAssociations(
+ kAutofillCreditCardLastUsedDateDisplay.name,
+ {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "false"},
+ {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "true"}},
+ {kAutofillCreditCardLastUsedDateDisplay.name});
+
+ const std::vector<CreditCard*> credit_cards =
+ personal_data_->GetCreditCards();
+ ASSERT_EQ(3U, credit_cards.size());
+
+ std::vector<Suggestion> suggestions =
+ personal_data_->GetCreditCardSuggestions(
+ AutofillType(CREDIT_CARD_NUMBER),
+ /* field_contents= */ base::string16());
+ ASSERT_EQ(3U, suggestions.size());
+
+ EXPECT_EQ(
+ ASCIIToUTF16("Last used: ") +
+ base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMddjmm"),
+ suggestions[0].label);
+
+#if defined(GOOGLE_CHROME_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Added to Chrome: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#elif defined(CHROMIUM_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Added to Chromium: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#endif
+
+ EXPECT_EQ(ASCIIToUTF16("Last used over a year ago"), suggestions[2].label);
+
+ variation_params_.ClearAllVariationParams();
+}
+
+// Test that credit card last used date suggestion can be generated correctly
+// in variation 4: show expiration date and last used date detail.
+TEST_F(PersonalDataManagerTest,
+ GetCreditCardSuggestions_ExpAndLastUsedDateDetail) {
+ SetupReferenceCreditCardsForLastUsedVariationTest();
+
+ variation_params_.SetVariationParamsWithFeatureAssociations(
+ kAutofillCreditCardLastUsedDateDisplay.name,
+ {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "true"},
+ {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "true"}},
+ {kAutofillCreditCardLastUsedDateDisplay.name});
+
+ const std::vector<CreditCard*> credit_cards =
+ personal_data_->GetCreditCards();
+ ASSERT_EQ(3U, credit_cards.size());
+
+ std::vector<Suggestion> suggestions =
+ personal_data_->GetCreditCardSuggestions(
+ AutofillType(CREDIT_CARD_NUMBER),
+ /* field_contents= */ base::string16());
+ ASSERT_EQ(3U, suggestions.size());
+
+ EXPECT_EQ(
+ ASCIIToUTF16("Exp: 04/21, last used: ") +
+ base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMddjmm"),
+ suggestions[0].label);
+
+#if defined(GOOGLE_CHROME_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Exp: 01/21, added to Chrome: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#elif defined(CHROMIUM_BUILD)
+ EXPECT_EQ(
+ ASCIIToUTF16("Exp: 01/21, added to Chromium: ") +
+ base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
+ suggestions[1].label);
+#endif
+
+ EXPECT_EQ(ASCIIToUTF16("Exp: 12/21, last used over a year ago"),
+ suggestions[2].label);
+
+ variation_params_.ClearAllVariationParams();
+}
+
// Tests that only the full server card is kept when deduping with a local
// duplicate of it.
TEST_F(PersonalDataManagerTest,

Powered by Google App Engine
This is Rietveld 408576698