| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/security_state_model.h" | 5 #include "components/security_state/core/security_state_model.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "components/security_state/security_state_model_client.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "components/security_state/switches.h" | 11 #include "components/security_state/core/switches.h" |
| 12 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
| 13 #include "net/ssl/ssl_cipher_suite_names.h" | 13 #include "net/ssl/ssl_cipher_suite_names.h" |
| 14 #include "net/ssl/ssl_connection_status_flags.h" | 14 #include "net/ssl/ssl_connection_status_flags.h" |
| 15 #include "net/test/cert_test_util.h" | 15 #include "net/test/cert_test_util.h" |
| 16 #include "net/test/test_certificate_data.h" | 16 #include "net/test/test_certificate_data.h" |
| 17 #include "net/test/test_data_directory.h" | 17 #include "net/test/test_data_directory.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace security_state { | 20 namespace security_state { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kHttpsUrl[] = "https://foo.test"; | 24 const char kHttpsUrl[] = "https://foo.test"; |
| 25 const char kHttpUrl[] = "http://foo.test"; | 25 const char kHttpUrl[] = "http://foo.test"; |
| 26 | 26 |
| 27 class TestSecurityStateModelClient : public SecurityStateModelClient { | 27 class TestSecurityStateModel { |
| 28 public: | 28 public: |
| 29 TestSecurityStateModelClient() | 29 TestSecurityStateModel() |
| 30 : url_(kHttpsUrl), | 30 : url_(kHttpsUrl), |
| 31 connection_status_(net::SSL_CONNECTION_VERSION_TLS1_2 | 31 connection_status_(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 32 << net::SSL_CONNECTION_VERSION_SHIFT), | 32 << net::SSL_CONNECTION_VERSION_SHIFT), |
| 33 cert_status_(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT), | 33 cert_status_(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT), |
| 34 displayed_mixed_content_(false), | 34 displayed_mixed_content_(false), |
| 35 ran_mixed_content_(false), | 35 ran_mixed_content_(false), |
| 36 fails_malware_check_(false), | 36 fails_malware_check_(false), |
| 37 displayed_password_field_on_http_(false), | 37 displayed_password_field_on_http_(false), |
| 38 displayed_credit_card_field_on_http_(false) { | 38 displayed_credit_card_field_on_http_(false) { |
| 39 cert_ = | 39 cert_ = |
| 40 net::ImportCertFromFile(net::GetTestCertsDirectory(), "sha1_2016.pem"); | 40 net::ImportCertFromFile(net::GetTestCertsDirectory(), "sha1_2016.pem"); |
| 41 } | 41 } |
| 42 ~TestSecurityStateModelClient() override {} | 42 virtual ~TestSecurityStateModel() {} |
| 43 | 43 |
| 44 void set_connection_status(int connection_status) { | 44 void set_connection_status(int connection_status) { |
| 45 connection_status_ = connection_status; | 45 connection_status_ = connection_status; |
| 46 } | 46 } |
| 47 void SetCipherSuite(uint16_t ciphersuite) { | 47 void SetCipherSuite(uint16_t ciphersuite) { |
| 48 net::SSLConnectionStatusSetCipherSuite(ciphersuite, &connection_status_); | 48 net::SSLConnectionStatusSetCipherSuite(ciphersuite, &connection_status_); |
| 49 } | 49 } |
| 50 void AddCertStatus(net::CertStatus cert_status) { | 50 void AddCertStatus(net::CertStatus cert_status) { |
| 51 cert_status_ |= cert_status; | 51 cert_status_ |= cert_status; |
| 52 } | 52 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 bool displayed_password_field_on_http) { | 63 bool displayed_password_field_on_http) { |
| 64 displayed_password_field_on_http_ = displayed_password_field_on_http; | 64 displayed_password_field_on_http_ = displayed_password_field_on_http; |
| 65 } | 65 } |
| 66 void set_displayed_credit_card_field_on_http( | 66 void set_displayed_credit_card_field_on_http( |
| 67 bool displayed_credit_card_field_on_http) { | 67 bool displayed_credit_card_field_on_http) { |
| 68 displayed_credit_card_field_on_http_ = displayed_credit_card_field_on_http; | 68 displayed_credit_card_field_on_http_ = displayed_credit_card_field_on_http; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void UseHttpUrl() { url_ = GURL(kHttpUrl); } | 71 void UseHttpUrl() { url_ = GURL(kHttpUrl); } |
| 72 | 72 |
| 73 // SecurityStateModelClient: | 73 std::unique_ptr<SecurityStateModel::VisibleSecurityState> |
| 74 void GetVisibleSecurityState( | 74 GetVisibleSecurityState() { |
| 75 SecurityStateModel::VisibleSecurityState* state) override { | 75 auto state = base::MakeUnique<SecurityStateModel::VisibleSecurityState>(); |
| 76 state->connection_info_initialized = true; | 76 state->connection_info_initialized = true; |
| 77 state->url = url_; | 77 state->url = url_; |
| 78 state->certificate = cert_; | 78 state->certificate = cert_; |
| 79 state->cert_status = cert_status_; | 79 state->cert_status = cert_status_; |
| 80 state->connection_status = connection_status_; | 80 state->connection_status = connection_status_; |
| 81 state->security_bits = 256; | 81 state->security_bits = 256; |
| 82 state->displayed_mixed_content = displayed_mixed_content_; | 82 state->displayed_mixed_content = displayed_mixed_content_; |
| 83 state->ran_mixed_content = ran_mixed_content_; | 83 state->ran_mixed_content = ran_mixed_content_; |
| 84 state->fails_malware_check = fails_malware_check_; | 84 state->fails_malware_check = fails_malware_check_; |
| 85 state->displayed_password_field_on_http = displayed_password_field_on_http_; | 85 state->displayed_password_field_on_http = displayed_password_field_on_http_; |
| 86 state->displayed_credit_card_field_on_http = | 86 state->displayed_credit_card_field_on_http = |
| 87 displayed_credit_card_field_on_http_; | 87 displayed_credit_card_field_on_http_; |
| 88 return state; |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool UsedPolicyInstalledCertificate() override { return false; } | 91 bool UsedPolicyInstalledCertificate() { return false; } |
| 91 | 92 |
| 92 bool IsOriginSecure(const GURL& url) override { | 93 void GetSecurityInfo(SecurityStateModel::SecurityInfo* security_info) { |
| 93 return url_ == GURL(kHttpsUrl); | 94 model_.GetSecurityInfo(security_info, GetVisibleSecurityState(), |
| 95 UsedPolicyInstalledCertificate()); |
| 94 } | 96 } |
| 95 | 97 |
| 96 private: | 98 private: |
| 99 SecurityStateModel model_; |
| 97 GURL url_; | 100 GURL url_; |
| 98 scoped_refptr<net::X509Certificate> cert_; | 101 scoped_refptr<net::X509Certificate> cert_; |
| 99 int connection_status_; | 102 int connection_status_; |
| 100 net::CertStatus cert_status_; | 103 net::CertStatus cert_status_; |
| 101 bool displayed_mixed_content_; | 104 bool displayed_mixed_content_; |
| 102 bool ran_mixed_content_; | 105 bool ran_mixed_content_; |
| 103 bool fails_malware_check_; | 106 bool fails_malware_check_; |
| 104 bool displayed_password_field_on_http_; | 107 bool displayed_password_field_on_http_; |
| 105 bool displayed_credit_card_field_on_http_; | 108 bool displayed_credit_card_field_on_http_; |
| 106 }; | 109 }; |
| 107 | 110 |
| 111 } // namespace |
| 112 |
| 108 // Tests that SHA1-signed certificates expiring in 2016 downgrade the | 113 // Tests that SHA1-signed certificates expiring in 2016 downgrade the |
| 109 // security state of the page. | 114 // security state of the page. |
| 110 TEST(SecurityStateModelTest, SHA1Warning) { | 115 TEST(SecurityStateModelTest, SHA1Warning) { |
| 111 TestSecurityStateModelClient client; | 116 TestSecurityStateModel model; |
| 112 SecurityStateModel model; | |
| 113 model.SetClient(&client); | |
| 114 SecurityStateModel::SecurityInfo security_info; | 117 SecurityStateModel::SecurityInfo security_info; |
| 115 model.GetSecurityInfo(&security_info); | 118 model.GetSecurityInfo(&security_info); |
| 116 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | 119 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, |
| 117 security_info.sha1_deprecation_status); | 120 security_info.sha1_deprecation_status); |
| 118 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 121 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); |
| 119 } | 122 } |
| 120 | 123 |
| 121 // Tests that SHA1 warnings don't interfere with the handling of mixed | 124 // Tests that SHA1 warnings don't interfere with the handling of mixed |
| 122 // content. | 125 // content. |
| 123 TEST(SecurityStateModelTest, SHA1WarningMixedContent) { | 126 TEST(SecurityStateModelTest, SHA1WarningMixedContent) { |
| 124 TestSecurityStateModelClient client; | 127 TestSecurityStateModel model; |
| 125 SecurityStateModel model; | 128 model.SetDisplayedMixedContent(true); |
| 126 model.SetClient(&client); | |
| 127 client.SetDisplayedMixedContent(true); | |
| 128 SecurityStateModel::SecurityInfo security_info1; | 129 SecurityStateModel::SecurityInfo security_info1; |
| 129 model.GetSecurityInfo(&security_info1); | 130 model.GetSecurityInfo(&security_info1); |
| 130 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | 131 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, |
| 131 security_info1.sha1_deprecation_status); | 132 security_info1.sha1_deprecation_status); |
| 132 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED, | 133 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED, |
| 133 security_info1.mixed_content_status); | 134 security_info1.mixed_content_status); |
| 134 EXPECT_EQ(SecurityStateModel::NONE, security_info1.security_level); | 135 EXPECT_EQ(SecurityStateModel::NONE, security_info1.security_level); |
| 135 | 136 |
| 136 client.SetDisplayedMixedContent(false); | 137 model.SetDisplayedMixedContent(false); |
| 137 client.SetRanMixedContent(true); | 138 model.SetRanMixedContent(true); |
| 138 SecurityStateModel::SecurityInfo security_info2; | 139 SecurityStateModel::SecurityInfo security_info2; |
| 139 model.GetSecurityInfo(&security_info2); | 140 model.GetSecurityInfo(&security_info2); |
| 140 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | 141 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, |
| 141 security_info2.sha1_deprecation_status); | 142 security_info2.sha1_deprecation_status); |
| 142 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_RAN, | 143 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_RAN, |
| 143 security_info2.mixed_content_status); | 144 security_info2.mixed_content_status); |
| 144 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info2.security_level); | 145 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info2.security_level); |
| 145 } | 146 } |
| 146 | 147 |
| 147 // Tests that SHA1 warnings don't interfere with the handling of major | 148 // Tests that SHA1 warnings don't interfere with the handling of major |
| 148 // cert errors. | 149 // cert errors. |
| 149 TEST(SecurityStateModelTest, SHA1WarningBrokenHTTPS) { | 150 TEST(SecurityStateModelTest, SHA1WarningBrokenHTTPS) { |
| 150 TestSecurityStateModelClient client; | 151 TestSecurityStateModel model; |
| 151 SecurityStateModel model; | 152 model.AddCertStatus(net::CERT_STATUS_DATE_INVALID); |
| 152 model.SetClient(&client); | |
| 153 client.AddCertStatus(net::CERT_STATUS_DATE_INVALID); | |
| 154 SecurityStateModel::SecurityInfo security_info; | 153 SecurityStateModel::SecurityInfo security_info; |
| 155 model.GetSecurityInfo(&security_info); | 154 model.GetSecurityInfo(&security_info); |
| 156 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, | 155 EXPECT_EQ(SecurityStateModel::DEPRECATED_SHA1_MINOR, |
| 157 security_info.sha1_deprecation_status); | 156 security_info.sha1_deprecation_status); |
| 158 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); | 157 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); |
| 159 } | 158 } |
| 160 | 159 |
| 161 // Tests that |security_info.is_secure_protocol_and_ciphersuite| is | 160 // Tests that |security_info.is_secure_protocol_and_ciphersuite| is |
| 162 // computed correctly. | 161 // computed correctly. |
| 163 TEST(SecurityStateModelTest, SecureProtocolAndCiphersuite) { | 162 TEST(SecurityStateModelTest, SecureProtocolAndCiphersuite) { |
| 164 TestSecurityStateModelClient client; | 163 TestSecurityStateModel model; |
| 165 SecurityStateModel model; | |
| 166 model.SetClient(&client); | |
| 167 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 164 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
| 168 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 165 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 169 const uint16_t ciphersuite = 0xc02f; | 166 const uint16_t ciphersuite = 0xc02f; |
| 170 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 167 model.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 171 << net::SSL_CONNECTION_VERSION_SHIFT); | 168 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 172 client.SetCipherSuite(ciphersuite); | 169 model.SetCipherSuite(ciphersuite); |
| 173 SecurityStateModel::SecurityInfo security_info; | 170 SecurityStateModel::SecurityInfo security_info; |
| 174 model.GetSecurityInfo(&security_info); | 171 model.GetSecurityInfo(&security_info); |
| 175 EXPECT_EQ(net::OBSOLETE_SSL_NONE, security_info.obsolete_ssl_status); | 172 EXPECT_EQ(net::OBSOLETE_SSL_NONE, security_info.obsolete_ssl_status); |
| 176 } | 173 } |
| 177 | 174 |
| 178 TEST(SecurityStateModelTest, NonsecureProtocol) { | 175 TEST(SecurityStateModelTest, NonsecureProtocol) { |
| 179 TestSecurityStateModelClient client; | 176 TestSecurityStateModel model; |
| 180 SecurityStateModel model; | |
| 181 model.SetClient(&client); | |
| 182 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 177 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
| 183 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 178 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 184 const uint16_t ciphersuite = 0xc02f; | 179 const uint16_t ciphersuite = 0xc02f; |
| 185 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_1 | 180 model.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_1 |
| 186 << net::SSL_CONNECTION_VERSION_SHIFT); | 181 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 187 client.SetCipherSuite(ciphersuite); | 182 model.SetCipherSuite(ciphersuite); |
| 188 SecurityStateModel::SecurityInfo security_info; | 183 SecurityStateModel::SecurityInfo security_info; |
| 189 model.GetSecurityInfo(&security_info); | 184 model.GetSecurityInfo(&security_info); |
| 190 EXPECT_EQ(net::OBSOLETE_SSL_MASK_PROTOCOL, security_info.obsolete_ssl_status); | 185 EXPECT_EQ(net::OBSOLETE_SSL_MASK_PROTOCOL, security_info.obsolete_ssl_status); |
| 191 } | 186 } |
| 192 | 187 |
| 193 TEST(SecurityStateModelTest, NonsecureCiphersuite) { | 188 TEST(SecurityStateModelTest, NonsecureCiphersuite) { |
| 194 TestSecurityStateModelClient client; | 189 TestSecurityStateModel model; |
| 195 SecurityStateModel model; | |
| 196 model.SetClient(&client); | |
| 197 // TLS_RSA_WITH_AES_128_CCM_8 from | 190 // TLS_RSA_WITH_AES_128_CCM_8 from |
| 198 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 191 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 199 const uint16_t ciphersuite = 0xc0a0; | 192 const uint16_t ciphersuite = 0xc0a0; |
| 200 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 193 model.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 201 << net::SSL_CONNECTION_VERSION_SHIFT); | 194 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 202 client.SetCipherSuite(ciphersuite); | 195 model.SetCipherSuite(ciphersuite); |
| 203 SecurityStateModel::SecurityInfo security_info; | 196 SecurityStateModel::SecurityInfo security_info; |
| 204 model.GetSecurityInfo(&security_info); | 197 model.GetSecurityInfo(&security_info); |
| 205 EXPECT_EQ(net::OBSOLETE_SSL_MASK_KEY_EXCHANGE | net::OBSOLETE_SSL_MASK_CIPHER, | 198 EXPECT_EQ(net::OBSOLETE_SSL_MASK_KEY_EXCHANGE | net::OBSOLETE_SSL_MASK_CIPHER, |
| 206 security_info.obsolete_ssl_status); | 199 security_info.obsolete_ssl_status); |
| 207 } | 200 } |
| 208 | 201 |
| 209 // Tests that the malware/phishing status is set, and it overrides valid HTTPS. | 202 // Tests that the malware/phishing status is set, and it overrides valid HTTPS. |
| 210 TEST(SecurityStateModelTest, MalwareOverride) { | 203 TEST(SecurityStateModelTest, MalwareOverride) { |
| 211 TestSecurityStateModelClient client; | 204 TestSecurityStateModel model; |
| 212 SecurityStateModel model; | |
| 213 model.SetClient(&client); | |
| 214 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 205 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
| 215 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 206 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
| 216 const uint16_t ciphersuite = 0xc02f; | 207 const uint16_t ciphersuite = 0xc02f; |
| 217 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 208 model.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
| 218 << net::SSL_CONNECTION_VERSION_SHIFT); | 209 << net::SSL_CONNECTION_VERSION_SHIFT); |
| 219 client.SetCipherSuite(ciphersuite); | 210 model.SetCipherSuite(ciphersuite); |
| 220 client.set_fails_malware_check(true); | 211 model.set_fails_malware_check(true); |
| 221 SecurityStateModel::SecurityInfo security_info; | 212 SecurityStateModel::SecurityInfo security_info; |
| 222 model.GetSecurityInfo(&security_info); | 213 model.GetSecurityInfo(&security_info); |
| 223 EXPECT_TRUE(security_info.fails_malware_check); | 214 EXPECT_TRUE(security_info.fails_malware_check); |
| 224 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); | 215 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); |
| 225 } | 216 } |
| 226 | 217 |
| 227 // Tests that the malware/phishing status is set, even if other connection info | 218 // Tests that the malware/phishing status is set, even if other connection info |
| 228 // is not available. | 219 // is not available. |
| 229 TEST(SecurityStateModelTest, MalwareWithoutCOnnectionState) { | 220 TEST(SecurityStateModelTest, MalwareWithoutCOnnectionState) { |
| 230 TestSecurityStateModelClient client; | 221 TestSecurityStateModel model; |
| 231 SecurityStateModel model; | 222 model.set_fails_malware_check(true); |
| 232 model.SetClient(&client); | |
| 233 client.set_fails_malware_check(true); | |
| 234 SecurityStateModel::SecurityInfo security_info; | 223 SecurityStateModel::SecurityInfo security_info; |
| 235 model.GetSecurityInfo(&security_info); | 224 model.GetSecurityInfo(&security_info); |
| 236 EXPECT_TRUE(security_info.fails_malware_check); | 225 EXPECT_TRUE(security_info.fails_malware_check); |
| 237 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); | 226 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); |
| 238 } | 227 } |
| 239 | 228 |
| 240 // Tests that password fields cause the security level to be downgraded | 229 // Tests that password fields cause the security level to be downgraded |
| 241 // to HTTP_SHOW_WARNING when the command-line switch is set. | 230 // to HTTP_SHOW_WARNING when the command-line switch is set. |
| 242 TEST(SecurityStateModelTest, PasswordFieldWarning) { | 231 TEST(SecurityStateModelTest, PasswordFieldWarning) { |
| 243 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 232 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 244 switches::kMarkHttpAs, | 233 switches::kMarkHttpAs, |
| 245 switches::kMarkHttpWithPasswordsOrCcWithChip); | 234 switches::kMarkHttpWithPasswordsOrCcWithChip); |
| 246 TestSecurityStateModelClient client; | 235 TestSecurityStateModel model; |
| 247 client.UseHttpUrl(); | 236 model.UseHttpUrl(); |
| 248 SecurityStateModel model; | 237 model.set_displayed_password_field_on_http(true); |
| 249 model.SetClient(&client); | |
| 250 client.set_displayed_password_field_on_http(true); | |
| 251 SecurityStateModel::SecurityInfo security_info; | 238 SecurityStateModel::SecurityInfo security_info; |
| 252 model.GetSecurityInfo(&security_info); | 239 model.GetSecurityInfo(&security_info); |
| 253 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); | 240 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); |
| 254 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, | 241 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, |
| 255 security_info.security_level); | 242 security_info.security_level); |
| 256 } | 243 } |
| 257 | 244 |
| 258 // Tests that credit card fields cause the security level to be downgraded | 245 // Tests that credit card fields cause the security level to be downgraded |
| 259 // to HTTP_SHOW_WARNING when the command-line switch is set. | 246 // to HTTP_SHOW_WARNING when the command-line switch is set. |
| 260 TEST(SecurityStateModelTest, CreditCardFieldWarning) { | 247 TEST(SecurityStateModelTest, CreditCardFieldWarning) { |
| 261 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 248 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 262 switches::kMarkHttpAs, | 249 switches::kMarkHttpAs, |
| 263 switches::kMarkHttpWithPasswordsOrCcWithChip); | 250 switches::kMarkHttpWithPasswordsOrCcWithChip); |
| 264 TestSecurityStateModelClient client; | 251 TestSecurityStateModel model; |
| 265 client.UseHttpUrl(); | 252 model.UseHttpUrl(); |
| 266 SecurityStateModel model; | 253 model.set_displayed_credit_card_field_on_http(true); |
| 267 model.SetClient(&client); | |
| 268 client.set_displayed_credit_card_field_on_http(true); | |
| 269 SecurityStateModel::SecurityInfo security_info; | 254 SecurityStateModel::SecurityInfo security_info; |
| 270 model.GetSecurityInfo(&security_info); | 255 model.GetSecurityInfo(&security_info); |
| 271 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); | 256 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); |
| 272 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, | 257 EXPECT_EQ(SecurityStateModel::HTTP_SHOW_WARNING, |
| 273 security_info.security_level); | 258 security_info.security_level); |
| 274 } | 259 } |
| 275 | 260 |
| 276 // Tests that neither password nor credit fields cause the security | 261 // Tests that neither password nor credit fields cause the security |
| 277 // level to be downgraded to HTTP_SHOW_WARNING when the command-line switch | 262 // level to be downgraded to HTTP_SHOW_WARNING when the command-line switch |
| 278 // is NOT set. | 263 // is NOT set. |
| 279 TEST(SecurityStateModelTest, HttpWarningNotSetWithoutSwitch) { | 264 TEST(SecurityStateModelTest, HttpWarningNotSetWithoutSwitch) { |
| 280 TestSecurityStateModelClient client; | 265 TestSecurityStateModel model; |
| 281 client.UseHttpUrl(); | 266 model.UseHttpUrl(); |
| 282 SecurityStateModel model; | 267 model.set_displayed_password_field_on_http(true); |
| 283 model.SetClient(&client); | 268 model.set_displayed_credit_card_field_on_http(true); |
| 284 client.set_displayed_password_field_on_http(true); | |
| 285 client.set_displayed_credit_card_field_on_http(true); | |
| 286 SecurityStateModel::SecurityInfo security_info; | 269 SecurityStateModel::SecurityInfo security_info; |
| 287 model.GetSecurityInfo(&security_info); | 270 model.GetSecurityInfo(&security_info); |
| 288 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); | 271 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); |
| 289 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 272 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); |
| 290 } | 273 } |
| 291 | 274 |
| 292 // Tests that |displayed_private_user_data_input_on_http| is not set | 275 // Tests that |displayed_private_user_data_input_on_http| is not set |
| 293 // when the corresponding VisibleSecurityState flags are not set. | 276 // when the corresponding VisibleSecurityState flags are not set. |
| 294 TEST(SecurityStateModelTest, PrivateUserDataNotSet) { | 277 TEST(SecurityStateModelTest, PrivateUserDataNotSet) { |
| 295 TestSecurityStateModelClient client; | 278 TestSecurityStateModel model; |
| 296 client.UseHttpUrl(); | 279 model.UseHttpUrl(); |
| 297 SecurityStateModel model; | |
| 298 model.SetClient(&client); | |
| 299 SecurityStateModel::SecurityInfo security_info; | 280 SecurityStateModel::SecurityInfo security_info; |
| 300 model.GetSecurityInfo(&security_info); | 281 model.GetSecurityInfo(&security_info); |
| 301 EXPECT_FALSE(security_info.displayed_private_user_data_input_on_http); | 282 EXPECT_FALSE(security_info.displayed_private_user_data_input_on_http); |
| 302 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 283 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); |
| 303 } | 284 } |
| 304 | 285 |
| 305 } // namespace | |
| 306 | |
| 307 } // namespace security_state | 286 } // namespace security_state |
| OLD | NEW |