| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "net/base/mock_cert_verifier.h" | 13 #include "net/base/mock_cert_verifier.h" |
| 14 #include "net/base/mock_host_resolver.h" | 14 #include "net/base/mock_host_resolver.h" |
| 15 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/base/ssl_config_service_defaults.h" | 17 #include "net/base/ssl_config_service_defaults.h" |
| 18 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 19 #include "net/disk_cache/disk_cache.h" | 19 #include "net/disk_cache/disk_cache.h" |
| 20 #include "net/http/http_cache.h" | 20 #include "net/http/http_cache.h" |
| 21 #include "net/http/http_network_session.h" | 21 #include "net/http/http_network_session.h" |
| 22 #include "net/http/http_server_properties_impl.h" | 22 #include "net/http/http_server_properties_impl.h" |
| 23 #include "net/test/test_server.h" | 23 #include "net/test/test_server.h" |
| 24 #include "net/url_request/file_protocol_handler.h" |
| 24 #include "net/url_request/url_request_context_storage.h" | 25 #include "net/url_request/url_request_context_storage.h" |
| 25 #include "net/url_request/url_request_file_job.h" | 26 #include "net/url_request/url_request_file_job.h" |
| 26 #include "net/url_request/url_request_job_factory.h" | 27 #include "net/url_request/url_request_job_factory.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "testing/platform_test.h" | 30 #include "testing/platform_test.h" |
| 30 | 31 |
| 31 namespace net { | 32 namespace net { |
| 32 | 33 |
| 33 // TODO(eroman): | 34 // TODO(eroman): |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 context_.set_network_delegate(&network_delegate_); | 212 context_.set_network_delegate(&network_delegate_); |
| 212 } | 213 } |
| 213 | 214 |
| 214 protected: | 215 protected: |
| 215 TestServer test_server_; | 216 TestServer test_server_; |
| 216 BasicNetworkDelegate network_delegate_; | 217 BasicNetworkDelegate network_delegate_; |
| 217 RequestContext context_; | 218 RequestContext context_; |
| 218 }; | 219 }; |
| 219 | 220 |
| 220 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { | 221 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { |
| 222 URLRequestJobFactory job_factory; |
| 223 job_factory.SetProtocolHandler( |
| 224 "file", |
| 225 new FileProtocolHandler(context_.network_delegate())); |
| 226 context_.set_job_factory(&job_factory); |
| 227 |
| 221 ProxyScriptFetcherImpl pac_fetcher(&context_); | 228 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 222 | 229 |
| 223 { // Fetch a non-existent file. | 230 { // Fetch a non-existent file. |
| 224 string16 text; | 231 string16 text; |
| 225 TestCompletionCallback callback; | 232 TestCompletionCallback callback; |
| 226 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), | 233 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), |
| 227 &text, callback.callback()); | 234 &text, callback.callback()); |
| 228 EXPECT_EQ(ERR_IO_PENDING, result); | 235 EXPECT_EQ(ERR_IO_PENDING, result); |
| 229 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); | 236 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); |
| 230 EXPECT_TRUE(text.empty()); | 237 EXPECT_TRUE(text.empty()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 TestCompletionCallback callback; | 351 TestCompletionCallback callback; |
| 345 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 352 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 346 EXPECT_EQ(ERR_IO_PENDING, result); | 353 EXPECT_EQ(ERR_IO_PENDING, result); |
| 347 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 354 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
| 348 } | 355 } |
| 349 } | 356 } |
| 350 | 357 |
| 351 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { | 358 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { |
| 352 ASSERT_TRUE(test_server_.Start()); | 359 ASSERT_TRUE(test_server_.Start()); |
| 353 | 360 |
| 361 URLRequestJobFactory job_factory; |
| 362 job_factory.SetProtocolHandler( |
| 363 "file", |
| 364 new FileProtocolHandler(context_.network_delegate())); |
| 365 context_.set_job_factory(&job_factory); |
| 366 |
| 354 ProxyScriptFetcherImpl pac_fetcher(&context_); | 367 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 355 | 368 |
| 356 // Set the maximum response size to 50 bytes. | 369 // Set the maximum response size to 50 bytes. |
| 357 int prev_size = pac_fetcher.SetSizeConstraint(50); | 370 int prev_size = pac_fetcher.SetSizeConstraint(50); |
| 358 | 371 |
| 359 // These two URLs are the same file, but are http:// vs file:// | 372 // These two URLs are the same file, but are http:// vs file:// |
| 360 GURL urls[] = { | 373 GURL urls[] = { |
| 361 test_server_.GetURL("files/large-pac.nsproxy"), | 374 test_server_.GetURL("files/large-pac.nsproxy"), |
| 362 GetTestFileUrl("large-pac.nsproxy") | 375 GetTestFileUrl("large-pac.nsproxy") |
| 363 }; | 376 }; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 { | 499 { |
| 487 GURL url(kEncodedUrlBroken); | 500 GURL url(kEncodedUrlBroken); |
| 488 string16 text; | 501 string16 text; |
| 489 TestCompletionCallback callback; | 502 TestCompletionCallback callback; |
| 490 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 503 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 491 EXPECT_EQ(ERR_FAILED, result); | 504 EXPECT_EQ(ERR_FAILED, result); |
| 492 } | 505 } |
| 493 } | 506 } |
| 494 | 507 |
| 495 } // namespace net | 508 } // namespace net |
| OLD | NEW |