Commit dfe9b9b4 authored by estade@chromium.org's avatar estade@chromium.org

Autofill: improve GetCreditCardSuggestions

BUG=401286

Review URL: https://codereview.chromium.org/447903003

Cr-Commit-Position: refs/heads/master@{#288475}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288475 0039d316-1c4b-4281-b951-d872f2087c98
parent a851245b
...@@ -865,8 +865,8 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) { ...@@ -865,8 +865,8 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) {
ASCIIToUTF16("************3456"), ASCIIToUTF16("************3456"),
ASCIIToUTF16("************8765") ASCIIToUTF16("************8765")
}; };
base::string16 expected_labels[] = { ASCIIToUTF16("*3456"), base::string16 expected_labels[] = { ASCIIToUTF16("04/12"),
ASCIIToUTF16("*8765")}; ASCIIToUTF16("10/14")};
base::string16 expected_icons[] = { base::string16 expected_icons[] = {
ASCIIToUTF16(kVisaCard), ASCIIToUTF16(kVisaCard),
ASCIIToUTF16(kMasterCard) ASCIIToUTF16(kMasterCard)
...@@ -899,7 +899,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { ...@@ -899,7 +899,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
// Test that we sent the right values to the external delegate. // Test that we sent the right values to the external delegate.
base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; base::string16 expected_values[] = {ASCIIToUTF16("************3456")};
base::string16 expected_labels[] = {ASCIIToUTF16("*3456")}; base::string16 expected_labels[] = {ASCIIToUTF16("04/12")};
base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)};
int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)};
external_delegate_->CheckSuggestions( external_delegate_->CheckSuggestions(
...@@ -1008,7 +1008,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { ...@@ -1008,7 +1008,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
CreditCard* credit_card = new CreditCard; CreditCard* credit_card = new CreditCard;
test::SetCreditCardInfo(credit_card, "Elvis Presley", test::SetCreditCardInfo(credit_card, "Elvis Presley",
"5231567890123456", // Mastercard "5231567890123456", // Mastercard
"04", "2012"); "05", "2012");
credit_card->set_guid("00000000-0000-0000-0000-000000000007"); credit_card->set_guid("00000000-0000-0000-0000-000000000007");
autofill_manager_->AddCreditCard(credit_card); autofill_manager_->AddCreditCard(credit_card);
...@@ -1032,9 +1032,9 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { ...@@ -1032,9 +1032,9 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
ASCIIToUTF16("************3456") ASCIIToUTF16("************3456")
}; };
base::string16 expected_labels[] = { base::string16 expected_labels[] = {
ASCIIToUTF16("*3456"), ASCIIToUTF16("04/12"),
ASCIIToUTF16("*8765"), ASCIIToUTF16("10/14"),
ASCIIToUTF16("*3456"), ASCIIToUTF16("05/12"),
}; };
base::string16 expected_icons[] = { base::string16 expected_icons[] = {
ASCIIToUTF16(kVisaCard), ASCIIToUTF16(kVisaCard),
...@@ -1095,8 +1095,8 @@ TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { ...@@ -1095,8 +1095,8 @@ TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) {
ASCIIToUTF16("************3456"), ASCIIToUTF16("************3456"),
ASCIIToUTF16("************8765") ASCIIToUTF16("************8765")
}; };
base::string16 expected_labels2[] = { ASCIIToUTF16("*3456"), base::string16 expected_labels2[] = { ASCIIToUTF16("04/12"),
ASCIIToUTF16("*8765")}; ASCIIToUTF16("10/14")};
base::string16 expected_icons2[] = { base::string16 expected_icons2[] = {
ASCIIToUTF16(kVisaCard), ASCIIToUTF16(kVisaCard),
ASCIIToUTF16(kMasterCard) ASCIIToUTF16(kMasterCard)
......
...@@ -671,11 +671,18 @@ void PersonalDataManager::GetCreditCardSuggestions( ...@@ -671,11 +671,18 @@ void PersonalDataManager::GetCreditCardSuggestions(
if (type.GetStorableType() == CREDIT_CARD_NUMBER) if (type.GetStorableType() == CREDIT_CARD_NUMBER)
creditcard_field_value = credit_card->ObfuscatedNumber(); creditcard_field_value = credit_card->ObfuscatedNumber();
// If the value is the card number, the label is the expiration date.
// Otherwise the label is the card number, or if that is empty the
// cardholder name. The label should never repeat the value.
base::string16 label; base::string16 label;
if (credit_card->number().empty()) { if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
// If there is no CC number, return name to show something. label = credit_card->GetInfo(
label = AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_);
credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_); } else if (credit_card->number().empty()) {
if (type.GetStorableType() != CREDIT_CARD_NAME) {
label =
credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_);
}
} else { } else {
label = kCreditCardPrefix; label = kCreditCardPrefix;
label.append(credit_card->LastFourDigits()); label.append(credit_card->LastFourDigits());
......
...@@ -2615,4 +2615,64 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions) { ...@@ -2615,4 +2615,64 @@ TEST_F(PersonalDataManagerTest, GetProfileSuggestions) {
base::UTF8ToUTF16("123 Zoo St., Second Line, Third line, unit 5")); base::UTF8ToUTF16("123 Zoo St., Second Line, Third line, unit 5"));
} }
TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) {
CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com");
test::SetCreditCardInfo(&credit_card0,
"Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
personal_data_->AddCreditCard(credit_card0);
CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com");
test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2010");
personal_data_->AddCreditCard(credit_card1);
CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com");
test::SetCreditCardInfo(&credit_card2,
"Bonnie Parker", "518765432109" /* Mastercard */, "", "");
personal_data_->AddCreditCard(credit_card2);
EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
.WillOnce(QuitMainMessageLoop());
base::MessageLoop::current()->Run();
// Sublabel is card number when filling name.
std::vector<base::string16> values;
std::vector<base::string16> labels;
std::vector<base::string16> icons;
std::vector<PersonalDataManager::GUIDPair> guid_pairs;
personal_data_->GetCreditCardSuggestions(
AutofillType(CREDIT_CARD_NAME),
base::string16(),
&values,
&labels,
&icons,
&guid_pairs);
ASSERT_EQ(3U, values.size());
ASSERT_EQ(values.size(), labels.size());
EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), values[0]);
EXPECT_EQ(ASCIIToUTF16("*8555"), labels[0]);
EXPECT_EQ(ASCIIToUTF16("John Dillinger"), values[1]);
EXPECT_EQ(base::string16(), labels[1]);
EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), values[2]);
EXPECT_EQ(ASCIIToUTF16("*2109"), labels[2]);
// Sublabel is expiration date when filling card number.
values.clear();
labels.clear();
icons.clear();
guid_pairs.clear();
personal_data_->GetCreditCardSuggestions(
AutofillType(CREDIT_CARD_NUMBER),
base::string16(),
&values,
&labels,
&icons,
&guid_pairs);
ASSERT_EQ(2U, values.size());
ASSERT_EQ(values.size(), labels.size());
EXPECT_EQ(ASCIIToUTF16("********8555"), values[0]);
EXPECT_EQ(ASCIIToUTF16("04/15"), labels[0]);
EXPECT_EQ(ASCIIToUTF16("********2109"), values[1]);
EXPECT_EQ(base::string16(), labels[1]);
}
} // namespace autofill } // namespace autofill
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment