OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ssl_host_state_delegate.h" | 5 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // DidHostRunInsecureContent unit tests the expected behavior of calling | 189 // DidHostRunInsecureContent unit tests the expected behavior of calling |
190 // DidHostRunInsecureContent as well as HostRanInsecureContent to check if | 190 // DidHostRunInsecureContent as well as HostRanInsecureContent to check if |
191 // insecure content has been run and to mark it as such. | 191 // insecure content has been run and to mark it as such. |
192 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, | 192 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, |
193 DidHostRunInsecureContent) { | 193 DidHostRunInsecureContent) { |
194 content::WebContents* tab = | 194 content::WebContents* tab = |
195 browser()->tab_strip_model()->GetActiveWebContents(); | 195 browser()->tab_strip_model()->GetActiveWebContents(); |
196 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 196 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
197 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 197 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
198 | 198 |
199 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 42)); | 199 EXPECT_FALSE(state->DidHostRunInsecureContent( |
200 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 191)); | 200 "www.google.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
201 EXPECT_FALSE(state->DidHostRunInsecureContent("example.com", 42)); | 201 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 202 "www.google.com", 191, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 203 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 204 "example.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 205 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 206 "www.google.com", 42, |
| 207 content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
| 208 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 209 "www.google.com", 191, |
| 210 content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
| 211 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 212 "example.com", 42, content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
202 | 213 |
203 state->HostRanInsecureContent("www.google.com", 42); | 214 // Mark a site as MIXED_CONTENT and check that only that host/child id |
| 215 // is affected, and only for MIXED_CONTENT (not for |
| 216 // CERT_ERRORS_CONTENT); |
| 217 state->HostRanInsecureContent("www.google.com", 42, |
| 218 content::SSLHostStateDelegate::MIXED_CONTENT); |
204 | 219 |
205 EXPECT_TRUE(state->DidHostRunInsecureContent("www.google.com", 42)); | 220 EXPECT_TRUE(state->DidHostRunInsecureContent( |
206 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 191)); | 221 "www.google.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
207 EXPECT_FALSE(state->DidHostRunInsecureContent("example.com", 42)); | 222 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 223 "www.google.com", 42, |
| 224 content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
| 225 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 226 "www.google.com", 191, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 227 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 228 "example.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
208 | 229 |
209 state->HostRanInsecureContent("example.com", 42); | 230 // Mark another site as MIXED_CONTENT, and check that that host/child |
| 231 // id is affected (for MIXED_CONTENT only), and that the previously |
| 232 // host/child id is still marked as MIXED_CONTENT. |
| 233 state->HostRanInsecureContent("example.com", 42, |
| 234 content::SSLHostStateDelegate::MIXED_CONTENT); |
210 | 235 |
211 EXPECT_TRUE(state->DidHostRunInsecureContent("www.google.com", 42)); | 236 EXPECT_TRUE(state->DidHostRunInsecureContent( |
212 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 191)); | 237 "www.google.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
213 EXPECT_TRUE(state->DidHostRunInsecureContent("example.com", 42)); | 238 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 239 "www.google.com", 191, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 240 EXPECT_TRUE(state->DidHostRunInsecureContent( |
| 241 "example.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 242 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 243 "example.com", 42, content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
| 244 |
| 245 // Mark a MIXED_CONTENT host/child id as CERT_ERRORS_CONTENT also. |
| 246 state->HostRanInsecureContent( |
| 247 "example.com", 42, content::SSLHostStateDelegate::CERT_ERRORS_CONTENT); |
| 248 |
| 249 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 250 "www.google.com", 191, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 251 EXPECT_TRUE(state->DidHostRunInsecureContent( |
| 252 "example.com", 42, content::SSLHostStateDelegate::MIXED_CONTENT)); |
| 253 EXPECT_TRUE(state->DidHostRunInsecureContent( |
| 254 "example.com", 42, content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
| 255 |
| 256 // Mark a non-MIXED_CONTENT host as CERT_ERRORS_CONTENT. |
| 257 state->HostRanInsecureContent( |
| 258 "www.google.com", 191, |
| 259 content::SSLHostStateDelegate::CERT_ERRORS_CONTENT); |
| 260 |
| 261 EXPECT_TRUE(state->DidHostRunInsecureContent( |
| 262 "www.google.com", 191, |
| 263 content::SSLHostStateDelegate::CERT_ERRORS_CONTENT)); |
| 264 EXPECT_FALSE(state->DidHostRunInsecureContent( |
| 265 "www.google.com", 191, content::SSLHostStateDelegate::MIXED_CONTENT)); |
214 } | 266 } |
215 | 267 |
216 // Test the migration code needed as a result of changing how the content | 268 // Test the migration code needed as a result of changing how the content |
217 // setting is stored. We used to map the settings dictionary to the pattern | 269 // setting is stored. We used to map the settings dictionary to the pattern |
218 // pair <origin, origin> but now we map it to <origin, wildcard>. | 270 // pair <origin, origin> but now we map it to <origin, wildcard>. |
219 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, Migrate) { | 271 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, Migrate) { |
220 scoped_refptr<net::X509Certificate> cert = GetOkCert(); | 272 scoped_refptr<net::X509Certificate> cert = GetOkCert(); |
221 content::WebContents* tab = | 273 content::WebContents* tab = |
222 browser()->tab_strip_model()->GetActiveWebContents(); | 274 browser()->tab_strip_model()->GetActiveWebContents(); |
223 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 275 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 EXPECT_EQ( | 676 EXPECT_EQ( |
625 content::SSLHostStateDelegate::ALLOWED, | 677 content::SSLHostStateDelegate::ALLOWED, |
626 state->QueryPolicy("localhost", *cert, | 678 state->QueryPolicy("localhost", *cert, |
627 net::CERT_STATUS_COMMON_NAME_INVALID, &unused_value)); | 679 net::CERT_STATUS_COMMON_NAME_INVALID, &unused_value)); |
628 | 680 |
629 EXPECT_EQ( | 681 EXPECT_EQ( |
630 content::SSLHostStateDelegate::ALLOWED, | 682 content::SSLHostStateDelegate::ALLOWED, |
631 state->QueryPolicy("127.0.0.1", *cert, | 683 state->QueryPolicy("127.0.0.1", *cert, |
632 net::CERT_STATUS_COMMON_NAME_INVALID, &unused_value)); | 684 net::CERT_STATUS_COMMON_NAME_INVALID, &unused_value)); |
633 } | 685 } |
OLD | NEW |