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

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

Issue 2949003003: Implement a skeleton of the Superfish interstitial (Closed)
Patch Set: meacer comments Created 3 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <utility> 5 #include <utility>
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "components/content_settings/core/browser/host_content_settings_map.h" 61 #include "components/content_settings/core/browser/host_content_settings_map.h"
62 #include "components/network_session_configurator/common/network_switches.h" 62 #include "components/network_session_configurator/common/network_switches.h"
63 #include "components/network_time/network_time_test_utils.h" 63 #include "components/network_time/network_time_test_utils.h"
64 #include "components/network_time/network_time_tracker.h" 64 #include "components/network_time/network_time_tracker.h"
65 #include "components/prefs/testing_pref_service.h" 65 #include "components/prefs/testing_pref_service.h"
66 #include "components/security_interstitials/core/controller_client.h" 66 #include "components/security_interstitials/core/controller_client.h"
67 #include "components/security_interstitials/core/metrics_helper.h" 67 #include "components/security_interstitials/core/metrics_helper.h"
68 #include "components/security_state/core/security_state.h" 68 #include "components/security_state/core/security_state.h"
69 #include "components/security_state/core/switches.h" 69 #include "components/security_state/core/switches.h"
70 #include "components/ssl_errors/error_classification.h" 70 #include "components/ssl_errors/error_classification.h"
71 #include "components/strings/grit/components_strings.h"
71 #include "components/variations/variations_associated_data.h" 72 #include "components/variations/variations_associated_data.h"
72 #include "components/variations/variations_switches.h" 73 #include "components/variations/variations_switches.h"
73 #include "components/web_modal/web_contents_modal_dialog_manager.h" 74 #include "components/web_modal/web_contents_modal_dialog_manager.h"
74 #include "content/public/browser/browser_context.h" 75 #include "content/public/browser/browser_context.h"
75 #include "content/public/browser/interstitial_page.h" 76 #include "content/public/browser/interstitial_page.h"
76 #include "content/public/browser/navigation_controller.h" 77 #include "content/public/browser/navigation_controller.h"
77 #include "content/public/browser/navigation_entry.h" 78 #include "content/public/browser/navigation_entry.h"
78 #include "content/public/browser/notification_details.h" 79 #include "content/public/browser/notification_details.h"
79 #include "content/public/browser/notification_service.h" 80 #include "content/public/browser/notification_service.h"
80 #include "content/public/browser/render_frame_host.h" 81 #include "content/public/browser/render_frame_host.h"
(...skipping 26 matching lines...) Expand all
107 #include "net/test/cert_test_util.h" 108 #include "net/test/cert_test_util.h"
108 #include "net/test/embedded_test_server/embedded_test_server.h" 109 #include "net/test/embedded_test_server/embedded_test_server.h"
109 #include "net/test/embedded_test_server/request_handler_util.h" 110 #include "net/test/embedded_test_server/request_handler_util.h"
110 #include "net/test/spawned_test_server/spawned_test_server.h" 111 #include "net/test/spawned_test_server/spawned_test_server.h"
111 #include "net/test/test_certificate_data.h" 112 #include "net/test/test_certificate_data.h"
112 #include "net/test/test_data_directory.h" 113 #include "net/test/test_data_directory.h"
113 #include "net/url_request/url_request_context.h" 114 #include "net/url_request/url_request_context.h"
114 #include "net/url_request/url_request_filter.h" 115 #include "net/url_request/url_request_filter.h"
115 #include "net/url_request/url_request_job.h" 116 #include "net/url_request/url_request_job.h"
116 #include "net/url_request/url_request_test_util.h" 117 #include "net/url_request/url_request_test_util.h"
118 #include "ui/base/l10n/l10n_util.h"
117 119
118 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) 120 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
119 #include "chrome/browser/ssl/captive_portal_blocking_page.h" 121 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
120 #endif 122 #endif
121 123
122 #if defined(USE_NSS_CERTS) 124 #if defined(USE_NSS_CERTS)
123 #include "chrome/browser/net/nss_context.h" 125 #include "chrome/browser/net/nss_context.h"
124 #include "net/cert/nss_cert_database.h" 126 #include "net/cert/nss_cert_database.h"
125 #endif // defined(USE_NSS_CERTS) 127 #endif // defined(USE_NSS_CERTS)
126 128
(...skipping 3799 matching lines...) Expand 10 before | Expand all | Expand 10 after
3926 protected: 3928 protected:
3927 // SecurityInterstitialIDNTest implementation 3929 // SecurityInterstitialIDNTest implementation
3928 security_interstitials::SecurityInterstitialPage* CreateInterstitial( 3930 security_interstitials::SecurityInterstitialPage* CreateInterstitial(
3929 content::WebContents* contents, 3931 content::WebContents* contents,
3930 const GURL& request_url) const override { 3932 const GURL& request_url) const override {
3931 net::SSLInfo ssl_info; 3933 net::SSLInfo ssl_info;
3932 ssl_info.cert = 3934 ssl_info.cert =
3933 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 3935 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
3934 return SSLBlockingPage::Create( 3936 return SSLBlockingPage::Create(
3935 contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0, 3937 contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0,
3936 base::Time::NowFromSystemTime(), nullptr, 3938 base::Time::NowFromSystemTime(), nullptr, false /* is superfish */,
3937 base::Callback<void(content::CertificateRequestResultType)>()); 3939 base::Callback<void(content::CertificateRequestResultType)>());
3938 } 3940 }
3939 }; 3941 };
3940 3942
3941 // Flaky on mac: https://crbug.com/689846 3943 // Flaky on mac: https://crbug.com/689846
3942 #if defined(OS_MACOSX) 3944 #if defined(OS_MACOSX)
3943 #define MAYBE_SSLBlockingPageDecodesIDN DISABLED_SSLBlockingPageDecodesIDN 3945 #define MAYBE_SSLBlockingPageDecodesIDN DISABLED_SSLBlockingPageDecodesIDN
3944 #else 3946 #else
3945 #define MAYBE_SSLBlockingPageDecodesIDN SSLBlockingPageDecodesIDN 3947 #define MAYBE_SSLBlockingPageDecodesIDN SSLBlockingPageDecodesIDN
3946 #endif 3948 #endif
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
4740 histograms.ExpectUniqueSample("interstitial.ssl_error_handler.superfish", 4742 histograms.ExpectUniqueSample("interstitial.ssl_error_handler.superfish",
4741 true, 1); 4743 true, 1);
4742 } 4744 }
4743 4745
4744 // Tests that the Superfish histogram is recorded properly when the Superfish 4746 // Tests that the Superfish histogram is recorded properly when the Superfish
4745 // certificate is not present. 4747 // certificate is not present.
4746 IN_PROC_BROWSER_TEST_F(SuperfishSSLUITest, NoSuperfishRecorded) { 4748 IN_PROC_BROWSER_TEST_F(SuperfishSSLUITest, NoSuperfishRecorded) {
4747 SetUpCertVerifier(false /* use superfish cert */); 4749 SetUpCertVerifier(false /* use superfish cert */);
4748 GURL url(https_server_.GetURL("/ssl/google.html")); 4750 GURL url(https_server_.GetURL("/ssl/google.html"));
4749 base::HistogramTester histograms; 4751 base::HistogramTester histograms;
4750 ui_test_utils::NavigateToURL(browser(), url); 4752 ui_test_utils::NavigateToURL(browser(), url);
meacer 2017/06/22 22:35:37 nit: Inline this while you are at it?
estark 2017/06/22 23:17:48 Done.
4751 histograms.ExpectUniqueSample("interstitial.ssl_error_handler.superfish", 4753 histograms.ExpectUniqueSample("interstitial.ssl_error_handler.superfish",
4752 false, 1); 4754 false, 1);
4753 } 4755 }
4754 4756
4757 // Tests that the Superfish interstitial is shown when the Finch feature is
4758 // enabled and the Superfish certificate is present.
4759 IN_PROC_BROWSER_TEST_F(SuperfishSSLUITest, SuperfishInterstitial) {
4760 base::test::ScopedFeatureList scoped_feature_list;
4761 scoped_feature_list.InitFromCommandLine("SuperfishInterstitial",
4762 std::string());
4763 SetUpCertVerifier(true /* use superfish cert */);
4764 ui_test_utils::NavigateToURL(browser(),
4765 https_server_.GetURL("/ssl/google.html"));
4766 content::WebContents* tab =
4767 browser()->tab_strip_model()->GetActiveWebContents();
4768 content::WaitForInterstitialAttach(tab);
4769 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
4770 ASSERT_TRUE(interstitial_page);
4771 EXPECT_TRUE(WaitForRenderFrameReady(interstitial_page->GetMainFrame()));
4772 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
4773 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
4774
4775 // Look for keywords on the page to check that the Superfish interstitial is
4776 // showing.
4777 std::string expected_title =
meacer 2017/06/22 22:35:37 nit: const
estark 2017/06/22 23:17:48 Done.
4778 l10n_util::GetStringUTF8(IDS_SSL_SUPERFISH_HEADING);
4779 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText(
estark 2017/06/22 22:01:05 I spent like an hour trying to rewrite this method
4780 interstitial_page, expected_title));
4781 }
4782
4783 // Tests that the Superfish interstitial is not shown when the Finch feature is
4784 // disabled.
4785 IN_PROC_BROWSER_TEST_F(SuperfishSSLUITest, SuperfishInterstitialDisabled) {
4786 base::test::ScopedFeatureList scoped_feature_list;
4787 scoped_feature_list.InitFromCommandLine(std::string(),
4788 "SuperfishInterstitial");
4789 SetUpCertVerifier(true /* use superfish cert */);
4790 ui_test_utils::NavigateToURL(browser(),
4791 https_server_.GetURL("/ssl/google.html"));
4792 content::WebContents* tab =
4793 browser()->tab_strip_model()->GetActiveWebContents();
4794 content::WaitForInterstitialAttach(tab);
4795 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
4796 ASSERT_TRUE(interstitial_page);
4797 EXPECT_TRUE(WaitForRenderFrameReady(interstitial_page->GetMainFrame()));
4798 EXPECT_EQ(SSLBlockingPage::kTypeForTesting,
4799 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
4800
4801 // Look for keywords on the page to check that the Superfish interstitial is
4802 // not showing.
4803 std::string expected_title = l10n_util::GetStringUTF8(IDS_SSL_V2_HEADING);
meacer 2017/06/22 22:35:37 const
estark 2017/06/22 23:17:48 Done.
4804 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText(
4805 interstitial_page, expected_title));
4806 }
4807
4755 // TODO(jcampan): more tests to do below. 4808 // TODO(jcampan): more tests to do below.
4756 4809
4757 // Visit a page over https that contains a frame with a redirect. 4810 // Visit a page over https that contains a frame with a redirect.
4758 4811
4759 // XMLHttpRequest insecure content in synchronous mode. 4812 // XMLHttpRequest insecure content in synchronous mode.
4760 4813
4761 // XMLHttpRequest insecure content in asynchronous mode. 4814 // XMLHttpRequest insecure content in asynchronous mode.
4762 4815
4763 // XMLHttpRequest over bad ssl in synchronous mode. 4816 // XMLHttpRequest over bad ssl in synchronous mode.
4764 4817
4765 // XMLHttpRequest over OK ssl in synchronous mode. 4818 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698