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

Unified Diff: components/certificate_reporting/error_reporter_unittest.cc

Issue 2483993002: Add report_id to ErrorReporter interface. (Closed)
Patch Set: Same as patchset #2 but with the proper diff Created 4 years, 1 month 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: components/certificate_reporting/error_reporter_unittest.cc
diff --git a/components/certificate_reporting/error_reporter_unittest.cc b/components/certificate_reporting/error_reporter_unittest.cc
index 08c43d9b00a79f35999ecff2c0dbe74ed835514f..8a5480b23af0981c595808923c62386cbadaae4a 100644
--- a/components/certificate_reporting/error_reporter_unittest.cc
+++ b/components/certificate_reporting/error_reporter_unittest.cc
@@ -16,10 +16,10 @@
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "base/test/histogram_tester.h"
#include "components/certificate_reporting/encrypted_cert_logger.pb.h"
#include "crypto/curve25519.h"
#include "net/test/url_request/url_request_failed_job.h"
+#include "net/test/url_request/url_request_mock_data_job.h"
#include "net/url_request/report_sender.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,7 +32,21 @@ const char kDummyHttpReportUri[] = "http://example.test";
const char kDummyHttpsReportUri[] = "https://example.test";
const char kDummyReport[] = "a dummy report";
const uint32_t kServerPublicKeyTestVersion = 16;
-const char kFailureHistogramName[] = "SSL.CertificateErrorReportFailure";
+
+void ErrorCallback(bool* called,
+ int expected_report_id,
+ const GURL& report_uri,
+ int net_error,
+ int report_id) {
+ EXPECT_NE(net::OK, net_error);
+ *called = true;
+ EXPECT_EQ(expected_report_id, report_id);
+}
+
+void SuccessCallback(bool* called, int expected_report_id, int report_id) {
+ *called = true;
+ EXPECT_EQ(expected_report_id, report_id);
+}
// A mock ReportSender that keeps track of the last report
// sent.
@@ -120,7 +134,7 @@ TEST_F(ErrorReporterTest, ExtendedReportingSendReport) {
ErrorReporter https_reporter(https_url, server_public_key_,
kServerPublicKeyTestVersion,
base::WrapUnique(mock_report_sender));
- https_reporter.SendExtendedReportingReport(kDummyReport);
+ https_reporter.SendExtendedReportingReport(kDummyReport, 0);
EXPECT_EQ(mock_report_sender->latest_report_uri(), https_url);
EXPECT_EQ(mock_report_sender->latest_report(), kDummyReport);
@@ -131,7 +145,7 @@ TEST_F(ErrorReporterTest, ExtendedReportingSendReport) {
ErrorReporter http_reporter(http_url, server_public_key_,
kServerPublicKeyTestVersion,
base::WrapUnique(http_mock_report_sender));
- http_reporter.SendExtendedReportingReport(kDummyReport);
+ http_reporter.SendExtendedReportingReport(kDummyReport, 0);
EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url);
EXPECT_EQ("application/octet-stream",
@@ -153,12 +167,9 @@ TEST_F(ErrorReporterTest, ExtendedReportingSendReport) {
}
// Tests that an UMA histogram is recorded if a report fails to send.
-TEST_F(ErrorReporterTest, UMAOnFailure) {
+TEST_F(ErrorReporterTest, ErroredRequestCallsCallback) {
net::URLRequestFailedJob::AddUrlHandler();
- base::HistogramTester histograms;
- histograms.ExpectTotalCount(kFailureHistogramName, 0);
-
base::RunLoop run_loop;
net::TestURLRequestContext context(true);
TestCertificateReporterNetworkDelegate test_delegate;
@@ -170,12 +181,48 @@ TEST_F(ErrorReporterTest, UMAOnFailure) {
net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_FAILED));
ErrorReporter reporter(&context, report_uri,
net::ReportSender::DO_NOT_SEND_COOKIES);
- reporter.SendExtendedReportingReport(kDummyReport);
+
+ bool error_callback_called = false;
+ bool success_callback_called = false;
+ const int report_id = 42;
+ reporter.SetErrorCallback(
+ base::Bind(&ErrorCallback, &error_callback_called, report_id));
+ reporter.SetSuccessCallback(
+ base::Bind(&SuccessCallback, &success_callback_called, report_id));
+ reporter.SendExtendedReportingReport(kDummyReport, report_id);
+ run_loop.Run();
+
+ EXPECT_TRUE(error_callback_called);
+ EXPECT_FALSE(success_callback_called);
+}
+
+// Tests that an UMA histogram is recorded if a report fails to send.
+TEST_F(ErrorReporterTest, SuccessfulRequestCallsCallback) {
+ net::URLRequestMockDataJob::AddUrlHandler();
+
+ base::RunLoop run_loop;
+ net::TestURLRequestContext context(true);
+ TestCertificateReporterNetworkDelegate test_delegate;
+ test_delegate.set_url_request_destroyed_callback(run_loop.QuitClosure());
+ context.set_network_delegate(&test_delegate);
+ context.Init();
+
+ GURL report_uri(net::URLRequestMockDataJob::GetMockHttpUrl("some data", 1));
+ ErrorReporter reporter(&context, report_uri,
+ net::ReportSender::DO_NOT_SEND_COOKIES);
+
+ bool error_callback_called = false;
+ bool success_callback_called = false;
+ const int report_id = 42;
+ reporter.SetErrorCallback(
+ base::Bind(&ErrorCallback, &error_callback_called, report_id));
+ reporter.SetSuccessCallback(
+ base::Bind(&SuccessCallback, &success_callback_called, report_id));
+ reporter.SendExtendedReportingReport(kDummyReport, report_id);
run_loop.Run();
- histograms.ExpectTotalCount(kFailureHistogramName, 1);
- histograms.ExpectBucketCount(kFailureHistogramName,
- -net::ERR_CONNECTION_FAILED, 1);
+ EXPECT_FALSE(error_callback_called);
+ EXPECT_TRUE(success_callback_called);
}
// This test decrypts a "known gold" report. It's intentionally brittle

Powered by Google App Engine
This is Rietveld 408576698