| 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 26 matching lines...) Expand all Loading... |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const FilePath::CharType kDocRoot[] = | 39 const FilePath::CharType kDocRoot[] = |
| 40 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); | 40 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); |
| 41 | 41 |
| 42 struct FetchResult { | 42 struct FetchResult { |
| 43 int code; | 43 int code; |
| 44 string16 text; | 44 string16 text; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // CheckNoRevocationFlagSetInterceptor causes a test failure if a request is | |
| 48 // seen that doesn't set a load flag to bypass revocation checking. | |
| 49 class CheckNoRevocationFlagSetInterceptor : | |
| 50 public URLRequestJobFactory::Interceptor { | |
| 51 public: | |
| 52 virtual URLRequestJob* MaybeIntercept( | |
| 53 URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE { | |
| 54 EXPECT_TRUE(request->load_flags() & LOAD_DISABLE_CERT_REVOCATION_CHECKING); | |
| 55 return NULL; | |
| 56 } | |
| 57 | |
| 58 virtual URLRequestJob* MaybeInterceptRedirect( | |
| 59 const GURL& location, | |
| 60 URLRequest* request, | |
| 61 NetworkDelegate* network_delegate) const OVERRIDE { | |
| 62 return NULL; | |
| 63 } | |
| 64 | |
| 65 virtual URLRequestJob* MaybeInterceptResponse( | |
| 66 URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE { | |
| 67 return NULL; | |
| 68 } | |
| 69 }; | |
| 70 | |
| 71 // A non-mock URL request which can access http:// and file:// urls. | 47 // A non-mock URL request which can access http:// and file:// urls. |
| 72 class RequestContext : public URLRequestContext { | 48 class RequestContext : public URLRequestContext { |
| 73 public: | 49 public: |
| 74 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { | 50 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { |
| 75 ProxyConfig no_proxy; | 51 ProxyConfig no_proxy; |
| 76 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); | 52 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); |
| 77 storage_.set_cert_verifier(new MockCertVerifier); | 53 storage_.set_cert_verifier(new MockCertVerifier); |
| 78 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy)); | 54 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy)); |
| 79 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); | 55 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); |
| 80 storage_.set_http_server_properties(new HttpServerPropertiesImpl); | 56 storage_.set_http_server_properties(new HttpServerPropertiesImpl); |
| 81 | 57 |
| 82 HttpNetworkSession::Params params; | 58 HttpNetworkSession::Params params; |
| 83 params.host_resolver = host_resolver(); | 59 params.host_resolver = host_resolver(); |
| 84 params.cert_verifier = cert_verifier(); | 60 params.cert_verifier = cert_verifier(); |
| 85 params.proxy_service = proxy_service(); | 61 params.proxy_service = proxy_service(); |
| 86 params.ssl_config_service = ssl_config_service(); | 62 params.ssl_config_service = ssl_config_service(); |
| 87 params.http_server_properties = http_server_properties(); | 63 params.http_server_properties = http_server_properties(); |
| 88 scoped_refptr<HttpNetworkSession> network_session( | 64 scoped_refptr<HttpNetworkSession> network_session( |
| 89 new HttpNetworkSession(params)); | 65 new HttpNetworkSession(params)); |
| 90 storage_.set_http_transaction_factory(new HttpCache( | 66 storage_.set_http_transaction_factory(new HttpCache( |
| 91 network_session, | 67 network_session, |
| 92 HttpCache::DefaultBackend::InMemory(0))); | 68 HttpCache::DefaultBackend::InMemory(0))); |
| 93 scoped_ptr<URLRequestJobFactoryImpl> factory(new URLRequestJobFactoryImpl); | 69 set_job_factory(new URLRequestJobFactoryImpl()); |
| 94 factory->AddInterceptor(new CheckNoRevocationFlagSetInterceptor); | |
| 95 url_request_job_factory_ = factory.Pass(); | |
| 96 set_job_factory(url_request_job_factory_.get()); | |
| 97 } | 70 } |
| 98 | 71 |
| 99 virtual ~RequestContext() { | 72 virtual ~RequestContext() { |
| 100 } | 73 } |
| 101 | 74 |
| 102 private: | 75 private: |
| 103 URLRequestContextStorage storage_; | 76 URLRequestContextStorage storage_; |
| 104 scoped_ptr<URLRequestJobFactory> url_request_job_factory_; | 77 scoped_ptr<URLRequestJobFactory> url_request_job_factory_; |
| 105 }; | 78 }; |
| 106 | 79 |
| 107 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. | 80 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. |
| 108 GURL GetTestFileUrl(const std::string& relpath) { | 81 GURL GetTestFileUrl(const std::string& relpath) { |
| 109 FilePath path; | 82 FilePath path; |
| 110 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 83 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 111 path = path.AppendASCII("net"); | 84 path = path.AppendASCII("net"); |
| 112 path = path.AppendASCII("data"); | 85 path = path.AppendASCII("data"); |
| 113 path = path.AppendASCII("proxy_script_fetcher_unittest"); | 86 path = path.AppendASCII("proxy_script_fetcher_unittest"); |
| 114 GURL base_url = FilePathToFileURL(path); | 87 GURL base_url = FilePathToFileURL(path); |
| 115 return GURL(base_url.spec() + "/" + relpath); | 88 return GURL(base_url.spec() + "/" + relpath); |
| 116 } | 89 } |
| 117 | 90 |
| 118 // Really simple NetworkDelegate so we can allow local file access on ChromeOS | 91 // Really simple NetworkDelegate so we can allow local file access on ChromeOS |
| 119 // without introducing layering violations. | 92 // without introducing layering violations. Also causes a test failure if a |
| 93 // request is seen that doesn't set a load flag to bypass revocation checking. |
| 94 |
| 120 class BasicNetworkDelegate : public NetworkDelegate { | 95 class BasicNetworkDelegate : public NetworkDelegate { |
| 121 public: | 96 public: |
| 122 BasicNetworkDelegate() {} | 97 BasicNetworkDelegate() {} |
| 123 virtual ~BasicNetworkDelegate() {} | 98 virtual ~BasicNetworkDelegate() {} |
| 124 | 99 |
| 125 private: | 100 private: |
| 126 virtual int OnBeforeURLRequest(URLRequest* request, | 101 virtual int OnBeforeURLRequest(URLRequest* request, |
| 127 const CompletionCallback& callback, | 102 const CompletionCallback& callback, |
| 128 GURL* new_url) OVERRIDE { | 103 GURL* new_url) OVERRIDE { |
| 104 EXPECT_TRUE(request->load_flags() & LOAD_DISABLE_CERT_REVOCATION_CHECKING); |
| 129 return OK; | 105 return OK; |
| 130 } | 106 } |
| 131 | 107 |
| 132 virtual int OnBeforeSendHeaders(URLRequest* request, | 108 virtual int OnBeforeSendHeaders(URLRequest* request, |
| 133 const CompletionCallback& callback, | 109 const CompletionCallback& callback, |
| 134 HttpRequestHeaders* headers) OVERRIDE { | 110 HttpRequestHeaders* headers) OVERRIDE { |
| 135 return OK; | 111 return OK; |
| 136 } | 112 } |
| 137 | 113 |
| 138 virtual void OnSendHeaders(URLRequest* request, | 114 virtual void OnSendHeaders(URLRequest* request, |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 { | 474 { |
| 499 GURL url(kEncodedUrlBroken); | 475 GURL url(kEncodedUrlBroken); |
| 500 string16 text; | 476 string16 text; |
| 501 TestCompletionCallback callback; | 477 TestCompletionCallback callback; |
| 502 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 478 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 503 EXPECT_EQ(ERR_FAILED, result); | 479 EXPECT_EQ(ERR_FAILED, result); |
| 504 } | 480 } |
| 505 } | 481 } |
| 506 | 482 |
| 507 } // namespace net | 483 } // namespace net |
| OLD | NEW |