| 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" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "net/base/upload_data.h" |
| 17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 GURL GenerateSpawnerCommandURL(const std::string& command, uint16 port) { | 25 GURL GenerateSpawnerCommandURL(const std::string& command, uint16 port) { |
| 25 // Always performs HTTP request for sending command to the spawner server. | 26 // Always performs HTTP request for sending command to the spawner server. |
| 26 return GURL(base::StringPrintf("%s:%u/%s", "http://127.0.0.1", port, | 27 return GURL(base::StringPrintf("%s:%u/%s", "http://127.0.0.1", port, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, | 177 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, |
| 177 result_code, | 178 result_code, |
| 178 data_received); | 179 data_received); |
| 179 DCHECK(data); | 180 DCHECK(data); |
| 180 cur_request_->SetUserData(this, data); | 181 cur_request_->SetUserData(this, data); |
| 181 | 182 |
| 182 if (post_data.empty()) { | 183 if (post_data.empty()) { |
| 183 cur_request_->set_method("GET"); | 184 cur_request_->set_method("GET"); |
| 184 } else { | 185 } else { |
| 185 cur_request_->set_method("POST"); | 186 cur_request_->set_method("POST"); |
| 186 cur_request_->AppendBytesToUpload(post_data.c_str(), post_data.size()); | 187 scoped_refptr<UploadData> upload_data(new UploadData()); |
| 188 upload_data->AppendBytes(post_data.c_str(), post_data.size()); |
| 189 cur_request_->set_upload(upload_data); |
| 187 net::HttpRequestHeaders headers; | 190 net::HttpRequestHeaders headers; |
| 188 headers.SetHeader(net::HttpRequestHeaders::kContentType, | 191 headers.SetHeader(net::HttpRequestHeaders::kContentType, |
| 189 "application/json"); | 192 "application/json"); |
| 190 cur_request_->SetExtraRequestHeaders(headers); | 193 cur_request_->SetExtraRequestHeaders(headers); |
| 191 } | 194 } |
| 192 | 195 |
| 193 // Post a task to timeout this request if it takes too long. | 196 // Post a task to timeout this request if it takes too long. |
| 194 MessageLoop::current()->PostDelayedTask( | 197 MessageLoop::current()->PostDelayedTask( |
| 195 FROM_HERE, | 198 FROM_HERE, |
| 196 base::Bind(&SpawnerCommunicator::OnTimeout, weak_factory_.GetWeakPtr(), | 199 base::Bind(&SpawnerCommunicator::OnTimeout, weak_factory_.GetWeakPtr(), |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 std::string server_return_data; | 366 std::string server_return_data; |
| 364 int result_code; | 367 int result_code; |
| 365 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); | 368 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); |
| 366 Shutdown(); | 369 Shutdown(); |
| 367 if (OK != result_code || server_return_data != "killed") | 370 if (OK != result_code || server_return_data != "killed") |
| 368 return false; | 371 return false; |
| 369 return true; | 372 return true; |
| 370 } | 373 } |
| 371 | 374 |
| 372 } // namespace net | 375 } // namespace net |
| OLD | NEW |