summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-06 21:13:36 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-06 21:13:36 +0000
commitec0a5ac08daab3f5c680c93408f51dd8d3912684 (patch)
tree73717609dd6f37b149eb3cc499b6b0d4fa16ad26 /net
parent2ed12962c41bcb40078d4d5364f8d94dd8fcb9b6 (diff)
downloadchromium_src-ec0a5ac08daab3f5c680c93408f51dd8d3912684.zip
chromium_src-ec0a5ac08daab3f5c680c93408f51dd8d3912684.tar.gz
chromium_src-ec0a5ac08daab3f5c680c93408f51dd8d3912684.tar.bz2
Submitting http://codereview.chromium.org/164076 for syf1984@gmail.com (aka miletus):
Make the timeout in WaitToStart() of TestServerLauncher parametrized and expose this parameter to HTTPTestServer::CreateServer() TBR=syf1984@gmail.com, tommi@chromium.org Review URL: http://codereview.chromium.org/164090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/socket/ssl_test_util.cc23
-rw-r--r--net/socket/ssl_test_util.h8
-rw-r--r--net/url_request/url_request_unittest.h29
3 files changed, 57 insertions, 3 deletions
diff --git a/net/socket/ssl_test_util.cc b/net/socket/ssl_test_util.cc
index 1acc0b5..649b27d 100644
--- a/net/socket/ssl_test_util.cc
+++ b/net/socket/ssl_test_util.cc
@@ -94,11 +94,29 @@ const int TestServerLauncher::kBadHTTPSPort = 9666;
// The issuer name of the cert that should be trusted for the test to work.
const wchar_t TestServerLauncher::kCertIssuerName[] = L"Test CA";
-TestServerLauncher::TestServerLauncher() : process_handle_(NULL)
+TestServerLauncher::TestServerLauncher() : process_handle_(NULL),
+ connection_attempts_(10),
+ connection_timeout_(1000)
#if defined(OS_LINUX)
, cert_(NULL)
#endif
{
+ InitCertPath();
+}
+
+TestServerLauncher::TestServerLauncher(int connection_attempts,
+ int connection_timeout)
+ : process_handle_(NULL),
+ connection_attempts_(connection_attempts),
+ connection_timeout_(connection_timeout)
+#if defined(OS_LINUX)
+, cert_(NULL)
+#endif
+{
+ InitCertPath();
+}
+
+void TestServerLauncher::InitCertPath() {
PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_);
cert_dir_ = cert_dir_.Append(FILE_PATH_LITERAL("net"))
.Append(FILE_PATH_LITERAL("data"))
@@ -253,7 +271,8 @@ bool TestServerLauncher::WaitToStart(const std::string& host_name, int port) {
return false;
net::TCPPinger pinger(addr);
- rv = pinger.Ping();
+ rv = pinger.Ping(base::TimeDelta::FromMilliseconds(connection_timeout_),
+ connection_attempts_);
return rv == net::OK;
}
diff --git a/net/socket/ssl_test_util.h b/net/socket/ssl_test_util.h
index acda685..ad9bbab 100644
--- a/net/socket/ssl_test_util.h
+++ b/net/socket/ssl_test_util.h
@@ -26,6 +26,7 @@ namespace net {
class TestServerLauncher {
public:
TestServerLauncher();
+ TestServerLauncher(int connection_attempts, int connection_timeout);
virtual ~TestServerLauncher();
@@ -94,6 +95,9 @@ class TestServerLauncher {
// Returns false if our test root certificate is not trusted.
bool CheckCATrusted();
+ // Initilize the certificate path.
+ void InitCertPath();
+
FilePath document_root_dir_;
FilePath cert_dir_;
@@ -102,6 +106,10 @@ class TestServerLauncher {
base::ProcessHandle process_handle_;
+ // Number of tries and timeout for each try used for WaitToStart.
+ int connection_attempts_;
+ int connection_timeout_;
+
#if defined(OS_LINUX)
struct PrivateCERTCertificate;
PrivateCERTCertificate *cert_;
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index 763389f..03d678d 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -238,6 +238,8 @@ class TestDelegate : public URLRequest::Delegate {
class BaseTestServer : public base::RefCounted<BaseTestServer> {
protected:
BaseTestServer() { }
+ BaseTestServer(int connection_attempts, int connection_timeout)
+ : launcher_(connection_attempts, connection_timeout) { }
public:
@@ -347,6 +349,10 @@ class HTTPTestServer : public BaseTestServer {
explicit HTTPTestServer() : loop_(NULL) {
}
+ explicit HTTPTestServer(int connection_attempts, int connection_timeout)
+ : BaseTestServer(connection_attempts, connection_timeout), loop_(NULL) {
+ }
+
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.
@@ -356,11 +362,32 @@ class HTTPTestServer : public BaseTestServer {
return CreateServerWithFileRootURL(document_root, std::wstring(), loop);
}
+ static scoped_refptr<HTTPTestServer> CreateServer(
+ const std::wstring& document_root,
+ MessageLoop* loop,
+ int connection_attempts,
+ int connection_timeout) {
+ return CreateServerWithFileRootURL(document_root, std::wstring(), loop,
+ connection_attempts,
+ connection_timeout);
+ }
+
static scoped_refptr<HTTPTestServer> CreateServerWithFileRootURL(
const std::wstring& document_root,
const std::wstring& file_root_url,
MessageLoop* loop) {
- scoped_refptr<HTTPTestServer> test_server = new HTTPTestServer();
+ return CreateServerWithFileRootURL(document_root, file_root_url,
+ loop, 10, 1000);
+ }
+
+ static scoped_refptr<HTTPTestServer> CreateServerWithFileRootURL(
+ const std::wstring& document_root,
+ const std::wstring& file_root_url,
+ MessageLoop* loop,
+ int connection_attempts,
+ int connection_timeout) {
+ scoped_refptr<HTTPTestServer> test_server =
+ new HTTPTestServer(connection_attempts, connection_timeout);
test_server->loop_ = loop;
FilePath no_cert;
FilePath docroot = FilePath::FromWStringHack(document_root);