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

Side by Side 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: Patch for landing Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_pipelined_connection_impl.cc ('k') | net/http/http_pipelined_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/http/http_pipelined_connection_impl.h" 5 #include "net/http/http_pipelined_connection_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 13 matching lines...) Expand all
24 namespace net { 24 namespace net {
25 25
26 class DummySocketParams : public base::RefCounted<DummySocketParams> { 26 class DummySocketParams : public base::RefCounted<DummySocketParams> {
27 private: 27 private:
28 friend class base::RefCounted<DummySocketParams>; 28 friend class base::RefCounted<DummySocketParams>;
29 }; 29 };
30 30
31 REGISTER_SOCKET_PARAMS_FOR_POOL(MockTransportClientSocketPool, 31 REGISTER_SOCKET_PARAMS_FOR_POOL(MockTransportClientSocketPool,
32 DummySocketParams); 32 DummySocketParams);
33 33
34 class MockPipelineDelegate : public HttpPipelinedConnectionImpl::Delegate { 34 namespace {
35
36 class MockPipelineDelegate : public HttpPipelinedConnection::Delegate {
35 public: 37 public:
36 MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline)); 38 MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline));
39 MOCK_METHOD2(OnPipelineFeedback, void(
40 HttpPipelinedConnection* pipeline,
41 HttpPipelinedConnection::Feedback feedback));
37 }; 42 };
38 43
39 class SuddenCloseObserver : public MessageLoop::TaskObserver { 44 class SuddenCloseObserver : public MessageLoop::TaskObserver {
40 public: 45 public:
41 SuddenCloseObserver(HttpStream* stream, int close_before_task) 46 SuddenCloseObserver(HttpStream* stream, int close_before_task)
42 : stream_(stream), 47 : stream_(stream),
43 close_before_task_(close_before_task), 48 close_before_task_(close_before_task),
44 current_task_(0) { } 49 current_task_(0) { }
45 50
46 virtual void WillProcessTask(base::TimeTicks) OVERRIDE { 51 virtual void WillProcessTask(base::TimeTicks) OVERRIDE {
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 HttpResponseInfo response2; 1209 HttpResponseInfo response2;
1205 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 1210 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
1206 1211
1207 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 1212 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
1208 stream1.release()->Drain(NULL); 1213 stream1.release()->Drain(NULL);
1209 1214
1210 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); 1215 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_));
1211 stream2->Close(false); 1216 stream2->Close(false);
1212 } 1217 }
1213 1218
1219 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
1220 MockWrite writes[] = {
1221 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1222 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
1223 MockWrite(false, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"),
1224 };
1225 MockRead reads[] = {
1226 MockRead(true, 3, "HTTP/1.1 200 OK\r\n\r\n"),
1227 MockRead(false, 4, "ok.html"),
1228 MockRead(false, OK, 5),
1229 };
1230 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1231
1232 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
1233 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
1234 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
1235
1236 HttpRequestHeaders headers;
1237 HttpResponseInfo response;
1238 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
1239 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
1240 &callback_));
1241 EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response,
1242 &callback_));
1243
1244 TestOldCompletionCallback ok_callback;
1245 EXPECT_EQ(ERR_IO_PENDING, ok_stream->ReadResponseHeaders(&ok_callback));
1246
1247 TestOldCompletionCallback evicted_callback;
1248 EXPECT_EQ(ERR_IO_PENDING,
1249 evicted_stream->ReadResponseHeaders(&evicted_callback));
1250
1251 data_->RunFor(1);
1252 EXPECT_LE(OK, ok_callback.WaitForResult());
1253 data_->StopAfter(10);
1254
1255 ExpectResponse("ok.html", ok_stream, false);
1256 ok_stream->Close(false);
1257
1258 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1259 rejected_stream->ReadResponseHeaders(&callback_));
1260 rejected_stream->Close(true);
1261 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
1262 evicted_stream->Close(true);
1263 }
1264
1265 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) {
1266 MockWrite writes[] = {
1267 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1268 };
1269 MockRead reads[] = {
1270 MockRead(false, ERR_FAILED, 1),
1271 };
1272 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1273
1274 EXPECT_CALL(delegate_,
1275 OnPipelineFeedback(
1276 pipeline_.get(),
1277 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR))
1278 .Times(1);
1279
1280 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1281 HttpRequestHeaders headers;
1282 HttpResponseInfo response;
1283 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_));
1284 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(&callback_));
1285 }
1286
1287 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) {
1288 MockWrite writes[] = {
1289 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1290 };
1291 MockRead reads[] = {
1292 MockRead(false, 1, "HTTP/1.0 200 OK\r\n"),
1293 MockRead(false, 2, "Content-Length: 7\r\n"),
1294 MockRead(false, 3, "Connection: keep-alive\r\n\r\n"),
1295 MockRead(false, 4, "ok.html"),
1296 };
1297 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1298
1299 EXPECT_CALL(delegate_,
1300 OnPipelineFeedback(pipeline_.get(),
1301 HttpPipelinedConnection::OLD_HTTP_VERSION))
1302 .Times(1);
1303
1304 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1305 TestSyncRequest(stream, "ok.html");
1306 }
1307
1308 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) {
1309 MockWrite writes[] = {
1310 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1311 };
1312 MockRead reads[] = {
1313 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
1314 MockRead(false, 2, "Content-Length: 7\r\n"),
1315 MockRead(false, 3, "Connection: close\r\n\r\n"),
1316 MockRead(false, 4, "ok.html"),
1317 };
1318 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1319
1320 EXPECT_CALL(delegate_,
1321 OnPipelineFeedback(
1322 pipeline_.get(),
1323 HttpPipelinedConnection::MUST_CLOSE_CONNECTION))
1324 .Times(1);
1325
1326 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1327 TestSyncRequest(stream, "ok.html");
1328 }
1329
1330 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) {
1331 MockWrite writes[] = {
1332 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1333 };
1334 MockRead reads[] = {
1335 MockRead(false, 1, "HTTP/1.1 200 OK\r\n\r\n"),
1336 MockRead(false, 2, "ok.html"),
1337 };
1338 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1339
1340 EXPECT_CALL(delegate_,
1341 OnPipelineFeedback(
1342 pipeline_.get(),
1343 HttpPipelinedConnection::MUST_CLOSE_CONNECTION))
1344 .Times(1);
1345
1346 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1347 TestSyncRequest(stream, "ok.html");
1348 }
1349
1214 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { 1350 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
1215 MockWrite writes[] = { 1351 MockWrite writes[] = {
1216 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1352 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1217 }; 1353 };
1218 Initialize(NULL, 0, writes, arraysize(writes)); 1354 Initialize(NULL, 0, writes, arraysize(writes));
1219 1355
1220 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1356 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1221 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1357 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1222 1358
1223 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1359 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
(...skipping 19 matching lines...) Expand all
1243 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1379 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1244 1380
1245 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1381 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1246 MessageLoop::current()->RunAllPending(); 1382 MessageLoop::current()->RunAllPending();
1247 1383
1248 stream->Close(false); 1384 stream->Close(false);
1249 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1385 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1250 stream.reset(NULL); 1386 stream.reset(NULL);
1251 } 1387 }
1252 1388
1389 } // anonymous namespace
1390
1253 } // namespace net 1391 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_pipelined_connection_impl.cc ('k') | net/http/http_pipelined_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698