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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(net::TestServer::TYPE_HTTP); |
105 if (command_line->HasSwitch("https")) { | 106 if (command_line->HasSwitch("https")) { |
106 server_type = net::TestServer::TYPE_HTTPS; | 107 server_type = net::TestServer::TYPE_HTTPS; |
108 } else if (command_line->HasSwitch("ws")) { | |
109 server_type = net::TestServer::TYPE_WS; | |
110 } else if (command_line->HasSwitch("wss")) { | |
111 server_type = net::TestServer::TYPE_WSS; | |
107 } else if (command_line->HasSwitch("ftp")) { | 112 } else if (command_line->HasSwitch("ftp")) { |
108 server_type = net::TestServer::TYPE_FTP; | 113 server_type = net::TestServer::TYPE_FTP; |
109 } else if (command_line->HasSwitch("sync")) { | 114 } else if (command_line->HasSwitch("sync")) { |
110 server_type = net::TestServer::TYPE_SYNC; | 115 server_type = net::TestServer::TYPE_SYNC; |
111 } else if (command_line->HasSwitch("sync-test")) { | 116 } else if (command_line->HasSwitch("sync-test")) { |
112 return RunSyncTest() ? 0 : -1; | 117 return RunSyncTest() ? 0 : -1; |
113 } | 118 } |
114 | 119 |
115 net::TestServer::SSLOptions ssl_options; | 120 net::TestServer::SSLOptions ssl_options; |
116 if (command_line->HasSwitch("https-cert")) { | 121 if (command_line->HasSwitch("ssl-cert")) { |
117 server_type = net::TestServer::TYPE_HTTPS; | 122 if (server_type == net::TestServer::TYPE_HTTP) |
Ryan Sleevi
2012/08/30 02:54:14
Do you not need to also have a mapping of TYPE_WS
Takashi Toyoshima
2012/08/31 17:38:20
If no scheme option is specified, TYPE_HTTP is use
| |
118 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); | 123 server_type = net::TestServer::TYPE_HTTPS; |
124 std::string cert_option = command_line->GetSwitchValueASCII("ssl-cert"); | |
119 if (cert_option == "ok") { | 125 if (cert_option == "ok") { |
120 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK; | 126 ssl_options.server_certificate = net::TestServer::SSLOptions::CERT_OK; |
121 } else if (cert_option == "mismatched-name") { | 127 } else if (cert_option == "mismatched-name") { |
122 ssl_options.server_certificate = | 128 ssl_options.server_certificate = |
123 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME; | 129 net::TestServer::SSLOptions::CERT_MISMATCHED_NAME; |
124 } else if (cert_option == "expired") { | 130 } else if (cert_option == "expired") { |
125 ssl_options.server_certificate = | 131 ssl_options.server_certificate = |
126 net::TestServer::SSLOptions::CERT_EXPIRED; | 132 net::TestServer::SSLOptions::CERT_EXPIRED; |
127 } else { | 133 } else { |
128 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str()); | 134 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str()); |
129 PrintUsage(); | 135 PrintUsage(); |
130 return -1; | 136 return -1; |
131 } | 137 } |
132 } | 138 } |
133 | 139 |
134 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); | 140 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); |
135 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { | 141 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { |
136 printf("Error: --doc-root must be specified\n"); | 142 printf("Error: --doc-root must be specified\n"); |
137 PrintUsage(); | 143 PrintUsage(); |
138 return -1; | 144 return -1; |
139 } | 145 } |
140 | 146 |
141 scoped_ptr<net::TestServer> test_server; | 147 scoped_ptr<net::TestServer> test_server; |
142 switch (server_type) { | 148 switch (server_type) { |
143 case net::TestServer::TYPE_HTTPS: { | 149 case net::TestServer::TYPE_HTTPS: |
150 case net::TestServer::TYPE_WSS: { | |
144 test_server.reset(new net::TestServer(server_type, | 151 test_server.reset(new net::TestServer(server_type, |
145 ssl_options, | 152 ssl_options, |
146 doc_root)); | 153 doc_root)); |
147 break; | 154 break; |
148 } | 155 } |
149 case net::TestServer::TYPE_SYNC: { | 156 case net::TestServer::TYPE_SYNC: { |
150 uint16 port = 0; | 157 uint16 port = 0; |
151 uint16 xmpp_port = 0; | 158 uint16 xmpp_port = 0; |
152 if (!GetPortFromSwitch("port", &port) || | 159 if (!GetPortFromSwitch("port", &port) || |
153 !GetPortFromSwitch("xmpp-port", &xmpp_port)) { | 160 !GetPortFromSwitch("xmpp-port", &xmpp_port)) { |
(...skipping 21 matching lines...) Expand all Loading... | |
175 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); | 182 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); |
176 return -1; | 183 return -1; |
177 } | 184 } |
178 | 185 |
179 printf("testserver running at %s (type ctrl+c to exit)\n", | 186 printf("testserver running at %s (type ctrl+c to exit)\n", |
180 test_server->host_port_pair().ToString().c_str()); | 187 test_server->host_port_pair().ToString().c_str()); |
181 | 188 |
182 message_loop.Run(); | 189 message_loop.Run(); |
183 return 0; | 190 return 0; |
184 } | 191 } |
OLD | NEW |