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/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "net/test/python_utils.h" |
14 #include "net/test/test_server.h" | 16 #include "net/test/test_server.h" |
15 | 17 |
16 static void PrintUsage() { | 18 static void PrintUsage() { |
17 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" | 19 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" |
18 " [--https-cert=ok|mismatched-name|expired]\n"); | 20 " [--https-cert=ok|mismatched-name|expired]\n"); |
19 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); | 21 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); |
20 } | 22 } |
21 | 23 |
| 24 // Launches the chromiumsync_test script, testing the --sync functionality. |
| 25 static bool RunSyncTest() { |
| 26 if (!net::TestServer::SetPythonPath()) { |
| 27 LOG(ERROR) << "Error trying to set python path. Exiting."; |
| 28 return false; |
| 29 } |
| 30 |
| 31 FilePath sync_test_path; |
| 32 if (!net::TestServer::GetTestServerDirectory(&sync_test_path)) { |
| 33 LOG(ERROR) << "Error trying to get python test server path."; |
| 34 return false; |
| 35 } |
| 36 |
| 37 sync_test_path = |
| 38 sync_test_path.Append(FILE_PATH_LITERAL("chromiumsync_test.py")); |
| 39 FilePath python_runtime; |
| 40 if (!GetPythonRunTime(&python_runtime)) { |
| 41 LOG(ERROR) << "Could not get python runtime command."; |
| 42 return false; |
| 43 } |
| 44 |
| 45 CommandLine python_command(python_runtime); |
| 46 python_command.AppendArgPath(sync_test_path); |
| 47 if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) { |
| 48 LOG(ERROR) << "Failed to launch test script."; |
| 49 return false; |
| 50 } |
| 51 return true; |
| 52 } |
| 53 |
22 int main(int argc, const char* argv[]) { | 54 int main(int argc, const char* argv[]) { |
23 base::AtExitManager at_exit_manager; | 55 base::AtExitManager at_exit_manager; |
24 MessageLoopForIO message_loop; | 56 MessageLoopForIO message_loop; |
25 | 57 |
26 // Process command line | 58 // Process command line |
27 CommandLine::Init(argc, argv); | 59 CommandLine::Init(argc, argv); |
28 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
29 | 61 |
30 if (!logging::InitLogging( | 62 if (!logging::InitLogging( |
31 FILE_PATH_LITERAL("testserver.log"), | 63 FILE_PATH_LITERAL("testserver.log"), |
(...skipping 12 matching lines...) Expand all Loading... |
44 return -1; | 76 return -1; |
45 } | 77 } |
46 | 78 |
47 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); | 79 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); |
48 if (command_line->HasSwitch("https")) { | 80 if (command_line->HasSwitch("https")) { |
49 server_type = net::TestServer::TYPE_HTTPS; | 81 server_type = net::TestServer::TYPE_HTTPS; |
50 } else if (command_line->HasSwitch("ftp")) { | 82 } else if (command_line->HasSwitch("ftp")) { |
51 server_type = net::TestServer::TYPE_FTP; | 83 server_type = net::TestServer::TYPE_FTP; |
52 } else if (command_line->HasSwitch("sync")) { | 84 } else if (command_line->HasSwitch("sync")) { |
53 server_type = net::TestServer::TYPE_SYNC; | 85 server_type = net::TestServer::TYPE_SYNC; |
| 86 } else if (command_line->HasSwitch("sync-test")) { |
| 87 return RunSyncTest() ? 0 : -1; |
54 } | 88 } |
55 | 89 |
56 net::TestServer::HTTPSOptions https_options; | 90 net::TestServer::HTTPSOptions https_options; |
57 if (command_line->HasSwitch("https-cert")) { | 91 if (command_line->HasSwitch("https-cert")) { |
58 server_type = net::TestServer::TYPE_HTTPS; | 92 server_type = net::TestServer::TYPE_HTTPS; |
59 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); | 93 std::string cert_option = command_line->GetSwitchValueASCII("https-cert"); |
60 if (cert_option == "ok") { | 94 if (cert_option == "ok") { |
61 https_options.server_certificate = net::TestServer::HTTPSOptions::CERT_OK; | 95 https_options.server_certificate = net::TestServer::HTTPSOptions::CERT_OK; |
62 } else if (cert_option == "mismatched-name") { | 96 } else if (cert_option == "mismatched-name") { |
63 https_options.server_certificate = | 97 https_options.server_certificate = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); | 131 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); |
98 return -1; | 132 return -1; |
99 } | 133 } |
100 | 134 |
101 printf("testserver running at %s (type ctrl+c to exit)\n", | 135 printf("testserver running at %s (type ctrl+c to exit)\n", |
102 test_server->host_port_pair().ToString().c_str()); | 136 test_server->host_port_pair().ToString().c_str()); |
103 | 137 |
104 message_loop.Run(); | 138 message_loop.Run(); |
105 return 0; | 139 return 0; |
106 } | 140 } |
OLD | NEW |