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

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

Issue 6339012: More net/ method ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More done while waiting for previous patch to clear Created 9 years, 10 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/socket/ssl_server_socket_nss.cc ('k') | net/url_request/url_request_about_job.h » ('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) 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 started_(false) { 98 started_(false) {
99 Init(document_root); 99 Init(document_root);
100 } 100 }
101 101
102 TestServer::~TestServer() { 102 TestServer::~TestServer() {
103 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 103 TestRootCerts* root_certs = TestRootCerts::GetInstance();
104 root_certs->Clear(); 104 root_certs->Clear();
105 Stop(); 105 Stop();
106 } 106 }
107 107
108 void TestServer::Init(const FilePath& document_root) {
109 // At this point, the port that the testserver will listen on is unknown.
110 // The testserver will listen on an ephemeral port, and write the port
111 // number out over a pipe that this TestServer object will read from. Once
112 // that is complete, the host_port_pair_ will contain the actual port.
113 host_port_pair_ = HostPortPair(GetHostname(type_, https_options_), 0);
114 process_handle_ = base::kNullProcessHandle;
115
116 FilePath src_dir;
117 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
118
119 document_root_ = src_dir.Append(document_root);
120
121 certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net"))
122 .Append(FILE_PATH_LITERAL("data"))
123 .Append(FILE_PATH_LITERAL("ssl"))
124 .Append(FILE_PATH_LITERAL("certificates"));
125 }
126
127 bool TestServer::Start() { 108 bool TestServer::Start() {
128 if (type_ == TYPE_HTTPS) { 109 if (type_ == TYPE_HTTPS) {
129 if (!LoadTestRootCert()) 110 if (!LoadTestRootCert())
130 return false; 111 return false;
131 } 112 }
132 113
133 // Get path to python server script 114 // Get path to python server script
134 FilePath testserver_path; 115 FilePath testserver_path;
135 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) { 116 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) {
136 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; 117 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 new_file_path += "replace_text="; 250 new_file_path += "replace_text=";
270 new_file_path += base64_old; 251 new_file_path += base64_old;
271 new_file_path += ":"; 252 new_file_path += ":";
272 new_file_path += base64_new; 253 new_file_path += base64_new;
273 } 254 }
274 255
275 *replacement_path = new_file_path; 256 *replacement_path = new_file_path;
276 return true; 257 return true;
277 } 258 }
278 259
260 void TestServer::Init(const FilePath& document_root) {
261 // At this point, the port that the testserver will listen on is unknown.
262 // The testserver will listen on an ephemeral port, and write the port
263 // number out over a pipe that this TestServer object will read from. Once
264 // that is complete, the host_port_pair_ will contain the actual port.
265 host_port_pair_ = HostPortPair(GetHostname(type_, https_options_), 0);
266 process_handle_ = base::kNullProcessHandle;
267
268 FilePath src_dir;
269 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
270
271 document_root_ = src_dir.Append(document_root);
272
273 certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net"))
274 .Append(FILE_PATH_LITERAL("data"))
275 .Append(FILE_PATH_LITERAL("ssl"))
276 .Append(FILE_PATH_LITERAL("certificates"));
277 }
278
279 bool TestServer::SetPythonPath() { 279 bool TestServer::SetPythonPath() {
280 FilePath third_party_dir; 280 FilePath third_party_dir;
281 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { 281 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) {
282 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; 282 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
283 return false; 283 return false;
284 } 284 }
285 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); 285 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party"));
286 286
287 // For simplejson. (simplejson, unlike all the other python modules 287 // For simplejson. (simplejson, unlike all the other python modules
288 // we include, doesn't have an extra 'simplejson' directory, so we 288 // we include, doesn't have an extra 'simplejson' directory, so we
(...skipping 11 matching lines...) Expand all
300 } 300 }
301 301
302 AppendToPythonPath(pyproto_code_dir); 302 AppendToPythonPath(pyproto_code_dir);
303 AppendToPythonPath(pyproto_code_dir.Append(FILE_PATH_LITERAL("sync_pb"))); 303 AppendToPythonPath(pyproto_code_dir.Append(FILE_PATH_LITERAL("sync_pb")));
304 AppendToPythonPath(pyproto_code_dir.Append( 304 AppendToPythonPath(pyproto_code_dir.Append(
305 FILE_PATH_LITERAL("device_management_pb"))); 305 FILE_PATH_LITERAL("device_management_pb")));
306 306
307 return true; 307 return true;
308 } 308 }
309 309
310 bool TestServer::ParseServerData(const std::string& server_data) {
311 VLOG(1) << "Server data: " << server_data;
312 base::JSONReader json_reader;
313 scoped_ptr<Value> value(json_reader.JsonToValue(server_data, true, false));
314 if (!value.get() ||
315 !value->IsType(Value::TYPE_DICTIONARY)) {
316 LOG(ERROR) << "Could not parse server data: "
317 << json_reader.GetErrorMessage();
318 return false;
319 }
320 server_data_.reset(static_cast<DictionaryValue*>(value.release()));
321 int port = 0;
322 if (!server_data_->GetInteger("port", &port)) {
323 LOG(ERROR) << "Could not find port value";
324 return false;
325 }
326 if ((port <= 0) || (port > kuint16max)) {
327 LOG(ERROR) << "Invalid port value: " << port;
328 return false;
329 }
330 host_port_pair_.set_port(port);
331 return true;
332 }
333
310 FilePath TestServer::GetRootCertificatePath() { 334 FilePath TestServer::GetRootCertificatePath() {
311 return certificates_dir_.AppendASCII("root_ca_cert.crt"); 335 return certificates_dir_.AppendASCII("root_ca_cert.crt");
312 } 336 }
313 337
314 bool TestServer::LoadTestRootCert() { 338 bool TestServer::LoadTestRootCert() {
315 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 339 TestRootCerts* root_certs = TestRootCerts::GetInstance();
316 return root_certs->AddFromFile(GetRootCertificatePath()); 340 return root_certs->AddFromFile(GetRootCertificatePath());
317 } 341 }
318 342
319 bool TestServer::AddCommandLineArguments(CommandLine* command_line) const { 343 bool TestServer::AddCommandLineArguments(CommandLine* command_line) const {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes128"); 382 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes128");
359 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) 383 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256)
360 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); 384 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256");
361 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) 385 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES)
362 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); 386 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des");
363 } 387 }
364 388
365 return true; 389 return true;
366 } 390 }
367 391
368 bool TestServer::ParseServerData(const std::string& server_data) {
369 VLOG(1) << "Server data: " << server_data;
370 base::JSONReader json_reader;
371 scoped_ptr<Value> value(json_reader.JsonToValue(server_data, true, false));
372 if (!value.get() ||
373 !value->IsType(Value::TYPE_DICTIONARY)) {
374 LOG(ERROR) << "Could not parse server data: "
375 << json_reader.GetErrorMessage();
376 return false;
377 }
378 server_data_.reset(static_cast<DictionaryValue*>(value.release()));
379 int port = 0;
380 if (!server_data_->GetInteger("port", &port)) {
381 LOG(ERROR) << "Could not find port value";
382 return false;
383 }
384 if ((port <= 0) || (port > kuint16max)) {
385 LOG(ERROR) << "Invalid port value: " << port;
386 return false;
387 }
388 host_port_pair_.set_port(port);
389 return true;
390 }
391
392 } // namespace net 392 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_server_socket_nss.cc ('k') | net/url_request/url_request_about_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698