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

Unified Diff: net/url_request/certificate_report_sender_unittest.cc

Issue 1847563004: Add error callback to net::CertificateReportSender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: eroman comment Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/certificate_report_sender.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/certificate_report_sender_unittest.cc
diff --git a/net/url_request/certificate_report_sender_unittest.cc b/net/url_request/certificate_report_sender_unittest.cc
index 0024bcbe5eb38ad2084cec241e7faefea4ff5170..8cf7a9162e1d34eb783c1d670ec06d901b0de92d 100644
--- a/net/url_request/certificate_report_sender_unittest.cc
+++ b/net/url_request/certificate_report_sender_unittest.cc
@@ -47,6 +47,13 @@ void CheckUploadData(const URLRequest& request,
EXPECT_EQ(1u, expect_reports->erase(upload_data));
}
+// Provides an error callback for report sending. If the callback is
+// called, it sets |called| to true.
+void ErrorCallback(bool* called, URLRequest* request) {
+ EXPECT_FALSE(request->status().is_success());
+ *called = true;
+}
+
// A network delegate that lets tests check that a certificate report
// was sent. It counts the number of requests and lets tests register a
// callback to run when the request is destroyed. It also checks that
@@ -238,6 +245,31 @@ TEST_F(CertificateReportSenderTest, ErroredRequestGetsDeleted) {
SendReport(&reporter, kDummyReport, url, 0);
}
+// Test that the error callback, if provided, gets called when a request
+// returns an error.
+TEST_F(CertificateReportSenderTest, ErroredRequestCallsCallback) {
+ bool error_callback_called = false;
+ GURL url = URLRequestFailedJob::GetMockHttpsUrl(ERR_FAILED);
+ CertificateReportSender reporter(
+ context(), CertificateReportSender::DO_NOT_SEND_COOKIES,
+ base::Bind(ErrorCallback, &error_callback_called));
+ // SendReport will block until the URLRequest is destroyed.
+ SendReport(&reporter, kDummyReport, url, 0);
+ EXPECT_TRUE(error_callback_called);
+}
+
+// Test that the error callback does not get called when a request
+// does not return an error.
+TEST_F(CertificateReportSenderTest, SuccessfulRequestDoesNotCallErrorCallback) {
+ bool error_callback_called = false;
+ GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
+ CertificateReportSender reporter(
+ context(), CertificateReportSender::DO_NOT_SEND_COOKIES,
+ base::Bind(ErrorCallback, &error_callback_called));
+ SendReport(&reporter, kDummyReport, url, 0);
+ EXPECT_FALSE(error_callback_called);
+}
+
// Test that cookies are sent or not sent according to the error
// reporter's cookies preference.
« no previous file with comments | « net/url_request/certificate_report_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698