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

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: Fix compile with OVERRIDE 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"
18 #include "net/test/local_sync_test_server.h"
17 19
18 static void PrintUsage() { 20 static void PrintUsage() {
19 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" 21 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"
20 " [--https-cert=ok|mismatched-name|expired]\n"); 22 " [--https-cert=ok|mismatched-name|expired]\n"
21 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); 23 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
24 printf("(NOTE: relpath should be relative to the 'src' directory.\n");
25 printf(" --port and --xmpp-port only work with the --sync flag.)\n");
22 } 26 }
23 27
24 // Launches the chromiumsync_test script, testing the --sync functionality. 28 // Launches the chromiumsync_test script, testing the --sync functionality.
25 static bool RunSyncTest() { 29 static bool RunSyncTest() {
26 if (!net::TestServer::SetPythonPath()) { 30 if (!net::TestServer::SetPythonPath()) {
27 LOG(ERROR) << "Error trying to set python path. Exiting."; 31 LOG(ERROR) << "Error trying to set python path. Exiting.";
28 return false; 32 return false;
29 } 33 }
30 34
31 FilePath sync_test_path; 35 FilePath sync_test_path;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (command_line->HasSwitch("https")) { 84 if (command_line->HasSwitch("https")) {
81 server_type = net::TestServer::TYPE_HTTPS; 85 server_type = net::TestServer::TYPE_HTTPS;
82 } else if (command_line->HasSwitch("ftp")) { 86 } else if (command_line->HasSwitch("ftp")) {
83 server_type = net::TestServer::TYPE_FTP; 87 server_type = net::TestServer::TYPE_FTP;
84 } else if (command_line->HasSwitch("sync")) { 88 } else if (command_line->HasSwitch("sync")) {
85 server_type = net::TestServer::TYPE_SYNC; 89 server_type = net::TestServer::TYPE_SYNC;
86 } else if (command_line->HasSwitch("sync-test")) { 90 } else if (command_line->HasSwitch("sync-test")) {
87 return RunSyncTest() ? 0 : -1; 91 return RunSyncTest() ? 0 : -1;
88 } 92 }
89 93
94 std::string port_str = "0";
akalin 2012/05/23 05:29:21 move port_str inside the if statement and don't in
Raghu Simha 2012/05/23 06:02:59 Done.
95 int port_int = 0;
96 if (command_line->HasSwitch("port")) {
97 port_str = command_line->GetSwitchValueASCII("port");
98 base::StringToInt(port_str, &port_int);
99 }
100
101 std::string xmpp_port_str = "0";
102 int xmpp_port_int = 0;
103 if (command_line->HasSwitch("xmpp-port")) {
104 xmpp_port_str = command_line->GetSwitchValueASCII("xmpp-port");
105 base::StringToInt(xmpp_port_str, &xmpp_port_int);
106 }
107
90 net::TestServer::HTTPSOptions https_options; 108 net::TestServer::HTTPSOptions https_options;
91 if (command_line->HasSwitch("https-cert")) { 109 if (command_line->HasSwitch("https-cert")) {
92 server_type = net::TestServer::TYPE_HTTPS; 110 server_type = net::TestServer::TYPE_HTTPS;
93 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); 111 std::string cert_option = command_line->GetSwitchValueASCII("https-cert");
94 if (cert_option == "ok") { 112 if (cert_option == "ok") {
95 https_options.server_certificate = net::TestServer::HTTPSOptions::CERT_OK; 113 https_options.server_certificate = net::TestServer::HTTPSOptions::CERT_OK;
96 } else if (cert_option == "mismatched-name") { 114 } else if (cert_option == "mismatched-name") {
97 https_options.server_certificate = 115 https_options.server_certificate =
98 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME; 116 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME;
99 } else if (cert_option == "expired") { 117 } else if (cert_option == "expired") {
100 https_options.server_certificate = 118 https_options.server_certificate =
101 net::TestServer::HTTPSOptions::CERT_EXPIRED; 119 net::TestServer::HTTPSOptions::CERT_EXPIRED;
102 } else { 120 } else {
103 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str()); 121 printf("Error: --https-cert has invalid value %s\n", cert_option.c_str());
104 PrintUsage(); 122 PrintUsage();
105 return -1; 123 return -1;
106 } 124 }
107 } 125 }
108 126
109 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); 127 FilePath doc_root = command_line->GetSwitchValuePath("doc-root");
110 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { 128 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) {
111 printf("Error: --doc-root must be specified\n"); 129 printf("Error: --doc-root must be specified\n");
112 PrintUsage(); 130 PrintUsage();
113 return -1; 131 return -1;
114 } 132 }
115 133
116 scoped_ptr<net::TestServer> test_server; 134 scoped_ptr<net::TestServer> test_server;
117 if (server_type == net::TestServer::TYPE_HTTPS) 135 switch (server_type) {
118 test_server.reset(new net::TestServer(https_options, doc_root)); 136 case net::TestServer::TYPE_HTTPS:
119 else 137 test_server.reset(new net::TestServer(https_options, doc_root));
120 test_server.reset(new net::TestServer(server_type, 138 break;
121 net::TestServer::kLocalhost, 139 case net::TestServer::TYPE_SYNC:
122 doc_root)); 140 test_server.reset(new net::LocalSyncTestServer((uint16) port_int,
akalin 2012/05/23 05:29:21 prefer static_cast<uint16>()
akalin 2012/05/23 05:29:21 in fact, you can probably stick the int parsing co
Raghu Simha 2012/05/23 06:02:59 Done.
Raghu Simha 2012/05/23 06:02:59 Done. Moved to a separate function. Added braces i
141 (uint16) xmpp_port_int));
142 break;
143 default:
144 test_server.reset(new net::TestServer(server_type,
145 net::TestServer::kLocalhost,
146 doc_root));
147 break;
148 }
123 149
124 if (!test_server->Start()) { 150 if (!test_server->Start()) {
125 printf("Error: failed to start test server. Exiting.\n"); 151 printf("Error: failed to start test server. Exiting.\n");
126 return -1; 152 return -1;
127 } 153 }
128 154
129 if (!file_util::DirectoryExists(test_server->document_root())) { 155 if (!file_util::DirectoryExists(test_server->document_root())) {
130 printf("Error: invalid doc root: \"%s\" does not exist!\n", 156 printf("Error: invalid doc root: \"%s\" does not exist!\n",
131 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); 157 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str());
132 return -1; 158 return -1;
133 } 159 }
134 160
135 printf("testserver running at %s (type ctrl+c to exit)\n", 161 printf("testserver running at %s (type ctrl+c to exit)\n",
136 test_server->host_port_pair().ToString().c_str()); 162 test_server->host_port_pair().ToString().c_str());
137 163
138 message_loop.Run(); 164 message_loop.Run();
139 return 0; 165 return 0;
140 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698