| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 base::Thread thread("test_server_watcher"); | 149 base::Thread thread("test_server_watcher"); |
| 150 if (!thread.Start()) | 150 if (!thread.Start()) |
| 151 return false; | 151 return false; |
| 152 | 152 |
| 153 // Prepare a timeout in case the server fails to start. | 153 // Prepare a timeout in case the server fails to start. |
| 154 bool unblocked = false; | 154 bool unblocked = false; |
| 155 thread.message_loop()->PostDelayedTask(FROM_HERE, | 155 thread.message_loop()->PostDelayedTask(FROM_HERE, |
| 156 NewRunnableFunction(UnblockPipe, child_write_fd_.Get(), &unblocked), | 156 NewRunnableFunction(UnblockPipe, child_write_fd_.Get(), &unblocked), |
| 157 TestTimeouts::action_max_timeout_ms()); | 157 TestTimeouts::action_max_timeout_ms()); |
| 158 | 158 |
| 159 char buf[8]; | 159 // Try to read two bytes from the pipe indicating the ephemeral port number. |
| 160 DWORD bytes_read; | 160 uint16 port; |
| 161 BOOL result = ReadFile(child_read_fd_.Get(), buf, sizeof(buf), &bytes_read, | 161 uint8* buffer = reinterpret_cast<uint8*>(&port); |
| 162 NULL); | 162 DWORD bytes_read = 0; |
| 163 | 163 DWORD bytes_max = sizeof(port); |
| 164 while (bytes_read < bytes_max) { |
| 165 DWORD num_bytes; |
| 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 } |
| 164 thread.Stop(); | 173 thread.Stop(); |
| 165 child_read_fd_.Close(); | 174 child_read_fd_.Close(); |
| 166 child_write_fd_.Close(); | 175 child_write_fd_.Close(); |
| 167 | 176 |
| 168 // If we hit the timeout, fail. | 177 // If we hit the timeout, fail. |
| 169 if (unblocked) | 178 if (unblocked) |
| 170 return false; | 179 return false; |
| 171 | 180 |
| 172 return result && bytes_read > 0; | 181 // If not enough bytes were read, fail. |
| 182 if (bytes_read < bytes_max) |
| 183 return false; |
| 184 |
| 185 host_port_pair_.set_port(port); |
| 186 return true; |
| 173 } | 187 } |
| 174 | 188 |
| 175 bool TestServer::CheckCATrusted() { | 189 bool TestServer::CheckCATrusted() { |
| 176 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); | 190 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); |
| 177 if (!cert_store) { | 191 if (!cert_store) { |
| 178 LOG(ERROR) << " could not open trusted root CA store"; | 192 LOG(ERROR) << " could not open trusted root CA store"; |
| 179 return false; | 193 return false; |
| 180 } | 194 } |
| 181 PCCERT_CONTEXT cert = | 195 PCCERT_CONTEXT cert = |
| 182 CertFindCertificateInStore(cert_store, | 196 CertFindCertificateInStore(cert_store, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 "certificate to your trusted roots for this test to work. " | 208 "certificate to your trusted roots for this test to work. " |
| 195 "For more info visit:\n" | 209 "For more info visit:\n" |
| 196 "http://dev.chromium.org/developers/testing\n"; | 210 "http://dev.chromium.org/developers/testing\n"; |
| 197 return false; | 211 return false; |
| 198 } | 212 } |
| 199 | 213 |
| 200 return true; | 214 return true; |
| 201 } | 215 } |
| 202 | 216 |
| 203 } // namespace net | 217 } // namespace net |
| OLD | NEW |