Commit 9f39c8bd authored by blundell@chromium.org's avatar blundell@chromium.org

Moved CCInfobarDelegate tests out of AutofillMetricsTest

The AutofillMetrics unittests will be componentized. The infobar-related tests,
however, cannot be componentized, as infobars are currently a //chrome-level
concept. This CL splits out the infobar-related tests from AutofillMetricsTest
into a new AutofillCCInfobarDelegateTest.

BUG=303083

Review URL: https://codereview.chromium.org/177923004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255842 0039d316-1c4b-4281-b951-d872f2087c98
parent f3a729d5
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.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"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
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") {}
using PersonalDataManager::set_database;
using PersonalDataManager::SetPrefService;
// Overridden to avoid a trip to the database.
virtual void LoadProfiles() OVERRIDE {}
virtual void LoadCreditCards() OVERRIDE {}
MOCK_METHOD1(SaveImportedCreditCard,
std::string(const CreditCard& imported_credit_card));
private:
DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
};
} // namespace
class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness {
public:
virtual ~AutofillCCInfobarDelegateTest();
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
protected:
scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
MockAutofillMetrics* metric_logger);
scoped_ptr<TestPersonalDataManager> personal_data_;
};
AutofillCCInfobarDelegateTest::~AutofillCCInfobarDelegateTest() {}
void AutofillCCInfobarDelegateTest::SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
// Ensure Mac OS X does not pop up a modal dialog for the Address Book.
autofill::test::DisableSystemServices(profile()->GetPrefs());
PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
TabAutofillManagerDelegate::CreateForWebContents(web_contents());
autofill::TabAutofillManagerDelegate* manager_delegate =
autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
personal_data_.reset(new TestPersonalDataManager());
personal_data_->set_database(manager_delegate->GetDatabase());
personal_data_->SetPrefService(profile()->GetPrefs());
}
void AutofillCCInfobarDelegateTest::TearDown() {
personal_data_.reset();
ChromeRenderViewHostTestHarness::TearDown();
}
scoped_ptr<ConfirmInfoBarDelegate>
AutofillCCInfobarDelegateTest::CreateDelegate(
MockAutofillMetrics* metric_logger) {
EXPECT_CALL(*metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
CreditCard credit_card;
return AutofillCCInfoBarDelegate::Create(
metric_logger,
base::Bind(
base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
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(&metric_logger));
ASSERT_TRUE(infobar);
EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED));
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
.Times(0);
EXPECT_TRUE(infobar->Accept());
}
// 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);
EXPECT_TRUE(infobar->Cancel());
}
// 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);
infobar->InfoBarDismissed();
}
// Ignore the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
ASSERT_TRUE(infobar);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
.Times(1);
}
}
} // namespace autofill
......@@ -595,6 +595,7 @@
'browser/autocomplete/keyword_provider_unittest.cc',
'browser/autocomplete/search_provider_unittest.cc',
'browser/autocomplete/shortcuts_provider_unittest.cc',
'browser/autofill/autofill_cc_infobar_delegate_unittest.cc',
'browser/background/background_application_list_model_unittest.cc',
'browser/background/background_contents_service_unittest.cc',
'browser/background/background_mode_manager_unittest.cc',
......
......@@ -11,7 +11,6 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
......@@ -242,9 +241,6 @@ class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
virtual void TearDown() OVERRIDE;
protected:
scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
MockAutofillMetrics* metric_logger);
scoped_ptr<TestAutofillDriver> autofill_driver_;
scoped_ptr<TestAutofillManager> autofill_manager_;
scoped_ptr<TestPersonalDataManager> personal_data_;
......@@ -291,19 +287,6 @@ void AutofillMetricsTest::TearDown() {
ChromeRenderViewHostTestHarness::TearDown();
}
scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
MockAutofillMetrics* metric_logger) {
EXPECT_CALL(*metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
CreditCard credit_card;
return AutofillCCInfoBarDelegate::Create(
metric_logger,
base::Bind(
base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
base::Unretained(personal_data_.get()), credit_card));
}
// Test that we log quality metrics appropriately.
TEST_F(AutofillMetricsTest, QualityMetrics) {
// Set up our form data.
......@@ -722,54 +705,6 @@ TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
autofill::NO_SPECIAL_FORMS_SEEN);
}
// Test that credit card infobar metrics are logged correctly.
TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
testing::NiceMock<MockAutofillMetrics> metric_logger;
::testing::InSequence dummy;
// Accept the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
ASSERT_TRUE(infobar);
EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
EXPECT_TRUE(infobar->Accept());
}
// 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);
EXPECT_TRUE(infobar->Cancel());
}
// 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);
infobar->InfoBarDismissed();
}
// Ignore the infobar.
{
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
ASSERT_TRUE(infobar);
EXPECT_CALL(metric_logger,
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
}
}
// Verify that we correctly log user happiness metrics dealing with form loading
// and form submission.
TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment