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

Side by Side Diff: components/security_state/security_state_model_unittest.cc

Issue 2483423002: HTTP Bad: Split out UMA metrics for password vs credit card "Not secure" warnings (Closed)
Patch Set: rebase to fix patch failure Created 4 years, 1 month 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/security_state/security_state_model.h" 5 #include "components/security_state/security_state_model.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 244 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
245 switches::kMarkHttpAs, 245 switches::kMarkHttpAs,
246 switches::kMarkHttpWithPasswordsOrCcWithChip); 246 switches::kMarkHttpWithPasswordsOrCcWithChip);
247 TestSecurityStateModelClient client; 247 TestSecurityStateModelClient client;
248 client.UseHttpUrl(); 248 client.UseHttpUrl();
249 SecurityStateModel model; 249 SecurityStateModel model;
250 model.SetClient(&client); 250 model.SetClient(&client);
251 client.set_displayed_password_field_on_http(true); 251 client.set_displayed_password_field_on_http(true);
252 SecurityStateModel::SecurityInfo security_info; 252 SecurityStateModel::SecurityInfo security_info;
253 model.GetSecurityInfo(&security_info); 253 model.GetSecurityInfo(&security_info);
254 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); 254 EXPECT_TRUE(security_info.displayed_password_field_on_http);
255 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, 255 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING,
256 security_info.security_level); 256 security_info.security_level);
257 } 257 }
258 258
259 // Tests that credit card fields cause the security level to be downgraded 259 // Tests that credit card fields cause the security level to be downgraded
260 // to HTTP_SHOW_WARNING when the command-line switch is set. 260 // to HTTP_SHOW_WARNING when the command-line switch is set.
261 TEST(SecurityStateModelTest, CreditCardFieldWarning) { 261 TEST(SecurityStateModelTest, CreditCardFieldWarning) {
262 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 262 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
263 switches::kMarkHttpAs, 263 switches::kMarkHttpAs,
264 switches::kMarkHttpWithPasswordsOrCcWithChip); 264 switches::kMarkHttpWithPasswordsOrCcWithChip);
265 TestSecurityStateModelClient client; 265 TestSecurityStateModelClient client;
266 client.UseHttpUrl(); 266 client.UseHttpUrl();
267 SecurityStateModel model; 267 SecurityStateModel model;
268 model.SetClient(&client); 268 model.SetClient(&client);
269 client.set_displayed_credit_card_field_on_http(true); 269 client.set_displayed_credit_card_field_on_http(true);
270 SecurityStateModel::SecurityInfo security_info; 270 SecurityStateModel::SecurityInfo security_info;
271 model.GetSecurityInfo(&security_info); 271 model.GetSecurityInfo(&security_info);
272 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); 272 EXPECT_TRUE(security_info.displayed_credit_card_field_on_http);
273 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, 273 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING,
274 security_info.security_level); 274 security_info.security_level);
275 } 275 }
276 276
277 // Tests that neither password nor credit fields cause the security 277 // Tests that neither password nor credit fields cause the security
278 // level to be downgraded to HTTP_SHOW_WARNING when the command-line switch 278 // level to be downgraded to HTTP_SHOW_WARNING when the command-line switch
279 // is NOT set. 279 // is NOT set.
280 TEST(SecurityStateModelTest, HttpWarningNotSetWithoutSwitch) { 280 TEST(SecurityStateModelTest, HttpWarningNotSetWithoutSwitch) {
281 TestSecurityStateModelClient client; 281 TestSecurityStateModelClient client;
282 client.UseHttpUrl(); 282 client.UseHttpUrl();
283 SecurityStateModel model; 283 SecurityStateModel model;
284 model.SetClient(&client); 284 model.SetClient(&client);
285 client.set_displayed_password_field_on_http(true); 285 client.set_displayed_password_field_on_http(true);
286 client.set_displayed_credit_card_field_on_http(true);
287 SecurityStateModel::SecurityInfo security_info; 286 SecurityStateModel::SecurityInfo security_info;
288 model.GetSecurityInfo(&security_info); 287 model.GetSecurityInfo(&security_info);
289 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); 288 EXPECT_TRUE(security_info.displayed_password_field_on_http);
289 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level);
290
291 client.set_displayed_credit_card_field_on_http(true);
292 model.GetSecurityInfo(&security_info);
293 EXPECT_TRUE(security_info.displayed_credit_card_field_on_http);
290 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); 294 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level);
291 } 295 }
292 296
293 // Tests that |displayed_private_user_data_input_on_http| is not set 297 // Tests that neither |displayed_password_field_on_http| nor
294 // when the corresponding VisibleSecurityState flags are not set. 298 // |displayed_credit_card_field_on_http| is set when the corresponding
299 // VisibleSecurityState flags are not set.
295 TEST(SecurityStateModelTest, PrivateUserDataNotSet) { 300 TEST(SecurityStateModelTest, PrivateUserDataNotSet) {
296 TestSecurityStateModelClient client; 301 TestSecurityStateModelClient client;
297 client.UseHttpUrl(); 302 client.UseHttpUrl();
298 SecurityStateModel model; 303 SecurityStateModel model;
299 model.SetClient(&client); 304 model.SetClient(&client);
300 SecurityStateModel::SecurityInfo security_info; 305 SecurityStateModel::SecurityInfo security_info;
301 model.GetSecurityInfo(&security_info); 306 model.GetSecurityInfo(&security_info);
302 EXPECT_FALSE(security_info.displayed_private_user_data_input_on_http); 307 EXPECT_FALSE(security_info.displayed_password_field_on_http);
308 EXPECT_FALSE(security_info.displayed_credit_card_field_on_http);
303 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); 309 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level);
304 } 310 }
305 311
306 // Tests that SSL.MarkHttpAsStatus histogram is updated when security state is 312 // Tests that SSL.MarkHttpAsStatus histogram is updated when security state is
307 // computed for a page. 313 // computed for a page.
308 TEST(SecurityStateModelTest, MarkHttpAsStatusHistogram) { 314 TEST(SecurityStateModelTest, MarkHttpAsStatusHistogram) {
309 const char* kHistogramName = "SSL.MarkHttpAsStatus"; 315 const char* kHistogramName = "SSL.MarkHttpAsStatus";
310 base::HistogramTester histograms; 316 base::HistogramTester histograms;
311 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 317 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
312 switches::kMarkHttpAs, switches::kMarkHttpWithPasswordsOrCcWithChip); 318 switches::kMarkHttpAs, switches::kMarkHttpWithPasswordsOrCcWithChip);
(...skipping 12 matching lines...) Expand all
325 331
326 // Ensure histogram recorded correctly even without a password input. 332 // Ensure histogram recorded correctly even without a password input.
327 client.set_displayed_password_field_on_http(false); 333 client.set_displayed_password_field_on_http(false);
328 model.GetSecurityInfo(&security_info); 334 model.GetSecurityInfo(&security_info);
329 histograms.ExpectUniqueSample(kHistogramName, 2 /* HTTP_SHOW_WARNING */, 2); 335 histograms.ExpectUniqueSample(kHistogramName, 2 /* HTTP_SHOW_WARNING */, 2);
330 } 336 }
331 337
332 } // namespace 338 } // namespace
333 339
334 } // namespace security_state 340 } // namespace security_state
OLDNEW
« no previous file with comments | « components/security_state/security_state_model.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698