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

Side by Side Diff: net/http/http_pipelined_connection_impl_unittest.cc

Issue 9425016: Change MockRead and MockWrite (et. al.) to take an IoMode enum, instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 8 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 TEST_F(HttpPipelinedConnectionImplTest, StreamBoundButNotUsed) { 172 TEST_F(HttpPipelinedConnectionImplTest, StreamBoundButNotUsed) {
173 Initialize(NULL, 0, NULL, 0); 173 Initialize(NULL, 0, NULL, 0);
174 174
175 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 175 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
176 176
177 stream->Close(false); 177 stream->Close(false);
178 } 178 }
179 179
180 TEST_F(HttpPipelinedConnectionImplTest, SyncSingleRequest) { 180 TEST_F(HttpPipelinedConnectionImplTest, SyncSingleRequest) {
181 MockWrite writes[] = { 181 MockWrite writes[] = {
182 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 182 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
183 }; 183 };
184 MockRead reads[] = { 184 MockRead reads[] = {
185 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 185 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
186 MockRead(false, 2, "Content-Length: 7\r\n\r\n"), 186 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"),
187 MockRead(false, 3, "ok.html"), 187 MockRead(SYNCHRONOUS, 3, "ok.html"),
188 }; 188 };
189 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 189 Initialize(reads, arraysize(reads), writes, arraysize(writes));
190 190
191 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 191 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
192 TestSyncRequest(stream, "ok.html"); 192 TestSyncRequest(stream, "ok.html");
193 } 193 }
194 194
195 TEST_F(HttpPipelinedConnectionImplTest, AsyncSingleRequest) { 195 TEST_F(HttpPipelinedConnectionImplTest, AsyncSingleRequest) {
196 MockWrite writes[] = { 196 MockWrite writes[] = {
197 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 197 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
198 }; 198 };
199 MockRead reads[] = { 199 MockRead reads[] = {
200 MockRead(true, 1, "HTTP/1.1 200 OK\r\n"), 200 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"),
201 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 201 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"),
202 MockRead(true, 3, "ok.html"), 202 MockRead(ASYNC, 3, "ok.html"),
203 }; 203 };
204 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 204 Initialize(reads, arraysize(reads), writes, arraysize(writes));
205 205
206 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 206 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
207 207
208 HttpRequestHeaders headers; 208 HttpRequestHeaders headers;
209 HttpResponseInfo response; 209 HttpResponseInfo response;
210 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response, 210 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
211 callback_.callback())); 211 callback_.callback()));
212 data_->RunFor(1); 212 data_->RunFor(1);
213 EXPECT_LE(OK, callback_.WaitForResult()); 213 EXPECT_LE(OK, callback_.WaitForResult());
214 214
215 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); 215 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback()));
216 data_->RunFor(2); 216 data_->RunFor(2);
217 EXPECT_LE(OK, callback_.WaitForResult()); 217 EXPECT_LE(OK, callback_.WaitForResult());
218 218
219 ExpectResponse("ok.html", stream, true); 219 ExpectResponse("ok.html", stream, true);
220 220
221 stream->Close(false); 221 stream->Close(false);
222 } 222 }
223 223
224 TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) { 224 TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) {
225 MockWrite writes[] = { 225 MockWrite writes[] = {
226 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 226 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
227 MockWrite(true, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), 227 MockWrite(ASYNC, 1, "GET /ko.html HTTP/1.1\r\n\r\n"),
228 }; 228 };
229 MockRead reads[] = { 229 MockRead reads[] = {
230 MockRead(true, 2, "HTTP/1.1 200 OK\r\n"), 230 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"),
231 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 231 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"),
232 MockRead(true, 4, "ok.html"), 232 MockRead(ASYNC, 4, "ok.html"),
233 MockRead(true, 5, "HTTP/1.1 200 OK\r\n"), 233 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"),
234 MockRead(true, 6, "Content-Length: 7\r\n\r\n"), 234 MockRead(ASYNC, 6, "Content-Length: 7\r\n\r\n"),
235 MockRead(true, 7, "ko.html"), 235 MockRead(ASYNC, 7, "ko.html"),
236 }; 236 };
237 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 237 Initialize(reads, arraysize(reads), writes, arraysize(writes));
238 238
239 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 239 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
240 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 240 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
241 241
242 HttpRequestHeaders headers1; 242 HttpRequestHeaders headers1;
243 HttpResponseInfo response1; 243 HttpResponseInfo response1;
244 EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, NULL, &response1, 244 EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, NULL, &response1,
245 callback_.callback())); 245 callback_.callback()));
(...skipping 21 matching lines...) Expand all
267 data_->RunFor(2); 267 data_->RunFor(2);
268 EXPECT_LE(OK, callback_.WaitForResult()); 268 EXPECT_LE(OK, callback_.WaitForResult());
269 269
270 ExpectResponse("ko.html", stream2, true); 270 ExpectResponse("ko.html", stream2, true);
271 271
272 stream2->Close(false); 272 stream2->Close(false);
273 } 273 }
274 274
275 TEST_F(HttpPipelinedConnectionImplTest, TwoResponsesInOnePacket) { 275 TEST_F(HttpPipelinedConnectionImplTest, TwoResponsesInOnePacket) {
276 MockWrite writes[] = { 276 MockWrite writes[] = {
277 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 277 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
278 MockWrite(false, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), 278 MockWrite(SYNCHRONOUS, 1, "GET /ko.html HTTP/1.1\r\n\r\n"),
279 }; 279 };
280 MockRead reads[] = { 280 MockRead reads[] = {
281 MockRead(false, 2, 281 MockRead(SYNCHRONOUS, 2,
282 "HTTP/1.1 200 OK\r\n" 282 "HTTP/1.1 200 OK\r\n"
283 "Content-Length: 7\r\n\r\n" 283 "Content-Length: 7\r\n\r\n"
284 "ok.html" 284 "ok.html"
285 "HTTP/1.1 200 OK\r\n" 285 "HTTP/1.1 200 OK\r\n"
286 "Content-Length: 7\r\n\r\n" 286 "Content-Length: 7\r\n\r\n"
287 "ko.html"), 287 "ko.html"),
288 }; 288 };
289 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 289 Initialize(reads, arraysize(reads), writes, arraysize(writes));
290 290
291 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 291 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
(...skipping 12 matching lines...) Expand all
304 ExpectResponse("ok.html", stream1, false); 304 ExpectResponse("ok.html", stream1, false);
305 stream1->Close(false); 305 stream1->Close(false);
306 306
307 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); 307 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
308 ExpectResponse("ko.html", stream2, false); 308 ExpectResponse("ko.html", stream2, false);
309 stream2->Close(false); 309 stream2->Close(false);
310 } 310 }
311 311
312 TEST_F(HttpPipelinedConnectionImplTest, SendOrderSwapped) { 312 TEST_F(HttpPipelinedConnectionImplTest, SendOrderSwapped) {
313 MockWrite writes[] = { 313 MockWrite writes[] = {
314 MockWrite(false, 0, "GET /ko.html HTTP/1.1\r\n\r\n"), 314 MockWrite(SYNCHRONOUS, 0, "GET /ko.html HTTP/1.1\r\n\r\n"),
315 MockWrite(false, 4, "GET /ok.html HTTP/1.1\r\n\r\n"), 315 MockWrite(SYNCHRONOUS, 4, "GET /ok.html HTTP/1.1\r\n\r\n"),
316 }; 316 };
317 MockRead reads[] = { 317 MockRead reads[] = {
318 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 318 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
319 MockRead(false, 2, "Content-Length: 7\r\n\r\n"), 319 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"),
320 MockRead(false, 3, "ko.html"), 320 MockRead(SYNCHRONOUS, 3, "ko.html"),
321 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 321 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
322 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 322 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"),
323 MockRead(false, 7, "ok.html"), 323 MockRead(SYNCHRONOUS, 7, "ok.html"),
324 }; 324 };
325 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 325 Initialize(reads, arraysize(reads), writes, arraysize(writes));
326 326
327 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 327 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
328 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 328 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
329 329
330 TestSyncRequest(stream2, "ko.html"); 330 TestSyncRequest(stream2, "ko.html");
331 TestSyncRequest(stream1, "ok.html"); 331 TestSyncRequest(stream1, "ok.html");
332 } 332 }
333 333
334 TEST_F(HttpPipelinedConnectionImplTest, ReadOrderSwapped) { 334 TEST_F(HttpPipelinedConnectionImplTest, ReadOrderSwapped) {
335 MockWrite writes[] = { 335 MockWrite writes[] = {
336 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 336 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
337 MockWrite(false, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), 337 MockWrite(SYNCHRONOUS, 1, "GET /ko.html HTTP/1.1\r\n\r\n"),
338 }; 338 };
339 MockRead reads[] = { 339 MockRead reads[] = {
340 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 340 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
341 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 341 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"),
342 MockRead(false, 4, "ok.html"), 342 MockRead(SYNCHRONOUS, 4, "ok.html"),
343 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 343 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
344 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 344 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"),
345 MockRead(false, 7, "ko.html"), 345 MockRead(SYNCHRONOUS, 7, "ko.html"),
346 }; 346 };
347 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 347 Initialize(reads, arraysize(reads), writes, arraysize(writes));
348 348
349 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 349 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
350 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 350 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
351 351
352 HttpRequestHeaders headers1; 352 HttpRequestHeaders headers1;
353 HttpResponseInfo response1; 353 HttpResponseInfo response1;
354 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 354 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
355 callback_.callback())); 355 callback_.callback()));
(...skipping 11 matching lines...) Expand all
367 stream1->Close(false); 367 stream1->Close(false);
368 368
369 EXPECT_LE(OK, callback_.WaitForResult()); 369 EXPECT_LE(OK, callback_.WaitForResult());
370 ExpectResponse("ko.html", stream2, false); 370 ExpectResponse("ko.html", stream2, false);
371 371
372 stream2->Close(false); 372 stream2->Close(false);
373 } 373 }
374 374
375 TEST_F(HttpPipelinedConnectionImplTest, SendWhileReading) { 375 TEST_F(HttpPipelinedConnectionImplTest, SendWhileReading) {
376 MockWrite writes[] = { 376 MockWrite writes[] = {
377 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 377 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
378 MockWrite(false, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), 378 MockWrite(SYNCHRONOUS, 3, "GET /ko.html HTTP/1.1\r\n\r\n"),
379 }; 379 };
380 MockRead reads[] = { 380 MockRead reads[] = {
381 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 381 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
382 MockRead(false, 2, "Content-Length: 7\r\n\r\n"), 382 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"),
383 MockRead(false, 4, "ok.html"), 383 MockRead(SYNCHRONOUS, 4, "ok.html"),
384 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 384 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
385 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 385 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"),
386 MockRead(false, 7, "ko.html"), 386 MockRead(SYNCHRONOUS, 7, "ko.html"),
387 }; 387 };
388 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 388 Initialize(reads, arraysize(reads), writes, arraysize(writes));
389 389
390 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 390 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
391 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 391 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
392 392
393 HttpRequestHeaders headers1; 393 HttpRequestHeaders headers1;
394 HttpResponseInfo response1; 394 HttpResponseInfo response1;
395 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 395 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
396 callback_.callback())); 396 callback_.callback()));
397 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); 397 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
398 398
399 HttpRequestHeaders headers2; 399 HttpRequestHeaders headers2;
400 HttpResponseInfo response2; 400 HttpResponseInfo response2;
401 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, 401 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
402 callback_.callback())); 402 callback_.callback()));
403 403
404 ExpectResponse("ok.html", stream1, false); 404 ExpectResponse("ok.html", stream1, false);
405 stream1->Close(false); 405 stream1->Close(false);
406 406
407 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); 407 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
408 ExpectResponse("ko.html", stream2, false); 408 ExpectResponse("ko.html", stream2, false);
409 stream2->Close(false); 409 stream2->Close(false);
410 } 410 }
411 411
412 TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) { 412 TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) {
413 MockWrite writes[] = { 413 MockWrite writes[] = {
414 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 414 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
415 MockWrite(true, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), 415 MockWrite(ASYNC, 3, "GET /ko.html HTTP/1.1\r\n\r\n"),
416 }; 416 };
417 MockRead reads[] = { 417 MockRead reads[] = {
418 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 418 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
419 MockRead(false, 2, "Content-Length: 7\r\n\r\n"), 419 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"),
420 MockRead(true, 4, "ok.html"), 420 MockRead(ASYNC, 4, "ok.html"),
421 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 421 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
422 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 422 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"),
423 MockRead(false, 7, "ko.html"), 423 MockRead(SYNCHRONOUS, 7, "ko.html"),
424 }; 424 };
425 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 425 Initialize(reads, arraysize(reads), writes, arraysize(writes));
426 426
427 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 427 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
428 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 428 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
429 429
430 HttpRequestHeaders headers1; 430 HttpRequestHeaders headers1;
431 HttpResponseInfo response1; 431 HttpResponseInfo response1;
432 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 432 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
433 callback_.callback())); 433 callback_.callback()));
(...skipping 23 matching lines...) Expand all
457 stream1->Close(false); 457 stream1->Close(false);
458 458
459 data_->StopAfter(8); 459 data_->StopAfter(8);
460 EXPECT_LE(OK, callback2.WaitForResult()); 460 EXPECT_LE(OK, callback2.WaitForResult());
461 ExpectResponse("ko.html", stream2, false); 461 ExpectResponse("ko.html", stream2, false);
462 stream2->Close(false); 462 stream2->Close(false);
463 } 463 }
464 464
465 TEST_F(HttpPipelinedConnectionImplTest, UnusedStreamAllowsLaterUse) { 465 TEST_F(HttpPipelinedConnectionImplTest, UnusedStreamAllowsLaterUse) {
466 MockWrite writes[] = { 466 MockWrite writes[] = {
467 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 467 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
468 }; 468 };
469 MockRead reads[] = { 469 MockRead reads[] = {
470 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 470 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
471 MockRead(false, 2, "Content-Length: 7\r\n\r\n"), 471 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"),
472 MockRead(false, 3, "ok.html"), 472 MockRead(SYNCHRONOUS, 3, "ok.html"),
473 }; 473 };
474 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 474 Initialize(reads, arraysize(reads), writes, arraysize(writes));
475 475
476 scoped_ptr<HttpStream> unused_stream(NewTestStream("unused.html")); 476 scoped_ptr<HttpStream> unused_stream(NewTestStream("unused.html"));
477 unused_stream->Close(false); 477 unused_stream->Close(false);
478 478
479 scoped_ptr<HttpStream> later_stream(NewTestStream("ok.html")); 479 scoped_ptr<HttpStream> later_stream(NewTestStream("ok.html"));
480 TestSyncRequest(later_stream, "ok.html"); 480 TestSyncRequest(later_stream, "ok.html");
481 } 481 }
482 482
483 TEST_F(HttpPipelinedConnectionImplTest, UnsentStreamAllowsLaterUse) { 483 TEST_F(HttpPipelinedConnectionImplTest, UnsentStreamAllowsLaterUse) {
484 MockWrite writes[] = { 484 MockWrite writes[] = {
485 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 485 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
486 MockWrite(false, 4, "GET /ko.html HTTP/1.1\r\n\r\n"), 486 MockWrite(SYNCHRONOUS, 4, "GET /ko.html HTTP/1.1\r\n\r\n"),
487 }; 487 };
488 MockRead reads[] = { 488 MockRead reads[] = {
489 MockRead(true, 1, "HTTP/1.1 200 OK\r\n"), 489 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"),
490 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 490 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"),
491 MockRead(true, 3, "ok.html"), 491 MockRead(ASYNC, 3, "ok.html"),
492 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 492 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
493 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 493 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"),
494 MockRead(false, 7, "ko.html"), 494 MockRead(SYNCHRONOUS, 7, "ko.html"),
495 }; 495 };
496 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 496 Initialize(reads, arraysize(reads), writes, arraysize(writes));
497 497
498 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 498 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
499 499
500 HttpRequestHeaders headers; 500 HttpRequestHeaders headers;
501 HttpResponseInfo response; 501 HttpResponseInfo response;
502 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response, 502 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
503 callback_.callback())); 503 callback_.callback()));
504 504
(...skipping 16 matching lines...) Expand all
521 521
522 stream->Close(false); 522 stream->Close(false);
523 523
524 data_->StopAfter(8); 524 data_->StopAfter(8);
525 scoped_ptr<HttpStream> later_stream(NewTestStream("ko.html")); 525 scoped_ptr<HttpStream> later_stream(NewTestStream("ko.html"));
526 TestSyncRequest(later_stream, "ko.html"); 526 TestSyncRequest(later_stream, "ko.html");
527 } 527 }
528 528
529 TEST_F(HttpPipelinedConnectionImplTest, FailedSend) { 529 TEST_F(HttpPipelinedConnectionImplTest, FailedSend) {
530 MockWrite writes[] = { 530 MockWrite writes[] = {
531 MockWrite(true, ERR_FAILED), 531 MockWrite(ASYNC, ERR_FAILED),
532 }; 532 };
533 Initialize(NULL, 0, writes, arraysize(writes)); 533 Initialize(NULL, 0, writes, arraysize(writes));
534 534
535 scoped_ptr<HttpStream> failed_stream(NewTestStream("ok.html")); 535 scoped_ptr<HttpStream> failed_stream(NewTestStream("ok.html"));
536 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 536 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
537 scoped_ptr<HttpStream> closed_stream(NewTestStream("closed.html")); 537 scoped_ptr<HttpStream> closed_stream(NewTestStream("closed.html"));
538 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); 538 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
539 539
540 HttpRequestHeaders headers; 540 HttpRequestHeaders headers;
541 HttpResponseInfo response; 541 HttpResponseInfo response;
(...skipping 17 matching lines...) Expand all
559 rejected_stream->SendRequest(headers, NULL, &response, 559 rejected_stream->SendRequest(headers, NULL, &response,
560 callback_.callback())); 560 callback_.callback()));
561 561
562 failed_stream->Close(true); 562 failed_stream->Close(true);
563 evicted_stream->Close(true); 563 evicted_stream->Close(true);
564 rejected_stream->Close(true); 564 rejected_stream->Close(true);
565 } 565 }
566 566
567 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) { 567 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
568 MockWrite writes[] = { 568 MockWrite writes[] = {
569 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 569 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
570 MockWrite(false, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"), 570 MockWrite(SYNCHRONOUS, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"),
571 MockWrite(false, 2, "GET /read_rejected.html HTTP/1.1\r\n\r\n"), 571 MockWrite(SYNCHRONOUS, 2, "GET /read_rejected.html HTTP/1.1\r\n\r\n"),
572 MockWrite(true, ERR_SOCKET_NOT_CONNECTED, 5), 572 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5),
573 }; 573 };
574 MockRead reads[] = { 574 MockRead reads[] = {
575 MockRead(false, 3, "HTTP/1.1 200 OK\r\n\r\n"), 575 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n\r\n"),
576 MockRead(false, 4, "ok.html"), 576 MockRead(SYNCHRONOUS, 4, "ok.html"),
577 }; 577 };
578 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 578 Initialize(reads, arraysize(reads), writes, arraysize(writes));
579 579
580 scoped_ptr<HttpStream> closed_stream(NewTestStream("ok.html")); 580 scoped_ptr<HttpStream> closed_stream(NewTestStream("ok.html"));
581 scoped_ptr<HttpStream> read_evicted_stream( 581 scoped_ptr<HttpStream> read_evicted_stream(
582 NewTestStream("read_evicted.html")); 582 NewTestStream("read_evicted.html"));
583 scoped_ptr<HttpStream> read_rejected_stream( 583 scoped_ptr<HttpStream> read_rejected_stream(
584 NewTestStream("read_rejected.html")); 584 NewTestStream("read_rejected.html"));
585 scoped_ptr<HttpStream> send_closed_stream( 585 scoped_ptr<HttpStream> send_closed_stream(
586 NewTestStream("send_closed.html")); 586 NewTestStream("send_closed.html"));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 send_evicted_stream->Close(true); 630 send_evicted_stream->Close(true);
631 631
632 EXPECT_EQ(ERR_PIPELINE_EVICTION, 632 EXPECT_EQ(ERR_PIPELINE_EVICTION,
633 send_rejected_stream->SendRequest(headers, NULL, &response, 633 send_rejected_stream->SendRequest(headers, NULL, &response,
634 callback_.callback())); 634 callback_.callback()));
635 send_rejected_stream->Close(true); 635 send_rejected_stream->Close(true);
636 } 636 }
637 637
638 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) { 638 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) {
639 MockWrite writes[] = { 639 MockWrite writes[] = {
640 MockWrite(true, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), 640 MockWrite(ASYNC, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"),
641 }; 641 };
642 Initialize(NULL, 0, writes, arraysize(writes)); 642 Initialize(NULL, 0, writes, arraysize(writes));
643 643
644 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); 644 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html"));
645 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 645 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
646 646
647 HttpRequestHeaders headers; 647 HttpRequestHeaders headers;
648 HttpResponseInfo response; 648 HttpResponseInfo response;
649 TestCompletionCallback aborted_callback; 649 TestCompletionCallback aborted_callback;
650 EXPECT_EQ(ERR_IO_PENDING, 650 EXPECT_EQ(ERR_IO_PENDING,
651 aborted_stream->SendRequest(headers, NULL, &response, 651 aborted_stream->SendRequest(headers, NULL, &response,
652 aborted_callback.callback())); 652 aborted_callback.callback()));
653 TestCompletionCallback evicted_callback; 653 TestCompletionCallback evicted_callback;
654 EXPECT_EQ(ERR_IO_PENDING, 654 EXPECT_EQ(ERR_IO_PENDING,
655 evicted_stream->SendRequest(headers, NULL, &response, 655 evicted_stream->SendRequest(headers, NULL, &response,
656 evicted_callback.callback())); 656 evicted_callback.callback()));
657 657
658 aborted_stream->Close(true); 658 aborted_stream->Close(true);
659 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 659 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
660 evicted_stream->Close(true); 660 evicted_stream->Close(true);
661 EXPECT_FALSE(aborted_callback.have_result()); 661 EXPECT_FALSE(aborted_callback.have_result());
662 } 662 }
663 663
664 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) { 664 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) {
665 MockWrite writes[] = { 665 MockWrite writes[] = {
666 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 666 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
667 MockWrite(true, 1, "GET /aborts.html HTTP/1.1\r\n\r\n"), 667 MockWrite(ASYNC, 1, "GET /aborts.html HTTP/1.1\r\n\r\n"),
668 }; 668 };
669 Initialize(NULL, 0, writes, arraysize(writes)); 669 Initialize(NULL, 0, writes, arraysize(writes));
670 670
671 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 671 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
672 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); 672 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html"));
673 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 673 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
674 674
675 HttpRequestHeaders headers; 675 HttpRequestHeaders headers;
676 HttpResponseInfo response; 676 HttpResponseInfo response;
677 TestCompletionCallback ok_callback; 677 TestCompletionCallback ok_callback;
(...skipping 14 matching lines...) Expand all
692 MessageLoop::current()->RunAllPending(); 692 MessageLoop::current()->RunAllPending();
693 aborted_stream->Close(true); 693 aborted_stream->Close(true);
694 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 694 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
695 evicted_stream->Close(true); 695 evicted_stream->Close(true);
696 EXPECT_FALSE(aborted_callback.have_result()); 696 EXPECT_FALSE(aborted_callback.have_result());
697 ok_stream->Close(true); 697 ok_stream->Close(true);
698 } 698 }
699 699
700 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) { 700 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) {
701 MockWrite writes[] = { 701 MockWrite writes[] = {
702 MockWrite(false, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), 702 MockWrite(SYNCHRONOUS, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"),
703 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 703 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
704 }; 704 };
705 MockRead reads[] = { 705 MockRead reads[] = {
706 MockRead(true, ERR_FAILED, 2), 706 MockRead(ASYNC, ERR_FAILED, 2),
707 }; 707 };
708 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 708 Initialize(reads, arraysize(reads), writes, arraysize(writes));
709 709
710 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); 710 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html"));
711 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 711 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
712 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); 712 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
713 713
714 HttpRequestHeaders headers; 714 HttpRequestHeaders headers;
715 HttpResponseInfo response; 715 HttpResponseInfo response;
716 EXPECT_EQ(OK, aborted_stream->SendRequest(headers, NULL, &response, 716 EXPECT_EQ(OK, aborted_stream->SendRequest(headers, NULL, &response,
(...skipping 12 matching lines...) Expand all
729 evicted_stream->Close(true); 729 evicted_stream->Close(true);
730 730
731 EXPECT_EQ(ERR_PIPELINE_EVICTION, 731 EXPECT_EQ(ERR_PIPELINE_EVICTION,
732 rejected_stream->SendRequest(headers, NULL, &response, 732 rejected_stream->SendRequest(headers, NULL, &response,
733 callback_.callback())); 733 callback_.callback()));
734 rejected_stream->Close(true); 734 rejected_stream->Close(true);
735 } 735 }
736 736
737 TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) { 737 TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) {
738 MockWrite writes[] = { 738 MockWrite writes[] = {
739 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 739 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
740 MockWrite(false, 1, "GET /abandoned.html HTTP/1.1\r\n\r\n"), 740 MockWrite(SYNCHRONOUS, 1, "GET /abandoned.html HTTP/1.1\r\n\r\n"),
741 MockWrite(false, 2, "GET /evicted.html HTTP/1.1\r\n\r\n"), 741 MockWrite(SYNCHRONOUS, 2, "GET /evicted.html HTTP/1.1\r\n\r\n"),
742 }; 742 };
743 MockRead reads[] = { 743 MockRead reads[] = {
744 MockRead(false, 3, "HTTP/1.1 200 OK\r\n"), 744 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"),
745 MockRead(false, 4, "Content-Length: 7\r\n\r\n"), 745 MockRead(SYNCHRONOUS, 4, "Content-Length: 7\r\n\r\n"),
746 MockRead(false, 5, "ok.html"), 746 MockRead(SYNCHRONOUS, 5, "ok.html"),
747 }; 747 };
748 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 748 Initialize(reads, arraysize(reads), writes, arraysize(writes));
749 749
750 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 750 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
751 scoped_ptr<HttpStream> abandoned_stream(NewTestStream("abandoned.html")); 751 scoped_ptr<HttpStream> abandoned_stream(NewTestStream("abandoned.html"));
752 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 752 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
753 753
754 HttpRequestHeaders headers; 754 HttpRequestHeaders headers;
755 HttpResponseInfo response; 755 HttpResponseInfo response;
756 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, 756 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
(...skipping 16 matching lines...) Expand all
773 ExpectResponse("ok.html", ok_stream, false); 773 ExpectResponse("ok.html", ok_stream, false);
774 ok_stream->Close(false); 774 ok_stream->Close(false);
775 775
776 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 776 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
777 evicted_stream->Close(true); 777 evicted_stream->Close(true);
778 EXPECT_FALSE(evicted_stream->IsConnectionReusable()); 778 EXPECT_FALSE(evicted_stream->IsConnectionReusable());
779 } 779 }
780 780
781 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) { 781 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) {
782 MockWrite writes[] = { 782 MockWrite writes[] = {
783 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 783 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
784 MockWrite(false, 1, "GET /rejected.html HTTP/1.1\r\n\r\n"), 784 MockWrite(SYNCHRONOUS, 1, "GET /rejected.html HTTP/1.1\r\n\r\n"),
785 MockWrite(true, ERR_SOCKET_NOT_CONNECTED, 5), 785 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5),
786 MockWrite(false, ERR_SOCKET_NOT_CONNECTED, 7), 786 MockWrite(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 7),
787 }; 787 };
788 MockRead reads[] = { 788 MockRead reads[] = {
789 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 789 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
790 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 790 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"),
791 MockRead(false, 4, "ok.html"), 791 MockRead(SYNCHRONOUS, 4, "ok.html"),
792 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 6), 792 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 6),
793 }; 793 };
794 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 794 Initialize(reads, arraysize(reads), writes, arraysize(writes));
795 795
796 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 796 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
797 scoped_ptr<HttpStream> rejected_read_stream(NewTestStream("rejected.html")); 797 scoped_ptr<HttpStream> rejected_read_stream(NewTestStream("rejected.html"));
798 scoped_ptr<HttpStream> evicted_send_stream(NewTestStream("evicted.html")); 798 scoped_ptr<HttpStream> evicted_send_stream(NewTestStream("evicted.html"));
799 scoped_ptr<HttpStream> rejected_send_stream(NewTestStream("rejected.html")); 799 scoped_ptr<HttpStream> rejected_send_stream(NewTestStream("rejected.html"));
800 800
801 HttpRequestHeaders headers; 801 HttpRequestHeaders headers;
802 HttpResponseInfo response; 802 HttpResponseInfo response;
(...skipping 18 matching lines...) Expand all
821 EXPECT_EQ(ERR_PIPELINE_EVICTION, 821 EXPECT_EQ(ERR_PIPELINE_EVICTION,
822 rejected_send_stream->SendRequest(headers, NULL, &response, 822 rejected_send_stream->SendRequest(headers, NULL, &response,
823 callback_.callback())); 823 callback_.callback()));
824 824
825 rejected_read_stream->Close(true); 825 rejected_read_stream->Close(true);
826 rejected_send_stream->Close(true); 826 rejected_send_stream->Close(true);
827 } 827 }
828 828
829 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) { 829 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) {
830 MockWrite writes[] = { 830 MockWrite writes[] = {
831 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 831 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
832 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 832 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
833 }; 833 };
834 MockRead reads[] = { 834 MockRead reads[] = {
835 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 835 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
836 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 836 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"),
837 MockRead(false, 4, "ok.html"), 837 MockRead(SYNCHRONOUS, 4, "ok.html"),
838 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5), 838 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5),
839 }; 839 };
840 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 840 Initialize(reads, arraysize(reads), writes, arraysize(writes));
841 841
842 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 842 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
843 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 843 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
844 844
845 HttpRequestHeaders headers; 845 HttpRequestHeaders headers;
846 HttpResponseInfo response; 846 HttpResponseInfo response;
847 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, 847 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
848 callback_.callback())); 848 callback_.callback()));
849 EXPECT_EQ(OK, evicted_stream->SendRequest( 849 EXPECT_EQ(OK, evicted_stream->SendRequest(
850 headers, NULL, &response, callback_.callback())); 850 headers, NULL, &response, callback_.callback()));
851 851
852 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); 852 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
853 ExpectResponse("ok.html", ok_stream, false); 853 ExpectResponse("ok.html", ok_stream, false);
854 854
855 TestCompletionCallback evicted_callback; 855 TestCompletionCallback evicted_callback;
856 EXPECT_EQ(ERR_IO_PENDING, 856 EXPECT_EQ(ERR_IO_PENDING,
857 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); 857 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
858 858
859 ok_stream->Close(false); 859 ok_stream->Close(false);
860 860
861 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 861 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
862 evicted_stream->Close(false); 862 evicted_stream->Close(false);
863 } 863 }
864 864
865 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) { 865 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) {
866 MockWrite writes[] = { 866 MockWrite writes[] = {
867 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 867 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
868 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 868 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
869 }; 869 };
870 MockRead reads[] = { 870 MockRead reads[] = {
871 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 871 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
872 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 872 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"),
873 MockRead(false, 4, "ok.html"), 873 MockRead(SYNCHRONOUS, 4, "ok.html"),
874 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5), 874 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5),
875 }; 875 };
876 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 876 Initialize(reads, arraysize(reads), writes, arraysize(writes));
877 877
878 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 878 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
879 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 879 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
880 880
881 HttpRequestHeaders headers; 881 HttpRequestHeaders headers;
882 HttpResponseInfo response; 882 HttpResponseInfo response;
883 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, 883 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
884 callback_.callback())); 884 callback_.callback()));
885 EXPECT_EQ(OK, evicted_stream->SendRequest( 885 EXPECT_EQ(OK, evicted_stream->SendRequest(
886 headers, NULL, &response, callback_.callback())); 886 headers, NULL, &response, callback_.callback()));
887 887
888 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); 888 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
889 ExpectResponse("ok.html", ok_stream, false); 889 ExpectResponse("ok.html", ok_stream, false);
890 890
891 TestCompletionCallback evicted_callback; 891 TestCompletionCallback evicted_callback;
892 EXPECT_EQ(ERR_IO_PENDING, 892 EXPECT_EQ(ERR_IO_PENDING,
893 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); 893 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
894 894
895 ok_stream->Close(false); 895 ok_stream->Close(false);
896 evicted_stream->Close(false); 896 evicted_stream->Close(false);
897 } 897 }
898 898
899 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) { 899 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) {
900 MockWrite writes[] = { 900 MockWrite writes[] = {
901 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 901 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
902 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 902 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
903 }; 903 };
904 MockRead reads[] = { 904 MockRead reads[] = {
905 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 905 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
906 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 906 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"),
907 MockRead(false, 4, "ok.html"), 907 MockRead(SYNCHRONOUS, 4, "ok.html"),
908 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5), 908 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5),
909 }; 909 };
910 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 910 Initialize(reads, arraysize(reads), writes, arraysize(writes));
911 911
912 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 912 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
913 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 913 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
914 914
915 HttpRequestHeaders headers; 915 HttpRequestHeaders headers;
916 HttpResponseInfo response; 916 HttpResponseInfo response;
917 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, 917 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
918 callback_.callback())); 918 callback_.callback()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 void OnIOComplete(int result) { 951 void OnIOComplete(int result) {
952 delete stream_; 952 delete stream_;
953 } 953 }
954 954
955 HttpStream* stream_; 955 HttpStream* stream_;
956 CompletionCallback callback_; 956 CompletionCallback callback_;
957 }; 957 };
958 958
959 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) { 959 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) {
960 MockWrite writes[] = { 960 MockWrite writes[] = {
961 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 961 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
962 }; 962 };
963 Initialize(NULL, 0, writes, arraysize(writes)); 963 Initialize(NULL, 0, writes, arraysize(writes));
964 964
965 HttpStream* stream(NewTestStream("ok.html")); 965 HttpStream* stream(NewTestStream("ok.html"));
966 966
967 StreamDeleter deleter(stream); 967 StreamDeleter deleter(stream);
968 HttpRequestHeaders headers; 968 HttpRequestHeaders headers;
969 HttpResponseInfo response; 969 HttpResponseInfo response;
970 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response, 970 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
971 deleter.callback())); 971 deleter.callback()));
972 data_->RunFor(1); 972 data_->RunFor(1);
973 } 973 }
974 974
975 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringReadCallback) { 975 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringReadCallback) {
976 MockWrite writes[] = { 976 MockWrite writes[] = {
977 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 977 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
978 }; 978 };
979 MockRead reads[] = { 979 MockRead reads[] = {
980 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 980 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
981 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 981 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"),
982 }; 982 };
983 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 983 Initialize(reads, arraysize(reads), writes, arraysize(writes));
984 984
985 HttpStream* stream(NewTestStream("ok.html")); 985 HttpStream* stream(NewTestStream("ok.html"));
986 986
987 HttpRequestHeaders headers; 987 HttpRequestHeaders headers;
988 HttpResponseInfo response; 988 HttpResponseInfo response;
989 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, 989 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
990 callback_.callback())); 990 callback_.callback()));
991 991
992 StreamDeleter deleter(stream); 992 StreamDeleter deleter(stream);
993 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback())); 993 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback()));
994 data_->RunFor(1); 994 data_->RunFor(1);
995 } 995 }
996 996
997 TEST_F(HttpPipelinedConnectionImplTest, 997 TEST_F(HttpPipelinedConnectionImplTest,
998 CloseCalledDuringReadCallbackWithPendingRead) { 998 CloseCalledDuringReadCallbackWithPendingRead) {
999 MockWrite writes[] = { 999 MockWrite writes[] = {
1000 MockWrite(false, 0, "GET /failed.html HTTP/1.1\r\n\r\n"), 1000 MockWrite(SYNCHRONOUS, 0, "GET /failed.html HTTP/1.1\r\n\r\n"),
1001 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 1001 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
1002 }; 1002 };
1003 MockRead reads[] = { 1003 MockRead reads[] = {
1004 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 1004 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
1005 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 1005 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"),
1006 }; 1006 };
1007 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1007 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1008 1008
1009 HttpStream* failed_stream(NewTestStream("failed.html")); 1009 HttpStream* failed_stream(NewTestStream("failed.html"));
1010 HttpStream* evicted_stream(NewTestStream("evicted.html")); 1010 HttpStream* evicted_stream(NewTestStream("evicted.html"));
1011 1011
1012 HttpRequestHeaders headers; 1012 HttpRequestHeaders headers;
1013 HttpResponseInfo response; 1013 HttpResponseInfo response;
1014 EXPECT_EQ(OK, failed_stream->SendRequest(headers, NULL, &response, 1014 EXPECT_EQ(OK, failed_stream->SendRequest(headers, NULL, &response,
1015 callback_.callback())); 1015 callback_.callback()));
1016 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response, 1016 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
1017 callback_.callback())); 1017 callback_.callback()));
1018 1018
1019 StreamDeleter failed_deleter(failed_stream); 1019 StreamDeleter failed_deleter(failed_stream);
1020 EXPECT_EQ(ERR_IO_PENDING, 1020 EXPECT_EQ(ERR_IO_PENDING,
1021 failed_stream->ReadResponseHeaders(failed_deleter.callback())); 1021 failed_stream->ReadResponseHeaders(failed_deleter.callback()));
1022 StreamDeleter evicted_deleter(evicted_stream); 1022 StreamDeleter evicted_deleter(evicted_stream);
1023 EXPECT_EQ(ERR_IO_PENDING, 1023 EXPECT_EQ(ERR_IO_PENDING,
1024 evicted_stream->ReadResponseHeaders(evicted_deleter.callback())); 1024 evicted_stream->ReadResponseHeaders(evicted_deleter.callback()));
1025 data_->RunFor(1); 1025 data_->RunFor(1);
1026 } 1026 }
1027 1027
1028 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) { 1028 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) {
1029 MockWrite writes[] = { 1029 MockWrite writes[] = {
1030 MockWrite(false, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"), 1030 MockWrite(SYNCHRONOUS, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"),
1031 MockWrite(false, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"), 1031 MockWrite(SYNCHRONOUS, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"),
1032 }; 1032 };
1033 MockRead reads[] = { 1033 MockRead reads[] = {
1034 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 1034 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"),
1035 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 1035 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"),
1036 }; 1036 };
1037 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1037 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1038 1038
1039 scoped_ptr<HttpStream> deleter_stream(NewTestStream("deleter.html")); 1039 scoped_ptr<HttpStream> deleter_stream(NewTestStream("deleter.html"));
1040 HttpStream* deleted_stream(NewTestStream("deleted.html")); 1040 HttpStream* deleted_stream(NewTestStream("deleted.html"));
1041 1041
1042 HttpRequestHeaders headers; 1042 HttpRequestHeaders headers;
1043 HttpResponseInfo response; 1043 HttpResponseInfo response;
1044 EXPECT_EQ(OK, deleter_stream->SendRequest(headers, NULL, &response, 1044 EXPECT_EQ(OK, deleter_stream->SendRequest(headers, NULL, &response,
1045 callback_.callback())); 1045 callback_.callback()));
1046 EXPECT_EQ(OK, deleted_stream->SendRequest(headers, NULL, &response, 1046 EXPECT_EQ(OK, deleted_stream->SendRequest(headers, NULL, &response,
1047 callback_.callback())); 1047 callback_.callback()));
1048 1048
1049 StreamDeleter deleter(deleted_stream); 1049 StreamDeleter deleter(deleted_stream);
1050 EXPECT_EQ(ERR_IO_PENDING, 1050 EXPECT_EQ(ERR_IO_PENDING,
1051 deleter_stream->ReadResponseHeaders(deleter.callback())); 1051 deleter_stream->ReadResponseHeaders(deleter.callback()));
1052 EXPECT_EQ(ERR_IO_PENDING, 1052 EXPECT_EQ(ERR_IO_PENDING,
1053 deleted_stream->ReadResponseHeaders(callback_.callback())); 1053 deleted_stream->ReadResponseHeaders(callback_.callback()));
1054 data_->RunFor(1); 1054 data_->RunFor(1);
1055 } 1055 }
1056 1056
1057 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) { 1057 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) {
1058 MockWrite writes[] = { 1058 MockWrite writes[] = {
1059 MockWrite(true, 0, "GET /close.html HTTP/1.1\r\n\r\n"), 1059 MockWrite(ASYNC, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1060 MockWrite(true, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"), 1060 MockWrite(ASYNC, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1061 }; 1061 };
1062 Initialize(NULL, 0, writes, arraysize(writes)); 1062 Initialize(NULL, 0, writes, arraysize(writes));
1063 1063
1064 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); 1064 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1065 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); 1065 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1066 1066
1067 scoped_ptr<TestCompletionCallback> close_callback( 1067 scoped_ptr<TestCompletionCallback> close_callback(
1068 new TestCompletionCallback); 1068 new TestCompletionCallback);
1069 HttpRequestHeaders headers; 1069 HttpRequestHeaders headers;
1070 HttpResponseInfo response; 1070 HttpResponseInfo response;
1071 EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest( 1071 EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest(
1072 headers, NULL, &response, close_callback->callback())); 1072 headers, NULL, &response, close_callback->callback()));
1073 1073
1074 data_->RunFor(1); 1074 data_->RunFor(1);
1075 EXPECT_FALSE(close_callback->have_result()); 1075 EXPECT_FALSE(close_callback->have_result());
1076 1076
1077 close_stream->Close(false); 1077 close_stream->Close(false);
1078 close_stream.reset(); 1078 close_stream.reset();
1079 close_callback.reset(); 1079 close_callback.reset();
1080 1080
1081 MessageLoop::current()->RunAllPending(); 1081 MessageLoop::current()->RunAllPending();
1082 } 1082 }
1083 1083
1084 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) { 1084 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
1085 MockWrite writes[] = { 1085 MockWrite writes[] = {
1086 MockWrite(false, 0, "GET /close.html HTTP/1.1\r\n\r\n"), 1086 MockWrite(SYNCHRONOUS, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1087 MockWrite(false, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"), 1087 MockWrite(SYNCHRONOUS, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1088 }; 1088 };
1089 MockRead reads[] = { 1089 MockRead reads[] = {
1090 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 1090 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
1091 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 1091 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"),
1092 }; 1092 };
1093 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1093 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1094 1094
1095 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); 1095 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1096 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); 1096 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1097 1097
1098 HttpRequestHeaders headers; 1098 HttpRequestHeaders headers;
1099 HttpResponseInfo response; 1099 HttpResponseInfo response;
1100 EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response, 1100 EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response,
1101 callback_.callback())); 1101 callback_.callback()));
1102 1102
1103 scoped_ptr<TestCompletionCallback> close_callback( 1103 scoped_ptr<TestCompletionCallback> close_callback(
1104 new TestCompletionCallback); 1104 new TestCompletionCallback);
1105 EXPECT_EQ(ERR_IO_PENDING, 1105 EXPECT_EQ(ERR_IO_PENDING,
1106 close_stream->ReadResponseHeaders(close_callback->callback())); 1106 close_stream->ReadResponseHeaders(close_callback->callback()));
1107 1107
1108 data_->RunFor(1); 1108 data_->RunFor(1);
1109 EXPECT_FALSE(close_callback->have_result()); 1109 EXPECT_FALSE(close_callback->have_result());
1110 1110
1111 close_stream->Close(false); 1111 close_stream->Close(false);
1112 close_stream.reset(); 1112 close_stream.reset();
1113 close_callback.reset(); 1113 close_callback.reset();
1114 1114
1115 MessageLoop::current()->RunAllPending(); 1115 MessageLoop::current()->RunAllPending();
1116 } 1116 }
1117 1117
1118 TEST_F(HttpPipelinedConnectionImplTest, NoGapBetweenCloseAndEviction) { 1118 TEST_F(HttpPipelinedConnectionImplTest, NoGapBetweenCloseAndEviction) {
1119 MockWrite writes[] = { 1119 MockWrite writes[] = {
1120 MockWrite(false, 0, "GET /close.html HTTP/1.1\r\n\r\n"), 1120 MockWrite(SYNCHRONOUS, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1121 MockWrite(false, 2, "GET /dummy.html HTTP/1.1\r\n\r\n"), 1121 MockWrite(SYNCHRONOUS, 2, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1122 }; 1122 };
1123 MockRead reads[] = { 1123 MockRead reads[] = {
1124 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 1124 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
1125 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 1125 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"),
1126 }; 1126 };
1127 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1127 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1128 1128
1129 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); 1129 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1130 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); 1130 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1131 1131
1132 HttpRequestHeaders headers; 1132 HttpRequestHeaders headers;
1133 HttpResponseInfo response; 1133 HttpResponseInfo response;
1134 EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response, 1134 EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response,
1135 callback_.callback())); 1135 callback_.callback()));
(...skipping 14 matching lines...) Expand all
1150 1150
1151 EXPECT_TRUE(dummy_callback.have_result()); 1151 EXPECT_TRUE(dummy_callback.have_result());
1152 EXPECT_EQ(ERR_PIPELINE_EVICTION, dummy_callback.WaitForResult()); 1152 EXPECT_EQ(ERR_PIPELINE_EVICTION, dummy_callback.WaitForResult());
1153 dummy_stream->Close(true); 1153 dummy_stream->Close(true);
1154 dummy_stream.reset(); 1154 dummy_stream.reset();
1155 pipeline_.reset(); 1155 pipeline_.reset();
1156 } 1156 }
1157 1157
1158 TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) { 1158 TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) {
1159 MockWrite writes[] = { 1159 MockWrite writes[] = {
1160 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1160 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1161 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1161 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1162 }; 1162 };
1163 MockRead reads[] = { 1163 MockRead reads[] = {
1164 MockRead(false, 2, 1164 MockRead(SYNCHRONOUS, 2,
1165 "HTTP/1.1 302 OK\r\n" 1165 "HTTP/1.1 302 OK\r\n"
1166 "Content-Length: 8\r\n\r\n" 1166 "Content-Length: 8\r\n\r\n"
1167 "redirect"), 1167 "redirect"),
1168 MockRead(false, 3, 1168 MockRead(SYNCHRONOUS, 3,
1169 "HTTP/1.1 200 OK\r\n" 1169 "HTTP/1.1 200 OK\r\n"
1170 "Content-Length: 7\r\n\r\n" 1170 "Content-Length: 7\r\n\r\n"
1171 "ok.html"), 1171 "ok.html"),
1172 }; 1172 };
1173 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1173 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1174 1174
1175 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1175 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1176 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1176 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1177 1177
1178 HttpRequestHeaders headers1; 1178 HttpRequestHeaders headers1;
1179 HttpResponseInfo response1; 1179 HttpResponseInfo response1;
1180 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 1180 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1181 callback_.callback())); 1181 callback_.callback()));
1182 HttpRequestHeaders headers2; 1182 HttpRequestHeaders headers2;
1183 HttpResponseInfo response2; 1183 HttpResponseInfo response2;
1184 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, 1184 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1185 callback_.callback())); 1185 callback_.callback()));
1186 1186
1187 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); 1187 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1188 stream1.release()->Drain(NULL); 1188 stream1.release()->Drain(NULL);
1189 1189
1190 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); 1190 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
1191 ExpectResponse("ok.html", stream2, false); 1191 ExpectResponse("ok.html", stream2, false);
1192 stream2->Close(false); 1192 stream2->Close(false);
1193 } 1193 }
1194 1194
1195 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) { 1195 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) {
1196 MockWrite writes[] = { 1196 MockWrite writes[] = {
1197 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1197 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1198 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1198 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1199 }; 1199 };
1200 MockRead reads[] = { 1200 MockRead reads[] = {
1201 MockRead(false, 2, 1201 MockRead(SYNCHRONOUS, 2,
1202 "HTTP/1.1 302 OK\r\n\r\n" 1202 "HTTP/1.1 302 OK\r\n\r\n"
1203 "redirect"), 1203 "redirect"),
1204 }; 1204 };
1205 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1205 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1206 1206
1207 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1207 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1208 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1208 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1209 1209
1210 HttpRequestHeaders headers1; 1210 HttpRequestHeaders headers1;
1211 HttpResponseInfo response1; 1211 HttpResponseInfo response1;
1212 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 1212 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1213 callback_.callback())); 1213 callback_.callback()));
1214 HttpRequestHeaders headers2; 1214 HttpRequestHeaders headers2;
1215 HttpResponseInfo response2; 1215 HttpResponseInfo response2;
1216 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, 1216 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1217 callback_.callback())); 1217 callback_.callback()));
1218 1218
1219 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); 1219 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1220 stream1.release()->Drain(NULL); 1220 stream1.release()->Drain(NULL);
1221 1221
1222 EXPECT_EQ(ERR_PIPELINE_EVICTION, 1222 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1223 stream2->ReadResponseHeaders(callback_.callback())); 1223 stream2->ReadResponseHeaders(callback_.callback()));
1224 stream2->Close(false); 1224 stream2->Close(false);
1225 } 1225 }
1226 1226
1227 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) { 1227 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) {
1228 MockWrite writes[] = { 1228 MockWrite writes[] = {
1229 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1229 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1230 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1230 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1231 }; 1231 };
1232 MockRead reads[] = { 1232 MockRead reads[] = {
1233 MockRead(false, 2, 1233 MockRead(SYNCHRONOUS, 2,
1234 "HTTP/1.1 302 OK\r\n" 1234 "HTTP/1.1 302 OK\r\n"
1235 "Content-Length: 8\r\n\r\n"), 1235 "Content-Length: 8\r\n\r\n"),
1236 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 3), 1236 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 3),
1237 }; 1237 };
1238 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1238 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1239 1239
1240 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1240 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1241 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1241 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1242 1242
1243 HttpRequestHeaders headers1; 1243 HttpRequestHeaders headers1;
1244 HttpResponseInfo response1; 1244 HttpResponseInfo response1;
1245 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 1245 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1246 callback_.callback())); 1246 callback_.callback()));
1247 HttpRequestHeaders headers2; 1247 HttpRequestHeaders headers2;
1248 HttpResponseInfo response2; 1248 HttpResponseInfo response2;
1249 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, 1249 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1250 callback_.callback())); 1250 callback_.callback()));
1251 1251
1252 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); 1252 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1253 stream1.release()->Drain(NULL); 1253 stream1.release()->Drain(NULL);
1254 1254
1255 EXPECT_EQ(ERR_PIPELINE_EVICTION, 1255 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1256 stream2->ReadResponseHeaders(callback_.callback())); 1256 stream2->ReadResponseHeaders(callback_.callback()));
1257 stream2->Close(false); 1257 stream2->Close(false);
1258 } 1258 }
1259 1259
1260 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) { 1260 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) {
1261 MockWrite writes[] = { 1261 MockWrite writes[] = {
1262 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1262 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1263 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1263 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1264 }; 1264 };
1265 MockRead reads[] = { 1265 MockRead reads[] = {
1266 MockRead(false, 2, 1266 MockRead(SYNCHRONOUS, 2,
1267 "HTTP/1.1 302 OK\r\n" 1267 "HTTP/1.1 302 OK\r\n"
1268 "Transfer-Encoding: chunked\r\n\r\n"), 1268 "Transfer-Encoding: chunked\r\n\r\n"),
1269 MockRead(false, 3, 1269 MockRead(SYNCHRONOUS, 3,
1270 "jibberish"), 1270 "jibberish"),
1271 }; 1271 };
1272 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1272 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1273 1273
1274 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1274 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1275 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1275 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1276 1276
1277 HttpRequestHeaders headers1; 1277 HttpRequestHeaders headers1;
1278 HttpResponseInfo response1; 1278 HttpResponseInfo response1;
1279 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, 1279 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1280 callback_.callback())); 1280 callback_.callback()));
1281 HttpRequestHeaders headers2; 1281 HttpRequestHeaders headers2;
1282 HttpResponseInfo response2; 1282 HttpResponseInfo response2;
1283 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, 1283 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1284 callback_.callback())); 1284 callback_.callback()));
1285 1285
1286 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); 1286 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1287 stream1.release()->Drain(NULL); 1287 stream1.release()->Drain(NULL);
1288 1288
1289 EXPECT_EQ(ERR_PIPELINE_EVICTION, 1289 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1290 stream2->ReadResponseHeaders(callback_.callback())); 1290 stream2->ReadResponseHeaders(callback_.callback()));
1291 stream2->Close(false); 1291 stream2->Close(false);
1292 } 1292 }
1293 1293
1294 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) { 1294 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
1295 MockWrite writes[] = { 1295 MockWrite writes[] = {
1296 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1296 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1297 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 1297 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
1298 MockWrite(false, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"), 1298 MockWrite(SYNCHRONOUS, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"),
1299 }; 1299 };
1300 MockRead reads[] = { 1300 MockRead reads[] = {
1301 MockRead(true, 3, "HTTP/1.1 200 OK\r\n\r\n"), 1301 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"),
1302 MockRead(false, 4, "ok.html"), 1302 MockRead(SYNCHRONOUS, 4, "ok.html"),
1303 MockRead(false, OK, 5), 1303 MockRead(SYNCHRONOUS, OK, 5),
1304 }; 1304 };
1305 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1305 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1306 1306
1307 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 1307 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
1308 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 1308 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
1309 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); 1309 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
1310 1310
1311 HttpRequestHeaders headers; 1311 HttpRequestHeaders headers;
1312 HttpResponseInfo response; 1312 HttpResponseInfo response;
1313 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, 1313 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
(...skipping 20 matching lines...) Expand all
1334 1334
1335 EXPECT_EQ(ERR_PIPELINE_EVICTION, 1335 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1336 rejected_stream->ReadResponseHeaders(callback_.callback())); 1336 rejected_stream->ReadResponseHeaders(callback_.callback()));
1337 rejected_stream->Close(true); 1337 rejected_stream->Close(true);
1338 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 1338 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
1339 evicted_stream->Close(true); 1339 evicted_stream->Close(true);
1340 } 1340 }
1341 1341
1342 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) { 1342 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) {
1343 MockWrite writes[] = { 1343 MockWrite writes[] = {
1344 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1344 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1345 }; 1345 };
1346 MockRead reads[] = { 1346 MockRead reads[] = {
1347 MockRead(false, ERR_FAILED, 1), 1347 MockRead(SYNCHRONOUS, ERR_FAILED, 1),
1348 }; 1348 };
1349 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1349 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1350 1350
1351 EXPECT_CALL(delegate_, 1351 EXPECT_CALL(delegate_,
1352 OnPipelineFeedback( 1352 OnPipelineFeedback(
1353 pipeline_.get(), 1353 pipeline_.get(),
1354 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR)) 1354 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR))
1355 .Times(1); 1355 .Times(1);
1356 1356
1357 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1357 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1358 HttpRequestHeaders headers; 1358 HttpRequestHeaders headers;
1359 HttpResponseInfo response; 1359 HttpResponseInfo response;
1360 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, 1360 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
1361 callback_.callback())); 1361 callback_.callback()));
1362 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback())); 1362 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback()));
1363 } 1363 }
1364 1364
1365 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoInternetConnection) { 1365 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoInternetConnection) {
1366 MockWrite writes[] = { 1366 MockWrite writes[] = {
1367 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1367 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1368 }; 1368 };
1369 MockRead reads[] = { 1369 MockRead reads[] = {
1370 MockRead(false, ERR_INTERNET_DISCONNECTED, 1), 1370 MockRead(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED, 1),
1371 }; 1371 };
1372 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1372 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1373 1373
1374 EXPECT_CALL(delegate_, OnPipelineFeedback(_, _)) 1374 EXPECT_CALL(delegate_, OnPipelineFeedback(_, _))
1375 .Times(0); 1375 .Times(0);
1376 1376
1377 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1377 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1378 HttpRequestHeaders headers; 1378 HttpRequestHeaders headers;
1379 HttpResponseInfo response; 1379 HttpResponseInfo response;
1380 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, 1380 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
1381 callback_.callback())); 1381 callback_.callback()));
1382 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, 1382 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
1383 stream->ReadResponseHeaders(callback_.callback())); 1383 stream->ReadResponseHeaders(callback_.callback()));
1384 } 1384 }
1385 1385
1386 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) { 1386 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) {
1387 MockWrite writes[] = { 1387 MockWrite writes[] = {
1388 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1388 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1389 }; 1389 };
1390 MockRead reads[] = { 1390 MockRead reads[] = {
1391 MockRead(false, 1, "HTTP/1.0 200 OK\r\n"), 1391 MockRead(SYNCHRONOUS, 1, "HTTP/1.0 200 OK\r\n"),
1392 MockRead(false, 2, "Content-Length: 7\r\n"), 1392 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n"),
1393 MockRead(false, 3, "Connection: keep-alive\r\n\r\n"), 1393 MockRead(SYNCHRONOUS, 3, "Connection: keep-alive\r\n\r\n"),
1394 MockRead(false, 4, "ok.html"), 1394 MockRead(SYNCHRONOUS, 4, "ok.html"),
1395 }; 1395 };
1396 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1396 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1397 1397
1398 EXPECT_CALL(delegate_, 1398 EXPECT_CALL(delegate_,
1399 OnPipelineFeedback(pipeline_.get(), 1399 OnPipelineFeedback(pipeline_.get(),
1400 HttpPipelinedConnection::OLD_HTTP_VERSION)) 1400 HttpPipelinedConnection::OLD_HTTP_VERSION))
1401 .Times(1); 1401 .Times(1);
1402 1402
1403 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1403 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1404 TestSyncRequest(stream, "ok.html"); 1404 TestSyncRequest(stream, "ok.html");
1405 } 1405 }
1406 1406
1407 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) { 1407 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) {
1408 MockWrite writes[] = { 1408 MockWrite writes[] = {
1409 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1409 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1410 }; 1410 };
1411 MockRead reads[] = { 1411 MockRead reads[] = {
1412 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 1412 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
1413 MockRead(false, 2, "Content-Length: 7\r\n"), 1413 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n"),
1414 MockRead(false, 3, "Connection: close\r\n\r\n"), 1414 MockRead(SYNCHRONOUS, 3, "Connection: close\r\n\r\n"),
1415 MockRead(false, 4, "ok.html"), 1415 MockRead(SYNCHRONOUS, 4, "ok.html"),
1416 }; 1416 };
1417 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1417 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1418 1418
1419 EXPECT_CALL(delegate_, 1419 EXPECT_CALL(delegate_,
1420 OnPipelineFeedback( 1420 OnPipelineFeedback(
1421 pipeline_.get(), 1421 pipeline_.get(),
1422 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)) 1422 HttpPipelinedConnection::MUST_CLOSE_CONNECTION))
1423 .Times(1); 1423 .Times(1);
1424 1424
1425 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1425 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1426 TestSyncRequest(stream, "ok.html"); 1426 TestSyncRequest(stream, "ok.html");
1427 } 1427 }
1428 1428
1429 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) { 1429 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) {
1430 MockWrite writes[] = { 1430 MockWrite writes[] = {
1431 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1431 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1432 }; 1432 };
1433 MockRead reads[] = { 1433 MockRead reads[] = {
1434 MockRead(false, 1, "HTTP/1.1 200 OK\r\n\r\n"), 1434 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"),
1435 MockRead(false, 2, "ok.html"), 1435 MockRead(SYNCHRONOUS, 2, "ok.html"),
1436 }; 1436 };
1437 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1437 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1438 1438
1439 EXPECT_CALL(delegate_, 1439 EXPECT_CALL(delegate_,
1440 OnPipelineFeedback( 1440 OnPipelineFeedback(
1441 pipeline_.get(), 1441 pipeline_.get(),
1442 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)) 1442 HttpPipelinedConnection::MUST_CLOSE_CONNECTION))
1443 .Times(1); 1443 .Times(1);
1444 1444
1445 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1445 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1446 TestSyncRequest(stream, "ok.html"); 1446 TestSyncRequest(stream, "ok.html");
1447 } 1447 }
1448 1448
1449 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnAuthenticationRequired) { 1449 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnAuthenticationRequired) {
1450 MockWrite writes[] = { 1450 MockWrite writes[] = {
1451 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1451 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1452 }; 1452 };
1453 MockRead reads[] = { 1453 MockRead reads[] = {
1454 MockRead(false, 1, "HTTP/1.1 401 Unauthorized\r\n"), 1454 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 401 Unauthorized\r\n"),
1455 MockRead(false, 2, "WWW-Authenticate: NTLM\r\n"), 1455 MockRead(SYNCHRONOUS, 2, "WWW-Authenticate: NTLM\r\n"),
1456 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 1456 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"),
1457 MockRead(false, 4, "ok.html"), 1457 MockRead(SYNCHRONOUS, 4, "ok.html"),
1458 }; 1458 };
1459 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1459 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1460 1460
1461 EXPECT_CALL(delegate_, 1461 EXPECT_CALL(delegate_,
1462 OnPipelineFeedback( 1462 OnPipelineFeedback(
1463 pipeline_.get(), 1463 pipeline_.get(),
1464 HttpPipelinedConnection::AUTHENTICATION_REQUIRED)) 1464 HttpPipelinedConnection::AUTHENTICATION_REQUIRED))
1465 .Times(1); 1465 .Times(1);
1466 1466
1467 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1467 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1468 TestSyncRequest(stream, "ok.html"); 1468 TestSyncRequest(stream, "ok.html");
1469 } 1469 }
1470 1470
1471 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { 1471 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
1472 MockWrite writes[] = { 1472 MockWrite writes[] = {
1473 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1473 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1474 }; 1474 };
1475 Initialize(NULL, 0, writes, arraysize(writes)); 1475 Initialize(NULL, 0, writes, arraysize(writes));
1476 1476
1477 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1477 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1478 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1478 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1479 1479
1480 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1480 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1481 HttpRequestHeaders headers; 1481 HttpRequestHeaders headers;
1482 HttpResponseInfo response; 1482 HttpResponseInfo response;
1483 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, 1483 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
1484 callback_.callback())); 1484 callback_.callback()));
1485 1485
1486 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1486 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1487 MessageLoop::current()->RunAllPending(); 1487 MessageLoop::current()->RunAllPending();
1488 1488
1489 stream->Close(false); 1489 stream->Close(false);
1490 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1490 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1491 stream.reset(NULL); 1491 stream.reset(NULL);
1492 } 1492 }
1493 1493
1494 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacityWithoutSend) { 1494 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacityWithoutSend) {
1495 MockWrite writes[] = { 1495 MockWrite writes[] = {
1496 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1496 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1497 }; 1497 };
1498 Initialize(NULL, 0, writes, arraysize(writes)); 1498 Initialize(NULL, 0, writes, arraysize(writes));
1499 1499
1500 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1500 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1501 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1501 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1502 1502
1503 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1503 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1504 MessageLoop::current()->RunAllPending(); 1504 MessageLoop::current()->RunAllPending();
1505 1505
1506 stream->Close(false); 1506 stream->Close(false);
1507 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1507 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1508 stream.reset(NULL); 1508 stream.reset(NULL);
1509 } 1509 }
1510 1510
1511 } // anonymous namespace 1511 } // anonymous namespace
1512 1512
1513 } // namespace net 1513 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/http/http_pipelined_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698