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

Side by Side Diff: chrome_frame/test/test_server.cc

Issue 2822016: [chrome_frame] Refactor/merge IE no interference tests with other mock event ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome_frame/test/test_server.h ('k') | chrome_frame/test/test_with_web_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/registry.h" 6 #include "base/registry.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h"
8 9
9 #include "chrome_frame/test/test_server.h" 10 #include "chrome_frame/test/test_server.h"
10 11
11 #include "net/base/winsock_init.h" 12 #include "net/base/winsock_init.h"
12 #include "net/http/http_util.h" 13 #include "net/http/http_util.h"
13 14
14 namespace test_server { 15 namespace test_server {
15 const char kDefaultHeaderTemplate[] = 16 const char kDefaultHeaderTemplate[] =
16 "HTTP/1.1 %hs\r\n" 17 "HTTP/1.1 %hs\r\n"
17 "Connection: close\r\n" 18 "Connection: close\r\n"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // 404's when the connection ends. 211 // 404's when the connection ends.
211 Connection* c = FindConnection(sock); 212 Connection* c = FindConnection(sock);
212 DCHECK(c); 213 DCHECK(c);
213 if (!FindResponse(c->request())) { 214 if (!FindResponse(c->request())) {
214 // extremely inefficient, but in one line and not that common... :) 215 // extremely inefficient, but in one line and not that common... :)
215 connections_.erase(std::find(connections_.begin(), connections_.end(), c)); 216 connections_.erase(std::find(connections_.begin(), connections_.end(), c));
216 delete c; 217 delete c;
217 } 218 }
218 } 219 }
219 220
220 HTTPTestServer::HTTPTestServer(int port, const char* address) { 221 HTTPTestServer::HTTPTestServer(int port, const std::wstring& address,
222 FilePath root_dir)
223 : port_(port), address_(address), root_dir_(root_dir) {
221 net::EnsureWinsockInit(); 224 net::EnsureWinsockInit();
222 server_ = ListenSocket::Listen(address, port, this); 225 server_ = ListenSocket::Listen(WideToUTF8(address), port, this);
223 } 226 }
224 227
225 HTTPTestServer::~HTTPTestServer() { 228 HTTPTestServer::~HTTPTestServer() {
226 } 229 }
227 230
228 std::list<scoped_refptr<ConfigurableConnection>>::iterator 231 std::list<scoped_refptr<ConfigurableConnection>>::iterator
229 HTTPTestServer::FindConnection(const ListenSocket* socket) { 232 HTTPTestServer::FindConnection(const ListenSocket* socket) {
230 ConnectionList::iterator it; 233 ConnectionList::iterator it;
231 for (it = connection_list_.begin(); it != connection_list_.end(); ++it) { 234 for (it = connection_list_.begin(); it != connection_list_.end(); ++it) {
232 if ((*it)->socket_ == socket) { 235 if ((*it)->socket_ == socket) {
(...skipping 18 matching lines...) Expand all
251 254
252 void HTTPTestServer::DidRead(ListenSocket* socket, 255 void HTTPTestServer::DidRead(ListenSocket* socket,
253 const char* data, 256 const char* data,
254 int len) { 257 int len) {
255 scoped_refptr<ConfigurableConnection> connection = 258 scoped_refptr<ConfigurableConnection> connection =
256 ConnectionFromSocket(socket); 259 ConnectionFromSocket(socket);
257 if (connection) { 260 if (connection) {
258 std::string str(data, len); 261 std::string str(data, len);
259 connection->r_.OnDataReceived(str); 262 connection->r_.OnDataReceived(str);
260 if (connection->r_.AllContentReceived()) { 263 if (connection->r_.AllContentReceived()) {
264 std::wstring path = UTF8ToWide(connection->r_.path());
261 if (LowerCaseEqualsASCII(connection->r_.method(), "post")) 265 if (LowerCaseEqualsASCII(connection->r_.method(), "post"))
262 this->Post(connection, connection->r_.path(), connection->r_); 266 this->Post(connection, path, connection->r_);
263 else 267 else
264 this->Get(connection, connection->r_.path(), connection->r_); 268 this->Get(connection, path, connection->r_);
265 } 269 }
266 } 270 }
267 } 271 }
268 272
269 void HTTPTestServer::DidClose(ListenSocket* socket) { 273 void HTTPTestServer::DidClose(ListenSocket* socket) {
270 ConnectionList::iterator it = FindConnection(socket); 274 ConnectionList::iterator it = FindConnection(socket);
271 DCHECK(it != connection_list_.end()); 275 DCHECK(it != connection_list_.end());
272 connection_list_.erase(it); 276 connection_list_.erase(it);
273 } 277 }
274 278
279 std::wstring HTTPTestServer::Resolve(const std::wstring& path) {
280 // Remove the first '/' if needed.
281 std::wstring stripped_path = path;
282 if (path.size() && path[0] == L'/')
283 stripped_path = path.substr(1);
284
285 if (port_ == 80) {
286 if (stripped_path.empty()) {
287 return StringPrintf(L"http://%ls", address_.c_str());
288 } else {
289 return StringPrintf(L"http://%ls/%ls", address_.c_str(),
290 stripped_path.c_str());
291 }
292 } else {
293 if (stripped_path.empty()) {
294 return StringPrintf(L"http://%ls:%d", address_.c_str(), port_);
295 } else {
296 return StringPrintf(L"http://%ls:%d/%ls", address_.c_str(), port_,
297 stripped_path.c_str());
298 }
299 }
300 }
301
275 void ConfigurableConnection::SendChunk() { 302 void ConfigurableConnection::SendChunk() {
276 int size = (int)data_.size(); 303 int size = (int)data_.size();
277 const char* chunk_ptr = data_.c_str() + cur_pos_; 304 const char* chunk_ptr = data_.c_str() + cur_pos_;
278 int bytes_to_send = std::min(options_.chunk_size_, size - cur_pos_); 305 int bytes_to_send = std::min(options_.chunk_size_, size - cur_pos_);
279 306
280 socket_->Send(chunk_ptr, bytes_to_send); 307 socket_->Send(chunk_ptr, bytes_to_send);
281 DLOG(INFO) << "Sent(" << cur_pos_ << "," << bytes_to_send 308 DLOG(INFO) << "Sent(" << cur_pos_ << "," << bytes_to_send
282 << "): " << base::StringPiece(chunk_ptr, bytes_to_send); 309 << "): " << base::StringPiece(chunk_ptr, bytes_to_send);
283 310
284 cur_pos_ += bytes_to_send; 311 cur_pos_ += bytes_to_send;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (options_.speed_ == SendOptions::DELAYED) { 354 if (options_.speed_ == SendOptions::DELAYED) {
328 data_ = headers; 355 data_ = headers;
329 data_.append(content_length_header); 356 data_.append(content_length_header);
330 data_.append("\r\n"); 357 data_.append("\r\n");
331 } 358 }
332 359
333 MessageLoop::current()->PostDelayedTask(FROM_HERE, 360 MessageLoop::current()->PostDelayedTask(FROM_HERE,
334 NewRunnableMethod(this, &ConfigurableConnection::SendChunk), 361 NewRunnableMethod(this, &ConfigurableConnection::SendChunk),
335 options.timeout_); 362 options.timeout_);
336 } 363 }
337 } // namespace test_server 364
365 } // namespace test_server
OLDNEW
« no previous file with comments | « chrome_frame/test/test_server.h ('k') | chrome_frame/test/test_with_web_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698