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

Unified Diff: chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc

Issue 2862453002: Add metrics for certificate report uploads (Closed)
Patch Set: Rebase and address comments Created 3 years, 7 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
Index: chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc
diff --git a/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc b/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc
index 724edb52dd9a4a0ff9d368c7d8758276222edfad..d224a65a98b8b85b60cb5008a90503fc43e3a846 100644
--- a/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc
+++ b/chrome/browser/safe_browsing/certificate_reporting_service_unittest.cc
@@ -36,6 +36,7 @@
using certificate_reporting_test_utils::CertificateReportingServiceTestHelper;
using certificate_reporting_test_utils::CertificateReportingServiceObserver;
+using certificate_reporting_test_utils::EventHistogramTester;
using certificate_reporting_test_utils::ReportExpectation;
using certificate_reporting_test_utils::RetryStatus;
@@ -119,6 +120,8 @@ class ReportHistogramTestHelper {
} // namespace
TEST(CertificateReportingServiceReportListTest, BoundedReportList) {
+ EventHistogramTester event_histogram_tester;
+
// Create a report list with maximum of 2 items.
CertificateReportingService::BoundedReportList list(2 /* max_size */);
EXPECT_EQ(0u, list.items().size());
@@ -154,6 +157,9 @@ TEST(CertificateReportingServiceReportListTest, BoundedReportList) {
EXPECT_EQ(2u, list.items().size());
EXPECT_EQ("report3_zero_minutes_old", list.items()[0].serialized_report);
EXPECT_EQ("report2_five_minutes_old", list.items()[1].serialized_report);
+
+ event_histogram_tester.SetExpectedValues(0 /* submitted */, 0 /* failed */,
+ 0 /* successful */, 2 /* dropped */);
}
class CertificateReportingServiceReporterOnIOThreadTest
@@ -167,13 +173,16 @@ class CertificateReportingServiceReporterOnIOThreadTest
new net::TestURLRequestContextGetter(message_loop_->task_runner());
net::URLRequestFailedJob::AddUrlHandler();
net::URLRequestMockDataJob::AddUrlHandler();
+
+ event_histogram_tester_.reset(new EventHistogramTester());
}
void TearDown() override {
ClearURLHandlers();
- // Check the histogram as the last thing. This makes sure no in-flight
- // report is missed.
+ // Check histograms as the last thing. This makes sure no in-flight report
+ // is missed.
histogram_test_helper_.CheckHistogram();
+ event_histogram_tester_.reset();
}
protected:
@@ -185,12 +194,21 @@ class CertificateReportingServiceReporterOnIOThreadTest
histogram_test_helper_.SetExpectedFailedReportCount(count);
}
+ EventHistogramTester* event_histogram_tester() {
+ return event_histogram_tester_.get();
+ }
+
private:
std::unique_ptr<base::MessageLoopForIO> message_loop_;
std::unique_ptr<content::TestBrowserThread> io_thread_;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
ReportHistogramTestHelper histogram_test_helper_;
+ // Histogram tester for reporting events. This is a member instead of a local
+ // so that we can check the histogram after the test teardown. At that point
+ // all in flight reports should be completed or deleted because
+ // of CleanUpOnIOThread().
+ std::unique_ptr<EventHistogramTester> event_histogram_tester_;
};
TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
@@ -280,6 +298,12 @@ TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
EXPECT_EQ(1u, reporter.inflight_report_count_for_testing());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, list->items().size());
+
+ // report1 was submitted once, failed once, dropped once.
+ // report2 was submitted twice, failed twice, dropped once.
+ // report3 was submitted four times, failed thrice, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 7 /* submitted */, 6 /* failed */, 1 /* successful */, 2 /* dropped */);
}
// Same as above, but retries are disabled.
@@ -329,6 +353,10 @@ TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
reporter.SendPending();
base::RunLoop().RunUntilIdle();
ASSERT_EQ(0u, list->items().size());
+
+ // report1 and report2 were both submitted once, failed once.
+ event_histogram_tester()->SetExpectedValues(
+ 2 /* submitted */, 2 /* failed */, 0 /* successful */, 0 /* dropped */);
}
class CertificateReportingServiceTest : public ::testing::Test {
@@ -364,6 +392,8 @@ class CertificateReportingServiceTest : public ::testing::Test {
base::Bind(&CertificateReportingServiceObserver::OnServiceReset,
base::Unretained(&service_observer_))));
service_observer_.WaitForReset();
+
+ event_histogram_tester_.reset(new EventHistogramTester());
}
void TearDown() override {
@@ -383,6 +413,7 @@ class CertificateReportingServiceTest : public ::testing::Test {
WaitForIOThread();
histogram_test_helper_.CheckHistogram();
+ event_histogram_tester_.reset();
}
protected:
@@ -425,6 +456,10 @@ class CertificateReportingServiceTest : public ::testing::Test {
CertificateReportingServiceTestHelper* test_helper() { return &test_helper_; }
+ EventHistogramTester* event_histogram_tester() {
+ return event_histogram_tester_.get();
+ }
+
private:
void SetUpURLRequestContextOnIOThread() {
std::unique_ptr<net::TestURLRequestContext> url_request_context(
@@ -453,6 +488,8 @@ class CertificateReportingServiceTest : public ::testing::Test {
CertificateReportingServiceTestHelper test_helper_;
ReportHistogramTestHelper histogram_test_helper_;
CertificateReportingServiceObserver service_observer_;
+
+ std::unique_ptr<EventHistogramTester> event_histogram_tester_;
};
TEST_F(CertificateReportingServiceTest, SendSuccessful) {
@@ -467,6 +504,10 @@ TEST_F(CertificateReportingServiceTest, SendSuccessful) {
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Successful({{"report0", RetryStatus::NOT_RETRIED},
{"report1", RetryStatus::NOT_RETRIED}}));
+
+ // report0 and report1 were both submitted once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 2 /* submitted */, 0 /* failed */, 2 /* successful */, 0 /* dropped */);
}
TEST_F(CertificateReportingServiceTest, SendFailure) {
@@ -502,6 +543,11 @@ TEST_F(CertificateReportingServiceTest, SendFailure) {
service()->SendPending();
test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful(
{{"report0", RetryStatus::RETRIED}, {"report1", RetryStatus::RETRIED}}));
+
+ // report0 and report1 were both submitted thrice, failed twice, succeeded
+ // once. report2 was submitted once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 7 /* submitted */, 4 /* failed */, 3 /* successful */, 0 /* dropped */);
}
TEST_F(CertificateReportingServiceTest, Disabled_ShouldNotSend) {
@@ -524,6 +570,10 @@ TEST_F(CertificateReportingServiceTest, Disabled_ShouldNotSend) {
service()->Send(MakeReport("report1"));
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Successful({{"report1", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was never sent. report1 was submitted once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */);
}
TEST_F(CertificateReportingServiceTest, Disabled_ShouldClearPendingReports) {
@@ -549,6 +599,10 @@ TEST_F(CertificateReportingServiceTest, Disabled_ShouldClearPendingReports) {
// Sending with empty queue has no effect.
service()->SendPending();
+
+ // report0 was submitted once, failed once.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 1 /* failed */, 0 /* successful */, 0 /* dropped */);
}
TEST_F(CertificateReportingServiceTest, DontSendOldReports) {
@@ -596,6 +650,13 @@ TEST_F(CertificateReportingServiceTest, DontSendOldReports) {
// Send pending reports. report2 should be discarded since it's too old. No
// other reports remain.
service()->SendPending();
+
+ // report0 was submitted once, failed once, dropped once.
+ // report1 was submitted twice, failed twice, dropped once.
+ // report2 was submitted twice, failed twice, dropped once.
+ // Need to wait for SendPending() to complete.
+ event_histogram_tester()->SetExpectedValues(
+ 5 /* submitted */, 5 /* failed */, 0 /* successful */, 3 /* dropped */);
}
TEST_F(CertificateReportingServiceTest, DiscardOldReports) {
@@ -654,6 +715,13 @@ TEST_F(CertificateReportingServiceTest, DiscardOldReports) {
// Do a final send. No reports should be sent.
service()->SendPending();
+
+ // report0 was submitted once, failed once, dropped once.
+ // report1 was submitted twice, failed twice, dropped once.
+ // report2 was submitted thrice, failed twice, succeeded once.
+ // report3 was submitted thrice, failed twice, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 9 /* submitted */, 7 /* failed */, 2 /* successful */, 2 /* dropped */);
}
// A delayed report should successfully upload when it's resumed.
@@ -672,6 +740,10 @@ TEST_F(CertificateReportingServiceTest, Delayed_Resumed) {
test_helper()->ResumeDelayedRequest();
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was submitted once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */);
}
// Delayed reports should cleaned when the service is reset.
@@ -707,4 +779,9 @@ TEST_F(CertificateReportingServiceTest, Delayed_Reset) {
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED},
{"report1", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was submitted once, but neither failed nor succeeded because the
+ // report queue was cleared. report1 was submitted once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 2 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */);
}
« no previous file with comments | « chrome/browser/safe_browsing/certificate_reporting_service_test_utils.cc ('k') | tools/metrics/histograms/enums.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698