Chromium Code Reviews| 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 net and http headers from disk. |
| 6 | 6 |
| 7 #ifndef CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ | 7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ |
| 8 #define CONTENT_TEST_NET_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> |
| 11 | 11 |
| 12 #include "net/url_request/url_request_file_job.h" | 12 #include "net/url_request/url_request_file_job.h" |
|
mmenke
2014/09/04 18:05:12
This was a bug from before, but should base/memory
xunjieli
2014/09/04 19:24:15
Done. Sorry I didn't see this.
| |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class FilePath; | 15 class FilePath; |
|
mmenke
2014/09/04 18:05:12
Need to forward declare SequencedWorkerPool
xunjieli
2014/09/04 19:24:15
Done.
| |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class URLRequestInterceptor; | 19 class URLRequestInterceptor; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace content { | 22 namespace net { |
| 23 | 23 |
| 24 class URLRequestMockHTTPJob : public net::URLRequestFileJob { | 24 class URLRequestMockHTTPJob : public net::URLRequestFileJob { |
|
mmenke
2014/09/04 18:05:12
"net::" no longer needed in this file.
xunjieli
2014/09/04 18:44:25
Done.
| |
| 25 public: | 25 public: |
| 26 URLRequestMockHTTPJob(net::URLRequest* request, | 26 URLRequestMockHTTPJob( |
| 27 net::NetworkDelegate* network_delegate, | 27 net::URLRequest* request, |
| 28 const base::FilePath& file_path); | 28 net::NetworkDelegate* network_delegate, |
| 29 const base::FilePath& file_path, | |
| 30 base::SequencedWorkerPool* worker_pool); | |
| 29 | 31 |
| 30 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 32 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 31 virtual int GetResponseCode() const OVERRIDE; | 33 virtual int GetResponseCode() const OVERRIDE; |
| 32 virtual bool GetCharset(std::string* charset) OVERRIDE; | 34 virtual bool GetCharset(std::string* charset) OVERRIDE; |
| 33 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 35 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
| 34 virtual bool IsRedirectResponse(GURL* location, | 36 virtual bool IsRedirectResponse(GURL* location, |
| 35 int* http_status_code) OVERRIDE; | 37 int* http_status_code) OVERRIDE; |
| 36 | 38 |
| 37 // Adds the testing URLs to the net::URLRequestFilter. | 39 // Adds the testing URLs to the net::URLRequestFilter. |
| 38 static void AddUrlHandler(const base::FilePath& base_path); | 40 static void AddUrlHandler( |
| 41 const base::FilePath& base_path, | |
| 42 base::SequencedWorkerPool* worker_pool); | |
|
mmenke
2014/09/04 18:05:12
These should probably actually be:
const scoped_r
xunjieli
2014/09/04 18:44:25
Done.
| |
| 39 | 43 |
| 40 // Respond to all HTTP requests of |hostname| with contents of the file | 44 // Respond to all HTTP requests of |hostname| with contents of the file |
| 41 // located at |file_path|. | 45 // located at |file_path|. |
| 42 static void AddHostnameToFileHandler(const std::string& hostname, | 46 static void AddHostnameToFileHandler( |
| 43 const base::FilePath& file); | 47 const std::string& hostname, |
| 48 const base::FilePath& file, | |
| 49 base::SequencedWorkerPool* worker_pool); | |
| 44 | 50 |
| 45 // Given the path to a file relative to the path passed to AddUrlHandler(), | 51 // Given the path to a file relative to the path passed to AddUrlHandler(), |
| 46 // construct a mock URL. | 52 // construct a mock URL. |
| 47 static GURL GetMockUrl(const base::FilePath& path); | 53 static GURL GetMockUrl(const base::FilePath& path); |
| 48 | 54 |
| 49 // Given the path to a file relative to the path passed to AddUrlHandler(), | 55 // Given the path to a file relative to the path passed to AddUrlHandler(), |
| 50 // construct a mock URL for view source. | 56 // construct a mock URL for view source. |
| 51 static GURL GetMockViewSourceUrl(const base::FilePath& path); | 57 static GURL GetMockViewSourceUrl(const base::FilePath& path); |
| 52 | 58 |
| 53 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves | 59 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves |
| 54 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the | 60 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the |
| 55 // file path leading to the root of the directory to use as the root of the | 61 // file path leading to the root of the directory to use as the root of the |
| 56 // HTTP server. | 62 // HTTP server. |
| 57 static scoped_ptr<net::URLRequestInterceptor> | 63 static scoped_ptr<net::URLRequestInterceptor> |
| 58 CreateInterceptor(const base::FilePath& base_path); | 64 CreateInterceptor( |
| 65 const base::FilePath& base_path, | |
| 66 base::SequencedWorkerPool* worker_pool); | |
| 59 | 67 |
| 60 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves | 68 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves |
| 61 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all | 69 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all |
| 62 // requests with the contents of |file|. | 70 // requests with the contents of |file|. |
| 63 static scoped_ptr<net::URLRequestInterceptor> | 71 static scoped_ptr<net::URLRequestInterceptor> |
| 64 CreateInterceptorForSingleFile(const base::FilePath& file); | 72 CreateInterceptorForSingleFile(const base::FilePath& file, |
| 73 base::SequencedWorkerPool* worker_pool); | |
| 65 | 74 |
| 66 protected: | 75 protected: |
| 67 virtual ~URLRequestMockHTTPJob(); | 76 virtual ~URLRequestMockHTTPJob(); |
| 68 | 77 |
| 69 private: | 78 private: |
| 70 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 79 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
|
mmenke
2014/09/04 18:05:12
Another bug from before: There should be a "DISAL
xunjieli
2014/09/04 18:44:25
Done. Thanks!
| |
| 71 }; | 80 }; |
| 72 | 81 |
| 73 } // namespace content | 82 } // namespace net |
| 74 | 83 |
| 75 #endif // CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ | 84 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ |
| OLD | NEW |