Commit 4759a157 authored by Jared Saul's avatar Jared Saul Committed by Commit Bot

[Autofill] Avoid offering local save for local cards

If credit card upload is not offered, Chrome can fall back to offering
local save instead.  It shouldn't do this for existing local cards.

Bug: 878177
Change-Id: I84ba77525864000a34aaa14b51305e854cd23c99
Reviewed-on: https://chromium-review.googlesource.com/1192405
Commit-Queue: Jared Saul <jsaul@google.com>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587665}
parent 2cbdecbb
...@@ -260,20 +260,21 @@ void CreditCardSaveManager::OnDidGetUploadDetails( ...@@ -260,20 +260,21 @@ void CreditCardSaveManager::OnDidGetUploadDetails(
} else { } else {
// If the upload details request failed and we *know* we have all possible // If the upload details request failed and we *know* we have all possible
// information (card number, expiration, cvc, name, and address), fall back // information (card number, expiration, cvc, name, and address), fall back
// to a local save. It indicates that "Payments doesn't want this card" or // to a local save (for new cards only). It indicates that "Payments doesn't
// "Payments doesn't currently support this country", in which case the // want this card" or "Payments doesn't currently support this country", in
// upload details request will consistently fail and if we don't fall back // which case the upload details request will consistently fail and if we
// to a local save, the user will never be offered *any* kind of credit card // don't fall back to a local save, the user will never be offered *any*
// save. (Note that this could intermittently backfire if there's a network // kind of credit card save. (Note that this could intermittently backfire
// breakdown or Payments outage, resulting in sometimes showing upload and // if there's a network breakdown or Payments outage, resulting in sometimes
// sometimes offering local save, but such cases should be rare.) // showing upload and sometimes offering local save, but such cases should
// be rare.)
int detected_values = GetDetectedValues(); int detected_values = GetDetectedValues();
bool found_name_and_postal_code_and_cvc = bool found_name_and_postal_code_and_cvc =
(detected_values & DetectedValue::CARDHOLDER_NAME || (detected_values & DetectedValue::CARDHOLDER_NAME ||
detected_values & DetectedValue::ADDRESS_NAME) && detected_values & DetectedValue::ADDRESS_NAME) &&
detected_values & DetectedValue::POSTAL_CODE && detected_values & DetectedValue::POSTAL_CODE &&
detected_values & DetectedValue::CVC; detected_values & DetectedValue::CVC;
if (found_name_and_postal_code_and_cvc) if (found_name_and_postal_code_and_cvc && !uploading_local_card_)
OfferCardLocalSave(upload_request_.card); OfferCardLocalSave(upload_request_.card);
upload_decision_metrics_ |= upload_decision_metrics_ |=
AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED; AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED;
......
...@@ -3417,6 +3417,58 @@ TEST_F(CreditCardSaveManagerTest, UploadCreditCard_UploadOfNewCard) { ...@@ -3417,6 +3417,58 @@ TEST_F(CreditCardSaveManagerTest, UploadCreditCard_UploadOfNewCard) {
AutofillMetrics::USER_ACCEPTED_UPLOAD_OF_NEW_CARD, 1); AutofillMetrics::USER_ACCEPTED_UPLOAD_OF_NEW_CARD, 1);
} }
// This test ensures that if offer-to-upload is denied by Google Payments, local
// save is not offered if the card is already a local card.
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_DenyingUploadOfLocalCardShouldNotOfferLocalSave) {
// Anything other than "en-US" will cause GetUploadDetails to return a failure
// response.
credit_card_save_manager_->SetAppLocale("pt-BR");
// Add a local credit card whose |TypeAndLastFourDigits| matches what we will
// enter below.
CreditCard local_card;
test::SetCreditCardInfo(&local_card, "Flo Master", "4111111111111111",
NextMonth().c_str(), NextYear().c_str(), "1");
local_card.set_record_type(CreditCard::LOCAL_CARD);
personal_data_.AddCreditCard(local_card);
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
FormData address_form;
test::CreateTestAddressFormData(&address_form);
FormsSeen(std::vector<FormData>(1, address_form));
ExpectUniqueFillableFormParsedUkm();
ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
FormSubmitted(address_form);
// Set up our credit card form data.
FormData credit_card_form;
CreateTestCreditCardFormData(&credit_card_form, true, false);
FormsSeen(std::vector<FormData>(1, credit_card_form));
ExpectFillableFormParsedUkm(2 /* num_fillable_forms_parsed */);
// Edit the data, and submit.
credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
credit_card_form.fields[2].value = ASCIIToUTF16(NextMonth());
credit_card_form.fields[3].value = ASCIIToUTF16(NextYear());
credit_card_form.fields[4].value = ASCIIToUTF16("123");
base::HistogramTester histogram_tester;
// Neither local or upload save should be offered in this case.
EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
FormSubmitted(credit_card_form);
EXPECT_FALSE(credit_card_save_manager_->CreditCardWasUploaded());
// Verify that metrics noted it was an existing local card for which credit
// card upload was offered and accepted.
histogram_tester.ExpectTotalCount("Autofill.UploadOfferedCardOrigin", 0);
histogram_tester.ExpectTotalCount("Autofill.UploadAcceptedCardOrigin", 0);
}
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_EloDisallowed) { TEST_F(CreditCardSaveManagerTest, UploadCreditCard_EloDisallowed) {
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamDisallowElo); features::kAutofillUpstreamDisallowElo);
......
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