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

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

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: update comments. Created 4 years, 1 month 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/chrome_security_state_model_client.h" 5 #include "chrome/browser/ssl/security_state_tab_helper.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/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.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"
14 #include "chrome/browser/ssl/ssl_blocking_page.h" 13 #include "chrome/browser/ssl/ssl_blocking_page.h"
15 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
21 #include "chrome/grit/generated_resources.h"
22 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
25 #include "components/security_state/switches.h" 23 #include "components/security_state/core/switches.h"
24 #include "components/strings/grit/components_strings.h"
26 #include "content/public/browser/interstitial_page.h" 25 #include "content/public/browser/interstitial_page.h"
27 #include "content/public/browser/navigation_controller.h" 26 #include "content/public/browser/navigation_controller.h"
28 #include "content/public/browser/navigation_entry.h" 27 #include "content/public/browser/navigation_entry.h"
29 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/notification_types.h" 29 #include "content/public/browser/notification_types.h"
31 #include "content/public/browser/security_style_explanation.h" 30 #include "content/public/browser/security_style_explanation.h"
32 #include "content/public/browser/security_style_explanations.h" 31 #include "content/public/browser/security_style_explanations.h"
33 #include "content/public/browser/ssl_status.h" 32 #include "content/public/browser/ssl_status.h"
34 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/referrer.h" 34 #include "content/public/common/referrer.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 expired_explanation.broken_explanations[0].summary); 122 expired_explanation.broken_explanations[0].summary);
124 123
125 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(error)); 124 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(error));
126 EXPECT_EQ(l10n_util::GetStringFUTF8( 125 EXPECT_EQ(l10n_util::GetStringFUTF8(
127 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string), 126 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
128 expired_explanation.broken_explanations[0].description); 127 expired_explanation.broken_explanations[0].description);
129 128
130 // Check the associated certificate. 129 // Check the associated certificate.
131 net::X509Certificate* cert = browser->tab_strip_model() 130 net::X509Certificate* cert = browser->tab_strip_model()
132 ->GetActiveWebContents() 131 ->GetActiveWebContents()
133 ->GetController() 132 ->GetController()
134 .GetActiveEntry() 133 .GetActiveEntry()
135 ->GetSSL() 134 ->GetSSL()
136 .certificate.get(); 135 .certificate.get();
137 EXPECT_TRUE(cert->Equals(expected_cert)); 136 EXPECT_TRUE(cert->Equals(expected_cert));
138 EXPECT_TRUE(expired_explanation.broken_explanations[0].has_certificate); 137 EXPECT_TRUE(expired_explanation.broken_explanations[0].has_certificate);
139 } 138 }
140 139
141 // Checks that the given |secure_explanations| contains an appropriate 140 // Checks that the given |secure_explanations| contains an appropriate
142 // explanation if the certificate status is valid. 141 // explanation if the certificate status is valid.
143 void CheckSecureExplanations( 142 void CheckSecureExplanations(
(...skipping 18 matching lines...) Expand all
162 EXPECT_TRUE(cert->Equals(expected_cert)); 161 EXPECT_TRUE(cert->Equals(expected_cert));
163 EXPECT_TRUE(secure_explanations[0].has_certificate); 162 EXPECT_TRUE(secure_explanations[0].has_certificate);
164 } 163 }
165 164
166 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY), 165 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY),
167 secure_explanations.back().summary); 166 secure_explanations.back().summary);
168 167
169 content::WebContents* web_contents = 168 content::WebContents* web_contents =
170 browser->tab_strip_model()->GetActiveWebContents(); 169 browser->tab_strip_model()->GetActiveWebContents();
171 SecurityStateModel::SecurityInfo security_info; 170 SecurityStateModel::SecurityInfo security_info;
172 ChromeSecurityStateModelClient::FromWebContents(web_contents) 171 SecurityStateTabHelper::FromWebContents(web_contents)
173 ->GetSecurityInfo(&security_info); 172 ->GetSecurityInfo(&security_info);
174 173
175 const char *protocol, *key_exchange, *cipher, *mac; 174 const char *protocol, *key_exchange, *cipher, *mac;
176 int ssl_version = 175 int ssl_version =
177 net::SSLConnectionStatusToVersion(security_info.connection_status); 176 net::SSLConnectionStatusToVersion(security_info.connection_status);
178 net::SSLVersionToString(&protocol, ssl_version); 177 net::SSLVersionToString(&protocol, ssl_version);
179 bool is_aead, is_tls13; 178 bool is_aead, is_tls13;
180 uint16_t cipher_suite = 179 uint16_t cipher_suite =
181 net::SSLConnectionStatusToCipherSuite(security_info.connection_status); 180 net::SSLConnectionStatusToCipherSuite(security_info.connection_status);
182 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 181 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead,
(...skipping 23 matching lines...) Expand all
206 205
207 void CheckSecurityInfoForSecure( 206 void CheckSecurityInfoForSecure(
208 content::WebContents* contents, 207 content::WebContents* contents,
209 SecurityStateModel::SecurityLevel expect_security_level, 208 SecurityStateModel::SecurityLevel expect_security_level,
210 SecurityStateModel::SHA1DeprecationStatus expect_sha1_status, 209 SecurityStateModel::SHA1DeprecationStatus expect_sha1_status,
211 SecurityStateModel::ContentStatus expect_mixed_content_status, 210 SecurityStateModel::ContentStatus expect_mixed_content_status,
212 bool pkp_bypassed, 211 bool pkp_bypassed,
213 bool expect_cert_error) { 212 bool expect_cert_error) {
214 ASSERT_TRUE(contents); 213 ASSERT_TRUE(contents);
215 214
216 ChromeSecurityStateModelClient* model_client = 215 SecurityStateTabHelper* helper =
217 ChromeSecurityStateModelClient::FromWebContents(contents); 216 SecurityStateTabHelper::FromWebContents(contents);
218 ASSERT_TRUE(model_client); 217 ASSERT_TRUE(helper);
219 SecurityStateModel::SecurityInfo security_info; 218 SecurityStateModel::SecurityInfo security_info;
220 model_client->GetSecurityInfo(&security_info); 219 helper->GetSecurityInfo(&security_info);
221 EXPECT_EQ(expect_security_level, security_info.security_level); 220 EXPECT_EQ(expect_security_level, security_info.security_level);
222 EXPECT_EQ(expect_sha1_status, security_info.sha1_deprecation_status); 221 EXPECT_EQ(expect_sha1_status, security_info.sha1_deprecation_status);
223 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status); 222 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status);
224 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 223 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
225 EXPECT_TRUE(security_info.scheme_is_cryptographic); 224 EXPECT_TRUE(security_info.scheme_is_cryptographic);
226 EXPECT_EQ(pkp_bypassed, security_info.pkp_bypassed); 225 EXPECT_EQ(pkp_bypassed, security_info.pkp_bypassed);
227 EXPECT_EQ(expect_cert_error, 226 EXPECT_EQ(expect_cert_error,
228 net::IsCertStatusError(security_info.cert_status)); 227 net::IsCertStatusError(security_info.cert_status));
229 EXPECT_GT(security_info.security_bits, 0); 228 EXPECT_GT(security_info.security_bits, 0);
230 EXPECT_TRUE(!!security_info.certificate); 229 EXPECT_TRUE(!!security_info.certificate);
231 } 230 }
232 231
233 void CheckSecurityInfoForNonSecure(content::WebContents* contents) { 232 void CheckSecurityInfoForNonSecure(content::WebContents* contents) {
234 ASSERT_TRUE(contents); 233 ASSERT_TRUE(contents);
235 234
236 ChromeSecurityStateModelClient* model_client = 235 SecurityStateTabHelper* helper =
237 ChromeSecurityStateModelClient::FromWebContents(contents); 236 SecurityStateTabHelper::FromWebContents(contents);
238 ASSERT_TRUE(model_client); 237 ASSERT_TRUE(helper);
239 SecurityStateModel::SecurityInfo security_info; 238 SecurityStateModel::SecurityInfo security_info;
240 model_client->GetSecurityInfo(&security_info); 239 helper->GetSecurityInfo(&security_info);
241 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); 240 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level);
242 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, 241 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1,
243 security_info.sha1_deprecation_status); 242 security_info.sha1_deprecation_status);
244 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_NONE, 243 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_NONE,
245 security_info.mixed_content_status); 244 security_info.mixed_content_status);
246 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 245 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
247 EXPECT_FALSE(security_info.scheme_is_cryptographic); 246 EXPECT_FALSE(security_info.scheme_is_cryptographic);
248 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 247 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
249 EXPECT_EQ(-1, security_info.security_bits); 248 EXPECT_EQ(-1, security_info.security_bits);
250 EXPECT_FALSE(!!security_info.certificate); 249 EXPECT_FALSE(!!security_info.certificate);
(...skipping 15 matching lines...) Expand all
266 const std::string& original_file_path, 265 const std::string& original_file_path,
267 const net::HostPortPair& host_port_pair, 266 const net::HostPortPair& host_port_pair,
268 std::string* replacement_path) { 267 std::string* replacement_path) {
269 base::StringPairs replacement_text; 268 base::StringPairs replacement_text;
270 replacement_text.push_back( 269 replacement_text.push_back(
271 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); 270 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString()));
272 net::test_server::GetFilePathWithReplacements( 271 net::test_server::GetFilePathWithReplacements(
273 original_file_path, replacement_text, replacement_path); 272 original_file_path, replacement_text, replacement_path);
274 } 273 }
275 274
276 class ChromeSecurityStateModelClientTest : public CertVerifierBrowserTest { 275 class SecurityStateTabHelperTest : public CertVerifierBrowserTest {
277 public: 276 public:
278 ChromeSecurityStateModelClientTest() 277 SecurityStateTabHelperTest()
279 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { 278 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
280 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 279 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
281 } 280 }
282 281
283 void SetUpCommandLine(base::CommandLine* command_line) override { 282 void SetUpCommandLine(base::CommandLine* command_line) override {
284 // Browser will both run and display insecure content. 283 // Browser will both run and display insecure content.
285 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 284 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
286 } 285 }
287 286
288 protected: 287 protected:
289 void SetUpMockCertVerifierForHttpsServer(net::CertStatus cert_status, 288 void SetUpMockCertVerifierForHttpsServer(net::CertStatus cert_status,
290 int net_result) { 289 int net_result) {
291 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); 290 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate());
292 net::CertVerifyResult verify_result; 291 net::CertVerifyResult verify_result;
293 verify_result.is_issued_by_known_root = true; 292 verify_result.is_issued_by_known_root = true;
294 verify_result.verified_cert = cert; 293 verify_result.verified_cert = cert;
295 verify_result.cert_status = cert_status; 294 verify_result.cert_status = cert_status;
296 295
297 mock_cert_verifier()->AddResultForCert(cert, verify_result, net_result); 296 mock_cert_verifier()->AddResultForCert(cert, verify_result, net_result);
298 } 297 }
299 298
300 net::EmbeddedTestServer https_server_; 299 net::EmbeddedTestServer https_server_;
301 300
302 private: 301 private:
303 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityStateModelClientTest); 302 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest);
304 }; 303 };
305 304
306 GURL GetURLWithNonLocalHostname(net::EmbeddedTestServer* server, 305 GURL GetURLWithNonLocalHostname(net::EmbeddedTestServer* server,
307 const std::string& path) { 306 const std::string& path) {
308 GURL::Replacements replace_host; 307 GURL::Replacements replace_host;
309 replace_host.SetHostStr("example.test"); 308 replace_host.SetHostStr("example.test");
310 return server->GetURL(path).ReplaceComponents(replace_host); 309 return server->GetURL(path).ReplaceComponents(replace_host);
311 } 310 }
312 311
313 class ChromeSecurityStateModelClientTestWithPasswordCcSwitch 312 class SecurityStateTabHelperTestWithPasswordCcSwitch
314 : public ChromeSecurityStateModelClientTest { 313 : public SecurityStateTabHelperTest {
315 public: 314 public:
316 ChromeSecurityStateModelClientTestWithPasswordCcSwitch() 315 SecurityStateTabHelperTestWithPasswordCcSwitch()
317 : ChromeSecurityStateModelClientTest() {} 316 : SecurityStateTabHelperTest() {}
318 317
319 void SetUpOnMainThread() override { 318 void SetUpOnMainThread() override {
320 ASSERT_TRUE(embedded_test_server()->Start()); 319 ASSERT_TRUE(embedded_test_server()->Start());
321 ASSERT_TRUE(https_server_.Start()); 320 ASSERT_TRUE(https_server_.Start());
322 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host()); 321 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host());
323 SetUpMockCertVerifierForHttpsServer(0, net::OK); 322 SetUpMockCertVerifierForHttpsServer(0, net::OK);
324 } 323 }
325 324
326 void SetUpCommandLine(base::CommandLine* command_line) override { 325 void SetUpCommandLine(base::CommandLine* command_line) override {
327 ChromeSecurityStateModelClientTest::SetUpCommandLine(command_line); 326 SecurityStateTabHelperTest::SetUpCommandLine(command_line);
328 command_line->AppendSwitchASCII( 327 command_line->AppendSwitchASCII(
329 security_state::switches::kMarkHttpAs, 328 security_state::switches::kMarkHttpAs,
330 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); 329 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
331 } 330 }
332 331
333 private: 332 private:
334 DISALLOW_COPY_AND_ASSIGN( 333 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTestWithPasswordCcSwitch);
335 ChromeSecurityStateModelClientTestWithPasswordCcSwitch);
336 }; 334 };
337 335
338 class SecurityStyleChangedTest : public InProcessBrowserTest { 336 class SecurityStyleChangedTest : public InProcessBrowserTest {
339 public: 337 public:
340 SecurityStyleChangedTest() 338 SecurityStyleChangedTest()
341 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { 339 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
342 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 340 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
343 } 341 }
344 342
345 void SetUpCommandLine(base::CommandLine* command_line) override { 343 void SetUpCommandLine(base::CommandLine* command_line) override {
346 // Browser will both run and display insecure content. 344 // Browser will both run and display insecure content.
347 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 345 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
348 } 346 }
349 347
350 protected: 348 protected:
351 net::EmbeddedTestServer https_server_; 349 net::EmbeddedTestServer https_server_;
352 350
353 private: 351 private:
354 DISALLOW_COPY_AND_ASSIGN(SecurityStyleChangedTest); 352 DISALLOW_COPY_AND_ASSIGN(SecurityStyleChangedTest);
355 }; 353 };
356 354
357 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, HttpPage) { 355 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpPage) {
358 ASSERT_TRUE(embedded_test_server()->Start()); 356 ASSERT_TRUE(embedded_test_server()->Start());
359 ui_test_utils::NavigateToURL( 357 ui_test_utils::NavigateToURL(
360 browser(), embedded_test_server()->GetURL("/ssl/google.html")); 358 browser(), embedded_test_server()->GetURL("/ssl/google.html"));
361 content::WebContents* contents = 359 content::WebContents* contents =
362 browser()->tab_strip_model()->GetActiveWebContents(); 360 browser()->tab_strip_model()->GetActiveWebContents();
363 ASSERT_TRUE(contents); 361 ASSERT_TRUE(contents);
364 362
365 ChromeSecurityStateModelClient* model_client = 363 SecurityStateTabHelper* helper =
366 ChromeSecurityStateModelClient::FromWebContents(contents); 364 SecurityStateTabHelper::FromWebContents(contents);
367 ASSERT_TRUE(model_client); 365 ASSERT_TRUE(helper);
368 SecurityStateModel::SecurityInfo security_info; 366 SecurityStateModel::SecurityInfo security_info;
369 model_client->GetSecurityInfo(&security_info); 367 helper->GetSecurityInfo(&security_info);
370 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); 368 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level);
371 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, 369 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1,
372 security_info.sha1_deprecation_status); 370 security_info.sha1_deprecation_status);
373 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_NONE, 371 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_NONE,
374 security_info.mixed_content_status); 372 security_info.mixed_content_status);
375 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 373 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
376 EXPECT_FALSE(security_info.scheme_is_cryptographic); 374 EXPECT_FALSE(security_info.scheme_is_cryptographic);
377 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 375 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
378 EXPECT_FALSE(!!security_info.certificate); 376 EXPECT_FALSE(!!security_info.certificate);
379 EXPECT_EQ(-1, security_info.security_bits); 377 EXPECT_EQ(-1, security_info.security_bits);
380 EXPECT_EQ(0, security_info.connection_status); 378 EXPECT_EQ(0, security_info.connection_status);
381 } 379 }
382 380
383 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, HttpsPage) { 381 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpsPage) {
384 ASSERT_TRUE(https_server_.Start()); 382 ASSERT_TRUE(https_server_.Start());
385 SetUpMockCertVerifierForHttpsServer(0, net::OK); 383 SetUpMockCertVerifierForHttpsServer(0, net::OK);
386 384
387 ui_test_utils::NavigateToURL(browser(), 385 ui_test_utils::NavigateToURL(browser(),
388 https_server_.GetURL("/ssl/google.html")); 386 https_server_.GetURL("/ssl/google.html"));
389 CheckSecurityInfoForSecure( 387 CheckSecurityInfoForSecure(
390 browser()->tab_strip_model()->GetActiveWebContents(), 388 browser()->tab_strip_model()->GetActiveWebContents(),
391 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, 389 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1,
392 SecurityStateModel::CONTENT_STATUS_NONE, false, 390 SecurityStateModel::CONTENT_STATUS_NONE, false,
393 false /* expect cert status error */); 391 false /* expect cert status error */);
394 } 392 }
395 393
396 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, SHA1Broken) { 394 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1Broken) {
397 ASSERT_TRUE(https_server_.Start()); 395 ASSERT_TRUE(https_server_.Start());
398 // The test server uses a long-lived cert by default, so a SHA1 396 // The test server uses a long-lived cert by default, so a SHA1
399 // signature in it will register as a "broken" condition rather than 397 // signature in it will register as a "broken" condition rather than
400 // "warning". 398 // "warning".
401 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 399 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
402 net::OK); 400 net::OK);
403 401
404 ui_test_utils::NavigateToURL(browser(), 402 ui_test_utils::NavigateToURL(browser(),
405 https_server_.GetURL("/ssl/google.html")); 403 https_server_.GetURL("/ssl/google.html"));
406 CheckSecurityInfoForSecure( 404 CheckSecurityInfoForSecure(
407 browser()->tab_strip_model()->GetActiveWebContents(), 405 browser()->tab_strip_model()->GetActiveWebContents(),
408 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR, 406 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR,
409 SecurityStateModel::CONTENT_STATUS_NONE, false, 407 SecurityStateModel::CONTENT_STATUS_NONE, false,
410 false /* expect cert status error */); 408 false /* expect cert status error */);
411 } 409 }
412 410
413 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, MixedContent) { 411 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) {
414 ASSERT_TRUE(embedded_test_server()->Start()); 412 ASSERT_TRUE(embedded_test_server()->Start());
415 ASSERT_TRUE(https_server_.Start()); 413 ASSERT_TRUE(https_server_.Start());
416 SetUpMockCertVerifierForHttpsServer(0, net::OK); 414 SetUpMockCertVerifierForHttpsServer(0, net::OK);
417 host_resolver()->AddRule("example.test", 415 host_resolver()->AddRule("example.test",
418 https_server_.GetURL("/title1.html").host()); 416 https_server_.GetURL("/title1.html").host());
419 417
420 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 418 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
421 replacement_pair.set_host("example.test"); 419 replacement_pair.set_host("example.test");
422 420
423 // Navigate to an HTTPS page that displays mixed content. 421 // Navigate to an HTTPS page that displays mixed content.
424 std::string replacement_path; 422 std::string replacement_path;
425 GetFilePathWithHostAndPortReplacement( 423 GetFilePathWithHostAndPortReplacement(
426 "/ssl/page_displays_insecure_content.html", 424 "/ssl/page_displays_insecure_content.html", replacement_pair,
427 replacement_pair, &replacement_path); 425 &replacement_path);
428 ui_test_utils::NavigateToURL(browser(), 426 ui_test_utils::NavigateToURL(browser(),
429 https_server_.GetURL(replacement_path)); 427 https_server_.GetURL(replacement_path));
430 CheckSecurityInfoForSecure( 428 CheckSecurityInfoForSecure(
431 browser()->tab_strip_model()->GetActiveWebContents(), 429 browser()->tab_strip_model()->GetActiveWebContents(),
432 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, 430 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1,
433 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, 431 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false,
434 false /* expect cert status error */); 432 false /* expect cert status error */);
435 433
436 // Navigate to an HTTPS page that displays mixed content dynamically. 434 // Navigate to an HTTPS page that displays mixed content dynamically.
437 GetFilePathWithHostAndPortReplacement( 435 GetFilePathWithHostAndPortReplacement(
438 "/ssl/page_with_dynamic_insecure_content.html", 436 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
439 replacement_pair, &replacement_path); 437 &replacement_path);
440 ui_test_utils::NavigateToURL(browser(), 438 ui_test_utils::NavigateToURL(browser(),
441 https_server_.GetURL(replacement_path)); 439 https_server_.GetURL(replacement_path));
442 CheckSecurityInfoForSecure( 440 CheckSecurityInfoForSecure(
443 browser()->tab_strip_model()->GetActiveWebContents(), 441 browser()->tab_strip_model()->GetActiveWebContents(),
444 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, 442 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1,
445 SecurityStateModel::CONTENT_STATUS_NONE, false, 443 SecurityStateModel::CONTENT_STATUS_NONE, false,
446 false /* expect cert status error */); 444 false /* expect cert status error */);
447 // Load the insecure image. 445 // Load the insecure image.
448 bool js_result = false; 446 bool js_result = false;
449 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 447 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
450 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 448 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
451 &js_result)); 449 &js_result));
452 EXPECT_TRUE(js_result); 450 EXPECT_TRUE(js_result);
453 CheckSecurityInfoForSecure( 451 CheckSecurityInfoForSecure(
454 browser()->tab_strip_model()->GetActiveWebContents(), 452 browser()->tab_strip_model()->GetActiveWebContents(),
455 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, 453 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1,
456 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, 454 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false,
457 false /* expect cert status error */); 455 false /* expect cert status error */);
458 456
459 // Navigate to an HTTPS page that runs mixed content. 457 // Navigate to an HTTPS page that runs mixed content.
460 GetFilePathWithHostAndPortReplacement( 458 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
461 "/ssl/page_runs_insecure_content.html", 459 replacement_pair, &replacement_path);
462 replacement_pair, &replacement_path);
463 ui_test_utils::NavigateToURL(browser(), 460 ui_test_utils::NavigateToURL(browser(),
464 https_server_.GetURL(replacement_path)); 461 https_server_.GetURL(replacement_path));
465 CheckSecurityInfoForSecure( 462 CheckSecurityInfoForSecure(
466 browser()->tab_strip_model()->GetActiveWebContents(), 463 browser()->tab_strip_model()->GetActiveWebContents(),
467 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1, 464 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1,
468 SecurityStateModel::CONTENT_STATUS_RAN, false, 465 SecurityStateModel::CONTENT_STATUS_RAN, false,
469 false /* expect cert status error */); 466 false /* expect cert status error */);
470 467
471 // Navigate to an HTTPS page that runs and displays mixed content. 468 // Navigate to an HTTPS page that runs and displays mixed content.
472 GetFilePathWithHostAndPortReplacement( 469 GetFilePathWithHostAndPortReplacement(
473 "/ssl/page_runs_and_displays_insecure_content.html", 470 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
474 replacement_pair, &replacement_path); 471 &replacement_path);
475 ui_test_utils::NavigateToURL(browser(), 472 ui_test_utils::NavigateToURL(browser(),
476 https_server_.GetURL(replacement_path)); 473 https_server_.GetURL(replacement_path));
477 CheckSecurityInfoForSecure( 474 CheckSecurityInfoForSecure(
478 browser()->tab_strip_model()->GetActiveWebContents(), 475 browser()->tab_strip_model()->GetActiveWebContents(),
479 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1, 476 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1,
480 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 477 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
481 false /* expect cert status error */); 478 false /* expect cert status error */);
482 479
483 // Navigate to an HTTPS page that runs mixed content in an iframe. 480 // Navigate to an HTTPS page that runs mixed content in an iframe.
484 net::HostPortPair host_port_pair = 481 net::HostPortPair host_port_pair =
485 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 482 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
486 host_port_pair.set_host("different-host.test"); 483 host_port_pair.set_host("different-host.test");
487 host_resolver()->AddRule("different-host.test", 484 host_resolver()->AddRule("different-host.test",
488 https_server_.GetURL("/title1.html").host()); 485 https_server_.GetURL("/title1.html").host());
489 host_resolver()->AddRule( 486 host_resolver()->AddRule(
490 "different-http-host.test", 487 "different-http-host.test",
491 embedded_test_server()->GetURL("/title1.html").host()); 488 embedded_test_server()->GetURL("/title1.html").host());
492 GetFilePathWithHostAndPortReplacement( 489 GetFilePathWithHostAndPortReplacement(
493 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, 490 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair,
494 &replacement_path); 491 &replacement_path);
495 ui_test_utils::NavigateToURL(browser(), 492 ui_test_utils::NavigateToURL(browser(),
496 https_server_.GetURL(replacement_path)); 493 https_server_.GetURL(replacement_path));
497 CheckSecurityInfoForSecure( 494 CheckSecurityInfoForSecure(
498 browser()->tab_strip_model()->GetActiveWebContents(), 495 browser()->tab_strip_model()->GetActiveWebContents(),
499 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1, 496 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1,
500 SecurityStateModel::CONTENT_STATUS_RAN, false, 497 SecurityStateModel::CONTENT_STATUS_RAN, false,
501 false /* expect cert status error */); 498 false /* expect cert status error */);
502 } 499 }
503 500
504 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, 501 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
505 ActiveContentWithCertErrors) { 502 ActiveContentWithCertErrors) {
506 ASSERT_TRUE(https_server_.Start()); 503 ASSERT_TRUE(https_server_.Start());
507 SetUpMockCertVerifierForHttpsServer(0, net::OK); 504 SetUpMockCertVerifierForHttpsServer(0, net::OK);
508 505
509 // Navigate to an HTTPS page and simulate active content with 506 // Navigate to an HTTPS page and simulate active content with
510 // certificate errors. 507 // certificate errors.
511 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); 508 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
512 content::WebContents* web_contents = 509 content::WebContents* web_contents =
513 browser()->tab_strip_model()->GetActiveWebContents(); 510 browser()->tab_strip_model()->GetActiveWebContents();
514 ASSERT_TRUE(web_contents); 511 ASSERT_TRUE(web_contents);
515 content::NavigationEntry* entry = 512 content::NavigationEntry* entry =
516 web_contents->GetController().GetVisibleEntry(); 513 web_contents->GetController().GetVisibleEntry();
517 ASSERT_TRUE(entry); 514 ASSERT_TRUE(entry);
518 entry->GetSSL().content_status |= 515 entry->GetSSL().content_status |=
519 content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS; 516 content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS;
520 517
521 ChromeSecurityStateModelClient* model_client = 518 SecurityStateTabHelper* helper =
522 ChromeSecurityStateModelClient::FromWebContents(web_contents); 519 SecurityStateTabHelper::FromWebContents(web_contents);
523 ASSERT_TRUE(model_client); 520 ASSERT_TRUE(helper);
524 SecurityStateModel::SecurityInfo security_info; 521 SecurityStateModel::SecurityInfo security_info;
525 model_client->GetSecurityInfo(&security_info); 522 helper->GetSecurityInfo(&security_info);
526 523
527 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 524 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
528 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); 525 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level);
529 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_RAN, 526 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_RAN,
530 security_info.content_with_cert_errors_status); 527 security_info.content_with_cert_errors_status);
531 } 528 }
532 529
533 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, 530 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
534 PassiveContentWithCertErrors) { 531 PassiveContentWithCertErrors) {
535 ASSERT_TRUE(https_server_.Start()); 532 ASSERT_TRUE(https_server_.Start());
536 SetUpMockCertVerifierForHttpsServer(0, net::OK); 533 SetUpMockCertVerifierForHttpsServer(0, net::OK);
537 534
538 // Navigate to an HTTPS page and simulate passive content with 535 // Navigate to an HTTPS page and simulate passive content with
539 // certificate errors. 536 // certificate errors.
540 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); 537 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
541 content::WebContents* web_contents = 538 content::WebContents* web_contents =
542 browser()->tab_strip_model()->GetActiveWebContents(); 539 browser()->tab_strip_model()->GetActiveWebContents();
543 ASSERT_TRUE(web_contents); 540 ASSERT_TRUE(web_contents);
544 content::NavigationEntry* entry = 541 content::NavigationEntry* entry =
545 web_contents->GetController().GetVisibleEntry(); 542 web_contents->GetController().GetVisibleEntry();
546 ASSERT_TRUE(entry); 543 ASSERT_TRUE(entry);
547 entry->GetSSL().content_status |= 544 entry->GetSSL().content_status |=
548 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS; 545 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS;
549 546
550 ChromeSecurityStateModelClient* model_client = 547 SecurityStateTabHelper* helper =
551 ChromeSecurityStateModelClient::FromWebContents(web_contents); 548 SecurityStateTabHelper::FromWebContents(web_contents);
552 ASSERT_TRUE(model_client); 549 ASSERT_TRUE(helper);
553 SecurityStateModel::SecurityInfo security_info; 550 SecurityStateModel::SecurityInfo security_info;
554 model_client->GetSecurityInfo(&security_info); 551 helper->GetSecurityInfo(&security_info);
555 552
556 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 553 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
557 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); 554 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level);
558 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED, 555 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED,
559 security_info.content_with_cert_errors_status); 556 security_info.content_with_cert_errors_status);
560 } 557 }
561 558
562 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, 559 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
563 ActiveAndPassiveContentWithCertErrors) { 560 ActiveAndPassiveContentWithCertErrors) {
564 ASSERT_TRUE(https_server_.Start()); 561 ASSERT_TRUE(https_server_.Start());
565 SetUpMockCertVerifierForHttpsServer(0, net::OK); 562 SetUpMockCertVerifierForHttpsServer(0, net::OK);
566 563
567 // Navigate to an HTTPS page and simulate active and passive content 564 // Navigate to an HTTPS page and simulate active and passive content
568 // with certificate errors. 565 // with certificate errors.
569 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); 566 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
570 content::WebContents* web_contents = 567 content::WebContents* web_contents =
571 browser()->tab_strip_model()->GetActiveWebContents(); 568 browser()->tab_strip_model()->GetActiveWebContents();
572 ASSERT_TRUE(web_contents); 569 ASSERT_TRUE(web_contents);
573 content::NavigationEntry* entry = 570 content::NavigationEntry* entry =
574 web_contents->GetController().GetVisibleEntry(); 571 web_contents->GetController().GetVisibleEntry();
575 ASSERT_TRUE(entry); 572 ASSERT_TRUE(entry);
576 entry->GetSSL().content_status |= 573 entry->GetSSL().content_status |=
577 content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS; 574 content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS;
578 entry->GetSSL().content_status |= 575 entry->GetSSL().content_status |=
579 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS; 576 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS;
580 577
581 ChromeSecurityStateModelClient* model_client = 578 SecurityStateTabHelper* helper =
582 ChromeSecurityStateModelClient::FromWebContents(web_contents); 579 SecurityStateTabHelper::FromWebContents(web_contents);
583 ASSERT_TRUE(model_client); 580 ASSERT_TRUE(helper);
584 SecurityStateModel::SecurityInfo security_info; 581 SecurityStateModel::SecurityInfo security_info;
585 model_client->GetSecurityInfo(&security_info); 582 helper->GetSecurityInfo(&security_info);
586 583
587 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 584 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
588 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level); 585 EXPECT_EQ(SecurityStateModel::DANGEROUS, security_info.security_level);
589 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, 586 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN,
590 security_info.content_with_cert_errors_status); 587 security_info.content_with_cert_errors_status);
591 } 588 }
592 589
593 // Same as the test above but with a long-lived SHA1 cert. 590 // Same as the test above but with a long-lived SHA1 cert.
594 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, 591 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithBrokenSHA1) {
595 MixedContentWithBrokenSHA1) {
596 ASSERT_TRUE(embedded_test_server()->Start()); 592 ASSERT_TRUE(embedded_test_server()->Start());
597 ASSERT_TRUE(https_server_.Start()); 593 ASSERT_TRUE(https_server_.Start());
598 // The test server uses a long-lived cert by default, so a SHA1 594 // The test server uses a long-lived cert by default, so a SHA1
599 // signature in it will register as a "broken" condition rather than 595 // signature in it will register as a "broken" condition rather than
600 // "warning". 596 // "warning".
601 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 597 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
602 net::OK); 598 net::OK);
603 599
604 host_resolver()->AddRule("example.test", 600 host_resolver()->AddRule("example.test",
605 https_server_.GetURL("/title1.html").host()); 601 https_server_.GetURL("/title1.html").host());
606 602
607 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 603 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
608 replacement_pair.set_host("example.test"); 604 replacement_pair.set_host("example.test");
609 605
610 // Navigate to an HTTPS page that displays mixed content. 606 // Navigate to an HTTPS page that displays mixed content.
611 std::string replacement_path; 607 std::string replacement_path;
612 GetFilePathWithHostAndPortReplacement( 608 GetFilePathWithHostAndPortReplacement(
613 "/ssl/page_displays_insecure_content.html", 609 "/ssl/page_displays_insecure_content.html", replacement_pair,
614 replacement_pair, &replacement_path); 610 &replacement_path);
615 ui_test_utils::NavigateToURL(browser(), 611 ui_test_utils::NavigateToURL(browser(),
616 https_server_.GetURL(replacement_path)); 612 https_server_.GetURL(replacement_path));
617 CheckSecurityInfoForSecure( 613 CheckSecurityInfoForSecure(
618 browser()->tab_strip_model()->GetActiveWebContents(), 614 browser()->tab_strip_model()->GetActiveWebContents(),
619 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR, 615 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR,
620 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, 616 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false,
621 false /* expect cert status error */); 617 false /* expect cert status error */);
622 618
623 // Navigate to an HTTPS page that displays mixed content dynamically. 619 // Navigate to an HTTPS page that displays mixed content dynamically.
624 GetFilePathWithHostAndPortReplacement( 620 GetFilePathWithHostAndPortReplacement(
625 "/ssl/page_with_dynamic_insecure_content.html", 621 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
626 replacement_pair, &replacement_path); 622 &replacement_path);
627 ui_test_utils::NavigateToURL(browser(), 623 ui_test_utils::NavigateToURL(browser(),
628 https_server_.GetURL(replacement_path)); 624 https_server_.GetURL(replacement_path));
629 CheckSecurityInfoForSecure( 625 CheckSecurityInfoForSecure(
630 browser()->tab_strip_model()->GetActiveWebContents(), 626 browser()->tab_strip_model()->GetActiveWebContents(),
631 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR, 627 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR,
632 SecurityStateModel::CONTENT_STATUS_NONE, false, 628 SecurityStateModel::CONTENT_STATUS_NONE, false,
633 false /* expect cert status error */); 629 false /* expect cert status error */);
634 // Load the insecure image. 630 // Load the insecure image.
635 bool js_result = false; 631 bool js_result = false;
636 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 632 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
637 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 633 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
638 &js_result)); 634 &js_result));
639 EXPECT_TRUE(js_result); 635 EXPECT_TRUE(js_result);
640 CheckSecurityInfoForSecure( 636 CheckSecurityInfoForSecure(
641 browser()->tab_strip_model()->GetActiveWebContents(), 637 browser()->tab_strip_model()->GetActiveWebContents(),
642 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR, 638 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR,
643 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, 639 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false,
644 false /* expect cert status error */); 640 false /* expect cert status error */);
645 641
646 // Navigate to an HTTPS page that runs mixed content. 642 // Navigate to an HTTPS page that runs mixed content.
647 GetFilePathWithHostAndPortReplacement( 643 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
648 "/ssl/page_runs_insecure_content.html", 644 replacement_pair, &replacement_path);
649 replacement_pair, &replacement_path);
650 ui_test_utils::NavigateToURL(browser(), 645 ui_test_utils::NavigateToURL(browser(),
651 https_server_.GetURL(replacement_path)); 646 https_server_.GetURL(replacement_path));
652 CheckSecurityInfoForSecure( 647 CheckSecurityInfoForSecure(
653 browser()->tab_strip_model()->GetActiveWebContents(), 648 browser()->tab_strip_model()->GetActiveWebContents(),
654 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR, 649 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR,
655 SecurityStateModel::CONTENT_STATUS_RAN, false, 650 SecurityStateModel::CONTENT_STATUS_RAN, false,
656 false /* expect cert status error */); 651 false /* expect cert status error */);
657 652
658 // Navigate to an HTTPS page that runs and displays mixed content. 653 // Navigate to an HTTPS page that runs and displays mixed content.
659 GetFilePathWithHostAndPortReplacement( 654 GetFilePathWithHostAndPortReplacement(
660 "/ssl/page_runs_and_displays_insecure_content.html", 655 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
661 replacement_pair, &replacement_path); 656 &replacement_path);
662 ui_test_utils::NavigateToURL(browser(), 657 ui_test_utils::NavigateToURL(browser(),
663 https_server_.GetURL(replacement_path)); 658 https_server_.GetURL(replacement_path));
664 CheckSecurityInfoForSecure( 659 CheckSecurityInfoForSecure(
665 browser()->tab_strip_model()->GetActiveWebContents(), 660 browser()->tab_strip_model()->GetActiveWebContents(),
666 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR, 661 SecurityStateModel::DANGEROUS, SecurityStateModel::DEPRECATED_SHA1_MAJOR,
667 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 662 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
668 false /* expect cert status error */); 663 false /* expect cert status error */);
669 } 664 }
670 665
671 // Tests that the Content Security Policy block-all-mixed-content 666 // Tests that the Content Security Policy block-all-mixed-content
672 // directive stops mixed content from running. 667 // directive stops mixed content from running.
673 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, 668 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) {
674 MixedContentStrictBlocking) {
675 ASSERT_TRUE(https_server_.Start()); 669 ASSERT_TRUE(https_server_.Start());
676 SetUpMockCertVerifierForHttpsServer(0, net::OK); 670 SetUpMockCertVerifierForHttpsServer(0, net::OK);
677 671
678 // Navigate to an HTTPS page that tries to run mixed content in an 672 // Navigate to an HTTPS page that tries to run mixed content in an
679 // iframe, with strict mixed content blocking. 673 // iframe, with strict mixed content blocking.
680 std::string replacement_path; 674 std::string replacement_path;
681 net::HostPortPair host_port_pair = 675 net::HostPortPair host_port_pair =
682 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 676 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
683 host_port_pair.set_host("different-host.test"); 677 host_port_pair.set_host("different-host.test");
684 host_resolver()->AddRule("different-host.test", 678 host_resolver()->AddRule("different-host.test",
685 https_server_.GetURL("/title1.html").host()); 679 https_server_.GetURL("/title1.html").host());
686 GetFilePathWithHostAndPortReplacement( 680 GetFilePathWithHostAndPortReplacement(
687 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html", 681 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html",
688 host_port_pair, &replacement_path); 682 host_port_pair, &replacement_path);
689 ui_test_utils::NavigateToURL(browser(), 683 ui_test_utils::NavigateToURL(browser(),
690 https_server_.GetURL(replacement_path)); 684 https_server_.GetURL(replacement_path));
691 CheckSecurityInfoForSecure( 685 CheckSecurityInfoForSecure(
692 browser()->tab_strip_model()->GetActiveWebContents(), 686 browser()->tab_strip_model()->GetActiveWebContents(),
693 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, 687 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1,
694 SecurityStateModel::CONTENT_STATUS_NONE, false, 688 SecurityStateModel::CONTENT_STATUS_NONE, false,
695 false /* expect cert status error */); 689 false /* expect cert status error */);
696 } 690 }
697 691
698 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, BrokenHTTPS) { 692 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) {
699 ASSERT_TRUE(embedded_test_server()->Start()); 693 ASSERT_TRUE(embedded_test_server()->Start());
700 ASSERT_TRUE(https_server_.Start()); 694 ASSERT_TRUE(https_server_.Start());
701 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, 695 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID,
702 net::ERR_CERT_DATE_INVALID); 696 net::ERR_CERT_DATE_INVALID);
703 697
704 ui_test_utils::NavigateToURL(browser(), 698 ui_test_utils::NavigateToURL(browser(),
705 https_server_.GetURL("/ssl/google.html")); 699 https_server_.GetURL("/ssl/google.html"));
706 CheckSecurityInfoForSecure( 700 CheckSecurityInfoForSecure(
707 browser()->tab_strip_model()->GetActiveWebContents(), 701 browser()->tab_strip_model()->GetActiveWebContents(),
708 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1, 702 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1,
(...skipping 18 matching lines...) Expand all
727 https_server_.GetURL(replacement_path)); 721 https_server_.GetURL(replacement_path));
728 CheckSecurityInfoForSecure( 722 CheckSecurityInfoForSecure(
729 browser()->tab_strip_model()->GetActiveWebContents(), 723 browser()->tab_strip_model()->GetActiveWebContents(),
730 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1, 724 SecurityStateModel::DANGEROUS, SecurityStateModel::NO_DEPRECATED_SHA1,
731 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, 725 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false,
732 true /* expect cert status error */); 726 true /* expect cert status error */);
733 } 727 }
734 728
735 const char kReportURI[] = "https://report-hpkp.test"; 729 const char kReportURI[] = "https://report-hpkp.test";
736 730
737 class PKPModelClientTest : public ChromeSecurityStateModelClientTest { 731 class PKPModelClientTest : public SecurityStateTabHelperTest {
738 public: 732 public:
739 void SetUpOnMainThread() override { 733 void SetUpOnMainThread() override {
740 ASSERT_TRUE(https_server_.Start()); 734 ASSERT_TRUE(https_server_.Start());
741 url_request_context_getter_ = browser()->profile()->GetRequestContext(); 735 url_request_context_getter_ = browser()->profile()->GetRequestContext();
742 content::BrowserThread::PostTask( 736 content::BrowserThread::PostTask(
743 content::BrowserThread::IO, FROM_HERE, 737 content::BrowserThread::IO, FROM_HERE,
744 base::Bind(&PKPModelClientTest::SetUpOnIOThread, 738 base::Bind(&PKPModelClientTest::SetUpOnIOThread,
745 base::Unretained(this))); 739 base::Unretained(this)));
746 } 740 }
747 741
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 DISALLOW_COPY_AND_ASSIGN(PendingJobInterceptor); 832 DISALLOW_COPY_AND_ASSIGN(PendingJobInterceptor);
839 }; 833 };
840 834
841 void InstallLoadingInterceptor(const std::string& host) { 835 void InstallLoadingInterceptor(const std::string& host) {
842 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); 836 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
843 filter->AddHostnameInterceptor( 837 filter->AddHostnameInterceptor(
844 "http", host, 838 "http", host,
845 std::unique_ptr<net::URLRequestInterceptor>(new PendingJobInterceptor())); 839 std::unique_ptr<net::URLRequestInterceptor>(new PendingJobInterceptor()));
846 } 840 }
847 841
848 class SecurityStateModelLoadingTest 842 class SecurityStateModelLoadingTest : public SecurityStateTabHelperTest {
849 : public ChromeSecurityStateModelClientTest {
850 public: 843 public:
851 SecurityStateModelLoadingTest() : ChromeSecurityStateModelClientTest() {} 844 SecurityStateModelLoadingTest() : SecurityStateTabHelperTest() {}
852 ~SecurityStateModelLoadingTest() override{}; 845 ~SecurityStateModelLoadingTest() override{};
853 846
854 protected: 847 protected:
855 void SetUpOnMainThread() override { 848 void SetUpOnMainThread() override {
856 ASSERT_TRUE(embedded_test_server()->Start()); 849 ASSERT_TRUE(embedded_test_server()->Start());
857 850
858 content::BrowserThread::PostTask( 851 content::BrowserThread::PostTask(
859 content::BrowserThread::IO, FROM_HERE, 852 content::BrowserThread::IO, FROM_HERE,
860 base::Bind(&InstallLoadingInterceptor, 853 base::Bind(&InstallLoadingInterceptor,
861 embedded_test_server()->GetURL("/title1.html").host())); 854 embedded_test_server()->GetURL("/title1.html").host()));
(...skipping 19 matching lines...) Expand all
881 874
882 // Navigate to a page that doesn't finish loading. Test that the 875 // Navigate to a page that doesn't finish loading. Test that the
883 // security state is neutral while the page is loading. 876 // security state is neutral while the page is loading.
884 browser()->OpenURL(content::OpenURLParams( 877 browser()->OpenURL(content::OpenURLParams(
885 embedded_test_server()->GetURL("/title1.html"), content::Referrer(), 878 embedded_test_server()->GetURL("/title1.html"), content::Referrer(),
886 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 879 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
887 CheckSecurityInfoForNonSecure( 880 CheckSecurityInfoForNonSecure(
888 browser()->tab_strip_model()->GetActiveWebContents()); 881 browser()->tab_strip_model()->GetActiveWebContents());
889 } 882 }
890 883
891 // Tests that the NavigationEntry's flags for nonsecure password/credit
892 // card inputs are reflected in the VisibleSecurityState.
893 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest,
894 VisibleSecurityStateNonsecureFormInputs) {
895 ASSERT_TRUE(https_server_.Start());
896 ui_test_utils::NavigateToURL(browser(),
897 https_server_.GetURL("/ssl/google.html"));
898
899 content::WebContents* contents =
900 browser()->tab_strip_model()->GetActiveWebContents();
901 ASSERT_TRUE(contents);
902
903 ChromeSecurityStateModelClient* model_client =
904 ChromeSecurityStateModelClient::FromWebContents(contents);
905 ASSERT_TRUE(model_client);
906
907 // First, test that if the flags aren't set on the NavigationEntry,
908 // then they also aren't set on the VisibleSecurityState.
909 content::SSLStatus& ssl_status =
910 contents->GetController().GetVisibleEntry()->GetSSL();
911 ASSERT_FALSE(ssl_status.content_status &
912 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
913 ASSERT_FALSE(ssl_status.content_status &
914 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
915 SecurityStateModel::VisibleSecurityState
916 visible_security_state_no_sensitive_inputs;
917 model_client->GetVisibleSecurityState(
918 &visible_security_state_no_sensitive_inputs);
919 EXPECT_FALSE(visible_security_state_no_sensitive_inputs
920 .displayed_password_field_on_http);
921 EXPECT_FALSE(visible_security_state_no_sensitive_inputs
922 .displayed_credit_card_field_on_http);
923
924 // Now, set the flags on the NavigationEntry and test that they are
925 // reflected in the VisibleSecurityState.
926 ssl_status.content_status |=
927 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP;
928 ssl_status.content_status |=
929 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP;
930 SecurityStateModel::VisibleSecurityState
931 visible_security_state_sensitive_inputs;
932 model_client->GetVisibleSecurityState(
933 &visible_security_state_sensitive_inputs);
934 EXPECT_TRUE(
935 visible_security_state_sensitive_inputs.displayed_password_field_on_http);
936 EXPECT_TRUE(visible_security_state_sensitive_inputs
937 .displayed_credit_card_field_on_http);
938 }
939
940 // Tests that when a visible password field is detected on an HTTP page 884 // Tests that when a visible password field is detected on an HTTP page
941 // load, and when the command-line flag is set, the security level is 885 // load, and when the command-line flag is set, the security level is
942 // downgraded to HTTP_SHOW_WARNING. 886 // downgraded to HTTP_SHOW_WARNING.
943 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 887 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
944 PasswordSecurityLevelDowngraded) { 888 PasswordSecurityLevelDowngraded) {
945 content::WebContents* contents = 889 content::WebContents* contents =
946 browser()->tab_strip_model()->GetActiveWebContents(); 890 browser()->tab_strip_model()->GetActiveWebContents();
947 ASSERT_TRUE(contents); 891 ASSERT_TRUE(contents);
948 892
949 ChromeSecurityStateModelClient* model_client = 893 SecurityStateTabHelper* helper =
950 ChromeSecurityStateModelClient::FromWebContents(contents); 894 SecurityStateTabHelper::FromWebContents(contents);
951 ASSERT_TRUE(model_client); 895 ASSERT_TRUE(helper);
952 896
953 ui_test_utils::NavigateToURL( 897 ui_test_utils::NavigateToURL(
954 browser(), GetURLWithNonLocalHostname(embedded_test_server(), 898 browser(), GetURLWithNonLocalHostname(embedded_test_server(),
955 "/password/simple_password.html")); 899 "/password/simple_password.html"));
956 security_state::SecurityStateModel::SecurityInfo security_info; 900 security_state::SecurityStateModel::SecurityInfo security_info;
957 model_client->GetSecurityInfo(&security_info); 901 helper->GetSecurityInfo(&security_info);
958 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 902 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
959 security_info.security_level); 903 security_info.security_level);
960 904
961 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 905 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
962 ASSERT_TRUE(entry); 906 ASSERT_TRUE(entry);
963 EXPECT_TRUE(entry->GetSSL().content_status & 907 EXPECT_TRUE(entry->GetSSL().content_status &
964 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 908 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
965 } 909 }
966 910
967 // Tests that when an invisible password field is present on an HTTP page 911 // Tests that when an invisible password field is present on an HTTP page
968 // load, and when the command-line flag is set, the security level is 912 // load, and when the command-line flag is set, the security level is
969 // *not* downgraded to HTTP_SHOW_WARNING. 913 // *not* downgraded to HTTP_SHOW_WARNING.
970 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 914 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
971 PasswordSecurityLevelNotDowngradedForInvisibleInput) { 915 PasswordSecurityLevelNotDowngradedForInvisibleInput) {
972 content::WebContents* contents = 916 content::WebContents* contents =
973 browser()->tab_strip_model()->GetActiveWebContents(); 917 browser()->tab_strip_model()->GetActiveWebContents();
974 ASSERT_TRUE(contents); 918 ASSERT_TRUE(contents);
975 919
976 ChromeSecurityStateModelClient* model_client = 920 SecurityStateTabHelper* helper =
977 ChromeSecurityStateModelClient::FromWebContents(contents); 921 SecurityStateTabHelper::FromWebContents(contents);
978 ASSERT_TRUE(model_client); 922 ASSERT_TRUE(helper);
979 923
980 ui_test_utils::NavigateToURL( 924 ui_test_utils::NavigateToURL(
981 browser(), 925 browser(),
982 GetURLWithNonLocalHostname(embedded_test_server(), 926 GetURLWithNonLocalHostname(embedded_test_server(),
983 "/password/invisible_password.html")); 927 "/password/invisible_password.html"));
984 security_state::SecurityStateModel::SecurityInfo security_info; 928 security_state::SecurityStateModel::SecurityInfo security_info;
985 model_client->GetSecurityInfo(&security_info); 929 helper->GetSecurityInfo(&security_info);
986 EXPECT_EQ(security_state::SecurityStateModel::NONE, 930 EXPECT_EQ(security_state::SecurityStateModel::NONE,
987 security_info.security_level); 931 security_info.security_level);
988 932
989 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 933 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
990 ASSERT_TRUE(entry); 934 ASSERT_TRUE(entry);
991 EXPECT_FALSE(entry->GetSSL().content_status & 935 EXPECT_FALSE(entry->GetSSL().content_status &
992 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 936 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
993 } 937 }
994 938
995 // Tests that when a visible password field is detected inside an iframe 939 // Tests that when a visible password field is detected inside an iframe
996 // on an HTTP page load, and when the command-line flag is set, the 940 // on an HTTP page load, and when the command-line flag is set, the
997 // security level is downgraded to HTTP_SHOW_WARNING. 941 // security level is downgraded to HTTP_SHOW_WARNING.
998 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 942 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
999 PasswordSecurityLevelDowngradedFromIframe) { 943 PasswordSecurityLevelDowngradedFromIframe) {
1000 content::WebContents* contents = 944 content::WebContents* contents =
1001 browser()->tab_strip_model()->GetActiveWebContents(); 945 browser()->tab_strip_model()->GetActiveWebContents();
1002 ASSERT_TRUE(contents); 946 ASSERT_TRUE(contents);
1003 947
1004 ChromeSecurityStateModelClient* model_client = 948 SecurityStateTabHelper* helper =
1005 ChromeSecurityStateModelClient::FromWebContents(contents); 949 SecurityStateTabHelper::FromWebContents(contents);
1006 ASSERT_TRUE(model_client); 950 ASSERT_TRUE(helper);
1007 951
1008 ui_test_utils::NavigateToURL( 952 ui_test_utils::NavigateToURL(
1009 browser(), 953 browser(),
1010 GetURLWithNonLocalHostname(embedded_test_server(), 954 GetURLWithNonLocalHostname(embedded_test_server(),
1011 "/password/simple_password_in_iframe.html")); 955 "/password/simple_password_in_iframe.html"));
1012 security_state::SecurityStateModel::SecurityInfo security_info; 956 security_state::SecurityStateModel::SecurityInfo security_info;
1013 model_client->GetSecurityInfo(&security_info); 957 helper->GetSecurityInfo(&security_info);
1014 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 958 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1015 security_info.security_level); 959 security_info.security_level);
1016 960
1017 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 961 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1018 ASSERT_TRUE(entry); 962 ASSERT_TRUE(entry);
1019 EXPECT_TRUE(entry->GetSSL().content_status & 963 EXPECT_TRUE(entry->GetSSL().content_status &
1020 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 964 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1021 } 965 }
1022 966
1023 // Tests that when a visible password field is detected inside an iframe 967 // Tests that when a visible password field is detected inside an iframe
1024 // on an HTTP page load, and when the command-line flag is set, the 968 // on an HTTP page load, and when the command-line flag is set, the
1025 // security level is downgraded to HTTP_SHOW_WARNING, even if the iframe 969 // security level is downgraded to HTTP_SHOW_WARNING, even if the iframe
1026 // itself was loaded over HTTPS. 970 // itself was loaded over HTTPS.
1027 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 971 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
1028 PasswordSecurityLevelDowngradedFromHttpsIframe) { 972 PasswordSecurityLevelDowngradedFromHttpsIframe) {
1029 content::WebContents* contents = 973 content::WebContents* contents =
1030 browser()->tab_strip_model()->GetActiveWebContents(); 974 browser()->tab_strip_model()->GetActiveWebContents();
1031 ASSERT_TRUE(contents); 975 ASSERT_TRUE(contents);
1032 976
1033 ChromeSecurityStateModelClient* model_client = 977 SecurityStateTabHelper* helper =
1034 ChromeSecurityStateModelClient::FromWebContents(contents); 978 SecurityStateTabHelper::FromWebContents(contents);
1035 ASSERT_TRUE(model_client); 979 ASSERT_TRUE(helper);
1036 980
1037 // Navigate to an HTTP URL, which loads an iframe using the host and port of 981 // Navigate to an HTTP URL, which loads an iframe using the host and port of
1038 // |https_server_|. 982 // |https_server_|.
1039 std::string replacement_path; 983 std::string replacement_path;
1040 GetFilePathWithHostAndPortReplacement( 984 GetFilePathWithHostAndPortReplacement(
1041 "/password/simple_password_in_https_iframe.html", 985 "/password/simple_password_in_https_iframe.html",
1042 https_server_.host_port_pair(), &replacement_path); 986 https_server_.host_port_pair(), &replacement_path);
1043 ui_test_utils::NavigateToURL( 987 ui_test_utils::NavigateToURL(
1044 browser(), 988 browser(),
1045 GetURLWithNonLocalHostname(embedded_test_server(), replacement_path)); 989 GetURLWithNonLocalHostname(embedded_test_server(), replacement_path));
1046 security_state::SecurityStateModel::SecurityInfo security_info; 990 security_state::SecurityStateModel::SecurityInfo security_info;
1047 model_client->GetSecurityInfo(&security_info); 991 helper->GetSecurityInfo(&security_info);
1048 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 992 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1049 security_info.security_level); 993 security_info.security_level);
1050 994
1051 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 995 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1052 ASSERT_TRUE(entry); 996 ASSERT_TRUE(entry);
1053 EXPECT_TRUE(entry->GetSSL().content_status & 997 EXPECT_TRUE(entry->GetSSL().content_status &
1054 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 998 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1055 } 999 }
1056 1000
1057 // Tests that when a visible password field is detected on an HTTP page 1001 // Tests that when a visible password field is detected on an HTTP page
1058 // load, and when the command-line flag is *not* set, the security level is 1002 // load, and when the command-line flag is *not* set, the security level is
1059 // *not* downgraded to HTTP_SHOW_WARNING. 1003 // *not* downgraded to HTTP_SHOW_WARNING.
1060 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, 1004 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
1061 PasswordSecurityLevelNotDowngradedWithoutSwitch) { 1005 PasswordSecurityLevelNotDowngradedWithoutSwitch) {
1062 ASSERT_TRUE(embedded_test_server()->Start()); 1006 ASSERT_TRUE(embedded_test_server()->Start());
1063 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host()); 1007 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host());
1064 1008
1065 content::WebContents* contents = 1009 content::WebContents* contents =
1066 browser()->tab_strip_model()->GetActiveWebContents(); 1010 browser()->tab_strip_model()->GetActiveWebContents();
1067 ASSERT_TRUE(contents); 1011 ASSERT_TRUE(contents);
1068 1012
1069 ChromeSecurityStateModelClient* model_client = 1013 SecurityStateTabHelper* helper =
1070 ChromeSecurityStateModelClient::FromWebContents(contents); 1014 SecurityStateTabHelper::FromWebContents(contents);
1071 ASSERT_TRUE(model_client); 1015 ASSERT_TRUE(helper);
1072 1016
1073 ui_test_utils::NavigateToURL( 1017 ui_test_utils::NavigateToURL(
1074 browser(), GetURLWithNonLocalHostname(embedded_test_server(), 1018 browser(), GetURLWithNonLocalHostname(embedded_test_server(),
1075 "/password/simple_password.html")); 1019 "/password/simple_password.html"));
1076 // The security level should not be HTTP_SHOW_WARNING, because the 1020 // The security level should not be HTTP_SHOW_WARNING, because the
1077 // command-line switch was not set. 1021 // command-line switch was not set.
1078 security_state::SecurityStateModel::SecurityInfo security_info; 1022 security_state::SecurityStateModel::SecurityInfo security_info;
1079 model_client->GetSecurityInfo(&security_info); 1023 helper->GetSecurityInfo(&security_info);
1080 EXPECT_EQ(security_state::SecurityStateModel::NONE, 1024 EXPECT_EQ(security_state::SecurityStateModel::NONE,
1081 security_info.security_level); 1025 security_info.security_level);
1082 1026
1083 // The appropriate SSLStatus flags should be set, however. 1027 // The appropriate SSLStatus flags should be set, however.
1084 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1028 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1085 ASSERT_TRUE(entry); 1029 ASSERT_TRUE(entry);
1086 EXPECT_TRUE(entry->GetSSL().content_status & 1030 EXPECT_TRUE(entry->GetSSL().content_status &
1087 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 1031 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1088 } 1032 }
1089 1033
1090 // Tests that when a visible password field is detected on an HTTPS page 1034 // Tests that when a visible password field is detected on an HTTPS page
1091 // load, and when the command-line flag is set, the security level is 1035 // load, and when the command-line flag is set, the security level is
1092 // *not* downgraded to HTTP_SHOW_WARNING. 1036 // *not* downgraded to HTTP_SHOW_WARNING.
1093 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 1037 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
1094 PasswordSecurityLevelNotDowngradedOnHttps) { 1038 PasswordSecurityLevelNotDowngradedOnHttps) {
1095 content::WebContents* contents = 1039 content::WebContents* contents =
1096 browser()->tab_strip_model()->GetActiveWebContents(); 1040 browser()->tab_strip_model()->GetActiveWebContents();
1097 ASSERT_TRUE(contents); 1041 ASSERT_TRUE(contents);
1098 1042
1099 ChromeSecurityStateModelClient* model_client = 1043 SecurityStateTabHelper* helper =
1100 ChromeSecurityStateModelClient::FromWebContents(contents); 1044 SecurityStateTabHelper::FromWebContents(contents);
1101 ASSERT_TRUE(model_client); 1045 ASSERT_TRUE(helper);
1102 1046
1103 GURL url = GetURLWithNonLocalHostname(&https_server_, 1047 GURL url = GetURLWithNonLocalHostname(&https_server_,
1104 "/password/simple_password.html"); 1048 "/password/simple_password.html");
1105 ui_test_utils::NavigateToURL(browser(), url); 1049 ui_test_utils::NavigateToURL(browser(), url);
1106 // The security level should not be HTTP_SHOW_WARNING, because the page was 1050 // The security level should not be HTTP_SHOW_WARNING, because the page was
1107 // HTTPS instead of HTTP. 1051 // HTTPS instead of HTTP.
1108 security_state::SecurityStateModel::SecurityInfo security_info; 1052 security_state::SecurityStateModel::SecurityInfo security_info;
1109 model_client->GetSecurityInfo(&security_info); 1053 helper->GetSecurityInfo(&security_info);
1110 EXPECT_EQ(security_state::SecurityStateModel::SECURE, 1054 EXPECT_EQ(security_state::SecurityStateModel::SECURE,
1111 security_info.security_level); 1055 security_info.security_level);
1112 1056
1113 // The SSLStatus flags should only be set if the top-level page load was HTTP, 1057 // The SSLStatus flags should only be set if the top-level page load was HTTP,
1114 // which it was not in this case. 1058 // which it was not in this case.
1115 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1059 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1116 ASSERT_TRUE(entry); 1060 ASSERT_TRUE(entry);
1117 EXPECT_FALSE(entry->GetSSL().content_status & 1061 EXPECT_FALSE(entry->GetSSL().content_status &
1118 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 1062 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1119 } 1063 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 ConsoleWebContentsDelegate* delegate) { 1123 ConsoleWebContentsDelegate* delegate) {
1180 const std::vector<base::string16>& messages = delegate->console_messages(); 1124 const std::vector<base::string16>& messages = delegate->console_messages();
1181 ASSERT_EQ(1u, messages.size()); 1125 ASSERT_EQ(1u, messages.size());
1182 EXPECT_NE(base::string16::npos, 1126 EXPECT_NE(base::string16::npos,
1183 messages[0].find(base::ASCIIToUTF16("warning will be added"))); 1127 messages[0].find(base::ASCIIToUTF16("warning will be added")));
1184 } 1128 }
1185 1129
1186 // Tests that console messages are printed upon a call to 1130 // Tests that console messages are printed upon a call to
1187 // GetSecurityInfo() on an HTTP_SHOW_WARNING page, exactly once per 1131 // GetSecurityInfo() on an HTTP_SHOW_WARNING page, exactly once per
1188 // main-frame navigation. 1132 // main-frame navigation.
1189 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 1133 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
1190 ConsoleMessage) { 1134 ConsoleMessage) {
1191 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate( 1135 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1192 Browser::CreateParams(browser()->profile())); 1136 Browser::CreateParams(browser()->profile()));
1193 content::WebContents* original_contents = 1137 content::WebContents* original_contents =
1194 browser()->tab_strip_model()->GetActiveWebContents(); 1138 browser()->tab_strip_model()->GetActiveWebContents();
1195 content::WebContents* contents = 1139 content::WebContents* contents =
1196 content::WebContents::Create(content::WebContents::CreateParams( 1140 content::WebContents::Create(content::WebContents::CreateParams(
1197 original_contents->GetBrowserContext())); 1141 original_contents->GetBrowserContext()));
1198 ASSERT_TRUE(contents); 1142 ASSERT_TRUE(contents);
1199 contents->SetDelegate(delegate); 1143 contents->SetDelegate(delegate);
(...skipping 12 matching lines...) Expand all
1212 EXPECT_EQ(http_url, entry->GetURL()); 1156 EXPECT_EQ(http_url, entry->GetURL());
1213 EXPECT_TRUE(delegate->console_messages().empty()); 1157 EXPECT_TRUE(delegate->console_messages().empty());
1214 1158
1215 // Trigger the HTTP_SHOW_WARNING state. 1159 // Trigger the HTTP_SHOW_WARNING state.
1216 base::RunLoop first_message; 1160 base::RunLoop first_message;
1217 delegate->set_console_message_callback(first_message.QuitClosure()); 1161 delegate->set_console_message_callback(first_message.QuitClosure());
1218 contents->OnPasswordInputShownOnHttp(); 1162 contents->OnPasswordInputShownOnHttp();
1219 first_message.Run(); 1163 first_message.Run();
1220 1164
1221 // Check that the HTTP_SHOW_WARNING state was actually triggered. 1165 // Check that the HTTP_SHOW_WARNING state was actually triggered.
1222 ChromeSecurityStateModelClient* client = 1166 SecurityStateTabHelper* helper =
1223 ChromeSecurityStateModelClient::FromWebContents(contents); 1167 SecurityStateTabHelper::FromWebContents(contents);
1224 ASSERT_TRUE(client); 1168 ASSERT_TRUE(helper);
1225 security_state::SecurityStateModel::SecurityInfo security_info; 1169 security_state::SecurityStateModel::SecurityInfo security_info;
1226 client->GetSecurityInfo(&security_info); 1170 helper->GetSecurityInfo(&security_info);
1227 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1171 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1228 security_info.security_level); 1172 security_info.security_level);
1229 1173
1230 // Check that the expected console message is present. 1174 // Check that the expected console message is present.
1231 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1175 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1232 delegate->ClearConsoleMessages(); 1176 delegate->ClearConsoleMessages();
1233 1177
1234 // Two subsequent triggers of VisibleSecurityStateChanged -- one on the 1178 // Two subsequent triggers of VisibleSecurityStateChanged -- one on the
1235 // same navigation and one on another navigation -- should only result 1179 // same navigation and one on another navigation -- should only result
1236 // in one additional console message. 1180 // in one additional console message.
1237 contents->OnCreditCardInputShownOnHttp(); 1181 contents->OnCreditCardInputShownOnHttp();
1238 GURL second_http_url = 1182 GURL second_http_url =
1239 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1183 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1240 ui_test_utils::NavigateToURL(delegate, second_http_url); 1184 ui_test_utils::NavigateToURL(delegate, second_http_url);
1241 entry = contents->GetController().GetVisibleEntry(); 1185 entry = contents->GetController().GetVisibleEntry();
1242 ASSERT_TRUE(entry); 1186 ASSERT_TRUE(entry);
1243 EXPECT_EQ(second_http_url, entry->GetURL()); 1187 EXPECT_EQ(second_http_url, entry->GetURL());
1244 1188
1245 base::RunLoop second_message; 1189 base::RunLoop second_message;
1246 delegate->set_console_message_callback(second_message.QuitClosure()); 1190 delegate->set_console_message_callback(second_message.QuitClosure());
1247 contents->OnPasswordInputShownOnHttp(); 1191 contents->OnPasswordInputShownOnHttp();
1248 second_message.Run(); 1192 second_message.Run();
1249 1193
1250 client->GetSecurityInfo(&security_info); 1194 helper->GetSecurityInfo(&security_info);
1251 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1195 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1252 security_info.security_level); 1196 security_info.security_level);
1253 1197
1254 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1198 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1255 } 1199 }
1256 1200
1257 // Tests that console messages are printed upon a call to 1201 // Tests that console messages are printed upon a call to
1258 // GetSecurityInfo() on a NONE page that will be marked 1202 // GetSecurityInfo() on a NONE page that will be marked
1259 // HTTP_SHOW_WARNING in future, exactly once per main-frame navigation. 1203 // HTTP_SHOW_WARNING in future, exactly once per main-frame navigation.
1260 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, ConsoleMessage) { 1204 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, ConsoleMessage) {
1261 ASSERT_TRUE(embedded_test_server()->Start()); 1205 ASSERT_TRUE(embedded_test_server()->Start());
1262 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host()); 1206 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host());
1263 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate( 1207 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1264 Browser::CreateParams(browser()->profile())); 1208 Browser::CreateParams(browser()->profile()));
1265 content::WebContents* original_contents = 1209 content::WebContents* original_contents =
1266 browser()->tab_strip_model()->GetActiveWebContents(); 1210 browser()->tab_strip_model()->GetActiveWebContents();
1267 content::WebContents* contents = 1211 content::WebContents* contents =
1268 content::WebContents::Create(content::WebContents::CreateParams( 1212 content::WebContents::Create(content::WebContents::CreateParams(
1269 original_contents->GetBrowserContext())); 1213 original_contents->GetBrowserContext()));
1270 ASSERT_TRUE(contents); 1214 ASSERT_TRUE(contents);
(...skipping 13 matching lines...) Expand all
1284 EXPECT_EQ(http_url, entry->GetURL()); 1228 EXPECT_EQ(http_url, entry->GetURL());
1285 EXPECT_TRUE(delegate->console_messages().empty()); 1229 EXPECT_TRUE(delegate->console_messages().empty());
1286 1230
1287 // Trigger the a state that will be marked as HTTP_SHOW_WARNING in future. 1231 // Trigger the a state that will be marked as HTTP_SHOW_WARNING in future.
1288 base::RunLoop first_message; 1232 base::RunLoop first_message;
1289 delegate->set_console_message_callback(first_message.QuitClosure()); 1233 delegate->set_console_message_callback(first_message.QuitClosure());
1290 contents->OnPasswordInputShownOnHttp(); 1234 contents->OnPasswordInputShownOnHttp();
1291 first_message.Run(); 1235 first_message.Run();
1292 1236
1293 // Check that the correct state was actually triggered. 1237 // Check that the correct state was actually triggered.
1294 ChromeSecurityStateModelClient* client = 1238 SecurityStateTabHelper* helper =
1295 ChromeSecurityStateModelClient::FromWebContents(contents); 1239 SecurityStateTabHelper::FromWebContents(contents);
1296 ASSERT_TRUE(client); 1240 ASSERT_TRUE(helper);
1297 security_state::SecurityStateModel::SecurityInfo security_info; 1241 security_state::SecurityStateModel::SecurityInfo security_info;
1298 client->GetSecurityInfo(&security_info); 1242 helper->GetSecurityInfo(&security_info);
1299 EXPECT_EQ(security_state::SecurityStateModel::NONE, 1243 EXPECT_EQ(security_state::SecurityStateModel::NONE,
1300 security_info.security_level); 1244 security_info.security_level);
1301 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); 1245 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http);
1302 1246
1303 // Check that the expected console message is present. 1247 // Check that the expected console message is present.
1304 ASSERT_NO_FATAL_FAILURE(CheckForOneFutureHttpWarningConsoleMessage(delegate)); 1248 ASSERT_NO_FATAL_FAILURE(CheckForOneFutureHttpWarningConsoleMessage(delegate));
1305 delegate->ClearConsoleMessages(); 1249 delegate->ClearConsoleMessages();
1306 1250
1307 // Two subsequent triggers of VisibleSecurityStateChanged -- one on the 1251 // Two subsequent triggers of VisibleSecurityStateChanged -- one on the
1308 // same navigation and one on another navigation -- should only result 1252 // same navigation and one on another navigation -- should only result
1309 // in one additional console message. 1253 // in one additional console message.
1310 contents->OnCreditCardInputShownOnHttp(); 1254 contents->OnCreditCardInputShownOnHttp();
1311 GURL second_http_url = 1255 GURL second_http_url =
1312 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1256 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1313 ui_test_utils::NavigateToURL(delegate, second_http_url); 1257 ui_test_utils::NavigateToURL(delegate, second_http_url);
1314 entry = contents->GetController().GetVisibleEntry(); 1258 entry = contents->GetController().GetVisibleEntry();
1315 ASSERT_TRUE(entry); 1259 ASSERT_TRUE(entry);
1316 EXPECT_EQ(second_http_url, entry->GetURL()); 1260 EXPECT_EQ(second_http_url, entry->GetURL());
1317 1261
1318 base::RunLoop second_message; 1262 base::RunLoop second_message;
1319 delegate->set_console_message_callback(second_message.QuitClosure()); 1263 delegate->set_console_message_callback(second_message.QuitClosure());
1320 contents->OnPasswordInputShownOnHttp(); 1264 contents->OnPasswordInputShownOnHttp();
1321 second_message.Run(); 1265 second_message.Run();
1322 1266
1323 client->GetSecurityInfo(&security_info); 1267 helper->GetSecurityInfo(&security_info);
1324 EXPECT_EQ(security_state::SecurityStateModel::NONE, 1268 EXPECT_EQ(security_state::SecurityStateModel::NONE,
1325 security_info.security_level); 1269 security_info.security_level);
1326 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http); 1270 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http);
1327 1271
1328 ASSERT_NO_FATAL_FAILURE(CheckForOneFutureHttpWarningConsoleMessage(delegate)); 1272 ASSERT_NO_FATAL_FAILURE(CheckForOneFutureHttpWarningConsoleMessage(delegate));
1329 } 1273 }
1330 1274
1331 // Tests that additional HTTP_SHOW_WARNING console messages are not 1275 // Tests that additional HTTP_SHOW_WARNING console messages are not
1332 // printed after subframe navigations. 1276 // printed after subframe navigations.
1333 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 1277 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
1334 ConsoleMessageNotPrintedForFrameNavigation) { 1278 ConsoleMessageNotPrintedForFrameNavigation) {
1335 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate( 1279 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1336 Browser::CreateParams(browser()->profile())); 1280 Browser::CreateParams(browser()->profile()));
1337 content::WebContents* original_contents = 1281 content::WebContents* original_contents =
1338 browser()->tab_strip_model()->GetActiveWebContents(); 1282 browser()->tab_strip_model()->GetActiveWebContents();
1339 content::WebContents* contents = 1283 content::WebContents* contents =
1340 content::WebContents::Create(content::WebContents::CreateParams( 1284 content::WebContents::Create(content::WebContents::CreateParams(
1341 original_contents->GetBrowserContext())); 1285 original_contents->GetBrowserContext()));
1342 ASSERT_TRUE(contents); 1286 ASSERT_TRUE(contents);
1343 contents->SetDelegate(delegate); 1287 contents->SetDelegate(delegate);
(...skipping 12 matching lines...) Expand all
1356 EXPECT_EQ(http_url, entry->GetURL()); 1300 EXPECT_EQ(http_url, entry->GetURL());
1357 EXPECT_TRUE(delegate->console_messages().empty()); 1301 EXPECT_TRUE(delegate->console_messages().empty());
1358 1302
1359 // Trigger the HTTP_SHOW_WARNING state. 1303 // Trigger the HTTP_SHOW_WARNING state.
1360 base::RunLoop first_message; 1304 base::RunLoop first_message;
1361 delegate->set_console_message_callback(first_message.QuitClosure()); 1305 delegate->set_console_message_callback(first_message.QuitClosure());
1362 contents->OnPasswordInputShownOnHttp(); 1306 contents->OnPasswordInputShownOnHttp();
1363 first_message.Run(); 1307 first_message.Run();
1364 1308
1365 // Check that the HTTP_SHOW_WARNING state was actually triggered. 1309 // Check that the HTTP_SHOW_WARNING state was actually triggered.
1366 ChromeSecurityStateModelClient* client = 1310 SecurityStateTabHelper* helper =
1367 ChromeSecurityStateModelClient::FromWebContents(contents); 1311 SecurityStateTabHelper::FromWebContents(contents);
1368 ASSERT_TRUE(client); 1312 ASSERT_TRUE(helper);
1369 security_state::SecurityStateModel::SecurityInfo security_info; 1313 security_state::SecurityStateModel::SecurityInfo security_info;
1370 client->GetSecurityInfo(&security_info); 1314 helper->GetSecurityInfo(&security_info);
1371 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1315 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1372 security_info.security_level); 1316 security_info.security_level);
1373 1317
1374 // Check that the expected console message is present. 1318 // Check that the expected console message is present.
1375 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1319 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1376 delegate->ClearConsoleMessages(); 1320 delegate->ClearConsoleMessages();
1377 1321
1378 // Navigate the subframe and trigger VisibleSecurityStateChanged 1322 // Navigate the subframe and trigger VisibleSecurityStateChanged
1379 // again. While the security level is still HTTP_SHOW_WARNING, an 1323 // again. While the security level is still HTTP_SHOW_WARNING, an
1380 // additional console message should not be logged because there was 1324 // additional console message should not be logged because there was
(...skipping 18 matching lines...) Expand all
1399 ui_test_utils::NavigateToURL(delegate, second_http_url); 1343 ui_test_utils::NavigateToURL(delegate, second_http_url);
1400 entry = contents->GetController().GetVisibleEntry(); 1344 entry = contents->GetController().GetVisibleEntry();
1401 ASSERT_TRUE(entry); 1345 ASSERT_TRUE(entry);
1402 EXPECT_EQ(second_http_url, entry->GetURL()); 1346 EXPECT_EQ(second_http_url, entry->GetURL());
1403 1347
1404 base::RunLoop second_message; 1348 base::RunLoop second_message;
1405 delegate->set_console_message_callback(second_message.QuitClosure()); 1349 delegate->set_console_message_callback(second_message.QuitClosure());
1406 contents->OnPasswordInputShownOnHttp(); 1350 contents->OnPasswordInputShownOnHttp();
1407 second_message.Run(); 1351 second_message.Run();
1408 1352
1409 client->GetSecurityInfo(&security_info); 1353 helper->GetSecurityInfo(&security_info);
1410 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1354 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1411 security_info.security_level); 1355 security_info.security_level);
1412 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1356 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1413 } 1357 }
1414 1358
1415 // Tests that additional HTTP_SHOW_WARNING console messages are not 1359 // Tests that additional HTTP_SHOW_WARNING console messages are not
1416 // printed after pushState navigations. 1360 // printed after pushState navigations.
1417 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 1361 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch,
1418 ConsoleMessageNotPrintedForPushStateNavigation) { 1362 ConsoleMessageNotPrintedForPushStateNavigation) {
1419 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate( 1363 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1420 Browser::CreateParams(browser()->profile())); 1364 Browser::CreateParams(browser()->profile()));
1421 content::WebContents* original_contents = 1365 content::WebContents* original_contents =
1422 browser()->tab_strip_model()->GetActiveWebContents(); 1366 browser()->tab_strip_model()->GetActiveWebContents();
1423 content::WebContents* contents = 1367 content::WebContents* contents =
1424 content::WebContents::Create(content::WebContents::CreateParams( 1368 content::WebContents::Create(content::WebContents::CreateParams(
1425 original_contents->GetBrowserContext())); 1369 original_contents->GetBrowserContext()));
1426 ASSERT_TRUE(contents); 1370 ASSERT_TRUE(contents);
1427 contents->SetDelegate(delegate); 1371 contents->SetDelegate(delegate);
(...skipping 12 matching lines...) Expand all
1440 EXPECT_EQ(http_url, entry->GetURL()); 1384 EXPECT_EQ(http_url, entry->GetURL());
1441 EXPECT_TRUE(delegate->console_messages().empty()); 1385 EXPECT_TRUE(delegate->console_messages().empty());
1442 1386
1443 // Trigger the HTTP_SHOW_WARNING state. 1387 // Trigger the HTTP_SHOW_WARNING state.
1444 base::RunLoop first_message; 1388 base::RunLoop first_message;
1445 delegate->set_console_message_callback(first_message.QuitClosure()); 1389 delegate->set_console_message_callback(first_message.QuitClosure());
1446 contents->OnPasswordInputShownOnHttp(); 1390 contents->OnPasswordInputShownOnHttp();
1447 first_message.Run(); 1391 first_message.Run();
1448 1392
1449 // Check that the HTTP_SHOW_WARNING state was actually triggered. 1393 // Check that the HTTP_SHOW_WARNING state was actually triggered.
1450 ChromeSecurityStateModelClient* client = 1394 SecurityStateTabHelper* helper =
1451 ChromeSecurityStateModelClient::FromWebContents(contents); 1395 SecurityStateTabHelper::FromWebContents(contents);
1452 ASSERT_TRUE(client); 1396 ASSERT_TRUE(helper);
1453 security_state::SecurityStateModel::SecurityInfo security_info; 1397 security_state::SecurityStateModel::SecurityInfo security_info;
1454 client->GetSecurityInfo(&security_info); 1398 helper->GetSecurityInfo(&security_info);
1455 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1399 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1456 security_info.security_level); 1400 security_info.security_level);
1457 1401
1458 // Check that the expected console message is present. 1402 // Check that the expected console message is present.
1459 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1403 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1460 delegate->ClearConsoleMessages(); 1404 delegate->ClearConsoleMessages();
1461 1405
1462 // Navigate with pushState and trigger VisibleSecurityStateChanged 1406 // Navigate with pushState and trigger VisibleSecurityStateChanged
1463 // again. While the security level is still HTTP_SHOW_WARNING, an 1407 // again. While the security level is still HTTP_SHOW_WARNING, an
1464 // additional console message should not be logged because there was 1408 // additional console message should not be logged because there was
(...skipping 13 matching lines...) Expand all
1478 ui_test_utils::NavigateToURL(delegate, second_http_url); 1422 ui_test_utils::NavigateToURL(delegate, second_http_url);
1479 entry = contents->GetController().GetVisibleEntry(); 1423 entry = contents->GetController().GetVisibleEntry();
1480 ASSERT_TRUE(entry); 1424 ASSERT_TRUE(entry);
1481 EXPECT_EQ(second_http_url, entry->GetURL()); 1425 EXPECT_EQ(second_http_url, entry->GetURL());
1482 1426
1483 base::RunLoop second_message; 1427 base::RunLoop second_message;
1484 delegate->set_console_message_callback(second_message.QuitClosure()); 1428 delegate->set_console_message_callback(second_message.QuitClosure());
1485 contents->OnPasswordInputShownOnHttp(); 1429 contents->OnPasswordInputShownOnHttp();
1486 second_message.Run(); 1430 second_message.Run();
1487 1431
1488 client->GetSecurityInfo(&security_info); 1432 helper->GetSecurityInfo(&security_info);
1489 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1433 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1490 security_info.security_level); 1434 security_info.security_level);
1491 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1435 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1492 } 1436 }
1493 1437
1494 // Tests that the SecurityStateModel for a WebContents is up to date 1438 // Tests that the SecurityStateModel for a WebContents is up to date
1495 // when the WebContents is inserted into a Browser's TabStripModel. 1439 // when the WebContents is inserted into a Browser's TabStripModel.
1496 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, AddedTab) { 1440 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, AddedTab) {
1497 ASSERT_TRUE(https_server_.Start()); 1441 ASSERT_TRUE(https_server_.Start());
1498 SetUpMockCertVerifierForHttpsServer(0, net::OK); 1442 SetUpMockCertVerifierForHttpsServer(0, net::OK);
1499 1443
1500 content::WebContents* tab = 1444 content::WebContents* tab =
1501 browser()->tab_strip_model()->GetActiveWebContents(); 1445 browser()->tab_strip_model()->GetActiveWebContents();
1502 ASSERT_TRUE(tab); 1446 ASSERT_TRUE(tab);
1503 1447
1504 content::WebContents* new_contents = content::WebContents::Create( 1448 content::WebContents* new_contents = content::WebContents::Create(
1505 content::WebContents::CreateParams(tab->GetBrowserContext())); 1449 content::WebContents::CreateParams(tab->GetBrowserContext()));
1506 content::NavigationController& controller = new_contents->GetController(); 1450 content::NavigationController& controller = new_contents->GetController();
1507 ChromeSecurityStateModelClient::CreateForWebContents(new_contents); 1451 SecurityStateTabHelper::CreateForWebContents(new_contents);
1508 CheckSecurityInfoForNonSecure(new_contents); 1452 CheckSecurityInfoForNonSecure(new_contents);
1509 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(), 1453 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(),
1510 ui::PAGE_TRANSITION_TYPED, std::string()); 1454 ui::PAGE_TRANSITION_TYPED, std::string());
1511 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); 1455 EXPECT_TRUE(content::WaitForLoadStop(new_contents));
1512 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, 1456 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE,
1513 SecurityStateModel::NO_DEPRECATED_SHA1, 1457 SecurityStateModel::NO_DEPRECATED_SHA1,
1514 SecurityStateModel::CONTENT_STATUS_NONE, false, 1458 SecurityStateModel::CONTENT_STATUS_NONE, false,
1515 false /* expect cert status error */); 1459 false /* expect cert status error */);
1516 1460
1517 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, 1461 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents,
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 // connection, the SCTs verification statuses are exposed on the 1975 // connection, the SCTs verification statuses are exposed on the
2032 // SecurityInfo. 1976 // SecurityInfo.
2033 IN_PROC_BROWSER_TEST_F(BrowserTestURLRequestWithSCTs, 1977 IN_PROC_BROWSER_TEST_F(BrowserTestURLRequestWithSCTs,
2034 SecurityInfoWithSCTsAttached) { 1978 SecurityInfoWithSCTsAttached) {
2035 ui_test_utils::NavigateToURL( 1979 ui_test_utils::NavigateToURL(
2036 browser(), GURL(std::string("https://") + kMockHostnameWithSCTs)); 1980 browser(), GURL(std::string("https://") + kMockHostnameWithSCTs));
2037 1981
2038 content::WebContents* web_contents = 1982 content::WebContents* web_contents =
2039 browser()->tab_strip_model()->GetActiveWebContents(); 1983 browser()->tab_strip_model()->GetActiveWebContents();
2040 ASSERT_TRUE(web_contents); 1984 ASSERT_TRUE(web_contents);
2041 ChromeSecurityStateModelClient* model_client = 1985 SecurityStateTabHelper* helper =
2042 ChromeSecurityStateModelClient::FromWebContents(web_contents); 1986 SecurityStateTabHelper::FromWebContents(web_contents);
2043 ASSERT_TRUE(model_client); 1987 ASSERT_TRUE(helper);
2044 SecurityStateModel::SecurityInfo security_info; 1988 SecurityStateModel::SecurityInfo security_info;
2045 model_client->GetSecurityInfo(&security_info); 1989 helper->GetSecurityInfo(&security_info);
2046 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level); 1990 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level);
2047 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); 1991 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses);
2048 } 1992 }
2049 1993
2050 } // namespace 1994 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698