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

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

Issue 11412070: Fix and enable the PAC fetcher NoCache test on Android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address pliard remark / amend comment layout Created 8 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
« no previous file with comments | « build/android/gtest_filter/net_unittests_disabled ('k') | no next file » | 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) 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
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
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
OLDNEW
« no previous file with comments | « build/android/gtest_filter/net_unittests_disabled ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698