121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen// A net::URLRequestJob class that pulls the content and http headers from disk. 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ 93345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <string> 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "net/url_request/url_request_file_job.h" 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass FilePath; 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 1721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsenclass URLRequestMockHTTPJob : public net::URLRequestFileJob { 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 1921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen URLRequestMockHTTPJob(net::URLRequest* request, const FilePath& file_path); 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual bool GetMimeType(std::string* mime_type) const; 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual bool GetCharset(std::string* charset); 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void GetResponseInfo(net::HttpResponseInfo* info); 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual bool IsRedirectResponse(GURL* location, int* http_status_code); 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 2621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen static net::URLRequest::ProtocolFactory Factory; 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 283f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // Adds the testing URLs to the net::URLRequestFilter. 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static void AddUrlHandler(const FilePath& base_path); 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Given the path to a file relative to base_path_, construct a mock URL. 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static GURL GetMockUrl(const FilePath& path); 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Given the path to a file relative to base_path_, 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // construct a mock URL for view source. 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static GURL GetMockViewSourceUrl(const FilePath& path); 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected: 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual ~URLRequestMockHTTPJob() { } 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static FilePath GetOnDiskPath(const FilePath& base_path, 4221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen net::URLRequest* request, 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& scheme); 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private: 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void GetResponseInfoConst(net::HttpResponseInfo* info) const; 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // This is the file path leading to the root of the directory to use as the 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // root of the http server. 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static FilePath base_path_; 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // CHROME_BROWSER_NET_URL_REQUEST_MOCK_HTTP_JOB_H_ 54