| Index: net/url_request/url_request_unittest.h
|
| diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
|
| index 92f527feea6937e0c77315266044a1925013c139..1a6faf6cdee53557af25b1786444cafbc1ebfa2a 100644
|
| --- a/net/url_request/url_request_unittest.h
|
| +++ b/net/url_request/url_request_unittest.h
|
| @@ -41,11 +41,6 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "googleurl/src/url_util.h"
|
|
|
| -const int kHTTPDefaultPort = 1337;
|
| -const int kFTPDefaultPort = 1338;
|
| -
|
| -const std::string kDefaultHostName("localhost");
|
| -
|
| using base::TimeDelta;
|
|
|
| //-----------------------------------------------------------------------------
|
| @@ -396,218 +391,4 @@ class TestDelegate : public URLRequest::Delegate {
|
| scoped_refptr<net::IOBuffer> buf_;
|
| };
|
|
|
| -//-----------------------------------------------------------------------------
|
| -
|
| -// This object bounds the lifetime of an external python-based HTTP/FTP server
|
| -// that can provide various responses useful for testing.
|
| -class BaseTestServer : public base::RefCounted<BaseTestServer> {
|
| - protected:
|
| - BaseTestServer() {}
|
| -
|
| - public:
|
| - bool WaitToFinish(int milliseconds) {
|
| - return launcher_.WaitToFinish(milliseconds);
|
| - }
|
| -
|
| - bool Stop() {
|
| - return launcher_.Stop();
|
| - }
|
| -
|
| - GURL TestServerPage(const std::string& base_address,
|
| - const std::string& path) {
|
| - return GURL(base_address + path);
|
| - }
|
| -
|
| - GURL TestServerPage(const std::string& path) {
|
| - // TODO(phajdan.jr): Check for problems with IPv6.
|
| - return GURL(scheme_ + "://" + host_name_ + ":" + port_str_ + "/" + path);
|
| - }
|
| -
|
| - GURL TestServerPage(const std::string& path,
|
| - const std::string& user,
|
| - const std::string& password) {
|
| - // TODO(phajdan.jr): Check for problems with IPv6.
|
| -
|
| - if (password.empty())
|
| - return GURL(scheme_ + "://" + user + "@" +
|
| - host_name_ + ":" + port_str_ + "/" + path);
|
| -
|
| - return GURL(scheme_ + "://" + user + ":" + password +
|
| - "@" + host_name_ + ":" + port_str_ + "/" + path);
|
| - }
|
| -
|
| - FilePath GetDataDirectory() {
|
| - return launcher_.GetDocumentRootPath();
|
| - }
|
| -
|
| - protected:
|
| - friend class base::RefCounted<BaseTestServer>;
|
| - virtual ~BaseTestServer() { }
|
| -
|
| - bool Start(net::TestServerLauncher::Protocol protocol,
|
| - const std::string& host_name, int port,
|
| - const FilePath& document_root,
|
| - const FilePath& cert_path,
|
| - const std::wstring& file_root_url) {
|
| - if (!launcher_.Start(protocol,
|
| - host_name, port, document_root, cert_path, file_root_url))
|
| - return false;
|
| -
|
| - if (protocol == net::TestServerLauncher::ProtoFTP)
|
| - scheme_ = "ftp";
|
| - else
|
| - scheme_ = "http";
|
| - if (!cert_path.empty())
|
| - scheme_.push_back('s');
|
| -
|
| - host_name_ = host_name;
|
| - port_str_ = IntToString(port);
|
| - return true;
|
| - }
|
| -
|
| - net::TestServerLauncher launcher_;
|
| - std::string scheme_;
|
| - std::string host_name_;
|
| - std::string port_str_;
|
| -};
|
| -
|
| -//-----------------------------------------------------------------------------
|
| -
|
| -// HTTP
|
| -class HTTPTestServer : public BaseTestServer {
|
| - protected:
|
| - HTTPTestServer() {}
|
| -
|
| - public:
|
| - // Creates and returns a new HTTPTestServer. If |loop| is non-null, requests
|
| - // are serviced on it, otherwise a new thread and message loop are created.
|
| - static scoped_refptr<HTTPTestServer> CreateServer(
|
| - const std::wstring& document_root) {
|
| - return CreateServerWithFileRootURL(document_root, std::wstring());
|
| - }
|
| -
|
| - static scoped_refptr<HTTPTestServer> CreateServerWithFileRootURL(
|
| - const std::wstring& document_root,
|
| - const std::wstring& file_root_url) {
|
| - scoped_refptr<HTTPTestServer> test_server(new HTTPTestServer());
|
| - FilePath no_cert;
|
| - FilePath docroot = FilePath::FromWStringHack(document_root);
|
| - if (!StartTestServer(test_server.get(), docroot, no_cert, file_root_url))
|
| - return NULL;
|
| - return test_server;
|
| - }
|
| -
|
| - static bool StartTestServer(HTTPTestServer* server,
|
| - const FilePath& document_root,
|
| - const FilePath& cert_path,
|
| - const std::wstring& file_root_url) {
|
| - return server->Start(net::TestServerLauncher::ProtoHTTP, kDefaultHostName,
|
| - kHTTPDefaultPort, document_root, cert_path,
|
| - file_root_url);
|
| - }
|
| -
|
| - virtual std::string scheme() { return "http"; }
|
| -};
|
| -
|
| -//-----------------------------------------------------------------------------
|
| -
|
| -class HTTPSTestServer : public HTTPTestServer {
|
| - protected:
|
| - explicit HTTPSTestServer() {
|
| - }
|
| -
|
| - public:
|
| - // Create a server with a valid certificate
|
| - // TODO(dkegel): HTTPSTestServer should not require an instance to specify
|
| - // stock test certificates
|
| - static scoped_refptr<HTTPSTestServer> CreateGoodServer(
|
| - const std::wstring& document_root) {
|
| - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer();
|
| - FilePath docroot = FilePath::FromWStringHack(document_root);
|
| - FilePath certpath = test_server->launcher_.GetOKCertPath();
|
| - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP,
|
| - net::TestServerLauncher::kHostName,
|
| - net::TestServerLauncher::kOKHTTPSPort,
|
| - docroot, certpath, std::wstring())) {
|
| - return NULL;
|
| - }
|
| - return test_server;
|
| - }
|
| -
|
| - // Create a server with an up to date certificate for the wrong hostname
|
| - // for this host
|
| - static scoped_refptr<HTTPSTestServer> CreateMismatchedServer(
|
| - const std::wstring& document_root) {
|
| - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer();
|
| - FilePath docroot = FilePath::FromWStringHack(document_root);
|
| - FilePath certpath = test_server->launcher_.GetOKCertPath();
|
| - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP,
|
| - net::TestServerLauncher::kMismatchedHostName,
|
| - net::TestServerLauncher::kOKHTTPSPort,
|
| - docroot, certpath, std::wstring())) {
|
| - return NULL;
|
| - }
|
| - return test_server;
|
| - }
|
| -
|
| - // Create a server with an expired certificate
|
| - static scoped_refptr<HTTPSTestServer> CreateExpiredServer(
|
| - const std::wstring& document_root) {
|
| - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer();
|
| - FilePath docroot = FilePath::FromWStringHack(document_root);
|
| - FilePath certpath = test_server->launcher_.GetExpiredCertPath();
|
| - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP,
|
| - net::TestServerLauncher::kHostName,
|
| - net::TestServerLauncher::kBadHTTPSPort,
|
| - docroot, certpath, std::wstring())) {
|
| - return NULL;
|
| - }
|
| - return test_server;
|
| - }
|
| -
|
| - // Create a server with an arbitrary certificate
|
| - static scoped_refptr<HTTPSTestServer> CreateServer(
|
| - const std::string& host_name, int port,
|
| - const std::wstring& document_root,
|
| - const std::wstring& cert_path) {
|
| - scoped_refptr<HTTPSTestServer> test_server = new HTTPSTestServer();
|
| - FilePath docroot = FilePath::FromWStringHack(document_root);
|
| - FilePath certpath = FilePath::FromWStringHack(cert_path);
|
| - if (!test_server->Start(net::TestServerLauncher::ProtoHTTP,
|
| - host_name, port, docroot, certpath, std::wstring())) {
|
| - return NULL;
|
| - }
|
| - return test_server;
|
| - }
|
| -
|
| - protected:
|
| - std::wstring cert_path_;
|
| -
|
| - private:
|
| - virtual ~HTTPSTestServer() {}
|
| -};
|
| -
|
| -//-----------------------------------------------------------------------------
|
| -
|
| -class FTPTestServer : public BaseTestServer {
|
| - public:
|
| - FTPTestServer() {
|
| - }
|
| -
|
| - static scoped_refptr<FTPTestServer> CreateServer(
|
| - const std::wstring& document_root) {
|
| - scoped_refptr<FTPTestServer> test_server = new FTPTestServer();
|
| - FilePath docroot = FilePath::FromWStringHack(document_root);
|
| - FilePath no_cert;
|
| - if (!test_server->Start(net::TestServerLauncher::ProtoFTP,
|
| - kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring())) {
|
| - return NULL;
|
| - }
|
| - return test_server;
|
| - }
|
| -
|
| - private:
|
| - ~FTPTestServer() {}
|
| -};
|
| -
|
| #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_
|
|
|