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

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

Issue 2562503002: Generalize WebContentsObserver::SecurityStyleChanged (Closed)
Patch Set: Fix nit. Created 4 years 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "third_party/boringssl/src/include/openssl/ssl.h" 56 #include "third_party/boringssl/src/include/openssl/ssl.h"
57 #include "ui/base/l10n/l10n_util.h" 57 #include "ui/base/l10n/l10n_util.h"
58 58
59 namespace { 59 namespace {
60 60
61 enum CertificateStatus { VALID_CERTIFICATE, INVALID_CERTIFICATE }; 61 enum CertificateStatus { VALID_CERTIFICATE, INVALID_CERTIFICATE };
62 62
63 const base::FilePath::CharType kDocRoot[] = 63 const base::FilePath::CharType kDocRoot[] =
64 FILE_PATH_LITERAL("chrome/test/data"); 64 FILE_PATH_LITERAL("chrome/test/data");
65 65
66 // A WebContentsObserver useful for testing the SecurityStyleChanged() 66 // A WebContentsObserver useful for testing the DidChangeVisibleSecurityState()
67 // method: it keeps track of the latest security style and explanation 67 // method: it keeps track of the latest security style and explanation that was
68 // that was fired. 68 // fired.
69 class SecurityStyleTestObserver : public content::WebContentsObserver { 69 class SecurityStyleTestObserver : public content::WebContentsObserver {
70 public: 70 public:
71 explicit SecurityStyleTestObserver(content::WebContents* web_contents) 71 explicit SecurityStyleTestObserver(content::WebContents* web_contents)
72 : content::WebContentsObserver(web_contents), 72 : content::WebContentsObserver(web_contents),
73 latest_security_style_(blink::WebSecurityStyleUnknown) {} 73 latest_security_style_(blink::WebSecurityStyleUnknown) {}
74 ~SecurityStyleTestObserver() override {} 74 ~SecurityStyleTestObserver() override {}
75 75
76 void SecurityStyleChanged(blink::WebSecurityStyle security_style, 76 void DidChangeVisibleSecurityState() override {
77 const content::SecurityStyleExplanations& 77 content::SecurityStyleExplanations explanations;
78 security_style_explanations) override { 78 latest_security_style_ = web_contents()->GetDelegate()->GetSecurityStyle(
79 latest_security_style_ = security_style; 79 web_contents(), &explanations);
80 latest_explanations_ = security_style_explanations; 80 latest_explanations_ = explanations;
81 } 81 }
82 82
83 blink::WebSecurityStyle latest_security_style() const { 83 blink::WebSecurityStyle latest_security_style() const {
84 return latest_security_style_; 84 return latest_security_style_;
85 } 85 }
86 86
87 const content::SecurityStyleExplanations& latest_explanations() const { 87 const content::SecurityStyleExplanations& latest_explanations() const {
88 return latest_explanations_; 88 return latest_explanations_;
89 } 89 }
90 90
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 command_line->AppendSwitchASCII( 336 command_line->AppendSwitchASCII(
337 security_state::switches::kMarkHttpAs, 337 security_state::switches::kMarkHttpAs,
338 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); 338 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
339 } 339 }
340 } 340 }
341 341
342 private: 342 private:
343 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTestWithPasswordCcSwitch); 343 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTestWithPasswordCcSwitch);
344 }; 344 };
345 345
346 class SecurityStyleChangedTest : public InProcessBrowserTest { 346 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest {
347 public: 347 public:
348 SecurityStyleChangedTest() 348 DidChangeVisibleSecurityStateTest()
349 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { 349 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
350 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 350 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
351 } 351 }
352 352
353 void SetUpCommandLine(base::CommandLine* command_line) override { 353 void SetUpCommandLine(base::CommandLine* command_line) override {
354 // Browser will both run and display insecure content. 354 // Browser will both run and display insecure content.
355 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 355 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
356 } 356 }
357 357
358 protected: 358 protected:
359 net::EmbeddedTestServer https_server_; 359 net::EmbeddedTestServer https_server_;
360 360
361 private: 361 private:
362 DISALLOW_COPY_AND_ASSIGN(SecurityStyleChangedTest); 362 DISALLOW_COPY_AND_ASSIGN(DidChangeVisibleSecurityStateTest);
363 }; 363 };
364 364
365 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpPage) { 365 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpPage) {
366 ASSERT_TRUE(embedded_test_server()->Start()); 366 ASSERT_TRUE(embedded_test_server()->Start());
367 ui_test_utils::NavigateToURL( 367 ui_test_utils::NavigateToURL(
368 browser(), embedded_test_server()->GetURL("/ssl/google.html")); 368 browser(), embedded_test_server()->GetURL("/ssl/google.html"));
369 content::WebContents* contents = 369 content::WebContents* contents =
370 browser()->tab_strip_model()->GetActiveWebContents(); 370 browser()->tab_strip_model()->GetActiveWebContents();
371 ASSERT_TRUE(contents); 371 ASSERT_TRUE(contents);
372 372
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 false /* expect cert status error */); 1505 false /* expect cert status error */);
1506 1506
1507 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, 1507 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents,
1508 TabStripModel::ADD_NONE); 1508 TabStripModel::ADD_NONE);
1509 CheckSecurityInfoForSecure(new_contents, security_state::SECURE, 1509 CheckSecurityInfoForSecure(new_contents, security_state::SECURE,
1510 security_state::NO_DEPRECATED_SHA1, 1510 security_state::NO_DEPRECATED_SHA1,
1511 security_state::CONTENT_STATUS_NONE, false, 1511 security_state::CONTENT_STATUS_NONE, false,
1512 false /* expect cert status error */); 1512 false /* expect cert status error */);
1513 } 1513 }
1514 1514
1515 // Tests that the WebContentsObserver::SecurityStyleChanged event fires 1515 // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires
1516 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages. 1516 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages.
1517 IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, SecurityStyleChangedObserver) { 1517 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
1518 DidChangeVisibleSecurityStateObserver) {
1518 ASSERT_TRUE(https_server_.Start()); 1519 ASSERT_TRUE(https_server_.Start());
1519 ASSERT_TRUE(embedded_test_server()->Start()); 1520 ASSERT_TRUE(embedded_test_server()->Start());
1520 1521
1521 net::EmbeddedTestServer https_test_server_expired( 1522 net::EmbeddedTestServer https_test_server_expired(
1522 net::EmbeddedTestServer::TYPE_HTTPS); 1523 net::EmbeddedTestServer::TYPE_HTTPS);
1523 https_test_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); 1524 https_test_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
1524 https_test_server_expired.ServeFilesFromSourceDirectory( 1525 https_test_server_expired.ServeFilesFromSourceDirectory(
1525 base::FilePath(kDocRoot)); 1526 base::FilePath(kDocRoot));
1526 ASSERT_TRUE(https_test_server_expired.Start()); 1527 ASSERT_TRUE(https_test_server_expired.Start());
1527 1528
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed); 1644 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed);
1644 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty()); 1645 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty());
1645 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content); 1646 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content);
1646 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content); 1647 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content);
1647 } 1648 }
1648 1649
1649 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back, 1650 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back,
1650 // and test that the observed security style matches. 1651 // and test that the observed security style matches.
1651 #if defined(OS_CHROMEOS) 1652 #if defined(OS_CHROMEOS)
1652 // Flaky on Chrome OS. See https://crbug.com/638576. 1653 // Flaky on Chrome OS. See https://crbug.com/638576.
1653 #define MAYBE_SecurityStyleChangedObserverGoBack \ 1654 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1654 DISABLED_SecurityStyleChangedObserverGoBack 1655 DISABLED_DidChangeVisibleSecurityStateObserverGoBack
1655 #else 1656 #else
1656 #define MAYBE_SecurityStyleChangedObserverGoBack \ 1657 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1657 SecurityStyleChangedObserverGoBack 1658 DidChangeVisibleSecurityStateObserverGoBack
1658 #endif 1659 #endif
1659 IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, 1660 IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
1660 MAYBE_SecurityStyleChangedObserverGoBack) { 1661 MAYBE_DidChangeVisibleSecurityStateObserverGoBack) {
1661 ASSERT_TRUE(https_server_.Start()); 1662 ASSERT_TRUE(https_server_.Start());
1662 1663
1663 net::EmbeddedTestServer https_test_server_expired( 1664 net::EmbeddedTestServer https_test_server_expired(
1664 net::EmbeddedTestServer::TYPE_HTTPS); 1665 net::EmbeddedTestServer::TYPE_HTTPS);
1665 https_test_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); 1666 https_test_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
1666 https_test_server_expired.ServeFilesFromSourceDirectory( 1667 https_test_server_expired.ServeFilesFromSourceDirectory(
1667 base::FilePath(kDocRoot)); 1668 base::FilePath(kDocRoot));
1668 ASSERT_TRUE(https_test_server_expired.Start()); 1669 ASSERT_TRUE(https_test_server_expired.Start());
1669 1670
1670 content::WebContents* web_contents = 1671 content::WebContents* web_contents =
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 1850
1850 private: 1851 private:
1851 scoped_refptr<net::X509Certificate> cert_; 1852 scoped_refptr<net::X509Certificate> cert_;
1852 1853
1853 DISALLOW_COPY_AND_ASSIGN(BrowserTestNonsecureURLRequest); 1854 DISALLOW_COPY_AND_ASSIGN(BrowserTestNonsecureURLRequest);
1854 }; 1855 };
1855 1856
1856 // Tests that a connection with obsolete TLS settings does not get a 1857 // Tests that a connection with obsolete TLS settings does not get a
1857 // secure connection explanation. 1858 // secure connection explanation.
1858 IN_PROC_BROWSER_TEST_F(BrowserTestNonsecureURLRequest, 1859 IN_PROC_BROWSER_TEST_F(BrowserTestNonsecureURLRequest,
1859 SecurityStyleChangedObserverNonsecureConnection) { 1860 DidChangeVisibleSecurityStateObserverNonsecureConnection) {
1860 content::WebContents* web_contents = 1861 content::WebContents* web_contents =
1861 browser()->tab_strip_model()->GetActiveWebContents(); 1862 browser()->tab_strip_model()->GetActiveWebContents();
1862 SecurityStyleTestObserver observer(web_contents); 1863 SecurityStyleTestObserver observer(web_contents);
1863 1864
1864 ui_test_utils::NavigateToURL( 1865 ui_test_utils::NavigateToURL(
1865 browser(), GURL(std::string("https://") + kMockNonsecureHostname)); 1866 browser(), GURL(std::string("https://") + kMockNonsecureHostname));
1866 1867
1867 // The security style of the page doesn't get downgraded for obsolete 1868 // The security style of the page doesn't get downgraded for obsolete
1868 // TLS settings, so it should remain at WebSecurityStyleAuthenticated. 1869 // TLS settings, so it should remain at WebSecurityStyleAuthenticated.
1869 EXPECT_EQ(blink::WebSecurityStyleAuthenticated, 1870 EXPECT_EQ(blink::WebSecurityStyleAuthenticated,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 SecurityStateTabHelper* helper = 2032 SecurityStateTabHelper* helper =
2032 SecurityStateTabHelper::FromWebContents(web_contents); 2033 SecurityStateTabHelper::FromWebContents(web_contents);
2033 ASSERT_TRUE(helper); 2034 ASSERT_TRUE(helper);
2034 security_state::SecurityInfo security_info; 2035 security_state::SecurityInfo security_info;
2035 helper->GetSecurityInfo(&security_info); 2036 helper->GetSecurityInfo(&security_info);
2036 EXPECT_EQ(security_state::SECURE, security_info.security_level); 2037 EXPECT_EQ(security_state::SECURE, security_info.security_level);
2037 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); 2038 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses);
2038 } 2039 }
2039 2040
2040 } // namespace 2041 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc ('k') | content/browser/devtools/protocol/security_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698