| 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" |
| 8 #include "content/public/browser/security_style_explanation.h" | 12 #include "content/public/browser/security_style_explanation.h" |
| 9 #include "content/public/browser/security_style_explanations.h" | 13 #include "content/public/browser/security_style_explanations.h" |
| 10 #include "net/cert/cert_status_flags.h" | 14 #include "net/cert/cert_status_flags.h" |
| 11 #include "net/ssl/ssl_cipher_suite_names.h" | 15 #include "net/ssl/ssl_cipher_suite_names.h" |
| 12 #include "net/ssl/ssl_connection_status_flags.h" | 16 #include "net/ssl/ssl_connection_status_flags.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 18 |
| 15 namespace { | 19 namespace { |
| 16 | 20 |
| 21 const char kHTTPBadHistogram[] = |
| 22 "Security.HTTPBad.UserWarnedAboutSensitiveInput"; |
| 23 |
| 17 // Tests that SecurityInfo flags for subresources with certificate | 24 // Tests that SecurityInfo flags for subresources with certificate |
| 18 // errors are reflected in the SecurityStyleExplanations produced by | 25 // errors are reflected in the SecurityStyleExplanations produced by |
| 19 // ChromeSecurityStateModelClient. | 26 // ChromeSecurityStateModelClient. |
| 20 TEST(ChromeSecurityStateModelClientTest, | 27 TEST(ChromeSecurityStateModelClientTest, |
| 21 GetSecurityStyleForContentWithCertErrors) { | 28 GetSecurityStyleForContentWithCertErrors) { |
| 22 content::SecurityStyleExplanations explanations; | 29 content::SecurityStyleExplanations explanations; |
| 23 security_state::SecurityStateModel::SecurityInfo security_info; | 30 security_state::SecurityStateModel::SecurityInfo security_info; |
| 24 security_info.cert_status = 0; | 31 security_info.cert_status = 0; |
| 25 security_info.scheme_is_cryptographic = true; | 32 security_info.scheme_is_cryptographic = true; |
| 26 | 33 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 content::SecurityStyleExplanations explanations; | 242 content::SecurityStyleExplanations explanations; |
| 236 security_info.security_level = security_state::SecurityStateModel::NONE; | 243 security_info.security_level = security_state::SecurityStateModel::NONE; |
| 237 security_info.displayed_private_user_data_input_on_http = true; | 244 security_info.displayed_private_user_data_input_on_http = true; |
| 238 blink::WebSecurityStyle security_style = | 245 blink::WebSecurityStyle security_style = |
| 239 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 246 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, |
| 240 &explanations); | 247 &explanations); |
| 241 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); | 248 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); |
| 242 EXPECT_EQ(1u, explanations.info_explanations.size()); | 249 EXPECT_EQ(1u, explanations.info_explanations.size()); |
| 243 } | 250 } |
| 244 | 251 |
| 252 class ChromeSecurityStateModelClientHistogramTest |
| 253 : public ChromeRenderViewHostTestHarness { |
| 254 public: |
| 255 ChromeSecurityStateModelClientHistogramTest() {} |
| 256 ~ChromeSecurityStateModelClientHistogramTest() override {} |
| 257 |
| 258 void SetUp() override { |
| 259 ChromeRenderViewHostTestHarness::SetUp(); |
| 260 |
| 261 ChromeSecurityStateModelClient::CreateForWebContents(web_contents()); |
| 262 client_ = ChromeSecurityStateModelClient::FromWebContents(web_contents()); |
| 263 navigate_to_http(); |
| 264 } |
| 265 |
| 266 protected: |
| 267 ChromeSecurityStateModelClient* client() { return client_; } |
| 268 |
| 269 void signal_password() { |
| 270 web_contents()->OnPasswordInputShownOnHttp(); |
| 271 client_->VisibleSecurityStateChanged(); |
| 272 } |
| 273 |
| 274 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); } |
| 275 |
| 276 private: |
| 277 ChromeSecurityStateModelClient* client_; |
| 278 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelClientHistogramTest); |
| 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 |