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. (simplejson, unlike all the other python modules |
| 285 // we include, doesn't have an extra 'simplejson' directory, so we |
| 286 // need to include its parent directory, i.e. third_party_dir). |
| 287 AppendToPythonPath(third_party_dir); |
| 288 |
281 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); | 289 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("tlslite"))); |
282 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); | 290 AppendToPythonPath(third_party_dir.Append(FILE_PATH_LITERAL("pyftpdlib"))); |
283 | 291 |
284 // Locate the Python code generated by the protocol buffers compiler. | 292 // Locate the Python code generated by the protocol buffers compiler. |
285 FilePath pyproto_code_dir; | 293 FilePath pyproto_code_dir; |
286 if (!GetPyProtoPath(&pyproto_code_dir)) { | 294 if (!GetPyProtoPath(&pyproto_code_dir)) { |
287 LOG(ERROR) << "Failed to get python dir for generated code."; | 295 LOG(ERROR) << "Failed to get python dir for generated code."; |
288 return false; | 296 return false; |
289 } | 297 } |
290 | 298 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes128"); | 374 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes128"); |
367 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) | 375 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_AES256) |
368 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); | 376 command_line->AppendSwitchASCII(kBulkCipherSwitch, "aes256"); |
369 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) | 377 if (https_options_.bulk_ciphers & HTTPSOptions::BULK_CIPHER_3DES) |
370 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); | 378 command_line->AppendSwitchASCII(kBulkCipherSwitch, "3des"); |
371 } | 379 } |
372 | 380 |
373 return true; | 381 return true; |
374 } | 382 } |
375 | 383 |
| 384 bool TestServer::ParseServerData(const std::string& server_data) { |
| 385 VLOG(1) << "Server data: " << server_data; |
| 386 base::JSONReader json_reader; |
| 387 scoped_ptr<Value> value(json_reader.JsonToValue(server_data, true, false)); |
| 388 if (!value.get() || |
| 389 !value->IsType(Value::TYPE_DICTIONARY)) { |
| 390 LOG(ERROR) << "Could not parse server data: " |
| 391 << json_reader.GetErrorMessage(); |
| 392 return false; |
| 393 } |
| 394 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 395 int port = 0; |
| 396 if (!dict->GetInteger("port", &port)) { |
| 397 LOG(ERROR) << "Could not find port value"; |
| 398 return false; |
| 399 } |
| 400 if ((port <= 0) || (port >= kuint16max)) { |
| 401 LOG(ERROR) << "Invalid port value: " << port; |
| 402 return false; |
| 403 } |
| 404 host_port_pair_.set_port(port); |
| 405 return true; |
| 406 } |
| 407 |
376 } // namespace net | 408 } // namespace net |
OLD | NEW |