OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/autofill/core/browser/autofill_credit_card_filling_infobar_
delegate_mobile.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/macros.h" |
| 10 #include "base/test/histogram_tester.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 12 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 13 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 14 #include "testing/gmock/include/gmock/gmock-spec-builders.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 using testing::_; |
| 18 |
| 19 namespace autofill { |
| 20 |
| 21 class TestAutofillCreditCardFillingInfoBarDelegateMobile |
| 22 : public AutofillCreditCardFillingInfoBarDelegateMobile { |
| 23 public: |
| 24 TestAutofillCreditCardFillingInfoBarDelegateMobile( |
| 25 const CreditCard& card, |
| 26 const base::Closure& callback) |
| 27 : AutofillCreditCardFillingInfoBarDelegateMobile(card, callback) {} |
| 28 }; |
| 29 |
| 30 class AutofillCreditCardFillingInfoBarDelegateMobileTest |
| 31 : public ChromeRenderViewHostTestHarness { |
| 32 public: |
| 33 AutofillCreditCardFillingInfoBarDelegateMobileTest() |
| 34 : infobar_callback_has_run_(false) {} |
| 35 ~AutofillCreditCardFillingInfoBarDelegateMobileTest() override {} |
| 36 |
| 37 protected: |
| 38 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(); |
| 39 |
| 40 void AcceptInfoBarCallback() { infobar_callback_has_run_ = true; } |
| 41 |
| 42 bool infobar_callback_has_run_; |
| 43 |
| 44 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardFillingInfoBarDelegateMobileTest); |
| 46 }; |
| 47 |
| 48 std::unique_ptr<ConfirmInfoBarDelegate> |
| 49 AutofillCreditCardFillingInfoBarDelegateMobileTest::CreateDelegate() { |
| 50 infobar_callback_has_run_ = false; |
| 51 base::HistogramTester histogram_tester; |
| 52 CreditCard credit_card; |
| 53 std::unique_ptr<ConfirmInfoBarDelegate> delegate( |
| 54 new TestAutofillCreditCardFillingInfoBarDelegateMobile( |
| 55 credit_card, |
| 56 base::Bind(&AutofillCreditCardFillingInfoBarDelegateMobileTest:: |
| 57 AcceptInfoBarCallback, |
| 58 base::Unretained(this)))); |
| 59 histogram_tester.ExpectUniqueSample("Autofill.CreditCardFillingInfoBar", |
| 60 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 61 return delegate; |
| 62 } |
| 63 |
| 64 // Test that credit card infobar metrics are logged correctly. |
| 65 TEST_F(AutofillCreditCardFillingInfoBarDelegateMobileTest, Metrics) { |
| 66 ::testing::InSequence dummy; |
| 67 |
| 68 // Accept the infobar. |
| 69 { |
| 70 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 71 |
| 72 base::HistogramTester histogram_tester; |
| 73 EXPECT_TRUE(infobar->Accept()); |
| 74 EXPECT_TRUE(infobar_callback_has_run_); |
| 75 histogram_tester.ExpectUniqueSample("Autofill.CreditCardFillingInfoBar", |
| 76 AutofillMetrics::INFOBAR_ACCEPTED, 1); |
| 77 } |
| 78 |
| 79 // Cancel the infobar. |
| 80 { |
| 81 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 82 |
| 83 base::HistogramTester histogram_tester; |
| 84 EXPECT_TRUE(infobar->Cancel()); |
| 85 EXPECT_FALSE(infobar_callback_has_run_); |
| 86 histogram_tester.ExpectUniqueSample("Autofill.CreditCardFillingInfoBar", |
| 87 AutofillMetrics::INFOBAR_DENIED, 1); |
| 88 } |
| 89 |
| 90 // Dismiss the infobar. |
| 91 { |
| 92 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 93 |
| 94 base::HistogramTester histogram_tester; |
| 95 infobar->InfoBarDismissed(); |
| 96 EXPECT_FALSE(infobar_callback_has_run_); |
| 97 histogram_tester.ExpectUniqueSample("Autofill.CreditCardFillingInfoBar", |
| 98 AutofillMetrics::INFOBAR_DENIED, 1); |
| 99 } |
| 100 |
| 101 // Ignore the infobar. |
| 102 { |
| 103 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 104 |
| 105 base::HistogramTester histogram_tester; |
| 106 infobar.reset(); |
| 107 EXPECT_FALSE(infobar_callback_has_run_); |
| 108 histogram_tester.ExpectUniqueSample("Autofill.CreditCardFillingInfoBar", |
| 109 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 110 } |
| 111 } |
| 112 |
| 113 } // namespace autofill |
OLD | NEW |