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

Unified Diff: content/child/site_isolation_stats_gatherer_browsertest.cc

Issue 1190423006: base/test/histogram_tester.h: Add a way to query a whole family of related (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review fixes Created 5 years, 6 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
« base/test/histogram_tester.cc ('K') | « base/test/histogram_tester.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/site_isolation_stats_gatherer_browsertest.cc
diff --git a/content/child/site_isolation_stats_gatherer_browsertest.cc b/content/child/site_isolation_stats_gatherer_browsertest.cc
index 43bdd86d98f7b8ec969cd39f9f28225a283d26de..328f751a0161657fab26dde2049435e8a6a3bee2 100644
--- a/content/child/site_isolation_stats_gatherer_browsertest.cc
+++ b/content/child/site_isolation_stats_gatherer_browsertest.cc
@@ -71,74 +71,29 @@ class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest {
// A few histograms are incremented unconditionally.
histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1);
- histograms.ExpectTotalCount("SiteIsolation.XSD.DataLength", 1);
- histograms.ExpectUniqueSample("SiteIsolation.XSD.MimeType", mime_type, 1);
-
- // Inspect the appropriate conditionally-incremented histogram[s].
- std::set<std::string> expected_metrics;
- std::string base_metric = "SiteIsolation.XSD." + bucket;
- base_metric += should_be_blocked ? ".Blocked" : ".NotBlocked";
- expected_metrics.insert(base_metric);
- if (should_be_blocked) {
- expected_metrics.insert(base_metric + ".RenderableStatusCode");
- } else if (MatchPattern(resource_name, "*js.*")) {
- expected_metrics.insert(base_metric + ".MaybeJS");
- }
+ std::vector<std::string> xsd_metrics;
+ xsd_metrics.push_back("SiteIsolation.XSD.DataLength=1");
+ xsd_metrics.push_back(
+ base::StringPrintf("SiteIsolation.XSD.MimeType[%d]=1", mime_type));
- for (std::string metric : expected_metrics) {
- if (MatchPattern(metric, "*.RenderableStatusCode")) {
- histograms.ExpectUniqueSample(metric, RESOURCE_TYPE_XHR, 1);
- } else {
- histograms.ExpectUniqueSample(metric, 1, 1);
+ // Determine the appropriate conditionally-incremented histograms.
+ std::string base = "SiteIsolation.XSD." + bucket;
+ if (should_be_blocked) {
+ xsd_metrics.push_back(base + ".Blocked=1");
+ xsd_metrics.push_back(base + ".Blocked.RenderableStatusCode[13]=1");
+ static_assert(13 == RESOURCE_TYPE_XHR, "Histogram enums mustn't change.");
+ } else {
+ xsd_metrics.push_back(base + ".NotBlocked=1");
+ if (MatchPattern(resource_name, "*js.*")) {
+ xsd_metrics.push_back(base + ".NotBlocked.MaybeJS=1");
}
}
+ std::sort(xsd_metrics.begin(), xsd_metrics.end());
- // Make sure no other conditionally-incremented histograms were touched.
- const char* all_metrics[] = {
- "SiteIsolation.XSD.HTML.Blocked",
- "SiteIsolation.XSD.HTML.Blocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.HTML.Blocked.RenderableStatusCode",
- "SiteIsolation.XSD.HTML.NoSniffBlocked",
- "SiteIsolation.XSD.HTML.NoSniffBlocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.HTML.NoSniffBlocked.RenderableStatusCode",
- "SiteIsolation.XSD.HTML.NotBlocked",
- "SiteIsolation.XSD.HTML.NotBlocked.MaybeJS",
- "SiteIsolation.XSD.JSON.Blocked",
- "SiteIsolation.XSD.JSON.Blocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.JSON.Blocked.RenderableStatusCode",
- "SiteIsolation.XSD.JSON.NoSniffBlocked",
- "SiteIsolation.XSD.JSON.NoSniffBlocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.JSON.NoSniffBlocked.RenderableStatusCode",
- "SiteIsolation.XSD.JSON.NotBlocked",
- "SiteIsolation.XSD.JSON.NotBlocked.MaybeJS",
- "SiteIsolation.XSD.Plain.HTML.Blocked",
- "SiteIsolation.XSD.Plain.HTML.Blocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.Plain.HTML.Blocked.RenderableStatusCode",
- "SiteIsolation.XSD.Plain.JSON.Blocked",
- "SiteIsolation.XSD.Plain.JSON.Blocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.Plain.JSON.Blocked.RenderableStatusCode",
- "SiteIsolation.XSD.Plain.NoSniffBlocked",
- "SiteIsolation.XSD.Plain.NoSniffBlocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.Plain.NoSniffBlocked.RenderableStatusCode",
- "SiteIsolation.XSD.Plain.NotBlocked",
- "SiteIsolation.XSD.Plain.NotBlocked.MaybeJS",
- "SiteIsolation.XSD.Plain.XML.Blocked",
- "SiteIsolation.XSD.Plain.XML.Blocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.Plain.XML.Blocked.RenderableStatusCode",
- "SiteIsolation.XSD.XML.Blocked",
- "SiteIsolation.XSD.XML.Blocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.XML.Blocked.RenderableStatusCode",
- "SiteIsolation.XSD.XML.NoSniffBlocked",
- "SiteIsolation.XSD.XML.NoSniffBlocked.NonRenderableStatusCode",
- "SiteIsolation.XSD.XML.NoSniffBlocked.RenderableStatusCode",
- "SiteIsolation.XSD.XML.NotBlocked",
- "SiteIsolation.XSD.XML.NotBlocked.MaybeJS"};
-
- for (const char* metric : all_metrics) {
- if (!expected_metrics.count(metric)) {
- histograms.ExpectTotalCount(metric, 0);
- }
- }
+ EXPECT_EQ(JoinString(xsd_metrics, "\n"),
+ histograms.GetTotalCountsForQuery("SiteIsolation.XSD."))
+ << "For resource_name=" << resource_name
+ << ", should_be_blocked=" << should_be_blocked;
}
private:
« base/test/histogram_tester.cc ('K') | « base/test/histogram_tester.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698