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

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

Issue 8985012: base::Bind: Convert net/proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more include. Created 9 years 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 | « net/proxy/proxy_script_fetcher_impl.cc ('k') | net/proxy/proxy_service.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 protected: 128 protected:
129 TestServer test_server_; 129 TestServer test_server_;
130 }; 130 };
131 131
132 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { 132 TEST_F(ProxyScriptFetcherImplTest, FileUrl) {
133 scoped_refptr<URLRequestContext> context(new RequestContext); 133 scoped_refptr<URLRequestContext> context(new RequestContext);
134 ProxyScriptFetcherImpl pac_fetcher(context); 134 ProxyScriptFetcherImpl pac_fetcher(context);
135 135
136 { // Fetch a non-existent file. 136 { // Fetch a non-existent file.
137 string16 text; 137 string16 text;
138 TestOldCompletionCallback callback; 138 TestCompletionCallback callback;
139 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), 139 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"),
140 &text, &callback); 140 &text, callback.callback());
141 EXPECT_EQ(ERR_IO_PENDING, result); 141 EXPECT_EQ(ERR_IO_PENDING, result);
142 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); 142 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult());
143 EXPECT_TRUE(text.empty()); 143 EXPECT_TRUE(text.empty());
144 } 144 }
145 { // Fetch a file that exists. 145 { // Fetch a file that exists.
146 string16 text; 146 string16 text;
147 TestOldCompletionCallback callback; 147 TestCompletionCallback callback;
148 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), 148 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"),
149 &text, &callback); 149 &text, callback.callback());
150 EXPECT_EQ(ERR_IO_PENDING, result); 150 EXPECT_EQ(ERR_IO_PENDING, result);
151 EXPECT_EQ(OK, callback.WaitForResult()); 151 EXPECT_EQ(OK, callback.WaitForResult());
152 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); 152 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
153 } 153 }
154 } 154 }
155 155
156 // Note that all mime types are allowed for PAC file, to be consistent 156 // Note that all mime types are allowed for PAC file, to be consistent
157 // with other browsers. 157 // with other browsers.
158 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { 158 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) {
159 ASSERT_TRUE(test_server_.Start()); 159 ASSERT_TRUE(test_server_.Start());
160 160
161 scoped_refptr<URLRequestContext> context(new RequestContext); 161 scoped_refptr<URLRequestContext> context(new RequestContext);
162 ProxyScriptFetcherImpl pac_fetcher(context); 162 ProxyScriptFetcherImpl pac_fetcher(context);
163 163
164 { // Fetch a PAC with mime type "text/plain" 164 { // Fetch a PAC with mime type "text/plain"
165 GURL url(test_server_.GetURL("files/pac.txt")); 165 GURL url(test_server_.GetURL("files/pac.txt"));
166 string16 text; 166 string16 text;
167 TestOldCompletionCallback callback; 167 TestCompletionCallback callback;
168 int result = pac_fetcher.Fetch(url, &text, &callback); 168 int result = pac_fetcher.Fetch(url, &text, callback.callback());
169 EXPECT_EQ(ERR_IO_PENDING, result); 169 EXPECT_EQ(ERR_IO_PENDING, result);
170 EXPECT_EQ(OK, callback.WaitForResult()); 170 EXPECT_EQ(OK, callback.WaitForResult());
171 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); 171 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
172 } 172 }
173 { // Fetch a PAC with mime type "text/html" 173 { // Fetch a PAC with mime type "text/html"
174 GURL url(test_server_.GetURL("files/pac.html")); 174 GURL url(test_server_.GetURL("files/pac.html"));
175 string16 text; 175 string16 text;
176 TestOldCompletionCallback callback; 176 TestCompletionCallback callback;
177 int result = pac_fetcher.Fetch(url, &text, &callback); 177 int result = pac_fetcher.Fetch(url, &text, callback.callback());
178 EXPECT_EQ(ERR_IO_PENDING, result); 178 EXPECT_EQ(ERR_IO_PENDING, result);
179 EXPECT_EQ(OK, callback.WaitForResult()); 179 EXPECT_EQ(OK, callback.WaitForResult());
180 EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text); 180 EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text);
181 } 181 }
182 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" 182 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig"
183 GURL url(test_server_.GetURL("files/pac.nsproxy")); 183 GURL url(test_server_.GetURL("files/pac.nsproxy"));
184 string16 text; 184 string16 text;
185 TestOldCompletionCallback callback; 185 TestCompletionCallback callback;
186 int result = pac_fetcher.Fetch(url, &text, &callback); 186 int result = pac_fetcher.Fetch(url, &text, callback.callback());
187 EXPECT_EQ(ERR_IO_PENDING, result); 187 EXPECT_EQ(ERR_IO_PENDING, result);
188 EXPECT_EQ(OK, callback.WaitForResult()); 188 EXPECT_EQ(OK, callback.WaitForResult());
189 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 189 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
190 } 190 }
191 } 191 }
192 192
193 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { 193 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) {
194 ASSERT_TRUE(test_server_.Start()); 194 ASSERT_TRUE(test_server_.Start());
195 195
196 scoped_refptr<URLRequestContext> context(new RequestContext); 196 scoped_refptr<URLRequestContext> context(new RequestContext);
197 ProxyScriptFetcherImpl pac_fetcher(context); 197 ProxyScriptFetcherImpl pac_fetcher(context);
198 198
199 { // Fetch a PAC which gives a 500 -- FAIL 199 { // Fetch a PAC which gives a 500 -- FAIL
200 GURL url(test_server_.GetURL("files/500.pac")); 200 GURL url(test_server_.GetURL("files/500.pac"));
201 string16 text; 201 string16 text;
202 TestOldCompletionCallback callback; 202 TestCompletionCallback callback;
203 int result = pac_fetcher.Fetch(url, &text, &callback); 203 int result = pac_fetcher.Fetch(url, &text, callback.callback());
204 EXPECT_EQ(ERR_IO_PENDING, result); 204 EXPECT_EQ(ERR_IO_PENDING, result);
205 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); 205 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
206 EXPECT_TRUE(text.empty()); 206 EXPECT_TRUE(text.empty());
207 } 207 }
208 { // Fetch a PAC which gives a 404 -- FAIL 208 { // Fetch a PAC which gives a 404 -- FAIL
209 GURL url(test_server_.GetURL("files/404.pac")); 209 GURL url(test_server_.GetURL("files/404.pac"));
210 string16 text; 210 string16 text;
211 TestOldCompletionCallback callback; 211 TestCompletionCallback callback;
212 int result = pac_fetcher.Fetch(url, &text, &callback); 212 int result = pac_fetcher.Fetch(url, &text, callback.callback());
213 EXPECT_EQ(ERR_IO_PENDING, result); 213 EXPECT_EQ(ERR_IO_PENDING, result);
214 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); 214 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
215 EXPECT_TRUE(text.empty()); 215 EXPECT_TRUE(text.empty());
216 } 216 }
217 } 217 }
218 218
219 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { 219 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) {
220 ASSERT_TRUE(test_server_.Start()); 220 ASSERT_TRUE(test_server_.Start());
221 221
222 scoped_refptr<URLRequestContext> context(new RequestContext); 222 scoped_refptr<URLRequestContext> context(new RequestContext);
223 ProxyScriptFetcherImpl pac_fetcher(context); 223 ProxyScriptFetcherImpl pac_fetcher(context);
224 224
225 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should 225 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should
226 // have no effect. 226 // have no effect.
227 GURL url(test_server_.GetURL("files/downloadable.pac")); 227 GURL url(test_server_.GetURL("files/downloadable.pac"));
228 string16 text; 228 string16 text;
229 TestOldCompletionCallback callback; 229 TestCompletionCallback callback;
230 int result = pac_fetcher.Fetch(url, &text, &callback); 230 int result = pac_fetcher.Fetch(url, &text, callback.callback());
231 EXPECT_EQ(ERR_IO_PENDING, result); 231 EXPECT_EQ(ERR_IO_PENDING, result);
232 EXPECT_EQ(OK, callback.WaitForResult()); 232 EXPECT_EQ(OK, callback.WaitForResult());
233 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); 233 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text);
234 } 234 }
235 235
236 TEST_F(ProxyScriptFetcherImplTest, NoCache) { 236 TEST_F(ProxyScriptFetcherImplTest, NoCache) {
237 ASSERT_TRUE(test_server_.Start()); 237 ASSERT_TRUE(test_server_.Start());
238 238
239 scoped_refptr<URLRequestContext> context(new RequestContext); 239 scoped_refptr<URLRequestContext> context(new RequestContext);
240 ProxyScriptFetcherImpl pac_fetcher(context); 240 ProxyScriptFetcherImpl pac_fetcher(context);
241 241
242 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. 242 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour.
243 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); 243 GURL url(test_server_.GetURL("files/cacheable_1hr.pac"));
244 { 244 {
245 string16 text; 245 string16 text;
246 TestOldCompletionCallback callback; 246 TestCompletionCallback callback;
247 int result = pac_fetcher.Fetch(url, &text, &callback); 247 int result = pac_fetcher.Fetch(url, &text, callback.callback());
248 EXPECT_EQ(ERR_IO_PENDING, result); 248 EXPECT_EQ(ERR_IO_PENDING, result);
249 EXPECT_EQ(OK, callback.WaitForResult()); 249 EXPECT_EQ(OK, callback.WaitForResult());
250 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); 250 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text);
251 } 251 }
252 252
253 // Now kill the HTTP server. 253 // Now kill the HTTP server.
254 ASSERT_TRUE(test_server_.Stop()); 254 ASSERT_TRUE(test_server_.Stop());
255 255
256 // Try to fetch the file again -- if should fail, since the server is not 256 // Try to fetch the file again -- if should fail, since the server is not
257 // running anymore. (If it were instead being loaded from cache, we would 257 // running anymore. (If it were instead being loaded from cache, we would
258 // get a success. 258 // get a success.
259 { 259 {
260 string16 text; 260 string16 text;
261 TestOldCompletionCallback callback; 261 TestCompletionCallback callback;
262 int result = pac_fetcher.Fetch(url, &text, &callback); 262 int result = pac_fetcher.Fetch(url, &text, callback.callback());
263 EXPECT_EQ(ERR_IO_PENDING, result); 263 EXPECT_EQ(ERR_IO_PENDING, result);
264 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); 264 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
265 } 265 }
266 } 266 }
267 267
268 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { 268 TEST_F(ProxyScriptFetcherImplTest, TooLarge) {
269 ASSERT_TRUE(test_server_.Start()); 269 ASSERT_TRUE(test_server_.Start());
270 270
271 scoped_refptr<URLRequestContext> context(new RequestContext); 271 scoped_refptr<URLRequestContext> context(new RequestContext);
272 ProxyScriptFetcherImpl pac_fetcher(context); 272 ProxyScriptFetcherImpl pac_fetcher(context);
273 273
274 // Set the maximum response size to 50 bytes. 274 // Set the maximum response size to 50 bytes.
275 int prev_size = pac_fetcher.SetSizeConstraint(50); 275 int prev_size = pac_fetcher.SetSizeConstraint(50);
276 276
277 // These two URLs are the same file, but are http:// vs file:// 277 // These two URLs are the same file, but are http:// vs file://
278 GURL urls[] = { 278 GURL urls[] = {
279 test_server_.GetURL("files/large-pac.nsproxy"), 279 test_server_.GetURL("files/large-pac.nsproxy"),
280 GetTestFileUrl("large-pac.nsproxy") 280 GetTestFileUrl("large-pac.nsproxy")
281 }; 281 };
282 282
283 // Try fetching URLs that are 101 bytes large. We should abort the request 283 // Try fetching URLs that are 101 bytes large. We should abort the request
284 // after 50 bytes have been read, and fail with a too large error. 284 // after 50 bytes have been read, and fail with a too large error.
285 for (size_t i = 0; i < arraysize(urls); ++i) { 285 for (size_t i = 0; i < arraysize(urls); ++i) {
286 const GURL& url = urls[i]; 286 const GURL& url = urls[i];
287 string16 text; 287 string16 text;
288 TestOldCompletionCallback callback; 288 TestCompletionCallback callback;
289 int result = pac_fetcher.Fetch(url, &text, &callback); 289 int result = pac_fetcher.Fetch(url, &text, callback.callback());
290 EXPECT_EQ(ERR_IO_PENDING, result); 290 EXPECT_EQ(ERR_IO_PENDING, result);
291 EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult()); 291 EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult());
292 EXPECT_TRUE(text.empty()); 292 EXPECT_TRUE(text.empty());
293 } 293 }
294 294
295 // Restore the original size bound. 295 // Restore the original size bound.
296 pac_fetcher.SetSizeConstraint(prev_size); 296 pac_fetcher.SetSizeConstraint(prev_size);
297 297
298 { // Make sure we can still fetch regular URLs. 298 { // Make sure we can still fetch regular URLs.
299 GURL url(test_server_.GetURL("files/pac.nsproxy")); 299 GURL url(test_server_.GetURL("files/pac.nsproxy"));
300 string16 text; 300 string16 text;
301 TestOldCompletionCallback callback; 301 TestCompletionCallback callback;
302 int result = pac_fetcher.Fetch(url, &text, &callback); 302 int result = pac_fetcher.Fetch(url, &text, callback.callback());
303 EXPECT_EQ(ERR_IO_PENDING, result); 303 EXPECT_EQ(ERR_IO_PENDING, result);
304 EXPECT_EQ(OK, callback.WaitForResult()); 304 EXPECT_EQ(OK, callback.WaitForResult());
305 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 305 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
306 } 306 }
307 } 307 }
308 308
309 TEST_F(ProxyScriptFetcherImplTest, Hang) { 309 TEST_F(ProxyScriptFetcherImplTest, Hang) {
310 ASSERT_TRUE(test_server_.Start()); 310 ASSERT_TRUE(test_server_.Start());
311 311
312 scoped_refptr<URLRequestContext> context(new RequestContext); 312 scoped_refptr<URLRequestContext> context(new RequestContext);
313 ProxyScriptFetcherImpl pac_fetcher(context); 313 ProxyScriptFetcherImpl pac_fetcher(context);
314 314
315 // Set the timeout period to 0.5 seconds. 315 // Set the timeout period to 0.5 seconds.
316 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( 316 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint(
317 base::TimeDelta::FromMilliseconds(500)); 317 base::TimeDelta::FromMilliseconds(500));
318 318
319 // Try fetching a URL which takes 1.2 seconds. We should abort the request 319 // Try fetching a URL which takes 1.2 seconds. We should abort the request
320 // after 500 ms, and fail with a timeout error. 320 // after 500 ms, and fail with a timeout error.
321 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); 321 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2"));
322 string16 text; 322 string16 text;
323 TestOldCompletionCallback callback; 323 TestCompletionCallback callback;
324 int result = pac_fetcher.Fetch(url, &text, &callback); 324 int result = pac_fetcher.Fetch(url, &text, callback.callback());
325 EXPECT_EQ(ERR_IO_PENDING, result); 325 EXPECT_EQ(ERR_IO_PENDING, result);
326 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); 326 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult());
327 EXPECT_TRUE(text.empty()); 327 EXPECT_TRUE(text.empty());
328 } 328 }
329 329
330 // Restore the original timeout period. 330 // Restore the original timeout period.
331 pac_fetcher.SetTimeoutConstraint(prev_timeout); 331 pac_fetcher.SetTimeoutConstraint(prev_timeout);
332 332
333 { // Make sure we can still fetch regular URLs. 333 { // Make sure we can still fetch regular URLs.
334 GURL url(test_server_.GetURL("files/pac.nsproxy")); 334 GURL url(test_server_.GetURL("files/pac.nsproxy"));
335 string16 text; 335 string16 text;
336 TestOldCompletionCallback callback; 336 TestCompletionCallback callback;
337 int result = pac_fetcher.Fetch(url, &text, &callback); 337 int result = pac_fetcher.Fetch(url, &text, callback.callback());
338 EXPECT_EQ(ERR_IO_PENDING, result); 338 EXPECT_EQ(ERR_IO_PENDING, result);
339 EXPECT_EQ(OK, callback.WaitForResult()); 339 EXPECT_EQ(OK, callback.WaitForResult());
340 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 340 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
341 } 341 }
342 } 342 }
343 343
344 // The ProxyScriptFetcher should decode any content-codings 344 // The ProxyScriptFetcher should decode any content-codings
345 // (like gzip, bzip, etc.), and apply any charset conversions to yield 345 // (like gzip, bzip, etc.), and apply any charset conversions to yield
346 // UTF8. 346 // UTF8.
347 TEST_F(ProxyScriptFetcherImplTest, Encodings) { 347 TEST_F(ProxyScriptFetcherImplTest, Encodings) {
348 ASSERT_TRUE(test_server_.Start()); 348 ASSERT_TRUE(test_server_.Start());
349 349
350 scoped_refptr<URLRequestContext> context(new RequestContext); 350 scoped_refptr<URLRequestContext> context(new RequestContext);
351 ProxyScriptFetcherImpl pac_fetcher(context); 351 ProxyScriptFetcherImpl pac_fetcher(context);
352 352
353 // Test a response that is gzip-encoded -- should get inflated. 353 // Test a response that is gzip-encoded -- should get inflated.
354 { 354 {
355 GURL url(test_server_.GetURL("files/gzipped_pac")); 355 GURL url(test_server_.GetURL("files/gzipped_pac"));
356 string16 text; 356 string16 text;
357 TestOldCompletionCallback callback; 357 TestCompletionCallback callback;
358 int result = pac_fetcher.Fetch(url, &text, &callback); 358 int result = pac_fetcher.Fetch(url, &text, callback.callback());
359 EXPECT_EQ(ERR_IO_PENDING, result); 359 EXPECT_EQ(ERR_IO_PENDING, result);
360 EXPECT_EQ(OK, callback.WaitForResult()); 360 EXPECT_EQ(OK, callback.WaitForResult());
361 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); 361 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text);
362 } 362 }
363 363
364 // Test a response that was served as UTF-16 (BE). It should 364 // Test a response that was served as UTF-16 (BE). It should
365 // be converted to UTF8. 365 // be converted to UTF8.
366 { 366 {
367 GURL url(test_server_.GetURL("files/utf16be_pac")); 367 GURL url(test_server_.GetURL("files/utf16be_pac"));
368 string16 text; 368 string16 text;
369 TestOldCompletionCallback callback; 369 TestCompletionCallback callback;
370 int result = pac_fetcher.Fetch(url, &text, &callback); 370 int result = pac_fetcher.Fetch(url, &text, callback.callback());
371 EXPECT_EQ(ERR_IO_PENDING, result); 371 EXPECT_EQ(ERR_IO_PENDING, result);
372 EXPECT_EQ(OK, callback.WaitForResult()); 372 EXPECT_EQ(OK, callback.WaitForResult());
373 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); 373 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text);
374 } 374 }
375 } 375 }
376 376
377 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { 377 TEST_F(ProxyScriptFetcherImplTest, DataURLs) {
378 scoped_refptr<URLRequestContext> context(new RequestContext); 378 scoped_refptr<URLRequestContext> context(new RequestContext);
379 ProxyScriptFetcherImpl pac_fetcher(context); 379 ProxyScriptFetcherImpl pac_fetcher(context);
380 380
381 const char kEncodedUrl[] = 381 const char kEncodedUrl[] =
382 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" 382 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R"
383 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" 383 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl"
384 "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0="; 384 "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0=";
385 const char kPacScript[] = 385 const char kPacScript[] =
386 "function FindProxyForURL(url, host) {\n" 386 "function FindProxyForURL(url, host) {\n"
387 " if (host == 'foobar.com')\n" 387 " if (host == 'foobar.com')\n"
388 " return 'PROXY blackhole:80';\n" 388 " return 'PROXY blackhole:80';\n"
389 " return 'DIRECT';\n" 389 " return 'DIRECT';\n"
390 "}"; 390 "}";
391 391
392 // Test fetching a "data:"-url containing a base64 encoded PAC script. 392 // Test fetching a "data:"-url containing a base64 encoded PAC script.
393 { 393 {
394 GURL url(kEncodedUrl); 394 GURL url(kEncodedUrl);
395 string16 text; 395 string16 text;
396 TestOldCompletionCallback callback; 396 TestCompletionCallback callback;
397 int result = pac_fetcher.Fetch(url, &text, &callback); 397 int result = pac_fetcher.Fetch(url, &text, callback.callback());
398 EXPECT_EQ(OK, result); 398 EXPECT_EQ(OK, result);
399 EXPECT_EQ(ASCIIToUTF16(kPacScript), text); 399 EXPECT_EQ(ASCIIToUTF16(kPacScript), text);
400 } 400 }
401 401
402 const char kEncodedUrlBroken[] = 402 const char kEncodedUrlBroken[] =
403 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R"; 403 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R";
404 404
405 // Test a broken "data:"-url containing a base64 encoded PAC script. 405 // Test a broken "data:"-url containing a base64 encoded PAC script.
406 { 406 {
407 GURL url(kEncodedUrlBroken); 407 GURL url(kEncodedUrlBroken);
408 string16 text; 408 string16 text;
409 TestOldCompletionCallback callback; 409 TestCompletionCallback callback;
410 int result = pac_fetcher.Fetch(url, &text, &callback); 410 int result = pac_fetcher.Fetch(url, &text, callback.callback());
411 EXPECT_EQ(ERR_FAILED, result); 411 EXPECT_EQ(ERR_FAILED, result);
412 } 412 }
413 } 413 }
414 414
415 } // namespace net 415 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_fetcher_impl.cc ('k') | net/proxy/proxy_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698