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" | |
| 8 #include "base/test/histogram_tester.h" | |
| 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 7 #include "components/security_state/security_state_model.h" | 10 #include "components/security_state/security_state_model.h" |
| 11 #include "components/security_state/switches.h" | |
| 12 #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
| |
| 8 #include "content/public/browser/security_style_explanation.h" | 13 #include "content/public/browser/security_style_explanation.h" |
| 9 #include "content/public/browser/security_style_explanations.h" | 14 #include "content/public/browser/security_style_explanations.h" |
| 15 #include "content/public/browser/ssl_status.h" | |
| 10 #include "net/cert/cert_status_flags.h" | 16 #include "net/cert/cert_status_flags.h" |
| 11 #include "net/ssl/ssl_cipher_suite_names.h" | 17 #include "net/ssl/ssl_cipher_suite_names.h" |
| 12 #include "net/ssl/ssl_connection_status_flags.h" | 18 #include "net/ssl/ssl_connection_status_flags.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 20 |
| 15 namespace { | 21 namespace { |
| 16 | 22 |
| 23 const char kHTTPBadHistogram[] = | |
| 24 "Security.HTTPBad.UserWarnedAboutSensitiveInput"; | |
| 25 | |
| 17 // Tests that SecurityInfo flags for subresources with certificate | 26 // Tests that SecurityInfo flags for subresources with certificate |
| 18 // errors are reflected in the SecurityStyleExplanations produced by | 27 // errors are reflected in the SecurityStyleExplanations produced by |
| 19 // ChromeSecurityStateModelClient. | 28 // ChromeSecurityStateModelClient. |
| 20 TEST(ChromeSecurityStateModelClientTest, | 29 TEST(ChromeSecurityStateModelClientTest, |
| 21 GetSecurityStyleForContentWithCertErrors) { | 30 GetSecurityStyleForContentWithCertErrors) { |
| 22 content::SecurityStyleExplanations explanations; | 31 content::SecurityStyleExplanations explanations; |
| 23 security_state::SecurityStateModel::SecurityInfo security_info; | 32 security_state::SecurityStateModel::SecurityInfo security_info; |
| 24 security_info.cert_status = 0; | 33 security_info.cert_status = 0; |
| 25 security_info.scheme_is_cryptographic = true; | 34 security_info.scheme_is_cryptographic = true; |
| 26 | 35 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 content::SecurityStyleExplanations explanations; | 244 content::SecurityStyleExplanations explanations; |
| 236 security_info.security_level = security_state::SecurityStateModel::NONE; | 245 security_info.security_level = security_state::SecurityStateModel::NONE; |
| 237 security_info.displayed_private_user_data_input_on_http = true; | 246 security_info.displayed_private_user_data_input_on_http = true; |
| 238 blink::WebSecurityStyle security_style = | 247 blink::WebSecurityStyle security_style = |
| 239 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 248 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 240 &explanations); | 249 &explanations); |
| 241 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); | 250 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); |
| 242 EXPECT_EQ(1u, explanations.info_explanations.size()); | 251 EXPECT_EQ(1u, explanations.info_explanations.size()); |
| 243 } | 252 } |
| 244 | 253 |
| 254 class ChromeSecurityStateModelClientHistogramTest | |
| 255 : public ChromeRenderViewHostTestHarness { | |
| 256 public: | |
| 257 ChromeSecurityStateModelClientHistogramTest() {} | |
| 258 ~ChromeSecurityStateModelClientHistogramTest() override {} | |
| 259 | |
| 260 void SetUp() override { | |
| 261 ChromeRenderViewHostTestHarness::SetUp(); | |
| 262 | |
| 263 ChromeSecurityStateModelClient::CreateForWebContents(web_contents()); | |
| 264 client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents()); | |
| 265 navigate_to_http(); | |
| 266 } | |
| 267 | |
| 268 protected: | |
| 269 ChromeSecurityStateModelClient* client() { return client_; } | |
| 270 void signal_password() { | |
|
estark
2016/10/26 21:29:46
nit: blank line above this
elawrence
2016/10/26 21:40:20
Done.
| |
| 271 web_contents()->OnPasswordInputShownOnHttp(); | |
| 272 client_->VisibleSSLStateChanged(); | |
| 273 } | |
| 274 | |
| 275 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); } | |
| 276 | |
| 277 private: | |
| 278 ChromeSecurityStateModelClient* client_; | |
| 279 }; | |
| 280 | |
| 281 // Tests that UMA logs the omnibox warning when security level is | |
| 282 // HTTP_SHOW_WARNING. | |
| 283 TEST_F(ChromeSecurityStateModelClientHistogramTest, | |
| 284 HTTPOmniboxWarningHistogram) { | |
| 285 // Show Warning Chip. | |
| 286 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 287 security_state::switches::kMarkHttpAs, | |
| 288 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); | |
| 289 | |
| 290 base::HistogramTester histograms; | |
| 291 signal_password(); | |
| 292 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); | |
| 293 | |
| 294 // Fire again and ensure no sample is recorded. | |
| 295 signal_password(); | |
| 296 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); | |
| 297 | |
| 298 // Navigate to a new page and ensure a sample is recorded. | |
| 299 navigate_to_http(); | |
| 300 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1); | |
| 301 signal_password(); | |
| 302 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 2); | |
| 303 } | |
| 304 | |
| 305 // Tests that UMA logs the console warning when security level is NONE. | |
| 306 TEST_F(ChromeSecurityStateModelClientHistogramTest, | |
| 307 HTTPConsoleWarningHistogram) { | |
| 308 // Show Neutral for HTTP | |
| 309 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 310 security_state::switches::kMarkHttpAs, | |
| 311 security_state::switches::kMarkHttpAsNeutral); | |
| 312 | |
| 313 base::HistogramTester histograms; | |
| 314 signal_password(); | |
| 315 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); | |
| 316 | |
| 317 // Fire again and ensure no sample is recorded. | |
| 318 signal_password(); | |
| 319 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); | |
| 320 | |
| 321 // Navigate to a new page and ensure a sample is recorded. | |
| 322 navigate_to_http(); | |
| 323 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1); | |
| 324 signal_password(); | |
| 325 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 2); | |
| 326 } | |
| 327 | |
| 245 } // namespace | 328 } // namespace |
| OLD | NEW |