| OLD | NEW |
| 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" |
| 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/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 #include "net/base/load_flags.h" | |
| 15 #include "net/base/ssl_config_service_defaults.h" | 14 #include "net/base/ssl_config_service_defaults.h" |
| 16 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 17 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
| 18 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
| 19 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 20 #include "net/test/test_server.h" | 19 #include "net/test/test_server.h" |
| 21 #include "net/url_request/url_request_context_storage.h" | 20 #include "net/url_request/url_request_context_storage.h" |
| 22 #include "net/url_request/url_request_job_factory.h" | |
| 23 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 26 | 24 |
| 27 namespace net { | 25 namespace net { |
| 28 | 26 |
| 29 // TODO(eroman): | 27 // TODO(eroman): |
| 30 // - Test canceling an outstanding request. | 28 // - Test canceling an outstanding request. |
| 31 // - Test deleting ProxyScriptFetcher while a request is in progress. | 29 // - Test deleting ProxyScriptFetcher while a request is in progress. |
| 32 | 30 |
| 33 namespace { | 31 namespace { |
| 34 | 32 |
| 35 const FilePath::CharType kDocRoot[] = | 33 const FilePath::CharType kDocRoot[] = |
| 36 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); | 34 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); |
| 37 | 35 |
| 38 struct FetchResult { | 36 struct FetchResult { |
| 39 int code; | 37 int code; |
| 40 string16 text; | 38 string16 text; |
| 41 }; | 39 }; |
| 42 | 40 |
| 43 // CheckNoRevocationFlagSetInterceptor causes a test failure if a request is | |
| 44 // seen that doesn't set a load flag to bypass revocation checking. | |
| 45 class CheckNoRevocationFlagSetInterceptor : | |
| 46 public URLRequestJobFactory::Interceptor { | |
| 47 public: | |
| 48 virtual URLRequestJob* MaybeIntercept(URLRequest* request) const OVERRIDE { | |
| 49 EXPECT_TRUE(request->load_flags() & LOAD_DISABLE_CERT_REVOCATION_CHECKING); | |
| 50 return NULL; | |
| 51 } | |
| 52 | |
| 53 virtual URLRequestJob* MaybeInterceptRedirect(const GURL& location, | |
| 54 URLRequest* request) const { | |
| 55 return NULL; | |
| 56 } | |
| 57 | |
| 58 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request) const { | |
| 59 return NULL; | |
| 60 } | |
| 61 }; | |
| 62 | |
| 63 // A non-mock URL request which can access http:// and file:// urls. | 41 // A non-mock URL request which can access http:// and file:// urls. |
| 64 class RequestContext : public URLRequestContext { | 42 class RequestContext : public URLRequestContext { |
| 65 public: | 43 public: |
| 66 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { | 44 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { |
| 67 ProxyConfig no_proxy; | 45 ProxyConfig no_proxy; |
| 68 storage_.set_host_resolver( | 46 storage_.set_host_resolver( |
| 69 CreateSystemHostResolver(HostResolver::kDefaultParallelism, | 47 CreateSystemHostResolver(HostResolver::kDefaultParallelism, |
| 70 HostResolver::kDefaultRetryAttempts, | 48 HostResolver::kDefaultRetryAttempts, |
| 71 NULL)); | 49 NULL)); |
| 72 storage_.set_cert_verifier(new CertVerifier); | 50 storage_.set_cert_verifier(new CertVerifier); |
| 73 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy)); | 51 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy)); |
| 74 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); | 52 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); |
| 75 | 53 |
| 76 HttpNetworkSession::Params params; | 54 HttpNetworkSession::Params params; |
| 77 params.host_resolver = host_resolver(); | 55 params.host_resolver = host_resolver(); |
| 78 params.cert_verifier = cert_verifier(); | 56 params.cert_verifier = cert_verifier(); |
| 79 params.proxy_service = proxy_service(); | 57 params.proxy_service = proxy_service(); |
| 80 params.ssl_config_service = ssl_config_service(); | 58 params.ssl_config_service = ssl_config_service(); |
| 81 scoped_refptr<HttpNetworkSession> network_session( | 59 scoped_refptr<HttpNetworkSession> network_session( |
| 82 new HttpNetworkSession(params)); | 60 new HttpNetworkSession(params)); |
| 83 storage_.set_http_transaction_factory(new HttpCache( | 61 storage_.set_http_transaction_factory(new HttpCache( |
| 84 network_session, | 62 network_session, |
| 85 HttpCache::DefaultBackend::InMemory(0))); | 63 HttpCache::DefaultBackend::InMemory(0))); |
| 86 url_request_job_factory_.reset(new URLRequestJobFactory); | |
| 87 set_job_factory(url_request_job_factory_.get()); | |
| 88 url_request_job_factory_->AddInterceptor( | |
| 89 new CheckNoRevocationFlagSetInterceptor); | |
| 90 } | 64 } |
| 91 | 65 |
| 92 private: | 66 private: |
| 93 ~RequestContext() { | 67 ~RequestContext() { |
| 94 } | 68 } |
| 95 | 69 |
| 96 URLRequestContextStorage storage_; | 70 URLRequestContextStorage storage_; |
| 97 scoped_ptr<URLRequestJobFactory> url_request_job_factory_; | |
| 98 }; | 71 }; |
| 99 | 72 |
| 100 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. | 73 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. |
| 101 GURL GetTestFileUrl(const std::string& relpath) { | 74 GURL GetTestFileUrl(const std::string& relpath) { |
| 102 FilePath path; | 75 FilePath path; |
| 103 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 76 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 104 path = path.AppendASCII("net"); | 77 path = path.AppendASCII("net"); |
| 105 path = path.AppendASCII("data"); | 78 path = path.AppendASCII("data"); |
| 106 path = path.AppendASCII("proxy_script_fetcher_unittest"); | 79 path = path.AppendASCII("proxy_script_fetcher_unittest"); |
| 107 GURL base_url = FilePathToFileURL(path); | 80 GURL base_url = FilePathToFileURL(path); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 { | 374 { |
| 402 GURL url(kEncodedUrlBroken); | 375 GURL url(kEncodedUrlBroken); |
| 403 string16 text; | 376 string16 text; |
| 404 TestCompletionCallback callback; | 377 TestCompletionCallback callback; |
| 405 int result = pac_fetcher.Fetch(url, &text, &callback); | 378 int result = pac_fetcher.Fetch(url, &text, &callback); |
| 406 EXPECT_EQ(ERR_FAILED, result); | 379 EXPECT_EQ(ERR_FAILED, result); |
| 407 } | 380 } |
| 408 } | 381 } |
| 409 | 382 |
| 410 } // namespace net | 383 } // namespace net |
| OLD | NEW |