| 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 "components/security_state/content/content_utils.h" | 5 #include "components/security_state/content/content_utils.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| 11 #include "base/test/scoped_command_line.h" |
| 9 #include "components/security_state/core/security_state.h" | 12 #include "components/security_state/core/security_state.h" |
| 10 #include "components/security_state/core/switches.h" | 13 #include "components/security_state/core/switches.h" |
| 11 #include "content/public/browser/security_style_explanation.h" | 14 #include "content/public/browser/security_style_explanation.h" |
| 12 #include "content/public/browser/security_style_explanations.h" | 15 #include "content/public/browser/security_style_explanations.h" |
| 13 #include "net/cert/cert_status_flags.h" | 16 #include "net/cert/cert_status_flags.h" |
| 14 #include "net/ssl/ssl_cipher_suite_names.h" | 17 #include "net/ssl/ssl_cipher_suite_names.h" |
| 15 #include "net/ssl/ssl_connection_status_flags.h" | 18 #include "net/ssl/ssl_connection_status_flags.h" |
| 16 #include "net/test/cert_test_util.h" | 19 #include "net/test/cert_test_util.h" |
| 17 #include "net/test/test_data_directory.h" | 20 #include "net/test/test_data_directory.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 249 |
| 247 // Check that when both password and credit card fields get displayed, only | 250 // Check that when both password and credit card fields get displayed, only |
| 248 // one explanation is added. | 251 // one explanation is added. |
| 249 explanations.neutral_explanations.clear(); | 252 explanations.neutral_explanations.clear(); |
| 250 security_info.displayed_credit_card_field_on_http = true; | 253 security_info.displayed_credit_card_field_on_http = true; |
| 251 security_info.displayed_password_field_on_http = true; | 254 security_info.displayed_password_field_on_http = true; |
| 252 security_style = GetSecurityStyle(security_info, &explanations); | 255 security_style = GetSecurityStyle(security_info, &explanations); |
| 253 EXPECT_EQ(blink::kWebSecurityStyleNeutral, security_style); | 256 EXPECT_EQ(blink::kWebSecurityStyleNeutral, security_style); |
| 254 // Verify only one explanation was shown when Form Not Secure is triggered. | 257 // Verify only one explanation was shown when Form Not Secure is triggered. |
| 255 EXPECT_EQ(1u, explanations.neutral_explanations.size()); | 258 EXPECT_EQ(1u, explanations.neutral_explanations.size()); |
| 259 |
| 260 { |
| 261 // Verify that two explanations are shown when the Incognito and |
| 262 // FormNotSecure flags are both set. |
| 263 base::test::ScopedCommandLine scoped_command_line; |
| 264 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII( |
| 265 security_state::switches::kMarkHttpAs, |
| 266 security_state::switches::kMarkHttpAsNonSecureWhileIncognito); |
| 267 explanations.neutral_explanations.clear(); |
| 268 security_info.displayed_credit_card_field_on_http = true; |
| 269 security_info.is_incognito = true; |
| 270 security_style = GetSecurityStyle(security_info, &explanations); |
| 271 EXPECT_EQ(blink::kWebSecurityStyleNeutral, security_style); |
| 272 EXPECT_EQ(2u, explanations.neutral_explanations.size()); |
| 273 } |
| 256 } | 274 } |
| 257 | 275 |
| 258 // Tests that an explanation is provided if a certificate is missing a | 276 // Tests that an explanation is provided if a certificate is missing a |
| 259 // subjectAltName extension containing a domain name or IP address. | 277 // subjectAltName extension containing a domain name or IP address. |
| 260 TEST(SecurityStateContentUtilsTest, SubjectAltNameWarning) { | 278 TEST(SecurityStateContentUtilsTest, SubjectAltNameWarning) { |
| 261 security_state::SecurityInfo security_info; | 279 security_state::SecurityInfo security_info; |
| 262 security_info.cert_status = 0; | 280 security_info.cert_status = 0; |
| 263 security_info.scheme_is_cryptographic = true; | 281 security_info.scheme_is_cryptographic = true; |
| 264 | 282 |
| 265 security_info.certificate = net::ImportCertFromFile( | 283 security_info.certificate = net::ImportCertFromFile( |
| 266 net::GetTestCertsDirectory(), "salesforce_com_test.pem"); | 284 net::GetTestCertsDirectory(), "salesforce_com_test.pem"); |
| 267 ASSERT_TRUE(security_info.certificate); | 285 ASSERT_TRUE(security_info.certificate); |
| 268 | 286 |
| 269 content::SecurityStyleExplanations explanations; | 287 content::SecurityStyleExplanations explanations; |
| 270 security_info.cert_missing_subject_alt_name = true; | 288 security_info.cert_missing_subject_alt_name = true; |
| 271 GetSecurityStyle(security_info, &explanations); | 289 GetSecurityStyle(security_info, &explanations); |
| 272 // Verify that an explanation was shown for a missing subjectAltName. | 290 // Verify that an explanation was shown for a missing subjectAltName. |
| 273 EXPECT_EQ(1u, explanations.insecure_explanations.size()); | 291 EXPECT_EQ(1u, explanations.insecure_explanations.size()); |
| 274 | 292 |
| 275 explanations.insecure_explanations.clear(); | 293 explanations.insecure_explanations.clear(); |
| 276 security_info.cert_missing_subject_alt_name = false; | 294 security_info.cert_missing_subject_alt_name = false; |
| 277 GetSecurityStyle(security_info, &explanations); | 295 GetSecurityStyle(security_info, &explanations); |
| 278 // Verify that no explanation is shown if the subjectAltName is present. | 296 // Verify that no explanation is shown if the subjectAltName is present. |
| 279 EXPECT_EQ(0u, explanations.insecure_explanations.size()); | 297 EXPECT_EQ(0u, explanations.insecure_explanations.size()); |
| 280 } | 298 } |
| 281 | 299 |
| 282 } // namespace | 300 } // namespace |
| OLD | NEW |