OLD | NEW |
---|---|
(Empty) | |
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. | |
6 | |
7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | |
8 #define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | |
9 | |
10 #include <string> | |
11 | |
12 #include "net/url_request/url_request_file_job.h" | |
13 | |
14 namespace base { | |
15 class FilePath; | |
mmenke
2014/09/04 19:02:38
Think you missed some of my comment in this file (
xunjieli
2014/09/04 19:24:16
Acknowledged.
| |
16 } | |
17 | |
18 namespace net { | |
19 class URLRequestInterceptor; | |
20 } | |
21 | |
22 namespace net { | |
23 | |
24 class URLRequestMockHTTPJob : public URLRequestFileJob { | |
25 public: | |
26 URLRequestMockHTTPJob( | |
27 URLRequest* request, | |
28 NetworkDelegate* network_delegate, | |
29 const base::FilePath& file_path, | |
30 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
31 | |
32 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | |
33 virtual int GetResponseCode() const OVERRIDE; | |
34 virtual bool GetCharset(std::string* charset) OVERRIDE; | |
35 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; | |
36 virtual bool IsRedirectResponse(GURL* location, | |
37 int* http_status_code) OVERRIDE; | |
38 | |
39 // Adds the testing URLs to the URLRequestFilter. | |
40 static void AddUrlHandler( | |
41 const base::FilePath& base_path, | |
42 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
mmenke
2014/09/04 19:02:38
Should include base/memory/ref_counted.h here (And
xunjieli
2014/09/04 19:24:16
Done.
| |
43 | |
44 // Respond to all HTTP requests of |hostname| with contents of the file | |
45 // located at |file_path|. | |
46 static void AddHostnameToFileHandler( | |
47 const std::string& hostname, | |
48 const base::FilePath& file, | |
49 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
50 | |
51 // Given the path to a file relative to the path passed to AddUrlHandler(), | |
52 // construct a mock URL. | |
53 static GURL GetMockUrl(const base::FilePath& path); | |
54 | |
55 // Given the path to a file relative to the path passed to AddUrlHandler(), | |
56 // construct a mock URL for view source. | |
57 static GURL GetMockViewSourceUrl(const base::FilePath& path); | |
58 | |
59 // Returns a URLRequestJobFactory::ProtocolHandler that serves | |
60 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the | |
61 // file path leading to the root of the directory to use as the root of the | |
62 // HTTP server. | |
63 static scoped_ptr<URLRequestInterceptor> | |
64 CreateInterceptor( | |
65 const base::FilePath& base_path, | |
66 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
67 | |
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> | |
72 CreateInterceptorForSingleFile( | |
73 const base::FilePath& file, | |
74 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
75 | |
76 protected: | |
77 virtual ~URLRequestMockHTTPJob(); | |
78 | |
79 private: | |
80 void GetResponseInfoConst(HttpResponseInfo* info) const; | |
81 }; | |
82 | |
83 } // namespace net | |
84 | |
85 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | |
OLD | NEW |