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..3eec3f8beb5225df20598c77240074f4100e9aaa 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,10 @@ |
#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 "components/user_prefs/user_prefs.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -54,11 +57,16 @@ 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_; |
private: |
+ // Weak reference to read & write |kAutofillAcceptSaveCreditCardPromptState|. |
+ PrefService* pref_service_{nullptr}; |
+ |
DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); |
}; |
@@ -80,6 +88,11 @@ void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() { |
personal_data_.reset(new TestPersonalDataManager()); |
personal_data_->set_database(autofill_client->GetDatabase()); |
personal_data_->SetPrefService(profile()->GetPrefs()); |
+ |
+ pref_service_ = |
+ user_prefs::UserPrefs::Get(web_contents()->GetBrowserContext()); |
+ pref_service_->SetBoolean(prefs::kAutofillAcceptSaveCreditCardPromptState, |
+ true); |
} |
void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
@@ -88,7 +101,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; |
@@ -99,9 +114,12 @@ AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(bool is_uploading) { |
&TestPersonalDataManager::SaveImportedCreditCard), |
base::Unretained(personal_data_.get()), credit_card))); |
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 +129,54 @@ 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 +186,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= */ true)); |
base::HistogramTester histogram_tester; |
infobar->InfoBarDismissed(); |
- histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
- AutofillMetrics::INFOBAR_DENIED, 1); |
+ histogram_tester.ExpectUniqueSample( |
+ "Autofill.CreditCardInfoBar.Server.PreviouslyAccepted", |
+ 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); |
} |
} |