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

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

Issue 1411073005: Migrating tests to use EmbeddedTestServer (/content) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month 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/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"
11 #include "content/public/common/resource_type.h" 11 #include "content/public/common/resource_type.h"
12 #include "content/public/test/browser_test_utils.h" 12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h" 13 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h" 14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
16 #include "net/test/spawned_test_server/spawned_test_server.h" 16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 // These tests simulate exploited renderer processes, which can fetch arbitrary 21 // These tests simulate exploited renderer processes, which can fetch arbitrary
22 // resources from other websites, not constrained by the Same Origin Policy. We 22 // resources from other websites, not constrained by the Same Origin Policy. We
23 // are trying to verify that the renderer cannot fetch any cross-site document 23 // are trying to verify that the renderer cannot fetch any cross-site document
24 // responses even when the Same Origin Policy is turned off inside the renderer. 24 // responses even when the Same Origin Policy is turned off inside the renderer.
25 class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest { 25 class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest {
26 public: 26 public:
27 SiteIsolationStatsGathererBrowserTest() {} 27 SiteIsolationStatsGathererBrowserTest() {}
28 ~SiteIsolationStatsGathererBrowserTest() override {} 28 ~SiteIsolationStatsGathererBrowserTest() override {}
29 29
30 void SetUpCommandLine(base::CommandLine* command_line) override { 30 void SetUpCommandLine(base::CommandLine* command_line) override {
31 ASSERT_TRUE(test_server()->Start()); 31 ASSERT_TRUE(embedded_test_server()->Start());
32 // Add a host resolver rule to map all outgoing requests to the test server. 32 // Add a host resolver rule to map all outgoing requests to the test server.
33 // This allows us to use "real" hostnames in URLs, which we can use to 33 // This allows us to use "real" hostnames in URLs, which we can use to
34 // create arbitrary SiteInstances. 34 // create arbitrary SiteInstances.
35 command_line->AppendSwitchASCII( 35 command_line->AppendSwitchASCII(
36 switches::kHostResolverRules, 36 switches::kHostResolverRules,
37 "MAP * " + test_server()->host_port_pair().ToString() + 37 "MAP * " + embedded_test_server()->host_port_pair().ToString() +
38 ",EXCLUDE localhost"); 38 ",EXCLUDE localhost");
39 39
40 // Since we assume exploited renderer process, it can bypass the same origin 40 // Since we assume exploited renderer process, it can bypass the same origin
41 // policy at will. Simulate that by passing the disable-web-security flag. 41 // policy at will. Simulate that by passing the disable-web-security flag.
42 command_line->AppendSwitch(switches::kDisableWebSecurity); 42 command_line->AppendSwitch(switches::kDisableWebSecurity);
43 } 43 }
44 44
45 void InspectHistograms(const base::HistogramTester& histograms, 45 void InspectHistograms(const base::HistogramTester& histograms,
46 bool should_be_blocked, 46 bool should_be_blocked,
47 const std::string& resource_name) { 47 const std::string& resource_name) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode"), 105 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode"),
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 RenderableStatusCode 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 // TODO(dsjang): we cannot run these tests on Android since SetUpCommandLine()
116 // is executed before the I/O thread is created on Android. After this bug
117 // (crbug.com/278425) is resolved, we can enable this test case on Android.
118 #if defined(OS_ANDROID)
119 #define MAYBE_CrossSiteDocumentBlockingForMimeType \
120 DISABLED_CrossSiteDocumentBlockingForMimeType
121 #else
122 #define MAYBE_CrossSiteDocumentBlockingForMimeType \
123 CrossSiteDocumentBlockingForMimeType
124 #endif
125
126 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, 115 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest,
127 MAYBE_CrossSiteDocumentBlockingForMimeType) { 116 CrossSiteDocumentBlockingForMimeType) {
128 // 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.
129 // The page uses XHR to request HTML/XML/JSON documents from bar.com, and 118 // The page uses XHR to request HTML/XML/JSON documents from bar.com, and
130 // inspects if any of them were successfully received. Currently, on illegal 119 // inspects if any of them were successfully received. Currently, on illegal
131 // access, the XHR requests should succeed, but the UMA histograms should 120 // access, the XHR requests should succeed, but the UMA histograms should
132 // record that they would have been blocked. This test is only possible since 121 // record that they would have been blocked. This test is only possible since
133 // we run the browser without the same origin policy. 122 // we run the browser without the same origin policy.
134 GURL foo("http://foo.com/files/cross_site_document_request.html"); 123 GURL foo("http://foo.com/cross_site_document_request.html");
135 124
136 NavigateToURL(shell(), foo); 125 NavigateToURL(shell(), foo);
137 126
138 // Flush out existing histogram activity. 127 // Flush out existing histogram activity.
139 FetchHistogramsFromChildProcesses(); 128 FetchHistogramsFromChildProcesses();
140 129
141 // The following are files under content/test/data/site_isolation. All 130 // The following are files under content/test/data/site_isolation. All
142 // should be disallowed for cross site XHR under the document blocking policy. 131 // should be disallowed for cross site XHR under the document blocking policy.
143 const char* blocked_resources[] = { 132 const char* blocked_resources[] = {
144 "comment_valid.html", 133 "comment_valid.html",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool was_blocked; 174 bool was_blocked;
186 ASSERT_TRUE(ExecuteScriptAndExtractBool( 175 ASSERT_TRUE(ExecuteScriptAndExtractBool(
187 shell()->web_contents(), 176 shell()->web_contents(),
188 base::StringPrintf("sendRequest(\"%s\");", resource), &was_blocked)); 177 base::StringPrintf("sendRequest(\"%s\");", resource), &was_blocked));
189 ASSERT_FALSE(was_blocked); 178 ASSERT_FALSE(was_blocked);
190 179
191 InspectHistograms(histograms, false, resource); 180 InspectHistograms(histograms, false, resource);
192 } 181 }
193 } 182 }
194 183
195 // TODO(dsjang): we cannot run these tests on Android since SetUpCommandLine()
196 // is executed before the I/O thread is created on Android. After this bug
197 // (crbug.com/278425) is resolved, we can enable this test case on Android.
198 #if defined(OS_ANDROID)
199 #define MAYBE_CrossSiteDocumentBlockingForDifferentTargets \
200 DISABLED_CrossSiteDocumentBlockingForDifferentTargets
201 #else
202 #define MAYBE_CrossSiteDocumentBlockingForDifferentTargets \
203 CrossSiteDocumentBlockingForDifferentTargets
204 #endif
205
206 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, 184 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest,
207 MAYBE_CrossSiteDocumentBlockingForDifferentTargets) { 185 CrossSiteDocumentBlockingForDifferentTargets) {
208 // This webpage loads a cross-site HTML page in different targets such as 186 // This webpage loads a cross-site HTML page in different targets such as
209 // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one 187 // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one
210 // character string (' ') is returned instead, this tests that the renderer 188 // character string (' ') is returned instead, this tests that the renderer
211 // does not crash even when it receives a response body which is " ", whose 189 // does not crash even when it receives a response body which is " ", whose
212 // 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
213 // different targets. 191 // different targets.
214 192
215 // 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
216 // what actually happens in these various resource-block cases. 194 // what actually happens in these various resource-block cases.
217 GURL foo("http://foo.com/files/cross_site_document_request_target.html"); 195 GURL foo("http://foo.com/cross_site_document_request_target.html");
218 NavigateToURL(shell(), foo); 196 NavigateToURL(shell(), foo);
219 } 197 }
220 198
221 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui_mojo_browsertest.cc ('k') | content/public/test/browser_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698