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