OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // have no effect. | 312 // have no effect. |
313 GURL url(test_server_.GetURL("files/downloadable.pac")); | 313 GURL url(test_server_.GetURL("files/downloadable.pac")); |
314 string16 text; | 314 string16 text; |
315 TestCompletionCallback callback; | 315 TestCompletionCallback callback; |
316 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 316 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
317 EXPECT_EQ(ERR_IO_PENDING, result); | 317 EXPECT_EQ(ERR_IO_PENDING, result); |
318 EXPECT_EQ(OK, callback.WaitForResult()); | 318 EXPECT_EQ(OK, callback.WaitForResult()); |
319 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); | 319 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); |
320 } | 320 } |
321 | 321 |
| 322 // Verifies that PAC scripts are not being cached. |
322 TEST_F(ProxyScriptFetcherImplTest, NoCache) { | 323 TEST_F(ProxyScriptFetcherImplTest, NoCache) { |
323 ASSERT_TRUE(test_server_.Start()); | 324 ASSERT_TRUE(test_server_.Start()); |
324 | 325 |
325 ProxyScriptFetcherImpl pac_fetcher(&context_); | 326 ProxyScriptFetcherImpl pac_fetcher(&context_); |
326 | 327 |
327 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. | 328 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. |
328 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); | 329 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); |
329 { | 330 { |
330 string16 text; | 331 string16 text; |
331 TestCompletionCallback callback; | 332 TestCompletionCallback callback; |
332 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 333 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
333 EXPECT_EQ(ERR_IO_PENDING, result); | 334 EXPECT_EQ(ERR_IO_PENDING, result); |
334 EXPECT_EQ(OK, callback.WaitForResult()); | 335 EXPECT_EQ(OK, callback.WaitForResult()); |
335 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); | 336 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); |
336 } | 337 } |
337 | 338 |
338 // Now kill the HTTP server. | 339 // Kill the HTTP server. |
339 ASSERT_TRUE(test_server_.Stop()); | 340 ASSERT_TRUE(test_server_.Stop()); |
340 | 341 |
341 // Try to fetch the file again -- if should fail, since the server is not | 342 // Try to fetch the file again. Since the server is not running anymore, the |
342 // running anymore. (If it were instead being loaded from cache, we would | 343 // call should fail, thus indicating that the file was not fetched from the |
343 // get a success. | 344 // local cache. |
344 { | 345 { |
345 string16 text; | 346 string16 text; |
346 TestCompletionCallback callback; | 347 TestCompletionCallback callback; |
347 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 348 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
348 EXPECT_EQ(ERR_IO_PENDING, result); | 349 EXPECT_EQ(ERR_IO_PENDING, result); |
| 350 |
| 351 #if defined(OS_ANDROID) |
| 352 // On Android platform, the tests are run on the device while the server |
| 353 // runs on the host machine. After killing the server, port forwarder |
| 354 // running on the device is still active, which produces error message |
| 355 // "Connection reset by peer" rather than "Connection refused". |
| 356 EXPECT_EQ(ERR_CONNECTION_RESET, callback.WaitForResult()); |
| 357 #else |
349 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 358 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
| 359 #endif |
350 } | 360 } |
351 } | 361 } |
352 | 362 |
353 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { | 363 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { |
354 ASSERT_TRUE(test_server_.Start()); | 364 ASSERT_TRUE(test_server_.Start()); |
355 | 365 |
356 ProxyScriptFetcherImpl pac_fetcher(&context_); | 366 ProxyScriptFetcherImpl pac_fetcher(&context_); |
357 | 367 |
358 // Set the maximum response size to 50 bytes. | 368 // Set the maximum response size to 50 bytes. |
359 int prev_size = pac_fetcher.SetSizeConstraint(50); | 369 int prev_size = pac_fetcher.SetSizeConstraint(50); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 { | 498 { |
489 GURL url(kEncodedUrlBroken); | 499 GURL url(kEncodedUrlBroken); |
490 string16 text; | 500 string16 text; |
491 TestCompletionCallback callback; | 501 TestCompletionCallback callback; |
492 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 502 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
493 EXPECT_EQ(ERR_FAILED, result); | 503 EXPECT_EQ(ERR_FAILED, result); |
494 } | 504 } |
495 } | 505 } |
496 | 506 |
497 } // namespace net | 507 } // namespace net |
OLD | NEW |