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

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: cleaning 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..a3eabe10a88170c147c4e843e6c18296224db641
--- /dev/null
+++ b/chrome/browser/autofill/autofill_credit_card_filling_infobar_delegate_mobile_unittest.cc
@@ -0,0 +1,113 @@
+// 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 {
+
+class AutofillCreditCardFillingInfoBarDelegateMobileTest
+ : public ChromeRenderViewHostTestHarness {
+ public:
+ AutofillCreditCardFillingInfoBarDelegateMobileTest()
+ : infobar_callback_has_run_(false) {}
+ ~AutofillCreditCardFillingInfoBarDelegateMobileTest() override {}
+
+ protected:
+ std::unique_ptr<AutofillCreditCardFillingInfoBarDelegateMobile>
+ CreateDelegate();
+
+ void AcceptInfoBarCallback() { infobar_callback_has_run_ = true; }
+
+ bool infobar_callback_has_run_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardFillingInfoBarDelegateMobileTest);
+};
+
+std::unique_ptr<AutofillCreditCardFillingInfoBarDelegateMobile>
+AutofillCreditCardFillingInfoBarDelegateMobileTest::CreateDelegate() {
+ infobar_callback_has_run_ = false;
+ CreditCard credit_card;
+ std::unique_ptr<AutofillCreditCardFillingInfoBarDelegateMobile> delegate(
+ new AutofillCreditCardFillingInfoBarDelegateMobile(
+ credit_card,
+ base::Bind(&AutofillCreditCardFillingInfoBarDelegateMobileTest::
+ AcceptInfoBarCallback,
+ base::Unretained(this))));
+ delegate->set_was_shown();
+ return delegate;
+}
+
+// Test that credit card infobar metrics are logged correctly.
+TEST_F(AutofillCreditCardFillingInfoBarDelegateMobileTest, Metrics) {
+ // Accept the infobar.
+ {
+ std::unique_ptr<AutofillCreditCardFillingInfoBarDelegateMobile> 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<AutofillCreditCardFillingInfoBarDelegateMobile> 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<AutofillCreditCardFillingInfoBarDelegateMobile> 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<AutofillCreditCardFillingInfoBarDelegateMobile> 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