Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / test / url_request / url_request_mock_http_job.h
index cb93412..6eb3c72 100644 (file)
@@ -28,19 +28,26 @@ namespace net {
 
 class URLRequestMockHTTPJob : public URLRequestFileJob {
  public:
+  enum FailurePhase {
+    START = 0,
+    READ_ASYNC = 1,
+    READ_SYNC = 2,
+    MAX_FAILURE_PHASE = 3,
+  };
+
   // Note that all file IO is done using |worker_pool|.
   URLRequestMockHTTPJob(URLRequest* request,
                         NetworkDelegate* network_delegate,
                         const base::FilePath& file_path,
                         const scoped_refptr<base::TaskRunner>& task_runner);
 
-  virtual void Start() OVERRIDE;
-  virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
-  virtual int GetResponseCode() const OVERRIDE;
-  virtual bool GetCharset(std::string* charset) OVERRIDE;
-  virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE;
-  virtual bool IsRedirectResponse(GURL* location,
-                                  int* http_status_code) OVERRIDE;
+  void Start() override;
+  bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override;
+  bool GetMimeType(std::string* mime_type) const override;
+  int GetResponseCode() const override;
+  bool GetCharset(std::string* charset) override;
+  void GetResponseInfo(HttpResponseInfo* info) override;
+  bool IsRedirectResponse(GURL* location, int* http_status_code) override;
 
   // Adds the testing URLs to the URLRequestFilter.
   static void AddUrlHandler(
@@ -58,6 +65,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
@@ -74,11 +88,17 @@ class URLRequestMockHTTPJob : public URLRequestFileJob {
       const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
 
  protected:
-  virtual ~URLRequestMockHTTPJob();
+  ~URLRequestMockHTTPJob() override;
 
  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_;