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 "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" | |
17 | |
18 namespace base { | |
19 class FilePath; | |
20 class SequencedWorkerPool; | |
21 } | |
22 | |
23 namespace net { | |
24 class URLRequestInterceptor; | |
25 } | |
26 | |
27 namespace net { | |
28 | |
29 class URLRequestMockHTTPJob : public URLRequestFileJob { | |
30 public: | |
31 URLRequestMockHTTPJob( | |
mmenke
2014/09/05 15:54:10
Think it's worth a comment that all file IO is don
xunjieli
2014/09/05 19:26:15
Done.
| |
32 URLRequest* request, | |
33 NetworkDelegate* network_delegate, | |
34 const base::FilePath& file_path, | |
35 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
36 | |
37 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | |
38 virtual int GetResponseCode() const OVERRIDE; | |
39 virtual bool GetCharset(std::string* charset) OVERRIDE; | |
40 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; | |
41 virtual bool IsRedirectResponse(GURL* location, | |
42 int* http_status_code) OVERRIDE; | |
43 | |
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); | |
48 | |
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); | |
55 | |
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); | |
59 | |
60 // Given the path to a file relative to the path passed to AddUrlHandler(), | |
61 // construct a mock URL for view source. | |
62 static GURL GetMockViewSourceUrl(const base::FilePath& path); | |
mmenke
2014/09/05 15:54:10
This is no longer implemented.
xunjieli
2014/09/05 19:26:15
Done. Good catch. Thanks!
| |
63 | |
64 // Returns a URLRequestJobFactory::ProtocolHandler that serves | |
65 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the | |
66 // file path leading to the root of the directory to use as the root of the | |
67 // HTTP server. | |
68 static scoped_ptr<URLRequestInterceptor> | |
69 CreateInterceptor( | |
70 const base::FilePath& base_path, | |
71 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
72 | |
73 // Returns a URLRequestJobFactory::ProtocolHandler that serves | |
74 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all | |
75 // requests with the contents of |file|. | |
76 static scoped_ptr<URLRequestInterceptor> | |
77 CreateInterceptorForSingleFile( | |
78 const base::FilePath& file, | |
79 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | |
80 | |
81 protected: | |
82 virtual ~URLRequestMockHTTPJob(); | |
83 | |
84 private: | |
85 void GetResponseInfoConst(HttpResponseInfo* info) const; | |
86 DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob); | |
mmenke
2014/09/05 15:54:10
nit: Blank line before DISALLOW_COPY_AND_ASSIGN.
xunjieli
2014/09/05 19:26:15
Done.
| |
87 }; | |
88 | |
89 } // namespace net | |
90 | |
91 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ | |
OLD | NEW |