diff options
Diffstat (limited to 'chrome/test/chromedriver')
-rw-r--r-- | chrome/test/chromedriver/net/net_util_unittest.cc | 17 | ||||
-rw-r--r-- | chrome/test/chromedriver/net/test_http_server.cc | 23 | ||||
-rw-r--r-- | chrome/test/chromedriver/net/test_http_server.h | 2 | ||||
-rw-r--r-- | chrome/test/chromedriver/server/chromedriver_server.cc | 10 |
4 files changed, 28 insertions, 24 deletions
diff --git a/chrome/test/chromedriver/net/net_util_unittest.cc b/chrome/test/chromedriver/net/net_util_unittest.cc index dbe41d0..e4d8b14 100644 --- a/chrome/test/chromedriver/net/net_util_unittest.cc +++ b/chrome/test/chromedriver/net/net_util_unittest.cc @@ -20,7 +20,7 @@ #include "net/base/net_errors.h" #include "net/server/http_server.h" #include "net/server/http_server_request_info.h" -#include "net/socket/tcp_server_socket.h" +#include "net/socket/tcp_listen_socket.h" #include "net/url_request/url_request_context_getter.h" #include "testing/gtest/include/gtest/gtest.h" @@ -54,10 +54,8 @@ class FetchUrlTest : public testing::Test, } void InitOnIO(base::WaitableEvent* event) { - scoped_ptr<net::ServerSocket> server_socket( - new net::TCPServerSocket(NULL, net::NetLog::Source())); - server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); - server_.reset(new net::HttpServer(server_socket.Pass(), this)); + net::TCPListenSocketFactory factory("127.0.0.1", 0); + server_ = new net::HttpServer(factory, this); net::IPEndPoint address; CHECK_EQ(net::OK, server_->GetLocalAddress(&address)); server_url_ = base::StringPrintf("http://127.0.0.1:%d", address.port()); @@ -65,7 +63,7 @@ class FetchUrlTest : public testing::Test, } void DestroyServerOnIO(base::WaitableEvent* event) { - server_.reset(NULL); + server_ = NULL; event->Signal(); } @@ -80,7 +78,10 @@ class FetchUrlTest : public testing::Test, server_->Send404(connection_id); break; case kClose: - server_->Close(connection_id); + // net::HttpServer doesn't allow us to close connection during callback. + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&net::HttpServer::Close, server_, connection_id)); break; default: break; @@ -103,7 +104,7 @@ class FetchUrlTest : public testing::Test, base::Thread io_thread_; ServerResponse response_; - scoped_ptr<net::HttpServer> server_; + scoped_refptr<net::HttpServer> server_; scoped_refptr<URLRequestContextGetter> context_getter_; std::string server_url_; }; diff --git a/chrome/test/chromedriver/net/test_http_server.cc b/chrome/test/chromedriver/net/test_http_server.cc index 1d19524..740a33d 100644 --- a/chrome/test/chromedriver/net/test_http_server.cc +++ b/chrome/test/chromedriver/net/test_http_server.cc @@ -13,7 +13,7 @@ #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" #include "net/server/http_server_request_info.h" -#include "net/socket/tcp_server_socket.h" +#include "net/socket/tcp_listen_socket.h" #include "testing/gtest/include/gtest/gtest.h" TestHttpServer::TestHttpServer() @@ -92,7 +92,10 @@ void TestHttpServer::OnWebSocketRequest( server_->Send404(connection_id); break; case kClose: - server_->Close(connection_id); + // net::HttpServer doesn't allow us to close connection during callback. + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&net::HttpServer::Close, server_, connection_id)); break; } } @@ -109,7 +112,10 @@ void TestHttpServer::OnWebSocketMessage(int connection_id, server_->SendOverWebSocket(connection_id, data); break; case kCloseOnMessage: - server_->Close(connection_id); + // net::HttpServer doesn't allow us to close connection during callback. + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&net::HttpServer::Close, server_, connection_id)); break; } } @@ -122,10 +128,8 @@ void TestHttpServer::OnClose(int connection_id) { void TestHttpServer::StartOnServerThread(bool* success, base::WaitableEvent* event) { - scoped_ptr<net::ServerSocket> server_socket( - new net::TCPServerSocket(NULL, net::NetLog::Source())); - server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); - server_.reset(new net::HttpServer(server_socket.Pass(), this)); + net::TCPListenSocketFactory factory("127.0.0.1", 0); + server_ = new net::HttpServer(factory, this); net::IPEndPoint address; int error = server_->GetLocalAddress(&address); @@ -135,13 +139,14 @@ void TestHttpServer::StartOnServerThread(bool* success, web_socket_url_ = GURL(base::StringPrintf("ws://127.0.0.1:%d", address.port())); } else { - server_.reset(NULL); + server_ = NULL; } *success = server_.get(); event->Signal(); } void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) { - server_.reset(NULL); + if (server_.get()) + server_ = NULL; event->Signal(); } diff --git a/chrome/test/chromedriver/net/test_http_server.h b/chrome/test/chromedriver/net/test_http_server.h index 40e6ac4..697434d 100644 --- a/chrome/test/chromedriver/net/test_http_server.h +++ b/chrome/test/chromedriver/net/test_http_server.h @@ -77,7 +77,7 @@ class TestHttpServer : public net::HttpServer::Delegate { base::Thread thread_; // Access only on the server thread. - scoped_ptr<net::HttpServer> server_; + scoped_refptr<net::HttpServer> server_; // Access only on the server thread. std::set<int> connections_; diff --git a/chrome/test/chromedriver/server/chromedriver_server.cc b/chrome/test/chromedriver/server/chromedriver_server.cc index 2508c59..e93091e 100644 --- a/chrome/test/chromedriver/server/chromedriver_server.cc +++ b/chrome/test/chromedriver/server/chromedriver_server.cc @@ -33,7 +33,7 @@ #include "net/server/http_server.h" #include "net/server/http_server_request_info.h" #include "net/server/http_server_response_info.h" -#include "net/socket/tcp_server_socket.h" +#include "net/socket/tcp_listen_socket.h" namespace { @@ -55,10 +55,8 @@ class HttpServer : public net::HttpServer::Delegate { std::string binding_ip = kLocalHostAddress; if (allow_remote) binding_ip = "0.0.0.0"; - scoped_ptr<net::ServerSocket> server_socket( - new net::TCPServerSocket(NULL, net::NetLog::Source())); - server_socket->ListenWithAddressAndPort(binding_ip, port, 1); - server_.reset(new net::HttpServer(server_socket.Pass(), this)); + server_ = new net::HttpServer( + net::TCPListenSocketFactory(binding_ip, port), this); net::IPEndPoint address; return server_->GetLocalAddress(&address) == net::OK; } @@ -91,7 +89,7 @@ class HttpServer : public net::HttpServer::Delegate { } HttpRequestHandlerFunc handle_request_func_; - scoped_ptr<net::HttpServer> server_; + scoped_refptr<net::HttpServer> server_; base::WeakPtrFactory<HttpServer> weak_factory_; // Should be last. }; |