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 <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<std::string>& text_to_replace, | |
| 280 std::string* replacement_path) { | |
| 281 DCHECK_EQ(0U, (text_to_replace.size() % 2)); | |
|
akalin
2010/11/11 05:20:54
if you take a vector of pairs, this won't be neces
Paweł Hajdan Jr.
2010/11/11 10:40:45
Yeah, this should really take a vector of pairs.
cbentzel
2010/11/11 15:34:09
That made things cleaner, thanks for suggestion.
| |
| 282 if (text_to_replace.empty()) { | |
|
akalin
2010/11/11 05:20:54
this check isn't necessary -- if you fall through
cbentzel
2010/11/11 15:34:09
Done.
| |
| 283 *replacement_path = original_file_path; | |
| 284 return true; | |
| 285 } | |
| 286 | |
| 287 std::string new_file_path = original_file_path; | |
| 288 for (size_t i = 0; i < text_to_replace.size(); i += 2) { | |
| 289 const std::string& old_text = text_to_replace[i]; | |
| 290 const std::string& new_text = text_to_replace[i + 1]; | |
| 291 std::string base64_old; | |
| 292 std::string base64_new; | |
| 293 if (!base::Base64Encode(old_text, &base64_old)) | |
| 294 return false; | |
| 295 if (!base::Base64Encode(new_text, &base64_new)) | |
| 296 return false; | |
| 297 new_file_path += (i == 0) ? "?" : "&"; | |
|
Paweł Hajdan Jr.
2010/11/11 10:40:45
I'm not sure if I understand the logic that decide
cbentzel
2010/11/11 15:34:09
That's correct. The new implementation should make
| |
| 298 new_file_path += "replace_text="; | |
| 299 new_file_path += base64_old; | |
| 300 new_file_path += ":"; | |
| 301 new_file_path += base64_new; | |
| 302 } | |
| 303 | |
| 304 *replacement_path = new_file_path; | |
| 305 return true; | |
| 306 } | |
| 307 | |
| 275 bool TestServer::SetPythonPath() { | 308 bool TestServer::SetPythonPath() { |
| 276 FilePath third_party_dir; | 309 FilePath third_party_dir; |
| 277 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { | 310 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { |
| 278 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 311 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
| 279 return false; | 312 return false; |
| 280 } | 313 } |
| 281 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); | 314 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); |
| 282 | 315 |
| 283 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); | 316 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); |
| 284 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); | 317 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) | 417 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) |
| 385 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); | 418 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); |
| 386 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) | 419 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) |
| 387 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); | 420 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); |
| 388 } | 421 } |
| 389 | 422 |
| 390 return true; | 423 return true; |
| 391 } | 424 } |
| 392 | 425 |
| 393 } // namespace net | 426 } // namespace net |
| OLD | NEW |