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

Side by Side Diff: chrome/browser/ui/autofill/autocheckout_bubble_controller_unittest.cc

Issue 23033016: Remove autocheckout code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Even more deletes, and Ilya review. Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 "base/bind.h"
6 #include "base/callback.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/ui/autofill/autocheckout_bubble_controller.h"
9 #include "components/autofill/core/browser/autofill_metrics.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/rect.h"
12
13 namespace autofill {
14 namespace {
15
16 class TestAutofillMetrics : public AutofillMetrics {
17 public:
18 TestAutofillMetrics()
19 : metric_(NUM_BUBBLE_METRICS) {}
20 virtual ~TestAutofillMetrics() {}
21 virtual void LogAutocheckoutBubbleMetric(BubbleMetric metric) const OVERRIDE {
22 metric_ = metric;
23 }
24
25 AutofillMetrics::BubbleMetric metric() const { return metric_; }
26
27 private:
28 mutable AutofillMetrics::BubbleMetric metric_;
29
30 DISALLOW_COPY_AND_ASSIGN(TestAutofillMetrics);
31 };
32
33 class TestCallback {
34 public:
35 TestCallback() : accepted_count_(0), dismissed_count_(0) {}
36 ~TestCallback() {}
37
38 void Run(AutocheckoutBubbleState state) {
39 if (state == AUTOCHECKOUT_BUBBLE_ACCEPTED)
40 accepted_count_++;
41 else
42 dismissed_count_++;
43 }
44
45 int accepted_count() const {
46 return accepted_count_;
47 }
48
49 int dismissed_count() const {
50 return dismissed_count_;
51 }
52
53 base::Callback<void(AutocheckoutBubbleState)> GetCallback() {
54 return base::Bind(&TestCallback::Run, base::Unretained(this));
55 }
56
57 private:
58 int accepted_count_;
59 int dismissed_count_;
60 };
61
62 class TestAutocheckoutBubbleController :
63 public autofill::AutocheckoutBubbleController {
64 public:
65 explicit TestAutocheckoutBubbleController(
66 const base::Callback<void(AutocheckoutBubbleState)>& callback)
67 : AutocheckoutBubbleController(gfx::RectF(),
68 gfx::NativeWindow(),
69 true /* is_google_user */,
70 callback) {
71 set_metric_logger(new TestAutofillMetrics);
72 }
73 virtual ~TestAutocheckoutBubbleController() {}
74
75 const TestAutofillMetrics* get_metric_logger() const {
76 return static_cast<TestAutofillMetrics*>(const_cast<AutofillMetrics*>(
77 AutocheckoutBubbleController::metric_logger()));
78 }
79 };
80
81 } // namespace
82
83 TEST(AutocheckoutBubbleControllerTest, BubbleCreationAndDestructionMetrics) {
84 // Test bubble created metric.
85 TestCallback callback;
86 TestAutocheckoutBubbleController controller(callback.GetCallback());
87
88 controller.BubbleCreated();
89
90 EXPECT_EQ(AutofillMetrics::BUBBLE_CREATED,
91 controller.get_metric_logger()->metric());
92 EXPECT_EQ(0, callback.accepted_count());
93 EXPECT_EQ(0, callback.dismissed_count());
94
95 // If neither BubbleAccepted or BubbleCanceled was called the bubble was
96 // ignored.
97 controller.BubbleDestroyed();
98
99 EXPECT_EQ(AutofillMetrics::BUBBLE_IGNORED,
100 controller.get_metric_logger()->metric());
101 EXPECT_EQ(0, callback.accepted_count());
102 EXPECT_EQ(1, callback.dismissed_count());
103 }
104
105 TEST(AutocheckoutBubbleControllerTest, BubbleAcceptedMetric) {
106 // Test bubble accepted metric.
107 TestCallback callback;
108 TestAutocheckoutBubbleController controller(callback.GetCallback());
109
110 controller.BubbleAccepted();
111
112 EXPECT_EQ(AutofillMetrics::BUBBLE_ACCEPTED,
113 controller.get_metric_logger()->metric());
114 EXPECT_EQ(1, callback.accepted_count());
115 EXPECT_EQ(0, callback.dismissed_count());
116
117 // Test that after a bubble is accepted it is not considered ignored.
118 controller.BubbleDestroyed();
119
120 EXPECT_EQ(AutofillMetrics::BUBBLE_ACCEPTED,
121 controller.get_metric_logger()->metric());
122 EXPECT_EQ(1, callback.accepted_count());
123 EXPECT_EQ(0, callback.dismissed_count());
124 }
125
126 TEST(AutocheckoutBubbleControllerTest, BubbleCanceledMetric) {
127 // Test bubble dismissed metric.
128 TestCallback callback;
129 TestAutocheckoutBubbleController controller(callback.GetCallback());
130
131 controller.BubbleCanceled();
132
133 EXPECT_EQ(AutofillMetrics::BUBBLE_DISMISSED,
134 controller.get_metric_logger()->metric());
135 EXPECT_EQ(0, callback.accepted_count());
136 EXPECT_EQ(1, callback.dismissed_count());
137
138 // Test that after a bubble is dismissed it is not considered ignored.
139 controller.BubbleDestroyed();
140
141 EXPECT_EQ(AutofillMetrics::BUBBLE_DISMISSED,
142 controller.get_metric_logger()->metric());
143 EXPECT_EQ(0, callback.accepted_count());
144 EXPECT_EQ(1, callback.dismissed_count());
145 }
146
147 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698