| Index: chrome/browser/autofill/autofill_assist_infobar_delegate_mobile_unittest.cc
|
| diff --git a/chrome/browser/autofill/autofill_assist_infobar_delegate_mobile_unittest.cc b/chrome/browser/autofill/autofill_assist_infobar_delegate_mobile_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..60467904f1714f73a5f3c0d8e0aadf2321f0de41
|
| --- /dev/null
|
| +++ b/chrome/browser/autofill/autofill_assist_infobar_delegate_mobile_unittest.cc
|
| @@ -0,0 +1,103 @@
|
| +// 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_assist_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"
|
| +
|
| +using testing::_;
|
| +
|
| +namespace autofill {
|
| +
|
| +class AutofillAssistInfoBarDelegateMobileTest
|
| + : public ChromeRenderViewHostTestHarness {
|
| + public:
|
| + AutofillAssistInfoBarDelegateMobileTest()
|
| + : infobar_callback_has_run_(false) {}
|
| + ~AutofillAssistInfoBarDelegateMobileTest() override {}
|
| +
|
| + protected:
|
| + std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate();
|
| +
|
| + void AcceptInfoBarCallback() { infobar_callback_has_run_ = true; }
|
| +
|
| + bool infobar_callback_has_run_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(AutofillAssistInfoBarDelegateMobileTest);
|
| +};
|
| +
|
| +std::unique_ptr<ConfirmInfoBarDelegate>
|
| +AutofillAssistInfoBarDelegateMobileTest::CreateDelegate() {
|
| + infobar_callback_has_run_ = false;
|
| + base::HistogramTester histogram_tester;
|
| + CreditCard credit_card;
|
| + std::unique_ptr<ConfirmInfoBarDelegate> delegate(
|
| + new AutofillAssistInfoBarDelegateMobile(
|
| + credit_card,
|
| + base::Bind(
|
| + &AutofillAssistInfoBarDelegateMobileTest::AcceptInfoBarCallback,
|
| + base::Unretained(this))));
|
| + histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar",
|
| + AutofillMetrics::INFOBAR_SHOWN, 1);
|
| + return delegate;
|
| +}
|
| +
|
| +// Test that credit card infobar metrics are logged correctly.
|
| +TEST_F(AutofillAssistInfoBarDelegateMobileTest, Metrics) {
|
| + ::testing::InSequence dummy;
|
| +
|
| + // Accept the infobar.
|
| + {
|
| + std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| +
|
| + base::HistogramTester histogram_tester;
|
| + EXPECT_TRUE(infobar->Accept());
|
| + EXPECT_TRUE(infobar_callback_has_run_);
|
| + histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar",
|
| + AutofillMetrics::INFOBAR_ACCEPTED, 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.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar",
|
| + AutofillMetrics::INFOBAR_DENIED, 1);
|
| + }
|
| +
|
| + // Dismiss the infobar.
|
| + {
|
| + std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| +
|
| + base::HistogramTester histogram_tester;
|
| + infobar->InfoBarDismissed();
|
| + EXPECT_FALSE(infobar_callback_has_run_);
|
| + histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar",
|
| + AutofillMetrics::INFOBAR_DENIED, 1);
|
| + }
|
| +
|
| + // Ignore the infobar.
|
| + {
|
| + std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate());
|
| +
|
| + base::HistogramTester histogram_tester;
|
| + infobar.reset();
|
| + EXPECT_FALSE(infobar_callback_has_run_);
|
| + histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar",
|
| + AutofillMetrics::INFOBAR_IGNORED, 1);
|
| + }
|
| +}
|
| +
|
| +} // namespace autofill
|
|
|