Add include.
[chromium-blink-merge.git] / net / test / url_request / url_request_mock_http_job.h
blob1a01a3084be2b9f6e847d2d2b0683ff080c14507
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
3 // found in the LICENSE file.
4 //
5 // A URLRequestJob class that pulls the net and http headers from disk.
7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
8 #define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
10 #include <string>
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "net/url_request/url_request_file_job.h"
16 #include "url/gurl.h"
18 namespace base {
19 class FilePath;
20 class SequencedWorkerPool;
23 namespace net {
24 class URLRequestInterceptor;
27 namespace net {
29 class URLRequestMockHTTPJob : public URLRequestFileJob {
30 public:
31 // Note that all file IO is done using |worker_pool|.
32 URLRequestMockHTTPJob(URLRequest* request,
33 NetworkDelegate* network_delegate,
34 const base::FilePath& file_path,
35 const scoped_refptr<base::TaskRunner>& task_runner);
37 void Start() override;
38 bool GetMimeType(std::string* mime_type) const override;
39 int GetResponseCode() const override;
40 bool GetCharset(std::string* charset) override;
41 void GetResponseInfo(HttpResponseInfo* info) override;
42 bool IsRedirectResponse(GURL* location, int* http_status_code) override;
44 // Adds the testing URLs to the URLRequestFilter.
45 static void AddUrlHandler(
46 const base::FilePath& base_path,
47 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
49 // Respond to all HTTP requests of |hostname| with contents of the file
50 // located at |file_path|.
51 static void AddHostnameToFileHandler(
52 const std::string& hostname,
53 const base::FilePath& file,
54 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
56 // Given the path to a file relative to the path passed to AddUrlHandler(),
57 // construct a mock URL.
58 static GURL GetMockUrl(const base::FilePath& path);
60 // Returns a URLRequestJobFactory::ProtocolHandler that serves
61 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the
62 // file path leading to the root of the directory to use as the root of the
63 // HTTP server.
64 static scoped_ptr<URLRequestInterceptor> CreateInterceptor(
65 const base::FilePath& base_path,
66 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
68 // Returns a URLRequestJobFactory::ProtocolHandler that serves
69 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all
70 // requests with the contents of |file|.
71 static scoped_ptr<URLRequestInterceptor> CreateInterceptorForSingleFile(
72 const base::FilePath& file,
73 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
75 protected:
76 ~URLRequestMockHTTPJob() override;
78 private:
79 void GetResponseInfoConst(HttpResponseInfo* info) const;
80 void GetRawHeaders(std::string raw_headers);
81 std::string raw_headers_;
82 const scoped_refptr<base::TaskRunner> task_runner_;
84 base::WeakPtrFactory<URLRequestMockHTTPJob> weak_ptr_factory_;
86 DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob);
89 } // namespace net
91 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_