| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/safe_browsing/ping_manager.h" | 17 #include "chrome/browser/safe_browsing/ping_manager.h" |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 19 #include "chrome/browser/safe_browsing/ui_manager.h" | 19 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 20 #include "chrome/browser/ssl/cert_report_helper.h" | 20 #include "chrome/browser/ssl/cert_report_helper.h" |
| 21 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 21 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "components/certificate_reporting/error_report.h" | 24 #include "components/certificate_reporting/error_report.h" |
| 25 #include "components/certificate_reporting/error_reporter.h" | 25 #include "components/certificate_reporting/error_reporter.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/variations/variations_associated_data.h" | 27 #include "components/variations/variations_associated_data.h" |
| 28 #include "net/url_request/certificate_report_sender.h" | 28 #include "net/url_request/report_sender.h" |
| 29 #include "net/url_request/url_request_context.h" | 29 #include "net/url_request/url_request_context.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 32 | 32 |
| 33 using safe_browsing::SafeBrowsingService; | 33 using safe_browsing::SafeBrowsingService; |
| 34 using safe_browsing::SafeBrowsingUIManager; | 34 using safe_browsing::SafeBrowsingUIManager; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 void SetMockReporter( | 38 void SetMockReporter( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 namespace certificate_reporting_test_utils { | 82 namespace certificate_reporting_test_utils { |
| 83 | 83 |
| 84 // This class is used to test invalid certificate chain reporting when | 84 // This class is used to test invalid certificate chain reporting when |
| 85 // the user opts in to do so on the interstitial. It keeps track of the | 85 // the user opts in to do so on the interstitial. It keeps track of the |
| 86 // most recent hostname for which an extended reporting report would | 86 // most recent hostname for which an extended reporting report would |
| 87 // have been sent over the network. | 87 // have been sent over the network. |
| 88 class CertificateReportingTest::MockReporter | 88 class CertificateReportingTest::MockReporter |
| 89 : public certificate_reporting::ErrorReporter { | 89 : public certificate_reporting::ErrorReporter { |
| 90 public: | 90 public: |
| 91 MockReporter( | 91 MockReporter(net::URLRequestContext* request_context, |
| 92 net::URLRequestContext* request_context, | 92 const GURL& upload_url, |
| 93 const GURL& upload_url, | 93 net::ReportSender::CookiesPreference cookies_preference); |
| 94 net::CertificateReportSender::CookiesPreference cookies_preference); | |
| 95 | 94 |
| 96 // ErrorReporter implementation. | 95 // ErrorReporter implementation. |
| 97 void SendExtendedReportingReport( | 96 void SendExtendedReportingReport( |
| 98 const std::string& serialized_report) override; | 97 const std::string& serialized_report) override; |
| 99 | 98 |
| 100 // Returns the hostname in the report for the last call to | 99 // Returns the hostname in the report for the last call to |
| 101 // |SendReport|. | 100 // |SendReport|. |
| 102 const std::string& latest_hostname_reported() { | 101 const std::string& latest_hostname_reported() { |
| 103 return latest_hostname_reported_; | 102 return latest_hostname_reported_; |
| 104 } | 103 } |
| 105 | 104 |
| 106 private: | 105 private: |
| 107 std::string latest_hostname_reported_; | 106 std::string latest_hostname_reported_; |
| 108 | 107 |
| 109 DISALLOW_COPY_AND_ASSIGN(MockReporter); | 108 DISALLOW_COPY_AND_ASSIGN(MockReporter); |
| 110 }; | 109 }; |
| 111 | 110 |
| 112 CertificateReportingTest::MockReporter::MockReporter( | 111 CertificateReportingTest::MockReporter::MockReporter( |
| 113 net::URLRequestContext* request_context, | 112 net::URLRequestContext* request_context, |
| 114 const GURL& upload_url, | 113 const GURL& upload_url, |
| 115 net::CertificateReportSender::CookiesPreference cookies_preference) | 114 net::ReportSender::CookiesPreference cookies_preference) |
| 116 : certificate_reporting::ErrorReporter(request_context, | 115 : certificate_reporting::ErrorReporter(request_context, |
| 117 upload_url, | 116 upload_url, |
| 118 cookies_preference) {} | 117 cookies_preference) {} |
| 119 | 118 |
| 120 void CertificateReportingTest::MockReporter::SendExtendedReportingReport( | 119 void CertificateReportingTest::MockReporter::SendExtendedReportingReport( |
| 121 const std::string& serialized_report) { | 120 const std::string& serialized_report) { |
| 122 certificate_reporting::ErrorReport report; | 121 certificate_reporting::ErrorReport report; |
| 123 ASSERT_TRUE(report.InitializeFromString(serialized_report)); | 122 ASSERT_TRUE(report.InitializeFromString(serialized_report)); |
| 124 latest_hostname_reported_ = report.hostname(); | 123 latest_hostname_reported_ = report.hostname(); |
| 125 } | 124 } |
| 126 | 125 |
| 127 void CertificateReportingTest::SetUpMockReporter() { | 126 void CertificateReportingTest::SetUpMockReporter() { |
| 128 // Set up the mock reporter to track the hostnames that reports get | 127 // Set up the mock reporter to track the hostnames that reports get |
| 129 // sent for. The request_context argument is null here | 128 // sent for. The request_context argument is null here |
| 130 // because the MockReporter doesn't actually use a | 129 // because the MockReporter doesn't actually use a |
| 131 // request_context. (In order to pass a real request_context, the | 130 // request_context. (In order to pass a real request_context, the |
| 132 // reporter would have to be constructed on the IO thread.) | 131 // reporter would have to be constructed on the IO thread.) |
| 133 reporter_ = new CertificateReportingTest::MockReporter( | 132 reporter_ = new CertificateReportingTest::MockReporter( |
| 134 nullptr, GURL("http://example.test"), | 133 nullptr, GURL("http://example.test"), |
| 135 net::CertificateReportSender::DO_NOT_SEND_COOKIES); | 134 net::ReportSender::DO_NOT_SEND_COOKIES); |
| 136 | 135 |
| 137 scoped_refptr<SafeBrowsingService> safe_browsing_service = | 136 scoped_refptr<SafeBrowsingService> safe_browsing_service = |
| 138 g_browser_process->safe_browsing_service(); | 137 g_browser_process->safe_browsing_service(); |
| 139 ASSERT_TRUE(safe_browsing_service); | 138 ASSERT_TRUE(safe_browsing_service); |
| 140 | 139 |
| 141 content::BrowserThread::PostTask( | 140 content::BrowserThread::PostTask( |
| 142 content::BrowserThread::IO, FROM_HERE, | 141 content::BrowserThread::IO, FROM_HERE, |
| 143 base::Bind( | 142 base::Bind( |
| 144 SetMockReporter, base::RetainedRef(safe_browsing_service), | 143 SetMockReporter, base::RetainedRef(safe_browsing_service), |
| 145 base::Passed(std::unique_ptr<certificate_reporting::ErrorReporter>( | 144 base::Passed(std::unique_ptr<certificate_reporting::ErrorReporter>( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (!base::StringToDouble(param, &sendingThreshold)) | 186 if (!base::StringToDouble(param, &sendingThreshold)) |
| 188 return CERT_REPORT_NOT_EXPECTED; | 187 return CERT_REPORT_NOT_EXPECTED; |
| 189 | 188 |
| 190 if (sendingThreshold == 1.0) | 189 if (sendingThreshold == 1.0) |
| 191 return certificate_reporting_test_utils::CERT_REPORT_EXPECTED; | 190 return certificate_reporting_test_utils::CERT_REPORT_EXPECTED; |
| 192 } | 191 } |
| 193 return certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED; | 192 return certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED; |
| 194 } | 193 } |
| 195 | 194 |
| 196 } // namespace certificate_reporting_test_utils | 195 } // namespace certificate_reporting_test_utils |
| OLD | NEW |