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

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

Powered by Google App Engine
This is Rietveld 408576698