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

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

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

Powered by Google App Engine
This is Rietveld 408576698