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

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: 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
« net/test/test_server.h ('K') | « net/test/test_server.h ('k') | no next file » | 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 (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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 default: 78 default:
79 NOTREACHED(); 79 NOTREACHED();
80 } 80 }
81 return FilePath(); 81 return FilePath();
82 } 82 }
83 83
84 TestServer::TestServer(Type type, const FilePath& document_root) 84 TestServer::TestServer(Type type, const FilePath& document_root)
85 : type_(type), 85 : type_(type),
86 started_(false), 86 started_(false),
87 log_to_console_(false) { 87 log_to_console_(false) {
88 Init(document_root); 88 Init("127.0.0.1", document_root);
89 }
90
91 TestServer::TestServer(Type type,
92 const std::string& host,
93 const FilePath& document_root)
94 : type_(type),
95 started_(false),
96 log_to_console_(false) {
97 Init(host, document_root);
89 } 98 }
90 99
91 TestServer::TestServer(const HTTPSOptions& https_options, 100 TestServer::TestServer(const HTTPSOptions& https_options,
92 const FilePath& document_root) 101 const FilePath& document_root)
93 : https_options_(https_options), 102 : https_options_(https_options),
94 type_(TYPE_HTTPS), 103 type_(TYPE_HTTPS),
95 started_(false), 104 started_(false),
96 log_to_console_(false) { 105 log_to_console_(false) {
97 Init(document_root); 106 Init(GetHostname(TYPE_HTTPS, https_options), document_root);
98 } 107 }
99 108
100 TestServer::~TestServer() { 109 TestServer::~TestServer() {
101 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 110 TestRootCerts* root_certs = TestRootCerts::GetInstance();
102 root_certs->Clear(); 111 root_certs->Clear();
103 Stop(); 112 Stop();
104 } 113 }
105 114
106 bool TestServer::Start() { 115 bool TestServer::Start() {
107 if (type_ == TYPE_HTTPS) { 116 if (type_ == TYPE_HTTPS) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 new_file_path += "replace_text="; 267 new_file_path += "replace_text=";
259 new_file_path += base64_old; 268 new_file_path += base64_old;
260 new_file_path += ":"; 269 new_file_path += ":";
261 new_file_path += base64_new; 270 new_file_path += base64_new;
262 } 271 }
263 272
264 *replacement_path = new_file_path; 273 *replacement_path = new_file_path;
265 return true; 274 return true;
266 } 275 }
267 276
268 void TestServer::Init(const FilePath& document_root) { 277 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. 278 // 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 279 // 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 280 // 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. 281 // that is complete, the host_port_pair_ will contain the actual port.
273 host_port_pair_ = HostPortPair(GetHostname(type_, https_options_), 0); 282 host_port_pair_ = HostPortPair(host, 0);
274 process_handle_ = base::kNullProcessHandle; 283 process_handle_ = base::kNullProcessHandle;
275 284
276 FilePath src_dir; 285 FilePath src_dir;
277 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); 286 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
278 287
279 document_root_ = src_dir.Append(document_root); 288 document_root_ = src_dir.Append(document_root);
280 289
281 certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net")) 290 certificates_dir_ = src_dir.Append(FILE_PATH_LITERAL("net"))
282 .Append(FILE_PATH_LITERAL("data")) 291 .Append(FILE_PATH_LITERAL("data"))
283 .Append(FILE_PATH_LITERAL("ssl")) 292 .Append(FILE_PATH_LITERAL("ssl"))
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 FilePath TestServer::GetRootCertificatePath() const { 362 FilePath TestServer::GetRootCertificatePath() const {
354 return certificates_dir_.AppendASCII("root_ca_cert.crt"); 363 return certificates_dir_.AppendASCII("root_ca_cert.crt");
355 } 364 }
356 365
357 bool TestServer::LoadTestRootCert() { 366 bool TestServer::LoadTestRootCert() {
358 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 367 TestRootCerts* root_certs = TestRootCerts::GetInstance();
359 return root_certs->AddFromFile(GetRootCertificatePath()); 368 return root_certs->AddFromFile(GetRootCertificatePath());
360 } 369 }
361 370
362 bool TestServer::AddCommandLineArguments(CommandLine* command_line) const { 371 bool TestServer::AddCommandLineArguments(CommandLine* command_line) const {
372 command_line->AppendArg("--host=" + host_port_pair_.host());
363 command_line->AppendArg("--port=" + 373 command_line->AppendArg("--port=" +
364 base::IntToString(host_port_pair_.port())); 374 base::IntToString(host_port_pair_.port()));
365 command_line->AppendArgNative(FILE_PATH_LITERAL("--data-dir=") + 375 command_line->AppendArgNative(FILE_PATH_LITERAL("--data-dir=") +
366 document_root_.value()); 376 document_root_.value());
367 377
368 if (VLOG_IS_ON(1) || log_to_console_) { 378 if (VLOG_IS_ON(1) || log_to_console_) {
369 command_line->AppendArg("--log-to-console"); 379 command_line->AppendArg("--log-to-console");
370 } 380 }
371 381
372 if (type_ == TYPE_FTP) { 382 if (type_ == TYPE_FTP) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 command_line->AppendArg(kBulkCipherSwitch + "=3des"); 426 command_line->AppendArg(kBulkCipherSwitch + "=3des");
417 427
418 if (https_options_.record_resume) 428 if (https_options_.record_resume)
419 command_line->AppendArg("--https-record-resume"); 429 command_line->AppendArg("--https-record-resume");
420 } 430 }
421 431
422 return true; 432 return true;
423 } 433 }
424 434
425 } // namespace net 435 } // namespace net
OLDNEW
« net/test/test_server.h ('K') | « net/test/test_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698