OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/spawned_test_server/local_test_server.h" | 5 #include "net/test/spawned_test_server/local_test_server.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 Stop(); | 77 Stop(); |
78 } | 78 } |
79 | 79 |
80 bool LocalTestServer::GetTestServerPath(base::FilePath* testserver_path) const { | 80 bool LocalTestServer::GetTestServerPath(base::FilePath* testserver_path) const { |
81 base::FilePath testserver_dir; | 81 base::FilePath testserver_dir; |
82 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { | 82 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { |
83 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 83 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
84 return false; | 84 return false; |
85 } | 85 } |
86 testserver_dir = testserver_dir.Append(FILE_PATH_LITERAL("net")) | 86 testserver_dir = testserver_dir.Append(FILE_PATH_LITERAL("net")) |
87 .Append(FILE_PATH_LITERAL("tools")) | 87 .Append(FILE_PATH_LITERAL("tools")) |
88 .Append(FILE_PATH_LITERAL("testserver")); | 88 .Append(FILE_PATH_LITERAL("testserver")); |
89 *testserver_path = testserver_dir.Append(FILE_PATH_LITERAL("testserver.py")); | 89 *testserver_path = testserver_dir.Append(FILE_PATH_LITERAL("testserver.py")); |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 bool LocalTestServer::Start() { | 93 bool LocalTestServer::Start() { |
94 return StartInBackground() && BlockUntilStarted(); | 94 return StartInBackground() && BlockUntilStarted(); |
95 } | 95 } |
96 | 96 |
97 bool LocalTestServer::StartInBackground() { | 97 bool LocalTestServer::StartInBackground() { |
98 // Get path to Python server script. | 98 // Get path to Python server script. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // number out over a pipe that this TestServer object will read from. Once | 154 // number out over a pipe that this TestServer object will read from. Once |
155 // that is complete, the host port pair will contain the actual port. | 155 // that is complete, the host port pair will contain the actual port. |
156 DCHECK(!GetPort()); | 156 DCHECK(!GetPort()); |
157 process_handle_ = base::kNullProcessHandle; | 157 process_handle_ = base::kNullProcessHandle; |
158 | 158 |
159 base::FilePath src_dir; | 159 base::FilePath src_dir; |
160 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) | 160 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
161 return false; | 161 return false; |
162 SetResourcePath(src_dir.Append(document_root), | 162 SetResourcePath(src_dir.Append(document_root), |
163 src_dir.AppendASCII("net") | 163 src_dir.AppendASCII("net") |
164 .AppendASCII("data") | 164 .AppendASCII("data") |
165 .AppendASCII("ssl") | 165 .AppendASCII("ssl") |
166 .AppendASCII("certificates")); | 166 .AppendASCII("certificates")); |
167 return true; | 167 return true; |
168 } | 168 } |
169 | 169 |
170 bool LocalTestServer::SetPythonPath() const { | 170 bool LocalTestServer::SetPythonPath() const { |
171 base::FilePath third_party_dir; | 171 base::FilePath third_party_dir; |
172 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { | 172 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { |
173 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 173 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
174 return false; | 174 return false; |
175 } | 175 } |
176 third_party_dir = third_party_dir.AppendASCII("third_party"); | 176 third_party_dir = third_party_dir.AppendASCII("third_party"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 it.Advance()) { | 209 it.Advance()) { |
210 const base::Value& value = it.value(); | 210 const base::Value& value = it.value(); |
211 const std::string& key = it.key(); | 211 const std::string& key = it.key(); |
212 | 212 |
213 // Add arguments from a list. | 213 // Add arguments from a list. |
214 if (value.IsType(base::Value::TYPE_LIST)) { | 214 if (value.IsType(base::Value::TYPE_LIST)) { |
215 const base::ListValue* list = NULL; | 215 const base::ListValue* list = NULL; |
216 if (!value.GetAsList(&list) || !list || list->empty()) | 216 if (!value.GetAsList(&list) || !list || list->empty()) |
217 return false; | 217 return false; |
218 for (base::ListValue::const_iterator list_it = list->begin(); | 218 for (base::ListValue::const_iterator list_it = list->begin(); |
219 list_it != list->end(); ++list_it) { | 219 list_it != list->end(); |
| 220 ++list_it) { |
220 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line)) | 221 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line)) |
221 return false; | 222 return false; |
222 } | 223 } |
223 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) { | 224 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) { |
224 return false; | 225 return false; |
225 } | 226 } |
226 } | 227 } |
227 | 228 |
228 // Append the appropriate server type argument. | 229 // Append the appropriate server type argument. |
229 switch (type()) { | 230 switch (type()) { |
230 case TYPE_HTTP: // The default type is HTTP, no argument required. | 231 case TYPE_HTTP: // The default type is HTTP, no argument required. |
231 break; | 232 break; |
232 case TYPE_HTTPS: | 233 case TYPE_HTTPS: |
233 command_line->AppendArg("--https"); | 234 command_line->AppendArg("--https"); |
234 break; | 235 break; |
(...skipping 15 matching lines...) Expand all Loading... |
250 break; | 251 break; |
251 default: | 252 default: |
252 NOTREACHED(); | 253 NOTREACHED(); |
253 return false; | 254 return false; |
254 } | 255 } |
255 | 256 |
256 return true; | 257 return true; |
257 } | 258 } |
258 | 259 |
259 } // namespace net | 260 } // namespace net |
OLD | NEW |