Skip to content

Commit

Permalink
[CVV Storage] CVC suggestion dialog main text
Browse files Browse the repository at this point in the history
Update suggestion main text when the CVC field is focused.

This applies to local card, server card and virtual card.

Mock: https://screenshot.googleplex.com/4Yft9mWRkUBSi4G
Current UI: https://screenshot.googleplex.com/5AwFgP6LZ6Fk9GM
Implementation UI: https://screenshot.googleplex.com/C5jcCyQtoHKcCbY
Mocked FPAN, VCN UI: https://screenshot.googleplex.com/A4ciJDtpsZhCQSf

Mock confirmed with UX: https://screenshot.googleplex.com/7Nsa5jyE4psMibi

Change-Id: I40ad76897d69d0b7c3416c2365ec27b690a4f113
Bug: 1450749
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4763427
Commit-Queue: Jiali Huang <jialihuang@google.com>
Reviewed-by: Siyu An <siyua@chromium.org>
Reviewed-by: Florian Leimgruber <fleimgruber@google.com>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Vinny Persky <vinnypersky@google.com>
Cr-Commit-Position: refs/heads/main@{#1190381}
  • Loading branch information
jialihuang authored and Chromium LUCI CQ committed Aug 30, 2023
1 parent f71b696 commit 62112eb
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ AutofillSuggestionGenerator::GetSuggestionMainTextAndMinorTextForCard(
main_text = credit_card.CardNameAndLastFourDigits(nickname,
GetObfuscationLength());
}
} else if (type.GetStorableType() == CREDIT_CARD_VERIFICATION_CODE) {
CHECK(!credit_card.cvc().empty());
main_text =
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT);
} else {
main_text = credit_card.GetInfo(type, app_locale);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AutofillSuggestionGeneratorTest : public testing::Test {
CreditCard server_card(CreditCard::RecordType::kMaskedServerCard, "a123");
test::SetCreditCardInfo(&server_card, "Elvis Presley", "1111" /* Visa */,
test::NextMonth().c_str(), test::NextYear().c_str(),
"1");
"1", /*cvc=*/u"123");
server_card.SetNetworkForMaskedCard(kVisaCard);
server_card.set_server_id(server_id);
server_card.set_guid(guid);
Expand All @@ -112,7 +112,7 @@ class AutofillSuggestionGeneratorTest : public testing::Test {
CreditCard local_card(guid, test::kEmptyOrigin);
test::SetCreditCardInfo(&local_card, "Elvis Presley", "4111111111111111",
test::NextMonth().c_str(), test::NextYear().c_str(),
"1");
"1", /*cvc=*/u"123");
return local_card;
}

Expand Down Expand Up @@ -1046,6 +1046,118 @@ TEST_F(AutofillCreditCardSuggestionContentTest,
base::UTF8ToUTF16(test::NextYear().substr(2))}));
}

#if !BUILDFLAG(IS_ANDROID)
// Verify that the suggestion's texts are populated correctly for a local and
// server card suggestion when the CVC field is focused.
TEST_F(AutofillCreditCardSuggestionContentTest,
GetSuggestionsForCreditCards_CvcField) {
// Create one server card and one local card with CVC.
CreditCard local_card = CreateLocalCard();
// We used last 4 to deduplicate local card and server card so we should set
// local card with different last 4.
local_card.SetNumber(u"5454545454545454");
personal_data()->AddCreditCard(std::move(local_card));
personal_data()->AddServerCreditCard(CreateServerCard());

bool should_display_gpay_logo;
bool with_offer;
autofill_metrics::CardMetadataLoggingContext metadata_logging_context;
const std::vector<Suggestion> suggestions =
suggestion_generator()->GetSuggestionsForCreditCards(
FormFieldData(), AutofillType(CREDIT_CARD_VERIFICATION_CODE),
/*app_locale=*/"en", should_display_gpay_logo, with_offer,
metadata_logging_context);

// Both local card and server card suggestion should be shown when CVC field
// is focused.
ASSERT_EQ(suggestions.size(), 2U);
EXPECT_EQ(suggestions[0].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
EXPECT_EQ(suggestions[1].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
}

// Verify that the suggestion's texts are populated correctly for a duplicate
// local and server card suggestion when the CVC field is focused.
TEST_F(AutofillCreditCardSuggestionContentTest,
GetSuggestionsForCreditCards_Duplicate_CvcField) {
// Create 2 duplicate local and server card with same last 4.
personal_data()->AddCreditCard(CreateLocalCard());
personal_data()->AddServerCreditCard(CreateServerCard());

bool should_display_gpay_logo;
bool with_offer;
autofill_metrics::CardMetadataLoggingContext metadata_logging_context;
const std::vector<Suggestion> suggestions =
suggestion_generator()->GetSuggestionsForCreditCards(
FormFieldData(), AutofillType(CREDIT_CARD_VERIFICATION_CODE),
/*app_locale=*/"en", should_display_gpay_logo, with_offer,
metadata_logging_context);

// Only 1 suggestion should be shown when CVC field is focused.
ASSERT_EQ(suggestions.size(), 1U);
EXPECT_EQ(suggestions[0].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
}

// Verify that the FPAN and VCN suggestion's texts are populated correctly for a
// enrolled card when the CVC field is focused.
TEST_F(AutofillCreditCardSuggestionContentTest,
GetSuggestionsForCreditCards_VirtualCard_CvcField) {
// Create a server card with CVC that enrolled to virtual card.
CreditCard server_card = CreateServerCard();
server_card.set_virtual_card_enrollment_state(
CreditCard::VirtualCardEnrollmentState::kEnrolled);
personal_data()->AddServerCreditCard(std::move(server_card));

bool should_display_gpay_logo;
bool with_offer;
autofill_metrics::CardMetadataLoggingContext metadata_logging_context;
const std::vector<Suggestion> suggestions =
suggestion_generator()->GetSuggestionsForCreditCards(
FormFieldData(), AutofillType(CREDIT_CARD_VERIFICATION_CODE),
/*app_locale=*/"en", should_display_gpay_logo, with_offer,
metadata_logging_context);

// Both FPAN and VCN suggestion should be shown when CVC field is focused.
ASSERT_EQ(suggestions.size(), 2U);
EXPECT_EQ(suggestions[0].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
EXPECT_EQ(suggestions[1].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
}

// Verify that the FPAN and VCN suggestion's texts are populated correctly for a
// enrolled card when the CVC field is focused.
TEST_F(AutofillCreditCardSuggestionContentTest,
GetSuggestionsForCreditCards_VirtualCard_Duplicate_CvcField) {
// Create duplicate local and server card with CVC that enrolled to virtual
// card.
CreditCard server_card = CreateServerCard();
server_card.set_virtual_card_enrollment_state(
CreditCard::VirtualCardEnrollmentState::kEnrolled);
personal_data()->AddServerCreditCard(std::move(server_card));
personal_data()->AddCreditCard(CreateLocalCard());

bool should_display_gpay_logo;
bool with_offer;
autofill_metrics::CardMetadataLoggingContext metadata_logging_context;
const std::vector<Suggestion> suggestions =
suggestion_generator()->GetSuggestionsForCreditCards(
FormFieldData(), AutofillType(CREDIT_CARD_VERIFICATION_CODE),
/*app_locale=*/"en", should_display_gpay_logo, with_offer,
metadata_logging_context);

// Both FPAN and VCN suggestion should be shown when CVC field is focused.
ASSERT_EQ(suggestions.size(), 2U);
EXPECT_EQ(suggestions[0].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
EXPECT_EQ(suggestions[1].main_text.value,
l10n_util::GetStringUTF16(IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT));
}

#endif // !BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_IOS)
// Tests that credit card suggestions on iOS use the correct number of '•'
// characters depending on the kAutofillUseTwoDotsForLastFourDigits feature.
Expand Down
3 changes: 3 additions & 0 deletions components/autofill_payments_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -980,4 +980,7 @@
Delete saved security codes
</message>
</if>
<message name="IDS_AUTOFILL_CVC_SUGGESTION_MAIN_TEXT" desc="The main text shown in the credit card suggestion list when the CVC field is focused. It will be the main text which is on the first line of suggestion. If the user hovers over the suggestion, the credit card will be previewed. If the user clicks on the suggestion, credit card will be filled.">
CVC
</message>
</grit-part>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d4e43f41387a15357557c27f6e9cbe0e646c67b6

0 comments on commit 62112eb

Please sign in to comment.