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 #ifndef NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // |network_task_runner| must not be NULL. | 101 // |network_task_runner| must not be NULL. |
102 explicit TestURLRequestContextGetter( | 102 explicit TestURLRequestContextGetter( |
103 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner); | 103 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner); |
104 | 104 |
105 // Use to pass a pre-initialized |context|. | 105 // Use to pass a pre-initialized |context|. |
106 TestURLRequestContextGetter( | 106 TestURLRequestContextGetter( |
107 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, | 107 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, |
108 scoped_ptr<TestURLRequestContext> context); | 108 scoped_ptr<TestURLRequestContext> context); |
109 | 109 |
110 // URLRequestContextGetter implementation. | 110 // URLRequestContextGetter implementation. |
111 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE; | 111 virtual TestURLRequestContext* GetURLRequestContext() override; |
112 virtual scoped_refptr<base::SingleThreadTaskRunner> | 112 virtual scoped_refptr<base::SingleThreadTaskRunner> |
113 GetNetworkTaskRunner() const OVERRIDE; | 113 GetNetworkTaskRunner() const override; |
114 | 114 |
115 protected: | 115 protected: |
116 virtual ~TestURLRequestContextGetter(); | 116 virtual ~TestURLRequestContextGetter(); |
117 | 117 |
118 private: | 118 private: |
119 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 119 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
120 scoped_ptr<TestURLRequestContext> context_; | 120 scoped_ptr<TestURLRequestContext> context_; |
121 }; | 121 }; |
122 | 122 |
123 //----------------------------------------------------------------------------- | 123 //----------------------------------------------------------------------------- |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 bool auth_required_called() const { return auth_required_; } | 164 bool auth_required_called() const { return auth_required_; } |
165 bool have_full_request_headers() const { return have_full_request_headers_; } | 165 bool have_full_request_headers() const { return have_full_request_headers_; } |
166 const HttpRequestHeaders& full_request_headers() const { | 166 const HttpRequestHeaders& full_request_headers() const { |
167 return full_request_headers_; | 167 return full_request_headers_; |
168 } | 168 } |
169 void ClearFullRequestHeaders(); | 169 void ClearFullRequestHeaders(); |
170 | 170 |
171 // URLRequest::Delegate: | 171 // URLRequest::Delegate: |
172 virtual void OnReceivedRedirect(URLRequest* request, | 172 virtual void OnReceivedRedirect(URLRequest* request, |
173 const RedirectInfo& redirect_info, | 173 const RedirectInfo& redirect_info, |
174 bool* defer_redirect) OVERRIDE; | 174 bool* defer_redirect) override; |
175 virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer) OVERRIDE; | 175 virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer) override; |
176 virtual void OnAuthRequired(URLRequest* request, | 176 virtual void OnAuthRequired(URLRequest* request, |
177 AuthChallengeInfo* auth_info) OVERRIDE; | 177 AuthChallengeInfo* auth_info) override; |
178 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. | 178 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. |
179 // (Unit tests use this as a post-condition.) But for policy, this method | 179 // (Unit tests use this as a post-condition.) But for policy, this method |
180 // consults |allow_certificate_errors_|. | 180 // consults |allow_certificate_errors_|. |
181 virtual void OnSSLCertificateError(URLRequest* request, | 181 virtual void OnSSLCertificateError(URLRequest* request, |
182 const SSLInfo& ssl_info, | 182 const SSLInfo& ssl_info, |
183 bool fatal) OVERRIDE; | 183 bool fatal) override; |
184 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; | 184 virtual void OnResponseStarted(URLRequest* request) override; |
185 virtual void OnReadCompleted(URLRequest* request, | 185 virtual void OnReadCompleted(URLRequest* request, |
186 int bytes_read) OVERRIDE; | 186 int bytes_read) override; |
187 | 187 |
188 private: | 188 private: |
189 static const int kBufferSize = 4096; | 189 static const int kBufferSize = 4096; |
190 | 190 |
191 virtual void OnResponseCompleted(URLRequest* request); | 191 virtual void OnResponseCompleted(URLRequest* request); |
192 | 192 |
193 // options for controlling behavior | 193 // options for controlling behavior |
194 bool cancel_in_rr_; | 194 bool cancel_in_rr_; |
195 bool cancel_in_rs_; | 195 bool cancel_in_rs_; |
196 bool cancel_in_rd_; | 196 bool cancel_in_rd_; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 279 |
280 // Last observed proxy in proxy header sent callback. | 280 // Last observed proxy in proxy header sent callback. |
281 HostPortPair last_observed_proxy() { | 281 HostPortPair last_observed_proxy() { |
282 return last_observed_proxy_; | 282 return last_observed_proxy_; |
283 } | 283 } |
284 | 284 |
285 protected: | 285 protected: |
286 // NetworkDelegate: | 286 // NetworkDelegate: |
287 virtual int OnBeforeURLRequest(URLRequest* request, | 287 virtual int OnBeforeURLRequest(URLRequest* request, |
288 const CompletionCallback& callback, | 288 const CompletionCallback& callback, |
289 GURL* new_url) OVERRIDE; | 289 GURL* new_url) override; |
290 virtual int OnBeforeSendHeaders(URLRequest* request, | 290 virtual int OnBeforeSendHeaders(URLRequest* request, |
291 const CompletionCallback& callback, | 291 const CompletionCallback& callback, |
292 HttpRequestHeaders* headers) OVERRIDE; | 292 HttpRequestHeaders* headers) override; |
293 virtual void OnBeforeSendProxyHeaders( | 293 virtual void OnBeforeSendProxyHeaders( |
294 net::URLRequest* request, | 294 net::URLRequest* request, |
295 const net::ProxyInfo& proxy_info, | 295 const net::ProxyInfo& proxy_info, |
296 net::HttpRequestHeaders* headers) OVERRIDE; | 296 net::HttpRequestHeaders* headers) override; |
297 virtual void OnSendHeaders(URLRequest* request, | 297 virtual void OnSendHeaders(URLRequest* request, |
298 const HttpRequestHeaders& headers) OVERRIDE; | 298 const HttpRequestHeaders& headers) override; |
299 virtual int OnHeadersReceived( | 299 virtual int OnHeadersReceived( |
300 URLRequest* request, | 300 URLRequest* request, |
301 const CompletionCallback& callback, | 301 const CompletionCallback& callback, |
302 const HttpResponseHeaders* original_response_headers, | 302 const HttpResponseHeaders* original_response_headers, |
303 scoped_refptr<HttpResponseHeaders>* override_response_headers, | 303 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
304 GURL* allowed_unsafe_redirect_url) OVERRIDE; | 304 GURL* allowed_unsafe_redirect_url) override; |
305 virtual void OnBeforeRedirect(URLRequest* request, | 305 virtual void OnBeforeRedirect(URLRequest* request, |
306 const GURL& new_location) OVERRIDE; | 306 const GURL& new_location) override; |
307 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; | 307 virtual void OnResponseStarted(URLRequest* request) override; |
308 virtual void OnRawBytesRead(const URLRequest& request, | 308 virtual void OnRawBytesRead(const URLRequest& request, |
309 int bytes_read) OVERRIDE; | 309 int bytes_read) override; |
310 virtual void OnCompleted(URLRequest* request, bool started) OVERRIDE; | 310 virtual void OnCompleted(URLRequest* request, bool started) override; |
311 virtual void OnURLRequestDestroyed(URLRequest* request) OVERRIDE; | 311 virtual void OnURLRequestDestroyed(URLRequest* request) override; |
312 virtual void OnPACScriptError(int line_number, | 312 virtual void OnPACScriptError(int line_number, |
313 const base::string16& error) OVERRIDE; | 313 const base::string16& error) override; |
314 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 314 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
315 URLRequest* request, | 315 URLRequest* request, |
316 const AuthChallengeInfo& auth_info, | 316 const AuthChallengeInfo& auth_info, |
317 const AuthCallback& callback, | 317 const AuthCallback& callback, |
318 AuthCredentials* credentials) OVERRIDE; | 318 AuthCredentials* credentials) override; |
319 virtual bool OnCanGetCookies(const URLRequest& request, | 319 virtual bool OnCanGetCookies(const URLRequest& request, |
320 const CookieList& cookie_list) OVERRIDE; | 320 const CookieList& cookie_list) override; |
321 virtual bool OnCanSetCookie(const URLRequest& request, | 321 virtual bool OnCanSetCookie(const URLRequest& request, |
322 const std::string& cookie_line, | 322 const std::string& cookie_line, |
323 CookieOptions* options) OVERRIDE; | 323 CookieOptions* options) override; |
324 virtual bool OnCanAccessFile(const URLRequest& request, | 324 virtual bool OnCanAccessFile(const URLRequest& request, |
325 const base::FilePath& path) const OVERRIDE; | 325 const base::FilePath& path) const override; |
326 virtual bool OnCanThrottleRequest( | 326 virtual bool OnCanThrottleRequest( |
327 const URLRequest& request) const OVERRIDE; | 327 const URLRequest& request) const override; |
328 virtual int OnBeforeSocketStreamConnect( | 328 virtual int OnBeforeSocketStreamConnect( |
329 SocketStream* stream, | 329 SocketStream* stream, |
330 const CompletionCallback& callback) OVERRIDE; | 330 const CompletionCallback& callback) override; |
331 virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 331 virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
332 const URLRequest& request, | 332 const URLRequest& request, |
333 const GURL& target_url, | 333 const GURL& target_url, |
334 const GURL& referrer_url) const OVERRIDE; | 334 const GURL& referrer_url) const override; |
335 | 335 |
336 void InitRequestStatesIfNew(int request_id); | 336 void InitRequestStatesIfNew(int request_id); |
337 | 337 |
338 GURL redirect_on_headers_received_url_; | 338 GURL redirect_on_headers_received_url_; |
339 // URL marked as safe for redirection at the onHeadersReceived stage. | 339 // URL marked as safe for redirection at the onHeadersReceived stage. |
340 GURL allowed_unsafe_redirect_url_; | 340 GURL allowed_unsafe_redirect_url_; |
341 | 341 |
342 int last_error_; | 342 int last_error_; |
343 int error_count_; | 343 int error_count_; |
344 int created_requests_; | 344 int created_requests_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 401 |
402 //----------------------------------------------------------------------------- | 402 //----------------------------------------------------------------------------- |
403 | 403 |
404 // A simple ProtocolHandler that returns a pre-built URLRequestJob only once. | 404 // A simple ProtocolHandler that returns a pre-built URLRequestJob only once. |
405 class TestJobInterceptor : public URLRequestJobFactory::ProtocolHandler { | 405 class TestJobInterceptor : public URLRequestJobFactory::ProtocolHandler { |
406 public: | 406 public: |
407 TestJobInterceptor(); | 407 TestJobInterceptor(); |
408 | 408 |
409 virtual URLRequestJob* MaybeCreateJob( | 409 virtual URLRequestJob* MaybeCreateJob( |
410 URLRequest* request, | 410 URLRequest* request, |
411 NetworkDelegate* network_delegate) const OVERRIDE; | 411 NetworkDelegate* network_delegate) const override; |
412 void set_main_intercept_job(URLRequestJob* job); | 412 void set_main_intercept_job(URLRequestJob* job); |
413 | 413 |
414 private: | 414 private: |
415 mutable URLRequestJob* main_intercept_job_; | 415 mutable URLRequestJob* main_intercept_job_; |
416 }; | 416 }; |
417 | 417 |
418 } // namespace net | 418 } // namespace net |
419 | 419 |
420 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ | 420 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ |
OLD | NEW |