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

Side by Side Diff: content/child/site_isolation_stats_gatherer_browsertest.cc

Issue 1515703005: WebRequest API: add more resource types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace == with && 2x Created 4 years, 12 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
« no previous file with comments | « content/child/site_isolation_stats_gatherer.cc ('k') | content/child/web_url_request_util.cc » ('j') | 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/pattern.h" 6 #include "base/strings/pattern.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // A few histograms are incremented unconditionally. 74 // A few histograms are incremented unconditionally.
75 histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1); 75 histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1);
76 base::HistogramTester::CountsMap expected_metrics; 76 base::HistogramTester::CountsMap expected_metrics;
77 expected_metrics["SiteIsolation.XSD.DataLength"] = 1; 77 expected_metrics["SiteIsolation.XSD.DataLength"] = 1;
78 expected_metrics["SiteIsolation.XSD.MimeType"] = 1; 78 expected_metrics["SiteIsolation.XSD.MimeType"] = 1;
79 79
80 // Determine the appropriate conditionally-incremented histograms. 80 // Determine the appropriate conditionally-incremented histograms.
81 std::string base = "SiteIsolation.XSD." + bucket; 81 std::string base = "SiteIsolation.XSD." + bucket;
82 if (should_be_blocked) { 82 if (should_be_blocked) {
83 expected_metrics[base + ".Blocked"] = 1; 83 expected_metrics[base + ".Blocked"] = 1;
84 expected_metrics[base + ".Blocked.RenderableStatusCode"] = 1; 84 expected_metrics[base + ".Blocked.RenderableStatusCode2"] = 1;
85 } else { 85 } else {
86 expected_metrics[base + ".NotBlocked"] = 1; 86 expected_metrics[base + ".NotBlocked"] = 1;
87 if (base::MatchPattern(resource_name, "*js.*")) { 87 if (base::MatchPattern(resource_name, "*js.*")) {
88 expected_metrics[base + ".NotBlocked.MaybeJS"] = 1; 88 expected_metrics[base + ".NotBlocked.MaybeJS"] = 1;
89 } 89 }
90 } 90 }
91 91
92 // Make sure that the expected metrics, and only those metrics, were 92 // Make sure that the expected metrics, and only those metrics, were
93 // incremented. 93 // incremented.
94 EXPECT_THAT(histograms.GetTotalCountsForPrefix("SiteIsolation.XSD."), 94 EXPECT_THAT(histograms.GetTotalCountsForPrefix("SiteIsolation.XSD."),
95 testing::ContainerEq(expected_metrics)) 95 testing::ContainerEq(expected_metrics))
96 << "For resource_name=" << resource_name 96 << "For resource_name=" << resource_name
97 << ", should_be_blocked=" << should_be_blocked; 97 << ", should_be_blocked=" << should_be_blocked;
98 98
99 EXPECT_THAT(histograms.GetAllSamples("SiteIsolation.XSD.MimeType"), 99 EXPECT_THAT(histograms.GetAllSamples("SiteIsolation.XSD.MimeType"),
100 testing::ElementsAre(base::Bucket(mime_type, 1))) 100 testing::ElementsAre(base::Bucket(mime_type, 1)))
101 << "The wrong mime type bucket was incremented."; 101 << "The wrong mime type bucket was incremented.";
102 if (should_be_blocked) { 102 if (should_be_blocked) {
103 static_assert(13 == RESOURCE_TYPE_XHR, "Histogram enums mustn't change."); 103 static_assert(13 == RESOURCE_TYPE_XHR, "Histogram enums mustn't change.");
104 EXPECT_THAT( 104 EXPECT_THAT(
105 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode"), 105 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode2"),
106 testing::ElementsAre(base::Bucket(RESOURCE_TYPE_XHR, 1))) 106 testing::ElementsAre(base::Bucket(RESOURCE_TYPE_XHR, 1)))
107 << "The wrong RenderableStatusCode bucket was incremented."; 107 << "The wrong RenderableStatusCode2 bucket was incremented.";
108 } 108 }
109 } 109 }
110 110
111 private: 111 private:
112 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest); 112 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest);
113 }; 113 };
114 114
115 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, 115 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest,
116 CrossSiteDocumentBlockingForMimeType) { 116 CrossSiteDocumentBlockingForMimeType) {
117 // Load a page that issues illegal cross-site document requests to bar.com. 117 // Load a page that issues illegal cross-site document requests to bar.com.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // length is different from what's described in "content-length" for such 190 // length is different from what's described in "content-length" for such
191 // different targets. 191 // different targets.
192 192
193 // TODO(nick): Split up these cases, and add positive assertions here about 193 // TODO(nick): Split up these cases, and add positive assertions here about
194 // what actually happens in these various resource-block cases. 194 // what actually happens in these various resource-block cases.
195 GURL foo("http://foo.com/cross_site_document_request_target.html"); 195 GURL foo("http://foo.com/cross_site_document_request_target.html");
196 NavigateToURL(shell(), foo); 196 NavigateToURL(shell(), foo);
197 } 197 }
198 198
199 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « content/child/site_isolation_stats_gatherer.cc ('k') | content/child/web_url_request_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698