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

Side by Side Diff: chrome/browser/ssl/chrome_security_state_model_client_browser_tests.cc

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

Powered by Google App Engine
This is Rietveld 408576698