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_assist_infobar_delegate_mobi
le.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/gtest/include/gtest/gtest.h" |
| 15 |
| 16 using testing::_; |
| 17 |
| 18 namespace autofill { |
| 19 |
| 20 class AutofillAssistInfoBarDelegateMobileTest |
| 21 : public ChromeRenderViewHostTestHarness { |
| 22 public: |
| 23 AutofillAssistInfoBarDelegateMobileTest() |
| 24 : infobar_callback_has_run_(false) {} |
| 25 ~AutofillAssistInfoBarDelegateMobileTest() override {} |
| 26 |
| 27 protected: |
| 28 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(); |
| 29 |
| 30 void AcceptInfoBarCallback() { infobar_callback_has_run_ = true; } |
| 31 |
| 32 bool infobar_callback_has_run_; |
| 33 |
| 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(AutofillAssistInfoBarDelegateMobileTest); |
| 36 }; |
| 37 |
| 38 std::unique_ptr<ConfirmInfoBarDelegate> |
| 39 AutofillAssistInfoBarDelegateMobileTest::CreateDelegate() { |
| 40 infobar_callback_has_run_ = false; |
| 41 base::HistogramTester histogram_tester; |
| 42 CreditCard credit_card; |
| 43 std::unique_ptr<ConfirmInfoBarDelegate> delegate( |
| 44 new AutofillAssistInfoBarDelegateMobile( |
| 45 credit_card, |
| 46 base::Bind( |
| 47 &AutofillAssistInfoBarDelegateMobileTest::AcceptInfoBarCallback, |
| 48 base::Unretained(this)))); |
| 49 histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar", |
| 50 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 51 return delegate; |
| 52 } |
| 53 |
| 54 // Test that credit card infobar metrics are logged correctly. |
| 55 TEST_F(AutofillAssistInfoBarDelegateMobileTest, Metrics) { |
| 56 ::testing::InSequence dummy; |
| 57 |
| 58 // Accept the infobar. |
| 59 { |
| 60 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 61 |
| 62 base::HistogramTester histogram_tester; |
| 63 EXPECT_TRUE(infobar->Accept()); |
| 64 EXPECT_TRUE(infobar_callback_has_run_); |
| 65 histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar", |
| 66 AutofillMetrics::INFOBAR_ACCEPTED, 1); |
| 67 } |
| 68 |
| 69 // Cancel the infobar. |
| 70 { |
| 71 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 72 |
| 73 base::HistogramTester histogram_tester; |
| 74 EXPECT_TRUE(infobar->Cancel()); |
| 75 EXPECT_FALSE(infobar_callback_has_run_); |
| 76 histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar", |
| 77 AutofillMetrics::INFOBAR_DENIED, 1); |
| 78 } |
| 79 |
| 80 // Dismiss the infobar. |
| 81 { |
| 82 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 83 |
| 84 base::HistogramTester histogram_tester; |
| 85 infobar->InfoBarDismissed(); |
| 86 EXPECT_FALSE(infobar_callback_has_run_); |
| 87 histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar", |
| 88 AutofillMetrics::INFOBAR_DENIED, 1); |
| 89 } |
| 90 |
| 91 // Ignore the infobar. |
| 92 { |
| 93 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); |
| 94 |
| 95 base::HistogramTester histogram_tester; |
| 96 infobar.reset(); |
| 97 EXPECT_FALSE(infobar_callback_has_run_); |
| 98 histogram_tester.ExpectUniqueSample("Autofill.CreditCardAssistInfoBar", |
| 99 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 100 } |
| 101 } |
| 102 |
| 103 } // namespace autofill |
OLD | NEW |