Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/test/test_server.h" | 5 #include "net/test/test_server.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 return false; | 152 return false; |
| 153 | 153 |
| 154 if (!LaunchPython(testserver_path)) | 154 if (!LaunchPython(testserver_path)) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 if (!WaitToStart()) { | 157 if (!WaitToStart()) { |
| 158 Stop(); | 158 Stop(); |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 // TODO(akalin): Automaticall whitelist all ports openened by the test server. | |
|
cbentzel
2010/12/09 14:25:13
This TODO isn't needed anymore.
| |
| 163 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); | |
| 164 | |
| 162 started_ = true; | 165 started_ = true; |
| 163 return true; | 166 return true; |
| 164 } | 167 } |
| 165 | 168 |
| 166 bool TestServer::Stop() { | 169 bool TestServer::Stop() { |
| 167 if (!process_handle_) | 170 if (!process_handle_) |
| 168 return true; | 171 return true; |
| 169 | 172 |
| 170 started_ = false; | 173 started_ = false; |
| 171 | 174 |
| 172 // First check if the process has already terminated. | 175 // First check if the process has already terminated. |
| 173 bool ret = base::WaitForSingleProcess(process_handle_, 0); | 176 bool ret = base::WaitForSingleProcess(process_handle_, 0); |
| 174 if (!ret) | 177 if (!ret) |
| 175 ret = base::KillProcess(process_handle_, 1, true); | 178 ret = base::KillProcess(process_handle_, 1, true); |
| 176 | 179 |
| 177 if (ret) { | 180 if (ret) { |
| 178 base::CloseProcessHandle(process_handle_); | 181 base::CloseProcessHandle(process_handle_); |
| 179 process_handle_ = base::kNullProcessHandle; | 182 process_handle_ = base::kNullProcessHandle; |
| 180 } else { | 183 } else { |
| 181 VLOG(1) << "Kill failed?"; | 184 VLOG(1) << "Kill failed?"; |
| 182 } | 185 } |
| 183 | 186 |
| 187 allowed_port_.reset(); | |
| 188 | |
| 184 return ret; | 189 return ret; |
| 185 } | 190 } |
| 186 | 191 |
| 187 const HostPortPair& TestServer::host_port_pair() const { | 192 const HostPortPair& TestServer::host_port_pair() const { |
| 188 DCHECK(started_); | 193 DCHECK(started_); |
| 189 return host_port_pair_; | 194 return host_port_pair_; |
| 190 } | 195 } |
| 191 | 196 |
| 192 const DictionaryValue& TestServer::server_data() const { | 197 const DictionaryValue& TestServer::server_data() const { |
| 193 DCHECK(started_); | 198 DCHECK(started_); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 } | 409 } |
| 405 if ((port <= 0) || (port > kuint16max)) { | 410 if ((port <= 0) || (port > kuint16max)) { |
| 406 LOG(ERROR) << "Invalid port value: " << port; | 411 LOG(ERROR) << "Invalid port value: " << port; |
| 407 return false; | 412 return false; |
| 408 } | 413 } |
| 409 host_port_pair_.set_port(port); | 414 host_port_pair_.set_port(port); |
| 410 return true; | 415 return true; |
| 411 } | 416 } |
| 412 | 417 |
| 413 } // namespace net | 418 } // namespace net |
| OLD | NEW |