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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/histogram_samples.h" 5 #include "base/metrics/histogram_samples.h"
6 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/statistics_delta_reader.h" 8 #include "base/test/histogram_tester.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h" 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 13 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
14 #include "components/password_manager/core/common/password_manager_ui.h" 14 #include "components/password_manager/core/common/password_manager_ui.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "content/public/test/web_contents_tester.h" 16 #include "content/public/test/web_contents_tester.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 TEST_F(ManagePasswordsBubbleModelTest, DefaultValues) { 78 TEST_F(ManagePasswordsBubbleModelTest, DefaultValues) {
79 EXPECT_EQ(model_->display_disposition(), 79 EXPECT_EQ(model_->display_disposition(),
80 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING); 80 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING);
81 EXPECT_EQ(model_->dismissal_reason(), 81 EXPECT_EQ(model_->dismissal_reason(),
82 password_manager::metrics_util::NOT_DISPLAYED); 82 password_manager::metrics_util::NOT_DISPLAYED);
83 EXPECT_FALSE(controller()->saved_password()); 83 EXPECT_FALSE(controller()->saved_password());
84 EXPECT_FALSE(controller()->never_saved_password()); 84 EXPECT_FALSE(controller()->never_saved_password());
85 } 85 }
86 86
87 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutLogging) { 87 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutLogging) {
88 base::StatisticsDeltaReader statistics_delta_reader; 88 base::HistogramTester histogram_tester;
89 model_->OnBubbleHidden(); 89 model_->OnBubbleHidden();
90 EXPECT_EQ(model_->dismissal_reason(), 90 EXPECT_EQ(model_->dismissal_reason(),
91 password_manager::metrics_util::NOT_DISPLAYED); 91 password_manager::metrics_util::NOT_DISPLAYED);
92 EXPECT_FALSE(controller()->saved_password()); 92 EXPECT_FALSE(controller()->saved_password());
93 EXPECT_FALSE(controller()->never_saved_password()); 93 EXPECT_FALSE(controller()->never_saved_password());
94 94
95 scoped_ptr<base::HistogramSamples> samples( 95 scoped_ptr<base::HistogramSamples> samples(
96 statistics_delta_reader.GetHistogramSamplesSinceCreation( 96 histogram_tester.GetHistogramSamplesSinceCreation(
97 kUIDismissalReasonMetric)); 97 kUIDismissalReasonMetric));
98 EXPECT_EQ(NULL, samples.get()); 98 EXPECT_EQ(NULL, samples.get());
99 } 99 }
100 100
101 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) { 101 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) {
102 base::StatisticsDeltaReader statistics_delta_reader; 102 base::HistogramTester histogram_tester;
103 PretendPasswordWaiting(); 103 PretendPasswordWaiting();
104 model_->OnBubbleHidden(); 104 model_->OnBubbleHidden();
105 EXPECT_EQ(model_->dismissal_reason(), 105 EXPECT_EQ(model_->dismissal_reason(),
106 password_manager::metrics_util::NO_DIRECT_INTERACTION); 106 password_manager::metrics_util::NO_DIRECT_INTERACTION);
107 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE, 107 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE,
108 model_->state()); 108 model_->state());
109 EXPECT_FALSE(controller()->saved_password()); 109 EXPECT_FALSE(controller()->saved_password());
110 EXPECT_FALSE(controller()->never_saved_password()); 110 EXPECT_FALSE(controller()->never_saved_password());
111 111
112 scoped_ptr<base::HistogramSamples> samples( 112 histogram_tester.ExpectUniqueSample(
113 statistics_delta_reader.GetHistogramSamplesSinceCreation( 113 kUIDismissalReasonMetric,
114 kUIDismissalReasonMetric)); 114 password_manager::metrics_util::NO_DIRECT_INTERACTION,
115 EXPECT_EQ( 115 1);
116 1,
117 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
118 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
119 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
120 EXPECT_EQ(0,
121 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
122 EXPECT_EQ(0,
123 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
124 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
125 EXPECT_EQ(
126 0,
127 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
128 } 116 }
129 117
130 TEST_F(ManagePasswordsBubbleModelTest, ClickSave) { 118 TEST_F(ManagePasswordsBubbleModelTest, ClickSave) {
131 base::StatisticsDeltaReader statistics_delta_reader; 119 base::HistogramTester histogram_tester;
132 PretendPasswordWaiting(); 120 PretendPasswordWaiting();
133 model_->OnSaveClicked(); 121 model_->OnSaveClicked();
134 model_->OnBubbleHidden(); 122 model_->OnBubbleHidden();
135 EXPECT_EQ(model_->dismissal_reason(), 123 EXPECT_EQ(model_->dismissal_reason(),
136 password_manager::metrics_util::CLICKED_SAVE); 124 password_manager::metrics_util::CLICKED_SAVE);
137 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state()); 125 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state());
138 EXPECT_TRUE(controller()->saved_password()); 126 EXPECT_TRUE(controller()->saved_password());
139 EXPECT_FALSE(controller()->never_saved_password()); 127 EXPECT_FALSE(controller()->never_saved_password());
140 128
141 scoped_ptr<base::HistogramSamples> samples( 129 histogram_tester.ExpectUniqueSample(
142 statistics_delta_reader.GetHistogramSamplesSinceCreation( 130 kUIDismissalReasonMetric,
143 kUIDismissalReasonMetric)); 131 password_manager::metrics_util::CLICKED_SAVE,
144 EXPECT_EQ( 132 1);
145 0,
146 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
147 EXPECT_EQ(1, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
148 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
149 EXPECT_EQ(0,
150 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
151 EXPECT_EQ(0,
152 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
153 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
154 EXPECT_EQ(
155 0,
156 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
157 } 133 }
158 134
159 TEST_F(ManagePasswordsBubbleModelTest, ClickNope) { 135 TEST_F(ManagePasswordsBubbleModelTest, ClickNope) {
160 base::StatisticsDeltaReader statistics_delta_reader; 136 base::HistogramTester histogram_tester;
161 PretendPasswordWaiting(); 137 PretendPasswordWaiting();
162 model_->OnNopeClicked(); 138 model_->OnNopeClicked();
163 model_->OnBubbleHidden(); 139 model_->OnBubbleHidden();
164 EXPECT_EQ(model_->dismissal_reason(), 140 EXPECT_EQ(model_->dismissal_reason(),
165 password_manager::metrics_util::CLICKED_NOPE); 141 password_manager::metrics_util::CLICKED_NOPE);
166 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); 142 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, model_->state());
167 EXPECT_FALSE(controller()->saved_password()); 143 EXPECT_FALSE(controller()->saved_password());
168 EXPECT_FALSE(controller()->never_saved_password()); 144 EXPECT_FALSE(controller()->never_saved_password());
169 145
170 scoped_ptr<base::HistogramSamples> samples( 146 histogram_tester.ExpectUniqueSample(
171 statistics_delta_reader.GetHistogramSamplesSinceCreation( 147 kUIDismissalReasonMetric,
172 kUIDismissalReasonMetric)); 148 password_manager::metrics_util::CLICKED_NOPE,
173 EXPECT_EQ( 149 1);
174 0,
175 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
176 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
177 EXPECT_EQ(1, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
178 EXPECT_EQ(0,
179 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
180 EXPECT_EQ(0,
181 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
182 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
183 EXPECT_EQ(
184 0,
185 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
186 } 150 }
187 151
188 TEST_F(ManagePasswordsBubbleModelTest, ClickNever) { 152 TEST_F(ManagePasswordsBubbleModelTest, ClickNever) {
189 base::StatisticsDeltaReader statistics_delta_reader; 153 base::HistogramTester histogram_tester;
190 PretendPasswordWaiting(); 154 PretendPasswordWaiting();
191 model_->OnNeverForThisSiteClicked(); 155 model_->OnNeverForThisSiteClicked();
192 model_->OnBubbleHidden(); 156 model_->OnBubbleHidden();
193 EXPECT_EQ(model_->dismissal_reason(), 157 EXPECT_EQ(model_->dismissal_reason(),
194 password_manager::metrics_util::CLICKED_NEVER); 158 password_manager::metrics_util::CLICKED_NEVER);
195 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, model_->state()); 159 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, model_->state());
196 EXPECT_FALSE(controller()->saved_password()); 160 EXPECT_FALSE(controller()->saved_password());
197 EXPECT_TRUE(controller()->never_saved_password()); 161 EXPECT_TRUE(controller()->never_saved_password());
198 162
199 scoped_ptr<base::HistogramSamples> samples( 163 histogram_tester.ExpectUniqueSample(
200 statistics_delta_reader.GetHistogramSamplesSinceCreation( 164 kUIDismissalReasonMetric,
201 kUIDismissalReasonMetric)); 165 password_manager::metrics_util::CLICKED_NEVER,
202 EXPECT_EQ( 166 1);
203 0,
204 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
205 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
206 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
207 EXPECT_EQ(1,
208 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
209 EXPECT_EQ(0,
210 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
211 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
212 EXPECT_EQ(
213 0,
214 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
215 } 167 }
216 168
217 TEST_F(ManagePasswordsBubbleModelTest, ClickManage) { 169 TEST_F(ManagePasswordsBubbleModelTest, ClickManage) {
218 base::StatisticsDeltaReader statistics_delta_reader; 170 base::HistogramTester histogram_tester;
219 PretendManagingPasswords(); 171 PretendManagingPasswords();
220 model_->OnManageLinkClicked(); 172 model_->OnManageLinkClicked();
221 model_->OnBubbleHidden(); 173 model_->OnBubbleHidden();
222 EXPECT_EQ(model_->dismissal_reason(), 174 EXPECT_EQ(model_->dismissal_reason(),
223 password_manager::metrics_util::CLICKED_MANAGE); 175 password_manager::metrics_util::CLICKED_MANAGE);
224 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state()); 176 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state());
225 EXPECT_FALSE(controller()->saved_password()); 177 EXPECT_FALSE(controller()->saved_password());
226 EXPECT_FALSE(controller()->never_saved_password()); 178 EXPECT_FALSE(controller()->never_saved_password());
227 179
228 scoped_ptr<base::HistogramSamples> samples( 180 histogram_tester.ExpectUniqueSample(
229 statistics_delta_reader.GetHistogramSamplesSinceCreation( 181 kUIDismissalReasonMetric,
230 kUIDismissalReasonMetric)); 182 password_manager::metrics_util::CLICKED_MANAGE,
231 EXPECT_EQ( 183 1);
232 0,
233 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
234 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
235 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
236 EXPECT_EQ(0,
237 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
238 EXPECT_EQ(1,
239 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
240 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
241 EXPECT_EQ(
242 0,
243 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
244 } 184 }
245 185
246 TEST_F(ManagePasswordsBubbleModelTest, ClickDone) { 186 TEST_F(ManagePasswordsBubbleModelTest, ClickDone) {
247 base::StatisticsDeltaReader statistics_delta_reader; 187 base::HistogramTester histogram_tester;
248 PretendManagingPasswords(); 188 PretendManagingPasswords();
249 model_->OnDoneClicked(); 189 model_->OnDoneClicked();
250 model_->OnBubbleHidden(); 190 model_->OnBubbleHidden();
251 EXPECT_EQ(model_->dismissal_reason(), 191 EXPECT_EQ(model_->dismissal_reason(),
252 password_manager::metrics_util::CLICKED_DONE); 192 password_manager::metrics_util::CLICKED_DONE);
253 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state()); 193 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state());
254 EXPECT_FALSE(controller()->saved_password()); 194 EXPECT_FALSE(controller()->saved_password());
255 EXPECT_FALSE(controller()->never_saved_password()); 195 EXPECT_FALSE(controller()->never_saved_password());
256 196
257 scoped_ptr<base::HistogramSamples> samples( 197 histogram_tester.ExpectUniqueSample(
258 statistics_delta_reader.GetHistogramSamplesSinceCreation( 198 kUIDismissalReasonMetric,
259 kUIDismissalReasonMetric)); 199 password_manager::metrics_util::CLICKED_DONE,
260 EXPECT_EQ( 200 1);
261 0,
262 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
263 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
264 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
265 EXPECT_EQ(0,
266 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
267 EXPECT_EQ(0,
268 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
269 EXPECT_EQ(1, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
270 EXPECT_EQ(
271 0,
272 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
273 } 201 }
274 202
275 TEST_F(ManagePasswordsBubbleModelTest, ClickUnblacklist) { 203 TEST_F(ManagePasswordsBubbleModelTest, ClickUnblacklist) {
276 base::StatisticsDeltaReader statistics_delta_reader; 204 base::HistogramTester histogram_tester;
277 PretendBlacklisted(); 205 PretendBlacklisted();
278 model_->OnUnblacklistClicked(); 206 model_->OnUnblacklistClicked();
279 model_->OnBubbleHidden(); 207 model_->OnBubbleHidden();
280 EXPECT_EQ(model_->dismissal_reason(), 208 EXPECT_EQ(model_->dismissal_reason(),
281 password_manager::metrics_util::CLICKED_UNBLACKLIST); 209 password_manager::metrics_util::CLICKED_UNBLACKLIST);
282 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state()); 210 EXPECT_EQ(password_manager::ui::MANAGE_STATE, model_->state());
283 EXPECT_FALSE(controller()->saved_password()); 211 EXPECT_FALSE(controller()->saved_password());
284 EXPECT_FALSE(controller()->never_saved_password()); 212 EXPECT_FALSE(controller()->never_saved_password());
285 213
286 scoped_ptr<base::HistogramSamples> samples( 214 histogram_tester.ExpectUniqueSample(
287 statistics_delta_reader.GetHistogramSamplesSinceCreation( 215 kUIDismissalReasonMetric,
288 kUIDismissalReasonMetric)); 216 password_manager::metrics_util::CLICKED_UNBLACKLIST,
289 EXPECT_EQ( 217 1);
290 0,
291 samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
292 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
293 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
294 EXPECT_EQ(0,
295 samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
296 EXPECT_EQ(0,
297 samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
298 EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
299 EXPECT_EQ(
300 1,
301 samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
302 } 218 }
303 219
304 TEST_F(ManagePasswordsBubbleModelTest, PasswordPendingUserDecision) { 220 TEST_F(ManagePasswordsBubbleModelTest, PasswordPendingUserDecision) {
305 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state())); 221 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state()));
306 222
307 model_->set_state(password_manager::ui::INACTIVE_STATE); 223 model_->set_state(password_manager::ui::INACTIVE_STATE);
308 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state())); 224 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state()));
309 model_->set_state(password_manager::ui::MANAGE_STATE); 225 model_->set_state(password_manager::ui::MANAGE_STATE);
310 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state())); 226 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state()));
311 model_->set_state(password_manager::ui::BLACKLIST_STATE); 227 model_->set_state(password_manager::ui::BLACKLIST_STATE);
312 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state())); 228 EXPECT_FALSE(password_manager::ui::IsPendingState(model_->state()));
313 229
314 model_->set_state(password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE); 230 model_->set_state(password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE);
315 EXPECT_TRUE(password_manager::ui::IsPendingState(model_->state())); 231 EXPECT_TRUE(password_manager::ui::IsPendingState(model_->state()));
316 model_->set_state(password_manager::ui::PENDING_PASSWORD_STATE); 232 model_->set_state(password_manager::ui::PENDING_PASSWORD_STATE);
317 EXPECT_TRUE(password_manager::ui::IsPendingState(model_->state())); 233 EXPECT_TRUE(password_manager::ui::IsPendingState(model_->state()));
318 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698