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

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

Issue 9369029: Add '--host' option to testserver.py and expose it via a new TestServer constructor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Integrate the definition of kLocalhost to facilitate follow-up CLs. Created 8 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
OLDNEW
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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 case CERT_MISMATCHED_NAME: 74 case CERT_MISMATCHED_NAME:
75 return FilePath(FILE_PATH_LITERAL("ok_cert.pem")); 75 return FilePath(FILE_PATH_LITERAL("ok_cert.pem"));
76 case CERT_EXPIRED: 76 case CERT_EXPIRED:
77 return FilePath(FILE_PATH_LITERAL("expired_cert.pem")); 77 return FilePath(FILE_PATH_LITERAL("expired_cert.pem"));
78 default: 78 default:
79 NOTREACHED(); 79 NOTREACHED();
80 } 80 }
81 return FilePath(); 81 return FilePath();
82 } 82 }
83 83
84 const char* TestServer::kLocalhost = "127.0.0.1";
85
84 TestServer::TestServer(Type type, const FilePath& document_root) 86 TestServer::TestServer(Type type, const FilePath& document_root)
85 : type_(type), 87 : type_(type),
86 started_(false), 88 started_(false),
87 log_to_console_(false) { 89 log_to_console_(false) {
88 Init(document_root); 90 Init("127.0.0.1", document_root);
91 }
92
93 TestServer::TestServer(Type type,
94 const std::string& host,
95 const FilePath& document_root)
96 : type_(type),
97 started_(false),
98 log_to_console_(false) {
99 Init(host, document_root);
89 } 100 }
90 101
91 TestServer::TestServer(const HTTPSOptions& https_options, 102 TestServer::TestServer(const HTTPSOptions& https_options,
92 const FilePath& document_root) 103 const FilePath& document_root)
93 : https_options_(https_options), 104 : https_options_(https_options),
94 type_(TYPE_HTTPS), 105 type_(TYPE_HTTPS),
95 started_(false), 106 started_(false),
96 log_to_console_(false) { 107 log_to_console_(false) {
97 Init(document_root); 108 Init(GetHostname(TYPE_HTTPS, https_options), document_root);
98 } 109 }
99 110
100 TestServer::~TestServer() { 111 TestServer::~TestServer() {
101 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 112 TestRootCerts* root_certs = TestRootCerts::GetInstance();
102 root_certs->Clear(); 113 root_certs->Clear();
103 Stop(); 114 Stop();
104 } 115 }
105 116
106 bool TestServer::Start() { 117 bool TestServer::Start() {
107 if (type_ == TYPE_HTTPS) { 118 if (type_ == TYPE_HTTPS) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 new_file_path += "replace_text="; 269 new_file_path += "replace_text=";
259 new_file_path += base64_old; 270 new_file_path += base64_old;
260 new_file_path += ":"; 271 new_file_path += ":";
261 new_file_path += base64_new; 272 new_file_path += base64_new;
262 } 273 }
263 274
264 *replacement_path = new_file_path; 275 *replacement_path = new_file_path;
265 return true; 276 return true;
266 } 277 }
267 278
268 void TestServer::Init(const FilePath& document_root) { 279 void TestServer::Init(const std::string& host, const FilePath& document_root) {
269 // At this point, the port that the testserver will listen on is unknown. 280 // At this point, the port that the testserver will listen on is unknown.
270 // The testserver will listen on an ephemeral port, and write the port 281 // The testserver will listen on an ephemeral port, and write the port
271 // number out over a pipe that this TestServer object will read from. Once 282 // number out over a pipe that this TestServer object will read from. Once
272 // that is complete, the host_port_pair_ will contain the actual port. 283 // that is complete, the host_port_pair_ will contain the actual port.
273 host_port_pair_ = HostPortPair(GetHostname(type_, https_options_), 0); 284 host_port_pair_ = HostPortPair(host, 0);
274 process_handle_ = base::kNullProcessHandle; 285 process_handle_ = base::kNullProcessHandle;
275 286
276 FilePath src_dir; 287 FilePath src_dir;
277 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); 288 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
278 289
279 document_root_ = src_dir.Append(document_root); 290 document_root_ = src_dir.Append(document_root);
280 291
281 certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net")) 292 certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net"))
282 .Append(FILE_PATH_LITERAL("data")) 293 .Append(FILE_PATH_LITERAL("data"))
283 .Append(FILE_PATH_LITERAL("ssl")) 294 .Append(FILE_PATH_LITERAL("ssl"))
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 FilePath TestServer::GetRootCertificatePath() const { 364 FilePath TestServer::GetRootCertificatePath() const {
354 return certificates_dir_.AppendASCII("root_ca_cert.crt"); 365 return certificates_dir_.AppendASCII("root_ca_cert.crt");
355 } 366 }
356 367
357 bool TestServer::LoadTestRootCert() { 368 bool TestServer::LoadTestRootCert() {
358 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 369 TestRootCerts* root_certs = TestRootCerts::GetInstance();
359 return root_certs->AddFromFile(GetRootCertificatePath()); 370 return root_certs->AddFromFile(GetRootCertificatePath());
360 } 371 }
361 372
362 bool TestServer::AddCommandLineArguments(CommandLine* command_line) const { 373 bool TestServer::AddCommandLineArguments(CommandLine* command_line) const {
374 command_line->AppendArg("--host=" + host_port_pair_.host());
363 command_line->AppendArg("--port=" + 375 command_line->AppendArg("--port=" +
364 base::IntToString(host_port_pair_.port())); 376 base::IntToString(host_port_pair_.port()));
365 command_line->AppendArgNative(FILE_PATH_LITERAL("--data-dir=") + 377 command_line->AppendArgNative(FILE_PATH_LITERAL("--data-dir=") +
366 document_root_.value()); 378 document_root_.value());
367 379
368 if (VLOG_IS_ON(1) || log_to_console_) { 380 if (VLOG_IS_ON(1) || log_to_console_) {
369 command_line->AppendArg("--log-to-console"); 381 command_line->AppendArg("--log-to-console");
370 } 382 }
371 383
372 if (type_ == TYPE_FTP) { 384 if (type_ == TYPE_FTP) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 command_line->AppendArg(kBulkCipherSwitch + "=3des"); 428 command_line->AppendArg(kBulkCipherSwitch + "=3des");
417 429
418 if (https_options_.record_resume) 430 if (https_options_.record_resume)
419 command_line->AppendArg("--https-record-resume"); 431 command_line->AppendArg("--https-record-resume");
420 } 432 }
421 433
422 return true; 434 return true;
423 } 435 }
424 436
425 } // namespace net 437 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698