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

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

Issue 1226673003: Move MatchPattern to its own header and the base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
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/string_util.h" 7 #include "base/strings/string_util.h"
7 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
8 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
9 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
10 #include "content/public/common/resource_type.h" 11 #include "content/public/common/resource_type.h"
11 #include "content/public/test/browser_test_utils.h" 12 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test.h" 13 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h" 14 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
15 #include "net/test/spawned_test_server/spawned_test_server.h" 16 #include "net/test/spawned_test_server/spawned_test_server.h"
(...skipping 22 matching lines...) Expand all
38 // Since we assume exploited renderer process, it can bypass the same origin 39 // Since we assume exploited renderer process, it can bypass the same origin
39 // policy at will. Simulate that by passing the disable-web-security flag. 40 // policy at will. Simulate that by passing the disable-web-security flag.
40 command_line->AppendSwitch(switches::kDisableWebSecurity); 41 command_line->AppendSwitch(switches::kDisableWebSecurity);
41 } 42 }
42 43
43 void InspectHistograms(const base::HistogramTester& histograms, 44 void InspectHistograms(const base::HistogramTester& histograms,
44 bool should_be_blocked, 45 bool should_be_blocked,
45 const std::string& resource_name) { 46 const std::string& resource_name) {
46 std::string bucket; 47 std::string bucket;
47 int mime_type = 0; // Hardcoded because histogram enums mustn't change. 48 int mime_type = 0; // Hardcoded because histogram enums mustn't change.
48 if (MatchPattern(resource_name, "*.html")) { 49 if (base::MatchPattern(resource_name, "*.html")) {
49 bucket = "HTML"; 50 bucket = "HTML";
50 mime_type = 0; 51 mime_type = 0;
51 } else if (MatchPattern(resource_name, "*.xml")) { 52 } else if (base::MatchPattern(resource_name, "*.xml")) {
52 bucket = "XML"; 53 bucket = "XML";
53 mime_type = 1; 54 mime_type = 1;
54 } else if (MatchPattern(resource_name, "*.json")) { 55 } else if (base::MatchPattern(resource_name, "*.json")) {
55 bucket = "JSON"; 56 bucket = "JSON";
56 mime_type = 2; 57 mime_type = 2;
57 } else if (MatchPattern(resource_name, "*.txt")) { 58 } else if (base::MatchPattern(resource_name, "*.txt")) {
58 bucket = "Plain"; 59 bucket = "Plain";
59 mime_type = 3; 60 mime_type = 3;
60 if (MatchPattern(resource_name, "json*")) { 61 if (base::MatchPattern(resource_name, "json*")) {
61 bucket += ".JSON"; 62 bucket += ".JSON";
62 } else if (MatchPattern(resource_name, "html*")) { 63 } else if (base::MatchPattern(resource_name, "html*")) {
63 bucket += ".HTML"; 64 bucket += ".HTML";
64 } else if (MatchPattern(resource_name, "xml*")) { 65 } else if (base::MatchPattern(resource_name, "xml*")) {
65 bucket += ".XML"; 66 bucket += ".XML";
66 } 67 }
67 } else { 68 } else {
68 FAIL(); 69 FAIL();
69 } 70 }
70 FetchHistogramsFromChildProcesses(); 71 FetchHistogramsFromChildProcesses();
71 72
72 // A few histograms are incremented unconditionally. 73 // A few histograms are incremented unconditionally.
73 histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1); 74 histograms.ExpectUniqueSample("SiteIsolation.AllResponses", 1, 1);
74 histograms.ExpectTotalCount("SiteIsolation.XSD.DataLength", 1); 75 histograms.ExpectTotalCount("SiteIsolation.XSD.DataLength", 1);
75 histograms.ExpectUniqueSample("SiteIsolation.XSD.MimeType", mime_type, 1); 76 histograms.ExpectUniqueSample("SiteIsolation.XSD.MimeType", mime_type, 1);
76 77
77 // Inspect the appropriate conditionally-incremented histogram[s]. 78 // Inspect the appropriate conditionally-incremented histogram[s].
78 std::set<std::string> expected_metrics; 79 std::set<std::string> expected_metrics;
79 std::string base_metric = "SiteIsolation.XSD." + bucket; 80 std::string base_metric = "SiteIsolation.XSD." + bucket;
80 base_metric += should_be_blocked ? ".Blocked" : ".NotBlocked"; 81 base_metric += should_be_blocked ? ".Blocked" : ".NotBlocked";
81 expected_metrics.insert(base_metric); 82 expected_metrics.insert(base_metric);
82 if (should_be_blocked) { 83 if (should_be_blocked) {
83 expected_metrics.insert(base_metric + ".RenderableStatusCode"); 84 expected_metrics.insert(base_metric + ".RenderableStatusCode");
84 } else if (MatchPattern(resource_name, "*js.*")) { 85 } else if (base::MatchPattern(resource_name, "*js.*")) {
85 expected_metrics.insert(base_metric + ".MaybeJS"); 86 expected_metrics.insert(base_metric + ".MaybeJS");
86 } 87 }
87 88
88 for (std::string metric : expected_metrics) { 89 for (std::string metric : expected_metrics) {
89 if (MatchPattern(metric, "*.RenderableStatusCode")) { 90 if (base::MatchPattern(metric, "*.RenderableStatusCode")) {
90 histograms.ExpectUniqueSample(metric, RESOURCE_TYPE_XHR, 1); 91 histograms.ExpectUniqueSample(metric, RESOURCE_TYPE_XHR, 1);
91 } else { 92 } else {
92 histograms.ExpectUniqueSample(metric, 1, 1); 93 histograms.ExpectUniqueSample(metric, 1, 1);
93 } 94 }
94 } 95 }
95 96
96 // Make sure no other conditionally-incremented histograms were touched. 97 // Make sure no other conditionally-incremented histograms were touched.
97 const char* all_metrics[] = { 98 const char* all_metrics[] = {
98 "SiteIsolation.XSD.HTML.Blocked", 99 "SiteIsolation.XSD.HTML.Blocked",
99 "SiteIsolation.XSD.HTML.Blocked.NonRenderableStatusCode", 100 "SiteIsolation.XSD.HTML.Blocked.NonRenderableStatusCode",
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // length is different from what's described in "content-length" for such 246 // length is different from what's described in "content-length" for such
246 // different targets. 247 // different targets.
247 248
248 // TODO(nick): Split up these cases, and add positive assertions here about 249 // TODO(nick): Split up these cases, and add positive assertions here about
249 // what actually happens in these various resource-block cases. 250 // what actually happens in these various resource-block cases.
250 GURL foo("http://foo.com/files/cross_site_document_request_target.html"); 251 GURL foo("http://foo.com/files/cross_site_document_request_target.html");
251 NavigateToURL(shell(), foo); 252 NavigateToURL(shell(), foo);
252 } 253 }
253 254
254 } // namespace content 255 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/background_tracing_manager_browsertest.cc ('k') | content/common/appcache_interfaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698