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/base64.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/debug/leak_annotations.h" | 19 #include "base/debug/leak_annotations.h" |
| 20 #include "base/json/json_reader.h" | |
| 20 #include "base/file_util.h" | 21 #include "base/file_util.h" |
| 21 #include "base/logging.h" | 22 #include "base/logging.h" |
| 22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 24 #include "base/scoped_ptr.h" | |
| 23 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
| 24 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 27 #include "base/values.h" | |
| 25 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 26 #include "net/base/cert_test_util.h" | 29 #include "net/base/cert_test_util.h" |
| 27 #include "net/base/host_port_pair.h" | 30 #include "net/base/host_port_pair.h" |
| 28 #include "net/base/host_resolver.h" | 31 #include "net/base/host_resolver.h" |
| 29 #include "net/base/test_completion_callback.h" | 32 #include "net/base/test_completion_callback.h" |
| 30 #include "net/socket/tcp_client_socket.h" | 33 #include "net/socket/tcp_client_socket.h" |
| 31 #include "net/test/python_utils.h" | 34 #include "net/test/python_utils.h" |
| 32 #include "testing/platform_test.h" | 35 #include "testing/platform_test.h" |
| 33 | 36 |
| 34 namespace net { | 37 namespace net { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 } | 274 } |
| 272 | 275 |
| 273 bool TestServer::SetPythonPath() { | 276 bool TestServer::SetPythonPath() { |
| 274 FilePath third_party_dir; | 277 FilePath third_party_dir; |
| 275 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { | 278 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { |
| 276 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 279 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
| 277 return false; | 280 return false; |
| 278 } | 281 } |
| 279 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); | 282 third_party_dir = third_party_dir.Append(FILE_PATH_LITERAL("third_party")); |
| 280 | 283 |
| 284 // For simplejson. | |
| 285 AppendToPythonPath(third_party_dir); | |
|
cbentzel
2010/11/17 22:32:50
This should be third_party_dir.Append(FILE_PATH_LI
akalin
2010/11/17 23:21:35
It should not -- the 'simplejson' directory, unlik
cbentzel
2010/11/18 01:47:19
Thanks. Could you expand the "For simplejson" comm
| |
| 286 | |
| 281 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); | 287 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); |
| 282 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); | 288 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); |
| 283 | 289 |
| 284 // Locate the Python code generated by the protocol buffers compiler. | 290 // Locate the Python code generated by the protocol buffers compiler. |
| 285 FilePath pyproto_code_dir; | 291 FilePath pyproto_code_dir; |
| 286 if (!GetPyProtoPath(&pyproto_code_dir)) { | 292 if (!GetPyProtoPath(&pyproto_code_dir)) { |
| 287 LOG(ERROR) << "Failed to get python dir for generated code."; | 293 LOG(ERROR) << "Failed to get python dir for generated code."; |
| 288 return false; | 294 return false; |
| 289 } | 295 } |
| 290 | 296 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes128"); | 372 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes128"); |
| 367 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) | 373 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) |
| 368 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); | 374 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); |
| 369 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) | 375 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) |
| 370 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); | 376 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); |
| 371 } | 377 } |
| 372 | 378 |
| 373 return true; | 379 return true; |
| 374 } | 380 } |
| 375 | 381 |
| 382 bool TestServer::ParseServerData(const std::string& server_data) { | |
|
cbentzel
2010/11/17 22:32:50
Should this be non-mutating static and have an out
akalin
2010/11/17 23:21:35
Hmm, in a future CL, the dict value is stashed in
| |
| 383 VLOG(1) << "Server data: " << server_data; | |
| 384 base::JSONReader json_reader; | |
| 385 scoped_ptr<Value> value(json_reader.JsonToValue(server_data, true, true)); | |
|
cbentzel
2010/11/17 22:32:50
Why is "allow trailing comma" needed - the parser
akalin
2010/11/17 23:21:35
Done.
| |
| 386 if (!value.get() || | |
| 387 !value->IsType(Value::TYPE_DICTIONARY)) { | |
| 388 LOG(ERROR) << "Could not parse server data: " | |
| 389 << json_reader.GetErrorMessage(); | |
| 390 return false; | |
| 391 } | |
| 392 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | |
| 393 int port = 0; | |
| 394 if (!dict->GetInteger("port", &port) || | |
|
cbentzel
2010/11/17 22:32:50
I thought you were working on multiple ports? Or i
akalin
2010/11/17 23:21:35
Yeah, it'll be in a separate CL (i'll send it to y
| |
| 395 (port <= 0) || (port >= kuint16max)) { | |
|
cbentzel
2010/11/17 22:32:50
I'd prefer splitting this into two different condi
akalin
2010/11/17 23:21:35
Done.
| |
| 396 LOG(ERROR) << "Could not find valid port value"; | |
| 397 return false; | |
| 398 } | |
| 399 host_port_pair_.set_port(port); | |
| 400 return true; | |
| 401 } | |
| 402 | |
| 376 } // namespace net | 403 } // namespace net |
| OLD | NEW |