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