Chromium Code Reviews| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 true, | 138 true, |
| 139 &process_handle_, | 139 &process_handle_, |
| 140 &job_handle_)) { | 140 &job_handle_)) { |
| 141 LOG(ERROR) << "Failed to launch " << python_command.command_line_string(); | 141 LOG(ERROR) << "Failed to launch " << python_command.command_line_string(); |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 namespace { | |
| 149 | |
| 150 bool ReadData(bool* unblocked, HANDLE fd, DWORD bytes_max, uint8* buffer) { | |
| 151 DWORD bytes_read = 0; | |
| 152 while (bytes_read < bytes_max) { | |
| 153 DWORD num_bytes; | |
| 154 if (!ReadFile(fd, buffer + bytes_read, bytes_max - bytes_read, | |
| 155 &num_bytes, NULL)) | |
| 156 return false; | |
| 157 if (num_bytes <= 0) | |
| 158 return false; | |
| 159 if (*unblocked) | |
| 160 return false; | |
| 161 bytes_read += num_bytes; | |
| 162 } | |
| 163 return true; | |
| 164 } | |
| 165 | |
| 166 } // namespace | |
| 167 | |
| 148 bool TestServer::WaitToStart() { | 168 bool TestServer::WaitToStart() { |
| 169 ScopedHandle read_fd(child_read_fd_.Take()); | |
| 170 ScopedHandle write_fd(child_write_fd_.Take()); | |
| 171 | |
| 149 base::Thread thread("test_server_watcher"); | 172 base::Thread thread("test_server_watcher"); |
| 150 if (!thread.Start()) | 173 if (!thread.Start()) |
| 151 return false; | 174 return false; |
| 152 | 175 |
| 153 // Prepare a timeout in case the server fails to start. | 176 // Prepare a timeout in case the server fails to start. |
| 154 bool unblocked = false; | 177 bool unblocked = false; |
| 155 thread.message_loop()->PostDelayedTask(FROM_HERE, | 178 thread.message_loop()->PostDelayedTask(FROM_HERE, |
| 156 NewRunnableFunction(UnblockPipe, child_write_fd_.Get(), &unblocked), | 179 NewRunnableFunction(UnblockPipe, write_fd.Get(), &unblocked), |
| 157 TestTimeouts::action_max_timeout_ms()); | 180 TestTimeouts::action_max_timeout_ms()); |
| 158 | 181 |
| 159 // Try to read two bytes from the pipe indicating the ephemeral port number. | 182 uint32 server_data_len = 0; |
| 160 uint16 port; | 183 if (!ReadData(&unblocked, read_fd.Get(), sizeof(server_data_len), |
| 161 uint8* buffer = reinterpret_cast<uint8*>(&port); | 184 reinterpret_cast<uint8*>(&server_data_len))) |
| 162 DWORD bytes_read = 0; | 185 return false; |
| 163 DWORD bytes_max = sizeof(port); | 186 std::string server_data(server_data_len, '\0'); |
| 164 while (bytes_read < bytes_max) { | 187 if (!ReadData(&unblocked, read_fd.Get(), server_data_len, |
| 165 DWORD num_bytes; | 188 reinterpret_cast<uint8*>(&server_data[0]))) |
| 166 if (!ReadFile(child_read_fd_, buffer + bytes_read, bytes_max - bytes_read, | |
| 167 &num_bytes, NULL)) | |
| 168 break; | |
| 169 if (num_bytes <= 0) | |
| 170 break; | |
| 171 bytes_read += num_bytes; | |
| 172 } | |
| 173 thread.Stop(); | |
| 174 child_read_fd_.Close(); | |
| 175 child_write_fd_.Close(); | |
| 176 | |
| 177 // If we hit the timeout, fail. | |
| 178 if (unblocked) | |
| 179 return false; | 189 return false; |
| 180 | 190 |
| 181 // If not enough bytes were read, fail. | 191 if (!ParseServerData(server_data)) |
|
Paweł Hajdan Jr.
2010/11/18 10:35:12
nit: Similar comments apply: move anonymous namesp
akalin
2010/11/18 22:38:34
Done.
| |
| 182 if (bytes_read < bytes_max) | |
| 183 return false; | 192 return false; |
| 184 | 193 |
| 185 host_port_pair_.set_port(port); | |
| 186 return true; | 194 return true; |
| 187 } | 195 } |
| 188 | 196 |
| 189 bool TestServer::CheckCATrusted() { | 197 bool TestServer::CheckCATrusted() { |
| 190 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); | 198 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); |
| 191 if (!cert_store) { | 199 if (!cert_store) { |
| 192 LOG(ERROR) << " could not open trusted root CA store"; | 200 LOG(ERROR) << " could not open trusted root CA store"; |
| 193 return false; | 201 return false; |
| 194 } | 202 } |
| 195 PCCERT_CONTEXT cert = | 203 PCCERT_CONTEXT cert = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 208 "certificate to your trusted roots for this test to work. " | 216 "certificate to your trusted roots for this test to work. " |
| 209 "For more info visit:\n" | 217 "For more info visit:\n" |
| 210 "http://dev.chromium.org/developers/testing\n"; | 218 "http://dev.chromium.org/developers/testing\n"; |
| 211 return false; | 219 return false; |
| 212 } | 220 } |
| 213 | 221 |
| 214 return true; | 222 return true; |
| 215 } | 223 } |
| 216 | 224 |
| 217 } // namespace net | 225 } // namespace net |
| OLD | NEW |