summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 21:41:31 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 21:41:31 +0000
commitb89ca03de8ef4f30169d72d3120ee291481d5964 (patch)
treee67f8a5956242cc4498ca374870ee0a839bef775 /net/url_request
parenta72c6bb647954c92109a57b3edbb789195edda57 (diff)
downloadchromium_src-b89ca03de8ef4f30169d72d3120ee291481d5964.zip
chromium_src-b89ca03de8ef4f30169d72d3120ee291481d5964.tar.gz
chromium_src-b89ca03de8ef4f30169d72d3120ee291481d5964.tar.bz2
Speed up net_unittests by re-using one FTP test server instance.
I managed to save 30s with this change! I had to change the interface of the test server a bit. Now the credentials to be used are passed (optionally) for TestPage request, not in the ctor. BUG=none TEST=none Review URL: http://codereview.chromium.org/182031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24942 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/url_request_unittest.cc70
-rw-r--r--net/url_request/url_request_unittest.h71
2 files changed, 68 insertions, 73 deletions
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 6f4338c..640174f 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -1919,15 +1919,30 @@ TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) {
EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
}
-TEST_F(URLRequestTest, FTPGetTestAnonymous) {
- scoped_refptr<FTPTestServer> server = FTPTestServer::CreateServer(L"");
- ASSERT_TRUE(NULL != server.get());
+class URLRequestTestFTP : public URLRequestTest {
+ protected:
+ static void SetUpTestCase() {
+ server_ = FTPTestServer::CreateServer(L"");
+ }
+
+ static void TearDownTestCase() {
+ server_ = NULL;
+ }
+
+ static scoped_refptr<FTPTestServer> server_;
+};
+
+// static
+scoped_refptr<FTPTestServer> URLRequestTestFTP::server_;
+
+TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1943,16 +1958,15 @@ TEST_F(URLRequestTest, FTPGetTestAnonymous) {
}
}
-TEST_F(URLRequestTest, FTPGetTest) {
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "chrome", "chrome");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPGetTest) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "chrome"),
+ &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1968,16 +1982,15 @@ TEST_F(URLRequestTest, FTPGetTest) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongPassword) {
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "chrome", "wrong_password");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "chrome", "wrong_password"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1993,11 +2006,8 @@ TEST_F(URLRequestTest, FTPCheckWrongPassword) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) {
- // Pass wrong login credentials in the request URL.
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "chrome", "wrong_password");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
@@ -2007,7 +2017,8 @@ TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) {
d.set_username(L"chrome");
d.set_password(L"chrome");
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "chrome", "wrong_password"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -2023,16 +2034,15 @@ TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongUser) {
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "wrong_user", "chrome");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
TestDelegate d;
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "wrong_user", "chrome"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -2048,11 +2058,8 @@ TEST_F(URLRequestTest, FTPCheckWrongUser) {
}
}
-TEST_F(URLRequestTest, FTPCheckWrongUserRestart) {
- // Pass wrong login credentials in the request URL.
- scoped_refptr<FTPTestServer> server =
- FTPTestServer::CreateServer(L"", "wrong_user", "chrome");
- ASSERT_TRUE(NULL != server.get());
+TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
+ ASSERT_TRUE(NULL != server_.get());
FilePath app_path;
PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
app_path = app_path.AppendASCII("LICENSE");
@@ -2062,7 +2069,8 @@ TEST_F(URLRequestTest, FTPCheckWrongUserRestart) {
d.set_username(L"chrome");
d.set_password(L"chrome");
{
- TestURLRequest r(server->TestServerPage("/LICENSE"), &d);
+ TestURLRequest r(server_->TestServerPage("/LICENSE",
+ "wrong_user", "chrome"), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index e058957..f16f0ae 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -263,11 +263,27 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
}
GURL TestServerPage(const std::string& path) {
- return GURL(base_address_ + 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);
+ }
+
+ // Deprecated in favor of TestServerPage.
+ // TODO(phajdan.jr): Remove TestServerPageW.
GURL TestServerPageW(const std::wstring& path) {
- return GURL(base_address_ + WideToUTF8(path));
+ return TestServerPage(WideToUTF8(path));
}
virtual bool MakeGETRequest(const std::string& page_name) = 0;
@@ -282,41 +298,19 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
const FilePath& document_root,
const FilePath& cert_path,
const std::wstring& file_root_url) {
- std::string blank;
- return Start(protocol, host_name, port, document_root, cert_path,
- file_root_url, blank, blank);
- }
-
- 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,
- const std::string& url_user,
- const std::string& url_password) {
if (!launcher_.Start(protocol,
host_name, port, document_root, cert_path, file_root_url))
return false;
- std::string scheme;
if (protocol == net::TestServerLauncher::ProtoFTP)
- scheme = "ftp";
+ scheme_ = "ftp";
else
- scheme = "http";
+ scheme_ = "http";
if (!cert_path.empty())
- scheme.push_back('s');
+ scheme_.push_back('s');
- std::string port_str = IntToString(port);
- if (url_user.empty()) {
- base_address_ = scheme + "://" + host_name + ":" + port_str + "/";
- } else {
- if (url_password.empty())
- base_address_ = scheme + "://" + url_user + "@" +
- host_name + ":" + port_str + "/";
- else
- base_address_ = scheme + "://" + url_user + ":" + url_password +
- "@" + host_name + ":" + port_str + "/";
- }
+ host_name_ = host_name;
+ port_str_ = IntToString(port);
return true;
}
@@ -344,7 +338,9 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
};
net::TestServerLauncher launcher_;
- std::string base_address_;
+ std::string scheme_;
+ std::string host_name_;
+ std::string port_str_;
};
@@ -419,7 +415,7 @@ class HTTPTestServer : public BaseTestServer {
const std::wstring& file_root_url) {
return server->Start(net::TestServerLauncher::ProtoHTTP, kDefaultHostName,
kHTTPDefaultPort, document_root, cert_path,
- file_root_url, "", "");
+ file_root_url);
}
// A subclass may wish to send the request in a different manner
@@ -577,27 +573,18 @@ class FTPTestServer : public BaseTestServer {
static scoped_refptr<FTPTestServer> CreateServer(
const std::wstring& document_root) {
- std::string blank;
- return CreateServer(document_root, blank, blank);
- }
-
- static scoped_refptr<FTPTestServer> CreateServer(
- const std::wstring& document_root,
- const std::string& url_user,
- const std::string& url_password) {
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(),
- url_user, url_password)) {
+ kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring())) {
return NULL;
}
return test_server;
}
virtual bool MakeGETRequest(const std::string& page_name) {
- const GURL& url = TestServerPage(base_address_, page_name);
+ const GURL& url = TestServerPage(page_name);
TestDelegate d;
URLRequest request(url, &d);
request.set_context(new TestURLRequestContext());