OLD | NEW |
---|---|
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 Loading... | |
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. | |
Paweł Hajdan Jr.
2012/09/01 07:39:10
I don't like this implicit handling of flags. This
Takashi Toyoshima
2012/09/01 08:36:59
This behavior is originally implemented in Line 10
Paweł Hajdan Jr.
2012/09/04 09:28:01
Ah, right - the new version just makes it more obv
Takashi Toyoshima
2012/09/11 06:36:32
Done.
| |
122 if (command_line->HasSwitch("ssl-cert")) | |
123 server_type = net::TestServer::TYPE_HTTPS; | |
124 else | |
125 server_type = net::TestServer::TYPE_HTTP; | |
113 } | 126 } |
114 | 127 |
115 net::TestServer::SSLOptions ssl_options; | 128 net::TestServer::SSLOptions ssl_options; |
116 if (command_line->HasSwitch("https-cert")) { | 129 if (command_line->HasSwitch("ssl-cert")) { |
117 server_type = net::TestServer::TYPE_HTTPS; | 130 if (server_type == net::TestServer::TYPE_HTTP || |
118 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); | 131 server_type == net::TestServer::TYPE_WS) { |
132 printf("Error: --ssl-cert is specified on non-secure scheme\n"); | |
133 PrintUsage(); | |
134 return -1; | |
135 } | |
136 std::string cert_option = command_line->GetSwitchValueASCII("ssl-cert"); | |
119 if (cert_option == "ok") { | 137 if (cert_option == "ok") { |
120 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK; | 138 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK; |
121 } else if (cert_option == "mismatched-name") { | 139 } else if (cert_option == "mismatched-name") { |
122 ssl_options.server_certificate = | 140 ssl_options.server_certificate = |
123 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME; | 141 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME; |
124 } else if (cert_option == "expired") { | 142 } else if (cert_option == "expired") { |
125 ssl_options.server_certificate = | 143 ssl_options.server_certificate = |
126 net::TestServer::SSLOptions::CERT_EXPIRED; | 144 net::TestServer::SSLOptions::CERT_EXPIRED; |
127 } else { | 145 } else { |
128 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str()); | 146 printf("Error: --ssl-cert has invalid value %s\n", cert_option.c_str()); |
129 PrintUsage(); | 147 PrintUsage(); |
130 return -1; | 148 return -1; |
131 } | 149 } |
132 } | 150 } |
133 | 151 |
134 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); | 152 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); |
135 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { | 153 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { |
136 printf("Error: --doc-root must be specified\n"); | 154 printf("Error: --doc-root must be specified\n"); |
137 PrintUsage(); | 155 PrintUsage(); |
138 return -1; | 156 return -1; |
139 } | 157 } |
140 | 158 |
141 scoped_ptr<net::TestServer> test_server; | 159 scoped_ptr<net::TestServer> test_server; |
142 switch (server_type) { | 160 switch (server_type) { |
143 case net::TestServer::TYPE_HTTPS: { | 161 case net::TestServer::TYPE_HTTPS: |
162 case net::TestServer::TYPE_WSS: { | |
144 test_server.reset(new net::TestServer(server_type, | 163 test_server.reset(new net::TestServer(server_type, |
145 ssl_options, | 164 ssl_options, |
146 doc_root)); | 165 doc_root)); |
147 break; | 166 break; |
148 } | 167 } |
149 case net::TestServer::TYPE_SYNC: { | 168 case net::TestServer::TYPE_SYNC: { |
150 uint16 port = 0; | 169 uint16 port = 0; |
151 uint16 xmpp_port = 0; | 170 uint16 xmpp_port = 0; |
152 if (!GetPortFromSwitch("port", &port) || | 171 if (!GetPortFromSwitch("port", &port) || |
153 !GetPortFromSwitch("xmpp-port", &xmpp_port)) { | 172 !GetPortFromSwitch("xmpp-port", &xmpp_port)) { |
(...skipping 21 matching lines...) Expand all Loading... | |
175 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); | 194 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); |
176 return -1; | 195 return -1; |
177 } | 196 } |
178 | 197 |
179 printf("testserver running at %s (type ctrl+c to exit)\n", | 198 printf("testserver running at %s (type ctrl+c to exit)\n", |
180 test_server->host_port_pair().ToString().c_str()); | 199 test_server->host_port_pair().ToString().c_str()); |
181 | 200 |
182 message_loop.Run(); | 201 message_loop.Run(); |
183 return 0; | 202 return 0; |
184 } | 203 } |
OLD | NEW |