Skip to content

Commit

Permalink
Add net::HttpServer::Delegate::OnConnect() function and set ChromeDri…
Browse files Browse the repository at this point in the history
…ver buffer sizes to 100 MB

BUG=

Review URL: https://codereview.chromium.org/594393002

Cr-Commit-Position: refs/heads/master@{#296881}
  • Loading branch information
samuong authored and Commit bot committed Sep 26, 2014
1 parent da1f537 commit 0b4d9b9
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 14 deletions.
2 changes: 2 additions & 0 deletions chrome/test/chromedriver/net/net_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
9 changes: 1 addition & 8 deletions chrome/test/chromedriver/net/test_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,14 @@ 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);
}

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_);
Expand All @@ -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_);
Expand Down
3 changes: 2 additions & 1 deletion chrome/test/chromedriver/net/test_http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions chrome/test/chromedriver/server/chromedriver_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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&)>
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions chrome/test/chromedriver/test/run_py_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
1 change: 1 addition & 0 deletions cloud_print/gcp20/prototype/privet_http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions content/browser/devtools/devtools_http_handler_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions mojo/spy/websocket_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion net/server/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions net/server/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 26 additions & 4 deletions net/server/http_server_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -461,8 +465,6 @@ TEST_F(HttpServerTest, SendRaw) {
ASSERT_EQ(expected_response, response);
}

namespace {

class MockStreamSocket : public StreamSocket {
public:
MockStreamSocket()
Expand Down Expand Up @@ -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<StreamSocket>(socket));
Expand Down Expand Up @@ -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<int> 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

0 comments on commit 0b4d9b9

Please sign in to comment.