Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: net/test/spawner_communicator.cc

Issue 10559036: Added URLRequestContext to constructor for URLRequest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Converted new unittest. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 void SpawnerCommunicator::SendCommandAndWaitForResultOnIOThread( 157 void SpawnerCommunicator::SendCommandAndWaitForResultOnIOThread(
158 const std::string& command, 158 const std::string& command,
159 const std::string& post_data, 159 const std::string& post_data,
160 int* result_code, 160 int* result_code,
161 std::string* data_received) { 161 std::string* data_received) {
162 MessageLoop* loop = io_thread_.message_loop(); 162 MessageLoop* loop = io_thread_.message_loop();
163 DCHECK(loop); 163 DCHECK(loop);
164 DCHECK_EQ(MessageLoop::current(), loop); 164 DCHECK_EQ(MessageLoop::current(), loop);
165 165
166 context_.reset(new TestURLRequestContext);
167
166 // Prepare the URLRequest for sending the command. 168 // Prepare the URLRequest for sending the command.
167 DCHECK(!cur_request_.get()); 169 DCHECK(!cur_request_.get());
mmenke 2012/06/20 18:33:50 Put this first, so the DCHECK occurs before the li
shalev 2012/06/20 20:13:12 Done.
shalev 2012/06/20 20:13:12 Done.
168 cur_request_.reset(new URLRequest(GenerateSpawnerCommandURL(command, port_), 170 cur_request_.reset(new URLRequest(GenerateSpawnerCommandURL(command, port_),
169 this)); 171 this,
172 context_.get()));
170 DCHECK(cur_request_.get()); 173 DCHECK(cur_request_.get());
171 int current_request_id = ++next_id_; 174 int current_request_id = ++next_id_;
172 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, 175 SpawnerRequestData* data = new SpawnerRequestData(current_request_id,
173 result_code, 176 result_code,
174 data_received); 177 data_received);
175 DCHECK(data); 178 DCHECK(data);
176 cur_request_->SetUserData(this, data); 179 cur_request_->SetUserData(this, data);
177 180
178 // Build the URLRequest.
179 context_.reset(new TestURLRequestContext);
180 cur_request_->set_context(context_.get());
181 if (post_data.empty()) { 181 if (post_data.empty()) {
182 cur_request_->set_method("GET"); 182 cur_request_->set_method("GET");
183 } else { 183 } else {
184 cur_request_->set_method("POST"); 184 cur_request_->set_method("POST");
185 cur_request_->AppendBytesToUpload(post_data.c_str(), post_data.size()); 185 cur_request_->AppendBytesToUpload(post_data.c_str(), post_data.size());
186 net::HttpRequestHeaders headers; 186 net::HttpRequestHeaders headers;
187 headers.SetHeader(net::HttpRequestHeaders::kContentType, 187 headers.SetHeader(net::HttpRequestHeaders::kContentType,
188 "application/json"); 188 "application/json");
189 cur_request_->SetExtraRequestHeaders(headers); 189 cur_request_->SetExtraRequestHeaders(headers);
190 } 190 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 std::string server_return_data; 362 std::string server_return_data;
363 int result_code; 363 int result_code;
364 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); 364 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data);
365 if (OK != result_code || server_return_data != "killed") 365 if (OK != result_code || server_return_data != "killed")
366 return false; 366 return false;
367 Shutdown(); 367 Shutdown();
368 return true; 368 return true;
369 } 369 }
370 370
371 } // namespace net 371 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698