Get foreground tab on Android
[chromium-blink-merge.git] / content / test / net / url_request_mock_http_job.h
blobe3427c5892f596ddbf1388c20fbf2677c7daf793
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.
7 #ifndef CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_
8 #define CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_
10 #include <string>
12 #include "net/url_request/url_request_file_job.h"
13 #include "net/url_request/url_request_job_factory.h"
15 namespace base {
16 class FilePath;
19 namespace content {
21 class URLRequestMockHTTPJob : public net::URLRequestFileJob {
22 public:
23 URLRequestMockHTTPJob(net::URLRequest* request,
24 net::NetworkDelegate* network_delegate,
25 const base::FilePath& file_path);
27 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
28 virtual int GetResponseCode() const OVERRIDE;
29 virtual bool GetCharset(std::string* charset) OVERRIDE;
30 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
31 virtual bool IsRedirectResponse(GURL* location,
32 int* http_status_code) OVERRIDE;
34 // Adds the testing URLs to the net::URLRequestFilter.
35 static void AddUrlHandler(const base::FilePath& base_path);
37 // Respond to all HTTP requests of |hostname| with contents of the file
38 // located at |file_path|.
39 static void AddHostnameToFileHandler(const std::string& hostname,
40 const base::FilePath& file);
42 // Given the path to a file relative to the path passed to AddUrlHandler(),
43 // construct a mock URL.
44 static GURL GetMockUrl(const base::FilePath& path);
46 // Given the path to a file relative to the path passed to AddUrlHandler(),
47 // construct a mock URL for view source.
48 static GURL GetMockViewSourceUrl(const base::FilePath& path);
50 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves
51 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the
52 // file path leading to the root of the directory to use as the root of the
53 // HTTP server.
54 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
55 CreateProtocolHandler(const base::FilePath& base_path);
57 // Returns a net::URLRequestJobFactory::ProtocolHandler that serves
58 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all
59 // requests with the contents of |file|.
60 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
61 CreateProtocolHandlerForSingleFile(const base::FilePath& file);
63 private:
64 virtual ~URLRequestMockHTTPJob();
66 void GetResponseInfoConst(net::HttpResponseInfo* info) const;
69 } // namespace content
71 #endif // CONTENT_TEST_NET_URL_REQUEST_MOCK_HTTP_JOB_H_