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

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: felt's comments 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 23 matching lines...) Expand all
67 using content::InterstitialPage; 69 using content::InterstitialPage;
68 using content::NavigationController; 70 using content::NavigationController;
69 using content::NavigationEntry; 71 using content::NavigationEntry;
70 using content::SSLStatus; 72 using content::SSLStatus;
71 using content::WebContents; 73 using content::WebContents;
72 using web_modal::WebContentsModalDialogManager; 74 using web_modal::WebContentsModalDialogManager;
73 75
74 const base::FilePath::CharType kDocRoot[] = 76 const base::FilePath::CharType kDocRoot[] =
75 FILE_PATH_LITERAL("chrome/test/data"); 77 FILE_PATH_LITERAL("chrome/test/data");
76 78
79 // Const for the Finch group DontShowDontSend
80 const char kHTTPSErrorReporterFinchGroupDontShowDontSend[] =
81 "DontShowAndDontSend";
77 namespace { 82 namespace {
78 83
79 class ProvisionalLoadWaiter : public content::WebContentsObserver { 84 class ProvisionalLoadWaiter : public content::WebContentsObserver {
80 public: 85 public:
81 explicit ProvisionalLoadWaiter(WebContents* tab) 86 explicit ProvisionalLoadWaiter(WebContents* tab)
82 : WebContentsObserver(tab), waiting_(false), seen_(false) {} 87 : WebContentsObserver(tab), waiting_(false), seen_(false) {}
83 88
84 void Wait() { 89 void Wait() {
85 if (seen_) 90 if (seen_)
86 return; 91 return;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 471
467 if (expect_report == CertificateReporting::CERT_REPORT_EXPECTED) { 472 if (expect_report == CertificateReporting::CERT_REPORT_EXPECTED) {
468 // Check that the mock reporter received a request to send a report. 473 // Check that the mock reporter received a request to send a report.
469 EXPECT_EQ(https_server_expired_.GetURL("/").host(), 474 EXPECT_EQ(https_server_expired_.GetURL("/").host(),
470 reporter_->latest_hostname_reported()); 475 reporter_->latest_hostname_reported());
471 } else { 476 } else {
472 EXPECT_EQ(std::string(), reporter_->latest_hostname_reported()); 477 EXPECT_EQ(std::string(), reporter_->latest_hostname_reported());
473 } 478 }
474 } 479 }
475 480
481 // Helper function to set the Finch options
482 void SetCertReportingFinchConfig(const std::string& group_name,
483 const std::string& param_value) {
484 base::FieldTrialList::CreateFieldTrial(
485 kHTTPSErrorReporterFinchExperimentName, group_name);
486 if (param_value.compare("") != 0) {
felt 2015/04/03 22:38:09 !param_value.empty()
fahl 2015/04/04 00:33:18 Done.
487 std::map<std::string, std::string> params;
488 params[kHTTPSErrorReporterFinchParamName] = param_value;
489 variations::AssociateVariationParams(
490 kHTTPSErrorReporterFinchExperimentName, group_name, params);
491 }
492 }
493
494 // Helper function to set the Finch options in case we have no parameter
495 void SetCertReportingFinchConfig(const std::string& group_name) {
496 SetCertReportingFinchConfig(group_name, std::string());
497 }
498
476 net::SpawnedTestServer https_server_; 499 net::SpawnedTestServer https_server_;
477 net::SpawnedTestServer https_server_expired_; 500 net::SpawnedTestServer https_server_expired_;
478 net::SpawnedTestServer https_server_mismatched_; 501 net::SpawnedTestServer https_server_mismatched_;
479 net::SpawnedTestServer wss_server_expired_; 502 net::SpawnedTestServer wss_server_expired_;
480 503
481 private: 504 private:
482 typedef net::SpawnedTestServer::SSLOptions SSLOptions; 505 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
483 CertificateReporting::MockReporter* reporter_; 506 CertificateReporting::MockReporter* reporter_;
484 507
485 DISALLOW_COPY_AND_ASSIGN(SSLUITest); 508 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
(...skipping 25 matching lines...) Expand all
511 534
512 void SetUpCommandLine(base::CommandLine* command_line) override { 535 void SetUpCommandLine(base::CommandLine* command_line) override {
513 // Browser will ignore certificate errors on localhost. 536 // Browser will ignore certificate errors on localhost.
514 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); 537 command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
515 } 538 }
516 }; 539 };
517 540
518 class SSLUITestWithExtendedReporting : public SSLUITest { 541 class SSLUITestWithExtendedReporting : public SSLUITest {
519 public: 542 public:
520 SSLUITestWithExtendedReporting() : SSLUITest() {} 543 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 }; 544 };
528 545
529 // Visits a regular page over http. 546 // Visits a regular page over http.
530 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { 547 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
531 ASSERT_TRUE(test_server()->Start()); 548 ASSERT_TRUE(test_server()->Start());
532 549
533 ui_test_utils::NavigateToURL(browser(), 550 ui_test_utils::NavigateToURL(browser(),
534 test_server()->GetURL("files/ssl/google.html")); 551 test_server()->GetURL("files/ssl/google.html"));
535 552
536 CheckUnauthenticatedState( 553 CheckUnauthenticatedState(
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 &replacement_path)); 1133 &replacement_path));
1117 1134
1118 // Load a page that displays insecure content. 1135 // Load a page that displays insecure content.
1119 ui_test_utils::NavigateToURL(browser(), 1136 ui_test_utils::NavigateToURL(browser(),
1120 https_server_.GetURL(replacement_path)); 1137 https_server_.GetURL(replacement_path));
1121 1138
1122 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(), 1139 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
1123 AuthState::DISPLAYED_INSECURE_CONTENT); 1140 AuthState::DISPLAYED_INSECURE_CONTENT);
1124 } 1141 }
1125 1142
1126 // Test that when the checkbox is checked and the user proceeds through 1143 // User proceeds, checkbox is shown and checked, Finch parameter is set
1127 // the interstitial, the FraudulentCertificateReporter sees a request to 1144 // -> we expect a report.
1128 // send a report. 1145 IN_PROC_BROWSER_TEST_F(
1129 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1146 SSLUITestWithExtendedReporting,
1130 TestBrokenHTTPSProceedWithReporting) { 1147 TestBrokenHTTPSProceedWithShowYesCheckYesParamYesReportYes) {
1148 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1149 "1.0");
1131 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1150 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1132 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1151 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1133 CertificateReporting::CERT_REPORT_EXPECTED, 1152 CertificateReporting::CERT_REPORT_EXPECTED,
1134 browser()); 1153 browser());
1135 } 1154 }
1136 1155
1137 // Test that when the checkbox is checked and the user goes back (does 1156 // User goes back, checkbox is shown and checked, Finch parameter is set
1138 // not proceed through the interstitial), the 1157 // -> we expect a report.
1139 // FraudulentCertificateReporter sees a request to send a report. 1158 IN_PROC_BROWSER_TEST_F(
1140 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1159 SSLUITestWithExtendedReporting,
1141 TestBrokenHTTPSGoBackWithReporting) { 1160 TestBrokenHTTPSGoBackWithShowYesCheckYesParamYesReportYes) {
1161 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1162 "1.0");
1142 TestBrokenHTTPSReporting( 1163 TestBrokenHTTPSReporting(
1143 CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1164 CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1144 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED, 1165 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1145 CertificateReporting::CERT_REPORT_EXPECTED, browser()); 1166 CertificateReporting::CERT_REPORT_EXPECTED, browser());
1146 } 1167 }
1147 1168
1148 // Test that when the checkbox is not checked and the user proceeds 1169 // User proceeds, checkbox is shown but unchecked, Finch parameter is set
1149 // through the interstitial, the FraudulentCertificateReporter does not 1170 // -> we expect no report.
1150 // see a request to send a report. 1171 IN_PROC_BROWSER_TEST_F(
1151 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1172 SSLUITestWithExtendedReporting,
1152 TestBrokenHTTPSProceedWithNoReporting) { 1173 TestBrokenHTTPSProceedWithShowYesCheckNoParamYesReportNo) {
1174 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1175 "1.0");
1153 TestBrokenHTTPSReporting( 1176 TestBrokenHTTPSReporting(
1154 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN, 1177 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN,
1155 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1178 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1156 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser()); 1179 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1157 } 1180 }
1158 1181
1159 // Test that when the checkbox is not checked and the user does not proceed 1182 // User goes back, checkbox is shown but unchecked, Finch parameter is set
1160 // through the interstitial, the FraudulentCertificateReporter does not 1183 // -> we expect no report.
1161 // see a request to send a report.
1162 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1184 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1163 TestBrokenHTTPSGoBackWithNoReporting) { 1185 TestBrokenHTTPSGoBackShowYesCheckNoParamYesReportNo) {
1186 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1187 "1.0");
1164 TestBrokenHTTPSReporting( 1188 TestBrokenHTTPSReporting(
1165 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN, 1189 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN,
1166 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED, 1190 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1167 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser()); 1191 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1168 } 1192 }
1169 1193
1170 // Test that when the command-line switch for reporting invalid cert 1194 // 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 1195 // set -> we expect no report.
1172 // preference is set. (i.e. if a user enables invalid cert collection in 1196 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1173 // chrome://flags, checks the box on an interstitial, and then disables 1197 TestBrokenHTTPSProceedShowYesCheckYesParamNoReportNo) {
1174 // the flag in chrome://flags, reports shouldn't be sent on the next 1198 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1175 // interstitial). 1199 "-1.0");
1176 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) {
1177 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1200 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1178 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1201 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1179 CertificateReporting::CERT_REPORT_NOT_EXPECTED, 1202 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1180 browser()); 1203 browser());
1181 } 1204 }
1182 1205
1183 // Test that reports don't get sent in incognito mode even if the opt-in 1206 // User goes back, checkbox is shown and checked, Finch parameter is not set
1184 // preference is set and the command-line switch is enabled. 1207 // -> we expect no report.
1185 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1208 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1186 TestBrokenHTTPSNoReportingInIncognito) { 1209 TestBrokenHTTPSGoBackShowYesCheckYesParamNoReportNo) {
1210 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1211 "-1.0");
1212 TestBrokenHTTPSReporting(
1213 CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1214 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1215 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1216 }
1217
1218 // User proceeds, checkbox is not shown but checked -> we expect no report
1219 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1220 TestBrokenHTTPSProceedShowNoCheckYesReportNo) {
1221 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupDontShowDontSend);
1222 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1223 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1224 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1225 browser());
1226 }
1227
1228 // Browser is incognito, user proceeds, checkbox is shown and checked, Finch
1229 // parameter is set -> we expect no report
1230 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1231 TestBrokenHTTPSInIncognitoReportNo) {
1232 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1233 "1.0");
1187 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1234 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1188 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1235 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1189 CertificateReporting::CERT_REPORT_NOT_EXPECTED, 1236 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1190 CreateIncognitoBrowser()); 1237 CreateIncognitoBrowser());
1191 } 1238 }
1192 1239
1240 // User proceeds, checkbox is shown and checked, Finch parameter is invalid
1241 // -> we expect no report.
1242 IN_PROC_BROWSER_TEST_F(
1243 SSLUITestWithExtendedReporting,
1244 TestBrokenHTTPSProceedWithShowYesCheckYesParamInvalidReportNo) {
1245 SetCertReportingFinchConfig(kHTTPSErrorReporterFinchGroupShowPossiblySend,
1246 "abcdef");
1247 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1248 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1249 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1250 browser());
1251 }
1252
1193 // Visits a page that runs insecure content and tries to suppress the insecure 1253 // Visits a page that runs insecure content and tries to suppress the insecure
1194 // content warnings by randomizing location.hash. 1254 // content warnings by randomizing location.hash.
1195 // Based on http://crbug.com/8706 1255 // Based on http://crbug.com/8706
1196 IN_PROC_BROWSER_TEST_F(SSLUITest, 1256 IN_PROC_BROWSER_TEST_F(SSLUITest,
1197 TestRunsInsecuredContentRandomizeHash) { 1257 TestRunsInsecuredContentRandomizeHash) {
1198 ASSERT_TRUE(test_server()->Start()); 1258 ASSERT_TRUE(test_server()->Start());
1199 ASSERT_TRUE(https_server_.Start()); 1259 ASSERT_TRUE(https_server_.Start());
1200 1260
1201 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( 1261 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
1202 "files/ssl/page_runs_insecure_content.html")); 1262 "files/ssl/page_runs_insecure_content.html"));
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 2212
2153 // Visit a page over https that contains a frame with a redirect. 2213 // Visit a page over https that contains a frame with a redirect.
2154 2214
2155 // XMLHttpRequest insecure content in synchronous mode. 2215 // XMLHttpRequest insecure content in synchronous mode.
2156 2216
2157 // XMLHttpRequest insecure content in asynchronous mode. 2217 // XMLHttpRequest insecure content in asynchronous mode.
2158 2218
2159 // XMLHttpRequest over bad ssl in synchronous mode. 2219 // XMLHttpRequest over bad ssl in synchronous mode.
2160 2220
2161 // XMLHttpRequest over OK ssl in synchronous mode. 2221 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698