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; |
| 197 void OnResponseStarted(URLRequest* request, int net_error) override; |
| 198 // Deprecated. |
| 199 // TODO(maksims): Remove this. |
196 void OnResponseStarted(URLRequest* request) override; | 200 void OnResponseStarted(URLRequest* request) override; |
197 void OnReadCompleted(URLRequest* request, int bytes_read) override; | 201 void OnReadCompleted(URLRequest* request, int bytes_read) override; |
198 | 202 |
199 private: | 203 private: |
200 static const int kBufferSize = 4096; | 204 static const int kBufferSize = 4096; |
201 | 205 |
202 virtual void OnResponseCompleted(URLRequest* request); | 206 virtual void OnResponseCompleted(URLRequest* request); |
203 | 207 |
204 // options for controlling behavior | 208 // options for controlling behavior |
205 bool cancel_in_rr_; | 209 bool cancel_in_rr_; |
(...skipping 12 matching lines...) Expand all Loading... |
218 int received_redirect_count_; | 222 int received_redirect_count_; |
219 bool received_data_before_response_; | 223 bool received_data_before_response_; |
220 bool request_failed_; | 224 bool request_failed_; |
221 bool have_certificate_errors_; | 225 bool have_certificate_errors_; |
222 bool certificate_errors_are_fatal_; | 226 bool certificate_errors_are_fatal_; |
223 bool auth_required_; | 227 bool auth_required_; |
224 std::string data_received_; | 228 std::string data_received_; |
225 bool have_full_request_headers_; | 229 bool have_full_request_headers_; |
226 HttpRequestHeaders full_request_headers_; | 230 HttpRequestHeaders full_request_headers_; |
227 | 231 |
| 232 // tracks status of request |
| 233 int request_status_; |
| 234 |
228 // our read buffer | 235 // our read buffer |
229 scoped_refptr<IOBuffer> buf_; | 236 scoped_refptr<IOBuffer> buf_; |
230 }; | 237 }; |
231 | 238 |
232 //----------------------------------------------------------------------------- | 239 //----------------------------------------------------------------------------- |
233 | 240 |
234 class TestNetworkDelegate : public NetworkDelegateImpl { | 241 class TestNetworkDelegate : public NetworkDelegateImpl { |
235 public: | 242 public: |
236 enum Options { | 243 enum Options { |
237 NO_GET_COOKIES = 1 << 0, | 244 NO_GET_COOKIES = 1 << 0, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 HttpRequestHeaders* headers) override; | 327 HttpRequestHeaders* headers) override; |
321 void OnStartTransaction(URLRequest* request, | 328 void OnStartTransaction(URLRequest* request, |
322 const HttpRequestHeaders& headers) override; | 329 const HttpRequestHeaders& headers) override; |
323 int OnHeadersReceived( | 330 int OnHeadersReceived( |
324 URLRequest* request, | 331 URLRequest* request, |
325 const CompletionCallback& callback, | 332 const CompletionCallback& callback, |
326 const HttpResponseHeaders* original_response_headers, | 333 const HttpResponseHeaders* original_response_headers, |
327 scoped_refptr<HttpResponseHeaders>* override_response_headers, | 334 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
328 GURL* allowed_unsafe_redirect_url) override; | 335 GURL* allowed_unsafe_redirect_url) override; |
329 void OnBeforeRedirect(URLRequest* request, const GURL& new_location) override; | 336 void OnBeforeRedirect(URLRequest* request, const GURL& new_location) override; |
| 337 void OnResponseStarted(URLRequest* request, int net_error) override; |
| 338 // Deprecated. |
330 void OnResponseStarted(URLRequest* request) override; | 339 void OnResponseStarted(URLRequest* request) override; |
331 void OnNetworkBytesReceived(URLRequest* request, | 340 void OnNetworkBytesReceived(URLRequest* request, |
332 int64_t bytes_received) override; | 341 int64_t bytes_received) override; |
333 void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) override; | 342 void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) override; |
| 343 void OnCompleted(URLRequest* request, bool started, int net_error) override; |
| 344 // Deprecated. |
| 345 // TODO(maksims): Remove this. |
334 void OnCompleted(URLRequest* request, bool started) override; | 346 void OnCompleted(URLRequest* request, bool started) override; |
335 void OnURLRequestDestroyed(URLRequest* request) override; | 347 void OnURLRequestDestroyed(URLRequest* request) override; |
336 void OnPACScriptError(int line_number, const base::string16& error) override; | 348 void OnPACScriptError(int line_number, const base::string16& error) override; |
337 NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 349 NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
338 URLRequest* request, | 350 URLRequest* request, |
339 const AuthChallengeInfo& auth_info, | 351 const AuthChallengeInfo& auth_info, |
340 const AuthCallback& callback, | 352 const AuthCallback& callback, |
341 AuthCredentials* credentials) override; | 353 AuthCredentials* credentials) override; |
342 bool OnCanGetCookies(const URLRequest& request, | 354 bool OnCanGetCookies(const URLRequest& request, |
343 const CookieList& cookie_list) override; | 355 const CookieList& cookie_list) override; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 NetworkDelegate* network_delegate) const override; | 424 NetworkDelegate* network_delegate) const override; |
413 void set_main_intercept_job(std::unique_ptr<URLRequestJob> job); | 425 void set_main_intercept_job(std::unique_ptr<URLRequestJob> job); |
414 | 426 |
415 private: | 427 private: |
416 mutable std::unique_ptr<URLRequestJob> main_intercept_job_; | 428 mutable std::unique_ptr<URLRequestJob> main_intercept_job_; |
417 }; | 429 }; |
418 | 430 |
419 } // namespace net | 431 } // namespace net |
420 | 432 |
421 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ | 433 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ |
OLD | NEW |