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

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

Issue 2616553002: Remove obsolete SHA-1 UX elements (Closed)
Patch Set: Address Emily's feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ssl/security_state_tab_helper.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"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 base::string16 secure_description = l10n_util::GetStringFUTF16( 198 base::string16 secure_description = l10n_util::GetStringFUTF16(
199 IDS_STRONG_SSL_DESCRIPTION, description_replacements, nullptr); 199 IDS_STRONG_SSL_DESCRIPTION, description_replacements, nullptr);
200 200
201 EXPECT_EQ(secure_description, 201 EXPECT_EQ(secure_description,
202 base::ASCIIToUTF16(secure_explanations.back().description)); 202 base::ASCIIToUTF16(secure_explanations.back().description));
203 } 203 }
204 204
205 void CheckSecurityInfoForSecure( 205 void CheckSecurityInfoForSecure(
206 content::WebContents* contents, 206 content::WebContents* contents,
207 security_state::SecurityLevel expect_security_level, 207 security_state::SecurityLevel expect_security_level,
208 security_state::SHA1DeprecationStatus expect_sha1_status, 208 bool expect_sha1_in_chain,
209 security_state::ContentStatus expect_mixed_content_status, 209 security_state::ContentStatus expect_mixed_content_status,
210 bool pkp_bypassed, 210 bool pkp_bypassed,
211 bool expect_cert_error) { 211 bool expect_cert_error) {
212 ASSERT_TRUE(contents); 212 ASSERT_TRUE(contents);
213 213
214 SecurityStateTabHelper* helper = 214 SecurityStateTabHelper* helper =
215 SecurityStateTabHelper::FromWebContents(contents); 215 SecurityStateTabHelper::FromWebContents(contents);
216 ASSERT_TRUE(helper); 216 ASSERT_TRUE(helper);
217 security_state::SecurityInfo security_info; 217 security_state::SecurityInfo security_info;
218 helper->GetSecurityInfo(&security_info); 218 helper->GetSecurityInfo(&security_info);
219 EXPECT_EQ(expect_security_level, security_info.security_level); 219 EXPECT_EQ(expect_security_level, security_info.security_level);
220 EXPECT_EQ(expect_sha1_status, security_info.sha1_deprecation_status); 220 EXPECT_EQ(expect_sha1_in_chain, security_info.sha1_in_chain);
221 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status); 221 EXPECT_EQ(expect_mixed_content_status, security_info.mixed_content_status);
222 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 222 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
223 EXPECT_TRUE(security_info.scheme_is_cryptographic); 223 EXPECT_TRUE(security_info.scheme_is_cryptographic);
224 EXPECT_EQ(pkp_bypassed, security_info.pkp_bypassed); 224 EXPECT_EQ(pkp_bypassed, security_info.pkp_bypassed);
225 EXPECT_EQ(expect_cert_error, 225 EXPECT_EQ(expect_cert_error,
226 net::IsCertStatusError(security_info.cert_status)); 226 net::IsCertStatusError(security_info.cert_status));
227 EXPECT_GT(security_info.security_bits, 0); 227 EXPECT_GT(security_info.security_bits, 0);
228 EXPECT_TRUE(!!security_info.certificate); 228 EXPECT_TRUE(!!security_info.certificate);
229 } 229 }
230 230
231 void CheckSecurityInfoForNonSecure(content::WebContents* contents) { 231 void CheckSecurityInfoForNonSecure(content::WebContents* contents) {
232 ASSERT_TRUE(contents); 232 ASSERT_TRUE(contents);
233 233
234 SecurityStateTabHelper* helper = 234 SecurityStateTabHelper* helper =
235 SecurityStateTabHelper::FromWebContents(contents); 235 SecurityStateTabHelper::FromWebContents(contents);
236 ASSERT_TRUE(helper); 236 ASSERT_TRUE(helper);
237 security_state::SecurityInfo security_info; 237 security_state::SecurityInfo security_info;
238 helper->GetSecurityInfo(&security_info); 238 helper->GetSecurityInfo(&security_info);
239 EXPECT_EQ(security_state::NONE, security_info.security_level); 239 EXPECT_EQ(security_state::NONE, security_info.security_level);
240 EXPECT_EQ(security_state::NO_DEPRECATED_SHA1, 240 EXPECT_EQ(false, security_info.sha1_in_chain);
estark 2017/01/08 16:39:58 nit: EXPECT_FALSE
elawrence 2017/01/09 18:13:11 Done.
241 security_info.sha1_deprecation_status);
242 EXPECT_EQ(security_state::CONTENT_STATUS_NONE, 241 EXPECT_EQ(security_state::CONTENT_STATUS_NONE,
243 security_info.mixed_content_status); 242 security_info.mixed_content_status);
244 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 243 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
245 EXPECT_FALSE(security_info.scheme_is_cryptographic); 244 EXPECT_FALSE(security_info.scheme_is_cryptographic);
246 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 245 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
247 EXPECT_EQ(-1, security_info.security_bits); 246 EXPECT_EQ(-1, security_info.security_bits);
248 EXPECT_FALSE(!!security_info.certificate); 247 EXPECT_FALSE(!!security_info.certificate);
249 } 248 }
250 249
251 void ProceedThroughInterstitial(content::WebContents* tab) { 250 void ProceedThroughInterstitial(content::WebContents* tab) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 content::WebContents* contents = 361 content::WebContents* contents =
363 browser()->tab_strip_model()->GetActiveWebContents(); 362 browser()->tab_strip_model()->GetActiveWebContents();
364 ASSERT_TRUE(contents); 363 ASSERT_TRUE(contents);
365 364
366 SecurityStateTabHelper* helper = 365 SecurityStateTabHelper* helper =
367 SecurityStateTabHelper::FromWebContents(contents); 366 SecurityStateTabHelper::FromWebContents(contents);
368 ASSERT_TRUE(helper); 367 ASSERT_TRUE(helper);
369 security_state::SecurityInfo security_info; 368 security_state::SecurityInfo security_info;
370 helper->GetSecurityInfo(&security_info); 369 helper->GetSecurityInfo(&security_info);
371 EXPECT_EQ(security_state::NONE, security_info.security_level); 370 EXPECT_EQ(security_state::NONE, security_info.security_level);
372 EXPECT_EQ(security_state::NO_DEPRECATED_SHA1, 371 EXPECT_EQ(false, security_info.sha1_in_chain);
estark 2017/01/08 16:39:58 nit: EXPECT_FALSE
elawrence 2017/01/09 18:13:11 Done.
373 security_info.sha1_deprecation_status);
374 EXPECT_EQ(security_state::CONTENT_STATUS_NONE, 372 EXPECT_EQ(security_state::CONTENT_STATUS_NONE,
375 security_info.mixed_content_status); 373 security_info.mixed_content_status);
376 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); 374 EXPECT_TRUE(security_info.sct_verify_statuses.empty());
377 EXPECT_FALSE(security_info.scheme_is_cryptographic); 375 EXPECT_FALSE(security_info.scheme_is_cryptographic);
378 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 376 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
379 EXPECT_FALSE(!!security_info.certificate); 377 EXPECT_FALSE(!!security_info.certificate);
380 EXPECT_EQ(-1, security_info.security_bits); 378 EXPECT_EQ(-1, security_info.security_bits);
381 EXPECT_EQ(0, security_info.connection_status); 379 EXPECT_EQ(0, security_info.connection_status);
382 } 380 }
383 381
384 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpsPage) { 382 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpsPage) {
385 ASSERT_TRUE(https_server_.Start()); 383 ASSERT_TRUE(https_server_.Start());
386 SetUpMockCertVerifierForHttpsServer(0, net::OK); 384 SetUpMockCertVerifierForHttpsServer(0, net::OK);
387 385
388 ui_test_utils::NavigateToURL(browser(), 386 ui_test_utils::NavigateToURL(browser(),
389 https_server_.GetURL("/ssl/google.html")); 387 https_server_.GetURL("/ssl/google.html"));
390 CheckSecurityInfoForSecure( 388 CheckSecurityInfoForSecure(
391 browser()->tab_strip_model()->GetActiveWebContents(), 389 browser()->tab_strip_model()->GetActiveWebContents(),
392 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 390 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
393 security_state::CONTENT_STATUS_NONE, false,
394 false /* expect cert status error */); 391 false /* expect cert status error */);
395 } 392 }
396 393
397 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1Certificate) { 394 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1Certificate) {
398 ASSERT_TRUE(https_server_.Start()); 395 ASSERT_TRUE(https_server_.Start());
399 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 396 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
400 net::OK); 397 net::OK);
401 398
402 ui_test_utils::NavigateToURL(browser(), 399 ui_test_utils::NavigateToURL(browser(),
403 https_server_.GetURL("/ssl/google.html")); 400 https_server_.GetURL("/ssl/google.html"));
404 CheckSecurityInfoForSecure( 401 CheckSecurityInfoForSecure(
405 browser()->tab_strip_model()->GetActiveWebContents(), 402 browser()->tab_strip_model()->GetActiveWebContents(),
406 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 403 security_state::NONE, true, security_state::CONTENT_STATUS_NONE, false,
estark 2017/01/08 16:39:58 Could you add: - a SecurityStyleTestObserver to th
elawrence 2017/01/09 18:13:11 Done.
407 security_state::CONTENT_STATUS_NONE, false,
408 false /* expect cert status error */); 404 false /* expect cert status error */);
409 } 405 }
410 406
411 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) { 407 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContent) {
412 ASSERT_TRUE(embedded_test_server()->Start()); 408 ASSERT_TRUE(embedded_test_server()->Start());
413 ASSERT_TRUE(https_server_.Start()); 409 ASSERT_TRUE(https_server_.Start());
414 SetUpMockCertVerifierForHttpsServer(0, net::OK); 410 SetUpMockCertVerifierForHttpsServer(0, net::OK);
415 host_resolver()->AddRule("example.test", 411 host_resolver()->AddRule("example.test",
416 https_server_.GetURL("/title1.html").host()); 412 https_server_.GetURL("/title1.html").host());
417 413
418 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 414 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
419 replacement_pair.set_host("example.test"); 415 replacement_pair.set_host("example.test");
420 416
421 // Navigate to an HTTPS page that displays mixed content. 417 // Navigate to an HTTPS page that displays mixed content.
422 std::string replacement_path; 418 std::string replacement_path;
423 GetFilePathWithHostAndPortReplacement( 419 GetFilePathWithHostAndPortReplacement(
424 "/ssl/page_displays_insecure_content.html", replacement_pair, 420 "/ssl/page_displays_insecure_content.html", replacement_pair,
425 &replacement_path); 421 &replacement_path);
426 ui_test_utils::NavigateToURL(browser(), 422 ui_test_utils::NavigateToURL(browser(),
427 https_server_.GetURL(replacement_path)); 423 https_server_.GetURL(replacement_path));
428 CheckSecurityInfoForSecure( 424 CheckSecurityInfoForSecure(
429 browser()->tab_strip_model()->GetActiveWebContents(), 425 browser()->tab_strip_model()->GetActiveWebContents(),
430 security_state::NONE, security_state::NO_DEPRECATED_SHA1, 426 security_state::NONE, false, security_state::CONTENT_STATUS_DISPLAYED,
431 security_state::CONTENT_STATUS_DISPLAYED, false, 427 false, false /* expect cert status error */);
432 false /* expect cert status error */);
433 428
434 // Navigate to an HTTPS page that displays mixed content dynamically. 429 // Navigate to an HTTPS page that displays mixed content dynamically.
435 GetFilePathWithHostAndPortReplacement( 430 GetFilePathWithHostAndPortReplacement(
436 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair, 431 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
437 &replacement_path); 432 &replacement_path);
438 ui_test_utils::NavigateToURL(browser(), 433 ui_test_utils::NavigateToURL(browser(),
439 https_server_.GetURL(replacement_path)); 434 https_server_.GetURL(replacement_path));
440 CheckSecurityInfoForSecure( 435 CheckSecurityInfoForSecure(
441 browser()->tab_strip_model()->GetActiveWebContents(), 436 browser()->tab_strip_model()->GetActiveWebContents(),
442 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 437 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
443 security_state::CONTENT_STATUS_NONE, false,
444 false /* expect cert status error */); 438 false /* expect cert status error */);
445 // Load the insecure image. 439 // Load the insecure image.
446 bool js_result = false; 440 bool js_result = false;
447 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 441 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
448 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 442 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
449 &js_result)); 443 &js_result));
450 EXPECT_TRUE(js_result); 444 EXPECT_TRUE(js_result);
451 CheckSecurityInfoForSecure( 445 CheckSecurityInfoForSecure(
452 browser()->tab_strip_model()->GetActiveWebContents(), 446 browser()->tab_strip_model()->GetActiveWebContents(),
453 security_state::NONE, security_state::NO_DEPRECATED_SHA1, 447 security_state::NONE, false, security_state::CONTENT_STATUS_DISPLAYED,
454 security_state::CONTENT_STATUS_DISPLAYED, false, 448 false, false /* expect cert status error */);
455 false /* expect cert status error */);
456 449
457 // Navigate to an HTTPS page that runs mixed content. 450 // Navigate to an HTTPS page that runs mixed content.
458 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html", 451 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
459 replacement_pair, &replacement_path); 452 replacement_pair, &replacement_path);
460 ui_test_utils::NavigateToURL(browser(), 453 ui_test_utils::NavigateToURL(browser(),
461 https_server_.GetURL(replacement_path)); 454 https_server_.GetURL(replacement_path));
462 CheckSecurityInfoForSecure( 455 CheckSecurityInfoForSecure(
463 browser()->tab_strip_model()->GetActiveWebContents(), 456 browser()->tab_strip_model()->GetActiveWebContents(),
464 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 457 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_RAN,
465 security_state::CONTENT_STATUS_RAN, false, 458 false, false /* expect cert status error */);
466 false /* expect cert status error */);
467 459
468 // Navigate to an HTTPS page that runs and displays mixed content. 460 // Navigate to an HTTPS page that runs and displays mixed content.
469 GetFilePathWithHostAndPortReplacement( 461 GetFilePathWithHostAndPortReplacement(
470 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair, 462 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
471 &replacement_path); 463 &replacement_path);
472 ui_test_utils::NavigateToURL(browser(), 464 ui_test_utils::NavigateToURL(browser(),
473 https_server_.GetURL(replacement_path)); 465 https_server_.GetURL(replacement_path));
474 CheckSecurityInfoForSecure( 466 CheckSecurityInfoForSecure(
475 browser()->tab_strip_model()->GetActiveWebContents(), 467 browser()->tab_strip_model()->GetActiveWebContents(),
476 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 468 security_state::DANGEROUS, false,
477 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 469 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
478 false /* expect cert status error */); 470 false /* expect cert status error */);
479 471
480 // Navigate to an HTTPS page that runs mixed content in an iframe. 472 // Navigate to an HTTPS page that runs mixed content in an iframe.
481 net::HostPortPair host_port_pair = 473 net::HostPortPair host_port_pair =
482 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 474 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
483 host_port_pair.set_host("different-host.test"); 475 host_port_pair.set_host("different-host.test");
484 host_resolver()->AddRule("different-host.test", 476 host_resolver()->AddRule("different-host.test",
485 https_server_.GetURL("/title1.html").host()); 477 https_server_.GetURL("/title1.html").host());
486 host_resolver()->AddRule( 478 host_resolver()->AddRule(
487 "different-http-host.test", 479 "different-http-host.test",
488 embedded_test_server()->GetURL("/title1.html").host()); 480 embedded_test_server()->GetURL("/title1.html").host());
489 GetFilePathWithHostAndPortReplacement( 481 GetFilePathWithHostAndPortReplacement(
490 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, 482 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair,
491 &replacement_path); 483 &replacement_path);
492 ui_test_utils::NavigateToURL(browser(), 484 ui_test_utils::NavigateToURL(browser(),
493 https_server_.GetURL(replacement_path)); 485 https_server_.GetURL(replacement_path));
494 CheckSecurityInfoForSecure( 486 CheckSecurityInfoForSecure(
495 browser()->tab_strip_model()->GetActiveWebContents(), 487 browser()->tab_strip_model()->GetActiveWebContents(),
496 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 488 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_RAN,
497 security_state::CONTENT_STATUS_RAN, false, 489 false, false /* expect cert status error */);
498 false /* expect cert status error */);
499 } 490 }
500 491
501 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, 492 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
502 ActiveContentWithCertErrors) { 493 ActiveContentWithCertErrors) {
503 ASSERT_TRUE(https_server_.Start()); 494 ASSERT_TRUE(https_server_.Start());
504 SetUpMockCertVerifierForHttpsServer(0, net::OK); 495 SetUpMockCertVerifierForHttpsServer(0, net::OK);
505 496
506 // Navigate to an HTTPS page and simulate active content with 497 // Navigate to an HTTPS page and simulate active content with
507 // certificate errors. 498 // certificate errors.
508 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); 499 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ASSERT_TRUE(helper); 571 ASSERT_TRUE(helper);
581 security_state::SecurityInfo security_info; 572 security_state::SecurityInfo security_info;
582 helper->GetSecurityInfo(&security_info); 573 helper->GetSecurityInfo(&security_info);
583 574
584 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); 575 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status));
585 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level); 576 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
586 EXPECT_EQ(security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, 577 EXPECT_EQ(security_state::CONTENT_STATUS_DISPLAYED_AND_RAN,
587 security_info.content_with_cert_errors_status); 578 security_info.content_with_cert_errors_status);
588 } 579 }
589 580
590 // Same as the test above but with a long-lived SHA1 cert. 581 // Same as the test above but with a SHA1 cert.
estark 2017/01/08 16:39:58 nit: while you are here, could you change "test ab
elawrence 2017/01/09 18:13:11 Done.
591 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithSHA1Cert) { 582 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentWithSHA1Cert) {
592 ASSERT_TRUE(embedded_test_server()->Start()); 583 ASSERT_TRUE(embedded_test_server()->Start());
593 ASSERT_TRUE(https_server_.Start()); 584 ASSERT_TRUE(https_server_.Start());
594 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, 585 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT,
595 net::OK); 586 net::OK);
596 587
597 host_resolver()->AddRule("example.test", 588 host_resolver()->AddRule("example.test",
598 https_server_.GetURL("/title1.html").host()); 589 https_server_.GetURL("/title1.html").host());
599 590
600 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); 591 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair();
601 replacement_pair.set_host("example.test"); 592 replacement_pair.set_host("example.test");
602 593
603 // Navigate to an HTTPS page that displays mixed content. 594 // Navigate to an HTTPS page that displays mixed content.
604 std::string replacement_path; 595 std::string replacement_path;
605 GetFilePathWithHostAndPortReplacement( 596 GetFilePathWithHostAndPortReplacement(
606 "/ssl/page_displays_insecure_content.html", replacement_pair, 597 "/ssl/page_displays_insecure_content.html", replacement_pair,
607 &replacement_path); 598 &replacement_path);
608 ui_test_utils::NavigateToURL(browser(), 599 ui_test_utils::NavigateToURL(browser(),
609 https_server_.GetURL(replacement_path)); 600 https_server_.GetURL(replacement_path));
610 CheckSecurityInfoForSecure( 601 CheckSecurityInfoForSecure(
611 browser()->tab_strip_model()->GetActiveWebContents(), 602 browser()->tab_strip_model()->GetActiveWebContents(),
612 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 603 security_state::NONE, true, security_state::CONTENT_STATUS_DISPLAYED,
613 security_state::CONTENT_STATUS_DISPLAYED, false, 604 false, false /* expect cert status error */);
614 false /* expect cert status error */);
615 605
616 // Navigate to an HTTPS page that displays mixed content dynamically. 606 // Navigate to an HTTPS page that displays mixed content dynamically.
617 GetFilePathWithHostAndPortReplacement( 607 GetFilePathWithHostAndPortReplacement(
618 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair, 608 "/ssl/page_with_dynamic_insecure_content.html", replacement_pair,
619 &replacement_path); 609 &replacement_path);
620 ui_test_utils::NavigateToURL(browser(), 610 ui_test_utils::NavigateToURL(browser(),
621 https_server_.GetURL(replacement_path)); 611 https_server_.GetURL(replacement_path));
622 CheckSecurityInfoForSecure( 612 CheckSecurityInfoForSecure(
623 browser()->tab_strip_model()->GetActiveWebContents(), 613 browser()->tab_strip_model()->GetActiveWebContents(),
624 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 614 security_state::NONE, true, security_state::CONTENT_STATUS_NONE, false,
625 security_state::CONTENT_STATUS_NONE, false,
626 false /* expect cert status error */); 615 false /* expect cert status error */);
627 // Load the insecure image. 616 // Load the insecure image.
628 bool js_result = false; 617 bool js_result = false;
629 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 618 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
630 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", 619 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();",
631 &js_result)); 620 &js_result));
632 EXPECT_TRUE(js_result); 621 EXPECT_TRUE(js_result);
633 CheckSecurityInfoForSecure( 622 CheckSecurityInfoForSecure(
634 browser()->tab_strip_model()->GetActiveWebContents(), 623 browser()->tab_strip_model()->GetActiveWebContents(),
635 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 624 security_state::NONE, true, security_state::CONTENT_STATUS_DISPLAYED,
636 security_state::CONTENT_STATUS_DISPLAYED, false, 625 false, false /* expect cert status error */);
637 false /* expect cert status error */);
638 626
639 // Navigate to an HTTPS page that runs mixed content. 627 // Navigate to an HTTPS page that runs mixed content.
640 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html", 628 GetFilePathWithHostAndPortReplacement("/ssl/page_runs_insecure_content.html",
641 replacement_pair, &replacement_path); 629 replacement_pair, &replacement_path);
642 ui_test_utils::NavigateToURL(browser(), 630 ui_test_utils::NavigateToURL(browser(),
643 https_server_.GetURL(replacement_path)); 631 https_server_.GetURL(replacement_path));
644 CheckSecurityInfoForSecure( 632 CheckSecurityInfoForSecure(
645 browser()->tab_strip_model()->GetActiveWebContents(), 633 browser()->tab_strip_model()->GetActiveWebContents(),
646 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 634 security_state::DANGEROUS, true, security_state::CONTENT_STATUS_RAN,
647 security_state::CONTENT_STATUS_RAN, false, 635 false, false /* expect cert status error */);
648 false /* expect cert status error */);
649 636
650 // Navigate to an HTTPS page that runs and displays mixed content. 637 // Navigate to an HTTPS page that runs and displays mixed content.
651 GetFilePathWithHostAndPortReplacement( 638 GetFilePathWithHostAndPortReplacement(
652 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair, 639 "/ssl/page_runs_and_displays_insecure_content.html", replacement_pair,
653 &replacement_path); 640 &replacement_path);
654 ui_test_utils::NavigateToURL(browser(), 641 ui_test_utils::NavigateToURL(browser(),
655 https_server_.GetURL(replacement_path)); 642 https_server_.GetURL(replacement_path));
656 CheckSecurityInfoForSecure( 643 CheckSecurityInfoForSecure(
657 browser()->tab_strip_model()->GetActiveWebContents(), 644 browser()->tab_strip_model()->GetActiveWebContents(),
658 security_state::DANGEROUS, security_state::DEPRECATED_SHA1_MAJOR, 645 security_state::DANGEROUS, true,
659 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false, 646 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN, false,
660 false /* expect cert status error */); 647 false /* expect cert status error */);
661 } 648 }
662 649
663 // Tests that the Content Security Policy block-all-mixed-content 650 // Tests that the Content Security Policy block-all-mixed-content
664 // directive stops mixed content from running. 651 // directive stops mixed content from running.
665 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) { 652 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, MixedContentStrictBlocking) {
666 ASSERT_TRUE(https_server_.Start()); 653 ASSERT_TRUE(https_server_.Start());
667 SetUpMockCertVerifierForHttpsServer(0, net::OK); 654 SetUpMockCertVerifierForHttpsServer(0, net::OK);
668 655
669 // Navigate to an HTTPS page that tries to run mixed content in an 656 // Navigate to an HTTPS page that tries to run mixed content in an
670 // iframe, with strict mixed content blocking. 657 // iframe, with strict mixed content blocking.
671 std::string replacement_path; 658 std::string replacement_path;
672 net::HostPortPair host_port_pair = 659 net::HostPortPair host_port_pair =
673 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); 660 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html"));
674 host_port_pair.set_host("different-host.test"); 661 host_port_pair.set_host("different-host.test");
675 host_resolver()->AddRule("different-host.test", 662 host_resolver()->AddRule("different-host.test",
676 https_server_.GetURL("/title1.html").host()); 663 https_server_.GetURL("/title1.html").host());
677 GetFilePathWithHostAndPortReplacement( 664 GetFilePathWithHostAndPortReplacement(
678 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html", 665 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html",
679 host_port_pair, &replacement_path); 666 host_port_pair, &replacement_path);
680 ui_test_utils::NavigateToURL(browser(), 667 ui_test_utils::NavigateToURL(browser(),
681 https_server_.GetURL(replacement_path)); 668 https_server_.GetURL(replacement_path));
682 CheckSecurityInfoForSecure( 669 CheckSecurityInfoForSecure(
683 browser()->tab_strip_model()->GetActiveWebContents(), 670 browser()->tab_strip_model()->GetActiveWebContents(),
684 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 671 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
685 security_state::CONTENT_STATUS_NONE, false,
686 false /* expect cert status error */); 672 false /* expect cert status error */);
687 } 673 }
688 674
689 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) { 675 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, BrokenHTTPS) {
690 ASSERT_TRUE(embedded_test_server()->Start()); 676 ASSERT_TRUE(embedded_test_server()->Start());
691 ASSERT_TRUE(https_server_.Start()); 677 ASSERT_TRUE(https_server_.Start());
692 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, 678 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID,
693 net::ERR_CERT_DATE_INVALID); 679 net::ERR_CERT_DATE_INVALID);
694 680
695 ui_test_utils::NavigateToURL(browser(), 681 ui_test_utils::NavigateToURL(browser(),
696 https_server_.GetURL("/ssl/google.html")); 682 https_server_.GetURL("/ssl/google.html"));
697 CheckSecurityInfoForSecure( 683 CheckSecurityInfoForSecure(
698 browser()->tab_strip_model()->GetActiveWebContents(), 684 browser()->tab_strip_model()->GetActiveWebContents(),
699 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 685 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_NONE,
700 security_state::CONTENT_STATUS_NONE, false, 686 false, true /* expect cert status error */);
701 true /* expect cert status error */);
702 687
703 ProceedThroughInterstitial( 688 ProceedThroughInterstitial(
704 browser()->tab_strip_model()->GetActiveWebContents()); 689 browser()->tab_strip_model()->GetActiveWebContents());
705 690
706 CheckSecurityInfoForSecure( 691 CheckSecurityInfoForSecure(
707 browser()->tab_strip_model()->GetActiveWebContents(), 692 browser()->tab_strip_model()->GetActiveWebContents(),
708 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 693 security_state::DANGEROUS, false, security_state::CONTENT_STATUS_NONE,
709 security_state::CONTENT_STATUS_NONE, false, 694 false, true /* expect cert status error */);
710 true /* expect cert status error */);
711 695
712 // Navigate to a broken HTTPS page that displays mixed content. 696 // Navigate to a broken HTTPS page that displays mixed content.
713 std::string replacement_path; 697 std::string replacement_path;
714 GetFilePathWithHostAndPortReplacement( 698 GetFilePathWithHostAndPortReplacement(
715 "/ssl/page_displays_insecure_content.html", 699 "/ssl/page_displays_insecure_content.html",
716 embedded_test_server()->host_port_pair(), &replacement_path); 700 embedded_test_server()->host_port_pair(), &replacement_path);
717 ui_test_utils::NavigateToURL(browser(), 701 ui_test_utils::NavigateToURL(browser(),
718 https_server_.GetURL(replacement_path)); 702 https_server_.GetURL(replacement_path));
719 CheckSecurityInfoForSecure( 703 CheckSecurityInfoForSecure(
720 browser()->tab_strip_model()->GetActiveWebContents(), 704 browser()->tab_strip_model()->GetActiveWebContents(),
721 security_state::DANGEROUS, security_state::NO_DEPRECATED_SHA1, 705 security_state::DANGEROUS, false,
722 security_state::CONTENT_STATUS_DISPLAYED, false, 706 security_state::CONTENT_STATUS_DISPLAYED, false,
723 true /* expect cert status error */); 707 true /* expect cert status error */);
724 } 708 }
725 709
726 const char kReportURI[] = "https://report-hpkp.test"; 710 const char kReportURI[] = "https://report-hpkp.test";
727 711
728 class PKPModelClientTest : public SecurityStateTabHelperTest { 712 class PKPModelClientTest : public SecurityStateTabHelperTest {
729 public: 713 public:
730 void SetUpOnMainThread() override { 714 void SetUpOnMainThread() override {
731 ASSERT_TRUE(https_server_.Start()); 715 ASSERT_TRUE(https_server_.Start());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 memset(hash.data(), 1, hash.size()); 756 memset(hash.data(), 1, hash.size());
773 verify_result.public_key_hashes.push_back(hash); 757 verify_result.public_key_hashes.push_back(hash);
774 758
775 mock_cert_verifier()->AddResultForCert(cert, verify_result, net::OK); 759 mock_cert_verifier()->AddResultForCert(cert, verify_result, net::OK);
776 760
777 ui_test_utils::NavigateToURL(browser(), 761 ui_test_utils::NavigateToURL(browser(),
778 https_server_.GetURL("/ssl/google.html")); 762 https_server_.GetURL("/ssl/google.html"));
779 763
780 CheckSecurityInfoForSecure( 764 CheckSecurityInfoForSecure(
781 browser()->tab_strip_model()->GetActiveWebContents(), 765 browser()->tab_strip_model()->GetActiveWebContents(),
782 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 766 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, true,
783 security_state::CONTENT_STATUS_NONE, true, false); 767 false);
784 768
785 const content::SecurityStyleExplanations& explanation = 769 const content::SecurityStyleExplanations& explanation =
786 observer.latest_explanations(); 770 observer.latest_explanations();
787 EXPECT_TRUE(explanation.pkp_bypassed); 771 EXPECT_TRUE(explanation.pkp_bypassed);
788 EXPECT_FALSE(explanation.info_explanations.empty()); 772 EXPECT_FALSE(explanation.info_explanations.empty());
789 } 773 }
790 774
791 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) { 775 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) {
792 content::WebContents* web_contents = 776 content::WebContents* web_contents =
793 browser()->tab_strip_model()->GetActiveWebContents(); 777 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 // updated. 842 // updated.
859 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { 843 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) {
860 ASSERT_TRUE(https_server_.Start()); 844 ASSERT_TRUE(https_server_.Start());
861 SetUpMockCertVerifierForHttpsServer(0, net::OK); 845 SetUpMockCertVerifierForHttpsServer(0, net::OK);
862 846
863 // Navigate to an HTTPS page. 847 // Navigate to an HTTPS page.
864 ui_test_utils::NavigateToURL(browser(), 848 ui_test_utils::NavigateToURL(browser(),
865 https_server_.GetURL("/ssl/google.html")); 849 https_server_.GetURL("/ssl/google.html"));
866 CheckSecurityInfoForSecure( 850 CheckSecurityInfoForSecure(
867 browser()->tab_strip_model()->GetActiveWebContents(), 851 browser()->tab_strip_model()->GetActiveWebContents(),
868 security_state::SECURE, security_state::NO_DEPRECATED_SHA1, 852 security_state::SECURE, false, security_state::CONTENT_STATUS_NONE, false,
869 security_state::CONTENT_STATUS_NONE, false,
870 false /* expect cert status error */); 853 false /* expect cert status error */);
871 854
872 // Navigate to a page that doesn't finish loading. Test that the 855 // Navigate to a page that doesn't finish loading. Test that the
873 // security state is neutral while the page is loading. 856 // security state is neutral while the page is loading.
874 browser()->OpenURL(content::OpenURLParams( 857 browser()->OpenURL(content::OpenURLParams(
875 embedded_test_server()->GetURL("/title1.html"), content::Referrer(), 858 embedded_test_server()->GetURL("/title1.html"), content::Referrer(),
876 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 859 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
877 CheckSecurityInfoForNonSecure( 860 CheckSecurityInfoForNonSecure(
878 browser()->tab_strip_model()->GetActiveWebContents()); 861 browser()->tab_strip_model()->GetActiveWebContents());
879 } 862 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 ASSERT_TRUE(tab); 1455 ASSERT_TRUE(tab);
1473 1456
1474 content::WebContents* new_contents = content::WebContents::Create( 1457 content::WebContents* new_contents = content::WebContents::Create(
1475 content::WebContents::CreateParams(tab->GetBrowserContext())); 1458 content::WebContents::CreateParams(tab->GetBrowserContext()));
1476 content::NavigationController& controller = new_contents->GetController(); 1459 content::NavigationController& controller = new_contents->GetController();
1477 SecurityStateTabHelper::CreateForWebContents(new_contents); 1460 SecurityStateTabHelper::CreateForWebContents(new_contents);
1478 CheckSecurityInfoForNonSecure(new_contents); 1461 CheckSecurityInfoForNonSecure(new_contents);
1479 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(), 1462 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(),
1480 ui::PAGE_TRANSITION_TYPED, std::string()); 1463 ui::PAGE_TRANSITION_TYPED, std::string());
1481 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); 1464 EXPECT_TRUE(content::WaitForLoadStop(new_contents));
1482 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1465 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, false,
1483 security_state::NO_DEPRECATED_SHA1,
1484 security_state::CONTENT_STATUS_NONE, false, 1466 security_state::CONTENT_STATUS_NONE, false,
1485 false /* expect cert status error */); 1467 false /* expect cert status error */);
1486 1468
1487 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, 1469 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents,
1488 TabStripModel::ADD_NONE); 1470 TabStripModel::ADD_NONE);
1489 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1471 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, false,
1490 security_state::NO_DEPRECATED_SHA1,
1491 security_state::CONTENT_STATUS_NONE, false, 1472 security_state::CONTENT_STATUS_NONE, false,
1492 false /* expect cert status error */); 1473 false /* expect cert status error */);
1493 } 1474 }
1494 1475
1495 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires 1476 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires
1496 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages. 1477 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages.
1497 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest, 1478 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
1498 DidChangeVisibleSecurityStateObserver) { 1479 DidChangeVisibleSecurityStateObserver) {
1499 ASSERT_TRUE(https_server_.Start()); 1480 ASSERT_TRUE(https_server_.Start());
1500 ASSERT_TRUE(embedded_test_server()->Start()); 1481 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 SecurityStateTabHelper* helper = 1999 SecurityStateTabHelper* helper =
2019 SecurityStateTabHelper::FromWebContents(web_contents); 2000 SecurityStateTabHelper::FromWebContents(web_contents);
2020 ASSERT_TRUE(helper); 2001 ASSERT_TRUE(helper);
2021 security_state::SecurityInfo security_info; 2002 security_state::SecurityInfo security_info;
2022 helper->GetSecurityInfo(&security_info); 2003 helper->GetSecurityInfo(&security_info);
2023 EXPECT_EQ(security_state::SECURE, security_info.security_level); 2004 EXPECT_EQ(security_state::SECURE, security_info.security_level);
2024 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); 2005 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses);
2025 } 2006 }
2026 2007
2027 } // namespace 2008 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698