OLD | NEW |
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/certificate_reporting_test_utils.h" | 5 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/safe_browsing/ping_manager.h" | 15 #include "chrome/browser/safe_browsing/ping_manager.h" |
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
16 #include "chrome/browser/safe_browsing/ui_manager.h" | 17 #include "chrome/browser/safe_browsing/ui_manager.h" |
17 #include "chrome/browser/ssl/cert_report_helper.h" | 18 #include "chrome/browser/ssl/cert_report_helper.h" |
18 #include "chrome/browser/ssl/certificate_error_report.h" | 19 #include "chrome/browser/ssl/certificate_error_report.h" |
19 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 20 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 g_browser_process->safe_browsing_service(); | 94 g_browser_process->safe_browsing_service(); |
94 ASSERT_TRUE(safe_browsing_service); | 95 ASSERT_TRUE(safe_browsing_service); |
95 | 96 |
96 content::BrowserThread::PostTask( | 97 content::BrowserThread::PostTask( |
97 content::BrowserThread::IO, FROM_HERE, | 98 content::BrowserThread::IO, FROM_HERE, |
98 base::Bind( | 99 base::Bind( |
99 SetMockReporter, safe_browsing_service, | 100 SetMockReporter, safe_browsing_service, |
100 base::Passed(scoped_ptr<CertificateErrorReporter>(reporter_)))); | 101 base::Passed(scoped_ptr<CertificateErrorReporter>(reporter_)))); |
101 } | 102 } |
102 | 103 |
103 const std::string& CertificateReportingTest::GetLatestHostnameReported() { | 104 const std::string& CertificateReportingTest::GetLatestHostnameReported() const { |
104 return reporter_->latest_hostname_reported(); | 105 return reporter_->latest_hostname_reported(); |
105 } | 106 } |
106 | 107 |
107 // This is a test implementation of the interface that blocking pages | 108 // This is a test implementation of the interface that blocking pages |
108 // use to send certificate reports. It checks that the blocking page | 109 // use to send certificate reports. It checks that the blocking page |
109 // calls or does not call the report method when a report should or | 110 // calls or does not call the report method when a report should or |
110 // should not be sent, respectively. | 111 // should not be sent, respectively. |
111 class MockSSLCertReporter : public SSLCertReporter { | 112 class MockSSLCertReporter : public SSLCertReporter { |
112 public: | 113 public: |
113 MockSSLCertReporter( | 114 MockSSLCertReporter( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return nullptr; | 157 return nullptr; |
157 | 158 |
158 scoped_ptr<MockSSLCertReporter> ssl_cert_reporter(new MockSSLCertReporter( | 159 scoped_ptr<MockSSLCertReporter> ssl_cert_reporter(new MockSSLCertReporter( |
159 sb_service->ui_manager(), expect_report == CERT_REPORT_EXPECTED | 160 sb_service->ui_manager(), expect_report == CERT_REPORT_EXPECTED |
160 ? run_loop->QuitClosure() | 161 ? run_loop->QuitClosure() |
161 : base::Bind(&base::DoNothing))); | 162 : base::Bind(&base::DoNothing))); |
162 ssl_cert_reporter->set_expect_report(expect_report == CERT_REPORT_EXPECTED); | 163 ssl_cert_reporter->set_expect_report(expect_report == CERT_REPORT_EXPECTED); |
163 return ssl_cert_reporter.Pass(); | 164 return ssl_cert_reporter.Pass(); |
164 } | 165 } |
165 | 166 |
166 // Helper function to set the Finch options. | 167 ExpectReport GetReportExpectedFromFinch() { |
167 void SetCertReportingFinchConfig(const std::string& group_name, | 168 const std::string group_name = base::FieldTrialList::FindFullName( |
168 const std::string& param_value) { | 169 CertReportHelper::kFinchExperimentName); |
169 base::FieldTrialList::CreateFieldTrial(CertReportHelper::kFinchExperimentName, | 170 |
170 group_name); | 171 if (group_name == CertReportHelper::kFinchGroupShowPossiblySend) { |
171 if (!param_value.empty()) { | 172 const std::string param = variations::GetVariationParamValue( |
172 std::map<std::string, std::string> params; | 173 CertReportHelper::kFinchExperimentName, |
173 params[CertReportHelper::kFinchParamName] = param_value; | 174 CertReportHelper::kFinchParamName); |
174 variations::AssociateVariationParams(CertReportHelper::kFinchExperimentName, | 175 double sendingThreshold; |
175 group_name, params); | 176 if (!base::StringToDouble(param, &sendingThreshold)) |
| 177 return CERT_REPORT_NOT_EXPECTED; |
| 178 |
| 179 if (sendingThreshold == 1.0) |
| 180 return CertificateReportingTestUtils::CERT_REPORT_EXPECTED; |
176 } | 181 } |
177 } | 182 return CertificateReportingTestUtils::CERT_REPORT_NOT_EXPECTED; |
178 | |
179 // Helper function to set the Finch options in case we have no parameter. | |
180 void SetCertReportingFinchConfig(const std::string& group_name) { | |
181 SetCertReportingFinchConfig(group_name, std::string()); | |
182 } | 183 } |
183 | 184 |
184 } // namespace CertificateReportingTestUtils | 185 } // namespace CertificateReportingTestUtils |
OLD | NEW |