From 0b4d9b95e0cb553624b994df899ee4010425985e Mon Sep 17 00:00:00 2001 From: samuong Date: Thu, 25 Sep 2014 21:15:29 -0700 Subject: [PATCH] Add net::HttpServer::Delegate::OnConnect() function and set ChromeDriver buffer sizes to 100 MB BUG= Review URL: https://codereview.chromium.org/594393002 Cr-Commit-Position: refs/heads/master@{#296881} --- .../chromedriver/net/net_util_unittest.cc | 2 ++ .../test/chromedriver/net/test_http_server.cc | 9 +----- .../test/chromedriver/net/test_http_server.h | 3 +- .../server/chromedriver_server.cc | 5 ++++ chrome/test/chromedriver/test/run_py_tests.py | 10 +++++++ .../gcp20/prototype/privet_http_server.h | 1 + .../devtools/devtools_http_handler_impl.h | 1 + mojo/spy/websocket_server.h | 1 + net/server/http_server.cc | 4 ++- net/server/http_server.h | 1 + net/server/http_server_unittest.cc | 30 ++++++++++++++++--- 11 files changed, 53 insertions(+), 14 deletions(-) diff --git a/chrome/test/chromedriver/net/net_util_unittest.cc b/chrome/test/chromedriver/net/net_util_unittest.cc index dbe41d042c6b..801620df7b51 100644 --- a/chrome/test/chromedriver/net/net_util_unittest.cc +++ b/chrome/test/chromedriver/net/net_util_unittest.cc @@ -70,6 +70,8 @@ class FetchUrlTest : public testing::Test, } // Overridden from net::HttpServer::Delegate: + virtual void OnConnect(int connection_id) OVERRIDE {} + virtual void OnHttpRequest(int connection_id, const net::HttpServerRequestInfo& info) OVERRIDE { switch (response_) { diff --git a/chrome/test/chromedriver/net/test_http_server.cc b/chrome/test/chromedriver/net/test_http_server.cc index f8795cc992c4..6b8a4bcf4c12 100644 --- a/chrome/test/chromedriver/net/test_http_server.cc +++ b/chrome/test/chromedriver/net/test_http_server.cc @@ -75,9 +75,7 @@ GURL TestHttpServer::web_socket_url() const { return web_socket_url_; } -void TestHttpServer::OnHttpRequest( - int connection_id, - const net::HttpServerRequestInfo& info) { +void TestHttpServer::OnConnect(int connection_id) { server_->SetSendBufferSize(connection_id, kBufferSize); server_->SetReceiveBufferSize(connection_id, kBufferSize); } @@ -85,9 +83,6 @@ void TestHttpServer::OnHttpRequest( void TestHttpServer::OnWebSocketRequest( int connection_id, const net::HttpServerRequestInfo& info) { - server_->SetSendBufferSize(connection_id, kBufferSize); - server_->SetReceiveBufferSize(connection_id, kBufferSize); - WebSocketRequestAction action; { base::AutoLock lock(action_lock_); @@ -111,8 +106,6 @@ void TestHttpServer::OnWebSocketRequest( void TestHttpServer::OnWebSocketMessage(int connection_id, const std::string& data) { - server_->SetSendBufferSize(connection_id, kBufferSize); - server_->SetReceiveBufferSize(connection_id, kBufferSize); WebSocketMessageAction action; { base::AutoLock lock(action_lock_); diff --git a/chrome/test/chromedriver/net/test_http_server.h b/chrome/test/chromedriver/net/test_http_server.h index 048cd34fba7e..70b26a5f7ec3 100644 --- a/chrome/test/chromedriver/net/test_http_server.h +++ b/chrome/test/chromedriver/net/test_http_server.h @@ -61,8 +61,9 @@ class TestHttpServer : public net::HttpServer::Delegate { GURL web_socket_url() const; // Overridden from net::HttpServer::Delegate: + virtual void OnConnect(int connection_id) OVERRIDE; virtual void OnHttpRequest(int connection_id, - const net::HttpServerRequestInfo& info) OVERRIDE; + const net::HttpServerRequestInfo& info) OVERRIDE {} virtual void OnWebSocketRequest( int connection_id, const net::HttpServerRequestInfo& info) OVERRIDE; diff --git a/chrome/test/chromedriver/server/chromedriver_server.cc b/chrome/test/chromedriver/server/chromedriver_server.cc index f06a7fc9c34b..97725407d0b5 100644 --- a/chrome/test/chromedriver/server/chromedriver_server.cc +++ b/chrome/test/chromedriver/server/chromedriver_server.cc @@ -38,6 +38,7 @@ namespace { const char* kLocalHostAddress = "127.0.0.1"; +const int kBufferSize = 100 * 1024 * 1024; // 100 MB typedef base::Callback< void(const net::HttpServerRequestInfo&, const HttpResponseSenderFunc&)> @@ -64,6 +65,10 @@ class HttpServer : public net::HttpServer::Delegate { } // Overridden from net::HttpServer::Delegate: + virtual void OnConnect(int connection_id) OVERRIDE { + server_->SetSendBufferSize(connection_id, kBufferSize); + server_->SetReceiveBufferSize(connection_id, kBufferSize); + } virtual void OnHttpRequest(int connection_id, const net::HttpServerRequestInfo& info) OVERRIDE { handle_request_func_.Run( diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/test/run_py_tests.py index 2b106a6783a3..1738f434267c 100755 --- a/chrome/test/chromedriver/test/run_py_tests.py +++ b/chrome/test/chromedriver/test/run_py_tests.py @@ -715,6 +715,16 @@ def testDoesntHangOnDebugger(self): def testMobileEmulationDisabledByDefault(self): self.assertFalse(self._driver.capabilities['mobileEmulationEnabled']) + def testChromeDriverSendLargeData(self): + script = 's = ""; for (i = 0; i < 10e6; i++) s += "0"; return s;' + lots_of_data = self._driver.ExecuteScript(script) + self.assertEquals('0'.zfill(int(10e6)), lots_of_data) + + def testChromeDriverRecieveAndSendLargeData(self): + lots_of_data = '1'.zfill(int(10e6)) + result = self._driver.ExecuteScript('return "%s"' % lots_of_data) + self.assertEquals(lots_of_data, result) + class ChromeDriverAndroidTest(ChromeDriverBaseTest): """End to end tests for Android-specific tests.""" diff --git a/cloud_print/gcp20/prototype/privet_http_server.h b/cloud_print/gcp20/prototype/privet_http_server.h index 6cb14d106459..5a3a2fe589a8 100644 --- a/cloud_print/gcp20/prototype/privet_http_server.h +++ b/cloud_print/gcp20/prototype/privet_http_server.h @@ -141,6 +141,7 @@ class PrivetHttpServer: public net::HttpServer::Delegate { private: // net::HttpServer::Delegate methods: + virtual void OnConnect(int connection_id) OVERRIDE {} virtual void OnHttpRequest( int connection_id, const net::HttpServerRequestInfo& info) OVERRIDE; diff --git a/content/browser/devtools/devtools_http_handler_impl.h b/content/browser/devtools/devtools_http_handler_impl.h index 0276c3f6b3d3..9f32bf70ddda 100644 --- a/content/browser/devtools/devtools_http_handler_impl.h +++ b/content/browser/devtools/devtools_http_handler_impl.h @@ -56,6 +56,7 @@ class DevToolsHttpHandlerImpl virtual GURL GetFrontendURL() OVERRIDE; // net::HttpServer::Delegate implementation. + virtual void OnConnect(int connection_id) OVERRIDE {} virtual void OnHttpRequest(int connection_id, const net::HttpServerRequestInfo& info) OVERRIDE; virtual void OnWebSocketRequest( diff --git a/mojo/spy/websocket_server.h b/mojo/spy/websocket_server.h index eb685c7f2288..272d6829735e 100644 --- a/mojo/spy/websocket_server.h +++ b/mojo/spy/websocket_server.h @@ -38,6 +38,7 @@ class WebSocketServer : public net::HttpServer::Delegate, protected: // Overridden from net::HttpServer::Delegate. + virtual void OnConnect(int connection_id) OVERRIDE {} virtual void OnHttpRequest( int connection_id, const net::HttpServerRequestInfo& info) OVERRIDE; diff --git a/net/server/http_server.cc b/net/server/http_server.cc index fb0dab37a4f4..6c7ee52f31b3 100644 --- a/net/server/http_server.cc +++ b/net/server/http_server.cc @@ -153,7 +153,9 @@ int HttpServer::HandleAcceptResult(int rv) { HttpConnection* connection = new HttpConnection(++last_id_, accepted_socket_.Pass()); id_to_connection_[connection->id()] = connection; - DoReadLoop(connection); + delegate_->OnConnect(connection->id()); + if (!HasClosedConnection(connection)) + DoReadLoop(connection); return OK; } diff --git a/net/server/http_server.h b/net/server/http_server.h index 2ae698b98c53..47214ab158ec 100644 --- a/net/server/http_server.h +++ b/net/server/http_server.h @@ -30,6 +30,7 @@ class HttpServer { // destroy the HttpServer in any of these callbacks. class Delegate { public: + virtual void OnConnect(int connection_id) = 0; virtual void OnHttpRequest(int connection_id, const HttpServerRequestInfo& info) = 0; virtual void OnWebSocketRequest(int connection_id, diff --git a/net/server/http_server_unittest.cc b/net/server/http_server_unittest.cc index 42e56399a10a..216cb0341617 100644 --- a/net/server/http_server_unittest.cc +++ b/net/server/http_server_unittest.cc @@ -189,6 +189,8 @@ class HttpServerTest : public testing::Test, ASSERT_EQ(OK, server_->GetLocalAddress(&server_address_)); } + virtual void OnConnect(int connection_id) OVERRIDE {} + virtual void OnHttpRequest(int connection_id, const HttpServerRequestInfo& info) OVERRIDE { requests_.push_back(std::make_pair(info, connection_id)); @@ -243,6 +245,8 @@ class HttpServerTest : public testing::Test, size_t quit_after_request_count_; }; +namespace { + class WebSocketTest : public HttpServerTest { virtual void OnHttpRequest(int connection_id, const HttpServerRequestInfo& info) OVERRIDE { @@ -461,8 +465,6 @@ TEST_F(HttpServerTest, SendRaw) { ASSERT_EQ(expected_response, response); } -namespace { - class MockStreamSocket : public StreamSocket { public: MockStreamSocket() @@ -557,8 +559,6 @@ class MockStreamSocket : public StreamSocket { DISALLOW_COPY_AND_ASSIGN(MockStreamSocket); }; -} // namespace - TEST_F(HttpServerTest, RequestWithBodySplitAcrossPackets) { MockStreamSocket* socket = new MockStreamSocket(); HandleAcceptResult(make_scoped_ptr(socket)); @@ -619,4 +619,26 @@ TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); } +class CloseOnConnectHttpServerTest : public HttpServerTest { + public: + virtual void OnConnect(int connection_id) OVERRIDE { + connection_ids_.push_back(connection_id); + server_->Close(connection_id); + } + + protected: + std::vector connection_ids_; +}; + +TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { + TestHttpClient client; + ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); + client.Send("GET / HTTP/1.1\r\n\r\n"); + ASSERT_FALSE(RunUntilRequestsReceived(1)); + ASSERT_EQ(1ul, connection_ids_.size()); + ASSERT_EQ(0ul, requests_.size()); +} + +} // namespace + } // namespace net