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

Side by Side 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 unified diff | Download patch
« base/test/histogram_tester.cc ('K') | « base/test/histogram_tester.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 #include "content/public/common/resource_type.h" 10 #include "content/public/common/resource_type.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } else if (MatchPattern(resource_name, "xml.*")) { 64 } else if (MatchPattern(resource_name, "xml.*")) {
65 bucket += ".XML"; 65 bucket += ".XML";
66 } 66 }
67 } else { 67 } else {
68 FAIL(); 68 FAIL();
69 } 69 }
70 FetchHistogramsFromChildProcesses(); 70 FetchHistogramsFromChildProcesses();
71 71
72 // A few histograms are incremented unconditionally. 72 // A few histograms are incremented unconditionally.
73 histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1); 73 histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1);
74 histograms.ExpectTotalCount("SiteIsolation.XSD.DataLength", 1); 74 std::vector<std::string> xsd_metrics;
75 histograms.ExpectUniqueSample("SiteIsolation.XSD.MimeType", mime_type, 1); 75 xsd_metrics.push_back("SiteIsolation.XSD.DataLength=1");
76 xsd_metrics.push_back(
77 base::StringPrintf("SiteIsolation.XSD.MimeType[%d]=1", mime_type));
76 78
77 // Inspect the appropriate conditionally-incremented histogram[s]. 79 // Determine the appropriate conditionally-incremented histograms.
78 std::set<std::string> expected_metrics; 80 std::string base = "SiteIsolation.XSD." + bucket;
79 std::string base_metric = "SiteIsolation.XSD." + bucket;
80 base_metric += should_be_blocked ? ".Blocked" : ".NotBlocked";
81 expected_metrics.insert(base_metric);
82 if (should_be_blocked) { 81 if (should_be_blocked) {
83 expected_metrics.insert(base_metric + ".RenderableStatusCode"); 82 xsd_metrics.push_back(base + ".Blocked=1");
84 } else if (MatchPattern(resource_name, "*js.*")) { 83 xsd_metrics.push_back(base + ".Blocked.RenderableStatusCode[13]=1");
85 expected_metrics.insert(base_metric + ".MaybeJS"); 84 static_assert(13 == RESOURCE_TYPE_XHR, "Histogram enums mustn't change.");
86 } 85 } else {
87 86 xsd_metrics.push_back(base + ".NotBlocked=1");
88 for (std::string metric : expected_metrics) { 87 if (MatchPattern(resource_name, "*js.*")) {
89 if (MatchPattern(metric, "*.RenderableStatusCode")) { 88 xsd_metrics.push_back(base + ".NotBlocked.MaybeJS=1");
90 histograms.ExpectUniqueSample(metric, RESOURCE_TYPE_XHR, 1);
91 } else {
92 histograms.ExpectUniqueSample(metric, 1, 1);
93 } 89 }
94 } 90 }
91 std::sort(xsd_metrics.begin(), xsd_metrics.end());
95 92
96 // Make sure no other conditionally-incremented histograms were touched. 93 EXPECT_EQ(JoinString(xsd_metrics, "\n"),
97 const char* all_metrics[] = { 94 histograms.GetTotalCountsForQuery("SiteIsolation.XSD."))
98 "SiteIsolation.XSD.HTML.Blocked", 95 << "For resource_name=" << resource_name
99 "SiteIsolation.XSD.HTML.Blocked.NonRenderableStatusCode", 96 << ", should_be_blocked=" << should_be_blocked;
100 "SiteIsolation.XSD.HTML.Blocked.RenderableStatusCode",
101 "SiteIsolation.XSD.HTML.NoSniffBlocked",
102 "SiteIsolation.XSD.HTML.NoSniffBlocked.NonRenderableStatusCode",
103 "SiteIsolation.XSD.HTML.NoSniffBlocked.RenderableStatusCode",
104 "SiteIsolation.XSD.HTML.NotBlocked",
105 "SiteIsolation.XSD.HTML.NotBlocked.MaybeJS",
106 "SiteIsolation.XSD.JSON.Blocked",
107 "SiteIsolation.XSD.JSON.Blocked.NonRenderableStatusCode",
108 "SiteIsolation.XSD.JSON.Blocked.RenderableStatusCode",
109 "SiteIsolation.XSD.JSON.NoSniffBlocked",
110 "SiteIsolation.XSD.JSON.NoSniffBlocked.NonRenderableStatusCode",
111 "SiteIsolation.XSD.JSON.NoSniffBlocked.RenderableStatusCode",
112 "SiteIsolation.XSD.JSON.NotBlocked",
113 "SiteIsolation.XSD.JSON.NotBlocked.MaybeJS",
114 "SiteIsolation.XSD.Plain.HTML.Blocked",
115 "SiteIsolation.XSD.Plain.HTML.Blocked.NonRenderableStatusCode",
116 "SiteIsolation.XSD.Plain.HTML.Blocked.RenderableStatusCode",
117 "SiteIsolation.XSD.Plain.JSON.Blocked",
118 "SiteIsolation.XSD.Plain.JSON.Blocked.NonRenderableStatusCode",
119 "SiteIsolation.XSD.Plain.JSON.Blocked.RenderableStatusCode",
120 "SiteIsolation.XSD.Plain.NoSniffBlocked",
121 "SiteIsolation.XSD.Plain.NoSniffBlocked.NonRenderableStatusCode",
122 "SiteIsolation.XSD.Plain.NoSniffBlocked.RenderableStatusCode",
123 "SiteIsolation.XSD.Plain.NotBlocked",
124 "SiteIsolation.XSD.Plain.NotBlocked.MaybeJS",
125 "SiteIsolation.XSD.Plain.XML.Blocked",
126 "SiteIsolation.XSD.Plain.XML.Blocked.NonRenderableStatusCode",
127 "SiteIsolation.XSD.Plain.XML.Blocked.RenderableStatusCode",
128 "SiteIsolation.XSD.XML.Blocked",
129 "SiteIsolation.XSD.XML.Blocked.NonRenderableStatusCode",
130 "SiteIsolation.XSD.XML.Blocked.RenderableStatusCode",
131 "SiteIsolation.XSD.XML.NoSniffBlocked",
132 "SiteIsolation.XSD.XML.NoSniffBlocked.NonRenderableStatusCode",
133 "SiteIsolation.XSD.XML.NoSniffBlocked.RenderableStatusCode",
134 "SiteIsolation.XSD.XML.NotBlocked",
135 "SiteIsolation.XSD.XML.NotBlocked.MaybeJS"};
136
137 for (const char* metric : all_metrics) {
138 if (!expected_metrics.count(metric)) {
139 histograms.ExpectTotalCount(metric, 0);
140 }
141 }
142 } 97 }
143 98
144 private: 99 private:
145 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest); 100 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest);
146 }; 101 };
147 102
148 // TODO(dsjang): we cannot run these tests on Android since SetUpCommandLine() 103 // TODO(dsjang): we cannot run these tests on Android since SetUpCommandLine()
149 // is executed before the I/O thread is created on Android. After this bug 104 // is executed before the I/O thread is created on Android. After this bug
150 // (crbug.com/278425) is resolved, we can enable this test case on Android. 105 // (crbug.com/278425) is resolved, we can enable this test case on Android.
151 #if defined(OS_ANDROID) 106 #if defined(OS_ANDROID)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // length is different from what's described in "content-length" for such 196 // length is different from what's described in "content-length" for such
242 // different targets. 197 // different targets.
243 198
244 // TODO(nick): Split up these cases, and add positive assertions here about 199 // TODO(nick): Split up these cases, and add positive assertions here about
245 // what actually happens in these various resource-block cases. 200 // what actually happens in these various resource-block cases.
246 GURL foo("http://foo.com/files/cross_site_document_request_target.html"); 201 GURL foo("http://foo.com/files/cross_site_document_request_target.html");
247 NavigateToURL(shell(), foo); 202 NavigateToURL(shell(), foo);
248 } 203 }
249 204
250 } // namespace content 205 } // namespace content
OLDNEW
« 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