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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 #if defined(OS_MACOSX) | 13 #if defined(OS_MACOSX) |
14 #include "net/base/x509_certificate.h" | 14 #include "net/base/x509_certificate.h" |
15 #endif | 15 #endif |
16 | 16 |
| 17 #include "base/base64.h" |
17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
18 #include "base/debug/leak_annotations.h" | 19 #include "base/debug/leak_annotations.h" |
19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
23 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
24 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
25 #include "net/base/cert_test_util.h" | 26 #include "net/base/cert_test_util.h" |
26 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 CreateSystemHostResolver(HostResolver::kDefaultParallelism, NULL, NULL)); | 246 CreateSystemHostResolver(HostResolver::kDefaultParallelism, NULL, NULL)); |
246 HostResolver::RequestInfo info(host_port_pair_); | 247 HostResolver::RequestInfo info(host_port_pair_); |
247 int rv = resolver->Resolve(info, address_list, NULL, NULL, BoundNetLog()); | 248 int rv = resolver->Resolve(info, address_list, NULL, NULL, BoundNetLog()); |
248 if (rv != net::OK) { | 249 if (rv != net::OK) { |
249 LOG(ERROR) << "Failed to resolve hostname: " << host_port_pair_.host(); | 250 LOG(ERROR) << "Failed to resolve hostname: " << host_port_pair_.host(); |
250 return false; | 251 return false; |
251 } | 252 } |
252 return true; | 253 return true; |
253 } | 254 } |
254 | 255 |
255 GURL TestServer::GetURL(const std::string& path) { | 256 GURL TestServer::GetURL(const std::string& path) const { |
256 return GURL(GetScheme() + "://" + host_port_pair_.ToString() + | 257 return GURL(GetScheme() + "://" + host_port_pair_.ToString() + |
257 "/" + path); | 258 "/" + path); |
258 } | 259 } |
259 | 260 |
260 GURL TestServer::GetURLWithUser(const std::string& path, | 261 GURL TestServer::GetURLWithUser(const std::string& path, |
261 const std::string& user) { | 262 const std::string& user) const { |
262 return GURL(GetScheme() + "://" + user + "@" + | 263 return GURL(GetScheme() + "://" + user + "@" + |
263 host_port_pair_.ToString() + | 264 host_port_pair_.ToString() + |
264 "/" + path); | 265 "/" + path); |
265 } | 266 } |
266 | 267 |
267 GURL TestServer::GetURLWithUserAndPassword(const std::string& path, | 268 GURL TestServer::GetURLWithUserAndPassword(const std::string& path, |
268 const std::string& user, | 269 const std::string& user, |
269 const std::string& password) { | 270 const std::string& password) const { |
270 return GURL(GetScheme() + "://" + user + ":" + password + | 271 return GURL(GetScheme() + "://" + user + ":" + password + |
271 "@" + host_port_pair_.ToString() + | 272 "@" + host_port_pair_.ToString() + |
272 "/" + path); | 273 "/" + path); |
273 } | 274 } |
274 | 275 |
| 276 // static |
| 277 bool TestServer::GetFilePathWithReplacements( |
| 278 const std::string& original_file_path, |
| 279 const std::vector<StringPair>& text_to_replace, |
| 280 std::string* replacement_path) { |
| 281 std::string new_file_path = original_file_path; |
| 282 bool first_query_parameter = true; |
| 283 const std::vector<StringPair>::const_iterator end = text_to_replace.end(); |
| 284 for (std::vector<StringPair>::const_iterator it = text_to_replace.begin(); |
| 285 it != end; |
| 286 ++it) { |
| 287 const std::string& old_text = it->first; |
| 288 const std::string& new_text = it->second; |
| 289 std::string base64_old; |
| 290 std::string base64_new; |
| 291 if (!base::Base64Encode(old_text, &base64_old)) |
| 292 return false; |
| 293 if (!base::Base64Encode(new_text, &base64_new)) |
| 294 return false; |
| 295 if (first_query_parameter) { |
| 296 new_file_path += "?"; |
| 297 first_query_parameter = false; |
| 298 } else { |
| 299 new_file_path += "&"; |
| 300 } |
| 301 new_file_path += "replace_text="; |
| 302 new_file_path += base64_old; |
| 303 new_file_path += ":"; |
| 304 new_file_path += base64_new; |
| 305 } |
| 306 |
| 307 *replacement_path = new_file_path; |
| 308 return true; |
| 309 } |
| 310 |
275 bool TestServer::SetPythonPath() { | 311 bool TestServer::SetPythonPath() { |
276 FilePath third_party_dir; | 312 FilePath third_party_dir; |
277 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { | 313 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { |
278 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 314 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
279 return false; | 315 return false; |
280 } | 316 } |
281 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); | 317 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); |
282 | 318 |
283 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); | 319 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); |
284 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); | 320 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) | 420 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) |
385 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); | 421 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); |
386 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) | 422 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) |
387 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); | 423 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); |
388 } | 424 } |
389 | 425 |
390 return true; | 426 return true; |
391 } | 427 } |
392 | 428 |
393 } // namespace net | 429 } // namespace net |
OLD | NEW |