Skip to content

Commit

Permalink
[101] Add metrics recorded for both save card infobar & messages
Browse files Browse the repository at this point in the history
Add metrics recorded for both so that we can see data for both
arms in the same histograms.

See https://crbug.com/1313716 for more details.

(cherry picked from commit 7c05d01)

Bug: 1313716
Change-Id: Iabf7e75130e0eaa10f503fad62c4c1b220615294
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3572208
Reviewed-by: Aishwarya Rajesh <aishwaryarj@google.com>
Reviewed-by: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: Jared Saul <jsaul@google.com>
Commit-Queue: Lijin Shen <lazzzis@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#991319}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3587326
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/branch-heads/4951@{#764}
Cr-Branched-From: 27de622-refs/heads/main@{#982481}
  • Loading branch information
Lijin Shen authored and Chromium LUCI CQ committed Apr 14, 2022
1 parent da6ce38 commit 034c683
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 25 deletions.
Expand Up @@ -14,6 +14,7 @@
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/metrics/payments/save_credit_card_prompt_metrics.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/common/autofill_payments_features.h"
Expand Down Expand Up @@ -51,6 +52,12 @@ class AutofillSaveCardInfoBarDelegateMobileTest
bool is_uploading,
std::string legal_message_string,
CreditCard credit_card = CreditCard());
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
CreateDelegateWithLegalMessageAndOptions(
bool is_uploading,
std::string legal_message_string,
AutofillClient::SaveCreditCardOptions options,
CreditCard credit_card = CreditCard());

std::unique_ptr<TestPersonalDataManager> personal_data_;

Expand Down Expand Up @@ -103,6 +110,18 @@ AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithLegalMessage(
bool is_uploading,
std::string legal_message_string,
CreditCard credit_card) {
return CreateDelegateWithLegalMessageAndOptions(
is_uploading, legal_message_string,
AutofillClient::SaveCreditCardOptions(), credit_card);
}

std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
AutofillSaveCardInfoBarDelegateMobileTest::
CreateDelegateWithLegalMessageAndOptions(
bool is_uploading,
std::string legal_message_string,
AutofillClient::SaveCreditCardOptions options,
CreditCard credit_card) {
LegalMessageLines legal_message_lines;
if (!legal_message_string.empty()) {
std::unique_ptr<base::Value> value(
Expand All @@ -116,8 +135,7 @@ AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithLegalMessage(
credit_card_to_save_ = credit_card;
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate(
new AutofillSaveCardInfoBarDelegateMobile(
is_uploading, AutofillClient::SaveCreditCardOptions(), credit_card,
legal_message_lines,
is_uploading, options, credit_card, legal_message_lines,
/*upload_save_card_callback=*/
base::BindOnce(&AutofillSaveCardInfoBarDelegateMobileTest::
UploadSaveCardPromptCallback,
Expand All @@ -129,8 +147,7 @@ AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithLegalMessage(
credit_card_to_save_ = credit_card;
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate(
new AutofillSaveCardInfoBarDelegateMobile(
is_uploading, AutofillClient::SaveCreditCardOptions(), credit_card,
legal_message_lines,
is_uploading, options, credit_card, legal_message_lines,
/*upload_save_card_callback=*/{},
/*local_save_card_callback=*/
base::BindOnce(&AutofillSaveCardInfoBarDelegateMobileTest::
Expand Down Expand Up @@ -165,6 +182,9 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local_Main) {
ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Local",
SaveCreditCardPromptResult::kAccepted, 1);
}

// Dismiss the infobar.
Expand All @@ -176,6 +196,9 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local_Main) {
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Local",
SaveCreditCardPromptResult::kDenied, 1);
}

// Ignore the infobar.
Expand All @@ -187,6 +210,9 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local_Main) {
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Local",
SaveCreditCardPromptResult::kIgnored, 1);
}
}

Expand Down Expand Up @@ -232,9 +258,66 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server_Main) {
ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kAccepted, 1);
}

// Dismiss the infobar.
// Accept the infobar which should request an expiration date.
{
personal_data_->ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
AutofillClient::SaveCreditCardOptions()
.with_should_request_expiration_date_from_user(true)));

base::HistogramTester histogram_tester;
EXPECT_TRUE(infobar->Accept());
ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingExpirationDate",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
// kAccept of "Autofill.CreditCardSaveFlowResult.Server" should only be
// recorded when all data is collected.
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kAccepted, 0);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingExpirationDate",
SaveCreditCardPromptResult::kAccepted, 0);
}

// Accept the infobar which should request a cardholder name.
{
personal_data_->ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
AutofillClient::SaveCreditCardOptions()
.with_should_request_name_from_user(true)));

base::HistogramTester histogram_tester;
EXPECT_TRUE(infobar->Accept());
ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingCardholderName",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
// kAccept of "Autofill.CreditCardSaveFlowResult.Server" should only be
// recorded when all data is collected.
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kAccepted, 0);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingCardholderName",
SaveCreditCardPromptResult::kAccepted, 0);
}

// Dismiss the infobar which doesn't request any data from user.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ true));
Expand All @@ -243,9 +326,58 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server_Main) {
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kDenied, 1);
}

// Ignore the infobar.
// Dismiss the infobar which should request an expiration date.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
AutofillClient::SaveCreditCardOptions()
.with_should_request_expiration_date_from_user(true)));

base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingExpirationDate",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kDenied, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingExpirationDate",
SaveCreditCardPromptResult::kDenied, 1);
}

// Dismiss the infobar which should request a cardholder name.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
AutofillClient::SaveCreditCardOptions()
.with_should_request_name_from_user(true)));

base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingCardholderName",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kDenied, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingCardholderName",
SaveCreditCardPromptResult::kDenied, 1);
}

// Ignore the infobar which doesn't request any data from user.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ true));
Expand All @@ -254,6 +386,55 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server_Main) {
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kIgnored, 1);
}

// Ignore the infobar which should request an expiration date.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
AutofillClient::SaveCreditCardOptions()
.with_should_request_expiration_date_from_user(true)));

base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingExpirationDate",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kIgnored, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingExpirationDate",
SaveCreditCardPromptResult::kIgnored, 1);
}

// Ignore the infobar which should request a cardholder name.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
AutofillClient::SaveCreditCardOptions()
.with_should_request_name_from_user(true)));

base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingCardholderName",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
SaveCreditCardPromptResult::kIgnored, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingCardholderName",
SaveCreditCardPromptResult::kIgnored, 1);
}
}

Expand Down
Expand Up @@ -30,6 +30,12 @@ SaveCardMessageControllerAndroid::SaveCardMessageControllerAndroid() {}

SaveCardMessageControllerAndroid::~SaveCardMessageControllerAndroid() {
DismissMessage();
// The dialog has shown before but user didn't take any action, like
// user navigates to ToS page and then closes the previous tab.
if (is_dialog_shown_ && !HadUserInteraction()) {
OnPromptCompleted(SaveCreditCardPromptResult::kInteractedAndIgnored,
/*user_provided_details=*/{});
}
}

void SaveCardMessageControllerAndroid::Show(
Expand Down Expand Up @@ -135,9 +141,8 @@ void SaveCardMessageControllerAndroid::HandleMessageDismiss(
!HadUserInteraction()) {
// Gesture: users explicitly swipe the UI to dismiss the message
bool gesture_dismiss = dismiss_reason == messages::DismissReason::GESTURE;
OnPromptCompleted(gesture_dismiss
? AutofillClient::SaveCardOfferUserDecision::kDeclined
: AutofillClient::SaveCardOfferUserDecision::kIgnored,
OnPromptCompleted(gesture_dismiss ? SaveCreditCardPromptResult::kDenied
: SaveCreditCardPromptResult::kIgnored,
/*user_provided_details=*/{});
}
// Reset all if we won't show dialogs in the next steps
Expand Down Expand Up @@ -172,7 +177,7 @@ void SaveCardMessageControllerAndroid::MaybeShowDialog() {
is_dialog_shown_ = true;
FixDate();
} else {
OnPromptCompleted(AutofillClient::SaveCardOfferUserDecision::kAccepted, {});
OnPromptCompleted(SaveCreditCardPromptResult::kAccepted, {});
}
}

Expand Down Expand Up @@ -200,7 +205,7 @@ void SaveCardMessageControllerAndroid::ConfirmSaveCard() {
void SaveCardMessageControllerAndroid::OnNameConfirmed(
JNIEnv* env,
const base::android::JavaParamRef<jstring>& name) {
OnPromptCompleted(AutofillClient::SaveCardOfferUserDecision::kAccepted,
OnPromptCompleted(SaveCreditCardPromptResult::kAccepted,
{base::android::ConvertJavaStringToUTF16(name),
std::u16string(), std::u16string()});
}
Expand All @@ -210,13 +215,13 @@ void SaveCardMessageControllerAndroid::OnDateConfirmed(
const base::android::JavaParamRef<jstring>& month,
const base::android::JavaParamRef<jstring>& year) {
OnPromptCompleted(
AutofillClient::SaveCardOfferUserDecision::kAccepted,
SaveCreditCardPromptResult::kAccepted,
{std::u16string(), base::android::ConvertJavaStringToUTF16(month),
base::android::ConvertJavaStringToUTF16(year)});
}

void SaveCardMessageControllerAndroid::OnSaveCardConfirmed(JNIEnv* env) {
OnPromptCompleted(AutofillClient::SaveCardOfferUserDecision::kAccepted, {});
OnPromptCompleted(SaveCreditCardPromptResult::kAccepted, {});
}

// --- Dialog Dismissed ---
Expand All @@ -226,7 +231,7 @@ void SaveCardMessageControllerAndroid::DialogDismissed(JNIEnv* env) {
return;
}
if (!HadUserInteraction()) {
OnPromptCompleted(AutofillClient::SaveCardOfferUserDecision::kDeclined,
OnPromptCompleted(SaveCreditCardPromptResult::kInteractedAndIgnored,
/*user_provided_details=*/{});
}
ResetInternal();
Expand Down Expand Up @@ -255,25 +260,37 @@ bool SaveCardMessageControllerAndroid::IsGooglePayBrandingEnabled() const {
}

void SaveCardMessageControllerAndroid::OnPromptCompleted(
AutofillClient::SaveCardOfferUserDecision user_decision,
SaveCreditCardPromptResult save_result,
AutofillClient::UserProvidedCardDetails user_provided_details) {
MessageMetrics message_state;
MessageDialogPromptMetrics dialog_state;
switch (user_decision) {
case AutofillClient::SaveCardOfferUserDecision::kAccepted:
AutofillClient::SaveCardOfferUserDecision user_decision;
switch (save_result) {
case SaveCreditCardPromptResult::kAccepted:
user_decision = AutofillClient::SaveCardOfferUserDecision::kAccepted;
message_state = MessageMetrics::kAccepted;
dialog_state = MessageDialogPromptMetrics::kAccepted;
break;
case AutofillClient::SaveCardOfferUserDecision::kDeclined:
case SaveCreditCardPromptResult::kDenied:
user_decision = AutofillClient::SaveCardOfferUserDecision::kDeclined;
message_state = MessageMetrics::kDenied;
dialog_state = MessageDialogPromptMetrics::kDenied;
break;
case AutofillClient::SaveCardOfferUserDecision::kIgnored:
case SaveCreditCardPromptResult::kIgnored:
user_decision = AutofillClient::SaveCardOfferUserDecision::kIgnored;
message_state = MessageMetrics::kIgnored;
dialog_state = MessageDialogPromptMetrics::kIgnored;
break;
case SaveCreditCardPromptResult::kInteractedAndIgnored:
// kIgnore in following metrics is equivalent to kInteractedAndIgnored and
// kIgnored of SaveCreditCardPromptResult.
user_decision = AutofillClient::SaveCardOfferUserDecision::kIgnored;
message_state = MessageMetrics::kIgnored;
dialog_state = MessageDialogPromptMetrics::kIgnored;
break;
}
LogAutofillCreditCardMessageMetrics(message_state, is_upload_, options_);
LogSaveCreditCardPromptResult(save_result, is_upload_, options_);
if (is_upload_) {
if (is_dialog_shown_) {
LogAutofillCreditCardMessageDialogPromptMetrics(dialog_state, options_,
Expand Down

0 comments on commit 034c683

Please sign in to comment.