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

Side by Side Diff: net/tools/testserver/run_testserver.cc

Issue 10388206: [sync] Add --port and --xmpp-port parameters to run_testserver.cc (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: "" Created 8 years, 7 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "base/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "net/test/python_utils.h" 16 #include "net/test/python_utils.h"
16 #include "net/test/test_server.h" 17 #include "net/test/test_server.h"
17 18
18 static void PrintUsage() { 19 static void PrintUsage() {
19 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" 20 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"
20 " [--https-cert=ok|mismatched-name|expired]\n"); 21 " [--https-cert=ok|mismatched-name|expired]\n");
21 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); 22 printf("(NOTE: relpath should be relative to the 'src' directory)\n");
22 } 23 }
23 24
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 71 }
71 72
72 TestTimeouts::Initialize(); 73 TestTimeouts::Initialize();
73 74
74 if (command_line->GetSwitches().empty() || command_line->HasSwitch("help")) { 75 if (command_line->GetSwitches().empty() || command_line->HasSwitch("help")) {
75 PrintUsage(); 76 PrintUsage();
76 return -1; 77 return -1;
77 } 78 }
78 79
79 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); 80 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP);
81 std::string xmpp_port_str = "0";
80 if (command_line->HasSwitch("https")) { 82 if (command_line->HasSwitch("https")) {
81 server_type = net::TestServer::TYPE_HTTPS; 83 server_type = net::TestServer::TYPE_HTTPS;
82 } else if (command_line->HasSwitch("ftp")) { 84 } else if (command_line->HasSwitch("ftp")) {
83 server_type = net::TestServer::TYPE_FTP; 85 server_type = net::TestServer::TYPE_FTP;
84 } else if (command_line->HasSwitch("sync")) { 86 } else if (command_line->HasSwitch("sync")) {
85 server_type = net::TestServer::TYPE_SYNC; 87 server_type = net::TestServer::TYPE_SYNC;
88 if (command_line->HasSwitch("xmpp-port")) {
89 xmpp_port_str = command_line->GetSwitchValueASCII("xmpp-port");
90 }
86 } else if (command_line->HasSwitch("sync-test")) { 91 } else if (command_line->HasSwitch("sync-test")) {
87 return RunSyncTest() ? 0 : -1; 92 return RunSyncTest() ? 0 : -1;
88 } 93 }
89 94
95 std::string port_str = "0";
96 if (command_line->HasSwitch("port")) {
97 port_str = command_line->GetSwitchValueASCII("port");
98 }
99
90 net::TestServer::HTTPSOptions https_options; 100 net::TestServer::HTTPSOptions https_options;
91 if (command_line->HasSwitch("https-cert")) { 101 if (command_line->HasSwitch("https-cert")) {
92 server_type = net::TestServer::TYPE_HTTPS; 102 server_type = net::TestServer::TYPE_HTTPS;
93 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); 103 std::string cert_option = command_line->GetSwitchValueASCII("https-cert");
94 if (cert_option == "ok") { 104 if (cert_option == "ok") {
95 https_options.server_certificate = net::TestServer::HTTPSOptions::CERT_OK; 105 https_options.server_certificate = net::TestServer::HTTPSOptions::CERT_OK;
96 } else if (cert_option == "mismatched-name") { 106 } else if (cert_option == "mismatched-name") {
97 https_options.server_certificate = 107 https_options.server_certificate =
98 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME; 108 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME;
99 } else if (cert_option == "expired") { 109 } else if (cert_option == "expired") {
100 https_options.server_certificate = 110 https_options.server_certificate =
101 net::TestServer::HTTPSOptions::CERT_EXPIRED; 111 net::TestServer::HTTPSOptions::CERT_EXPIRED;
102 } else { 112 } else {
103 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str()); 113 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str());
104 PrintUsage(); 114 PrintUsage();
105 return -1; 115 return -1;
106 } 116 }
107 } 117 }
108 118
109 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); 119 FilePath doc_root = command_line->GetSwitchValuePath("doc-root");
110 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { 120 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) {
111 printf("Error: --doc-root must be specified\n"); 121 printf("Error: --doc-root must be specified\n");
112 PrintUsage(); 122 PrintUsage();
113 return -1; 123 return -1;
114 } 124 }
115 125
116 scoped_ptr<net::TestServer> test_server; 126 scoped_ptr<net::TestServer> test_server;
117 if (server_type == net::TestServer::TYPE_HTTPS) 127 if (server_type == net::TestServer::TYPE_HTTPS) {
118 test_server.reset(new net::TestServer(https_options, doc_root)); 128 test_server.reset(new net::TestServer(https_options, doc_root));
119 else 129 } else {
120 test_server.reset(new net::TestServer(server_type, 130 test_server.reset(new net::TestServer(server_type,
121 net::TestServer::kLocalhost, 131 net::TestServer::kLocalhost,
122 doc_root)); 132 doc_root));
133 }
134
135 if (port_str != "0") {
136 int port_int = 0;
137 base::StringToInt(port_str, &port_int);
138 test_server->SetPort((uint16) port_int);
139 }
140
141 if (server_type == net::TestServer::TYPE_SYNC && xmpp_port_str != "0") {
142 int xmpp_port_int = 0;
143 base::StringToInt(xmpp_port_str, &xmpp_port_int);
144 test_server->SetXmppPort((uint16) xmpp_port_int);
145 }
123 146
124 if (!test_server->Start()) { 147 if (!test_server->Start()) {
125 printf("Error: failed to start test server. Exiting.\n"); 148 printf("Error: failed to start test server. Exiting.\n");
126 return -1; 149 return -1;
127 } 150 }
128 151
129 if (!file_util::DirectoryExists(test_server->document_root())) { 152 if (!file_util::DirectoryExists(test_server->document_root())) {
130 printf("Error: invalid doc root: \"%s\" does not exist!\n", 153 printf("Error: invalid doc root: \"%s\" does not exist!\n",
131 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); 154 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str());
132 return -1; 155 return -1;
133 } 156 }
134 157
135 printf("testserver running at %s (type ctrl+c to exit)\n", 158 printf("testserver running at %s (type ctrl+c to exit)\n",
136 test_server->host_port_pair().ToString().c_str()); 159 test_server->host_port_pair().ToString().c_str());
137 160
138 message_loop.Run(); 161 message_loop.Run();
139 return 0; 162 return 0;
140 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698