| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spawner_communicator.h" | 5 #include "net/test/spawner_communicator.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // Send the start command to spawner server to start the Python test server | 314 // Send the start command to spawner server to start the Python test server |
| 315 // on remote machine. | 315 // on remote machine. |
| 316 std::string server_return_data; | 316 std::string server_return_data; |
| 317 int result_code; | 317 int result_code; |
| 318 SendCommandAndWaitForResult("start", arguments, &result_code, | 318 SendCommandAndWaitForResult("start", arguments, &result_code, |
| 319 &server_return_data); | 319 &server_return_data); |
| 320 if (OK != result_code || server_return_data.empty()) | 320 if (OK != result_code || server_return_data.empty()) |
| 321 return false; | 321 return false; |
| 322 | 322 |
| 323 // Check whether the data returned from spawner server is JSON-formatted. | 323 // Check whether the data returned from spawner server is JSON-formatted. |
| 324 base::JSONReader json_reader; | 324 scoped_ptr<base::Value> value(base::JSONReader::Read(server_return_data)); |
| 325 scoped_ptr<base::Value> value(json_reader.JsonToValue(server_return_data, | |
| 326 true, false)); | |
| 327 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) { | 325 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 328 LOG(ERROR) << "Invalid server data: " << server_return_data.c_str(); | 326 LOG(ERROR) << "Invalid server data: " << server_return_data.c_str(); |
| 329 return false; | 327 return false; |
| 330 } | 328 } |
| 331 | 329 |
| 332 // Check whether spawner server returns valid data. | 330 // Check whether spawner server returns valid data. |
| 333 DictionaryValue* server_data = static_cast<DictionaryValue*>(value.get()); | 331 DictionaryValue* server_data = static_cast<DictionaryValue*>(value.get()); |
| 334 std::string message; | 332 std::string message; |
| 335 if (!server_data->GetString("message", &message) || message != "started") { | 333 if (!server_data->GetString("message", &message) || message != "started") { |
| 336 LOG(ERROR) << "Invalid message in server data: "; | 334 LOG(ERROR) << "Invalid message in server data: "; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 357 std::string server_return_data; | 355 std::string server_return_data; |
| 358 int result_code; | 356 int result_code; |
| 359 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); | 357 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); |
| 360 if (OK != result_code || server_return_data != "killed") | 358 if (OK != result_code || server_return_data != "killed") |
| 361 return false; | 359 return false; |
| 362 Shutdown(); | 360 Shutdown(); |
| 363 return true; | 361 return true; |
| 364 } | 362 } |
| 365 | 363 |
| 366 } // namespace net | 364 } // namespace net |
| OLD | NEW |