| 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 #ifndef CHROME_BROWSER_SSL_CERTIFICATE_REPORTING_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_SSL_CERTIFICATE_REPORTING_TEST_UTILS_H_ |
| 6 #define CHROME_BROWSER_SSL_CERTIFICATE_REPORTING_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_SSL_CERTIFICATE_REPORTING_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 12 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 13 #include "components/certificate_reporting/cert_logger.pb.h" |
| 13 #include "components/certificate_reporting/error_reporter.h" | 14 #include "components/certificate_reporting/error_reporter.h" |
| 14 | 15 |
| 15 class Browser; | 16 class Browser; |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class RunLoop; | 19 class RunLoop; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace certificate_reporting_test_utils { | 22 namespace certificate_reporting_test_utils { |
| 22 | 23 |
| 23 enum OptIn { EXTENDED_REPORTING_OPT_IN, EXTENDED_REPORTING_DO_NOT_OPT_IN }; | 24 enum OptIn { EXTENDED_REPORTING_OPT_IN, EXTENDED_REPORTING_DO_NOT_OPT_IN }; |
| 24 | 25 |
| 25 enum ExpectReport { CERT_REPORT_NOT_EXPECTED, CERT_REPORT_EXPECTED }; | 26 enum ExpectReport { CERT_REPORT_NOT_EXPECTED, CERT_REPORT_EXPECTED }; |
| 26 | 27 |
| 27 // This class is used to keep track of the latest hostname for sent reports. An | 28 // This class is used to keep track of the latest hostname for sent reports. An |
| 28 // SSLCertReporter is destroyed when the interstitial it's associated with is | 29 // SSLCertReporter is destroyed when the interstitial it's associated with is |
| 29 // dismissed, so the tests can't check whether SSLCertReporter sent a report. | 30 // dismissed, so the tests can't check whether SSLCertReporter sent a report. |
| 30 // For that reason, SSLCertReporter calls ReportSent() method on this class when | 31 // For that reason, SSLCertReporter calls ReportSent() method on this class when |
| 31 // it sends a report. SSLCertReporterCallback outlives both the SSLCertReporter | 32 // it sends a report. SSLCertReporterCallback outlives both the SSLCertReporter |
| 32 // and the interstitial so that the tests can query the latest hostname for | 33 // and the interstitial so that the tests can query the latest hostname for |
| 33 // which a report was sent. | 34 // which a report was sent. |
| 34 class SSLCertReporterCallback { | 35 class SSLCertReporterCallback { |
| 35 public: | 36 public: |
| 36 explicit SSLCertReporterCallback(base::RunLoop* run_loop); | 37 explicit SSLCertReporterCallback(base::RunLoop* run_loop); |
| 37 ~SSLCertReporterCallback(); | 38 ~SSLCertReporterCallback(); |
| 38 | 39 |
| 39 void ReportSent(const std::string& hostname); | 40 void ReportSent(const std::string& hostname, |
| 41 const certificate_reporting::CertLoggerRequest::ChromeChannel |
| 42 chrome_channel); |
| 40 | 43 |
| 41 const std::string& GetLatestHostnameReported() const; | 44 const std::string& GetLatestHostnameReported() const; |
| 45 certificate_reporting::CertLoggerRequest::ChromeChannel |
| 46 GetLatestChromeChannelReported() const; |
| 42 | 47 |
| 43 private: | 48 private: |
| 44 base::RunLoop* run_loop_; | 49 base::RunLoop* run_loop_; |
| 45 std::string latest_hostname_reported_; | 50 std::string latest_hostname_reported_; |
| 51 certificate_reporting::CertLoggerRequest::ChromeChannel chrome_channel_; |
| 46 | 52 |
| 47 DISALLOW_COPY_AND_ASSIGN(SSLCertReporterCallback); | 53 DISALLOW_COPY_AND_ASSIGN(SSLCertReporterCallback); |
| 48 }; | 54 }; |
| 49 | 55 |
| 50 // Sets the browser preference to enable or disable extended reporting. | 56 // Sets the browser preference to enable or disable extended reporting. |
| 51 void SetCertReportingOptIn(Browser* browser, OptIn opt_in); | 57 void SetCertReportingOptIn(Browser* browser, OptIn opt_in); |
| 52 | 58 |
| 53 // Creates a mock SSLCertReporter and return a pointer to it, which will | 59 // Creates a mock SSLCertReporter and return a pointer to it, which will |
| 54 // be owned by the caller. The mock SSLCertReporter will call | 60 // be owned by the caller. The mock SSLCertReporter will call |
| 55 // |report_sent_callback| when a report is sent. It also checks that a | 61 // |report_sent_callback| when a report is sent. It also checks that a |
| 56 // report is sent or not sent according to |expect_report|. | 62 // report is sent or not sent according to |expect_report|. |
| 57 std::unique_ptr<SSLCertReporter> CreateMockSSLCertReporter( | 63 std::unique_ptr<SSLCertReporter> CreateMockSSLCertReporter( |
| 58 const base::Callback<void(const std::string&)>& report_sent_callback, | 64 const base::Callback< |
| 65 void(const std::string&, |
| 66 const certificate_reporting::CertLoggerRequest_ChromeChannel)>& |
| 67 report_sent_callback, |
| 59 ExpectReport expect_report); | 68 ExpectReport expect_report); |
| 60 | 69 |
| 61 // Returns whether a report should be expected (due to the Finch config) | 70 // Returns whether a report should be expected (due to the Finch config) |
| 62 // if the user opts in. | 71 // if the user opts in. |
| 63 ExpectReport GetReportExpectedFromFinch(); | 72 ExpectReport GetReportExpectedFromFinch(); |
| 64 | 73 |
| 65 } // namespace certificate_reporting_test_utils | 74 } // namespace certificate_reporting_test_utils |
| 66 | 75 |
| 67 #endif // CHROME_BROWSER_SSL_CERTIFICATE_REPORTING_TEST_UTILS_H_ | 76 #endif // CHROME_BROWSER_SSL_CERTIFICATE_REPORTING_TEST_UTILS_H_ |
| OLD | NEW |