| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // process jobs on this queue, use ProcessOnePendingMessage, which will process | 30 // process jobs on this queue, use ProcessOnePendingMessage, which will process |
| 31 // one step of the next job. If the job is incomplete, it will be added to the | 31 // one step of the next job. If the job is incomplete, it will be added to the |
| 32 // end of the queue. | 32 // end of the queue. |
| 33 // | 33 // |
| 34 // Optionally, you can also construct test jobs that advance automatically | 34 // Optionally, you can also construct test jobs that advance automatically |
| 35 // without having to call ProcessOnePendingMessage. | 35 // without having to call ProcessOnePendingMessage. |
| 36 class URLRequestTestJob : public net::URLRequestJob { | 36 class URLRequestTestJob : public net::URLRequestJob { |
| 37 public: | 37 public: |
| 38 // Constructs a job to return one of the canned responses depending on the | 38 // Constructs a job to return one of the canned responses depending on the |
| 39 // request url, with auto advance disabled. | 39 // request url, with auto advance disabled. |
| 40 explicit URLRequestTestJob(URLRequest* request); | 40 explicit URLRequestTestJob(net::URLRequest* request); |
| 41 | 41 |
| 42 // Constructs a job to return one of the canned responses depending on the | 42 // Constructs a job to return one of the canned responses depending on the |
| 43 // request url, optionally with auto advance enabled. | 43 // request url, optionally with auto advance enabled. |
| 44 explicit URLRequestTestJob(URLRequest* request, bool auto_advance); | 44 explicit URLRequestTestJob(net::URLRequest* request, bool auto_advance); |
| 45 | 45 |
| 46 // Constructs a job to return the given response regardless of the request | 46 // Constructs a job to return the given response regardless of the request |
| 47 // url. The headers should include the HTTP status line and be formatted as | 47 // url. The headers should include the HTTP status line and be formatted as |
| 48 // expected by net::HttpResponseHeaders. | 48 // expected by net::HttpResponseHeaders. |
| 49 explicit URLRequestTestJob(URLRequest* request, | 49 explicit URLRequestTestJob(net::URLRequest* request, |
| 50 const std::string& response_headers, | 50 const std::string& response_headers, |
| 51 const std::string& response_data, | 51 const std::string& response_data, |
| 52 bool auto_advance); | 52 bool auto_advance); |
| 53 | 53 |
| 54 // The three canned URLs this handler will respond to without having been | 54 // The three canned URLs this handler will respond to without having been |
| 55 // explicitly initialized with response headers and data. | 55 // explicitly initialized with response headers and data. |
| 56 // FIXME(brettw): we should probably also have a redirect one | 56 // FIXME(brettw): we should probably also have a redirect one |
| 57 static GURL test_url_1(); | 57 static GURL test_url_1(); |
| 58 static GURL test_url_2(); | 58 static GURL test_url_2(); |
| 59 static GURL test_url_3(); | 59 static GURL test_url_3(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 79 static bool ProcessOnePendingMessage(); | 79 static bool ProcessOnePendingMessage(); |
| 80 | 80 |
| 81 // With auto advance enabled, the job will advance thru the stages without | 81 // With auto advance enabled, the job will advance thru the stages without |
| 82 // the caller having to call ProcessOnePendingMessage. Auto advance depends | 82 // the caller having to call ProcessOnePendingMessage. Auto advance depends |
| 83 // on having a message loop running. The default is to not auto advance. | 83 // on having a message loop running. The default is to not auto advance. |
| 84 // Should not be altered after the job has started. | 84 // Should not be altered after the job has started. |
| 85 bool auto_advance() { return auto_advance_; } | 85 bool auto_advance() { return auto_advance_; } |
| 86 void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } | 86 void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } |
| 87 | 87 |
| 88 // Factory method for protocol factory registration if callers don't subclass | 88 // Factory method for protocol factory registration if callers don't subclass |
| 89 static URLRequest::ProtocolFactory Factory; | 89 static net::URLRequest::ProtocolFactory Factory; |
| 90 | 90 |
| 91 // Job functions | 91 // Job functions |
| 92 virtual void Start(); | 92 virtual void Start(); |
| 93 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 93 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
| 94 virtual void Kill(); | 94 virtual void Kill(); |
| 95 virtual bool GetMimeType(std::string* mime_type) const; | 95 virtual bool GetMimeType(std::string* mime_type) const; |
| 96 virtual void GetResponseInfo(net::HttpResponseInfo* info); | 96 virtual void GetResponseInfo(net::HttpResponseInfo* info); |
| 97 virtual int GetResponseCode() const; | 97 virtual int GetResponseCode() const; |
| 98 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); | 98 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); |
| 99 | 99 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 128 | 128 |
| 129 // current offset within response_data_ | 129 // current offset within response_data_ |
| 130 int offset_; | 130 int offset_; |
| 131 | 131 |
| 132 // Holds the buffer for an asynchronous ReadRawData call | 132 // Holds the buffer for an asynchronous ReadRawData call |
| 133 net::IOBuffer* async_buf_; | 133 net::IOBuffer* async_buf_; |
| 134 int async_buf_size_; | 134 int async_buf_size_; |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 137 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
| OLD | NEW |