Chromium Code Reviews| Index: chrome/browser/ssl/chrome_security_state_model_client_unittest.cc |
| diff --git a/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc b/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc |
| index 9a50d7bc05b7e937f30a2843530afc2399932d46..b212395e3bf10837d8c62df8b9cfe6d1f229f4ee 100644 |
| --- a/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc |
| +++ b/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc |
| @@ -4,9 +4,15 @@ |
| #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| +#include "base/command_line.h" |
| +#include "base/test/histogram_tester.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "components/security_state/security_state_model.h" |
| +#include "components/security_state/switches.h" |
| +#include "content/public/browser/navigation_entry.h" |
|
estark
2016/10/26 21:29:46
nit: are this and ssl_status.h needed?
elawrence
2016/10/26 21:40:20
Nope; stale from when I was fumbling about earlier
|
| #include "content/public/browser/security_style_explanation.h" |
| #include "content/public/browser/security_style_explanations.h" |
| +#include "content/public/browser/ssl_status.h" |
| #include "net/cert/cert_status_flags.h" |
| #include "net/ssl/ssl_cipher_suite_names.h" |
| #include "net/ssl/ssl_connection_status_flags.h" |
| @@ -14,6 +20,9 @@ |
| namespace { |
| +const char kHTTPBadHistogram[] = |
| + "Security.HTTPBad.UserWarnedAboutSensitiveInput"; |
| + |
| // Tests that SecurityInfo flags for subresources with certificate |
| // errors are reflected in the SecurityStyleExplanations produced by |
| // ChromeSecurityStateModelClient. |
| @@ -242,4 +251,78 @@ TEST(ChromeSecurityStateModelClientTest, HTTPWarningInFuture) { |
| EXPECT_EQ(1u, explanations.info_explanations.size()); |
| } |
| +class ChromeSecurityStateModelClientHistogramTest |
| + : public ChromeRenderViewHostTestHarness { |
| + public: |
| + ChromeSecurityStateModelClientHistogramTest() {} |
| + ~ChromeSecurityStateModelClientHistogramTest() override {} |
| + |
| + void SetUp() override { |
| + ChromeRenderViewHostTestHarness::SetUp(); |
| + |
| + ChromeSecurityStateModelClient::CreateForWebContents(web_contents()); |
| + client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents()); |
| + navigate_to_http(); |
| + } |
| + |
| + protected: |
| + ChromeSecurityStateModelClient* client() { return client_; } |
| + void signal_password() { |
|
estark
2016/10/26 21:29:46
nit: blank line above this
elawrence
2016/10/26 21:40:20
Done.
|
| + web_contents()->OnPasswordInputShownOnHttp(); |
| + client_->VisibleSSLStateChanged(); |
| + } |
| + |
| + void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); } |
| + |
| + private: |
| + ChromeSecurityStateModelClient* client_; |
| +}; |
| + |
| +// Tests that UMA logs the omnibox warning when security level is |
| +// HTTP_SHOW_WARNING. |
| +TEST_F(ChromeSecurityStateModelClientHistogramTest, |
| + HTTPOmniboxWarningHistogram) { |
| + // Show Warning Chip. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| + security_state::switches::kMarkHttpAs, |
| + security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); |
| + |
| + base::HistogramTester histograms; |
| + signal_password(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); |
| + |
| + // Fire again and ensure no sample is recorded. |
| + signal_password(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); |
| + |
| + // Navigate to a new page and ensure a sample is recorded. |
| + navigate_to_http(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); |
| + signal_password(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 2); |
| +} |
| + |
| +// Tests that UMA logs the console warning when security level is NONE. |
| +TEST_F(ChromeSecurityStateModelClientHistogramTest, |
| + HTTPConsoleWarningHistogram) { |
| + // Show Neutral for HTTP |
| + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| + security_state::switches::kMarkHttpAs, |
| + security_state::switches::kMarkHttpAsNeutral); |
| + |
| + base::HistogramTester histograms; |
| + signal_password(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); |
| + |
| + // Fire again and ensure no sample is recorded. |
| + signal_password(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); |
| + |
| + // Navigate to a new page and ensure a sample is recorded. |
| + navigate_to_http(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); |
| + signal_password(); |
| + histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 2); |
| +} |
| + |
| } // namespace |