Index: chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc |
diff --git a/chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc b/chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc |
index 7a560a276f20b9b38b623aa921db16e2f7bb9dc0..fb7e8804557bd52c1227274bfea977e2a6ac4214 100644 |
--- a/chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc |
+++ b/chrome/browser/autofill/autofill_save_card_infobar_delegate_mobile_unittest.cc |
@@ -14,7 +14,9 @@ |
#include "chrome/test/base/testing_profile.h" |
#include "components/autofill/core/browser/autofill_test_utils.h" |
#include "components/autofill/core/browser/personal_data_manager.h" |
+#include "components/autofill/core/common/autofill_pref_names.h" |
#include "components/infobars/core/confirm_infobar_delegate.h" |
+#include "components/prefs/pref_service.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -54,7 +56,9 @@ class AutofillSaveCardInfoBarDelegateMobileTest |
void TearDown() override; |
protected: |
- std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(bool is_uploading); |
+ std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
+ bool is_uploading, |
+ bool did_user_accept_previous_save_credit_card_prompt); |
std::unique_ptr<TestPersonalDataManager> personal_data_; |
@@ -80,6 +84,9 @@ void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() { |
personal_data_.reset(new TestPersonalDataManager()); |
personal_data_->set_database(autofill_client->GetDatabase()); |
personal_data_->SetPrefService(profile()->GetPrefs()); |
+ |
+ profile()->GetPrefs()->SetBoolean( |
+ prefs::kAutofillAcceptSaveCreditCardPromptState, true); |
} |
void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
@@ -88,7 +95,9 @@ void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
} |
std::unique_ptr<ConfirmInfoBarDelegate> |
-AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(bool is_uploading) { |
+AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate( |
+ bool is_uploading, |
+ bool did_user_accept_previous_save_credit_card_prompt) { |
base::HistogramTester histogram_tester; |
CreditCard credit_card; |
std::unique_ptr<base::DictionaryValue> legal_message; |
@@ -97,11 +106,15 @@ AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(bool is_uploading) { |
is_uploading, credit_card, std::move(legal_message), |
base::Bind(base::IgnoreResult( |
&TestPersonalDataManager::SaveImportedCreditCard), |
- base::Unretained(personal_data_.get()), credit_card))); |
+ base::Unretained(personal_data_.get()), credit_card), |
+ profile()->GetPrefs())); |
std::string destination = is_uploading ? ".Server" : ".Local"; |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar" |
- + destination, |
- AutofillMetrics::INFOBAR_SHOWN, 1); |
+ std::string previous_response = |
+ did_user_accept_previous_save_credit_card_prompt ? ".PreviouslyAccepted" |
+ : ".PreviouslyDenied"; |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar" + destination + previous_response, |
+ AutofillMetrics::INFOBAR_SHOWN, 1); |
return delegate; |
} |
@@ -111,47 +124,55 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { |
// Accept the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ false)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ false, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ true)); |
EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
base::HistogramTester histogram_tester; |
EXPECT_TRUE(infobar->Accept()); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", |
- AutofillMetrics::INFOBAR_ACCEPTED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Local.PreviouslyAccepted", |
+ AutofillMetrics::INFOBAR_ACCEPTED, 1); |
} |
// Cancel the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ false)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ false, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ true)); |
base::HistogramTester histogram_tester; |
EXPECT_TRUE(infobar->Cancel()); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", |
- AutofillMetrics::INFOBAR_DENIED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Local.PreviouslyAccepted", |
+ AutofillMetrics::INFOBAR_DENIED, 1); |
} |
// Dismiss the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ false)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ false, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ false)); |
base::HistogramTester histogram_tester; |
infobar->InfoBarDismissed(); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", |
- AutofillMetrics::INFOBAR_DENIED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
+ AutofillMetrics::INFOBAR_DENIED, 1); |
} |
// Ignore the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ false)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ false, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ false)); |
base::HistogramTester histogram_tester; |
infobar.reset(); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", |
- AutofillMetrics::INFOBAR_IGNORED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
+ AutofillMetrics::INFOBAR_IGNORED, 1); |
} |
} |
@@ -161,47 +182,55 @@ TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { |
// Accept the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ true)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ true, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ true)); |
EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
base::HistogramTester histogram_tester; |
EXPECT_TRUE(infobar->Accept()); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
- AutofillMetrics::INFOBAR_ACCEPTED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Server.PreviouslyAccepted", |
+ AutofillMetrics::INFOBAR_ACCEPTED, 1); |
} |
// Cancel the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ true)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ true, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ true)); |
base::HistogramTester histogram_tester; |
EXPECT_TRUE(infobar->Cancel()); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
- AutofillMetrics::INFOBAR_DENIED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Server.PreviouslyAccepted", |
+ AutofillMetrics::INFOBAR_DENIED, 1); |
} |
// Dismiss the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ true)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ true, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ false)); |
base::HistogramTester histogram_tester; |
infobar->InfoBarDismissed(); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
- AutofillMetrics::INFOBAR_DENIED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
+ AutofillMetrics::INFOBAR_DENIED, 1); |
} |
// Ignore the infobar. |
{ |
- std::unique_ptr<ConfirmInfoBarDelegate> infobar( |
- CreateDelegate(/* is_uploading= */ true)); |
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
+ /* is_uploading= */ true, |
+ /* did_user_accept_previous_save_credit_card_prompt= */ false)); |
base::HistogramTester histogram_tester; |
infobar.reset(); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
- AutofillMetrics::INFOBAR_IGNORED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
+ AutofillMetrics::INFOBAR_IGNORED, 1); |
} |
} |