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

Unified Diff: chrome/browser/safe_browsing/certificate_reporting_service_browsertest.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_browsertest.cc
diff --git a/chrome/browser/safe_browsing/certificate_reporting_service_browsertest.cc b/chrome/browser/safe_browsing/certificate_reporting_service_browsertest.cc
index dbe29ea07993c81bc20776e957c447b5c4255ade..184e7b4f5a244af8df4da256b25f7d46e7f370ae 100644
--- a/chrome/browser/safe_browsing/certificate_reporting_service_browsertest.cc
+++ b/chrome/browser/safe_browsing/certificate_reporting_service_browsertest.cc
@@ -37,6 +37,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;
@@ -84,6 +85,8 @@ class CertificateReportingServiceBrowserTest : public InProcessBrowserTest {
->SetServiceResetCallbackForTesting(
base::Bind(&CertificateReportingServiceObserver::OnServiceReset,
base::Unretained(&service_observer_)));
+
+ event_histogram_tester_.reset(new EventHistogramTester());
InProcessBrowserTest::SetUpOnMainThread();
}
@@ -102,6 +105,8 @@ class CertificateReportingServiceBrowserTest : public InProcessBrowserTest {
} else {
histogram_tester_.ExpectTotalCount(kFailedReportHistogram, 0);
}
+
+ event_histogram_tester_.reset();
}
void SetUpCommandLine(base::CommandLine* command_line) override {
@@ -175,6 +180,10 @@ class CertificateReportingServiceBrowserTest : public InProcessBrowserTest {
browser()->profile());
}
+ EventHistogramTester* event_histogram_tester() {
+ return event_histogram_tester_.get();
+ }
+
private:
// Checks that the serialized reports in |received_reports| have the same
// hostnames as |expected_hostnames|.
@@ -200,6 +209,11 @@ class CertificateReportingServiceBrowserTest : public InProcessBrowserTest {
CertificateReportingServiceObserver service_observer_;
base::HistogramTester histogram_tester_;
+ // 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_;
DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceBrowserTest);
};
@@ -216,6 +230,8 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
// Send a report. Test teardown checks for created and in-flight requests. If
// a report was incorrectly sent, the test will fail.
SendReport("no-report");
+
+ event_histogram_tester()->SetExpectedValues(0, 0, 0, 0);
}
// Tests that report send attempts are not cancelled when extended reporting is
@@ -236,6 +252,10 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
SendReport("report0");
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Successful({{"report0", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was successfully submitted.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */);
}
// Tests that report send attempts are not cancelled when extended reporting is
@@ -280,6 +300,12 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
// nothing should be sent this time. If any report is sent, test teardown
// will catch it.
SendPendingReports();
+
+ // report0 was submitted twice, failed once, succeeded once.
+ // report1 was submitted twice, failed once, succeeded once.
+ // report2 was submitted once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 5 /* submitted */, 2 /* failed */, 3 /* successful */, 0 /* dropped */);
}
// Opting in then opting out of extended reporting should clear the pending
@@ -305,6 +331,10 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
// Send pending reports. No reports should be observed during test teardown.
SendPendingReports();
+
+ // report0 was submitted once and failed once.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 1 /* failed */, 0 /* successful */, 0 /* dropped */);
}
// Opting out, then in, then out of extended reporting should work as expected.
@@ -344,6 +374,11 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
// Send pending reports. Nothing should be sent since there aren't any
// pending reports. If any report is sent, test teardown will catch it.
SendPendingReports();
+
+ // report0 was submitted once and failed once.
+ // report1 was never submitted.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 1 /* failed */, 0 /* successful */, 0 /* dropped */);
}
// Disabling SafeBrowsing should clear pending reports queue in
@@ -358,7 +393,7 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
test_helper()->SetFailureMode(
certificate_reporting_test_utils::ReportSendingResult::REPORTS_FAIL);
- // Send a delayed report.
+ // Send a report.
SendReport("report0");
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Failed({{"report0", RetryStatus::NOT_RETRIED}}));
@@ -382,6 +417,11 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
SendPendingReports();
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Successful({{"report1", RetryStatus::RETRIED}}));
+
+ // report0 was submitted once, failed once, then cleared.
+ // report1 was submitted twice, failed once, succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 3 /* submitted */, 2 /* failed */, 1 /* successful */, 0 /* dropped */);
}
// CertificateReportingService should ignore reports older than the report TTL.
@@ -446,6 +486,12 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
// Send pending reports. report2 should be discarded since it's too old. No
// other reports remain. If any report is sent, test teardown will catch it.
SendPendingReports();
+
+ // report0 was submitted once, failed once, dropped once.
+ // report1 was submitted twice, failed twice, dropped once.
+ // report2 was submitted twice, failed twice, dropped once.
+ event_histogram_tester()->SetExpectedValues(
+ 5 /* submitted */, 5 /* failed */, 0 /* successful */, 3 /* dropped */);
}
// CertificateReportingService should drop old reports from its pending report
@@ -520,6 +566,13 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
SendPendingReports();
test_helper()->WaitForRequestsDestroyed(ReportExpectation::Successful(
{{"report2", RetryStatus::RETRIED}, {"report3", RetryStatus::RETRIED}}));
+
+ // 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 */);
}
IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
@@ -543,6 +596,10 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
test_helper()->ResumeDelayedRequest();
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was submitted once and succeeded once.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */);
}
// Same as above, but the service is shut down before resuming the delayed
@@ -567,6 +624,10 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest,
test_helper()->ResumeDelayedRequest();
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Delayed({{"report0", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was submitted once and never completed since the service shut down.
+ event_histogram_tester()->SetExpectedValues(
+ 1 /* submitted */, 0 /* failed */, 0 /* successful */, 0 /* dropped */);
}
// Trigger a delayed report, then disable Safebrowsing. Certificate reporting
@@ -607,6 +668,11 @@ IN_PROC_BROWSER_TEST_F(CertificateReportingServiceBrowserTest, Delayed_Reset) {
test_helper()->ResumeDelayedRequest();
test_helper()->WaitForRequestsDestroyed(
ReportExpectation::Delayed({{"report1", RetryStatus::NOT_RETRIED}}));
+
+ // report0 was submitted once and delayed, then cleared.
+ // report1 was submitted once and delayed, then succeeded.
+ event_histogram_tester()->SetExpectedValues(
+ 2 /* submitted */, 0 /* failed */, 1 /* successful */, 0 /* dropped */);
}
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698