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 <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 bool have_certificate_errors() const { return have_certificate_errors_; } | 173 bool have_certificate_errors() const { return have_certificate_errors_; } |
174 bool certificate_errors_are_fatal() const { | 174 bool certificate_errors_are_fatal() const { |
175 return certificate_errors_are_fatal_; | 175 return certificate_errors_are_fatal_; |
176 } | 176 } |
177 bool auth_required_called() const { return auth_required_; } | 177 bool auth_required_called() const { return auth_required_; } |
178 bool have_full_request_headers() const { return have_full_request_headers_; } | 178 bool have_full_request_headers() const { return have_full_request_headers_; } |
179 const HttpRequestHeaders& full_request_headers() const { | 179 const HttpRequestHeaders& full_request_headers() const { |
180 return full_request_headers_; | 180 return full_request_headers_; |
181 } | 181 } |
182 void ClearFullRequestHeaders(); | 182 void ClearFullRequestHeaders(); |
| 183 int request_status() const { return request_status_; } |
183 | 184 |
184 // URLRequest::Delegate: | 185 // URLRequest::Delegate: |
185 void OnReceivedRedirect(URLRequest* request, | 186 void OnReceivedRedirect(URLRequest* request, |
186 const RedirectInfo& redirect_info, | 187 const RedirectInfo& redirect_info, |
187 bool* defer_redirect) override; | 188 bool* defer_redirect) override; |
188 void OnAuthRequired(URLRequest* request, | 189 void OnAuthRequired(URLRequest* request, |
189 AuthChallengeInfo* auth_info) override; | 190 AuthChallengeInfo* auth_info) override; |
190 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. | 191 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. |
191 // (Unit tests use this as a post-condition.) But for policy, this method | 192 // (Unit tests use this as a post-condition.) But for policy, this method |
192 // consults |allow_certificate_errors_|. | 193 // consults |allow_certificate_errors_|. |
193 void OnSSLCertificateError(URLRequest* request, | 194 void OnSSLCertificateError(URLRequest* request, |
194 const SSLInfo& ssl_info, | 195 const SSLInfo& ssl_info, |
195 bool fatal) override; | 196 bool fatal) override; |
196 void OnResponseStarted(URLRequest* request) override; | 197 void OnResponseStarted(URLRequest* request, int net_error) override; |
197 void OnReadCompleted(URLRequest* request, int bytes_read) override; | 198 void OnReadCompleted(URLRequest* request, int bytes_read) override; |
198 | 199 |
199 private: | 200 private: |
200 static const int kBufferSize = 4096; | 201 static const int kBufferSize = 4096; |
201 | 202 |
202 virtual void OnResponseCompleted(URLRequest* request); | 203 virtual void OnResponseCompleted(URLRequest* request); |
203 | 204 |
204 // options for controlling behavior | 205 // options for controlling behavior |
205 bool cancel_in_rr_; | 206 bool cancel_in_rr_; |
206 bool cancel_in_rs_; | 207 bool cancel_in_rs_; |
(...skipping 11 matching lines...) Expand all Loading... |
218 int received_redirect_count_; | 219 int received_redirect_count_; |
219 bool received_data_before_response_; | 220 bool received_data_before_response_; |
220 bool request_failed_; | 221 bool request_failed_; |
221 bool have_certificate_errors_; | 222 bool have_certificate_errors_; |
222 bool certificate_errors_are_fatal_; | 223 bool certificate_errors_are_fatal_; |
223 bool auth_required_; | 224 bool auth_required_; |
224 std::string data_received_; | 225 std::string data_received_; |
225 bool have_full_request_headers_; | 226 bool have_full_request_headers_; |
226 HttpRequestHeaders full_request_headers_; | 227 HttpRequestHeaders full_request_headers_; |
227 | 228 |
| 229 // tracks status of request |
| 230 int request_status_; |
| 231 |
228 // our read buffer | 232 // our read buffer |
229 scoped_refptr<IOBuffer> buf_; | 233 scoped_refptr<IOBuffer> buf_; |
230 }; | 234 }; |
231 | 235 |
232 //----------------------------------------------------------------------------- | 236 //----------------------------------------------------------------------------- |
233 | 237 |
234 class TestNetworkDelegate : public NetworkDelegateImpl { | 238 class TestNetworkDelegate : public NetworkDelegateImpl { |
235 public: | 239 public: |
236 enum Options { | 240 enum Options { |
237 NO_GET_COOKIES = 1 << 0, | 241 NO_GET_COOKIES = 1 << 0, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 HttpRequestHeaders* headers) override; | 324 HttpRequestHeaders* headers) override; |
321 void OnStartTransaction(URLRequest* request, | 325 void OnStartTransaction(URLRequest* request, |
322 const HttpRequestHeaders& headers) override; | 326 const HttpRequestHeaders& headers) override; |
323 int OnHeadersReceived( | 327 int OnHeadersReceived( |
324 URLRequest* request, | 328 URLRequest* request, |
325 const CompletionCallback& callback, | 329 const CompletionCallback& callback, |
326 const HttpResponseHeaders* original_response_headers, | 330 const HttpResponseHeaders* original_response_headers, |
327 scoped_refptr<HttpResponseHeaders>* override_response_headers, | 331 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
328 GURL* allowed_unsafe_redirect_url) override; | 332 GURL* allowed_unsafe_redirect_url) override; |
329 void OnBeforeRedirect(URLRequest* request, const GURL& new_location) override; | 333 void OnBeforeRedirect(URLRequest* request, const GURL& new_location) override; |
330 void OnResponseStarted(URLRequest* request) override; | 334 void OnResponseStarted(URLRequest* request, int net_error) override; |
331 void OnNetworkBytesReceived(URLRequest* request, | 335 void OnNetworkBytesReceived(URLRequest* request, |
332 int64_t bytes_received) override; | 336 int64_t bytes_received) override; |
333 void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) override; | 337 void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) override; |
334 void OnCompleted(URLRequest* request, bool started) override; | 338 void OnCompleted(URLRequest* request, bool started, int net_error) override; |
335 void OnURLRequestDestroyed(URLRequest* request) override; | 339 void OnURLRequestDestroyed(URLRequest* request) override; |
336 void OnPACScriptError(int line_number, const base::string16& error) override; | 340 void OnPACScriptError(int line_number, const base::string16& error) override; |
337 NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 341 NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
338 URLRequest* request, | 342 URLRequest* request, |
339 const AuthChallengeInfo& auth_info, | 343 const AuthChallengeInfo& auth_info, |
340 const AuthCallback& callback, | 344 const AuthCallback& callback, |
341 AuthCredentials* credentials) override; | 345 AuthCredentials* credentials) override; |
342 bool OnCanGetCookies(const URLRequest& request, | 346 bool OnCanGetCookies(const URLRequest& request, |
343 const CookieList& cookie_list) override; | 347 const CookieList& cookie_list) override; |
344 bool OnCanSetCookie(const URLRequest& request, | 348 bool OnCanSetCookie(const URLRequest& request, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 NetworkDelegate* network_delegate) const override; | 416 NetworkDelegate* network_delegate) const override; |
413 void set_main_intercept_job(std::unique_ptr<URLRequestJob> job); | 417 void set_main_intercept_job(std::unique_ptr<URLRequestJob> job); |
414 | 418 |
415 private: | 419 private: |
416 mutable std::unique_ptr<URLRequestJob> main_intercept_job_; | 420 mutable std::unique_ptr<URLRequestJob> main_intercept_job_; |
417 }; | 421 }; |
418 | 422 |
419 } // namespace net | 423 } // namespace net |
420 | 424 |
421 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ | 425 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ |
OLD | NEW |