Chromium Code Reviews| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <objbase.h> | 6 #include <objbase.h> |
| 7 #include <urlmon.h> | 7 #include <urlmon.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome_frame/test/chrome_frame_test_utils.h" | |
| 16 #include "chrome_frame/test/test_server.h" | 17 #include "chrome_frame/test/test_server.h" |
| 17 #include "net/base/tcp_listen_socket.h" | 18 #include "net/base/tcp_listen_socket.h" |
| 18 #include "net/base/winsock_init.h" | 19 #include "net/base/winsock_init.h" |
| 19 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
| 20 | 21 |
| 21 namespace test_server { | 22 namespace test_server { |
| 22 const char kDefaultHeaderTemplate[] = | 23 const char kDefaultHeaderTemplate[] = |
| 23 "HTTP/1.1 %hs\r\n" | 24 "HTTP/1.1 %hs\r\n" |
| 24 "Connection: close\r\n" | 25 "Connection: close\r\n" |
| 25 "Content-Type: %hs\r\n" | 26 "Content-Type: %hs\r\n" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 *headers = base::StringPrintf("HTTP/1.1 302 Found\r\n" | 130 *headers = base::StringPrintf("HTTP/1.1 302 Found\r\n" |
| 130 "Connection: close\r\n" | 131 "Connection: close\r\n" |
| 131 "Content-Length: 0\r\n" | 132 "Content-Length: 0\r\n" |
| 132 "Content-Type: text/html\r\n" | 133 "Content-Type: text/html\r\n" |
| 133 "Location: %hs\r\n\r\n", | 134 "Location: %hs\r\n\r\n", |
| 134 redirect_url_.c_str()); | 135 redirect_url_.c_str()); |
| 135 return true; | 136 return true; |
| 136 } | 137 } |
| 137 | 138 |
| 138 SimpleWebServer::SimpleWebServer(int port) { | 139 SimpleWebServer::SimpleWebServer(int port) { |
| 139 CHECK(MessageLoop::current()) << "SimpleWebServer requires a message loop"; | 140 Construct(chrome_frame_test::GetLocalIPv4Address(), port); |
| 140 net::EnsureWinsockInit(); | 141 } |
| 141 AddResponse(&quit_); | 142 |
| 142 server_ = net::TCPListenSocket::CreateAndListen("127.0.0.1", port, this); | 143 SimpleWebServer::SimpleWebServer(const std::string& address, int port) { |
| 143 DCHECK(server_.get() != NULL); | 144 Construct(address, port); |
| 144 } | 145 } |
| 145 | 146 |
| 146 SimpleWebServer::~SimpleWebServer() { | 147 SimpleWebServer::~SimpleWebServer() { |
| 147 ConnectionList::const_iterator it; | 148 ConnectionList::const_iterator it; |
| 148 for (it = connections_.begin(); it != connections_.end(); ++it) | 149 for (it = connections_.begin(); it != connections_.end(); ++it) |
| 149 delete (*it); | 150 delete (*it); |
| 150 connections_.clear(); | 151 connections_.clear(); |
| 151 } | 152 } |
| 152 | 153 |
| 154 void SimpleWebServer::Construct(const std::string& address, int port) { | |
| 155 CHECK(MessageLoop::current()) << "SimpleWebServer requires a message loop"; | |
| 156 net::EnsureWinsockInit(); | |
| 157 AddResponse(&quit_); | |
| 158 host_ = address; | |
| 159 server_ = net::TCPListenSocket::CreateAndListen(address, port, this); | |
| 160 DCHECK(server_.get() != NULL); | |
|
robertshield
2012/08/22 20:18:27
Since this is running in tests, can we log a failu
grt (UTC plus 2)
2012/08/24 15:36:40
Done.
| |
| 161 } | |
| 162 | |
| 153 void SimpleWebServer::AddResponse(Response* response) { | 163 void SimpleWebServer::AddResponse(Response* response) { |
| 154 responses_.push_back(response); | 164 responses_.push_back(response); |
| 155 } | 165 } |
| 156 | 166 |
| 157 void SimpleWebServer::DeleteAllResponses() { | 167 void SimpleWebServer::DeleteAllResponses() { |
| 158 std::list<Response*>::const_iterator it; | 168 std::list<Response*>::const_iterator it; |
| 159 for (it = responses_.begin(); it != responses_.end(); ++it) { | 169 for (it = responses_.begin(); it != responses_.end(); ++it) { |
| 160 if ((*it) != &quit_) | 170 if ((*it) != &quit_) |
| 161 delete (*it); | 171 delete (*it); |
| 162 } | 172 } |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 data_.append(content_length_header); | 409 data_.append(content_length_header); |
| 400 data_.append("\r\n"); | 410 data_.append("\r\n"); |
| 401 } | 411 } |
| 402 | 412 |
| 403 MessageLoop::current()->PostDelayedTask( | 413 MessageLoop::current()->PostDelayedTask( |
| 404 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), | 414 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), |
| 405 base::TimeDelta::FromMilliseconds(options.timeout_)); | 415 base::TimeDelta::FromMilliseconds(options.timeout_)); |
| 406 } | 416 } |
| 407 | 417 |
| 408 } // namespace test_server | 418 } // namespace test_server |
| OLD | NEW |