| Index: chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc
|
| diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc
|
| index 3aa5b178449d7503d7cf225f2853ed89f39d2816..2b5e9a47e5693c9924a47871e97c3771627ce818 100644
|
| --- a/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc
|
| +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc
|
| @@ -5,11 +5,11 @@
|
| #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
|
|
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "base/test/histogram_tester.h"
|
| #include "chrome/browser/autofill/personal_data_manager_factory.h"
|
| #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
|
| #include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "components/autofill/core/browser/autofill_metrics.h"
|
| #include "components/autofill/core/browser/autofill_test_utils.h"
|
| #include "components/autofill/core/browser/personal_data_manager.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -20,6 +20,15 @@
|
| namespace autofill {
|
|
|
| namespace {
|
| +
|
| +class MockAutofillMetrics : public AutofillMetrics {
|
| + public:
|
| + MockAutofillMetrics() {}
|
| + MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
|
| +};
|
|
|
| class TestPersonalDataManager : public PersonalDataManager {
|
| public:
|
| @@ -49,7 +58,8 @@
|
| void TearDown() override;
|
|
|
| protected:
|
| - scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate();
|
| + scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
|
| + MockAutofillMetrics* metric_logger);
|
|
|
| scoped_ptr<TestPersonalDataManager> personal_data_;
|
| };
|
| @@ -79,61 +89,72 @@
|
| }
|
|
|
| scoped_ptr<ConfirmInfoBarDelegate>
|
| -AutofillCCInfobarDelegateTest::CreateDelegate() {
|
| - base::HistogramTester histogram_tester;
|
| +AutofillCCInfobarDelegateTest::CreateDelegate(
|
| + MockAutofillMetrics* metric_logger) {
|
| + EXPECT_CALL(*metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
|
| +
|
| CreditCard credit_card;
|
| - scoped_ptr<ConfirmInfoBarDelegate> delegate(
|
| - AutofillCCInfoBarDelegate::Create(base::Bind(
|
| + return AutofillCCInfoBarDelegate::Create(
|
| + metric_logger,
|
| + base::Bind(
|
| base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
|
| - base::Unretained(personal_data_.get()), credit_card)));
|
| - histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
|
| - AutofillMetrics::INFOBAR_SHOWN, 1);
|
| - return delegate.Pass();
|
| + base::Unretained(personal_data_.get()),
|
| + credit_card));
|
| }
|
|
|
| // Test that credit card infobar metrics are logged correctly.
|
| TEST_F(AutofillCCInfobarDelegateTest, Metrics) {
|
| + MockAutofillMetrics metric_logger;
|
| ::testing::InSequence dummy;
|
|
|
| // Accept the infobar.
|
| {
|
| - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
|
| + ASSERT_TRUE(infobar);
|
| EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED));
|
|
|
| - base::HistogramTester histogram_tester;
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
|
| + .Times(0);
|
| EXPECT_TRUE(infobar->Accept());
|
| - histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
|
| - AutofillMetrics::INFOBAR_ACCEPTED, 1);
|
| }
|
|
|
| // Cancel the infobar.
|
| {
|
| - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| -
|
| - base::HistogramTester histogram_tester;
|
| + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
|
| + ASSERT_TRUE(infobar);
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED))
|
| + .Times(1);
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
|
| + .Times(0);
|
| EXPECT_TRUE(infobar->Cancel());
|
| - histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
|
| - AutofillMetrics::INFOBAR_DENIED, 1);
|
| }
|
|
|
| // Dismiss the infobar.
|
| {
|
| - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| -
|
| - base::HistogramTester histogram_tester;
|
| + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
|
| + ASSERT_TRUE(infobar);
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED))
|
| + .Times(1);
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
|
| + .Times(0);
|
| infobar->InfoBarDismissed();
|
| - histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
|
| - AutofillMetrics::INFOBAR_DENIED, 1);
|
| }
|
|
|
| // Ignore the infobar.
|
| {
|
| - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| -
|
| - base::HistogramTester histogram_tester;
|
| - infobar.reset();
|
| - histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar",
|
| - AutofillMetrics::INFOBAR_IGNORED, 1);
|
| + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
|
| + ASSERT_TRUE(infobar);
|
| + EXPECT_CALL(metric_logger,
|
| + LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
|
| + .Times(1);
|
| }
|
| }
|
|
|
|
|