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

Side by Side Diff: net/proxy/proxy_script_fetcher_unittest.cc

Issue 17030: Revert 7508.7509 and 7510 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/ui/inspector_controller_uitest.cc ('k') | net/url_request/url_request_unittest.h » ('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 (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "net/proxy/proxy_script_fetcher.h" 5 #include "net/proxy/proxy_script_fetcher.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 { // Fetch a file that exists. 174 { // Fetch a file that exists.
175 FetchResult result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt")); 175 FetchResult result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"));
176 EXPECT_EQ(net::OK, result.code); 176 EXPECT_EQ(net::OK, result.code);
177 EXPECT_EQ("-pac.txt-\n", result.bytes); 177 EXPECT_EQ("-pac.txt-\n", result.bytes);
178 } 178 }
179 } 179 }
180 180
181 // Note that all mime types are allowed for PAC file, to be consistent 181 // Note that all mime types are allowed for PAC file, to be consistent
182 // with other browsers. 182 // with other browsers.
183 TEST_F(ProxyScriptFetcherTest, HttpMimeType) { 183 TEST_F(ProxyScriptFetcherTest, HttpMimeType) {
184 scoped_refptr<HTTPTestServer> server = 184 TestServer server(kDocRoot);
185 HTTPTestServer::CreateServer(kDocRoot);
186 ASSERT_TRUE(NULL != server.get());
187 SynchFetcher pac_fetcher; 185 SynchFetcher pac_fetcher;
188 186
189 { // Fetch a PAC with mime type "text/plain" 187 { // Fetch a PAC with mime type "text/plain"
190 GURL url = server->TestServerPage("files/pac.txt"); 188 GURL url = server.TestServerPage("files/pac.txt");
191 FetchResult result = pac_fetcher.Fetch(url); 189 FetchResult result = pac_fetcher.Fetch(url);
192 EXPECT_EQ(net::OK, result.code); 190 EXPECT_EQ(net::OK, result.code);
193 EXPECT_EQ("-pac.txt-\n", result.bytes); 191 EXPECT_EQ("-pac.txt-\n", result.bytes);
194 } 192 }
195 { // Fetch a PAC with mime type "text/html" 193 { // Fetch a PAC with mime type "text/html"
196 GURL url = server->TestServerPage("files/pac.html"); 194 GURL url = server.TestServerPage("files/pac.html");
197 FetchResult result = pac_fetcher.Fetch(url); 195 FetchResult result = pac_fetcher.Fetch(url);
198 EXPECT_EQ(net::OK, result.code); 196 EXPECT_EQ(net::OK, result.code);
199 EXPECT_EQ("-pac.html-\n", result.bytes); 197 EXPECT_EQ("-pac.html-\n", result.bytes);
200 } 198 }
201 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" 199 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig"
202 GURL url = server->TestServerPage("files/pac.nsproxy"); 200 GURL url = server.TestServerPage("files/pac.nsproxy");
203 FetchResult result = pac_fetcher.Fetch(url); 201 FetchResult result = pac_fetcher.Fetch(url);
204 EXPECT_EQ(net::OK, result.code); 202 EXPECT_EQ(net::OK, result.code);
205 EXPECT_EQ("-pac.nsproxy-\n", result.bytes); 203 EXPECT_EQ("-pac.nsproxy-\n", result.bytes);
206 } 204 }
207 } 205 }
208 206
209 TEST_F(ProxyScriptFetcherTest, HttpStatusCode) { 207 TEST_F(ProxyScriptFetcherTest, HttpStatusCode) {
210 scoped_refptr<HTTPTestServer> server = 208 TestServer server(kDocRoot);
211 HTTPTestServer::CreateServer(kDocRoot);
212 ASSERT_TRUE(NULL != server.get());
213 SynchFetcher pac_fetcher; 209 SynchFetcher pac_fetcher;
214 210
215 { // Fetch a PAC which gives a 500 -- FAIL 211 { // Fetch a PAC which gives a 500 -- FAIL
216 GURL url = server->TestServerPage("files/500.pac"); 212 GURL url = server.TestServerPage("files/500.pac");
217 FetchResult result = pac_fetcher.Fetch(url); 213 FetchResult result = pac_fetcher.Fetch(url);
218 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code); 214 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code);
219 EXPECT_TRUE(result.bytes.empty()); 215 EXPECT_TRUE(result.bytes.empty());
220 } 216 }
221 { // Fetch a PAC which gives a 404 -- FAIL 217 { // Fetch a PAC which gives a 404 -- FAIL
222 GURL url = server->TestServerPage("files/404.pac"); 218 GURL url = server.TestServerPage("files/404.pac");
223 FetchResult result = pac_fetcher.Fetch(url); 219 FetchResult result = pac_fetcher.Fetch(url);
224 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code); 220 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code);
225 EXPECT_TRUE(result.bytes.empty()); 221 EXPECT_TRUE(result.bytes.empty());
226 } 222 }
227 } 223 }
228 224
229 TEST_F(ProxyScriptFetcherTest, ContentDisposition) { 225 TEST_F(ProxyScriptFetcherTest, ContentDisposition) {
230 scoped_refptr<HTTPTestServer> server = 226 TestServer server(kDocRoot);
231 HTTPTestServer::CreateServer(kDocRoot);
232 ASSERT_TRUE(NULL != server.get());
233 SynchFetcher pac_fetcher; 227 SynchFetcher pac_fetcher;
234 228
235 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should 229 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should
236 // have no effect. 230 // have no effect.
237 GURL url = server->TestServerPage("files/downloadable.pac"); 231 GURL url = server.TestServerPage("files/downloadable.pac");
238 FetchResult result = pac_fetcher.Fetch(url); 232 FetchResult result = pac_fetcher.Fetch(url);
239 EXPECT_EQ(net::OK, result.code); 233 EXPECT_EQ(net::OK, result.code);
240 EXPECT_EQ("-downloadable.pac-\n", result.bytes); 234 EXPECT_EQ("-downloadable.pac-\n", result.bytes);
241 } 235 }
242 236
243 TEST_F(ProxyScriptFetcherTest, TooLarge) { 237 TEST_F(ProxyScriptFetcherTest, TooLarge) {
244 scoped_refptr<HTTPTestServer> server = 238 TestServer server(kDocRoot);
245 HTTPTestServer::CreateServer(kDocRoot);
246 ASSERT_TRUE(NULL != server.get());
247 SynchFetcher pac_fetcher; 239 SynchFetcher pac_fetcher;
248 240
249 // Set the maximum response size to 50 bytes. 241 // Set the maximum response size to 50 bytes.
250 int prev_size = net::ProxyScriptFetcher::SetSizeConstraintForUnittest(50); 242 int prev_size = net::ProxyScriptFetcher::SetSizeConstraintForUnittest(50);
251 243
252 // These two URLs are the same file, but are http:// vs file:// 244 // These two URLs are the same file, but are http:// vs file://
253 GURL urls[] = { 245 GURL urls[] = {
254 server->TestServerPage("files/large-pac.nsproxy"), 246 server.TestServerPage("files/large-pac.nsproxy"),
255 GetTestFileUrl("large-pac.nsproxy") 247 GetTestFileUrl("large-pac.nsproxy")
256 }; 248 };
257 249
258 // Try fetching URLs that are 101 bytes large. We should abort the request 250 // Try fetching URLs that are 101 bytes large. We should abort the request
259 // after 50 bytes have been read, and fail with a too large error. 251 // after 50 bytes have been read, and fail with a too large error.
260 for (size_t i = 0; i < arraysize(urls); ++i) { 252 for (size_t i = 0; i < arraysize(urls); ++i) {
261 const GURL& url = urls[i]; 253 const GURL& url = urls[i];
262 FetchResult result = pac_fetcher.Fetch(url); 254 FetchResult result = pac_fetcher.Fetch(url);
263 EXPECT_EQ(net::ERR_FILE_TOO_BIG, result.code); 255 EXPECT_EQ(net::ERR_FILE_TOO_BIG, result.code);
264 EXPECT_TRUE(result.bytes.empty()); 256 EXPECT_TRUE(result.bytes.empty());
265 } 257 }
266 258
267 // Restore the original size bound. 259 // Restore the original size bound.
268 net::ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size); 260 net::ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size);
269 261
270 { // Make sure we can still fetch regular URLs. 262 { // Make sure we can still fetch regular URLs.
271 GURL url = server->TestServerPage("files/pac.nsproxy"); 263 GURL url = server.TestServerPage("files/pac.nsproxy");
272 FetchResult result = pac_fetcher.Fetch(url); 264 FetchResult result = pac_fetcher.Fetch(url);
273 EXPECT_EQ(net::OK, result.code); 265 EXPECT_EQ(net::OK, result.code);
274 EXPECT_EQ("-pac.nsproxy-\n", result.bytes); 266 EXPECT_EQ("-pac.nsproxy-\n", result.bytes);
275 } 267 }
276 } 268 }
277 269
278 TEST_F(ProxyScriptFetcherTest, Hang) { 270 TEST_F(ProxyScriptFetcherTest, Hang) {
279 scoped_refptr<HTTPTestServer> server = 271 TestServer server(kDocRoot);
280 HTTPTestServer::CreateServer(kDocRoot);
281 ASSERT_TRUE(NULL != server.get());
282 SynchFetcher pac_fetcher; 272 SynchFetcher pac_fetcher;
283 273
284 // Set the timeout period to 0.5 seconds. 274 // Set the timeout period to 0.5 seconds.
285 int prev_timeout = 275 int prev_timeout =
286 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(500); 276 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(500);
287 277
288 // Try fetching a URL which takes 1.2 seconds. We should abort the request 278 // Try fetching a URL which takes 1.2 seconds. We should abort the request
289 // after 500 ms, and fail with a timeout error. 279 // after 500 ms, and fail with a timeout error.
290 { GURL url = server->TestServerPage("slow/proxy.pac?1.2"); 280 { GURL url = server.TestServerPage("slow/proxy.pac?1.2");
291 FetchResult result = pac_fetcher.Fetch(url); 281 FetchResult result = pac_fetcher.Fetch(url);
292 EXPECT_EQ(net::ERR_TIMED_OUT, result.code); 282 EXPECT_EQ(net::ERR_TIMED_OUT, result.code);
293 EXPECT_TRUE(result.bytes.empty()); 283 EXPECT_TRUE(result.bytes.empty());
294 } 284 }
295 285
296 // Restore the original timeout period. 286 // Restore the original timeout period.
297 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout); 287 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout);
298 288
299 { // Make sure we can still fetch regular URLs. 289 { // Make sure we can still fetch regular URLs.
300 GURL url = server->TestServerPage("files/pac.nsproxy"); 290 GURL url = server.TestServerPage("files/pac.nsproxy");
301 FetchResult result = pac_fetcher.Fetch(url); 291 FetchResult result = pac_fetcher.Fetch(url);
302 EXPECT_EQ(net::OK, result.code); 292 EXPECT_EQ(net::OK, result.code);
303 EXPECT_EQ("-pac.nsproxy-\n", result.bytes); 293 EXPECT_EQ("-pac.nsproxy-\n", result.bytes);
304 } 294 }
305 } 295 }
306 296
307 } // namespace net 297 } // namespace net
OLDNEW
« no previous file with comments | « chrome/test/ui/inspector_controller_uitest.cc ('k') | net/url_request/url_request_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698