OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // A URLRequestJob class that pulls the net and http headers from disk. | 5 // A URLRequestJob class that pulls the net and http headers from disk. |
6 | 6 |
7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | 7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ |
8 #define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | 8 #define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 16 matching lines...) Expand all Loading... |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 class URLRequestMockHTTPJob : public URLRequestFileJob { | 29 class URLRequestMockHTTPJob : public URLRequestFileJob { |
30 public: | 30 public: |
31 // Note that all file IO is done using |worker_pool|. | 31 // Note that all file IO is done using |worker_pool|. |
32 URLRequestMockHTTPJob(URLRequest* request, | 32 URLRequestMockHTTPJob(URLRequest* request, |
33 NetworkDelegate* network_delegate, | 33 NetworkDelegate* network_delegate, |
34 const base::FilePath& file_path, | 34 const base::FilePath& file_path, |
35 const scoped_refptr<base::TaskRunner>& task_runner); | 35 const scoped_refptr<base::TaskRunner>& task_runner); |
36 | 36 |
37 virtual void Start() override; | 37 void Start() override; |
38 virtual bool GetMimeType(std::string* mime_type) const override; | 38 bool GetMimeType(std::string* mime_type) const override; |
39 virtual int GetResponseCode() const override; | 39 int GetResponseCode() const override; |
40 virtual bool GetCharset(std::string* charset) override; | 40 bool GetCharset(std::string* charset) override; |
41 virtual void GetResponseInfo(HttpResponseInfo* info) override; | 41 void GetResponseInfo(HttpResponseInfo* info) override; |
42 virtual bool IsRedirectResponse(GURL* location, | 42 bool IsRedirectResponse(GURL* location, int* http_status_code) override; |
43 int* http_status_code) override; | |
44 | 43 |
45 // Adds the testing URLs to the URLRequestFilter. | 44 // Adds the testing URLs to the URLRequestFilter. |
46 static void AddUrlHandler( | 45 static void AddUrlHandler( |
47 const base::FilePath& base_path, | 46 const base::FilePath& base_path, |
48 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | 47 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); |
49 | 48 |
50 // Respond to all HTTP requests of |hostname| with contents of the file | 49 // Respond to all HTTP requests of |hostname| with contents of the file |
51 // located at |file_path|. | 50 // located at |file_path|. |
52 static void AddHostnameToFileHandler( | 51 static void AddHostnameToFileHandler( |
53 const std::string& hostname, | 52 const std::string& hostname, |
(...skipping 13 matching lines...) Expand all Loading... |
67 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | 66 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); |
68 | 67 |
69 // Returns a URLRequestJobFactory::ProtocolHandler that serves | 68 // Returns a URLRequestJobFactory::ProtocolHandler that serves |
70 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all | 69 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all |
71 // requests with the contents of |file|. | 70 // requests with the contents of |file|. |
72 static scoped_ptr<URLRequestInterceptor> CreateInterceptorForSingleFile( | 71 static scoped_ptr<URLRequestInterceptor> CreateInterceptorForSingleFile( |
73 const base::FilePath& file, | 72 const base::FilePath& file, |
74 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | 73 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); |
75 | 74 |
76 protected: | 75 protected: |
77 virtual ~URLRequestMockHTTPJob(); | 76 ~URLRequestMockHTTPJob() override; |
78 | 77 |
79 private: | 78 private: |
80 void GetResponseInfoConst(HttpResponseInfo* info) const; | 79 void GetResponseInfoConst(HttpResponseInfo* info) const; |
81 void GetRawHeaders(std::string raw_headers); | 80 void GetRawHeaders(std::string raw_headers); |
82 std::string raw_headers_; | 81 std::string raw_headers_; |
83 const scoped_refptr<base::TaskRunner> task_runner_; | 82 const scoped_refptr<base::TaskRunner> task_runner_; |
84 | 83 |
85 base::WeakPtrFactory<URLRequestMockHTTPJob> weak_ptr_factory_; | 84 base::WeakPtrFactory<URLRequestMockHTTPJob> weak_ptr_factory_; |
86 | 85 |
87 DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob); | 86 DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob); |
88 }; | 87 }; |
89 | 88 |
90 } // namespace net | 89 } // namespace net |
91 | 90 |
92 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | 91 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ |
OLD | NEW |