OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
14 #include "net/test/spawned_test_server/spawned_test_server.h" | 14 #include "net/test/spawned_test_server/spawned_test_server.h" |
15 | 15 |
16 static void PrintUsage() { | 16 static void PrintUsage() { |
17 printf("run_testserver --doc-root=relpath\n" | 17 printf( |
18 " [--http|--https|--ws|--wss|--ftp]\n" | 18 "run_testserver --doc-root=relpath\n" |
19 " [--ssl-cert=ok|mismatched-name|expired]\n"); | 19 " [--http|--https|--ws|--wss|--ftp]\n" |
| 20 " [--ssl-cert=ok|mismatched-name|expired]\n"); |
20 printf("(NOTE: relpath should be relative to the 'src' directory.\n"); | 21 printf("(NOTE: relpath should be relative to the 'src' directory.\n"); |
21 } | 22 } |
22 | 23 |
23 int main(int argc, const char* argv[]) { | 24 int main(int argc, const char* argv[]) { |
24 base::AtExitManager at_exit_manager; | 25 base::AtExitManager at_exit_manager; |
25 base::MessageLoopForIO message_loop; | 26 base::MessageLoopForIO message_loop; |
26 | 27 |
27 // Process command line | 28 // Process command line |
28 CommandLine::Init(argc, argv); | 29 CommandLine::Init(argc, argv); |
29 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 30 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
30 | 31 |
31 logging::LoggingSettings settings; | 32 logging::LoggingSettings settings; |
32 settings.logging_dest = logging::LOG_TO_ALL; | 33 settings.logging_dest = logging::LOG_TO_ALL; |
33 settings.log_file = FILE_PATH_LITERAL("testserver.log"); | 34 settings.log_file = FILE_PATH_LITERAL("testserver.log"); |
34 if (!logging::InitLogging(settings)) { | 35 if (!logging::InitLogging(settings)) { |
35 printf("Error: could not initialize logging. Exiting.\n"); | 36 printf("Error: could not initialize logging. Exiting.\n"); |
36 return -1; | 37 return -1; |
37 } | 38 } |
38 | 39 |
39 TestTimeouts::Initialize(); | 40 TestTimeouts::Initialize(); |
40 | 41 |
41 if (command_line->GetSwitches().empty() || | 42 if (command_line->GetSwitches().empty() || command_line->HasSwitch("help")) { |
42 command_line->HasSwitch("help")) { | |
43 PrintUsage(); | 43 PrintUsage(); |
44 return -1; | 44 return -1; |
45 } | 45 } |
46 | 46 |
47 net::SpawnedTestServer::Type server_type; | 47 net::SpawnedTestServer::Type server_type; |
48 if (command_line->HasSwitch("http")) { | 48 if (command_line->HasSwitch("http")) { |
49 server_type = net::SpawnedTestServer::TYPE_HTTP; | 49 server_type = net::SpawnedTestServer::TYPE_HTTP; |
50 } else if (command_line->HasSwitch("https")) { | 50 } else if (command_line->HasSwitch("https")) { |
51 server_type = net::SpawnedTestServer::TYPE_HTTPS; | 51 server_type = net::SpawnedTestServer::TYPE_HTTPS; |
52 } else if (command_line->HasSwitch("ws")) { | 52 } else if (command_line->HasSwitch("ws")) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 PrintUsage(); | 94 PrintUsage(); |
95 return -1; | 95 return -1; |
96 } | 96 } |
97 | 97 |
98 scoped_ptr<net::SpawnedTestServer> test_server; | 98 scoped_ptr<net::SpawnedTestServer> test_server; |
99 if (net::SpawnedTestServer::UsingSSL(server_type)) { | 99 if (net::SpawnedTestServer::UsingSSL(server_type)) { |
100 test_server.reset( | 100 test_server.reset( |
101 new net::SpawnedTestServer(server_type, ssl_options, doc_root)); | 101 new net::SpawnedTestServer(server_type, ssl_options, doc_root)); |
102 } else { | 102 } else { |
103 test_server.reset(new net::SpawnedTestServer( | 103 test_server.reset(new net::SpawnedTestServer( |
104 server_type, | 104 server_type, net::SpawnedTestServer::kLocalhost, doc_root)); |
105 net::SpawnedTestServer::kLocalhost, | |
106 doc_root)); | |
107 } | 105 } |
108 | 106 |
109 if (!test_server->Start()) { | 107 if (!test_server->Start()) { |
110 printf("Error: failed to start test server. Exiting.\n"); | 108 printf("Error: failed to start test server. Exiting.\n"); |
111 return -1; | 109 return -1; |
112 } | 110 } |
113 | 111 |
114 if (!base::DirectoryExists(test_server->document_root())) { | 112 if (!base::DirectoryExists(test_server->document_root())) { |
115 printf("Error: invalid doc root: \"%s\" does not exist!\n", | 113 printf("Error: invalid doc root: \"%s\" does not exist!\n", |
116 base::UTF16ToUTF8( | 114 base::UTF16ToUTF8(test_server->document_root().LossyDisplayName()) |
117 test_server->document_root().LossyDisplayName()).c_str()); | 115 .c_str()); |
118 return -1; | 116 return -1; |
119 } | 117 } |
120 | 118 |
121 printf("testserver running at %s (type ctrl+c to exit)\n", | 119 printf("testserver running at %s (type ctrl+c to exit)\n", |
122 test_server->host_port_pair().ToString().c_str()); | 120 test_server->host_port_pair().ToString().c_str()); |
123 | 121 |
124 message_loop.Run(); | 122 message_loop.Run(); |
125 return 0; | 123 return 0; |
126 } | 124 } |
OLD | NEW |