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

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

Issue 2646753002: [Mojo-Loading] Implement "Site Isolation Stats Gathering" feature (Closed)
Patch Set: Created 3 years, 11 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/macros.h" 6 #include "base/macros.h"
7 #include "base/strings/pattern.h" 7 #include "base/strings/pattern.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "content/public/common/resource_type.h" 12 #include "content/public/common/resource_type.h"
13 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 15 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/shell/browser/shell.h" 16 #include "content/shell/browser/shell.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h" 17 #include "net/test/embedded_test_server/embedded_test_server.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 // These tests simulate exploited renderer processes, which can fetch arbitrary 22 // These tests simulate exploited renderer processes, which can fetch arbitrary
23 // resources from other websites, not constrained by the Same Origin Policy. We 23 // resources from other websites, not constrained by the Same Origin Policy. We
24 // are trying to verify that the renderer cannot fetch any cross-site document 24 // are trying to verify that the renderer cannot fetch any cross-site document
25 // responses even when the Same Origin Policy is turned off inside the renderer. 25 // responses even when the Same Origin Policy is turned off inside the renderer.
26 class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest { 26 class SiteIsolationStatsGathererBrowserTest
27 : public ContentBrowserTest,
28 public testing::WithParamInterface<bool> {
27 public: 29 public:
28 SiteIsolationStatsGathererBrowserTest() {} 30 SiteIsolationStatsGathererBrowserTest() {}
29 ~SiteIsolationStatsGathererBrowserTest() override {} 31 ~SiteIsolationStatsGathererBrowserTest() override {}
30 32
31 void SetUpCommandLine(base::CommandLine* command_line) override { 33 void SetUpCommandLine(base::CommandLine* command_line) override {
32 // EmbeddedTestServer::InitializeAndListen() initializes its |base_url_| 34 // EmbeddedTestServer::InitializeAndListen() initializes its |base_url_|
33 // which is required below. This cannot invoke Start() however as that kicks 35 // which is required below. This cannot invoke Start() however as that kicks
34 // off the "EmbeddedTestServer IO Thread" which then races with 36 // off the "EmbeddedTestServer IO Thread" which then races with
35 // initialization in ContentBrowserTest::SetUp(), http://crbug.com/674545. 37 // initialization in ContentBrowserTest::SetUp(), http://crbug.com/674545.
36 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); 38 ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
37 39
38 // Add a host resolver rule to map all outgoing requests to the test server. 40 // Add a host resolver rule to map all outgoing requests to the test server.
39 // This allows us to use "real" hostnames in URLs, which we can use to 41 // This allows us to use "real" hostnames in URLs, which we can use to
40 // create arbitrary SiteInstances. 42 // create arbitrary SiteInstances.
41 command_line->AppendSwitchASCII( 43 command_line->AppendSwitchASCII(
42 switches::kHostResolverRules, 44 switches::kHostResolverRules,
43 "MAP * " + embedded_test_server()->host_port_pair().ToString() + 45 "MAP * " + embedded_test_server()->host_port_pair().ToString() +
44 ",EXCLUDE localhost"); 46 ",EXCLUDE localhost");
45 47
46 // Since we assume exploited renderer process, it can bypass the same origin 48 // Since we assume exploited renderer process, it can bypass the same origin
47 // policy at will. Simulate that by passing the disable-web-security flag. 49 // policy at will. Simulate that by passing the disable-web-security flag.
48 command_line->AppendSwitch(switches::kDisableWebSecurity); 50 command_line->AppendSwitch(switches::kDisableWebSecurity);
51
52 if (GetParam()) {
53 command_line->AppendSwitchASCII("--enable-blink-features",
54 "LoadingWithMojo");
55 }
49 } 56 }
50 57
51 void SetUpOnMainThread() override { 58 void SetUpOnMainThread() override {
52 // Complete the manual Start() after ContentBrowserTest's own 59 // Complete the manual Start() after ContentBrowserTest's own
53 // initialization, ref. comment on InitializeAndListen() above. 60 // initialization, ref. comment on InitializeAndListen() above.
54 embedded_test_server()->StartAcceptingConnections(); 61 embedded_test_server()->StartAcceptingConnections();
55 } 62 }
56 63
57 void InspectHistograms(const base::HistogramTester& histograms, 64 void InspectHistograms(const base::HistogramTester& histograms,
58 bool should_be_blocked, 65 bool should_be_blocked,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode2"), 124 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode2"),
118 testing::ElementsAre(base::Bucket(RESOURCE_TYPE_XHR, 1))) 125 testing::ElementsAre(base::Bucket(RESOURCE_TYPE_XHR, 1)))
119 << "The wrong RenderableStatusCode2 bucket was incremented."; 126 << "The wrong RenderableStatusCode2 bucket was incremented.";
120 } 127 }
121 } 128 }
122 129
123 private: 130 private:
124 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest); 131 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest);
125 }; 132 };
126 133
127 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, 134 IN_PROC_BROWSER_TEST_P(SiteIsolationStatsGathererBrowserTest,
128 CrossSiteDocumentBlockingForMimeType) { 135 CrossSiteDocumentBlockingForMimeType) {
129 // Load a page that issues illegal cross-site document requests to bar.com. 136 // Load a page that issues illegal cross-site document requests to bar.com.
130 // The page uses XHR to request HTML/XML/JSON documents from bar.com, and 137 // The page uses XHR to request HTML/XML/JSON documents from bar.com, and
131 // inspects if any of them were successfully received. Currently, on illegal 138 // inspects if any of them were successfully received. Currently, on illegal
132 // access, the XHR requests should succeed, but the UMA histograms should 139 // access, the XHR requests should succeed, but the UMA histograms should
133 // record that they would have been blocked. This test is only possible since 140 // record that they would have been blocked. This test is only possible since
134 // we run the browser without the same origin policy. 141 // we run the browser without the same origin policy.
135 GURL foo("http://foo.com/cross_site_document_request.html"); 142 GURL foo("http://foo.com/cross_site_document_request.html");
136 143
137 NavigateToURL(shell(), foo); 144 NavigateToURL(shell(), foo);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 bool was_blocked; 193 bool was_blocked;
187 ASSERT_TRUE(ExecuteScriptAndExtractBool( 194 ASSERT_TRUE(ExecuteScriptAndExtractBool(
188 shell(), base::StringPrintf("sendRequest(\"%s\");", resource), 195 shell(), base::StringPrintf("sendRequest(\"%s\");", resource),
189 &was_blocked)); 196 &was_blocked));
190 ASSERT_FALSE(was_blocked); 197 ASSERT_FALSE(was_blocked);
191 198
192 InspectHistograms(histograms, false, resource); 199 InspectHistograms(histograms, false, resource);
193 } 200 }
194 } 201 }
195 202
196 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, 203 IN_PROC_BROWSER_TEST_P(SiteIsolationStatsGathererBrowserTest,
197 CrossSiteDocumentBlockingForDifferentTargets) { 204 CrossSiteDocumentBlockingForDifferentTargets) {
198 // This webpage loads a cross-site HTML page in different targets such as 205 // This webpage loads a cross-site HTML page in different targets such as
199 // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one 206 // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one
200 // character string (' ') is returned instead, this tests that the renderer 207 // character string (' ') is returned instead, this tests that the renderer
201 // does not crash even when it receives a response body which is " ", whose 208 // does not crash even when it receives a response body which is " ", whose
202 // length is different from what's described in "content-length" for such 209 // length is different from what's described in "content-length" for such
203 // different targets. 210 // different targets.
204 211
205 // TODO(nick): Split up these cases, and add positive assertions here about 212 // TODO(nick): Split up these cases, and add positive assertions here about
206 // what actually happens in these various resource-block cases. 213 // what actually happens in these various resource-block cases.
207 GURL foo("http://foo.com/cross_site_document_request_target.html"); 214 GURL foo("http://foo.com/cross_site_document_request_target.html");
208 NavigateToURL(shell(), foo); 215 NavigateToURL(shell(), foo);
209 } 216 }
210 217
218 INSTANTIATE_TEST_CASE_P(SiteIsolationStatsGathererBrowserTest,
219 SiteIsolationStatsGathererBrowserTest,
220 ::testing::Values(false, true));
221
211 } // namespace content 222 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/url_response_body_consumer.cc » ('j') | content/child/url_response_body_consumer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698