Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: chrome/browser/autofill/autofill_metrics_unittest.cc

Issue 6989001: Misc. infobar stuff: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/autofill_metrics_unittest.cc
===================================================================
--- chrome/browser/autofill/autofill_metrics_unittest.cc (revision 86331)
+++ chrome/browser/autofill/autofill_metrics_unittest.cc (working copy)
@@ -182,22 +182,15 @@
class AutofillMetricsTest : public TabContentsWrapperTestHarness {
public:
- AutofillMetricsTest() {}
- virtual ~AutofillMetricsTest() {
- // Order of destruction is important as AutofillManager relies on
- // PersonalDataManager to be around when it gets destroyed.
- autofill_manager_.reset(NULL);
- test_personal_data_ = NULL;
- }
+ AutofillMetricsTest();
+ virtual ~AutofillMetricsTest();
- virtual void SetUp() {
- TabContentsWrapperTestHarness::SetUp();
- test_personal_data_ = new TestPersonalDataManager();
- autofill_manager_.reset(new TestAutofillManager(contents_wrapper(),
- test_personal_data_.get()));
- }
+ virtual void SetUp();
protected:
+ AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger,
+ CreditCard** created_card);
+
scoped_ptr<TestAutofillManager> autofill_manager_;
scoped_refptr<TestPersonalDataManager> test_personal_data_;
@@ -205,6 +198,36 @@
DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
};
+AutofillMetricsTest::AutofillMetricsTest() {
+}
+
+AutofillMetricsTest::~AutofillMetricsTest() {
+ // Order of destruction is important as AutofillManager relies on
+ // PersonalDataManager to be around when it gets destroyed.
+ autofill_manager_.reset(NULL);
+ test_personal_data_ = NULL;
+}
+
+void AutofillMetricsTest::SetUp() {
+ TabContentsWrapperTestHarness::SetUp();
+ test_personal_data_ = new TestPersonalDataManager();
+ autofill_manager_.reset(new TestAutofillManager(contents_wrapper(),
+ test_personal_data_.get()));
+}
+
+AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate(
+ MockAutofillMetrics* metric_logger,
+ CreditCard** created_card) {
+ EXPECT_CALL(*metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
+ // The delegate created below will take ownership of this object.
+ CreditCard* credit_card = new CreditCard();
+ if (created_card)
+ *created_card = credit_card;
+ return new AutofillCCInfoBarDelegate(contents(), credit_card,
+ test_personal_data_.get(), metric_logger);
+}
+
// Test that we log quality metrics appropriately.
TEST_F(AutofillMetricsTest, QualityMetrics) {
// Set up our form data.
@@ -893,76 +916,46 @@
// Test that credit card infobar metrics are logged correctly.
TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
MockAutofillMetrics metric_logger;
- CreditCard* credit_card;
- AutofillCCInfoBarDelegate* infobar;
::testing::InSequence dummy;
// Accept the infobar.
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
- credit_card = new CreditCard();
- infobar = new AutofillCCInfoBarDelegate(contents(),
- credit_card,
- test_personal_data_.get(),
- &metric_logger);
+ {
+ CreditCard* credit_card;
+ scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger,
+ &credit_card));
+ EXPECT_CALL(*test_personal_data_.get(),
+ SaveImportedCreditCard(*credit_card));
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
+ EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Accept());
+ }
- EXPECT_CALL(*test_personal_data_.get(), SaveImportedCreditCard(*credit_card));
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED))
- .Times(1);
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
- .Times(0);
- EXPECT_TRUE(infobar->Accept());
- infobar->InfoBarClosed();
-
// Cancel the infobar.
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
- credit_card = new CreditCard();
- infobar = new AutofillCCInfoBarDelegate(contents(),
- credit_card,
- test_personal_data_.get(),
- &metric_logger);
+ {
+ scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
+ EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Cancel());
+ }
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED))
- .Times(1);
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
- .Times(0);
- EXPECT_TRUE(infobar->Cancel());
- infobar->InfoBarClosed();
-
// Dismiss the infobar.
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
- credit_card = new CreditCard();
- infobar = new AutofillCCInfoBarDelegate(contents(),
- credit_card,
- test_personal_data_.get(),
- &metric_logger);
+ {
+ scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
+ infobar->InfoBarDismissed();
+ }
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED))
- .Times(1);
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
- .Times(0);
- infobar->InfoBarDismissed();
- infobar->InfoBarClosed();
-
// Ignore the infobar.
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
- credit_card = new CreditCard();
- infobar = new AutofillCCInfoBarDelegate(contents(),
- credit_card,
- test_personal_data_.get(),
- &metric_logger);
-
- EXPECT_CALL(metric_logger,
- LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
- .Times(1);
- infobar->InfoBarClosed();
+ {
+ scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
+ EXPECT_CALL(metric_logger,
+ LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
+ }
}
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698