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

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: Rebase 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
« no previous file with comments | « net/test/local_test_server.h ('k') | net/test/remote_test_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::GetTestServerPath(FilePath* testserver_path) const {
81 bool LocalTestServer::GetTestServerDirectory(FilePath* directory) {
82 // Get path to python server script.
83 FilePath testserver_dir; 81 FilePath testserver_dir;
84 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { 82 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) {
85 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; 83 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
86 return false; 84 return false;
87 } 85 }
88 86 testserver_dir = testserver_dir.Append(FILE_PATH_LITERAL("net"))
89 testserver_dir = testserver_dir 87 .Append(FILE_PATH_LITERAL("tools"))
90 .Append(FILE_PATH_LITERAL("net")) 88 .Append(FILE_PATH_LITERAL("testserver"));
91 .Append(FILE_PATH_LITERAL("tools")) 89 *testserver_path = testserver_dir.Append(FILE_PATH_LITERAL("testserver.py"));
92 .Append(FILE_PATH_LITERAL("testserver"));
93 *directory = testserver_dir;
94 return true; 90 return true;
95 } 91 }
96 92
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
105 bool LocalTestServer::Start() { 93 bool LocalTestServer::Start() {
106 // Get path to Python server script. 94 // Get path to Python server script.
107 FilePath testserver_path; 95 FilePath testserver_path;
108 if (!GetTestServerPath(&testserver_path)) 96 if (!GetTestServerPath(&testserver_path))
109 return false; 97 return false;
110 98
111 if (!SetPythonPath()) 99 if (!SetPythonPath())
112 return false; 100 return false;
113 101
114 if (!LaunchPython(testserver_path)) 102 if (!LaunchPython(testserver_path))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return false; 147 return false;
160 SetResourcePath(src_dir.Append(document_root), 148 SetResourcePath(src_dir.Append(document_root),
161 src_dir.AppendASCII("net") 149 src_dir.AppendASCII("net")
162 .AppendASCII("data") 150 .AppendASCII("data")
163 .AppendASCII("ssl") 151 .AppendASCII("ssl")
164 .AppendASCII("certificates")); 152 .AppendASCII("certificates"));
165 return true; 153 return true;
166 } 154 }
167 155
168 bool LocalTestServer::SetPythonPath() const { 156 bool LocalTestServer::SetPythonPath() const {
169 return SetPythonPathStatic();
170 }
171
172 // static
173 bool LocalTestServer::SetPythonPathStatic() {
174 FilePath third_party_dir; 157 FilePath third_party_dir;
175 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { 158 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) {
176 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; 159 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
177 return false; 160 return false;
178 } 161 }
179 third_party_dir = third_party_dir.AppendASCII("third_party"); 162 third_party_dir = third_party_dir.AppendASCII("third_party");
180 163
181 // For simplejson. (simplejson, unlike all the other Python modules 164 // For simplejson. (simplejson, unlike all the other Python modules
182 // we include, doesn't have an extra 'simplejson' directory, so we 165 // we include, doesn't have an extra 'simplejson' directory, so we
183 // need to include its parent directory, i.e. third_party_dir). 166 // need to include its parent directory, i.e. third_party_dir).
184 AppendToPythonPath(third_party_dir); 167 AppendToPythonPath(third_party_dir);
185 168
186 AppendToPythonPath(third_party_dir.AppendASCII("tlslite")); 169 AppendToPythonPath(third_party_dir.AppendASCII("tlslite"));
187 AppendToPythonPath( 170 AppendToPythonPath(
188 third_party_dir.AppendASCII("pyftpdlib").AppendASCII("src")); 171 third_party_dir.AppendASCII("pyftpdlib").AppendASCII("src"));
189 AppendToPythonPath( 172 AppendToPythonPath(
190 third_party_dir.AppendASCII("pywebsocket").AppendASCII("src")); 173 third_party_dir.AppendASCII("pywebsocket").AppendASCII("src"));
191 174
192 // Locate the Python code generated by the protocol buffers compiler. 175 // Locate the Python code generated by the protocol buffers compiler.
193 FilePath pyproto_dir; 176 FilePath pyproto_dir;
194 if (!GetPyProtoPath(&pyproto_dir)) { 177 if (!GetPyProtoPath(&pyproto_dir)) {
195 LOG(WARNING) << "Cannot find pyproto dir for generated code. " 178 LOG(WARNING) << "Cannot find pyproto dir for generated code. "
196 << "Testserver features that rely on it will not work"; 179 << "Testserver features that rely on it will not work";
197 return true; 180 return true;
198 } 181 }
182 AppendToPythonPath(pyproto_dir);
199 183
200 AppendToPythonPath(pyproto_dir); 184 // TODO(cloud_policy): Move this out of net/, since net/ should not have to
201 AppendToPythonPath(pyproto_dir.AppendASCII("sync").AppendASCII("protocol")); 185 // depend on chrome/. See http://crbug.com/119403.
202 AppendToPythonPath(pyproto_dir.AppendASCII("chrome") 186 AppendToPythonPath(pyproto_dir.AppendASCII("chrome")
203 .AppendASCII("browser") 187 .AppendASCII("browser")
204 .AppendASCII("policy") 188 .AppendASCII("policy")
205 .AppendASCII("proto")); 189 .AppendASCII("proto"));
206 190
207 return true; 191 return true;
208 } 192 }
209 193
210 bool LocalTestServer::AddCommandLineArguments(CommandLine* command_line) const { 194 bool LocalTestServer::AddCommandLineArguments(CommandLine* command_line) const {
211 base::DictionaryValue arguments_dict; 195 base::DictionaryValue arguments_dict;
(...skipping 16 matching lines...) Expand all
228 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line)) 212 if (!AppendArgumentFromJSONValue(key, *(*list_it), command_line))
229 return false; 213 return false;
230 } 214 }
231 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) { 215 } else if (!AppendArgumentFromJSONValue(key, value, command_line)) {
232 return false; 216 return false;
233 } 217 }
234 } 218 }
235 219
236 // Append the appropriate server type argument. 220 // Append the appropriate server type argument.
237 switch (type()) { 221 switch (type()) {
238 case TYPE_HTTP: 222 case TYPE_HTTP: // The default type is HTTP, no argument required.
223 break;
239 case TYPE_HTTPS: 224 case TYPE_HTTPS:
240 // The default type is HTTP, no argument required. 225 command_line->AppendArg("--https");
241 break; 226 break;
242 case TYPE_WS: 227 case TYPE_WS:
243 case TYPE_WSS: 228 case TYPE_WSS:
244 command_line->AppendArg("--websocket"); 229 command_line->AppendArg("--websocket");
245 break; 230 break;
246 case TYPE_FTP: 231 case TYPE_FTP:
247 command_line->AppendArg("-f"); 232 command_line->AppendArg("--ftp");
248 break;
249 case TYPE_SYNC:
250 command_line->AppendArg("--sync");
251 break; 233 break;
252 case TYPE_TCP_ECHO: 234 case TYPE_TCP_ECHO:
253 command_line->AppendArg("--tcp-echo"); 235 command_line->AppendArg("--tcp-echo");
254 break; 236 break;
255 case TYPE_UDP_ECHO: 237 case TYPE_UDP_ECHO:
256 command_line->AppendArg("--udp-echo"); 238 command_line->AppendArg("--udp-echo");
257 break; 239 break;
258 case TYPE_BASIC_AUTH_PROXY: 240 case TYPE_BASIC_AUTH_PROXY:
259 command_line->AppendArg("--basic-auth-proxy"); 241 command_line->AppendArg("--basic-auth-proxy");
260 break; 242 break;
261 default: 243 default:
262 NOTREACHED(); 244 NOTREACHED();
263 return false; 245 return false;
264 } 246 }
265 247
266 return true; 248 return true;
267 } 249 }
268 250
269 } // namespace net 251 } // namespace net
OLDNEW
« no previous file with comments | « net/test/local_test_server.h ('k') | net/test/remote_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698