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

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

Issue 2026353002: [Autofill] Credit Card Assist Infobar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed CreateCreditCardFillingInfoBar from interface Created 4 years, 4 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
Index: chrome/browser/autofill/autofill_credit_card_filling_infobar_delegate_mobile_unittest.cc
diff --git a/chrome/browser/autofill/autofill_credit_card_filling_infobar_delegate_mobile_unittest.cc b/chrome/browser/autofill/autofill_credit_card_filling_infobar_delegate_mobile_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..69f756ae1b4b1824b134f3abd8985863f3446921
--- /dev/null
+++ b/chrome/browser/autofill/autofill_credit_card_filling_infobar_delegate_mobile_unittest.cc
@@ -0,0 +1,124 @@
+// Copyright 2016 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 "components/autofill/core/browser/autofill_credit_card_filling_infobar_delegate_mobile.h"
+
+#include <memory>
+
+#include "base/macros.h"
+#include "base/test/histogram_tester.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "components/autofill/core/browser/autofill_test_utils.h"
+#include "components/infobars/core/confirm_infobar_delegate.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+// In order to use protected methods.
Peter Kasting 2016/08/03 02:25:40 Nit: If you need to declare a subclass just to exp
Mathieu 2016/08/03 18:34:44 Done.
+class TestAutofillCreditCardFillingInfoBarDelegateMobile
+ : public AutofillCreditCardFillingInfoBarDelegateMobile {
+ public:
+ TestAutofillCreditCardFillingInfoBarDelegateMobile(
+ const CreditCard& card,
+ const base::Closure& callback)
+ : AutofillCreditCardFillingInfoBarDelegateMobile(card, callback) {}
+
+ using AutofillCreditCardFillingInfoBarDelegateMobile::Accept;
+ using AutofillCreditCardFillingInfoBarDelegateMobile::Cancel;
+ using AutofillCreditCardFillingInfoBarDelegateMobile::InfoBarDismissed;
+};
+
+class AutofillCreditCardFillingInfoBarDelegateMobileTest
+ : public ChromeRenderViewHostTestHarness {
+ public:
+ AutofillCreditCardFillingInfoBarDelegateMobileTest()
+ : infobar_callback_has_run_(false) {}
+ ~AutofillCreditCardFillingInfoBarDelegateMobileTest() override {}
+
+ protected:
+ std::unique_ptr<TestAutofillCreditCardFillingInfoBarDelegateMobile>
+ CreateDelegate();
+
+ void AcceptInfoBarCallback() { infobar_callback_has_run_ = true; }
+
+ bool infobar_callback_has_run_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardFillingInfoBarDelegateMobileTest);
+};
+
+std::unique_ptr<TestAutofillCreditCardFillingInfoBarDelegateMobile>
+AutofillCreditCardFillingInfoBarDelegateMobileTest::CreateDelegate() {
Peter Kasting 2016/08/03 02:25:40 Nit: If you manage to return to a Create()-based A
Mathieu 2016/08/03 18:34:44 Acknowledged.
+ infobar_callback_has_run_ = false;
+ CreditCard credit_card;
+ std::unique_ptr<TestAutofillCreditCardFillingInfoBarDelegateMobile> delegate(
+ new TestAutofillCreditCardFillingInfoBarDelegateMobile(
+ credit_card,
+ base::Bind(&AutofillCreditCardFillingInfoBarDelegateMobileTest::
+ AcceptInfoBarCallback,
+ base::Unretained(this))));
+ delegate->set_was_shown(true);
+ return delegate;
+}
+
+// Test that credit card infobar metrics are logged correctly.
+TEST_F(AutofillCreditCardFillingInfoBarDelegateMobileTest, Metrics) {
+ // Accept the infobar.
+ {
+ std::unique_ptr<TestAutofillCreditCardFillingInfoBarDelegateMobile> infobar(
+ CreateDelegate());
+
+ base::HistogramTester histogram_tester;
+ EXPECT_TRUE(infobar->Accept());
+ EXPECT_TRUE(infobar_callback_has_run_);
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_ACCEPTED, 1);
+ infobar.reset();
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_SHOWN, 1);
+ }
+
+ // Cancel the infobar.
+ {
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
+
+ base::HistogramTester histogram_tester;
+ EXPECT_TRUE(infobar->Cancel());
+ EXPECT_FALSE(infobar_callback_has_run_);
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_DENIED, 1);
+ infobar.reset();
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_SHOWN, 1);
+ }
+
+ // Dismiss the infobar.
+ {
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
+
+ base::HistogramTester histogram_tester;
+ infobar->InfoBarDismissed();
+ EXPECT_FALSE(infobar_callback_has_run_);
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_DENIED, 1);
+ infobar.reset();
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_SHOWN, 1);
+ }
+
+ // Ignore the infobar.
+ {
+ std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
+
+ base::HistogramTester histogram_tester;
+ infobar.reset();
+ EXPECT_FALSE(infobar_callback_has_run_);
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_SHOWN, 1);
+ histogram_tester.ExpectBucketCount("Autofill.CreditCardFillingInfoBar",
+ AutofillMetrics::INFOBAR_IGNORED, 1);
+ }
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698