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

Unified Diff: chrome/browser/ssl/certificate_reporting_test_utils.h

Issue 2578873003: Remove certificate reporting code from SafeBrowsing ping and ui managers (Closed)
Patch Set: Rebase Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/certificate_reporting_test_utils.h
diff --git a/chrome/browser/ssl/certificate_reporting_test_utils.h b/chrome/browser/ssl/certificate_reporting_test_utils.h
index 0abafb715aea738009515e5301a3855f47a309fe..94d7bdb40f0ed0a861b89233397a5fccd649bef7 100644
--- a/chrome/browser/ssl/certificate_reporting_test_utils.h
+++ b/chrome/browser/ssl/certificate_reporting_test_utils.h
@@ -8,79 +8,54 @@
#include <memory>
#include <string>
+#include "base/macros.h"
+#include "chrome/browser/ssl/ssl_cert_reporter.h"
#include "components/certificate_reporting/error_reporter.h"
class Browser;
-class GURL;
-class SSLCertReporter;
namespace base {
class RunLoop;
}
-namespace net {
-class URLRequestContext;
-}
-
namespace certificate_reporting_test_utils {
enum OptIn { EXTENDED_REPORTING_OPT_IN, EXTENDED_REPORTING_DO_NOT_OPT_IN };
-enum ExpectReport { CERT_REPORT_EXPECTED, CERT_REPORT_NOT_EXPECTED };
+enum ExpectReport { CERT_REPORT_NOT_EXPECTED, CERT_REPORT_EXPECTED };
-// This class is used to test invalid certificate chain reporting when
-// the user opts in to do so on the interstitial. It keeps track of the
-// most recent hostname for which an extended reporting report would
-// have been sent over the network.
-class MockErrorReporter : public certificate_reporting::ErrorReporter {
+// This class is used to keep track of the latest hostname for sent reports. An
+// SSLCertReporter is destroyed when the interstitial it's associated with is
+// dismissed, so the tests can't check whether SSLCertReporter sent a report.
+// For that reason, SSLCertReporter calls ReportSent() method on this class when
+// it sends a report. SSLCertReporterCallback outlives both the SSLCertReporter
+// and the interstitial so that the tests can query the latest hostname for
+// which a report was sent.
+class SSLCertReporterCallback {
public:
- MockErrorReporter(net::URLRequestContext* request_context,
- const GURL& upload_url,
- net::ReportSender::CookiesPreference cookies_preference);
+ explicit SSLCertReporterCallback(base::RunLoop* run_loop);
+ ~SSLCertReporterCallback();
- // ErrorReporter implementation.
- void SendExtendedReportingReport(
- const std::string& serialized_report,
- const base::Callback<void()>& success_callback,
- const base::Callback<void(const GURL&, int)>& error_callback) override;
+ void ReportSent(const std::string& hostname);
- // Returns the hostname in the report for the last call to |SendReport|.
- const std::string& latest_hostname_reported() {
- return latest_hostname_reported_;
- }
+ const std::string& GetLatestHostnameReported() const;
private:
+ base::RunLoop* run_loop_;
std::string latest_hostname_reported_;
- DISALLOW_COPY_AND_ASSIGN(MockErrorReporter);
-};
-
-// A test class that tracks the latest hostname for which a certificate
-// report would have been sent over the network.
-class CertificateReportingTest {
- public:
- // Set up the mock reporter that keeps track of certificate reports
- // that the safe browsing service sends.
- void SetUpMockReporter();
-
- protected:
- // Get the latest hostname for which a certificate report was
- // sent. SetUpMockReporter() must have been called before this.
- const std::string& GetLatestHostnameReported() const;
-
- private:
- MockErrorReporter* reporter_;
+ DISALLOW_COPY_AND_ASSIGN(SSLCertReporterCallback);
};
// Sets the browser preference to enable or disable extended reporting.
void SetCertReportingOptIn(Browser* browser, OptIn opt_in);
-// Sets up a mock SSLCertReporter and return a pointer to it, which will
+// Creates a mock SSLCertReporter and return a pointer to it, which will
// be owned by the caller. The mock SSLCertReporter will call
-// |run_loop|'s QuitClosure when a report is sent. It also checks that a
+// |report_sent_callback| when a report is sent. It also checks that a
// report is sent or not sent according to |expect_report|.
-std::unique_ptr<SSLCertReporter> SetUpMockSSLCertReporter(
- base::RunLoop* run_loop,
+std::unique_ptr<SSLCertReporter> CreateMockSSLCertReporter(
+ const base::Callback<void(const std::string&)>& report_sent_callback,
ExpectReport expect_report);
// Returns whether a report should be expected (due to the Finch config)
« no previous file with comments | « chrome/browser/ssl/captive_portal_blocking_page_browsertest.cc ('k') | chrome/browser/ssl/certificate_reporting_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698