blob: 9536193fa53b17c52301d699b1cab145c0f92605 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
3// found in the LICENSE file.
4
5#ifndef NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_
6#define NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_
7
8#include <stdlib.h>
9
10#include <map>
11#include <string>
12
13#include "base/basictypes.h"
14#include "base/compiler_specific.h"
15#include "base/memory/ref_counted.h"
Torne (Richard Coles)46d4c2b2014-06-09 12:00:27 +010016#include "base/memory/scoped_ptr.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010017#include "base/message_loop/message_loop_proxy.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000018#include "base/path_service.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010019#include "base/strings/string16.h"
20#include "base/strings/string_util.h"
21#include "base/strings/utf_string_conversions.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010022#include "base/time/time.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023#include "net/base/io_buffer.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000024#include "net/base/load_timing_info.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000025#include "net/base/net_errors.h"
26#include "net/base/network_delegate.h"
Torne (Richard Coles)0f1bc082013-11-06 12:27:47 +000027#include "net/base/request_priority.h"
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010028#include "net/base/sdch_manager.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010029#include "net/cert/cert_verifier.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030#include "net/cookies/cookie_monster.h"
31#include "net/disk_cache/disk_cache.h"
32#include "net/ftp/ftp_network_layer.h"
33#include "net/http/http_auth_handler_factory.h"
34#include "net/http/http_cache.h"
35#include "net/http/http_network_layer.h"
Torne (Richard Coles)46d4c2b2014-06-09 12:00:27 +010036#include "net/http/http_network_session.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010037#include "net/http/http_request_headers.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038#include "net/proxy/proxy_service.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000039#include "net/ssl/ssl_config_service_defaults.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000040#include "net/url_request/url_request.h"
41#include "net/url_request/url_request_context.h"
42#include "net/url_request/url_request_context_getter.h"
43#include "net/url_request/url_request_context_storage.h"
44#include "net/url_request/url_request_job_factory.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010045#include "url/url_util.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000046
47using base::TimeDelta;
48
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000049namespace net {
50
Torne (Richard Coles)58218062012-11-14 11:43:16 +000051//-----------------------------------------------------------------------------
52
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000053class TestURLRequestContext : public URLRequestContext {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000054 public:
55 TestURLRequestContext();
56 // Default constructor like TestURLRequestContext() but does not call
57 // Init() in case |delay_initialization| is true. This allows modifying the
58 // URLRequestContext before it is constructed completely. If
59 // |delay_initialization| is true, Init() needs be be called manually.
60 explicit TestURLRequestContext(bool delay_initialization);
61 virtual ~TestURLRequestContext();
62
63 void Init();
64
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000065 ClientSocketFactory* client_socket_factory() {
66 return client_socket_factory_;
67 }
68 void set_client_socket_factory(ClientSocketFactory* factory) {
69 client_socket_factory_ = factory;
70 }
71
Torne (Richard Coles)46d4c2b2014-06-09 12:00:27 +010072 void set_http_network_session_params(
73 const HttpNetworkSession::Params& params) {
74 }
75
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010076 void SetSdchManager(scoped_ptr<SdchManager> sdch_manager) {
77 context_storage_.set_sdch_manager(sdch_manager.Pass());
78 }
79
Torne (Richard Coles)58218062012-11-14 11:43:16 +000080 private:
81 bool initialized_;
82
Torne (Richard Coles)46d4c2b2014-06-09 12:00:27 +010083 // Optional parameters to override default values. Note that values that
84 // point to other objects the TestURLRequestContext creates will be
85 // overwritten.
86 scoped_ptr<HttpNetworkSession::Params> http_network_session_params_;
87
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000088 // Not owned:
89 ClientSocketFactory* client_socket_factory_;
90
Torne (Richard Coles)58218062012-11-14 11:43:16 +000091 protected:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000092 URLRequestContextStorage context_storage_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000093};
94
95//-----------------------------------------------------------------------------
96
97// Used to return a dummy context, which lives on the message loop
98// given in the constructor.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000099class TestURLRequestContextGetter : public URLRequestContextGetter {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000100 public:
101 // |network_task_runner| must not be NULL.
102 explicit TestURLRequestContextGetter(
103 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner);
104
105 // Use to pass a pre-initialized |context|.
106 TestURLRequestContextGetter(
107 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner,
108 scoped_ptr<TestURLRequestContext> context);
109
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000110 // URLRequestContextGetter implementation.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000111 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE;
112 virtual scoped_refptr<base::SingleThreadTaskRunner>
113 GetNetworkTaskRunner() const OVERRIDE;
114
115 protected:
116 virtual ~TestURLRequestContextGetter();
117
118 private:
119 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
120 scoped_ptr<TestURLRequestContext> context_;
121};
122
123//-----------------------------------------------------------------------------
124
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000125class TestURLRequest : public URLRequest {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000126 public:
Torne (Richard Coles)0f1bc082013-11-06 12:27:47 +0000127 TestURLRequest(const GURL& url,
128 RequestPriority priority,
129 Delegate* delegate,
130 TestURLRequestContext* context);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000131 virtual ~TestURLRequest();
132};
133
134//-----------------------------------------------------------------------------
135
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000136class TestDelegate : public URLRequest::Delegate {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000137 public:
138 TestDelegate();
139 virtual ~TestDelegate();
140
141 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; }
142 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; }
143 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; }
144 void set_cancel_in_received_data_pending(bool val) {
145 cancel_in_rd_pending_ = val;
146 }
147 void set_quit_on_complete(bool val) { quit_on_complete_ = val; }
148 void set_quit_on_redirect(bool val) { quit_on_redirect_ = val; }
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000149 void set_quit_on_network_start(bool val) {
150 quit_on_before_network_start_ = val;
151 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000152 void set_allow_certificate_errors(bool val) {
153 allow_certificate_errors_ = val;
154 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000155 void set_credentials(const AuthCredentials& credentials) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000156 credentials_ = credentials;
157 }
158
159 // query state
160 const std::string& data_received() const { return data_received_; }
161 int bytes_received() const { return static_cast<int>(data_received_.size()); }
162 int response_started_count() const { return response_started_count_; }
163 int received_redirect_count() const { return received_redirect_count_; }
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000164 int received_before_network_start_count() const {
165 return received_before_network_start_count_;
166 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000167 bool received_data_before_response() const {
168 return received_data_before_response_;
169 }
170 bool request_failed() const { return request_failed_; }
171 bool have_certificate_errors() const { return have_certificate_errors_; }
172 bool certificate_errors_are_fatal() const {
173 return certificate_errors_are_fatal_;
174 }
175 bool auth_required_called() const { return auth_required_; }
Ben Murdocheb525c52013-07-10 11:40:50 +0100176 bool have_full_request_headers() const { return have_full_request_headers_; }
177 const HttpRequestHeaders& full_request_headers() const {
178 return full_request_headers_;
179 }
180 void ClearFullRequestHeaders();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000181
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000182 // URLRequest::Delegate:
Torne (Richard Coles)6e8cce62014-08-19 13:00:08 +0100183 virtual void OnReceivedRedirect(URLRequest* request,
184 const RedirectInfo& redirect_info,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000185 bool* defer_redirect) OVERRIDE;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000186 virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000187 virtual void OnAuthRequired(URLRequest* request,
188 AuthChallengeInfo* auth_info) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000189 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true.
190 // (Unit tests use this as a post-condition.) But for policy, this method
191 // consults |allow_certificate_errors_|.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000192 virtual void OnSSLCertificateError(URLRequest* request,
193 const SSLInfo& ssl_info,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000194 bool fatal) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000195 virtual void OnResponseStarted(URLRequest* request) OVERRIDE;
196 virtual void OnReadCompleted(URLRequest* request,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000197 int bytes_read) OVERRIDE;
198
199 private:
200 static const int kBufferSize = 4096;
201
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000202 virtual void OnResponseCompleted(URLRequest* request);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000203
204 // options for controlling behavior
205 bool cancel_in_rr_;
206 bool cancel_in_rs_;
207 bool cancel_in_rd_;
208 bool cancel_in_rd_pending_;
209 bool quit_on_complete_;
210 bool quit_on_redirect_;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000211 bool quit_on_before_network_start_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000212 bool allow_certificate_errors_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000213 AuthCredentials credentials_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000214
215 // tracks status of callbacks
216 int response_started_count_;
217 int received_bytes_count_;
218 int received_redirect_count_;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000219 int received_before_network_start_count_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000220 bool received_data_before_response_;
221 bool request_failed_;
222 bool have_certificate_errors_;
223 bool certificate_errors_are_fatal_;
224 bool auth_required_;
225 std::string data_received_;
Ben Murdocheb525c52013-07-10 11:40:50 +0100226 bool have_full_request_headers_;
227 HttpRequestHeaders full_request_headers_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000228
229 // our read buffer
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000230 scoped_refptr<IOBuffer> buf_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000231};
232
233//-----------------------------------------------------------------------------
234
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000235class TestNetworkDelegate : public NetworkDelegate {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000236 public:
237 enum Options {
238 NO_GET_COOKIES = 1 << 0,
239 NO_SET_COOKIE = 1 << 1,
240 };
241
242 TestNetworkDelegate();
243 virtual ~TestNetworkDelegate();
244
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000245 // Writes the LoadTimingInfo during the most recent call to OnBeforeRedirect.
246 bool GetLoadTimingInfoBeforeRedirect(
247 LoadTimingInfo* load_timing_info_before_redirect) const;
248
249 // Same as GetLoadTimingInfoBeforeRedirect, except for calls to
250 // AuthRequiredResponse.
251 bool GetLoadTimingInfoBeforeAuth(
252 LoadTimingInfo* load_timing_info_before_auth) const;
253
Ben Murdocheffb81e2014-03-31 11:51:25 +0100254 // Will redirect once to the given URL when the next set of headers are
255 // received.
256 void set_redirect_on_headers_received_url(
257 GURL redirect_on_headers_received_url) {
258 redirect_on_headers_received_url_ = redirect_on_headers_received_url;
259 }
260
261 void set_allowed_unsafe_redirect_url(GURL allowed_unsafe_redirect_url) {
262 allowed_unsafe_redirect_url_ = allowed_unsafe_redirect_url;
263 }
264
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000265 void set_cookie_options(int o) {cookie_options_bit_mask_ = o; }
266
267 int last_error() const { return last_error_; }
268 int error_count() const { return error_count_; }
269 int created_requests() const { return created_requests_; }
270 int destroyed_requests() const { return destroyed_requests_; }
271 int completed_requests() const { return completed_requests_; }
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000272 int canceled_requests() const { return canceled_requests_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000273 int blocked_get_cookies_count() const { return blocked_get_cookies_count_; }
274 int blocked_set_cookie_count() const { return blocked_set_cookie_count_; }
275 int set_cookie_count() const { return set_cookie_count_; }
276
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000277 void set_can_access_files(bool val) { can_access_files_ = val; }
278 bool can_access_files() const { return can_access_files_; }
279
280 void set_can_throttle_requests(bool val) { can_throttle_requests_ = val; }
281 bool can_throttle_requests() const { return can_throttle_requests_; }
282
Ben Murdoch116680a2014-07-20 18:25:52 -0700283 int observed_before_proxy_headers_sent_callbacks() const {
284 return observed_before_proxy_headers_sent_callbacks_;
285 }
286
287 // Last observed proxy in proxy header sent callback.
288 HostPortPair last_observed_proxy() {
289 return last_observed_proxy_;
290 }
291
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000292 protected:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000293 // NetworkDelegate:
294 virtual int OnBeforeURLRequest(URLRequest* request,
295 const CompletionCallback& callback,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000296 GURL* new_url) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000297 virtual int OnBeforeSendHeaders(URLRequest* request,
298 const CompletionCallback& callback,
299 HttpRequestHeaders* headers) OVERRIDE;
Ben Murdoch116680a2014-07-20 18:25:52 -0700300 virtual void OnBeforeSendProxyHeaders(
301 net::URLRequest* request,
302 const net::ProxyInfo& proxy_info,
303 net::HttpRequestHeaders* headers) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000304 virtual void OnSendHeaders(URLRequest* request,
305 const HttpRequestHeaders& headers) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000306 virtual int OnHeadersReceived(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000307 URLRequest* request,
308 const CompletionCallback& callback,
309 const HttpResponseHeaders* original_response_headers,
Ben Murdocheffb81e2014-03-31 11:51:25 +0100310 scoped_refptr<HttpResponseHeaders>* override_response_headers,
311 GURL* allowed_unsafe_redirect_url) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000312 virtual void OnBeforeRedirect(URLRequest* request,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000313 const GURL& new_location) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000314 virtual void OnResponseStarted(URLRequest* request) OVERRIDE;
315 virtual void OnRawBytesRead(const URLRequest& request,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000316 int bytes_read) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000317 virtual void OnCompleted(URLRequest* request, bool started) OVERRIDE;
318 virtual void OnURLRequestDestroyed(URLRequest* request) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000319 virtual void OnPACScriptError(int line_number,
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100320 const base::string16& error) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000321 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired(
322 URLRequest* request,
323 const AuthChallengeInfo& auth_info,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000324 const AuthCallback& callback,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000325 AuthCredentials* credentials) OVERRIDE;
326 virtual bool OnCanGetCookies(const URLRequest& request,
327 const CookieList& cookie_list) OVERRIDE;
328 virtual bool OnCanSetCookie(const URLRequest& request,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000329 const std::string& cookie_line,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000330 CookieOptions* options) OVERRIDE;
331 virtual bool OnCanAccessFile(const URLRequest& request,
332 const base::FilePath& path) const OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000333 virtual bool OnCanThrottleRequest(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000334 const URLRequest& request) const OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000335 virtual int OnBeforeSocketStreamConnect(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000336 SocketStream* stream,
337 const CompletionCallback& callback) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000338
339 void InitRequestStatesIfNew(int request_id);
340
Ben Murdocheffb81e2014-03-31 11:51:25 +0100341 GURL redirect_on_headers_received_url_;
342 // URL marked as safe for redirection at the onHeadersReceived stage.
343 GURL allowed_unsafe_redirect_url_;
344
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000345 int last_error_;
346 int error_count_;
347 int created_requests_;
348 int destroyed_requests_;
349 int completed_requests_;
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000350 int canceled_requests_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000351 int cookie_options_bit_mask_;
352 int blocked_get_cookies_count_;
353 int blocked_set_cookie_count_;
354 int set_cookie_count_;
Ben Murdoch116680a2014-07-20 18:25:52 -0700355 int observed_before_proxy_headers_sent_callbacks_;
356 // Last observed proxy in before proxy header sent callback.
357 HostPortPair last_observed_proxy_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000358
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000359 // NetworkDelegate callbacks happen in a particular order (e.g.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000360 // OnBeforeURLRequest is always called before OnBeforeSendHeaders).
361 // This bit-set indicates for each request id (key) what events may be sent
362 // next.
363 std::map<int, int> next_states_;
364
365 // A log that records for each request id (key) the order in which On...
366 // functions were called.
367 std::map<int, std::string> event_order_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000368
369 LoadTimingInfo load_timing_info_before_redirect_;
370 bool has_load_timing_info_before_redirect_;
371
372 LoadTimingInfo load_timing_info_before_auth_;
373 bool has_load_timing_info_before_auth_;
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000374
375 bool can_access_files_; // true by default
376 bool can_throttle_requests_; // true by default
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000377};
378
379// Overrides the host used by the LocalHttpTestServer in
380// url_request_unittest.cc . This is used by the chrome_frame_net_tests due to
381// a mysterious bug when tests execute over the loopback adapter. See
382// http://crbug.com/114369 .
383class ScopedCustomUrlRequestTestHttpHost {
384 public:
385 // Sets the host name to be used. The previous hostname will be stored and
386 // restored upon destruction. Note that if the lifetimes of two or more
387 // instances of this class overlap, they must be strictly nested.
388 explicit ScopedCustomUrlRequestTestHttpHost(const std::string& new_value);
389
390 ~ScopedCustomUrlRequestTestHttpHost();
391
392 // Returns the current value to be used by HTTP tests in
393 // url_request_unittest.cc .
394 static const std::string& value();
395
396 private:
397 static std::string value_;
398 const std::string old_value_;
399 const std::string new_value_;
400
401 DISALLOW_COPY_AND_ASSIGN(ScopedCustomUrlRequestTestHttpHost);
402};
403
404//-----------------------------------------------------------------------------
405
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000406// A simple ProtocolHandler that returns a pre-built URLRequestJob only once.
407class TestJobInterceptor : public URLRequestJobFactory::ProtocolHandler {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000408 public:
409 TestJobInterceptor();
410
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000411 virtual URLRequestJob* MaybeCreateJob(
412 URLRequest* request,
413 NetworkDelegate* network_delegate) const OVERRIDE;
414 void set_main_intercept_job(URLRequestJob* job);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000415
416 private:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000417 mutable URLRequestJob* main_intercept_job_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000418};
419
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000420} // namespace net
421
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000422#endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_