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

Unified Diff: net/http/http_pipelined_connection_impl_unittest.cc

Issue 8586015: Slow start pipelining. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitelist some socket errors Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_pipelined_connection_impl_unittest.cc
diff --git a/net/http/http_pipelined_connection_impl_unittest.cc b/net/http/http_pipelined_connection_impl_unittest.cc
index a95549430ca21d0be72bf5b870b3e4f19871aa3b..7c589bc76af3fa2cc061a372789f8c8cea942431 100644
--- a/net/http/http_pipelined_connection_impl_unittest.cc
+++ b/net/http/http_pipelined_connection_impl_unittest.cc
@@ -31,9 +31,12 @@ class DummySocketParams : public base::RefCounted<DummySocketParams> {
REGISTER_SOCKET_PARAMS_FOR_POOL(MockTransportClientSocketPool,
DummySocketParams);
-class MockPipelineDelegate : public HttpPipelinedConnectionImpl::Delegate {
+class MockPipelineDelegate : public HttpPipelinedConnection::Delegate {
public:
MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline));
+ MOCK_METHOD2(OnPipelineFeedback, void(
+ HttpPipelinedConnection* pipeline,
+ HttpPipelinedConnection::Feedback feedback));
};
class SuddenCloseObserver : public MessageLoop::TaskObserver {
@@ -1086,6 +1089,136 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
MessageLoop::current()->RunAllPending();
}
+TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
+ MockWrite writes[] = {
+ MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
+ MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
+ MockWrite(false, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"),
+ };
+ MockRead reads[] = {
+ MockRead(true, 3, "HTTP/1.1 200 OK\r\n\r\n"),
+ MockRead(false, 4, "ok.html"),
+ MockRead(false, OK, 5),
+ };
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
+ scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
+ scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
+
+ HttpRequestHeaders headers;
+ HttpResponseInfo response;
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
+ &callback_));
+ EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response,
+ &callback_));
+
+ TestOldCompletionCallback ok_callback;
+ EXPECT_EQ(ERR_IO_PENDING, ok_stream->ReadResponseHeaders(&ok_callback));
+
+ TestOldCompletionCallback evicted_callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ evicted_stream->ReadResponseHeaders(&evicted_callback));
+
+ data_->RunFor(1);
+ EXPECT_LE(OK, ok_callback.WaitForResult());
+ data_->StopAfter(10);
+
+ ExpectResponse("ok.html", ok_stream, false);
+ ok_stream->Close(false);
+
+ EXPECT_EQ(ERR_PIPELINE_EVICTION,
+ rejected_stream->ReadResponseHeaders(&callback_));
+ rejected_stream->Close(true);
+ EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
+ evicted_stream->Close(true);
+}
+
+TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) {
+ MockWrite writes[] = {
+ MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
+ };
+ MockRead reads[] = {
+ MockRead(false, ERR_FAILED, 1),
+ };
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ EXPECT_CALL(delegate_,
+ OnPipelineFeedback(pipeline_.get(),
+ HttpPipelinedConnection::SOCKET_ERROR))
+ .Times(1);
+
+ scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
+ HttpRequestHeaders headers;
+ HttpResponseInfo response;
+ EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(&callback_));
+}
+
+TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) {
+ MockWrite writes[] = {
+ MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
+ };
+ MockRead reads[] = {
+ MockRead(false, 1, "HTTP/1.0 200 OK\r\n"),
+ MockRead(false, 2, "Content-Length: 7\r\n"),
+ MockRead(false, 3, "Connection: keep-alive\r\n\r\n"),
+ MockRead(false, 4, "ok.html"),
+ };
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ EXPECT_CALL(delegate_,
+ OnPipelineFeedback(pipeline_.get(),
+ HttpPipelinedConnection::OLD_HTTP_VERSION))
+ .Times(1);
+
+ scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
+ TestSyncRequest(stream, "ok.html");
+}
+
+TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) {
+ MockWrite writes[] = {
+ MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
+ };
+ MockRead reads[] = {
+ MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
+ MockRead(false, 2, "Content-Length: 7\r\n"),
+ MockRead(false, 3, "Connection: close\r\n\r\n"),
+ MockRead(false, 4, "ok.html"),
+ };
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ EXPECT_CALL(delegate_,
+ OnPipelineFeedback(
+ pipeline_.get(),
+ HttpPipelinedConnection::MUST_CLOSE_CONNECTION))
+ .Times(1);
+
+ scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
+ TestSyncRequest(stream, "ok.html");
+}
+
+TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) {
+ MockWrite writes[] = {
+ MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
+ };
+ MockRead reads[] = {
+ MockRead(false, 1, "HTTP/1.1 200 OK\r\n\r\n"),
+ MockRead(false, 2, "ok.html"),
+ };
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ EXPECT_CALL(delegate_,
+ OnPipelineFeedback(
+ pipeline_.get(),
+ HttpPipelinedConnection::MUST_CLOSE_CONNECTION))
+ .Times(1);
+
+ scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
+ TestSyncRequest(stream, "ok.html");
+}
+
TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
MockWrite writes[] = {
MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),

Powered by Google App Engine
This is Rietveld 408576698