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

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

Issue 10913268: Revert 156742 - Launch pywebsocket via net::TestServer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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/remote_test_server.cc ('k') | net/tools/testserver/testserver.py » ('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 (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/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "net/test/local_sync_test_server.h" 16 #include "net/test/local_sync_test_server.h"
17 #include "net/test/python_utils.h" 17 #include "net/test/python_utils.h"
18 #include "net/test/test_server.h" 18 #include "net/test/test_server.h"
19 19
20 static void PrintUsage() { 20 static void PrintUsage() {
21 printf("run_testserver --doc-root=relpath\n" 21 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"
22 " [--http|--https|--ws|--wss|--ftp|--sync]\n" 22 " [--https-cert=ok|mismatched-name|expired]\n"
23 " [--ssl-cert=ok|mismatched-name|expired]\n"
24 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n"); 23 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
25 printf("(NOTE: relpath should be relative to the 'src' directory.\n"); 24 printf("(NOTE: relpath should be relative to the 'src' directory.\n");
26 printf(" --port and --xmpp-port only work with the --sync flag.)\n"); 25 printf(" --port and --xmpp-port only work with the --sync flag.)\n");
27 } 26 }
28 27
29 // Launches the chromiumsync_test script, testing the --sync functionality. 28 // Launches the chromiumsync_test script, testing the --sync functionality.
30 static bool RunSyncTest() { 29 static bool RunSyncTest() {
31 if (!net::TestServer::SetPythonPath()) { 30 if (!net::TestServer::SetPythonPath()) {
32 LOG(ERROR) << "Error trying to set python path. Exiting."; 31 LOG(ERROR) << "Error trying to set python path. Exiting.";
33 return false; 32 return false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 94
96 if (command_line->GetSwitches().empty() || 95 if (command_line->GetSwitches().empty() ||
97 command_line->HasSwitch("help") || 96 command_line->HasSwitch("help") ||
98 ((command_line->HasSwitch("port") || 97 ((command_line->HasSwitch("port") ||
99 command_line->HasSwitch("xmpp-port")) && 98 command_line->HasSwitch("xmpp-port")) &&
100 !command_line->HasSwitch("sync"))) { 99 !command_line->HasSwitch("sync"))) {
101 PrintUsage(); 100 PrintUsage();
102 return -1; 101 return -1;
103 } 102 }
104 103
105 net::TestServer::Type server_type; 104 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP);
106 if (command_line->HasSwitch("http")) { 105 if (command_line->HasSwitch("https")) {
107 server_type = net::TestServer::TYPE_HTTP;
108 } else if (command_line->HasSwitch("https")) {
109 server_type = net::TestServer::TYPE_HTTPS; 106 server_type = net::TestServer::TYPE_HTTPS;
110 } else if (command_line->HasSwitch("ws")) {
111 server_type = net::TestServer::TYPE_WS;
112 } else if (command_line->HasSwitch("wss")) {
113 server_type = net::TestServer::TYPE_WSS;
114 } else if (command_line->HasSwitch("ftp")) { 107 } else if (command_line->HasSwitch("ftp")) {
115 server_type = net::TestServer::TYPE_FTP; 108 server_type = net::TestServer::TYPE_FTP;
116 } else if (command_line->HasSwitch("sync")) { 109 } else if (command_line->HasSwitch("sync")) {
117 server_type = net::TestServer::TYPE_SYNC; 110 server_type = net::TestServer::TYPE_SYNC;
118 } else if (command_line->HasSwitch("sync-test")) { 111 } else if (command_line->HasSwitch("sync-test")) {
119 return RunSyncTest() ? 0 : -1; 112 return RunSyncTest() ? 0 : -1;
120 } else {
121 // If no scheme switch is specified, select http or https scheme.
122 // TODO(toyoshim): Remove this estimation.
123 if (command_line->HasSwitch("ssl-cert"))
124 server_type = net::TestServer::TYPE_HTTPS;
125 else
126 server_type = net::TestServer::TYPE_HTTP;
127 } 113 }
128 114
129 net::TestServer::SSLOptions ssl_options; 115 net::TestServer::SSLOptions ssl_options;
130 if (command_line->HasSwitch("ssl-cert")) { 116 if (command_line->HasSwitch("https-cert")) {
131 if (!net::TestServer::UsingSSL(server_type)) { 117 server_type = net::TestServer::TYPE_HTTPS;
132 printf("Error: --ssl-cert is specified on non-secure scheme\n"); 118 std::string cert_option = command_line->GetSwitchValueASCII("https-cert");
133 PrintUsage();
134 return -1;
135 }
136 std::string cert_option = command_line->GetSwitchValueASCII("ssl-cert");
137 if (cert_option == "ok") { 119 if (cert_option == "ok") {
138 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK; 120 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK;
139 } else if (cert_option == "mismatched-name") { 121 } else if (cert_option == "mismatched-name") {
140 ssl_options.server_certificate = 122 ssl_options.server_certificate =
141 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME; 123 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME;
142 } else if (cert_option == "expired") { 124 } else if (cert_option == "expired") {
143 ssl_options.server_certificate = 125 ssl_options.server_certificate =
144 net::TestServer::SSLOptions::CERT_EXPIRED; 126 net::TestServer::SSLOptions::CERT_EXPIRED;
145 } else { 127 } else {
146 printf("Error: --ssl-cert has invalid value %s\n", cert_option.c_str()); 128 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str());
147 PrintUsage(); 129 PrintUsage();
148 return -1; 130 return -1;
149 } 131 }
150 } 132 }
151 133
152 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); 134 FilePath doc_root = command_line->GetSwitchValuePath("doc-root");
153 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { 135 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) {
154 printf("Error: --doc-root must be specified\n"); 136 printf("Error: --doc-root must be specified\n");
155 PrintUsage(); 137 PrintUsage();
156 return -1; 138 return -1;
157 } 139 }
158 140
159 scoped_ptr<net::TestServer> test_server; 141 scoped_ptr<net::TestServer> test_server;
160 if (net::TestServer::UsingSSL(server_type)) { 142 switch (server_type) {
161 test_server.reset(new net::TestServer(server_type, ssl_options, doc_root)); 143 case net::TestServer::TYPE_HTTPS: {
162 } else if (server_type == net::TestServer::TYPE_SYNC) { 144 test_server.reset(new net::TestServer(server_type,
163 uint16 port = 0; 145 ssl_options,
164 uint16 xmpp_port = 0; 146 doc_root));
165 if (!GetPortFromSwitch("port", &port) || 147 break;
166 !GetPortFromSwitch("xmpp-port", &xmpp_port)) {
167 printf("Error: Could not extract --port and/or --xmpp-port.\n");
168 return -1;
169 } 148 }
170 test_server.reset(new net::LocalSyncTestServer(port, xmpp_port)); 149 case net::TestServer::TYPE_SYNC: {
171 } else { 150 uint16 port = 0;
172 test_server.reset(new net::TestServer(server_type, 151 uint16 xmpp_port = 0;
173 net::TestServer::kLocalhost, 152 if (!GetPortFromSwitch("port", &port) ||
174 doc_root)); 153 !GetPortFromSwitch("xmpp-port", &xmpp_port)) {
154 printf("Error: Could not extract --port and/or --xmpp-port.\n");
155 return -1;
156 }
157 test_server.reset(new net::LocalSyncTestServer(port, xmpp_port));
158 break;
159 }
160 default: {
161 test_server.reset(new net::TestServer(server_type,
162 net::TestServer::kLocalhost,
163 doc_root));
164 break;
165 }
175 } 166 }
176 167
177 if (!test_server->Start()) { 168 if (!test_server->Start()) {
178 printf("Error: failed to start test server. Exiting.\n"); 169 printf("Error: failed to start test server. Exiting.\n");
179 return -1; 170 return -1;
180 } 171 }
181 172
182 if (!file_util::DirectoryExists(test_server->document_root())) { 173 if (!file_util::DirectoryExists(test_server->document_root())) {
183 printf("Error: invalid doc root: \"%s\" does not exist!\n", 174 printf("Error: invalid doc root: \"%s\" does not exist!\n",
184 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); 175 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str());
185 return -1; 176 return -1;
186 } 177 }
187 178
188 printf("testserver running at %s (type ctrl+c to exit)\n", 179 printf("testserver running at %s (type ctrl+c to exit)\n",
189 test_server->host_port_pair().ToString().c_str()); 180 test_server->host_port_pair().ToString().c_str());
190 181
191 message_loop.Run(); 182 message_loop.Run();
192 return 0; 183 return 0;
193 } 184 }
OLDNEW
« no previous file with comments | « net/test/remote_test_server.cc ('k') | net/tools/testserver/testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698