Index: net/test/test_server.cc |
diff --git a/net/test/test_server.cc b/net/test/test_server.cc |
index 4b426eb4e9d28fc5a825f5d3f04b2a986190d8f3..1e6ff642b1291463f5b8b493b1a9c428423c0744 100644 |
--- a/net/test/test_server.cc |
+++ b/net/test/test_server.cc |
@@ -40,59 +40,6 @@ const int kServerConnectionAttempts = 10; |
// Connection timeout in milliseconds for tests. |
const int kServerConnectionTimeoutMs = 1000; |
-const char kTestServerShardFlag[] = "test-server-shard"; |
- |
-int GetHTTPSPortBase(const TestServer::HTTPSOptions& options) { |
- if (options.request_client_certificate) |
- return 9543; |
- |
- switch (options.server_certificate) { |
- case TestServer::HTTPSOptions::CERT_OK: |
- return 9443; |
- case TestServer::HTTPSOptions::CERT_MISMATCHED_NAME: |
- return 9643; |
- case TestServer::HTTPSOptions::CERT_EXPIRED: |
- // TODO(phajdan.jr): Some tests rely on this hardcoded value. |
- // Some uses of this are actually in .html/.js files. |
- return 9666; |
- default: |
- NOTREACHED(); |
- } |
- return -1; |
-} |
- |
-int GetPortBase(TestServer::Type type, |
- const TestServer::HTTPSOptions& options) { |
- switch (type) { |
- case TestServer::TYPE_FTP: |
- return 3117; |
- case TestServer::TYPE_HTTP: |
- return 1337; |
- case TestServer::TYPE_HTTPS: |
- return GetHTTPSPortBase(options); |
- default: |
- NOTREACHED(); |
- } |
- return -1; |
-} |
- |
-int GetPort(TestServer::Type type, |
- const TestServer::HTTPSOptions& options) { |
- int port = GetPortBase(type, options); |
- if (CommandLine::ForCurrentProcess()->HasSwitch(kTestServerShardFlag)) { |
- std::string shard_str(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
- kTestServerShardFlag)); |
- int shard = -1; |
- if (base::StringToInt(shard_str, &shard)) { |
- port += shard; |
- } else { |
- LOG(FATAL) << "Got invalid " << kTestServerShardFlag << " flag value. " |
- << "An integer is expected."; |
- } |
- } |
- return port; |
-} |
- |
std::string GetHostname(TestServer::Type type, |
const TestServer::HTTPSOptions& options) { |
if (type == TestServer::TYPE_HTTPS && |
@@ -138,13 +85,16 @@ FilePath TestServer::HTTPSOptions::GetCertificateFile() const { |
} |
TestServer::TestServer(Type type, const FilePath& document_root) |
- : type_(type) { |
+ : type_(type), |
+ started_(false) { |
Init(document_root); |
} |
TestServer::TestServer(const HTTPSOptions& https_options, |
const FilePath& document_root) |
- : https_options_(https_options), type_(TYPE_HTTPS) { |
+ : https_options_(https_options), |
+ type_(TYPE_HTTPS), |
+ started_(false) { |
Init(document_root); |
} |
@@ -156,8 +106,11 @@ TestServer::~TestServer() { |
} |
void TestServer::Init(const FilePath& document_root) { |
- host_port_pair_ = HostPortPair(GetHostname(type_, https_options_), |
- GetPort(type_, https_options_)); |
+ // At this point, the port that the testserver will listen on is unknown. |
+ // The testserver will listen on an ephemeral port, and write the port |
+ // number out over a pipe that this TestServer object will read from. Once |
+ // that is complete, the host_port_pair_ will contain the actual port. |
+ host_port_pair_ = HostPortPair(GetHostname(type_, https_options_), 0); |
process_handle_ = base::kNullProcessHandle; |
FilePath src_dir; |
@@ -202,6 +155,7 @@ bool TestServer::Start() { |
return false; |
} |
+ started_ = true; |
return true; |
} |
@@ -209,6 +163,8 @@ bool TestServer::Stop() { |
if (!process_handle_) |
return true; |
+ started_ = false; |
+ |
// First check if the process has already terminated. |
bool ret = base::WaitForSingleProcess(process_handle_, 0); |
if (!ret) |
@@ -224,6 +180,11 @@ bool TestServer::Stop() { |
return ret; |
} |
+const HostPortPair& TestServer::host_port_pair() const { |
+ DCHECK(started_); |
+ return host_port_pair_; |
+} |
+ |
std::string TestServer::GetScheme() const { |
switch (type_) { |
case TYPE_FTP: |