Chromium Code Reviews| 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. | |
| 323 // See: https://codereview.chromium.org/118032/ | |
|
eroman
2012/11/20 00:26:58
We typically don't link to codereviews.
You could
| |
| 322 TEST_F(ProxyScriptFetcherImplTest, NoCache) { | 324 TEST_F(ProxyScriptFetcherImplTest, NoCache) { |
| 323 ASSERT_TRUE(test_server_.Start()); | 325 ASSERT_TRUE(test_server_.Start()); |
| 324 | 326 |
| 325 ProxyScriptFetcherImpl pac_fetcher(&context_); | 327 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 326 | 328 |
| 327 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. | 329 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. |
| 328 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); | 330 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); |
| 329 { | 331 { |
| 330 string16 text; | 332 string16 text; |
| 331 TestCompletionCallback callback; | 333 TestCompletionCallback callback; |
| 332 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 334 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 333 EXPECT_EQ(ERR_IO_PENDING, result); | 335 EXPECT_EQ(ERR_IO_PENDING, result); |
| 334 EXPECT_EQ(OK, callback.WaitForResult()); | 336 EXPECT_EQ(OK, callback.WaitForResult()); |
| 335 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); | 337 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); |
| 336 } | 338 } |
| 337 | 339 |
| 338 // Now kill the HTTP server. | 340 // Kill the HTTP server. |
| 339 ASSERT_TRUE(test_server_.Stop()); | 341 ASSERT_TRUE(test_server_.Stop()); |
| 340 | 342 |
| 341 // Try to fetch the file again -- if should fail, since the server is not | 343 // 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 | 344 // call should fail, thus indicating that the file was not fetched from the |
| 343 // get a success. | 345 // local cache. |
| 344 { | 346 { |
| 345 string16 text; | 347 string16 text; |
| 346 TestCompletionCallback callback; | 348 TestCompletionCallback callback; |
| 347 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 349 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 348 EXPECT_EQ(ERR_IO_PENDING, result); | 350 EXPECT_EQ(ERR_IO_PENDING, result); |
| 351 | |
| 352 #if defined(OS_ANDROID) | |
| 353 // On Android platform, the tests are run on the device while the server | |
| 354 // runs on the host machine. After killing the server, port forwarder | |
| 355 // running on the device is still active, which produces error message | |
| 356 // "Connection reset by peer" rather than "Connection refused". | |
| 357 EXPECT_EQ(ERR_CONNECTION_RESET, callback.WaitForResult()); | |
| 358 #else | |
| 349 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 359 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
| 360 #endif | |
| 350 } | 361 } |
| 351 } | 362 } |
| 352 | 363 |
| 353 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { | 364 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { |
| 354 ASSERT_TRUE(test_server_.Start()); | 365 ASSERT_TRUE(test_server_.Start()); |
| 355 | 366 |
| 356 ProxyScriptFetcherImpl pac_fetcher(&context_); | 367 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 357 | 368 |
| 358 // Set the maximum response size to 50 bytes. | 369 // Set the maximum response size to 50 bytes. |
| 359 int prev_size = pac_fetcher.SetSizeConstraint(50); | 370 int prev_size = pac_fetcher.SetSizeConstraint(50); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 { | 499 { |
| 489 GURL url(kEncodedUrlBroken); | 500 GURL url(kEncodedUrlBroken); |
| 490 string16 text; | 501 string16 text; |
| 491 TestCompletionCallback callback; | 502 TestCompletionCallback callback; |
| 492 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 503 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 493 EXPECT_EQ(ERR_FAILED, result); | 504 EXPECT_EQ(ERR_FAILED, result); |
| 494 } | 505 } |
| 495 } | 506 } |
| 496 | 507 |
| 497 } // namespace net | 508 } // namespace net |
| OLD | NEW |