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

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

Issue 10879029: reland: Launch pywebsocket via net::TestServer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed 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
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 [--http|--https|--ftp|--sync]\n" 21 printf("run_testserver --doc-root=relpath\n"
22 " [--https-cert=ok|mismatched-name|expired]\n" 22 " [--http|--https|--ws|--wss|--ftp|--sync]\n"
23 " [--ssl-cert=ok|mismatched-name|expired]\n"
23 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n"); 24 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
24 printf("(NOTE: relpath should be relative to the 'src' directory.\n"); 25 printf("(NOTE: relpath should be relative to the 'src' directory.\n");
25 printf(" --port and --xmpp-port only work with the --sync flag.)\n"); 26 printf(" --port and --xmpp-port only work with the --sync flag.)\n");
26 } 27 }
27 28
28 // Launches the chromiumsync_test script, testing the --sync functionality. 29 // Launches the chromiumsync_test script, testing the --sync functionality.
29 static bool RunSyncTest() { 30 static bool RunSyncTest() {
30 if (!net::TestServer::SetPythonPath()) { 31 if (!net::TestServer::SetPythonPath()) {
31 LOG(ERROR) << "Error trying to set python path. Exiting."; 32 LOG(ERROR) << "Error trying to set python path. Exiting.";
32 return false; 33 return false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 if (command_line->GetSwitches().empty() || 96 if (command_line->GetSwitches().empty() ||
96 command_line->HasSwitch("help") || 97 command_line->HasSwitch("help") ||
97 ((command_line->HasSwitch("port") || 98 ((command_line->HasSwitch("port") ||
98 command_line->HasSwitch("xmpp-port")) && 99 command_line->HasSwitch("xmpp-port")) &&
99 !command_line->HasSwitch("sync"))) { 100 !command_line->HasSwitch("sync"))) {
100 PrintUsage(); 101 PrintUsage();
101 return -1; 102 return -1;
102 } 103 }
103 104
104 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); 105 net::TestServer::Type server_type;
105 if (command_line->HasSwitch("https")) { 106 if (command_line->HasSwitch("http")) {
107 server_type = net::TestServer::TYPE_HTTP;
108 } else if (command_line->HasSwitch("https")) {
106 server_type = net::TestServer::TYPE_HTTPS; 109 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;
107 } else if (command_line->HasSwitch("ftp")) { 114 } else if (command_line->HasSwitch("ftp")) {
108 server_type = net::TestServer::TYPE_FTP; 115 server_type = net::TestServer::TYPE_FTP;
109 } else if (command_line->HasSwitch("sync")) { 116 } else if (command_line->HasSwitch("sync")) {
110 server_type = net::TestServer::TYPE_SYNC; 117 server_type = net::TestServer::TYPE_SYNC;
111 } else if (command_line->HasSwitch("sync-test")) { 118 } else if (command_line->HasSwitch("sync-test")) {
112 return RunSyncTest() ? 0 : -1; 119 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;
113 } 127 }
114 128
115 net::TestServer::SSLOptions ssl_options; 129 net::TestServer::SSLOptions ssl_options;
116 if (command_line->HasSwitch("https-cert")) { 130 if (command_line->HasSwitch("ssl-cert")) {
117 server_type = net::TestServer::TYPE_HTTPS; 131 if (server_type == net::TestServer::TYPE_HTTP ||
Paweł Hajdan Jr. 2012/09/12 10:32:55 This is inversion of UsingSSL. Please design thing
Takashi Toyoshima 2012/09/13 07:06:23 OK. I believe no one want to use secure ftp, sync,
118 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); 132 server_type == net::TestServer::TYPE_WS) {
133 printf("Error: --ssl-cert is specified on non-secure scheme\n");
134 PrintUsage();
135 return -1;
136 }
137 std::string cert_option = command_line->GetSwitchValueASCII("ssl-cert");
119 if (cert_option == "ok") { 138 if (cert_option == "ok") {
120 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK; 139 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK;
121 } else if (cert_option == "mismatched-name") { 140 } else if (cert_option == "mismatched-name") {
122 ssl_options.server_certificate = 141 ssl_options.server_certificate =
123 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME; 142 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME;
124 } else if (cert_option == "expired") { 143 } else if (cert_option == "expired") {
125 ssl_options.server_certificate = 144 ssl_options.server_certificate =
126 net::TestServer::SSLOptions::CERT_EXPIRED; 145 net::TestServer::SSLOptions::CERT_EXPIRED;
127 } else { 146 } else {
128 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str()); 147 printf("Error: --ssl-cert has invalid value %s\n", cert_option.c_str());
129 PrintUsage(); 148 PrintUsage();
130 return -1; 149 return -1;
131 } 150 }
132 } 151 }
133 152
134 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); 153 FilePath doc_root = command_line->GetSwitchValuePath("doc-root");
135 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { 154 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) {
136 printf("Error: --doc-root must be specified\n"); 155 printf("Error: --doc-root must be specified\n");
137 PrintUsage(); 156 PrintUsage();
138 return -1; 157 return -1;
139 } 158 }
140 159
141 scoped_ptr<net::TestServer> test_server; 160 scoped_ptr<net::TestServer> test_server;
142 switch (server_type) { 161 switch (server_type) {
143 case net::TestServer::TYPE_HTTPS: { 162 case net::TestServer::TYPE_HTTPS:
Paweł Hajdan Jr. 2012/09/12 10:32:55 This is also effectively UsingSSL.
Takashi Toyoshima 2012/09/13 07:06:23 Done.
163 case net::TestServer::TYPE_WSS: {
144 test_server.reset(new net::TestServer(server_type, 164 test_server.reset(new net::TestServer(server_type,
145 ssl_options, 165 ssl_options,
146 doc_root)); 166 doc_root));
147 break; 167 break;
148 } 168 }
149 case net::TestServer::TYPE_SYNC: { 169 case net::TestServer::TYPE_SYNC: {
150 uint16 port = 0; 170 uint16 port = 0;
151 uint16 xmpp_port = 0; 171 uint16 xmpp_port = 0;
152 if (!GetPortFromSwitch("port", &port) || 172 if (!GetPortFromSwitch("port", &port) ||
153 !GetPortFromSwitch("xmpp-port", &xmpp_port)) { 173 !GetPortFromSwitch("xmpp-port", &xmpp_port)) {
(...skipping 21 matching lines...) Expand all
175 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); 195 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str());
176 return -1; 196 return -1;
177 } 197 }
178 198
179 printf("testserver running at %s (type ctrl+c to exit)\n", 199 printf("testserver running at %s (type ctrl+c to exit)\n",
180 test_server->host_port_pair().ToString().c_str()); 200 test_server->host_port_pair().ToString().c_str());
181 201
182 message_loop.Run(); 202 message_loop.Run();
183 return 0; 203 return 0;
184 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698