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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 explicit TestURLRequestContextGetter( | 86 explicit TestURLRequestContextGetter( |
87 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner); | 87 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner); |
88 | 88 |
89 // Use to pass a pre-initialized |context|. | 89 // Use to pass a pre-initialized |context|. |
90 TestURLRequestContextGetter( | 90 TestURLRequestContextGetter( |
91 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, | 91 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, |
92 scoped_ptr<TestURLRequestContext> context); | 92 scoped_ptr<TestURLRequestContext> context); |
93 | 93 |
94 // URLRequestContextGetter implementation. | 94 // URLRequestContextGetter implementation. |
95 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE; | 95 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE; |
96 virtual scoped_refptr<base::SingleThreadTaskRunner> | 96 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
97 GetNetworkTaskRunner() const OVERRIDE; | 97 const OVERRIDE; |
98 | 98 |
99 protected: | 99 protected: |
100 virtual ~TestURLRequestContextGetter(); | 100 virtual ~TestURLRequestContextGetter(); |
101 | 101 |
102 private: | 102 private: |
103 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 103 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
104 scoped_ptr<TestURLRequestContext> context_; | 104 scoped_ptr<TestURLRequestContext> context_; |
105 }; | 105 }; |
106 | 106 |
107 //----------------------------------------------------------------------------- | 107 //----------------------------------------------------------------------------- |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return certificate_errors_are_fatal_; | 157 return certificate_errors_are_fatal_; |
158 } | 158 } |
159 bool auth_required_called() const { return auth_required_; } | 159 bool auth_required_called() const { return auth_required_; } |
160 bool have_full_request_headers() const { return have_full_request_headers_; } | 160 bool have_full_request_headers() const { return have_full_request_headers_; } |
161 const HttpRequestHeaders& full_request_headers() const { | 161 const HttpRequestHeaders& full_request_headers() const { |
162 return full_request_headers_; | 162 return full_request_headers_; |
163 } | 163 } |
164 void ClearFullRequestHeaders(); | 164 void ClearFullRequestHeaders(); |
165 | 165 |
166 // URLRequest::Delegate: | 166 // URLRequest::Delegate: |
167 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url, | 167 virtual void OnReceivedRedirect(URLRequest* request, |
| 168 const GURL& new_url, |
168 bool* defer_redirect) OVERRIDE; | 169 bool* defer_redirect) OVERRIDE; |
169 virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer) OVERRIDE; | 170 virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer) OVERRIDE; |
170 virtual void OnAuthRequired(URLRequest* request, | 171 virtual void OnAuthRequired(URLRequest* request, |
171 AuthChallengeInfo* auth_info) OVERRIDE; | 172 AuthChallengeInfo* auth_info) OVERRIDE; |
172 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. | 173 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. |
173 // (Unit tests use this as a post-condition.) But for policy, this method | 174 // (Unit tests use this as a post-condition.) But for policy, this method |
174 // consults |allow_certificate_errors_|. | 175 // consults |allow_certificate_errors_|. |
175 virtual void OnSSLCertificateError(URLRequest* request, | 176 virtual void OnSSLCertificateError(URLRequest* request, |
176 const SSLInfo& ssl_info, | 177 const SSLInfo& ssl_info, |
177 bool fatal) OVERRIDE; | 178 bool fatal) OVERRIDE; |
178 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; | 179 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; |
179 virtual void OnReadCompleted(URLRequest* request, | 180 virtual void OnReadCompleted(URLRequest* request, int bytes_read) OVERRIDE; |
180 int bytes_read) OVERRIDE; | |
181 | 181 |
182 private: | 182 private: |
183 static const int kBufferSize = 4096; | 183 static const int kBufferSize = 4096; |
184 | 184 |
185 virtual void OnResponseCompleted(URLRequest* request); | 185 virtual void OnResponseCompleted(URLRequest* request); |
186 | 186 |
187 // options for controlling behavior | 187 // options for controlling behavior |
188 bool cancel_in_rr_; | 188 bool cancel_in_rr_; |
189 bool cancel_in_rs_; | 189 bool cancel_in_rs_; |
190 bool cancel_in_rd_; | 190 bool cancel_in_rd_; |
(...skipping 21 matching lines...) Expand all Loading... |
212 // our read buffer | 212 // our read buffer |
213 scoped_refptr<IOBuffer> buf_; | 213 scoped_refptr<IOBuffer> buf_; |
214 }; | 214 }; |
215 | 215 |
216 //----------------------------------------------------------------------------- | 216 //----------------------------------------------------------------------------- |
217 | 217 |
218 class TestNetworkDelegate : public NetworkDelegate { | 218 class TestNetworkDelegate : public NetworkDelegate { |
219 public: | 219 public: |
220 enum Options { | 220 enum Options { |
221 NO_GET_COOKIES = 1 << 0, | 221 NO_GET_COOKIES = 1 << 0, |
222 NO_SET_COOKIE = 1 << 1, | 222 NO_SET_COOKIE = 1 << 1, |
223 }; | 223 }; |
224 | 224 |
225 TestNetworkDelegate(); | 225 TestNetworkDelegate(); |
226 virtual ~TestNetworkDelegate(); | 226 virtual ~TestNetworkDelegate(); |
227 | 227 |
228 // Writes the LoadTimingInfo during the most recent call to OnBeforeRedirect. | 228 // Writes the LoadTimingInfo during the most recent call to OnBeforeRedirect. |
229 bool GetLoadTimingInfoBeforeRedirect( | 229 bool GetLoadTimingInfoBeforeRedirect( |
230 LoadTimingInfo* load_timing_info_before_redirect) const; | 230 LoadTimingInfo* load_timing_info_before_redirect) const; |
231 | 231 |
232 // Same as GetLoadTimingInfoBeforeRedirect, except for calls to | 232 // Same as GetLoadTimingInfoBeforeRedirect, except for calls to |
233 // AuthRequiredResponse. | 233 // AuthRequiredResponse. |
234 bool GetLoadTimingInfoBeforeAuth( | 234 bool GetLoadTimingInfoBeforeAuth( |
235 LoadTimingInfo* load_timing_info_before_auth) const; | 235 LoadTimingInfo* load_timing_info_before_auth) const; |
236 | 236 |
237 // Will redirect once to the given URL when the next set of headers are | 237 // Will redirect once to the given URL when the next set of headers are |
238 // received. | 238 // received. |
239 void set_redirect_on_headers_received_url( | 239 void set_redirect_on_headers_received_url( |
240 GURL redirect_on_headers_received_url) { | 240 GURL redirect_on_headers_received_url) { |
241 redirect_on_headers_received_url_ = redirect_on_headers_received_url; | 241 redirect_on_headers_received_url_ = redirect_on_headers_received_url; |
242 } | 242 } |
243 | 243 |
244 void set_allowed_unsafe_redirect_url(GURL allowed_unsafe_redirect_url) { | 244 void set_allowed_unsafe_redirect_url(GURL allowed_unsafe_redirect_url) { |
245 allowed_unsafe_redirect_url_ = allowed_unsafe_redirect_url; | 245 allowed_unsafe_redirect_url_ = allowed_unsafe_redirect_url; |
246 } | 246 } |
247 | 247 |
248 void set_cookie_options(int o) {cookie_options_bit_mask_ = o; } | 248 void set_cookie_options(int o) { cookie_options_bit_mask_ = o; } |
249 | 249 |
250 int last_error() const { return last_error_; } | 250 int last_error() const { return last_error_; } |
251 int error_count() const { return error_count_; } | 251 int error_count() const { return error_count_; } |
252 int created_requests() const { return created_requests_; } | 252 int created_requests() const { return created_requests_; } |
253 int destroyed_requests() const { return destroyed_requests_; } | 253 int destroyed_requests() const { return destroyed_requests_; } |
254 int completed_requests() const { return completed_requests_; } | 254 int completed_requests() const { return completed_requests_; } |
255 int canceled_requests() const { return canceled_requests_; } | 255 int canceled_requests() const { return canceled_requests_; } |
256 int blocked_get_cookies_count() const { return blocked_get_cookies_count_; } | 256 int blocked_get_cookies_count() const { return blocked_get_cookies_count_; } |
257 int blocked_set_cookie_count() const { return blocked_set_cookie_count_; } | 257 int blocked_set_cookie_count() const { return blocked_set_cookie_count_; } |
258 int set_cookie_count() const { return set_cookie_count_; } | 258 int set_cookie_count() const { return set_cookie_count_; } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 const AuthChallengeInfo& auth_info, | 293 const AuthChallengeInfo& auth_info, |
294 const AuthCallback& callback, | 294 const AuthCallback& callback, |
295 AuthCredentials* credentials) OVERRIDE; | 295 AuthCredentials* credentials) OVERRIDE; |
296 virtual bool OnCanGetCookies(const URLRequest& request, | 296 virtual bool OnCanGetCookies(const URLRequest& request, |
297 const CookieList& cookie_list) OVERRIDE; | 297 const CookieList& cookie_list) OVERRIDE; |
298 virtual bool OnCanSetCookie(const URLRequest& request, | 298 virtual bool OnCanSetCookie(const URLRequest& request, |
299 const std::string& cookie_line, | 299 const std::string& cookie_line, |
300 CookieOptions* options) OVERRIDE; | 300 CookieOptions* options) OVERRIDE; |
301 virtual bool OnCanAccessFile(const URLRequest& request, | 301 virtual bool OnCanAccessFile(const URLRequest& request, |
302 const base::FilePath& path) const OVERRIDE; | 302 const base::FilePath& path) const OVERRIDE; |
303 virtual bool OnCanThrottleRequest( | 303 virtual bool OnCanThrottleRequest(const URLRequest& request) const OVERRIDE; |
304 const URLRequest& request) const OVERRIDE; | |
305 virtual int OnBeforeSocketStreamConnect( | 304 virtual int OnBeforeSocketStreamConnect( |
306 SocketStream* stream, | 305 SocketStream* stream, |
307 const CompletionCallback& callback) OVERRIDE; | 306 const CompletionCallback& callback) OVERRIDE; |
308 | 307 |
309 void InitRequestStatesIfNew(int request_id); | 308 void InitRequestStatesIfNew(int request_id); |
310 | 309 |
311 GURL redirect_on_headers_received_url_; | 310 GURL redirect_on_headers_received_url_; |
312 // URL marked as safe for redirection at the onHeadersReceived stage. | 311 // URL marked as safe for redirection at the onHeadersReceived stage. |
313 GURL allowed_unsafe_redirect_url_; | 312 GURL allowed_unsafe_redirect_url_; |
314 | 313 |
(...skipping 17 matching lines...) Expand all Loading... |
332 // A log that records for each request id (key) the order in which On... | 331 // A log that records for each request id (key) the order in which On... |
333 // functions were called. | 332 // functions were called. |
334 std::map<int, std::string> event_order_; | 333 std::map<int, std::string> event_order_; |
335 | 334 |
336 LoadTimingInfo load_timing_info_before_redirect_; | 335 LoadTimingInfo load_timing_info_before_redirect_; |
337 bool has_load_timing_info_before_redirect_; | 336 bool has_load_timing_info_before_redirect_; |
338 | 337 |
339 LoadTimingInfo load_timing_info_before_auth_; | 338 LoadTimingInfo load_timing_info_before_auth_; |
340 bool has_load_timing_info_before_auth_; | 339 bool has_load_timing_info_before_auth_; |
341 | 340 |
342 bool can_access_files_; // true by default | 341 bool can_access_files_; // true by default |
343 bool can_throttle_requests_; // true by default | 342 bool can_throttle_requests_; // true by default |
344 }; | 343 }; |
345 | 344 |
346 // Overrides the host used by the LocalHttpTestServer in | 345 // Overrides the host used by the LocalHttpTestServer in |
347 // url_request_unittest.cc . This is used by the chrome_frame_net_tests due to | 346 // url_request_unittest.cc . This is used by the chrome_frame_net_tests due to |
348 // a mysterious bug when tests execute over the loopback adapter. See | 347 // a mysterious bug when tests execute over the loopback adapter. See |
349 // http://crbug.com/114369 . | 348 // http://crbug.com/114369 . |
350 class ScopedCustomUrlRequestTestHttpHost { | 349 class ScopedCustomUrlRequestTestHttpHost { |
351 public: | 350 public: |
352 // Sets the host name to be used. The previous hostname will be stored and | 351 // Sets the host name to be used. The previous hostname will be stored and |
(...skipping 27 matching lines...) Expand all Loading... |
380 NetworkDelegate* network_delegate) const OVERRIDE; | 379 NetworkDelegate* network_delegate) const OVERRIDE; |
381 void set_main_intercept_job(URLRequestJob* job); | 380 void set_main_intercept_job(URLRequestJob* job); |
382 | 381 |
383 private: | 382 private: |
384 mutable URLRequestJob* main_intercept_job_; | 383 mutable URLRequestJob* main_intercept_job_; |
385 }; | 384 }; |
386 | 385 |
387 } // namespace net | 386 } // namespace net |
388 | 387 |
389 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ | 388 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ |
OLD | NEW |