Commit 57e2ceec authored by Fabio Tirelo's avatar Fabio Tirelo Committed by Commit Bot

[af] Always use the same obfuscation for card numbers

With this change we will stop using *1234 to obsfucate the card
number when we show a suggestion, for example, on a name field.
We can simply use ****1234 in all places instead.

The change applies to both the new and the deprecated dropdown.

Bug: 768881
Change-Id: Ic17c28f668dc0bed42f220d474a72924f02c7ad5
Reviewed-on: https://chromium-review.googlesource.com/1026213
Commit-Queue: Fabio Tirelo <ftirelo@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553607}
parent dcf11e3e
......@@ -1277,8 +1277,10 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) {
static const std::string kMcSuggestion =
std::string("Mastercard") + kUTF8MidlineEllipsis + "8765";
#else
static const std::string kVisaSuggestion = "*3456";
static const std::string kMcSuggestion = "*8765";
static const std::string kVisaSuggestion =
std::string(kUTF8MidlineEllipsis) + "3456";
static const std::string kMcSuggestion =
std::string(kUTF8MidlineEllipsis) + "8765";
#endif
// Test that we sent the right values to the external delegate.
......@@ -5365,7 +5367,8 @@ TEST_F(AutofillManagerTest, DisplayCreditCardSuggestionsWithMatchingTokens) {
static const std::string kVisaSuggestion =
std::string("Visa") + kUTF8MidlineEllipsis + "3456";
#else
static const std::string kVisaSuggestion = "*3456";
static const std::string kVisaSuggestion =
std::string(kUTF8MidlineEllipsis) + "3456";
#endif
CheckSuggestions(kDefaultPageID,
......
......@@ -110,6 +110,10 @@ base::string16 GetLastFourDigits(const base::string16& number) {
return stripped.substr(stripped.size() - kNumLastDigits, kNumLastDigits);
}
base::string16 GetObfuscatedStringForCardDigits(const base::string16& digits) {
return base::string16(kMidlineEllipsis) + digits;
}
} // namespace
CreditCard::CreditCard(const std::string& guid, const std::string& origin)
......@@ -735,6 +739,10 @@ base::string16 CreditCard::NetworkForDisplay() const {
return CreditCard::NetworkForDisplay(network_);
}
base::string16 CreditCard::ObfuscatedLastFourDigits() const {
return GetObfuscatedStringForCardDigits(LastFourDigits());
}
base::string16 CreditCard::NetworkAndLastFourDigits() const {
base::string16 network = NetworkForDisplay();
// TODO(crbug.com/734197): truncate network.
......@@ -744,7 +752,7 @@ base::string16 CreditCard::NetworkAndLastFourDigits() const {
return network;
// TODO(estade): i18n?
return network + base::string16(kMidlineEllipsis) + digits;
return network + GetObfuscatedStringForCardDigits(digits);
}
base::string16 CreditCard::BankNameAndLastFourDigits() const {
......@@ -752,7 +760,7 @@ base::string16 CreditCard::BankNameAndLastFourDigits() const {
// TODO(crbug.com/734197): truncate bank name.
if (digits.empty())
return ASCIIToUTF16(bank_name_);
return ASCIIToUTF16(bank_name_) + base::string16(kMidlineEllipsis) + digits;
return ASCIIToUTF16(bank_name_) + GetObfuscatedStringForCardDigits(digits);
}
base::string16 CreditCard::NetworkOrBankNameAndLastFourDigits() const {
......
......@@ -218,7 +218,7 @@ class CreditCard : public AutofillDataModel {
// Various display functions.
// Card preview summary, for example: "Visa - 1234", ", 01/2020".
// Card preview summary, for example: "Visa - ****1234", ", 01/2020".
const std::pair<base::string16, base::string16> LabelPieces() const;
// Like LabelPieces, but appends the two pieces together.
const base::string16 Label() const;
......@@ -227,11 +227,13 @@ class CreditCard : public AutofillDataModel {
base::string16 LastFourDigits() const;
// The user-visible issuer network of the card, e.g. 'Mastercard'.
base::string16 NetworkForDisplay() const;
// A label for this card formatted as 'IssuerNetwork - 2345'.
// A label for this card formatted as '****2345'
base::string16 ObfuscatedLastFourDigits() const;
// A label for this card formatted as 'IssuerNetwork - ****2345'.
base::string16 NetworkAndLastFourDigits() const;
// A label for this card formatted as 'BankName' - 2345' if bank name
// A label for this card formatted as 'BankName' - ****2345' if bank name
// experiment turned on and bank name available; otherwise, formated as
// 'IssuerNetwork - 2345'.
// 'IssuerNetwork - ****2345'.
base::string16 NetworkOrBankNameAndLastFourDigits() const;
// Localized expiration for this card formatted as 'Exp: 06/17'.
base::string16 AbbreviatedExpirationDateForDisplay() const;
......
......@@ -1119,16 +1119,24 @@ INSTANTIATE_TEST_CASE_P(
TEST(CreditCardTest, LastFourDigits) {
CreditCard card(base::GenerateGUID(), "https://www.example.com/");
ASSERT_EQ(base::string16(), card.LastFourDigits());
ASSERT_EQ(base::UTF8ToUTF16(std::string(kUTF8MidlineEllipsis)),
card.ObfuscatedLastFourDigits());
test::SetCreditCardInfo(&card, "Baby Face Nelson", "5212341234123489", "01",
"2010", "1");
ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits());
ASSERT_EQ(base::UTF8ToUTF16(std::string(kUTF8MidlineEllipsis) + "3489"),
card.ObfuscatedLastFourDigits());
card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("3489"));
ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits());
ASSERT_EQ(base::UTF8ToUTF16(std::string(kUTF8MidlineEllipsis) + "3489"),
card.ObfuscatedLastFourDigits());
card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("489"));
ASSERT_EQ(base::ASCIIToUTF16("489"), card.LastFourDigits());
ASSERT_EQ(base::UTF8ToUTF16(std::string(kUTF8MidlineEllipsis) + "489"),
card.ObfuscatedLastFourDigits());
}
// Verifies that a credit card should be updated.
......
......@@ -1679,12 +1679,11 @@ std::vector<Suggestion> PersonalDataManager::GetSuggestionsForCards(
} else {
#if defined(OS_ANDROID)
// Since Android places the label on its own row, there's more
// horizontal
// space to work with. Show "Amex - 1234" rather than desktop's "*1234".
// horizontal space to work with. Show "Amex - 1234" rather than
// desktop's "****1234".
suggestion->label = credit_card->NetworkOrBankNameAndLastFourDigits();
#else
suggestion->label = base::ASCIIToUTF16("*");
suggestion->label.append(credit_card->LastFourDigits());
suggestion->label = credit_card->ObfuscatedLastFourDigits();
#endif
}
}
......
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