Chromium Code Reviews| Index: net/test/url_request/url_request_mock_http_job.h |
| diff --git a/net/test/url_request/url_request_mock_http_job.h b/net/test/url_request/url_request_mock_http_job.h |
| index eb68a2d27f126e1708f8d2af5f320dce7449dfe5..e11e28cbfeebfc1cfe2b73e3699973e078c6917b 100644 |
| --- a/net/test/url_request/url_request_mock_http_job.h |
| +++ b/net/test/url_request/url_request_mock_http_job.h |
| @@ -28,6 +28,12 @@ namespace net { |
| class URLRequestMockHTTPJob : public URLRequestFileJob { |
| public: |
| + enum FailurePhase { |
| + START = 0, |
| + READ_ASYNC = 1, |
| + READ_SYNC = 2, |
| + }; |
| + |
| // Note that all file IO is done using |worker_pool|. |
| URLRequestMockHTTPJob(URLRequest* request, |
| NetworkDelegate* network_delegate, |
| @@ -35,6 +41,9 @@ class URLRequestMockHTTPJob : public URLRequestFileJob { |
| const scoped_refptr<base::TaskRunner>& task_runner); |
| virtual void Start() override; |
| + virtual bool ReadRawData(IOBuffer* buf, |
|
xunjieli
2014/10/17 00:31:35
nit: remove virtual.
mef
2014/10/17 20:19:43
Done.
|
| + int buf_size, |
| + int* bytes_read) override; |
| virtual bool GetMimeType(std::string* mime_type) const override; |
| virtual int GetResponseCode() const override; |
| virtual bool GetCharset(std::string* charset) override; |
| @@ -58,6 +67,13 @@ class URLRequestMockHTTPJob : public URLRequestFileJob { |
| // construct a mock URL. |
| static GURL GetMockUrl(const base::FilePath& path); |
| + // Given the path to a file relative to the path passed to AddUrlHandler(), |
| + // construct a mock URL that reports |net_error| at given |phase| of the |
| + // request. Reporting |net_error| ERR_IO_PENDING results in a hung request. |
| + static GURL GetMockUrlWithFailure(const base::FilePath& path, |
| + FailurePhase phase, |
| + int net_error); |
| + |
| // Returns a URLRequestJobFactory::ProtocolHandler that serves |
| // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the |
| // file path leading to the root of the directory to use as the root of the |
| @@ -78,7 +94,13 @@ class URLRequestMockHTTPJob : public URLRequestFileJob { |
| private: |
| void GetResponseInfoConst(HttpResponseInfo* info) const; |
| - void GetRawHeaders(std::string raw_headers); |
| + void SetHeadersAndStart(const std::string& raw_headers); |
| + // Checks query part of request url, and reports an error if it matches. |
| + // Error is parsed out from the query and is reported synchronously. |
| + // Reporting ERR_IO_PENDING results in a hung request. |
| + // The "readasync" error is posted asynchronously. |
| + bool MaybeReportErrorOnPhase(FailurePhase phase); |
| + |
| std::string raw_headers_; |
| const scoped_refptr<base::TaskRunner> task_runner_; |