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 net::URLRequestJob class that pulls the content and http headers from disk. | 5 // A net::URLRequestJob class that pulls the content and http headers from disk. |
6 | 6 |
7 #ifndef CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ | 7 #ifndef CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ |
8 #define CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ | 8 #define CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "net/url_request/url_request_file_job.h" | 12 #include "net/url_request/url_request_file_job.h" |
13 #include "net/url_request/url_request_job_factory.h" | 13 #include "net/url_request/url_request_job_factory.h" |
14 | 14 |
| 15 namespace base { |
15 class FilePath; | 16 class FilePath; |
| 17 } |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 | 20 |
19 class URLRequestMockHTTPJob : public net::URLRequestFileJob { | 21 class URLRequestMockHTTPJob : public net::URLRequestFileJob { |
20 public: | 22 public: |
21 URLRequestMockHTTPJob(net::URLRequest* request, | 23 URLRequestMockHTTPJob(net::URLRequest* request, |
22 net::NetworkDelegate* network_delegate, | 24 net::NetworkDelegate* network_delegate, |
23 const FilePath& file_path); | 25 const base::FilePath& file_path); |
24 | 26 |
25 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 27 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
26 virtual int GetResponseCode() const OVERRIDE; | 28 virtual int GetResponseCode() const OVERRIDE; |
27 virtual bool GetCharset(std::string* charset) OVERRIDE; | 29 virtual bool GetCharset(std::string* charset) OVERRIDE; |
28 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 30 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
29 virtual bool IsRedirectResponse(GURL* location, | 31 virtual bool IsRedirectResponse(GURL* location, |
30 int* http_status_code) OVERRIDE; | 32 int* http_status_code) OVERRIDE; |
31 | 33 |
32 // Adds the testing URLs to the net::URLRequestFilter. | 34 // Adds the testing URLs to the net::URLRequestFilter. |
33 static void AddUrlHandler(const FilePath& base_path); | 35 static void AddUrlHandler(const base::FilePath& base_path); |
34 | 36 |
35 // Respond to all HTTP requests of |hostname| with contents of the file | 37 // Respond to all HTTP requests of |hostname| with contents of the file |
36 // located at |file_path|. | 38 // located at |file_path|. |
37 static void AddHostnameToFileHandler(const std::string& hostname, | 39 static void AddHostnameToFileHandler(const std::string& hostname, |
38 const FilePath& file_path); | 40 const base::FilePath& file_path); |
39 | 41 |
40 // Given the path to a file relative to the path passed to AddUrlHandler(), | 42 // Given the path to a file relative to the path passed to AddUrlHandler(), |
41 // construct a mock URL. | 43 // construct a mock URL. |
42 static GURL GetMockUrl(const FilePath& path); | 44 static GURL GetMockUrl(const base::FilePath& path); |
43 | 45 |
44 // Given the path to a file relative to the path passed to AddUrlHandler(), | 46 // Given the path to a file relative to the path passed to AddUrlHandler(), |
45 // construct a mock URL for view source. | 47 // construct a mock URL for view source. |
46 static GURL GetMockViewSourceUrl(const FilePath& path); | 48 static GURL GetMockViewSourceUrl(const base::FilePath& path); |
47 | 49 |
48 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves | 50 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves |
49 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the | 51 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the |
50 // file path leading to the root of the directory to use as the root of the | 52 // file path leading to the root of the directory to use as the root of the |
51 // HTTP server. | 53 // HTTP server. |
52 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 54 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
53 CreateProtocolHandler(const FilePath& base_path); | 55 CreateProtocolHandler(const base::FilePath& base_path); |
54 | 56 |
55 private: | 57 private: |
56 virtual ~URLRequestMockHTTPJob(); | 58 virtual ~URLRequestMockHTTPJob(); |
57 | 59 |
58 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 60 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
59 }; | 61 }; |
60 | 62 |
61 } // namespace content | 63 } // namespace content |
62 | 64 |
63 #endif // CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ | 65 #endif // CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ |
OLD | NEW |