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

Side by Side Diff: chrome/browser/ssl/chrome_security_state_model_client_unittest.cc

Issue 2483423002: HTTP Bad: Split out UMA metrics for password vs credit card "Not secure" warnings (Closed)
Patch Set: advise test 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 2016 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ssl/chrome_security_state_model_client.h" 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "components/security_state/security_state_model.h" 10 #include "components/security_state/security_state_model.h"
11 #include "components/security_state/switches.h" 11 #include "components/security_state/switches.h"
12 #include "content/public/browser/security_style_explanation.h" 12 #include "content/public/browser/security_style_explanation.h"
13 #include "content/public/browser/security_style_explanations.h" 13 #include "content/public/browser/security_style_explanations.h"
14 #include "net/cert/cert_status_flags.h" 14 #include "net/cert/cert_status_flags.h"
15 #include "net/ssl/ssl_cipher_suite_names.h" 15 #include "net/ssl/ssl_cipher_suite_names.h"
16 #include "net/ssl/ssl_connection_status_flags.h" 16 #include "net/ssl/ssl_connection_status_flags.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace { 19 namespace {
20 20
21 const char kHTTPBadHistogram[] =
22 "Security.HTTPBad.UserWarnedAboutSensitiveInput";
23
24 // Tests that SecurityInfo flags for subresources with certificate 21 // Tests that SecurityInfo flags for subresources with certificate
25 // errors are reflected in the SecurityStyleExplanations produced by 22 // errors are reflected in the SecurityStyleExplanations produced by
26 // ChromeSecurityStateModelClient. 23 // ChromeSecurityStateModelClient.
27 TEST(ChromeSecurityStateModelClientTest, 24 TEST(ChromeSecurityStateModelClientTest,
28 GetSecurityStyleForContentWithCertErrors) { 25 GetSecurityStyleForContentWithCertErrors) {
29 content::SecurityStyleExplanations explanations; 26 content::SecurityStyleExplanations explanations;
30 security_state::SecurityStateModel::SecurityInfo security_info; 27 security_state::SecurityStateModel::SecurityInfo security_info;
31 security_info.cert_status = 0; 28 security_info.cert_status = 0;
32 security_info.scheme_is_cryptographic = true; 29 security_info.scheme_is_cryptographic = true;
33 30
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 security_state::SecurityStateModel::HTTP_SHOW_WARNING; 226 security_state::SecurityStateModel::HTTP_SHOW_WARNING;
230 blink::WebSecurityStyle security_style = 227 blink::WebSecurityStyle security_style =
231 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, 228 ChromeSecurityStateModelClient::GetSecurityStyle(security_info,
232 &explanations); 229 &explanations);
233 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); 230 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style);
234 EXPECT_EQ(1u, explanations.unauthenticated_explanations.size()); 231 EXPECT_EQ(1u, explanations.unauthenticated_explanations.size());
235 } 232 }
236 233
237 // Tests that a security level of NONE when there is a password or 234 // Tests that a security level of NONE when there is a password or
238 // credit card field on HTTP produces a content::SecurityStyle of 235 // credit card field on HTTP produces a content::SecurityStyle of
239 // UNAUTHENTICATED, with an info explanation. 236 // UNAUTHENTICATED, with an info explanation for each.
240 TEST(ChromeSecurityStateModelClientTest, HTTPWarningInFuture) { 237 TEST(ChromeSecurityStateModelClientTest, HTTPWarningInFuture) {
241 security_state::SecurityStateModel::SecurityInfo security_info; 238 security_state::SecurityStateModel::SecurityInfo security_info;
242 content::SecurityStyleExplanations explanations; 239 content::SecurityStyleExplanations explanations;
243 security_info.security_level = security_state::SecurityStateModel::NONE; 240 security_info.security_level = security_state::SecurityStateModel::NONE;
244 security_info.displayed_private_user_data_input_on_http = true; 241 security_info.displayed_password_field_on_http = true;
245 blink::WebSecurityStyle security_style = 242 blink::WebSecurityStyle security_style =
246 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, 243 ChromeSecurityStateModelClient::GetSecurityStyle(security_info,
247 &explanations); 244 &explanations);
248 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); 245 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style);
249 EXPECT_EQ(1u, explanations.info_explanations.size()); 246 EXPECT_EQ(1u, explanations.info_explanations.size());
247
248 explanations.info_explanations.clear();
249 security_info.displayed_credit_card_field_on_http = true;
250 security_style = ChromeSecurityStateModelClient::GetSecurityStyle(
251 security_info, &explanations);
252 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style);
253 EXPECT_EQ(1u, explanations.info_explanations.size());
254
255 // Check that when both password and credit card fields get displayed, only
256 // one explanation added.
estark 2016/11/10 05:19:29 nit: added => is added
lshang 2016/11/10 05:33:52 Done.
257 explanations.info_explanations.clear();
258 security_info.displayed_credit_card_field_on_http = true;
259 security_info.displayed_password_field_on_http = true;
260 security_style = ChromeSecurityStateModelClient::GetSecurityStyle(
261 security_info, &explanations);
262 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style);
263 EXPECT_EQ(1u, explanations.info_explanations.size());
250 } 264 }
251 265
252 class ChromeSecurityStateModelClientHistogramTest 266 class ChromeSecurityStateModelClientHistogramTest
253 : public ChromeRenderViewHostTestHarness { 267 : public ChromeRenderViewHostTestHarness,
268 public testing::WithParamInterface<bool> {
254 public: 269 public:
255 ChromeSecurityStateModelClientHistogramTest() {} 270 ChromeSecurityStateModelClientHistogramTest() {}
256 ~ChromeSecurityStateModelClientHistogramTest() override {} 271 ~ChromeSecurityStateModelClientHistogramTest() override {}
257 272
258 void SetUp() override { 273 void SetUp() override {
259 ChromeRenderViewHostTestHarness::SetUp(); 274 ChromeRenderViewHostTestHarness::SetUp();
260 275
261 ChromeSecurityStateModelClient::CreateForWebContents(web_contents()); 276 ChromeSecurityStateModelClient::CreateForWebContents(web_contents());
262 client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents()); 277 client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents());
263 navigate_to_http(); 278 navigate_to_http();
264 } 279 }
265 280
266 protected: 281 protected:
267 ChromeSecurityStateModelClient* client() { return client_; } 282 ChromeSecurityStateModelClient* client() { return client_; }
268 283
269 void signal_password() { 284 void signal_sensitive_input() {
270 web_contents()->OnPasswordInputShownOnHttp(); 285 if (GetParam())
286 web_contents()->OnPasswordInputShownOnHttp();
287 else
288 web_contents()->OnCreditCardInputShownOnHttp();
271 client_->VisibleSecurityStateChanged(); 289 client_->VisibleSecurityStateChanged();
272 } 290 }
273 291
292 const std::string histogram_name() {
293 if (GetParam())
294 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password";
295 else
296 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.CreditCard";
297 }
298
274 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); } 299 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); }
275 300
276 private: 301 private:
277 ChromeSecurityStateModelClient* client_; 302 ChromeSecurityStateModelClient* client_;
278 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelClientHistogramTest); 303 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelClientHistogramTest);
279 }; 304 };
280 305
281 // Tests that UMA logs the omnibox warning when security level is 306 // Tests that UMA logs the omnibox warning when security level is
282 // HTTP_SHOW_WARNING. 307 // HTTP_SHOW_WARNING.
283 TEST_F(ChromeSecurityStateModelClientHistogramTest, 308 TEST_P(ChromeSecurityStateModelClientHistogramTest,
284 HTTPOmniboxWarningHistogram) { 309 HTTPOmniboxWarningHistogram) {
285 // Show Warning Chip. 310 // Show Warning Chip.
286 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 311 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
287 security_state::switches::kMarkHttpAs, 312 security_state::switches::kMarkHttpAs,
288 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); 313 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
289 314
290 base::HistogramTester histograms; 315 base::HistogramTester histograms;
291 signal_password(); 316 signal_sensitive_input();
292 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); 317 histograms.ExpectUniqueSample(histogram_name(), true, 1);
293 318
294 // Fire again and ensure no sample is recorded. 319 // Fire again and ensure no sample is recorded.
295 signal_password(); 320 signal_sensitive_input();
296 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); 321 histograms.ExpectUniqueSample(histogram_name(), true, 1);
297 322
298 // Navigate to a new page and ensure a sample is recorded. 323 // Navigate to a new page and ensure a sample is recorded.
299 navigate_to_http(); 324 navigate_to_http();
300 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); 325 histograms.ExpectUniqueSample(histogram_name(), true, 1);
301 signal_password(); 326 signal_sensitive_input();
302 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 2); 327 histograms.ExpectUniqueSample(histogram_name(), true, 2);
303 } 328 }
304 329
305 // Tests that UMA logs the console warning when security level is NONE. 330 // Tests that UMA logs the console warning when security level is NONE.
306 TEST_F(ChromeSecurityStateModelClientHistogramTest, 331 TEST_P(ChromeSecurityStateModelClientHistogramTest,
307 HTTPConsoleWarningHistogram) { 332 HTTPConsoleWarningHistogram) {
308 // Show Neutral for HTTP 333 // Show Neutral for HTTP
309 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 334 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
310 security_state::switches::kMarkHttpAs, 335 security_state::switches::kMarkHttpAs,
311 security_state::switches::kMarkHttpAsNeutral); 336 security_state::switches::kMarkHttpAsNeutral);
312 337
313 base::HistogramTester histograms; 338 base::HistogramTester histograms;
314 signal_password(); 339 signal_sensitive_input();
315 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); 340 histograms.ExpectUniqueSample(histogram_name(), false, 1);
316 341
317 // Fire again and ensure no sample is recorded. 342 // Fire again and ensure no sample is recorded.
318 signal_password(); 343 signal_sensitive_input();
319 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); 344 histograms.ExpectUniqueSample(histogram_name(), false, 1);
320 345
321 // Navigate to a new page and ensure a sample is recorded. 346 // Navigate to a new page and ensure a sample is recorded.
322 navigate_to_http(); 347 navigate_to_http();
323 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); 348 histograms.ExpectUniqueSample(histogram_name(), false, 1);
324 signal_password(); 349 signal_sensitive_input();
325 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 2); 350 histograms.ExpectUniqueSample(histogram_name(), false, 2);
326 } 351 }
327 352
353 INSTANTIATE_TEST_CASE_P(ChromeSecurityStateModelClientHistogramTest,
354 ChromeSecurityStateModelClientHistogramTest,
355 // Here 'true' to test password field triggered
356 // histogram and 'false' to test
357 // credit catd field.
estark 2016/11/10 05:19:29 nit: typo, catd => card
lshang 2016/11/10 05:33:52 Done. Also correct the indent.
358 testing::Bool());
359
328 } // namespace 360 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698