OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "net/url_request/url_request_unittest.h" | 11 #include "net/test/test_server.h" |
12 | 12 |
13 static void PrintUsage() { | 13 static void PrintUsage() { |
14 printf("run_testserver --doc-root=relpath [--http|--https|--ftp]\n"); | 14 printf("run_testserver --doc-root=relpath [--http|--https|--ftp]\n"); |
15 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); | 15 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); |
16 } | 16 } |
17 | 17 |
18 int main(int argc, const char* argv[]) { | 18 int main(int argc, const char* argv[]) { |
19 base::AtExitManager at_exit_manager; | 19 base::AtExitManager at_exit_manager; |
20 MessageLoopForIO message_loop; | 20 MessageLoopForIO message_loop; |
21 | 21 |
22 // Process command line | 22 // Process command line |
23 CommandLine::Init(argc, argv); | 23 CommandLine::Init(argc, argv); |
24 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 24 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
25 | 25 |
26 if (command_line->GetSwitchCount() == 0 || | 26 if (command_line->GetSwitchCount() == 0 || |
27 command_line->HasSwitch("help")) { | 27 command_line->HasSwitch("help")) { |
28 PrintUsage(); | 28 PrintUsage(); |
29 return -1; | 29 return -1; |
30 } | 30 } |
31 | 31 |
32 std::string protocol; | 32 std::string protocol; |
33 int port; | 33 int port; |
34 if (command_line->HasSwitch("https")) { | 34 if (command_line->HasSwitch("https")) { |
35 protocol = "https"; | 35 protocol = "https"; |
36 port = net::TestServerLauncher::kOKHTTPSPort; | 36 port = net::TestServerLauncher::kOKHTTPSPort; |
37 } else if (command_line->HasSwitch("ftp")) { | 37 } else if (command_line->HasSwitch("ftp")) { |
38 protocol = "ftp"; | 38 protocol = "ftp"; |
39 port = kFTPDefaultPort; | 39 port = net::kFTPDefaultPort; |
40 } else { | 40 } else { |
41 protocol = "http"; | 41 protocol = "http"; |
42 port = kHTTPDefaultPort; | 42 port = net::kHTTPDefaultPort; |
43 } | 43 } |
44 std::wstring doc_root = command_line->GetSwitchValue("doc-root"); | 44 std::wstring doc_root = command_line->GetSwitchValue("doc-root"); |
45 if (doc_root.empty()) { | 45 if (doc_root.empty()) { |
46 printf("Error: --doc-root must be specified\n"); | 46 printf("Error: --doc-root must be specified\n"); |
47 PrintUsage(); | 47 PrintUsage(); |
48 return -1; | 48 return -1; |
49 } | 49 } |
50 | 50 |
51 // Launch testserver | 51 // Launch testserver |
52 scoped_refptr<BaseTestServer> test_server; | 52 scoped_refptr<net::BaseTestServer> test_server; |
53 if (protocol == "https") { | 53 if (protocol == "https") { |
54 test_server = HTTPSTestServer::CreateGoodServer(doc_root); | 54 test_server = net::HTTPSTestServer::CreateGoodServer(doc_root); |
55 } else if (protocol == "ftp") { | 55 } else if (protocol == "ftp") { |
56 test_server = FTPTestServer::CreateServer(doc_root); | 56 test_server = net::FTPTestServer::CreateServer(doc_root); |
57 } else if (protocol == "http") { | 57 } else if (protocol == "http") { |
58 test_server = HTTPTestServer::CreateServer(doc_root); | 58 test_server = net::HTTPTestServer::CreateServer(doc_root); |
59 } else { | 59 } else { |
60 NOTREACHED(); | 60 NOTREACHED(); |
61 } | 61 } |
62 | 62 |
63 printf("testserver running at %s://%s:%d (type ctrl+c to exit)\n", | 63 printf("testserver running at %s://%s:%d (type ctrl+c to exit)\n", |
64 protocol.c_str(), | 64 protocol.c_str(), |
65 net::TestServerLauncher::kHostName, | 65 net::TestServerLauncher::kHostName, |
66 port); | 66 port); |
67 | 67 |
68 message_loop.Run(); | 68 message_loop.Run(); |
69 return 0; | 69 return 0; |
70 } | 70 } |
OLD | NEW |