Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: components/security_state/content/content_utils_unittest.cc

Issue 2881513003: DevTools: Convert Security Panel to Sentence case (Closed)
Patch Set: Fix hardcoded UnitTest Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/security_state/content/content_utils.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 "components/security_state/core/security_state.h" 9 #include "components/security_state/core/security_state.h"
10 #include "components/security_state/core/switches.h" 10 #include "components/security_state/core/switches.h"
11 #include "components/strings/grit/components_strings.h"
11 #include "content/public/browser/security_style_explanation.h" 12 #include "content/public/browser/security_style_explanation.h"
12 #include "content/public/browser/security_style_explanations.h" 13 #include "content/public/browser/security_style_explanations.h"
13 #include "net/cert/cert_status_flags.h" 14 #include "net/cert/cert_status_flags.h"
14 #include "net/ssl/ssl_cipher_suite_names.h" 15 #include "net/ssl/ssl_cipher_suite_names.h"
15 #include "net/ssl/ssl_connection_status_flags.h" 16 #include "net/ssl/ssl_connection_status_flags.h"
16 #include "net/test/cert_test_util.h" 17 #include "net/test/cert_test_util.h"
17 #include "net/test/test_data_directory.h" 18 #include "net/test/test_data_directory.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/l10n/l10n_util.h"
19 21
20 namespace { 22 namespace {
21 23
22 using security_state::GetSecurityStyle; 24 using security_state::GetSecurityStyle;
23 25
24 // Tests that SecurityInfo flags for subresources with certificate 26 // Tests that SecurityInfo flags for subresources with certificate
25 // errors are reflected in the SecurityStyleExplanations produced by 27 // errors are reflected in the SecurityStyleExplanations produced by
26 // GetSecurityStyle. 28 // GetSecurityStyle.
27 TEST(SecurityStateContentUtilsTest, GetSecurityStyleForContentWithCertErrors) { 29 TEST(SecurityStateContentUtilsTest, GetSecurityStyleForContentWithCertErrors) {
28 content::SecurityStyleExplanations explanations; 30 content::SecurityStyleExplanations explanations;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 security_info.contained_mixed_form = false; 146 security_info.contained_mixed_form = false;
145 security_info.mixed_content_status = security_state::CONTENT_STATUS_DISPLAYED; 147 security_info.mixed_content_status = security_state::CONTENT_STATUS_DISPLAYED;
146 GetSecurityStyle(security_info, &explanations); 148 GetSecurityStyle(security_info, &explanations);
147 EXPECT_FALSE(explanations.contained_mixed_form); 149 EXPECT_FALSE(explanations.contained_mixed_form);
148 EXPECT_TRUE(explanations.displayed_mixed_content); 150 EXPECT_TRUE(explanations.displayed_mixed_content);
149 } 151 }
150 152
151 bool FindSecurityStyleExplanation( 153 bool FindSecurityStyleExplanation(
152 const std::vector<content::SecurityStyleExplanation>& explanations, 154 const std::vector<content::SecurityStyleExplanation>& explanations,
153 const char* summary, 155 const std::string& summary,
154 content::SecurityStyleExplanation* explanation) { 156 content::SecurityStyleExplanation* explanation) {
155 for (const auto& entry : explanations) { 157 for (const auto& entry : explanations) {
156 if (entry.summary == summary) { 158 if (entry.summary == summary) {
157 *explanation = entry; 159 *explanation = entry;
158 return true; 160 return true;
159 } 161 }
160 } 162 }
161 163
162 return false; 164 return false;
163 } 165 }
(...skipping 10 matching lines...) Expand all
174 &security_info.connection_status); 176 &security_info.connection_status);
175 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_2, 177 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_2,
176 &security_info.connection_status); 178 &security_info.connection_status);
177 security_info.key_exchange_group = 29; // X25519 179 security_info.key_exchange_group = 29; // X25519
178 180
179 { 181 {
180 content::SecurityStyleExplanations explanations; 182 content::SecurityStyleExplanations explanations;
181 GetSecurityStyle(security_info, &explanations); 183 GetSecurityStyle(security_info, &explanations);
182 content::SecurityStyleExplanation explanation; 184 content::SecurityStyleExplanation explanation;
183 ASSERT_TRUE(FindSecurityStyleExplanation( 185 ASSERT_TRUE(FindSecurityStyleExplanation(
184 explanations.secure_explanations, "Secure Connection", &explanation)); 186 explanations.secure_explanations,
187 l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY), &explanation));
185 EXPECT_EQ( 188 EXPECT_EQ(
186 "The connection to this site is encrypted and authenticated using a " 189 "The connection to this site is encrypted and authenticated using a "
187 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA with " 190 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA with "
188 "X25519), and a strong cipher (CHACHA20_POLY1305).", 191 "X25519), and a strong cipher (CHACHA20_POLY1305).",
189 explanation.description); 192 explanation.description);
190 } 193 }
191 194
192 // Some older cache entries may be missing the key exchange group, despite 195 // Some older cache entries may be missing the key exchange group, despite
193 // having a cipher which should supply one. 196 // having a cipher which should supply one.
194 security_info.key_exchange_group = 0; 197 security_info.key_exchange_group = 0;
195 { 198 {
196 content::SecurityStyleExplanations explanations; 199 content::SecurityStyleExplanations explanations;
197 GetSecurityStyle(security_info, &explanations); 200 GetSecurityStyle(security_info, &explanations);
198 content::SecurityStyleExplanation explanation; 201 content::SecurityStyleExplanation explanation;
199 ASSERT_TRUE(FindSecurityStyleExplanation( 202 ASSERT_TRUE(FindSecurityStyleExplanation(
200 explanations.secure_explanations, "Secure Connection", &explanation)); 203 explanations.secure_explanations,
204 l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY), &explanation));
201 EXPECT_EQ( 205 EXPECT_EQ(
202 "The connection to this site is encrypted and authenticated using a " 206 "The connection to this site is encrypted and authenticated using a "
203 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA), and a " 207 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA), and a "
204 "strong cipher (CHACHA20_POLY1305).", 208 "strong cipher (CHACHA20_POLY1305).",
205 explanation.description); 209 explanation.description);
206 } 210 }
207 211
208 // TLS 1.3 ciphers use the key exchange group exclusively. 212 // TLS 1.3 ciphers use the key exchange group exclusively.
209 net::SSLConnectionStatusSetCipherSuite(0x1301 /* TLS_AES_128_GCM_SHA256 */, 213 net::SSLConnectionStatusSetCipherSuite(0x1301 /* TLS_AES_128_GCM_SHA256 */,
210 &security_info.connection_status); 214 &security_info.connection_status);
211 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_3, 215 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_3,
212 &security_info.connection_status); 216 &security_info.connection_status);
213 security_info.key_exchange_group = 29; // X25519 217 security_info.key_exchange_group = 29; // X25519
214 { 218 {
215 content::SecurityStyleExplanations explanations; 219 content::SecurityStyleExplanations explanations;
216 GetSecurityStyle(security_info, &explanations); 220 GetSecurityStyle(security_info, &explanations);
217 content::SecurityStyleExplanation explanation; 221 content::SecurityStyleExplanation explanation;
218 ASSERT_TRUE(FindSecurityStyleExplanation( 222 ASSERT_TRUE(FindSecurityStyleExplanation(
219 explanations.secure_explanations, "Secure Connection", &explanation)); 223 explanations.secure_explanations,
224 l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY), &explanation));
220 EXPECT_EQ( 225 EXPECT_EQ(
221 "The connection to this site is encrypted and authenticated using a " 226 "The connection to this site is encrypted and authenticated using a "
222 "strong protocol (TLS 1.3), a strong key exchange (X25519), and a " 227 "strong protocol (TLS 1.3), a strong key exchange (X25519), and a "
223 "strong cipher (AES_128_GCM).", 228 "strong cipher (AES_128_GCM).",
224 explanation.description); 229 explanation.description);
225 } 230 }
226 } 231 }
227 232
228 // Tests that a security level of HTTP_SHOW_WARNING produces 233 // Tests that a security level of HTTP_SHOW_WARNING produces
229 // blink::WebSecurityStyleNeutral and an explanation if appropriate. 234 // blink::WebSecurityStyleNeutral and an explanation if appropriate.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 EXPECT_EQ(1u, explanations.insecure_explanations.size()); 278 EXPECT_EQ(1u, explanations.insecure_explanations.size());
274 279
275 explanations.insecure_explanations.clear(); 280 explanations.insecure_explanations.clear();
276 security_info.cert_missing_subject_alt_name = false; 281 security_info.cert_missing_subject_alt_name = false;
277 GetSecurityStyle(security_info, &explanations); 282 GetSecurityStyle(security_info, &explanations);
278 // Verify that no explanation is shown if the subjectAltName is present. 283 // Verify that no explanation is shown if the subjectAltName is present.
279 EXPECT_EQ(0u, explanations.insecure_explanations.size()); 284 EXPECT_EQ(0u, explanations.insecure_explanations.size());
280 } 285 }
281 286
282 } // namespace 287 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698