OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/local_test_server.h" | 5 #include "net/test/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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 testserver_dir = testserver_dir | 89 testserver_dir = testserver_dir |
90 .Append(FILE_PATH_LITERAL("net")) | 90 .Append(FILE_PATH_LITERAL("net")) |
91 .Append(FILE_PATH_LITERAL("tools")) | 91 .Append(FILE_PATH_LITERAL("tools")) |
92 .Append(FILE_PATH_LITERAL("testserver")); | 92 .Append(FILE_PATH_LITERAL("testserver")); |
93 *directory = testserver_dir; | 93 *directory = testserver_dir; |
94 return true; | 94 return true; |
95 } | 95 } |
96 | 96 |
| 97 bool LocalTestServer::GetTestServerPath(FilePath* testserver_path) const { |
| 98 if (!GetTestServerDirectory(testserver_path)) |
| 99 return false; |
| 100 *testserver_path = testserver_path->Append(FILE_PATH_LITERAL( |
| 101 "testserver.py")); |
| 102 return true; |
| 103 } |
| 104 |
97 bool LocalTestServer::Start() { | 105 bool LocalTestServer::Start() { |
98 // Get path to Python server script. | 106 // Get path to Python server script. |
99 FilePath testserver_path; | 107 FilePath testserver_path; |
100 if (!GetTestServerDirectory(&testserver_path)) | 108 if (!GetTestServerPath(&testserver_path)) |
101 return false; | 109 return false; |
102 testserver_path = | |
103 testserver_path.Append(FILE_PATH_LITERAL("testserver.py")); | |
104 | 110 |
105 if (!SetPythonPath()) | 111 if (!SetPythonPath()) |
106 return false; | 112 return false; |
107 | 113 |
108 if (!LaunchPython(testserver_path)) | 114 if (!LaunchPython(testserver_path)) |
109 return false; | 115 return false; |
110 | 116 |
111 if (!WaitToStart()) { | 117 if (!WaitToStart()) { |
112 Stop(); | 118 Stop(); |
113 return false; | 119 return false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) | 158 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
153 return false; | 159 return false; |
154 SetResourcePath(src_dir.Append(document_root), | 160 SetResourcePath(src_dir.Append(document_root), |
155 src_dir.AppendASCII("net") | 161 src_dir.AppendASCII("net") |
156 .AppendASCII("data") | 162 .AppendASCII("data") |
157 .AppendASCII("ssl") | 163 .AppendASCII("ssl") |
158 .AppendASCII("certificates")); | 164 .AppendASCII("certificates")); |
159 return true; | 165 return true; |
160 } | 166 } |
161 | 167 |
| 168 bool LocalTestServer::SetPythonPath() const { |
| 169 return SetPythonPathStatic(); |
| 170 } |
| 171 |
162 // static | 172 // static |
163 bool LocalTestServer::SetPythonPath() { | 173 bool LocalTestServer::SetPythonPathStatic() { |
164 FilePath third_party_dir; | 174 FilePath third_party_dir; |
165 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { | 175 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { |
166 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 176 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
167 return false; | 177 return false; |
168 } | 178 } |
169 third_party_dir = third_party_dir.AppendASCII("third_party"); | 179 third_party_dir = third_party_dir.AppendASCII("third_party"); |
170 | 180 |
171 // For simplejson. (simplejson, unlike all the other Python modules | 181 // For simplejson. (simplejson, unlike all the other Python modules |
172 // we include, doesn't have an extra 'simplejson' directory, so we | 182 // we include, doesn't have an extra 'simplejson' directory, so we |
173 // need to include its parent directory, i.e. third_party_dir). | 183 // need to include its parent directory, i.e. third_party_dir). |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 std::string("--auth-token") + "=" + BaseTestServer::kGDataAuthToken); | 258 std::string("--auth-token") + "=" + BaseTestServer::kGDataAuthToken); |
249 break; | 259 break; |
250 default: | 260 default: |
251 NOTREACHED(); | 261 NOTREACHED(); |
252 return false; | 262 return false; |
253 } | 263 } |
254 | 264 |
255 return true; | 265 return true; |
256 } | 266 } |
257 | 267 |
| 268 void LocalTestServer::AddPythonArguments(const FilePath& testserver_path, |
| 269 CommandLine* command_line) const { |
| 270 // Make python stdout and stderr unbuffered, to prevent incomplete stderr on |
| 271 // win bots, and also fix mixed up ordering of stdout and stderr. |
| 272 command_line->AppendSwitch("-u"); |
| 273 |
| 274 command_line->AppendArgPath(testserver_path); |
| 275 } |
| 276 |
258 } // namespace net | 277 } // namespace net |
OLD | NEW |