Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: net/test/local_test_server.cc

Issue 11971025: [sync] Divorce python sync test server chromiumsync.py from testserver.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Philippe's comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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/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"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const FilePath& document_root) 70 const FilePath& document_root)
71 : BaseTestServer(type, ssl_options) { 71 : BaseTestServer(type, ssl_options) {
72 if (!Init(document_root)) 72 if (!Init(document_root))
73 NOTREACHED(); 73 NOTREACHED();
74 } 74 }
75 75
76 LocalTestServer::~LocalTestServer() { 76 LocalTestServer::~LocalTestServer() {
77 Stop(); 77 Stop();
78 } 78 }
79 79
80 // static 80 bool LocalTestServer::GetTestServerDirectory(FilePath* directory) const {
81 bool LocalTestServer::GetTestServerDirectory(FilePath* directory) {
82 // Get path to python server script. 81 // Get path to python server script.
83 FilePath testserver_dir; 82 FilePath testserver_dir;
84 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { 83 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) {
85 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; 84 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
86 return false; 85 return false;
87 } 86 }
88 87
89 testserver_dir = testserver_dir 88 testserver_dir = testserver_dir
90 .Append(FILE_PATH_LITERAL("net")) 89 .Append(FILE_PATH_LITERAL("net"))
91 .Append(FILE_PATH_LITERAL("tools")) 90 .Append(FILE_PATH_LITERAL("tools"))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return false; 158 return false;
160 SetResourcePath(src_dir.Append(document_root), 159 SetResourcePath(src_dir.Append(document_root),
161 src_dir.AppendASCII("net") 160 src_dir.AppendASCII("net")
162 .AppendASCII("data") 161 .AppendASCII("data")
163 .AppendASCII("ssl") 162 .AppendASCII("ssl")
164 .AppendASCII("certificates")); 163 .AppendASCII("certificates"));
165 return true; 164 return true;
166 } 165 }
167 166
168 bool LocalTestServer::SetPythonPath() const { 167 bool LocalTestServer::SetPythonPath() const {
169 return SetPythonPathStatic();
170 }
171
172 // static
173 bool LocalTestServer::SetPythonPathStatic() {
174 FilePath third_party_dir; 168 FilePath third_party_dir;
175 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { 169 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) {
176 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; 170 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
177 return false; 171 return false;
178 } 172 }
179 third_party_dir = third_party_dir.AppendASCII("third_party"); 173 third_party_dir = third_party_dir.AppendASCII("third_party");
180 174
181 // For simplejson. (simplejson, unlike all the other Python modules 175 // For simplejson. (simplejson, unlike all the other Python modules
182 // we include, doesn't have an extra 'simplejson' directory, so we 176 // we include, doesn't have an extra 'simplejson' directory, so we
183 // need to include its parent directory, i.e. third_party_dir). 177 // need to include its parent directory, i.e. third_party_dir).
184 AppendToPythonPath(third_party_dir); 178 AppendToPythonPath(third_party_dir);
185 179
186 AppendToPythonPath(third_party_dir.AppendASCII("tlslite")); 180 AppendToPythonPath(third_party_dir.AppendASCII("tlslite"));
187 AppendToPythonPath( 181 AppendToPythonPath(
188 third_party_dir.AppendASCII("pyftpdlib").AppendASCII("src")); 182 third_party_dir.AppendASCII("pyftpdlib").AppendASCII("src"));
189 AppendToPythonPath( 183 AppendToPythonPath(
190 third_party_dir.AppendASCII("pywebsocket").AppendASCII("src")); 184 third_party_dir.AppendASCII("pywebsocket").AppendASCII("src"));
191 185
192 // Locate the Python code generated by the protocol buffers compiler. 186 // Locate the Python code generated by the protocol buffers compiler.
193 FilePath pyproto_dir; 187 FilePath pyproto_dir;
194 if (!GetPyProtoPath(&pyproto_dir)) { 188 if (!GetPyProtoPath(&pyproto_dir)) {
195 LOG(WARNING) << "Cannot find pyproto dir for generated code. " 189 LOG(WARNING) << "Cannot find pyproto dir for generated code. "
196 << "Testserver features that rely on it will not work"; 190 << "Testserver features that rely on it will not work";
197 return true; 191 return true;
198 } 192 }
193 AppendToPythonPath(pyproto_dir);
199 194
200 AppendToPythonPath(pyproto_dir); 195 // TODO(cloud_policy): Move this out of net/, since net/ should not have to
201 AppendToPythonPath(pyproto_dir.AppendASCII("sync").AppendASCII("protocol")); 196 // depend on chrome/. See http://crbug.com/119403.
202 AppendToPythonPath(pyproto_dir.AppendASCII("chrome") 197 AppendToPythonPath(pyproto_dir.AppendASCII("chrome")
203 .AppendASCII("browser") 198 .AppendASCII("browser")
204 .AppendASCII("policy") 199 .AppendASCII("policy")
205 .AppendASCII("proto")); 200 .AppendASCII("proto"));
206 201
207 return true; 202 return true;
208 } 203 }
209 204
210 bool LocalTestServer::AddCommandLineArguments(CommandLine* command_line) const { 205 bool LocalTestServer::AddCommandLineArguments(CommandLine* command_line) const {
211 base::DictionaryValue arguments_dict; 206 base::DictionaryValue arguments_dict;
(...skipping 16 matching lines...) Expand all
228 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line)) 223 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line))
229 return false; 224 return false;
230 } 225 }
231 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) { 226 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) {
232 return false; 227 return false;
233 } 228 }
234 } 229 }
235 230
236 // Append the appropriate server type argument. 231 // Append the appropriate server type argument.
237 switch (type()) { 232 switch (type()) {
238 case TYPE_HTTP: 233 case TYPE_HTTP: // The default type is HTTP, no argument required.
234 break;
239 case TYPE_HTTPS: 235 case TYPE_HTTPS:
240 // The default type is HTTP, no argument required. 236 command_line->AppendArg("--https");
241 break; 237 break;
242 case TYPE_WS: 238 case TYPE_WS:
243 case TYPE_WSS: 239 case TYPE_WSS:
244 command_line->AppendArg("--websocket"); 240 command_line->AppendArg("--websocket");
245 break; 241 break;
246 case TYPE_FTP: 242 case TYPE_FTP:
247 command_line->AppendArg("-f"); 243 command_line->AppendArg("--ftp");
248 break;
249 case TYPE_SYNC:
250 command_line->AppendArg("--sync");
251 break; 244 break;
252 case TYPE_TCP_ECHO: 245 case TYPE_TCP_ECHO:
253 command_line->AppendArg("--tcp-echo"); 246 command_line->AppendArg("--tcp-echo");
254 break; 247 break;
255 case TYPE_UDP_ECHO: 248 case TYPE_UDP_ECHO:
256 command_line->AppendArg("--udp-echo"); 249 command_line->AppendArg("--udp-echo");
257 break; 250 break;
258 case TYPE_BASIC_AUTH_PROXY: 251 case TYPE_BASIC_AUTH_PROXY:
259 command_line->AppendArg("--basic-auth-proxy"); 252 command_line->AppendArg("--basic-auth-proxy");
260 break; 253 break;
261 default: 254 default:
262 NOTREACHED(); 255 NOTREACHED();
263 return false; 256 return false;
264 } 257 }
265 258
266 return true; 259 return true;
267 } 260 }
268 261
269 } // namespace net 262 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698