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 2b5e9a47e5693c9924a47871e97c3771627ce818..3aa5b178449d7503d7cf225f2853ed89f39d2816 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" |
@@ -21,15 +21,6 @@ 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: |
TestPersonalDataManager() : PersonalDataManager("en-US") {} |
@@ -58,8 +49,7 @@ class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { |
void TearDown() override; |
protected: |
- scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
- MockAutofillMetrics* metric_logger); |
+ scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); |
scoped_ptr<TestPersonalDataManager> personal_data_; |
}; |
@@ -89,72 +79,61 @@ void AutofillCCInfobarDelegateTest::TearDown() { |
} |
scoped_ptr<ConfirmInfoBarDelegate> |
-AutofillCCInfobarDelegateTest::CreateDelegate( |
- MockAutofillMetrics* metric_logger) { |
- EXPECT_CALL(*metric_logger, |
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
- |
+AutofillCCInfobarDelegateTest::CreateDelegate() { |
+ base::HistogramTester histogram_tester; |
CreditCard credit_card; |
- return AutofillCCInfoBarDelegate::Create( |
- metric_logger, |
- base::Bind( |
+ scoped_ptr<ConfirmInfoBarDelegate> delegate( |
+ AutofillCCInfoBarDelegate::Create(base::Bind( |
base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), |
- base::Unretained(personal_data_.get()), |
- credit_card)); |
+ base::Unretained(personal_data_.get()), credit_card))); |
+ histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
+ AutofillMetrics::INFOBAR_SHOWN, 1); |
+ return delegate.Pass(); |
} |
// 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(&metric_logger)); |
- ASSERT_TRUE(infobar); |
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
- EXPECT_CALL(metric_logger, |
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)); |
- EXPECT_CALL(metric_logger, |
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) |
- .Times(0); |
+ base::HistogramTester histogram_tester; |
EXPECT_TRUE(infobar->Accept()); |
+ histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
+ AutofillMetrics::INFOBAR_ACCEPTED, 1); |
} |
// Cancel the infobar. |
{ |
- 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); |
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
+ |
+ base::HistogramTester histogram_tester; |
EXPECT_TRUE(infobar->Cancel()); |
+ histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
+ AutofillMetrics::INFOBAR_DENIED, 1); |
} |
// Dismiss the infobar. |
{ |
- 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); |
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
+ |
+ base::HistogramTester histogram_tester; |
infobar->InfoBarDismissed(); |
+ histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
+ AutofillMetrics::INFOBAR_DENIED, 1); |
} |
// Ignore the infobar. |
{ |
- scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |
- ASSERT_TRUE(infobar); |
- EXPECT_CALL(metric_logger, |
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) |
- .Times(1); |
+ scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
+ |
+ base::HistogramTester histogram_tester; |
+ infobar.reset(); |
+ histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", |
+ AutofillMetrics::INFOBAR_IGNORED, 1); |
} |
} |