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

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

Issue 11293252: Change Interceptors into URLRequestJobFactory::ProtocolHandlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address erikwright's third round of comments Created 8 years 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 | Annotate | Revision Log
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"
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/protocol_intercept_job_factory.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_impl.h" 27 #include "net/url_request/url_request_job_factory_impl.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):
34 // - Test canceling an outstanding request. 35 // - Test canceling an outstanding request.
35 // - Test deleting ProxyScriptFetcher while a request is in progress. 36 // - Test deleting ProxyScriptFetcher while a request is in progress.
36 37
37 namespace { 38 namespace {
38 39
39 const FilePath::CharType kDocRoot[] = 40 const FilePath::CharType kDocRoot[] =
40 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); 41 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest");
41 42
42 struct FetchResult { 43 struct FetchResult {
43 int code; 44 int code;
44 string16 text; 45 string16 text;
45 }; 46 };
46 47
47 // CheckNoRevocationFlagSetInterceptor causes a test failure if a request is 48 // CheckNoRevocationFlagSetInterceptor causes a test failure if a request is
48 // seen that doesn't set a load flag to bypass revocation checking. 49 // seen that doesn't set a load flag to bypass revocation checking.
49 class CheckNoRevocationFlagSetInterceptor : 50 class CheckNoRevocationFlagSetInterceptor :
50 public URLRequestJobFactory::Interceptor { 51 public URLRequestJobFactory::ProtocolHandler {
51 public: 52 public:
52 virtual URLRequestJob* MaybeIntercept( 53 virtual URLRequestJob* MaybeCreateJob(
53 URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE { 54 URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE {
54 EXPECT_TRUE(request->load_flags() & LOAD_DISABLE_CERT_REVOCATION_CHECKING); 55 EXPECT_TRUE(request->load_flags() & LOAD_DISABLE_CERT_REVOCATION_CHECKING);
55 return NULL; 56 return NULL;
56 } 57 }
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 }; 58 };
70 59
71 // A non-mock URL request which can access http:// and file:// urls. 60 // A non-mock URL request which can access http:// and file:// urls.
72 class RequestContext : public URLRequestContext { 61 class RequestContext : public URLRequestContext {
73 public: 62 public:
74 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { 63 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) {
75 ProxyConfig no_proxy; 64 ProxyConfig no_proxy;
76 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); 65 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver));
77 storage_.set_cert_verifier(new MockCertVerifier); 66 storage_.set_cert_verifier(new MockCertVerifier);
78 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy)); 67 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy));
79 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); 68 storage_.set_ssl_config_service(new SSLConfigServiceDefaults);
80 storage_.set_http_server_properties(new HttpServerPropertiesImpl); 69 storage_.set_http_server_properties(new HttpServerPropertiesImpl);
81 70
82 HttpNetworkSession::Params params; 71 HttpNetworkSession::Params params;
83 params.host_resolver = host_resolver(); 72 params.host_resolver = host_resolver();
84 params.cert_verifier = cert_verifier(); 73 params.cert_verifier = cert_verifier();
85 params.proxy_service = proxy_service(); 74 params.proxy_service = proxy_service();
86 params.ssl_config_service = ssl_config_service(); 75 params.ssl_config_service = ssl_config_service();
87 params.http_server_properties = http_server_properties(); 76 params.http_server_properties = http_server_properties();
88 scoped_refptr<HttpNetworkSession> network_session( 77 scoped_refptr<HttpNetworkSession> network_session(
89 new HttpNetworkSession(params)); 78 new HttpNetworkSession(params));
90 storage_.set_http_transaction_factory(new HttpCache( 79 storage_.set_http_transaction_factory(new HttpCache(
91 network_session, 80 network_session,
92 HttpCache::DefaultBackend::InMemory(0))); 81 HttpCache::DefaultBackend::InMemory(0)));
93 scoped_ptr<URLRequestJobFactoryImpl> factory(new URLRequestJobFactoryImpl); 82 url_request_job_factory_.reset(new URLRequestJobFactoryImpl);
94 factory->AddInterceptor(new CheckNoRevocationFlagSetInterceptor); 83 url_request_job_factory_.reset(new ProtocolInterceptJobFactory(
95 url_request_job_factory_ = factory.Pass(); 84 url_request_job_factory_.Pass(),
mmenke 2012/12/11 17:22:38 optional: This certainly works, but I think stori
85 new CheckNoRevocationFlagSetInterceptor()));
96 set_job_factory(url_request_job_factory_.get()); 86 set_job_factory(url_request_job_factory_.get());
97 } 87 }
98 88
99 virtual ~RequestContext() { 89 virtual ~RequestContext() {
100 } 90 }
101 91
102 private: 92 private:
103 URLRequestContextStorage storage_; 93 URLRequestContextStorage storage_;
104 scoped_ptr<URLRequestJobFactory> url_request_job_factory_; 94 scoped_ptr<URLRequestJobFactory> url_request_job_factory_;
105 }; 95 };
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 { 488 {
499 GURL url(kEncodedUrlBroken); 489 GURL url(kEncodedUrlBroken);
500 string16 text; 490 string16 text;
501 TestCompletionCallback callback; 491 TestCompletionCallback callback;
502 int result = pac_fetcher.Fetch(url, &text, callback.callback()); 492 int result = pac_fetcher.Fetch(url, &text, callback.callback());
503 EXPECT_EQ(ERR_FAILED, result); 493 EXPECT_EQ(ERR_FAILED, result);
504 } 494 }
505 } 495 }
506 496
507 } // namespace net 497 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698