Chromium Code Reviews| Index: chrome/browser/autofill/autofill_metrics_unittest.cc |
| diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc |
| index 40fb33fec085a66c81466c168d51460678c4a665..1b208e1a572cee12d226618742c75c5749704bd4 100644 |
| --- a/chrome/browser/autofill/autofill_metrics_unittest.cc |
| +++ b/chrome/browser/autofill/autofill_metrics_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/string16.h" |
| #include "base/time.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/autofill/autocheckout_infobar_delegate.h" |
| #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| #include "chrome/browser/autofill/autofill_common_test.h" |
| #include "chrome/browser/autofill/autofill_manager.h" |
| @@ -22,6 +23,7 @@ |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "content/public/test/test_browser_thread.h" |
| +#include "googleurl/src/gurl.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/gfx/rect.h" |
| @@ -39,6 +41,7 @@ class MockAutofillMetrics : public AutofillMetrics { |
| public: |
| MockAutofillMetrics() {} |
| MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); |
| + MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric)); |
| MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, |
| void(DeveloperEngagementMetric metric)); |
| MOCK_CONST_METHOD3(LogHeuristicTypePrediction, |
| @@ -257,6 +260,22 @@ class TestAutofillManager : public AutofillManager { |
| DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| }; |
| +class TestAutocheckoutManager : public AutocheckoutManager { |
| + public: |
| + explicit TestAutocheckoutManager(AutofillManager* autofill_manager) |
| + : AutocheckoutManager(autofill_manager) { |
| + } |
|
Ilya Sherman
2013/01/18 01:45:02
nit: It's best to explicitly include a (virtual) d
Raman Kakilate
2013/01/18 04:22:30
Done.
|
| + |
| + virtual void ShowAutocheckoutDialog( |
| + const GURL& frame_url, |
| + const content::SSLStatus& ssl_status) OVERRIDE { |
| + // no-op. Just used as callback from autocheckout_infobar_delegate. |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TestAutocheckoutManager); |
| +}; |
| + |
| } // namespace |
| class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
| @@ -272,6 +291,9 @@ class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
| MockAutofillMetrics* metric_logger, |
| CreditCard** created_card); |
| + scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate( |
| + MockAutofillMetrics* metric_logger); |
| + |
| content::TestBrowserThread ui_thread_; |
| content::TestBrowserThread file_thread_; |
| @@ -347,6 +369,20 @@ scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |
| metric_logger); |
| } |
| +scoped_ptr<ConfirmInfoBarDelegate> |
| +AutofillMetricsTest::CreateAutocheckoutDelegate( |
| + MockAutofillMetrics* metric_logger) { |
| + EXPECT_CALL(*metric_logger, |
| + LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| + GURL url("www.google.com"); |
| + content::SSLStatus ssl_status; |
| + return AutocheckoutInfoBarDelegate::Create( |
| + *metric_logger, |
| + url, |
| + ssl_status, |
| + new TestAutocheckoutManager(NULL)); |
| +} |
| + |
| // Test that we log quality metrics appropriately. |
| TEST_F(AutofillMetricsTest, QualityMetrics) { |
| // Set up our form data. |
| @@ -1186,6 +1222,65 @@ TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |
| } |
| } |
| +// Test that autofill flow infobar metrics are logged correctly. |
| +TEST_F(AutofillMetricsTest, AutocheckoutInfoBar) { |
| + MockAutofillMetrics metric_logger; |
| + ::testing::InSequence dummy; |
| + |
| + // Accept the infobar. |
| + { |
| + scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| + CreateAutocheckoutDelegate(&metric_logger)); |
| + ASSERT_TRUE(infobar); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| + EXPECT_TRUE(infobar->Accept()); |
| + } |
| + |
| + // Cancel the infobar. |
| + { |
| + scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| + CreateAutocheckoutDelegate(&metric_logger)); |
| + ASSERT_TRUE(infobar); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| + EXPECT_TRUE(infobar->Cancel()); |
| + } |
| + |
| + // Dismiss the infobar. |
| + { |
| + scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| + CreateAutocheckoutDelegate(&metric_logger)); |
| + ASSERT_TRUE(infobar); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| + infobar->InfoBarDismissed(); |
| + } |
| + |
| + // Ignore the infobar. |
| + { |
| + scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| + CreateAutocheckoutDelegate(&metric_logger)); |
| + ASSERT_TRUE(infobar); |
| + EXPECT_CALL(metric_logger, |
| + LogAutocheckoutInfoBarMetric( |
| + AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
| + } |
| +} |
| + |
| + |
| // Test that server query response experiment id metrics are logged correctly. |
| TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { |
| MockAutofillMetrics metric_logger; |