| 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 "components/security_state/content/content_utils.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 "components/security_state/core/security_state_model.h" |
| 10 #include "components/security_state/security_state_model.h" | 10 #include "components/security_state/core/switches.h" |
| 11 #include "components/security_state/switches.h" | |
| 12 #include "content/public/browser/security_style_explanation.h" | 11 #include "content/public/browser/security_style_explanation.h" |
| 13 #include "content/public/browser/security_style_explanations.h" | 12 #include "content/public/browser/security_style_explanations.h" |
| 14 #include "net/cert/cert_status_flags.h" | 13 #include "net/cert/cert_status_flags.h" |
| 15 #include "net/ssl/ssl_cipher_suite_names.h" | 14 #include "net/ssl/ssl_cipher_suite_names.h" |
| 16 #include "net/ssl/ssl_connection_status_flags.h" | 15 #include "net/ssl/ssl_connection_status_flags.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 const char kHTTPBadHistogram[] = | 20 using security_state_content_utils::GetSecurityStyle; |
| 22 "Security.HTTPBad.UserWarnedAboutSensitiveInput"; | |
| 23 | 21 |
| 24 // Tests that SecurityInfo flags for subresources with certificate | 22 // Tests that SecurityInfo flags for subresources with certificate |
| 25 // errors are reflected in the SecurityStyleExplanations produced by | 23 // errors are reflected in the SecurityStyleExplanations produced by |
| 26 // ChromeSecurityStateModelClient. | 24 // GetSecurityStyle. |
| 27 TEST(ChromeSecurityStateModelClientTest, | 25 TEST(SecurityStateContentUtilsTest, GetSecurityStyleForContentWithCertErrors) { |
| 28 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 |
| 34 security_info.content_with_cert_errors_status = | 31 security_info.content_with_cert_errors_status = |
| 35 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | 32 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; |
| 36 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 33 GetSecurityStyle(security_info, &explanations); |
| 37 &explanations); | |
| 38 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | 34 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 39 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | 35 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 40 | 36 |
| 41 security_info.content_with_cert_errors_status = | 37 security_info.content_with_cert_errors_status = |
| 42 security_state::SecurityStateModel::CONTENT_STATUS_RAN; | 38 security_state::SecurityStateModel::CONTENT_STATUS_RAN; |
| 43 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 39 GetSecurityStyle(security_info, &explanations); |
| 44 &explanations); | |
| 45 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | 40 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 46 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 41 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 47 | 42 |
| 48 security_info.content_with_cert_errors_status = | 43 security_info.content_with_cert_errors_status = |
| 49 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; | 44 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; |
| 50 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 45 GetSecurityStyle(security_info, &explanations); |
| 51 &explanations); | |
| 52 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 46 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 53 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | 47 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 54 | 48 |
| 55 security_info.content_with_cert_errors_status = | 49 security_info.content_with_cert_errors_status = |
| 56 security_state::SecurityStateModel::CONTENT_STATUS_NONE; | 50 security_state::SecurityStateModel::CONTENT_STATUS_NONE; |
| 57 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 51 GetSecurityStyle(security_info, &explanations); |
| 58 &explanations); | |
| 59 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 52 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 60 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 53 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 61 } | 54 } |
| 62 | 55 |
| 63 // Tests that SecurityStyleExplanations for subresources with cert | 56 // Tests that SecurityStyleExplanations for subresources with cert |
| 64 // errors are *not* set when the main resource has major certificate | 57 // errors are *not* set when the main resource has major certificate |
| 65 // errors. If the main resource has certificate errors, it would be | 58 // errors. If the main resource has certificate errors, it would be |
| 66 // duplicative/confusing to also report subresources with cert errors. | 59 // duplicative/confusing to also report subresources with cert errors. |
| 67 TEST(ChromeSecurityStateModelClientTest, | 60 TEST(SecurityStateContentUtilsTest, |
| 68 SubresourcesAndMainResourceWithMajorCertErrors) { | 61 SubresourcesAndMainResourceWithMajorCertErrors) { |
| 69 content::SecurityStyleExplanations explanations; | 62 content::SecurityStyleExplanations explanations; |
| 70 security_state::SecurityStateModel::SecurityInfo security_info; | 63 security_state::SecurityStateModel::SecurityInfo security_info; |
| 71 security_info.cert_status = net::CERT_STATUS_DATE_INVALID; | 64 security_info.cert_status = net::CERT_STATUS_DATE_INVALID; |
| 72 security_info.scheme_is_cryptographic = true; | 65 security_info.scheme_is_cryptographic = true; |
| 73 | 66 |
| 74 security_info.content_with_cert_errors_status = | 67 security_info.content_with_cert_errors_status = |
| 75 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | 68 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; |
| 76 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 69 GetSecurityStyle(security_info, &explanations); |
| 77 &explanations); | |
| 78 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 70 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 79 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 71 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 80 | 72 |
| 81 security_info.content_with_cert_errors_status = | 73 security_info.content_with_cert_errors_status = |
| 82 security_state::SecurityStateModel::CONTENT_STATUS_RAN; | 74 security_state::SecurityStateModel::CONTENT_STATUS_RAN; |
| 83 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 75 GetSecurityStyle(security_info, &explanations); |
| 84 &explanations); | |
| 85 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 76 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 86 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 77 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 87 | 78 |
| 88 security_info.content_with_cert_errors_status = | 79 security_info.content_with_cert_errors_status = |
| 89 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; | 80 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; |
| 90 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 81 GetSecurityStyle(security_info, &explanations); |
| 91 &explanations); | |
| 92 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 82 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 93 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 83 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 94 | 84 |
| 95 security_info.content_with_cert_errors_status = | 85 security_info.content_with_cert_errors_status = |
| 96 security_state::SecurityStateModel::CONTENT_STATUS_NONE; | 86 security_state::SecurityStateModel::CONTENT_STATUS_NONE; |
| 97 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 87 GetSecurityStyle(security_info, &explanations); |
| 98 &explanations); | |
| 99 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 88 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 100 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 89 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 101 } | 90 } |
| 102 | 91 |
| 103 // Tests that SecurityStyleExplanations for subresources with cert | 92 // Tests that SecurityStyleExplanations for subresources with cert |
| 104 // errors are set when the main resource has only minor certificate | 93 // errors are set when the main resource has only minor certificate |
| 105 // errors. Minor errors on the main resource should not hide major | 94 // errors. Minor errors on the main resource should not hide major |
| 106 // errors on subresources. | 95 // errors on subresources. |
| 107 TEST(ChromeSecurityStateModelClientTest, | 96 TEST(SecurityStateContentUtilsTest, |
| 108 SubresourcesAndMainResourceWithMinorCertErrors) { | 97 SubresourcesAndMainResourceWithMinorCertErrors) { |
| 109 content::SecurityStyleExplanations explanations; | 98 content::SecurityStyleExplanations explanations; |
| 110 security_state::SecurityStateModel::SecurityInfo security_info; | 99 security_state::SecurityStateModel::SecurityInfo security_info; |
| 111 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; | 100 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; |
| 112 security_info.scheme_is_cryptographic = true; | 101 security_info.scheme_is_cryptographic = true; |
| 113 | 102 |
| 114 security_info.content_with_cert_errors_status = | 103 security_info.content_with_cert_errors_status = |
| 115 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | 104 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; |
| 116 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 105 GetSecurityStyle(security_info, &explanations); |
| 117 &explanations); | |
| 118 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | 106 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 119 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | 107 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 120 | 108 |
| 121 security_info.content_with_cert_errors_status = | 109 security_info.content_with_cert_errors_status = |
| 122 security_state::SecurityStateModel::CONTENT_STATUS_RAN; | 110 security_state::SecurityStateModel::CONTENT_STATUS_RAN; |
| 123 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 111 GetSecurityStyle(security_info, &explanations); |
| 124 &explanations); | |
| 125 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | 112 EXPECT_TRUE(explanations.ran_content_with_cert_errors); |
| 126 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 113 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 127 | 114 |
| 128 security_info.content_with_cert_errors_status = | 115 security_info.content_with_cert_errors_status = |
| 129 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; | 116 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; |
| 130 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 117 GetSecurityStyle(security_info, &explanations); |
| 131 &explanations); | |
| 132 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 118 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 133 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | 119 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); |
| 134 | 120 |
| 135 security_info.content_with_cert_errors_status = | 121 security_info.content_with_cert_errors_status = |
| 136 security_state::SecurityStateModel::CONTENT_STATUS_NONE; | 122 security_state::SecurityStateModel::CONTENT_STATUS_NONE; |
| 137 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 123 GetSecurityStyle(security_info, &explanations); |
| 138 &explanations); | |
| 139 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | 124 EXPECT_FALSE(explanations.ran_content_with_cert_errors); |
| 140 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | 125 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); |
| 141 } | 126 } |
| 142 | 127 |
| 143 bool FindSecurityStyleExplanation( | 128 bool FindSecurityStyleExplanation( |
| 144 const std::vector<content::SecurityStyleExplanation>& explanations, | 129 const std::vector<content::SecurityStyleExplanation>& explanations, |
| 145 const char* summary, | 130 const char* summary, |
| 146 content::SecurityStyleExplanation* explanation) { | 131 content::SecurityStyleExplanation* explanation) { |
| 147 for (const auto& entry : explanations) { | 132 for (const auto& entry : explanations) { |
| 148 if (entry.summary == summary) { | 133 if (entry.summary == summary) { |
| 149 *explanation = entry; | 134 *explanation = entry; |
| 150 return true; | 135 return true; |
| 151 } | 136 } |
| 152 } | 137 } |
| 153 | 138 |
| 154 return false; | 139 return false; |
| 155 } | 140 } |
| 156 | 141 |
| 157 // Test that connection explanations are formated as expected. Note the strings | 142 // Test that connection explanations are formated as expected. Note the strings |
| 158 // are not translated and so will be the same in any locale. | 143 // are not translated and so will be the same in any locale. |
| 159 TEST(ChromeSecurityStateModelClientTest, ConnectionExplanation) { | 144 TEST(SecurityStateContentUtilsTest, ConnectionExplanation) { |
| 160 // Test a modern configuration with a key exchange group. | 145 // Test a modern configuration with a key exchange group. |
| 161 security_state::SecurityStateModel::SecurityInfo security_info; | 146 security_state::SecurityStateModel::SecurityInfo security_info; |
| 162 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; | 147 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; |
| 163 security_info.scheme_is_cryptographic = true; | 148 security_info.scheme_is_cryptographic = true; |
| 164 net::SSLConnectionStatusSetCipherSuite( | 149 net::SSLConnectionStatusSetCipherSuite( |
| 165 0xcca8 /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */, | 150 0xcca8 /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */, |
| 166 &security_info.connection_status); | 151 &security_info.connection_status); |
| 167 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_2, | 152 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_2, |
| 168 &security_info.connection_status); | 153 &security_info.connection_status); |
| 169 security_info.key_exchange_group = 29; // X25519 | 154 security_info.key_exchange_group = 29; // X25519 |
| 170 | 155 |
| 171 { | 156 { |
| 172 content::SecurityStyleExplanations explanations; | 157 content::SecurityStyleExplanations explanations; |
| 173 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 158 GetSecurityStyle(security_info, &explanations); |
| 174 &explanations); | |
| 175 content::SecurityStyleExplanation explanation; | 159 content::SecurityStyleExplanation explanation; |
| 176 ASSERT_TRUE(FindSecurityStyleExplanation( | 160 ASSERT_TRUE(FindSecurityStyleExplanation( |
| 177 explanations.secure_explanations, "Secure Connection", &explanation)); | 161 explanations.secure_explanations, "Secure Connection", &explanation)); |
| 178 EXPECT_EQ( | 162 EXPECT_EQ( |
| 179 "The connection to this site is encrypted and authenticated using a " | 163 "The connection to this site is encrypted and authenticated using a " |
| 180 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA with " | 164 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA with " |
| 181 "X25519), and a strong cipher (CHACHA20_POLY1305).", | 165 "X25519), and a strong cipher (CHACHA20_POLY1305).", |
| 182 explanation.description); | 166 explanation.description); |
| 183 } | 167 } |
| 184 | 168 |
| 185 // Some older cache entries may be missing the key exchange group, despite | 169 // Some older cache entries may be missing the key exchange group, despite |
| 186 // having a cipher which should supply one. | 170 // having a cipher which should supply one. |
| 187 security_info.key_exchange_group = 0; | 171 security_info.key_exchange_group = 0; |
| 188 { | 172 { |
| 189 content::SecurityStyleExplanations explanations; | 173 content::SecurityStyleExplanations explanations; |
| 190 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 174 GetSecurityStyle(security_info, &explanations); |
| 191 &explanations); | |
| 192 content::SecurityStyleExplanation explanation; | 175 content::SecurityStyleExplanation explanation; |
| 193 ASSERT_TRUE(FindSecurityStyleExplanation( | 176 ASSERT_TRUE(FindSecurityStyleExplanation( |
| 194 explanations.secure_explanations, "Secure Connection", &explanation)); | 177 explanations.secure_explanations, "Secure Connection", &explanation)); |
| 195 EXPECT_EQ( | 178 EXPECT_EQ( |
| 196 "The connection to this site is encrypted and authenticated using a " | 179 "The connection to this site is encrypted and authenticated using a " |
| 197 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA), and a " | 180 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA), and a " |
| 198 "strong cipher (CHACHA20_POLY1305).", | 181 "strong cipher (CHACHA20_POLY1305).", |
| 199 explanation.description); | 182 explanation.description); |
| 200 } | 183 } |
| 201 | 184 |
| 202 // TLS 1.3 ciphers use the key exchange group exclusively. | 185 // TLS 1.3 ciphers use the key exchange group exclusively. |
| 203 net::SSLConnectionStatusSetCipherSuite(0x1301 /* TLS_AES_128_GCM_SHA256 */, | 186 net::SSLConnectionStatusSetCipherSuite(0x1301 /* TLS_AES_128_GCM_SHA256 */, |
| 204 &security_info.connection_status); | 187 &security_info.connection_status); |
| 205 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_3, | 188 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_3, |
| 206 &security_info.connection_status); | 189 &security_info.connection_status); |
| 207 security_info.key_exchange_group = 29; // X25519 | 190 security_info.key_exchange_group = 29; // X25519 |
| 208 { | 191 { |
| 209 content::SecurityStyleExplanations explanations; | 192 content::SecurityStyleExplanations explanations; |
| 210 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 193 GetSecurityStyle(security_info, &explanations); |
| 211 &explanations); | |
| 212 content::SecurityStyleExplanation explanation; | 194 content::SecurityStyleExplanation explanation; |
| 213 ASSERT_TRUE(FindSecurityStyleExplanation( | 195 ASSERT_TRUE(FindSecurityStyleExplanation( |
| 214 explanations.secure_explanations, "Secure Connection", &explanation)); | 196 explanations.secure_explanations, "Secure Connection", &explanation)); |
| 215 EXPECT_EQ( | 197 EXPECT_EQ( |
| 216 "The connection to this site is encrypted and authenticated using a " | 198 "The connection to this site is encrypted and authenticated using a " |
| 217 "strong protocol (TLS 1.3), a strong key exchange (X25519), and a " | 199 "strong protocol (TLS 1.3), a strong key exchange (X25519), and a " |
| 218 "strong cipher (AES_128_GCM).", | 200 "strong cipher (AES_128_GCM).", |
| 219 explanation.description); | 201 explanation.description); |
| 220 } | 202 } |
| 221 } | 203 } |
| 222 | 204 |
| 223 // Tests that a security level of HTTP_SHOW_WARNING produces a | 205 // Tests that a security level of HTTP_SHOW_WARNING produces a |
| 224 // content::SecurityStyle of UNAUTHENTICATED, with an explanation. | 206 // content::SecurityStyle of UNAUTHENTICATED, with an explanation. |
| 225 TEST(ChromeSecurityStateModelClientTest, HTTPWarning) { | 207 TEST(SecurityStateContentUtilsTest, HTTPWarning) { |
| 226 security_state::SecurityStateModel::SecurityInfo security_info; | 208 security_state::SecurityStateModel::SecurityInfo security_info; |
| 227 content::SecurityStyleExplanations explanations; | 209 content::SecurityStyleExplanations explanations; |
| 228 security_info.security_level = | 210 security_info.security_level = |
| 229 security_state::SecurityStateModel::HTTP_SHOW_WARNING; | 211 security_state::SecurityStateModel::HTTP_SHOW_WARNING; |
| 230 blink::WebSecurityStyle security_style = | 212 blink::WebSecurityStyle security_style = |
| 231 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 213 GetSecurityStyle(security_info, &explanations); |
| 232 &explanations); | |
| 233 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); | 214 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); |
| 234 EXPECT_EQ(1u, explanations.unauthenticated_explanations.size()); | 215 EXPECT_EQ(1u, explanations.unauthenticated_explanations.size()); |
| 235 } | 216 } |
| 236 | 217 |
| 237 // Tests that a security level of NONE when there is a password or | 218 // Tests that a security level of NONE when there is a password or |
| 238 // credit card field on HTTP produces a content::SecurityStyle of | 219 // credit card field on HTTP produces a content::SecurityStyle of |
| 239 // UNAUTHENTICATED, with an info explanation. | 220 // UNAUTHENTICATED, with an info explanation. |
| 240 TEST(ChromeSecurityStateModelClientTest, HTTPWarningInFuture) { | 221 TEST(SecurityStateContentUtilsTest, HTTPWarningInFuture) { |
| 241 security_state::SecurityStateModel::SecurityInfo security_info; | 222 security_state::SecurityStateModel::SecurityInfo security_info; |
| 242 content::SecurityStyleExplanations explanations; | 223 content::SecurityStyleExplanations explanations; |
| 243 security_info.security_level = security_state::SecurityStateModel::NONE; | 224 security_info.security_level = security_state::SecurityStateModel::NONE; |
| 244 security_info.displayed_private_user_data_input_on_http = true; | 225 security_info.displayed_private_user_data_input_on_http = true; |
| 245 blink::WebSecurityStyle security_style = | 226 blink::WebSecurityStyle security_style = |
| 246 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | 227 GetSecurityStyle(security_info, &explanations); |
| 247 &explanations); | |
| 248 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); | 228 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); |
| 249 EXPECT_EQ(1u, explanations.info_explanations.size()); | 229 EXPECT_EQ(1u, explanations.info_explanations.size()); |
| 250 } | 230 } |
| 251 | 231 |
| 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 | |
| 328 } // namespace | 232 } // namespace |
| OLD | NEW |