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 "net/test/test_server.h" | 5 #include "net/test/test_server.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/command_line.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/process_util.h" | 14 #include "base/process_util.h" |
14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Helper class used to detect and kill orphaned python test server processes. | 21 // Helper class used to detect and kill orphaned python test server processes. |
(...skipping 27 matching lines...) Expand all Loading... |
48 | 49 |
49 private: | 50 private: |
50 std::string path_string_; | 51 std::string path_string_; |
51 std::string port_string_; | 52 std::string port_string_; |
52 DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter); | 53 DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter); |
53 }; | 54 }; |
54 | 55 |
55 } // namespace | 56 } // namespace |
56 | 57 |
57 namespace net { | 58 namespace net { |
| 59 |
58 bool TestServer::LaunchPython(const FilePath& testserver_path) { | 60 bool TestServer::LaunchPython(const FilePath& testserver_path) { |
59 std::vector<std::string> command_line; | 61 CommandLine python_command(FilePath(FILE_PATH_LITERAL("python"))); |
60 command_line.push_back("python"); | 62 python_command.AppendArgPath(testserver_path); |
61 command_line.push_back(testserver_path.value()); | 63 if (!AddCommandLineArguments(&python_command)) |
62 command_line.push_back("--port=" + base::IntToString(host_port_pair_.port())); | 64 return false; |
63 command_line.push_back("--data-dir=" + document_root_.value()); | |
64 | |
65 if (type_ == TYPE_FTP) | |
66 command_line.push_back("-f"); | |
67 | |
68 FilePath certificate_path(GetCertificatePath()); | |
69 if (!certificate_path.value().empty()) { | |
70 if (!file_util::PathExists(certificate_path)) { | |
71 LOG(ERROR) << "Certificate path " << certificate_path.value() | |
72 << " doesn't exist. Can't launch https server."; | |
73 return false; | |
74 } | |
75 command_line.push_back("--https=" + certificate_path.value()); | |
76 } | |
77 | |
78 if (type_ == TYPE_HTTPS_CLIENT_AUTH) | |
79 command_line.push_back("--ssl-client-auth"); | |
80 | 65 |
81 int pipefd[2]; | 66 int pipefd[2]; |
82 if (pipe(pipefd) != 0) { | 67 if (pipe(pipefd) != 0) { |
83 PLOG(ERROR) << "Could not create pipe."; | 68 PLOG(ERROR) << "Could not create pipe."; |
84 return false; | 69 return false; |
85 } | 70 } |
86 | 71 |
87 // Save the read half. The write half is sent to the child. | 72 // Save the read half. The write half is sent to the child. |
88 child_fd_ = pipefd[0]; | 73 child_fd_ = pipefd[0]; |
89 child_fd_closer_.reset(&child_fd_); | 74 child_fd_closer_.reset(&child_fd_); |
90 file_util::ScopedFD write_closer(&pipefd[1]); | 75 file_util::ScopedFD write_closer(&pipefd[1]); |
91 base::file_handle_mapping_vector map_write_fd; | 76 base::file_handle_mapping_vector map_write_fd; |
92 map_write_fd.push_back(std::make_pair(pipefd[1], pipefd[1])); | 77 map_write_fd.push_back(std::make_pair(pipefd[1], pipefd[1])); |
93 | 78 |
94 command_line.push_back("--startup-pipe=" + base::IntToString(pipefd[1])); | 79 python_command.AppendSwitchASCII("startup-pipe", |
| 80 base::IntToString(pipefd[1])); |
95 | 81 |
96 // Try to kill any orphaned testserver processes that may be running. | 82 // Try to kill any orphaned testserver processes that may be running. |
97 OrphanedTestServerFilter filter(testserver_path.value(), | 83 OrphanedTestServerFilter filter(testserver_path.value(), |
98 base::IntToString(host_port_pair_.port())); | 84 base::IntToString(host_port_pair_.port())); |
99 if (!base::KillProcesses(L"python", -1, &filter)) { | 85 if (!base::KillProcesses(L"python", -1, &filter)) { |
100 LOG(WARNING) << "Failed to clean up older orphaned testserver instances."; | 86 LOG(WARNING) << "Failed to clean up older orphaned testserver instances."; |
101 } | 87 } |
102 | 88 |
103 // Launch a new testserver process. | 89 // Launch a new testserver process. |
104 if (!base::LaunchApp(command_line, map_write_fd, false, &process_handle_)) { | 90 if (!base::LaunchApp(python_command.argv(), map_write_fd, false, |
105 LOG(ERROR) << "Failed to launch " << command_line[0] << " ..."; | 91 &process_handle_)) { |
| 92 LOG(ERROR) << "Failed to launch " << python_command.command_line_string() |
| 93 << " ..."; |
106 return false; | 94 return false; |
107 } | 95 } |
108 | 96 |
109 return true; | 97 return true; |
110 } | 98 } |
111 | 99 |
112 bool TestServer::WaitToStart() { | 100 bool TestServer::WaitToStart() { |
113 struct pollfd poll_fds[1]; | 101 struct pollfd poll_fds[1]; |
114 | 102 |
115 poll_fds[0].fd = child_fd_; | 103 poll_fds[0].fd = child_fd_; |
(...skipping 12 matching lines...) Expand all Loading... |
128 // We don't need the FD anymore. | 116 // We don't need the FD anymore. |
129 child_fd_closer_.reset(NULL); | 117 child_fd_closer_.reset(NULL); |
130 return n > 0; | 118 return n > 0; |
131 } | 119 } |
132 | 120 |
133 bool TestServer::CheckCATrusted() { | 121 bool TestServer::CheckCATrusted() { |
134 return true; | 122 return true; |
135 } | 123 } |
136 | 124 |
137 } // namespace net | 125 } // namespace net |
OLD | NEW |