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

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

Issue 1035023002: Adding the Finch code for the certificate error reporter experiment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittests Created 5 years, 8 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 18 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
18 #include "chrome/browser/net/certificate_error_reporter.h" 19 #include "chrome/browser/net/certificate_error_reporter.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/safe_browsing/ping_manager.h" 21 #include "chrome/browser/safe_browsing/ping_manager.h"
21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
22 #include "chrome/browser/ssl/ssl_blocking_page.h" 23 #include "chrome/browser/ssl/ssl_blocking_page.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
25 #include "chrome/browser/ui/browser_navigator.h" 26 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 27 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
32 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/content_settings/core/browser/host_content_settings_map.h" 34 #include "components/content_settings/core/browser/host_content_settings_map.h"
35 #include "components/variations/variations_associated_data.h"
34 #include "components/web_modal/web_contents_modal_dialog_manager.h" 36 #include "components/web_modal/web_contents_modal_dialog_manager.h"
35 #include "content/public/browser/browser_context.h" 37 #include "content/public/browser/browser_context.h"
36 #include "content/public/browser/interstitial_page.h" 38 #include "content/public/browser/interstitial_page.h"
37 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
38 #include "content/public/browser/navigation_entry.h" 40 #include "content/public/browser/navigation_entry.h"
39 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/render_frame_host.h" 42 #include "content/public/browser/render_frame_host.h"
41 #include "content/public/browser/render_view_host.h" 43 #include "content/public/browser/render_view_host.h"
42 #include "content/public/browser/render_widget_host_view.h" 44 #include "content/public/browser/render_widget_host_view.h"
43 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 513
512 void SetUpCommandLine(base::CommandLine* command_line) override { 514 void SetUpCommandLine(base::CommandLine* command_line) override {
513 // Browser will ignore certificate errors on localhost. 515 // Browser will ignore certificate errors on localhost.
514 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); 516 command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
515 } 517 }
516 }; 518 };
517 519
518 class SSLUITestWithExtendedReporting : public SSLUITest { 520 class SSLUITestWithExtendedReporting : public SSLUITest {
519 public: 521 public:
520 SSLUITestWithExtendedReporting() : SSLUITest() {} 522 SSLUITestWithExtendedReporting() : SSLUITest() {}
521
522 void SetUpCommandLine(base::CommandLine* command_line) override {
523 // Enable a checkbox on SSL interstitials that allows users to opt
524 // in to reporting invalid certificate chains.
525 command_line->AppendSwitch(switches::kEnableInvalidCertCollection);
526 }
527 }; 523 };
528 524
529 // Visits a regular page over http. 525 // Visits a regular page over http.
530 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { 526 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
531 ASSERT_TRUE(test_server()->Start()); 527 ASSERT_TRUE(test_server()->Start());
532 528
533 ui_test_utils::NavigateToURL(browser(), 529 ui_test_utils::NavigateToURL(browser(),
534 test_server()->GetURL("files/ssl/google.html")); 530 test_server()->GetURL("files/ssl/google.html"));
535 531
536 CheckUnauthenticatedState( 532 CheckUnauthenticatedState(
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 &replacement_path)); 1112 &replacement_path));
1117 1113
1118 // Load a page that displays insecure content. 1114 // Load a page that displays insecure content.
1119 ui_test_utils::NavigateToURL(browser(), 1115 ui_test_utils::NavigateToURL(browser(),
1120 https_server_.GetURL(replacement_path)); 1116 https_server_.GetURL(replacement_path));
1121 1117
1122 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(), 1118 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
1123 AuthState::DISPLAYED_INSECURE_CONTENT); 1119 AuthState::DISPLAYED_INSECURE_CONTENT);
1124 } 1120 }
1125 1121
1126 // Test that when the checkbox is checked and the user proceeds through 1122 // User proceeds, checkbox is shown and checked, Finch parameter is set
1127 // the interstitial, the FraudulentCertificateReporter sees a request to 1123 // -> we expect a report to be sent.
1128 // send a report. 1124 IN_PROC_BROWSER_TEST_F(
1129 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1125 SSLUITestWithExtendedReporting,
1130 TestBrokenHTTPSProceedWithReporting) { 1126 TestBrokenHTTPSProceedWithShowYesCheckYesParamYesReportYes) {
1127 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1128 "ShowAndPossiblySend");
1129 std::map<std::string, std::string> params;
estark 2015/04/02 18:33:34 you could also factor this out into a helper funct
fahl 2015/04/02 19:24:58 Done.
1130 params["possibly_send"] = "1.0";
1131 variations::AssociateVariationParams("ReportCertificateErrors",
1132 "ShowAndPossiblySend", params);
1131 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1133 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1132 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1134 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1133 CertificateReporting::CERT_REPORT_EXPECTED, 1135 CertificateReporting::CERT_REPORT_EXPECTED,
1134 browser()); 1136 browser());
1135 } 1137 }
1136 1138
1137 // Test that when the checkbox is checked and the user goes back (does 1139 // User goes back, checkbox is shown and checked, Finch parameter is set
1138 // not proceed through the interstitial), the 1140 // -> we expect a report.
1139 // FraudulentCertificateReporter sees a request to send a report. 1141 IN_PROC_BROWSER_TEST_F(
1140 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1142 SSLUITestWithExtendedReporting,
1141 TestBrokenHTTPSGoBackWithReporting) { 1143 TestBrokenHTTPSGoBackWithShowYesCheckYesParamYesReportYes) {
1144 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1145 "ShowAndPossiblySend");
1146 std::map<std::string, std::string> params;
1147 params["possibly_send"] = "1.0";
1148 variations::AssociateVariationParams("ReportCertificateErrors",
1149 "ShowAndPossiblySend", params);
1142 TestBrokenHTTPSReporting( 1150 TestBrokenHTTPSReporting(
1143 CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1151 CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1144 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED, 1152 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1145 CertificateReporting::CERT_REPORT_EXPECTED, browser()); 1153 CertificateReporting::CERT_REPORT_EXPECTED, browser());
1146 } 1154 }
1147 1155
1148 // Test that when the checkbox is not checked and the user proceeds 1156 // User proceeds, checkbox is shown but unchecked, Finch parameter is set
1149 // through the interstitial, the FraudulentCertificateReporter does not 1157 // -> we expect no report.
1150 // see a request to send a report. 1158 IN_PROC_BROWSER_TEST_F(
1151 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1159 SSLUITestWithExtendedReporting,
1152 TestBrokenHTTPSProceedWithNoReporting) { 1160 TestBrokenHTTPSProceedWithShowYesCheckNoParamYesReportNo) {
1161 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1162 "ShowAndPossiblySend");
1163 std::map<std::string, std::string> params;
1164 params["possibly_send"] = "1.0";
1165 variations::AssociateVariationParams("ReportCertificateErrors",
1166 "ShowAndPossiblySend", params);
1153 TestBrokenHTTPSReporting( 1167 TestBrokenHTTPSReporting(
1154 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN, 1168 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN,
1155 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1169 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1156 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser()); 1170 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1157 } 1171 }
1158 1172
1159 // Test that when the checkbox is not checked and the user does not proceed 1173 // User goes back, checkbox is shown but unchecked, Finch parameter is set
1160 // through the interstitial, the FraudulentCertificateReporter does not 1174 // -> we expect no report.
1161 // see a request to send a report.
1162 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1175 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1163 TestBrokenHTTPSGoBackWithNoReporting) { 1176 TestBrokenHTTPSGoBackShowYesCheckNoParamYesReportNo) {
1177 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1178 "ShowAndPossiblySend");
1179 std::map<std::string, std::string> params;
1180 params["possibly_send"] = "1.0";
1181 variations::AssociateVariationParams("ReportCertificateErrors",
1182 "ShowAndPossiblySend", params);
1164 TestBrokenHTTPSReporting( 1183 TestBrokenHTTPSReporting(
1165 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN, 1184 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN,
1166 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED, 1185 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1167 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser()); 1186 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1168 } 1187 }
1169 1188
1170 // Test that when the command-line switch for reporting invalid cert 1189 // User proceeds, checkbox is shown and checked, Finch parameter is not
1171 // chains is not enabled, reports don't get sent, even if the opt-in 1190 // set -> we expect no report.
1172 // preference is set. (i.e. if a user enables invalid cert collection in 1191 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1173 // chrome://flags, checks the box on an interstitial, and then disables 1192 TestBrokenHTTPSProceedShowYesCheckYesParamNoReportNo) {
1174 // the flag in chrome://flags, reports shouldn't be sent on the next 1193 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1175 // interstitial). 1194 "ShowAndPossiblySend");
1176 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) { 1195 std::map<std::string, std::string> params;
1196 params["possibly_send"] = "-1.0";
1197 variations::AssociateVariationParams("ReportCertificateErrors",
1198 "ShowAndPossiblySend", params);
1177 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1199 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1178 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1200 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1179 CertificateReporting::CERT_REPORT_NOT_EXPECTED, 1201 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1180 browser()); 1202 browser());
1181 } 1203 }
1182 1204
1183 // Test that reports don't get sent in incognito mode even if the opt-in 1205 // User goes back, checkbox is shown and checked, Finch parameter is not set
1184 // preference is set and the command-line switch is enabled. 1206 // -> we expect no report.
1185 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1207 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1186 TestBrokenHTTPSNoReportingInIncognito) { 1208 TestBrokenHTTPSGoBackShowYesCheckYesParamNoReportNo) {
1209 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1210 "ShowAndPossiblySend");
1211 std::map<std::string, std::string> params;
1212 params["possibly_send"] = "-1.0";
1213 variations::AssociateVariationParams("ReportCertificateErrors",
1214 "ShowAndPossiblySend", params);
1215 TestBrokenHTTPSReporting(
1216 CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1217 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1218 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1219 }
1220
1221 // User proceeds, checkbox is not shown but checked -> we expect no report
1222 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1223 TestBrokenHTTPSProceedShowNoCheckYesReportNo) {
1224 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1225 "DontShowAndDontSend");
1187 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1226 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1188 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1227 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1189 CertificateReporting::CERT_REPORT_NOT_EXPECTED, 1228 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1229 browser());
1230 }
1231
1232 // Browser is incognito, user proceeds, checkbox is shown and checked, Finch
1233 // parameter is set -> we expect no report
1234 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1235 TestBrokenHTTPSInIncognitoReportNo) {
1236 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1237 "ShowAndPossiblySend");
1238 std::map<std::string, std::string> params;
1239 params["possibly_send"] = "1.0";
1240 variations::AssociateVariationParams("ReportCertificateErrors",
1241 "ShowAndPossiblySend", params);
1242 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1243 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1244 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1190 CreateIncognitoBrowser()); 1245 CreateIncognitoBrowser());
1191 } 1246 }
1192 1247
1193 // Visits a page that runs insecure content and tries to suppress the insecure 1248 // Visits a page that runs insecure content and tries to suppress the insecure
1194 // content warnings by randomizing location.hash. 1249 // content warnings by randomizing location.hash.
1195 // Based on http://crbug.com/8706 1250 // Based on http://crbug.com/8706
1196 IN_PROC_BROWSER_TEST_F(SSLUITest, 1251 IN_PROC_BROWSER_TEST_F(SSLUITest,
1197 TestRunsInsecuredContentRandomizeHash) { 1252 TestRunsInsecuredContentRandomizeHash) {
1198 ASSERT_TRUE(test_server()->Start()); 1253 ASSERT_TRUE(test_server()->Start());
1199 ASSERT_TRUE(https_server_.Start()); 1254 ASSERT_TRUE(https_server_.Start());
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 2207
2153 // Visit a page over https that contains a frame with a redirect. 2208 // Visit a page over https that contains a frame with a redirect.
2154 2209
2155 // XMLHttpRequest insecure content in synchronous mode. 2210 // XMLHttpRequest insecure content in synchronous mode.
2156 2211
2157 // XMLHttpRequest insecure content in asynchronous mode. 2212 // XMLHttpRequest insecure content in asynchronous mode.
2158 2213
2159 // XMLHttpRequest over bad ssl in synchronous mode. 2214 // XMLHttpRequest over bad ssl in synchronous mode.
2160 2215
2161 // XMLHttpRequest over OK ssl in synchronous mode. 2216 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698