Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 kHTTPBadNavigationHistogram[] = | |
| 22 "Security.HTTPBad.NavigationStartedAfterUserWarnedAboutSensitiveInput"; | |
| 23 const char kHTTPBadWebContentsDestroyedHistogram[] = | |
| 24 "Security.HTTPBad.WebContentsDestroyedAfterUserWarnedAboutSensitiveInput"; | |
| 25 | |
| 21 // Tests that SecurityInfo flags for subresources with certificate | 26 // Tests that SecurityInfo flags for subresources with certificate |
| 22 // errors are reflected in the SecurityStyleExplanations produced by | 27 // errors are reflected in the SecurityStyleExplanations produced by |
| 23 // ChromeSecurityStateModelClient. | 28 // ChromeSecurityStateModelClient. |
| 24 TEST(ChromeSecurityStateModelClientTest, | 29 TEST(ChromeSecurityStateModelClientTest, |
| 25 GetSecurityStyleForContentWithCertErrors) { | 30 GetSecurityStyleForContentWithCertErrors) { |
| 26 content::SecurityStyleExplanations explanations; | 31 content::SecurityStyleExplanations explanations; |
| 27 security_state::SecurityStateModel::SecurityInfo security_info; | 32 security_state::SecurityStateModel::SecurityInfo security_info; |
| 28 security_info.cert_status = 0; | 33 security_info.cert_status = 0; |
| 29 security_info.scheme_is_cryptographic = true; | 34 security_info.scheme_is_cryptographic = true; |
| 30 | 35 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 public testing::WithParamInterface<bool> { | 273 public testing::WithParamInterface<bool> { |
| 269 public: | 274 public: |
| 270 ChromeSecurityStateModelClientHistogramTest() {} | 275 ChromeSecurityStateModelClientHistogramTest() {} |
| 271 ~ChromeSecurityStateModelClientHistogramTest() override {} | 276 ~ChromeSecurityStateModelClientHistogramTest() override {} |
| 272 | 277 |
| 273 void SetUp() override { | 278 void SetUp() override { |
| 274 ChromeRenderViewHostTestHarness::SetUp(); | 279 ChromeRenderViewHostTestHarness::SetUp(); |
| 275 | 280 |
| 276 ChromeSecurityStateModelClient::CreateForWebContents(web_contents()); | 281 ChromeSecurityStateModelClient::CreateForWebContents(web_contents()); |
| 277 client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents()); | 282 client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents()); |
| 278 navigate_to_http(); | 283 NavigateToHTTP(); |
| 279 } | 284 } |
| 280 | 285 |
| 281 protected: | 286 protected: |
| 282 ChromeSecurityStateModelClient* client() { return client_; } | 287 ChromeSecurityStateModelClient* client() { return client_; } |
| 283 | 288 |
| 284 void signal_sensitive_input() { | 289 void SignalSensitiveInput() { |
| 285 if (GetParam()) | 290 if (GetParam()) |
| 286 web_contents()->OnPasswordInputShownOnHttp(); | 291 web_contents()->OnPasswordInputShownOnHttp(); |
| 287 else | 292 else |
| 288 web_contents()->OnCreditCardInputShownOnHttp(); | 293 web_contents()->OnCreditCardInputShownOnHttp(); |
| 289 client_->VisibleSecurityStateChanged(); | 294 client_->VisibleSecurityStateChanged(); |
| 290 } | 295 } |
| 291 | 296 |
| 292 const std::string histogram_name() { | 297 const std::string GetHistogramName() { |
| 293 if (GetParam()) | 298 if (GetParam()) |
| 294 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password"; | 299 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password"; |
| 295 else | 300 else |
| 296 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.CreditCard"; | 301 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.CreditCard"; |
| 297 } | 302 } |
| 298 | 303 |
| 299 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); } | 304 void NavigateToHTTP() { NavigateAndCommit(GURL("http://example.test")); } |
| 300 | 305 |
| 301 void navigate_to_different_http_page() { | 306 void NavigateToDifferentHTTPPage() { |
| 302 NavigateAndCommit(GURL("http://example2.test")); | 307 NavigateAndCommit(GURL("http://example2.test")); |
| 303 } | 308 } |
| 304 | 309 |
| 305 private: | 310 private: |
| 306 ChromeSecurityStateModelClient* client_; | 311 ChromeSecurityStateModelClient* client_; |
| 307 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelClientHistogramTest); | 312 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelClientHistogramTest); |
| 308 }; | 313 }; |
| 309 | 314 |
| 315 // Tests that an UMA histogram is recorded after setting the security | |
| 316 // level to HTTP_SHOW_WARNING and navigating away. | |
| 317 TEST_P(ChromeSecurityStateModelClientHistogramTest, | |
| 318 HTTPOmniboxWarningNavigationHistogram) { | |
| 319 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 320 security_state::switches::kMarkHttpAs, | |
| 321 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); | |
| 322 | |
| 323 base::HistogramTester histograms; | |
| 324 SignalSensitiveInput(); | |
| 325 // Make sure that if the omnibox warning gets dynamically hidden, the | |
| 326 // histogram still gets recorded. | |
| 327 if (GetParam()) | |
| 328 web_contents()->OnAllPasswordInputsHiddenOnHttp(); | |
| 329 NavigateToDifferentHTTPPage(); | |
| 330 // Destroy the WebContents to simulate the tab being closed after a | |
| 331 // navigation. | |
| 332 SetContents(nullptr); | |
| 333 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 1); | |
| 334 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 0); | |
| 335 } | |
| 336 | |
| 337 // Tests that an UMA histogram is recorded after showing a console | |
| 338 // warning for a sensitive input on HTTP and navigating away. | |
| 339 TEST_P(ChromeSecurityStateModelClientHistogramTest, | |
| 340 HTTPConsoleWarningNavigationHistogram) { | |
| 341 // Same as the test above, but ensuring that the histogram gets | |
|
elawrence
2016/11/15 16:29:53
"test above"
This comment feels fragile. Is it sa
estark
2016/11/16 05:16:14
Done.
| |
| 342 // recorded even if the command-line switch to show the omnibox | |
| 343 // warning is not set. | |
| 344 base::HistogramTester histograms; | |
| 345 SignalSensitiveInput(); | |
| 346 NavigateToDifferentHTTPPage(); | |
| 347 // Destroy the WebContents to simulate the tab being closed after a | |
| 348 // navigation. | |
| 349 SetContents(nullptr); | |
| 350 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 1); | |
| 351 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 0); | |
| 352 } | |
| 353 | |
| 354 // Tests that an UMA histogram is recorded after setting the security | |
| 355 // level to HTTP_SHOW_WARNING and closing the tab. | |
| 356 TEST_P(ChromeSecurityStateModelClientHistogramTest, | |
| 357 HTTPOmniboxWarningTabClosedHistogram) { | |
| 358 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 359 security_state::switches::kMarkHttpAs, | |
| 360 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); | |
| 361 | |
| 362 base::HistogramTester histograms; | |
| 363 SignalSensitiveInput(); | |
| 364 // Destroy the WebContents to simulate the tab being closed. | |
| 365 SetContents(nullptr); | |
| 366 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 0); | |
| 367 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 1); | |
| 368 } | |
| 369 | |
| 370 // Tests that an UMA histogram is recorded after showing a console | |
| 371 // warning for a sensitive input on HTTP and closing the tab. | |
| 372 TEST_P(ChromeSecurityStateModelClientHistogramTest, | |
| 373 HTTPConsoleWarningTabClosedHistogram) { | |
| 374 // Same as the test above, but ensuring that the histogram gets | |
|
elawrence
2016/11/15 16:29:53
"test above"
estark
2016/11/16 05:16:14
Done.
| |
| 375 // recorded even if the command-line switch to show the omnibox | |
| 376 // warning is not set. | |
|
elawrence
2016/11/15 16:29:53
"warning is not set"
Do we explicitly need to set
estark
2016/11/16 05:16:13
Done.
| |
| 377 base::HistogramTester histograms; | |
| 378 SignalSensitiveInput(); | |
| 379 // Destroy the WebContents to simulate the tab being closed. | |
| 380 SetContents(nullptr); | |
| 381 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 0); | |
| 382 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 1); | |
| 383 } | |
| 384 | |
| 310 // Tests that UMA logs the omnibox warning when security level is | 385 // Tests that UMA logs the omnibox warning when security level is |
| 311 // HTTP_SHOW_WARNING. | 386 // HTTP_SHOW_WARNING. |
| 312 TEST_P(ChromeSecurityStateModelClientHistogramTest, | 387 TEST_P(ChromeSecurityStateModelClientHistogramTest, |
| 313 HTTPOmniboxWarningHistogram) { | 388 HTTPOmniboxWarningHistogram) { |
| 314 // Show Warning Chip. | 389 // Show Warning Chip. |
| 315 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 390 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 316 security_state::switches::kMarkHttpAs, | 391 security_state::switches::kMarkHttpAs, |
| 317 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); | 392 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); |
| 318 | 393 |
| 319 base::HistogramTester histograms; | 394 base::HistogramTester histograms; |
| 320 signal_sensitive_input(); | 395 SignalSensitiveInput(); |
| 321 histograms.ExpectUniqueSample(histogram_name(), true, 1); | 396 histograms.ExpectUniqueSample(GetHistogramName(), true, 1); |
| 322 | 397 |
| 323 // Fire again and ensure no sample is recorded. | 398 // Fire again and ensure no sample is recorded. |
| 324 signal_sensitive_input(); | 399 SignalSensitiveInput(); |
| 325 histograms.ExpectUniqueSample(histogram_name(), true, 1); | 400 histograms.ExpectUniqueSample(GetHistogramName(), true, 1); |
| 326 | 401 |
| 327 // Navigate to a new page and ensure a sample is recorded. | 402 // Navigate to a new page and ensure a sample is recorded. |
| 328 navigate_to_different_http_page(); | 403 NavigateToDifferentHTTPPage(); |
| 329 histograms.ExpectUniqueSample(histogram_name(), true, 1); | 404 histograms.ExpectUniqueSample(GetHistogramName(), true, 1); |
| 330 signal_sensitive_input(); | 405 SignalSensitiveInput(); |
| 331 histograms.ExpectUniqueSample(histogram_name(), true, 2); | 406 histograms.ExpectUniqueSample(GetHistogramName(), true, 2); |
| 332 } | 407 } |
| 333 | 408 |
| 334 // Tests that UMA logs the console warning when security level is NONE. | 409 // Tests that UMA logs the console warning when security level is NONE. |
| 335 TEST_P(ChromeSecurityStateModelClientHistogramTest, | 410 TEST_P(ChromeSecurityStateModelClientHistogramTest, |
| 336 HTTPConsoleWarningHistogram) { | 411 HTTPConsoleWarningHistogram) { |
| 337 // Show Neutral for HTTP | 412 // Show Neutral for HTTP |
| 338 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 413 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 339 security_state::switches::kMarkHttpAs, | 414 security_state::switches::kMarkHttpAs, |
| 340 security_state::switches::kMarkHttpAsNeutral); | 415 security_state::switches::kMarkHttpAsNeutral); |
| 341 | 416 |
| 342 base::HistogramTester histograms; | 417 base::HistogramTester histograms; |
| 343 signal_sensitive_input(); | 418 SignalSensitiveInput(); |
| 344 histograms.ExpectUniqueSample(histogram_name(), false, 1); | 419 histograms.ExpectUniqueSample(GetHistogramName(), false, 1); |
| 345 | 420 |
| 346 // Fire again and ensure no sample is recorded. | 421 // Fire again and ensure no sample is recorded. |
| 347 signal_sensitive_input(); | 422 SignalSensitiveInput(); |
| 348 histograms.ExpectUniqueSample(histogram_name(), false, 1); | 423 histograms.ExpectUniqueSample(GetHistogramName(), false, 1); |
| 349 | 424 |
| 350 // Navigate to a new page and ensure a sample is recorded. | 425 // Navigate to a new page and ensure a sample is recorded. |
| 351 navigate_to_different_http_page(); | 426 NavigateToDifferentHTTPPage(); |
| 352 histograms.ExpectUniqueSample(histogram_name(), false, 1); | 427 histograms.ExpectUniqueSample(GetHistogramName(), false, 1); |
| 353 signal_sensitive_input(); | 428 SignalSensitiveInput(); |
| 354 histograms.ExpectUniqueSample(histogram_name(), false, 2); | 429 histograms.ExpectUniqueSample(GetHistogramName(), false, 2); |
| 355 } | 430 } |
| 356 | 431 |
| 357 INSTANTIATE_TEST_CASE_P(ChromeSecurityStateModelClientHistogramTest, | 432 INSTANTIATE_TEST_CASE_P(ChromeSecurityStateModelClientHistogramTest, |
| 358 ChromeSecurityStateModelClientHistogramTest, | 433 ChromeSecurityStateModelClientHistogramTest, |
| 359 // Here 'true' to test password field triggered | 434 // Here 'true' to test password field triggered |
| 360 // histogram and 'false' to test credit card field. | 435 // histogram and 'false' to test credit card field. |
| 361 testing::Bool()); | 436 testing::Bool()); |
| 362 | 437 |
| 363 } // namespace | 438 } // namespace |
| OLD | NEW |