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 "chrome/browser/ssl/security_state_model.h" | 5 #include "chrome/browser/ssl/chrome_security_state_model_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "chrome/browser/ssl/cert_verifier_browser_test.h" | 12 #include "chrome/browser/ssl/cert_verifier_browser_test.h" |
13 #include "chrome/browser/ssl/ssl_blocking_page.h" | 13 #include "chrome/browser/ssl/ssl_blocking_page.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 21 matching lines...) Expand all Loading... |
37 #include "net/test/url_request/url_request_failed_job.h" | 37 #include "net/test/url_request/url_request_failed_job.h" |
38 #include "net/url_request/url_request_filter.h" | 38 #include "net/url_request/url_request_filter.h" |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 const base::FilePath::CharType kDocRoot[] = | 42 const base::FilePath::CharType kDocRoot[] = |
43 FILE_PATH_LITERAL("chrome/test/data"); | 43 FILE_PATH_LITERAL("chrome/test/data"); |
44 | 44 |
45 void CheckSecurityInfoForSecure( | 45 void CheckSecurityInfoForSecure( |
46 content::WebContents* contents, | 46 content::WebContents* contents, |
47 SecurityStateModel::SecurityLevel expect_security_level, | 47 security_state::SecurityLevel expect_security_level, |
48 SecurityStateModel::SHA1DeprecationStatus expect_sha1_status, | 48 security_state::SHA1DeprecationStatus expect_sha1_status, |
49 SecurityStateModel::MixedContentStatus expect_mixed_content_status, | 49 security_state::MixedContentStatus expect_mixed_content_status, |
50 bool expect_cert_error) { | 50 bool expect_cert_error) { |
51 ASSERT_TRUE(contents); | 51 ASSERT_TRUE(contents); |
52 | 52 |
53 SecurityStateModel* model = SecurityStateModel::FromWebContents(contents); | 53 ChromeSecurityStateModelDelegate* model_delegate = |
54 ASSERT_TRUE(model); | 54 ChromeSecurityStateModelDelegate::FromWebContents(contents); |
55 const SecurityStateModel::SecurityInfo& security_info = | 55 ASSERT_TRUE(model_delegate); |
56 model->GetSecurityInfo(); | 56 const security_state::SecurityInfo& security_info = |
| 57 model_delegate->GetSecurityInfo(); |
57 EXPECT_EQ(expect_security_level, security_info.security_level); | 58 EXPECT_EQ(expect_security_level, security_info.security_level); |
58 EXPECT_EQ(expect_sha1_status, security_info.sha1_deprecation_status); | 59 EXPECT_EQ(expect_sha1_status, security_info.sha1_deprecation_status); |
59 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status); | 60 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status); |
60 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); | 61 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); |
61 EXPECT_TRUE(security_info.scheme_is_cryptographic); | 62 EXPECT_TRUE(security_info.scheme_is_cryptographic); |
62 EXPECT_EQ(expect_cert_error, | 63 EXPECT_EQ(expect_cert_error, |
63 net::IsCertStatusError(security_info.cert_status)); | 64 net::IsCertStatusError(security_info.cert_status)); |
64 EXPECT_GT(security_info.security_bits, 0); | 65 EXPECT_GT(security_info.security_bits, 0); |
65 | 66 |
66 content::CertStore* cert_store = content::CertStore::GetInstance(); | 67 content::CertStore* cert_store = content::CertStore::GetInstance(); |
67 scoped_refptr<net::X509Certificate> cert; | 68 scoped_refptr<net::X509Certificate> cert; |
68 EXPECT_TRUE(cert_store->RetrieveCert(security_info.cert_id, &cert)); | 69 EXPECT_TRUE(cert_store->RetrieveCert(security_info.cert_id, &cert)); |
69 } | 70 } |
70 | 71 |
71 void CheckSecurityInfoForNonSecure(content::WebContents* contents) { | 72 void CheckSecurityInfoForNonSecure(content::WebContents* contents) { |
72 ASSERT_TRUE(contents); | 73 ASSERT_TRUE(contents); |
73 | 74 |
74 SecurityStateModel* model = SecurityStateModel::FromWebContents(contents); | 75 ChromeSecurityStateModelDelegate* model_delegate = |
75 ASSERT_TRUE(model); | 76 ChromeSecurityStateModelDelegate::FromWebContents(contents); |
76 const SecurityStateModel::SecurityInfo& security_info = | 77 ASSERT_TRUE(model_delegate); |
77 model->GetSecurityInfo(); | 78 const security_state::SecurityInfo& security_info = |
78 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 79 model_delegate->GetSecurityInfo(); |
79 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, | 80 EXPECT_EQ(security_state::NONE, security_info.security_level); |
| 81 EXPECT_EQ(security_state::NO_DEPRECATED_SHA1, |
80 security_info.sha1_deprecation_status); | 82 security_info.sha1_deprecation_status); |
81 EXPECT_EQ(SecurityStateModel::NO_MIXED_CONTENT, | 83 EXPECT_EQ(security_state::NO_MIXED_CONTENT, |
82 security_info.mixed_content_status); | 84 security_info.mixed_content_status); |
83 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); | 85 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); |
84 EXPECT_FALSE(security_info.scheme_is_cryptographic); | 86 EXPECT_FALSE(security_info.scheme_is_cryptographic); |
85 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); | 87 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); |
86 EXPECT_EQ(-1, security_info.security_bits); | 88 EXPECT_EQ(-1, security_info.security_bits); |
87 EXPECT_EQ(0, security_info.cert_id); | 89 EXPECT_EQ(0, security_info.cert_id); |
88 } | 90 } |
89 | 91 |
90 class SecurityStateModelTest : public CertVerifierBrowserTest { | 92 class ChromeSecurityStateModelDelegateTest : public CertVerifierBrowserTest { |
91 public: | 93 public: |
92 SecurityStateModelTest() | 94 ChromeSecurityStateModelDelegateTest() |
93 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { | 95 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { |
94 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); | 96 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); |
95 } | 97 } |
96 | 98 |
97 void SetUpCommandLine(base::CommandLine* command_line) override { | 99 void SetUpCommandLine(base::CommandLine* command_line) override { |
98 // Browser will both run and display insecure content. | 100 // Browser will both run and display insecure content. |
99 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); | 101 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); |
100 } | 102 } |
101 | 103 |
102 void ProceedThroughInterstitial(content::WebContents* tab) { | 104 void ProceedThroughInterstitial(content::WebContents* tab) { |
(...skipping 28 matching lines...) Expand all Loading... |
131 verify_result.verified_cert = cert; | 133 verify_result.verified_cert = cert; |
132 verify_result.cert_status = cert_status; | 134 verify_result.cert_status = cert_status; |
133 | 135 |
134 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, | 136 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, |
135 net_result); | 137 net_result); |
136 } | 138 } |
137 | 139 |
138 net::EmbeddedTestServer https_server_; | 140 net::EmbeddedTestServer https_server_; |
139 | 141 |
140 private: | 142 private: |
141 DISALLOW_COPY_AND_ASSIGN(SecurityStateModelTest); | 143 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelDelegateTest); |
142 }; | 144 }; |
143 | 145 |
144 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, HttpPage) { | 146 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, HttpPage) { |
145 ASSERT_TRUE(embedded_test_server()->Start()); | 147 ASSERT_TRUE(embedded_test_server()->Start()); |
146 ui_test_utils::NavigateToURL( | 148 ui_test_utils::NavigateToURL( |
147 browser(), embedded_test_server()->GetURL("/ssl/google.html")); | 149 browser(), embedded_test_server()->GetURL("/ssl/google.html")); |
148 content::WebContents* contents = | 150 content::WebContents* contents = |
149 browser()->tab_strip_model()->GetActiveWebContents(); | 151 browser()->tab_strip_model()->GetActiveWebContents(); |
150 ASSERT_TRUE(contents); | 152 ASSERT_TRUE(contents); |
151 | 153 |
152 SecurityStateModel* model = SecurityStateModel::FromWebContents(contents); | 154 ChromeSecurityStateModelDelegate* model_delegate = |
153 ASSERT_TRUE(model); | 155 ChromeSecurityStateModelDelegate::FromWebContents(contents); |
154 const SecurityStateModel::SecurityInfo& security_info = | 156 ASSERT_TRUE(model_delegate); |
155 model->GetSecurityInfo(); | 157 const security_state::SecurityInfo& security_info = |
156 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 158 model_delegate->GetSecurityInfo(); |
157 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, | 159 EXPECT_EQ(security_state::NONE, security_info.security_level); |
| 160 EXPECT_EQ(security_state::NO_DEPRECATED_SHA1, |
158 security_info.sha1_deprecation_status); | 161 security_info.sha1_deprecation_status); |
159 EXPECT_EQ(SecurityStateModel::NO_MIXED_CONTENT, | 162 EXPECT_EQ(security_state::NO_MIXED_CONTENT, |
160 security_info.mixed_content_status); | 163 security_info.mixed_content_status); |
161 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); | 164 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); |
162 EXPECT_FALSE(security_info.scheme_is_cryptographic); | 165 EXPECT_FALSE(security_info.scheme_is_cryptographic); |
163 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); | 166 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); |
164 EXPECT_EQ(0, security_info.cert_id); | 167 EXPECT_EQ(0, security_info.cert_id); |
165 EXPECT_EQ(-1, security_info.security_bits); | 168 EXPECT_EQ(-1, security_info.security_bits); |
166 EXPECT_EQ(0, security_info.connection_status); | 169 EXPECT_EQ(0, security_info.connection_status); |
167 } | 170 } |
168 | 171 |
169 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, HttpsPage) { | 172 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, HttpsPage) { |
170 ASSERT_TRUE(https_server_.Start()); | 173 ASSERT_TRUE(https_server_.Start()); |
171 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 174 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
172 | 175 |
173 ui_test_utils::NavigateToURL(browser(), | 176 ui_test_utils::NavigateToURL(browser(), |
174 https_server_.GetURL("/ssl/google.html")); | 177 https_server_.GetURL("/ssl/google.html")); |
175 CheckSecurityInfoForSecure( | 178 CheckSecurityInfoForSecure( |
176 browser()->tab_strip_model()->GetActiveWebContents(), | 179 browser()->tab_strip_model()->GetActiveWebContents(), |
177 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 180 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, |
178 SecurityStateModel::NO_MIXED_CONTENT, | 181 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
179 false /* expect cert status error */); | |
180 } | 182 } |
181 | 183 |
182 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, SHA1Broken) { | 184 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, SHA1Broken) { |
183 ASSERT_TRUE(https_server_.Start()); | 185 ASSERT_TRUE(https_server_.Start()); |
184 // The test server uses a long-lived cert by default, so a SHA1 | 186 // The test server uses a long-lived cert by default, so a SHA1 |
185 // signature in it will register as a "broken" condition rather than | 187 // signature in it will register as a "broken" condition rather than |
186 // "warning". | 188 // "warning". |
187 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, | 189 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, |
188 net::OK); | 190 net::OK); |
189 | 191 |
190 ui_test_utils::NavigateToURL(browser(), | 192 ui_test_utils::NavigateToURL(browser(), |
191 https_server_.GetURL("/ssl/google.html")); | 193 https_server_.GetURL("/ssl/google.html")); |
192 CheckSecurityInfoForSecure( | 194 CheckSecurityInfoForSecure( |
193 browser()->tab_strip_model()->GetActiveWebContents(), | 195 browser()->tab_strip_model()->GetActiveWebContents(), |
194 SecurityStateModel::SECURITY_ERROR, | 196 security_state::SECURITY_ERROR, security_state::DEPRECATED_SHA1_MAJOR, |
195 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 197 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
196 SecurityStateModel::NO_MIXED_CONTENT, | |
197 false /* expect cert status error */); | |
198 } | 198 } |
199 | 199 |
200 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, MixedContent) { | 200 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, MixedContent) { |
201 ASSERT_TRUE(embedded_test_server()->Start()); | 201 ASSERT_TRUE(embedded_test_server()->Start()); |
202 ASSERT_TRUE(https_server_.Start()); | 202 ASSERT_TRUE(https_server_.Start()); |
203 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 203 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
204 | 204 |
205 // Navigate to an HTTPS page that displays mixed content. | 205 // Navigate to an HTTPS page that displays mixed content. |
206 std::string replacement_path; | 206 std::string replacement_path; |
207 GetFilePathWithHostAndPortReplacement( | 207 GetFilePathWithHostAndPortReplacement( |
208 "/ssl/page_displays_insecure_content.html", | 208 "/ssl/page_displays_insecure_content.html", |
209 embedded_test_server()->host_port_pair(), &replacement_path); | 209 embedded_test_server()->host_port_pair(), &replacement_path); |
210 ui_test_utils::NavigateToURL(browser(), | 210 ui_test_utils::NavigateToURL(browser(), |
211 https_server_.GetURL(replacement_path)); | 211 https_server_.GetURL(replacement_path)); |
212 CheckSecurityInfoForSecure( | 212 CheckSecurityInfoForSecure( |
213 browser()->tab_strip_model()->GetActiveWebContents(), | 213 browser()->tab_strip_model()->GetActiveWebContents(), |
214 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, | 214 security_state::NONE, security_state::NO_DEPRECATED_SHA1, |
215 SecurityStateModel::DISPLAYED_MIXED_CONTENT, | 215 security_state::DISPLAYED_MIXED_CONTENT, |
216 false /* expect cert status error */); | 216 false /* expect cert status error */); |
217 | 217 |
218 // Navigate to an HTTPS page that displays mixed content dynamically. | 218 // Navigate to an HTTPS page that displays mixed content dynamically. |
219 GetFilePathWithHostAndPortReplacement( | 219 GetFilePathWithHostAndPortReplacement( |
220 "/ssl/page_with_dynamic_insecure_content.html", | 220 "/ssl/page_with_dynamic_insecure_content.html", |
221 embedded_test_server()->host_port_pair(), &replacement_path); | 221 embedded_test_server()->host_port_pair(), &replacement_path); |
222 ui_test_utils::NavigateToURL(browser(), | 222 ui_test_utils::NavigateToURL(browser(), |
223 https_server_.GetURL(replacement_path)); | 223 https_server_.GetURL(replacement_path)); |
224 CheckSecurityInfoForSecure( | 224 CheckSecurityInfoForSecure( |
225 browser()->tab_strip_model()->GetActiveWebContents(), | 225 browser()->tab_strip_model()->GetActiveWebContents(), |
226 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 226 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, |
227 SecurityStateModel::NO_MIXED_CONTENT, | 227 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
228 false /* expect cert status error */); | |
229 // Load the insecure image. | 228 // Load the insecure image. |
230 bool js_result = false; | 229 bool js_result = false; |
231 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 230 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
232 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", | 231 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", |
233 &js_result)); | 232 &js_result)); |
234 EXPECT_TRUE(js_result); | 233 EXPECT_TRUE(js_result); |
235 CheckSecurityInfoForSecure( | 234 CheckSecurityInfoForSecure( |
236 browser()->tab_strip_model()->GetActiveWebContents(), | 235 browser()->tab_strip_model()->GetActiveWebContents(), |
237 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, | 236 security_state::NONE, security_state::NO_DEPRECATED_SHA1, |
238 SecurityStateModel::DISPLAYED_MIXED_CONTENT, | 237 security_state::DISPLAYED_MIXED_CONTENT, |
239 false /* expect cert status error */); | 238 false /* expect cert status error */); |
240 | 239 |
241 // Navigate to an HTTPS page that runs mixed content. | 240 // Navigate to an HTTPS page that runs mixed content. |
242 GetFilePathWithHostAndPortReplacement( | 241 GetFilePathWithHostAndPortReplacement( |
243 "/ssl/page_runs_insecure_content.html", | 242 "/ssl/page_runs_insecure_content.html", |
244 embedded_test_server()->host_port_pair(), &replacement_path); | 243 embedded_test_server()->host_port_pair(), &replacement_path); |
245 ui_test_utils::NavigateToURL(browser(), | 244 ui_test_utils::NavigateToURL(browser(), |
246 https_server_.GetURL(replacement_path)); | 245 https_server_.GetURL(replacement_path)); |
247 CheckSecurityInfoForSecure( | 246 CheckSecurityInfoForSecure( |
248 browser()->tab_strip_model()->GetActiveWebContents(), | 247 browser()->tab_strip_model()->GetActiveWebContents(), |
249 SecurityStateModel::SECURITY_ERROR, | 248 security_state::SECURITY_ERROR, security_state::NO_DEPRECATED_SHA1, |
250 SecurityStateModel::NO_DEPRECATED_SHA1, | 249 security_state::RAN_MIXED_CONTENT, false /* expect cert status error */); |
251 SecurityStateModel::RAN_MIXED_CONTENT, | |
252 false /* expect cert status error */); | |
253 | 250 |
254 // Navigate to an HTTPS page that runs and displays mixed content. | 251 // Navigate to an HTTPS page that runs and displays mixed content. |
255 GetFilePathWithHostAndPortReplacement( | 252 GetFilePathWithHostAndPortReplacement( |
256 "/ssl/page_runs_and_displays_insecure_content.html", | 253 "/ssl/page_runs_and_displays_insecure_content.html", |
257 embedded_test_server()->host_port_pair(), &replacement_path); | 254 embedded_test_server()->host_port_pair(), &replacement_path); |
258 ui_test_utils::NavigateToURL(browser(), | 255 ui_test_utils::NavigateToURL(browser(), |
259 https_server_.GetURL(replacement_path)); | 256 https_server_.GetURL(replacement_path)); |
260 CheckSecurityInfoForSecure( | 257 CheckSecurityInfoForSecure( |
261 browser()->tab_strip_model()->GetActiveWebContents(), | 258 browser()->tab_strip_model()->GetActiveWebContents(), |
262 SecurityStateModel::SECURITY_ERROR, | 259 security_state::SECURITY_ERROR, security_state::NO_DEPRECATED_SHA1, |
263 SecurityStateModel::NO_DEPRECATED_SHA1, | 260 security_state::RAN_AND_DISPLAYED_MIXED_CONTENT, |
264 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, | |
265 false /* expect cert status error */); | 261 false /* expect cert status error */); |
266 | 262 |
267 // Navigate to an HTTPS page that runs mixed content in an iframe. | 263 // Navigate to an HTTPS page that runs mixed content in an iframe. |
268 net::HostPortPair host_port_pair = | 264 net::HostPortPair host_port_pair = |
269 net::HostPortPair::FromURL(https_server_.GetURL("/")); | 265 net::HostPortPair::FromURL(https_server_.GetURL("/")); |
270 host_port_pair.set_host("different-host.test"); | 266 host_port_pair.set_host("different-host.test"); |
271 host_resolver()->AddRule("different-host.test", | 267 host_resolver()->AddRule("different-host.test", |
272 https_server_.GetURL("/").host()); | 268 https_server_.GetURL("/").host()); |
273 host_resolver()->AddRule("different-http-host.test", | 269 host_resolver()->AddRule("different-http-host.test", |
274 embedded_test_server()->GetURL("/").host()); | 270 embedded_test_server()->GetURL("/").host()); |
275 GetFilePathWithHostAndPortReplacement( | 271 GetFilePathWithHostAndPortReplacement( |
276 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, | 272 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, |
277 &replacement_path); | 273 &replacement_path); |
278 ui_test_utils::NavigateToURL(browser(), | 274 ui_test_utils::NavigateToURL(browser(), |
279 https_server_.GetURL(replacement_path)); | 275 https_server_.GetURL(replacement_path)); |
280 CheckSecurityInfoForSecure( | 276 CheckSecurityInfoForSecure( |
281 browser()->tab_strip_model()->GetActiveWebContents(), | 277 browser()->tab_strip_model()->GetActiveWebContents(), |
282 SecurityStateModel::SECURITY_ERROR, | 278 security_state::SECURITY_ERROR, security_state::NO_DEPRECATED_SHA1, |
283 SecurityStateModel::NO_DEPRECATED_SHA1, | 279 security_state::RAN_MIXED_CONTENT, false /* expect cert status error */); |
284 SecurityStateModel::RAN_MIXED_CONTENT, | |
285 false /* expect cert status error */); | |
286 } | 280 } |
287 | 281 |
288 // Same as the test above but with a long-lived SHA1 cert. | 282 // Same as the test above but with a long-lived SHA1 cert. |
289 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, MixedContentWithBrokenSHA1) { | 283 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, |
| 284 MixedContentWithBrokenSHA1) { |
290 ASSERT_TRUE(embedded_test_server()->Start()); | 285 ASSERT_TRUE(embedded_test_server()->Start()); |
291 ASSERT_TRUE(https_server_.Start()); | 286 ASSERT_TRUE(https_server_.Start()); |
292 // The test server uses a long-lived cert by default, so a SHA1 | 287 // The test server uses a long-lived cert by default, so a SHA1 |
293 // signature in it will register as a "broken" condition rather than | 288 // signature in it will register as a "broken" condition rather than |
294 // "warning". | 289 // "warning". |
295 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, | 290 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, |
296 net::OK); | 291 net::OK); |
297 | 292 |
298 // Navigate to an HTTPS page that displays mixed content. | 293 // Navigate to an HTTPS page that displays mixed content. |
299 std::string replacement_path; | 294 std::string replacement_path; |
300 GetFilePathWithHostAndPortReplacement( | 295 GetFilePathWithHostAndPortReplacement( |
301 "/ssl/page_displays_insecure_content.html", | 296 "/ssl/page_displays_insecure_content.html", |
302 embedded_test_server()->host_port_pair(), &replacement_path); | 297 embedded_test_server()->host_port_pair(), &replacement_path); |
303 ui_test_utils::NavigateToURL(browser(), | 298 ui_test_utils::NavigateToURL(browser(), |
304 https_server_.GetURL(replacement_path)); | 299 https_server_.GetURL(replacement_path)); |
305 CheckSecurityInfoForSecure( | 300 CheckSecurityInfoForSecure( |
306 browser()->tab_strip_model()->GetActiveWebContents(), | 301 browser()->tab_strip_model()->GetActiveWebContents(), |
307 SecurityStateModel::SECURITY_ERROR, | 302 security_state::SECURITY_ERROR, security_state::DEPRECATED_SHA1_MAJOR, |
308 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 303 security_state::DISPLAYED_MIXED_CONTENT, |
309 SecurityStateModel::DISPLAYED_MIXED_CONTENT, | |
310 false /* expect cert status error */); | 304 false /* expect cert status error */); |
311 | 305 |
312 // Navigate to an HTTPS page that displays mixed content dynamically. | 306 // Navigate to an HTTPS page that displays mixed content dynamically. |
313 GetFilePathWithHostAndPortReplacement( | 307 GetFilePathWithHostAndPortReplacement( |
314 "/ssl/page_with_dynamic_insecure_content.html", | 308 "/ssl/page_with_dynamic_insecure_content.html", |
315 embedded_test_server()->host_port_pair(), &replacement_path); | 309 embedded_test_server()->host_port_pair(), &replacement_path); |
316 ui_test_utils::NavigateToURL(browser(), | 310 ui_test_utils::NavigateToURL(browser(), |
317 https_server_.GetURL(replacement_path)); | 311 https_server_.GetURL(replacement_path)); |
318 CheckSecurityInfoForSecure( | 312 CheckSecurityInfoForSecure( |
319 browser()->tab_strip_model()->GetActiveWebContents(), | 313 browser()->tab_strip_model()->GetActiveWebContents(), |
320 SecurityStateModel::SECURITY_ERROR, | 314 security_state::SECURITY_ERROR, security_state::DEPRECATED_SHA1_MAJOR, |
321 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 315 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
322 SecurityStateModel::NO_MIXED_CONTENT, | |
323 false /* expect cert status error */); | |
324 // Load the insecure image. | 316 // Load the insecure image. |
325 bool js_result = false; | 317 bool js_result = false; |
326 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 318 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
327 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", | 319 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", |
328 &js_result)); | 320 &js_result)); |
329 EXPECT_TRUE(js_result); | 321 EXPECT_TRUE(js_result); |
330 CheckSecurityInfoForSecure( | 322 CheckSecurityInfoForSecure( |
331 browser()->tab_strip_model()->GetActiveWebContents(), | 323 browser()->tab_strip_model()->GetActiveWebContents(), |
332 SecurityStateModel::SECURITY_ERROR, | 324 security_state::SECURITY_ERROR, security_state::DEPRECATED_SHA1_MAJOR, |
333 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 325 security_state::DISPLAYED_MIXED_CONTENT, |
334 SecurityStateModel::DISPLAYED_MIXED_CONTENT, | |
335 false /* expect cert status error */); | 326 false /* expect cert status error */); |
336 | 327 |
337 // Navigate to an HTTPS page that runs mixed content. | 328 // Navigate to an HTTPS page that runs mixed content. |
338 GetFilePathWithHostAndPortReplacement( | 329 GetFilePathWithHostAndPortReplacement( |
339 "/ssl/page_runs_insecure_content.html", | 330 "/ssl/page_runs_insecure_content.html", |
340 embedded_test_server()->host_port_pair(), &replacement_path); | 331 embedded_test_server()->host_port_pair(), &replacement_path); |
341 ui_test_utils::NavigateToURL(browser(), | 332 ui_test_utils::NavigateToURL(browser(), |
342 https_server_.GetURL(replacement_path)); | 333 https_server_.GetURL(replacement_path)); |
343 CheckSecurityInfoForSecure( | 334 CheckSecurityInfoForSecure( |
344 browser()->tab_strip_model()->GetActiveWebContents(), | 335 browser()->tab_strip_model()->GetActiveWebContents(), |
345 SecurityStateModel::SECURITY_ERROR, | 336 security_state::SECURITY_ERROR, security_state::DEPRECATED_SHA1_MAJOR, |
346 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 337 security_state::RAN_MIXED_CONTENT, false /* expect cert status error */); |
347 SecurityStateModel::RAN_MIXED_CONTENT, | |
348 false /* expect cert status error */); | |
349 | 338 |
350 // Navigate to an HTTPS page that runs and displays mixed content. | 339 // Navigate to an HTTPS page that runs and displays mixed content. |
351 GetFilePathWithHostAndPortReplacement( | 340 GetFilePathWithHostAndPortReplacement( |
352 "/ssl/page_runs_and_displays_insecure_content.html", | 341 "/ssl/page_runs_and_displays_insecure_content.html", |
353 embedded_test_server()->host_port_pair(), &replacement_path); | 342 embedded_test_server()->host_port_pair(), &replacement_path); |
354 ui_test_utils::NavigateToURL(browser(), | 343 ui_test_utils::NavigateToURL(browser(), |
355 https_server_.GetURL(replacement_path)); | 344 https_server_.GetURL(replacement_path)); |
356 CheckSecurityInfoForSecure( | 345 CheckSecurityInfoForSecure( |
357 browser()->tab_strip_model()->GetActiveWebContents(), | 346 browser()->tab_strip_model()->GetActiveWebContents(), |
358 SecurityStateModel::SECURITY_ERROR, | 347 security_state::SECURITY_ERROR, security_state::DEPRECATED_SHA1_MAJOR, |
359 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 348 security_state::RAN_AND_DISPLAYED_MIXED_CONTENT, |
360 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, | |
361 false /* expect cert status error */); | 349 false /* expect cert status error */); |
362 } | 350 } |
363 | 351 |
364 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, BrokenHTTPS) { | 352 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, BrokenHTTPS) { |
365 ASSERT_TRUE(embedded_test_server()->Start()); | 353 ASSERT_TRUE(embedded_test_server()->Start()); |
366 ASSERT_TRUE(https_server_.Start()); | 354 ASSERT_TRUE(https_server_.Start()); |
367 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, | 355 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, |
368 net::ERR_CERT_DATE_INVALID); | 356 net::ERR_CERT_DATE_INVALID); |
369 | 357 |
370 ui_test_utils::NavigateToURL(browser(), | 358 ui_test_utils::NavigateToURL(browser(), |
371 https_server_.GetURL("/ssl/google.html")); | 359 https_server_.GetURL("/ssl/google.html")); |
372 CheckSecurityInfoForSecure( | 360 CheckSecurityInfoForSecure( |
373 browser()->tab_strip_model()->GetActiveWebContents(), | 361 browser()->tab_strip_model()->GetActiveWebContents(), |
374 SecurityStateModel::SECURITY_ERROR, | 362 security_state::SECURITY_ERROR, security_state::NO_DEPRECATED_SHA1, |
375 SecurityStateModel::NO_DEPRECATED_SHA1, | 363 security_state::NO_MIXED_CONTENT, true /* expect cert status error */); |
376 SecurityStateModel::NO_MIXED_CONTENT, | |
377 true /* expect cert status error */); | |
378 | 364 |
379 ProceedThroughInterstitial( | 365 ProceedThroughInterstitial( |
380 browser()->tab_strip_model()->GetActiveWebContents()); | 366 browser()->tab_strip_model()->GetActiveWebContents()); |
381 | 367 |
382 CheckSecurityInfoForSecure( | 368 CheckSecurityInfoForSecure( |
383 browser()->tab_strip_model()->GetActiveWebContents(), | 369 browser()->tab_strip_model()->GetActiveWebContents(), |
384 SecurityStateModel::SECURITY_ERROR, | 370 security_state::SECURITY_ERROR, security_state::NO_DEPRECATED_SHA1, |
385 SecurityStateModel::NO_DEPRECATED_SHA1, | 371 security_state::NO_MIXED_CONTENT, true /* expect cert status error */); |
386 SecurityStateModel::NO_MIXED_CONTENT, | |
387 true /* expect cert status error */); | |
388 | 372 |
389 // Navigate to a broken HTTPS page that displays mixed content. | 373 // Navigate to a broken HTTPS page that displays mixed content. |
390 std::string replacement_path; | 374 std::string replacement_path; |
391 GetFilePathWithHostAndPortReplacement( | 375 GetFilePathWithHostAndPortReplacement( |
392 "/ssl/page_displays_insecure_content.html", | 376 "/ssl/page_displays_insecure_content.html", |
393 embedded_test_server()->host_port_pair(), &replacement_path); | 377 embedded_test_server()->host_port_pair(), &replacement_path); |
394 ui_test_utils::NavigateToURL(browser(), | 378 ui_test_utils::NavigateToURL(browser(), |
395 https_server_.GetURL(replacement_path)); | 379 https_server_.GetURL(replacement_path)); |
396 CheckSecurityInfoForSecure( | 380 CheckSecurityInfoForSecure( |
397 browser()->tab_strip_model()->GetActiveWebContents(), | 381 browser()->tab_strip_model()->GetActiveWebContents(), |
398 SecurityStateModel::SECURITY_ERROR, | 382 security_state::SECURITY_ERROR, security_state::NO_DEPRECATED_SHA1, |
399 SecurityStateModel::NO_DEPRECATED_SHA1, | 383 security_state::DISPLAYED_MIXED_CONTENT, |
400 SecurityStateModel::DISPLAYED_MIXED_CONTENT, | |
401 true /* expect cert status error */); | 384 true /* expect cert status error */); |
402 } | 385 } |
403 | 386 |
404 // Fails requests with ERR_IO_PENDING. Can be used to simulate a navigation | 387 // Fails requests with ERR_IO_PENDING. Can be used to simulate a navigation |
405 // that never stops loading. | 388 // that never stops loading. |
406 class PendingJobInterceptor : public net::URLRequestInterceptor { | 389 class PendingJobInterceptor : public net::URLRequestInterceptor { |
407 public: | 390 public: |
408 PendingJobInterceptor() {} | 391 PendingJobInterceptor() {} |
409 ~PendingJobInterceptor() override {} | 392 ~PendingJobInterceptor() override {} |
410 | 393 |
411 // URLRequestInterceptor implementation | 394 // URLRequestInterceptor implementation |
412 net::URLRequestJob* MaybeInterceptRequest( | 395 net::URLRequestJob* MaybeInterceptRequest( |
413 net::URLRequest* request, | 396 net::URLRequest* request, |
414 net::NetworkDelegate* network_delegate) const override { | 397 net::NetworkDelegate* network_delegate) const override { |
415 return new net::URLRequestFailedJob(request, network_delegate, | 398 return new net::URLRequestFailedJob(request, network_delegate, |
416 net::ERR_IO_PENDING); | 399 net::ERR_IO_PENDING); |
417 } | 400 } |
418 | 401 |
419 private: | 402 private: |
420 DISALLOW_COPY_AND_ASSIGN(PendingJobInterceptor); | 403 DISALLOW_COPY_AND_ASSIGN(PendingJobInterceptor); |
421 }; | 404 }; |
422 | 405 |
423 void InstallLoadingInterceptor(const std::string& host) { | 406 void InstallLoadingInterceptor(const std::string& host) { |
424 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 407 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
425 filter->AddHostnameInterceptor( | 408 filter->AddHostnameInterceptor( |
426 "http", host, | 409 "http", host, |
427 scoped_ptr<net::URLRequestInterceptor>(new PendingJobInterceptor())); | 410 scoped_ptr<net::URLRequestInterceptor>(new PendingJobInterceptor())); |
428 } | 411 } |
429 | 412 |
430 class SecurityStateModelLoadingTest : public SecurityStateModelTest { | 413 class SecurityStateModelLoadingTest |
| 414 : public ChromeSecurityStateModelDelegateTest { |
431 public: | 415 public: |
432 SecurityStateModelLoadingTest() : SecurityStateModelTest() {} | 416 SecurityStateModelLoadingTest() : ChromeSecurityStateModelDelegateTest() {} |
433 ~SecurityStateModelLoadingTest() override{}; | 417 ~SecurityStateModelLoadingTest() override{}; |
434 | 418 |
435 protected: | 419 protected: |
436 void SetUpOnMainThread() override { | 420 void SetUpOnMainThread() override { |
437 ASSERT_TRUE(embedded_test_server()->Start()); | 421 ASSERT_TRUE(embedded_test_server()->Start()); |
438 | 422 |
439 content::BrowserThread::PostTask( | 423 content::BrowserThread::PostTask( |
440 content::BrowserThread::IO, FROM_HERE, | 424 content::BrowserThread::IO, FROM_HERE, |
441 base::Bind(&InstallLoadingInterceptor, | 425 base::Bind(&InstallLoadingInterceptor, |
442 embedded_test_server()->GetURL("/").host())); | 426 embedded_test_server()->GetURL("/").host())); |
443 } | 427 } |
444 | 428 |
445 DISALLOW_COPY_AND_ASSIGN(SecurityStateModelLoadingTest); | 429 DISALLOW_COPY_AND_ASSIGN(SecurityStateModelLoadingTest); |
446 }; | 430 }; |
447 | 431 |
448 // Tests that navigation state changes cause the security state to be | 432 // Tests that navigation state changes cause the security state to be |
449 // updated. | 433 // updated. |
450 IN_PROC_BROWSER_TEST_F(SecurityStateModelLoadingTest, NavigationStateChanges) { | 434 IN_PROC_BROWSER_TEST_F(SecurityStateModelLoadingTest, NavigationStateChanges) { |
451 ASSERT_TRUE(https_server_.Start()); | 435 ASSERT_TRUE(https_server_.Start()); |
452 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 436 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
453 | 437 |
454 // Navigate to an HTTPS page. | 438 // Navigate to an HTTPS page. |
455 ui_test_utils::NavigateToURL(browser(), | 439 ui_test_utils::NavigateToURL(browser(), |
456 https_server_.GetURL("/ssl/google.html")); | 440 https_server_.GetURL("/ssl/google.html")); |
457 CheckSecurityInfoForSecure( | 441 CheckSecurityInfoForSecure( |
458 browser()->tab_strip_model()->GetActiveWebContents(), | 442 browser()->tab_strip_model()->GetActiveWebContents(), |
459 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 443 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, |
460 SecurityStateModel::NO_MIXED_CONTENT, | 444 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
461 false /* expect cert status error */); | |
462 | 445 |
463 // Navigate to a page that doesn't finish loading. Test that the | 446 // Navigate to a page that doesn't finish loading. Test that the |
464 // security state is neutral while the page is loading. | 447 // security state is neutral while the page is loading. |
465 browser()->OpenURL(content::OpenURLParams(embedded_test_server()->GetURL("/"), | 448 browser()->OpenURL(content::OpenURLParams(embedded_test_server()->GetURL("/"), |
466 content::Referrer(), CURRENT_TAB, | 449 content::Referrer(), CURRENT_TAB, |
467 ui::PAGE_TRANSITION_TYPED, false)); | 450 ui::PAGE_TRANSITION_TYPED, false)); |
468 CheckSecurityInfoForNonSecure( | 451 CheckSecurityInfoForNonSecure( |
469 browser()->tab_strip_model()->GetActiveWebContents()); | 452 browser()->tab_strip_model()->GetActiveWebContents()); |
470 } | 453 } |
471 | 454 |
472 // Tests that the SecurityStateModel for a WebContents is up-to-date | 455 // Tests that the SecurityStateModel for a WebContents is up-to-date |
473 // when the WebContents is inserted into a Browser's TabStripModel. | 456 // when the WebContents is inserted into a Browser's TabStripModel. |
474 IN_PROC_BROWSER_TEST_F(SecurityStateModelTest, AddedTab) { | 457 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelDelegateTest, AddedTab) { |
475 ASSERT_TRUE(https_server_.Start()); | 458 ASSERT_TRUE(https_server_.Start()); |
476 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 459 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
477 | 460 |
478 content::WebContents* tab = | 461 content::WebContents* tab = |
479 browser()->tab_strip_model()->GetActiveWebContents(); | 462 browser()->tab_strip_model()->GetActiveWebContents(); |
480 ASSERT_TRUE(tab); | 463 ASSERT_TRUE(tab); |
481 | 464 |
482 content::WebContents* new_contents = content::WebContents::Create( | 465 content::WebContents* new_contents = content::WebContents::Create( |
483 content::WebContents::CreateParams(tab->GetBrowserContext())); | 466 content::WebContents::CreateParams(tab->GetBrowserContext())); |
484 content::NavigationController& controller = new_contents->GetController(); | 467 content::NavigationController& controller = new_contents->GetController(); |
485 SecurityStateModel::CreateForWebContents(new_contents); | 468 ChromeSecurityStateModelDelegate::CreateForWebContents(new_contents); |
486 CheckSecurityInfoForNonSecure(new_contents); | 469 CheckSecurityInfoForNonSecure(new_contents); |
487 controller.LoadURL(https_server_.GetURL("/"), content::Referrer(), | 470 controller.LoadURL(https_server_.GetURL("/ssl/google.html"), |
488 ui::PAGE_TRANSITION_TYPED, std::string()); | 471 content::Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 472 std::string()); |
489 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); | 473 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); |
490 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, | 474 CheckSecurityInfoForSecure( |
491 SecurityStateModel::NO_DEPRECATED_SHA1, | 475 new_contents, security_state::SECURE, security_state::NO_DEPRECATED_SHA1, |
492 SecurityStateModel::NO_MIXED_CONTENT, | 476 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
493 false /* expect cert status error */); | |
494 | 477 |
495 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, | 478 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, |
496 TabStripModel::ADD_NONE); | 479 TabStripModel::ADD_NONE); |
497 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, | 480 CheckSecurityInfoForSecure( |
498 SecurityStateModel::NO_DEPRECATED_SHA1, | 481 new_contents, security_state::SECURE, security_state::NO_DEPRECATED_SHA1, |
499 SecurityStateModel::NO_MIXED_CONTENT, | 482 security_state::NO_MIXED_CONTENT, false /* expect cert status error */); |
500 false /* expect cert status error */); | |
501 } | 483 } |
502 | 484 |
503 } // namespace | 485 } // namespace |
OLD | NEW |