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