Index: net/url_request/url_request_test_job.h |
=================================================================== |
--- net/url_request/url_request_test_job.h (revision 13871) |
+++ net/url_request/url_request_test_job.h (working copy) |
@@ -22,32 +22,70 @@ |
// |
// You can override the known URLs or the response data by overriding Start(). |
// |
+// Optionally, you can also construct test jobs to return a headers and data |
+// provided to the contstructor in response to any request url. |
+// |
// When a job is created, it gets put on a queue of pending test jobs. To |
// process jobs on this queue, use ProcessOnePendingMessage, which will process |
// one step of the next job. If the job is incomplete, it will be added to the |
// end of the queue. |
+// |
+// Optionally, you can also construct test jobs that advance automatically |
+// without having to call ProcessOnePendingMessage. |
class URLRequestTestJob : public URLRequestJob { |
public: |
+ // Constructs a job to return one of the canned responses depending on the |
+ // request url, with auto advance disabled. |
explicit URLRequestTestJob(URLRequest* request); |
- virtual ~URLRequestTestJob() {} |
- // the three URLs this handler will respond to |
+ // Constructs a job to return one of the canned responses depending on the |
+ // request url, optionally with auto advance enabled. |
+ explicit URLRequestTestJob(URLRequest* request, bool auto_advance); |
+ |
+ // Constructs a job to return the given response regardless of the request |
+ // url. The headers should include the HTTP status line and be formatted as |
+ // expected by net::HttpResponseHeaders. |
+ explicit URLRequestTestJob(URLRequest* request, |
+ const std::string& response_headers, |
+ const std::string& response_data, |
+ bool auto_advance); |
+ |
+ virtual ~URLRequestTestJob(); |
+ |
+ // The three canned URLs this handler will respond to without having been |
+ // explicitly initialized with response headers and data. |
// FIXME(brettw): we should probably also have a redirect one |
static GURL test_url_1(); |
static GURL test_url_2(); |
static GURL test_url_3(); |
static GURL test_url_error(); |
- // the data that corresponds to each of the URLs above |
+ // The data that corresponds to each of the URLs above |
static std::string test_data_1(); |
static std::string test_data_2(); |
static std::string test_data_3(); |
+ // The headers that correspond to each of the URLs above |
+ static std::string test_headers(); |
+ |
+ // The headers for a redirect response |
+ static std::string test_redirect_headers(); |
+ |
+ // The headers for a server error response |
+ static std::string test_error_headers(); |
+ |
// Processes one pending message from the stack, returning true if any |
// message was processed, or false if there are no more pending request |
- // notifications to send. |
+ // notifications to send. This is not applicable when using auto_advance. |
static bool ProcessOnePendingMessage(); |
+ // With auto advance enabled, the job will advance thru the stages without |
+ // the caller having to call ProcessOnePendingMessage. Auto advance depends |
+ // on having a message loop running. The default is to not auto advance. |
+ // Should not be altered after the job has started. |
+ bool auto_advance() { return auto_advance_; } |
+ void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } |
+ |
// Factory method for protocol factory registration if callers don't subclass |
static URLRequest::ProtocolFactory Factory; |
@@ -57,6 +95,7 @@ |
virtual void Kill(); |
virtual bool GetMimeType(std::string* mime_type) const; |
virtual void GetResponseInfo(net::HttpResponseInfo* info); |
+ virtual bool IsRedirectResponse(GURL* location, int* http_status_code); |
protected: |
// This is what operation we are going to do next when this job is handled. |
@@ -64,19 +103,28 @@ |
enum Stage { WAITING, DATA_AVAILABLE, ALL_DATA, DONE }; |
// Call to process the next opeation, usually sending a notification, and |
- // advancing the stage if necessary. THIS MAY DELETE THE OBJECT, we will |
- // return false if the operations are complete, true if there are more. |
- bool ProcessNextOperation(); |
+ // advancing the stage if necessary. THIS MAY DELETE THE OBJECT. |
+ void ProcessNextOperation(); |
+ // Call to move the job along to the next operation. |
+ void AdvanceJob(); |
+ |
// Called via InvokeLater to cause callbacks to occur after Start() returns. |
- void StartAsync(); |
+ virtual void StartAsync(); |
+ bool auto_advance_; |
+ |
Stage stage_; |
- // The data to send, will be set in Start() |
- std::string data_; |
+ // The headers the job should return, will be set in Start() if not provided |
+ // in the explicit ctor. |
+ scoped_refptr<net::HttpResponseHeaders> response_headers_; |
- // current offset within data_ |
+ // The data to send, will be set in Start() if not provided in the explicit |
+ // ctor. |
+ std::string response_data_; |
+ |
+ // current offset within response_data_ |
int offset_; |
// Holds the buffer for an asynchronous ReadRawData call |