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

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

Issue 8990001: base::Bind: Convert most of net/http. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang. 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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 HttpRequestInfo* request_info = new HttpRequestInfo; 97 HttpRequestInfo* request_info = new HttpRequestInfo;
98 request_info->url = GURL("http://localhost/" + filename); 98 request_info->url = GURL("http://localhost/" + filename);
99 request_info->method = "GET"; 99 request_info->method = "GET";
100 request_info_vector_.push_back(request_info); 100 request_info_vector_.push_back(request_info);
101 return request_info; 101 return request_info;
102 } 102 }
103 103
104 HttpStream* NewTestStream(const std::string& filename) { 104 HttpStream* NewTestStream(const std::string& filename) {
105 HttpStream* stream = pipeline_->CreateNewStream(); 105 HttpStream* stream = pipeline_->CreateNewStream();
106 HttpRequestInfo* request_info = GetRequestInfo(filename); 106 HttpRequestInfo* request_info = GetRequestInfo(filename);
107 int rv = stream->InitializeStream(request_info, BoundNetLog(), NULL); 107 int rv = stream->InitializeStream(
108 request_info, BoundNetLog(), CompletionCallback());
108 DCHECK_EQ(OK, rv); 109 DCHECK_EQ(OK, rv);
109 return stream; 110 return stream;
110 } 111 }
111 112
112 void ExpectResponse(const std::string& expected, 113 void ExpectResponse(const std::string& expected,
113 scoped_ptr<HttpStream>& stream, bool async) { 114 scoped_ptr<HttpStream>& stream, bool async) {
114 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); 115 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size()));
115 116
116 if (async) { 117 if (async) {
117 EXPECT_EQ(ERR_IO_PENDING, 118 EXPECT_EQ(ERR_IO_PENDING,
118 stream->ReadResponseBody(buffer.get(), expected.size(), 119 stream->ReadResponseBody(buffer.get(), expected.size(),
119 &callback_)); 120 callback_.callback()));
120 data_->RunFor(1); 121 data_->RunFor(1);
121 EXPECT_EQ(static_cast<int>(expected.size()), callback_.WaitForResult()); 122 EXPECT_EQ(static_cast<int>(expected.size()), callback_.WaitForResult());
122 } else { 123 } else {
123 EXPECT_EQ(static_cast<int>(expected.size()), 124 EXPECT_EQ(static_cast<int>(expected.size()),
124 stream->ReadResponseBody(buffer.get(), expected.size(), 125 stream->ReadResponseBody(buffer.get(), expected.size(),
125 &callback_)); 126 callback_.callback()));
126 } 127 }
127 std::string actual(buffer->data(), expected.size()); 128 std::string actual(buffer->data(), expected.size());
128 EXPECT_THAT(actual, StrEq(expected)); 129 EXPECT_THAT(actual, StrEq(expected));
129 } 130 }
130 131
131 void TestSyncRequest(scoped_ptr<HttpStream>& stream, 132 void TestSyncRequest(scoped_ptr<HttpStream>& stream,
132 const std::string& filename) { 133 const std::string& filename) {
133 HttpRequestHeaders headers; 134 HttpRequestHeaders headers;
134 HttpResponseInfo response; 135 HttpResponseInfo response;
135 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_)); 136 EXPECT_EQ(OK, stream->SendRequest(
136 EXPECT_EQ(OK, stream->ReadResponseHeaders(&callback_)); 137 headers, NULL, &response, callback_.callback()));
138 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
137 ExpectResponse(filename, stream, false); 139 ExpectResponse(filename, stream, false);
138 140
139 stream->Close(false); 141 stream->Close(false);
140 } 142 }
141 143
142 DeterministicMockClientSocketFactory factory_; 144 DeterministicMockClientSocketFactory factory_;
143 ClientSocketPoolHistograms histograms_; 145 ClientSocketPoolHistograms histograms_;
144 MockTransportClientSocketPool pool_; 146 MockTransportClientSocketPool pool_;
145 scoped_refptr<DeterministicSocketData> data_; 147 scoped_refptr<DeterministicSocketData> data_;
146 148
147 SSLConfig ssl_config_; 149 SSLConfig ssl_config_;
148 ProxyInfo proxy_info_; 150 ProxyInfo proxy_info_;
149 NiceMock<MockPipelineDelegate> delegate_; 151 NiceMock<MockPipelineDelegate> delegate_;
150 TestOldCompletionCallback callback_; 152 TestCompletionCallback callback_;
151 scoped_ptr<HttpPipelinedConnectionImpl> pipeline_; 153 scoped_ptr<HttpPipelinedConnectionImpl> pipeline_;
152 ScopedVector<HttpRequestInfo> request_info_vector_; 154 ScopedVector<HttpRequestInfo> request_info_vector_;
153 }; 155 };
154 156
155 TEST_F(HttpPipelinedConnectionImplTest, PipelineNotUsed) { 157 TEST_F(HttpPipelinedConnectionImplTest, PipelineNotUsed) {
156 Initialize(NULL, 0, NULL, 0); 158 Initialize(NULL, 0, NULL, 0);
157 } 159 }
158 160
159 TEST_F(HttpPipelinedConnectionImplTest, StreamNotUsed) { 161 TEST_F(HttpPipelinedConnectionImplTest, StreamNotUsed) {
160 Initialize(NULL, 0, NULL, 0); 162 Initialize(NULL, 0, NULL, 0);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 MockRead(true, 1, "HTTP/1.1 200 OK\r\n"), 197 MockRead(true, 1, "HTTP/1.1 200 OK\r\n"),
196 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 198 MockRead(true, 2, "Content-Length: 7\r\n\r\n"),
197 MockRead(true, 3, "ok.html"), 199 MockRead(true, 3, "ok.html"),
198 }; 200 };
199 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 201 Initialize(reads, arraysize(reads), writes, arraysize(writes));
200 202
201 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 203 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
202 204
203 HttpRequestHeaders headers; 205 HttpRequestHeaders headers;
204 HttpResponseInfo response; 206 HttpResponseInfo response;
205 EXPECT_EQ(ERR_IO_PENDING, 207 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
206 stream->SendRequest(headers, NULL, &response, &callback_)); 208 callback_.callback()));
207 data_->RunFor(1); 209 data_->RunFor(1);
208 EXPECT_LE(OK, callback_.WaitForResult()); 210 EXPECT_LE(OK, callback_.WaitForResult());
209 211
210 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(&callback_)); 212 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback()));
211 data_->RunFor(2); 213 data_->RunFor(2);
212 EXPECT_LE(OK, callback_.WaitForResult()); 214 EXPECT_LE(OK, callback_.WaitForResult());
213 215
214 ExpectResponse("ok.html", stream, true); 216 ExpectResponse("ok.html", stream, true);
215 217
216 stream->Close(false); 218 stream->Close(false);
217 } 219 }
218 220
219 TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) { 221 TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) {
220 MockWrite writes[] = { 222 MockWrite writes[] = {
221 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 223 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
222 MockWrite(true, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), 224 MockWrite(true, 1, "GET /ko.html HTTP/1.1\r\n\r\n"),
223 }; 225 };
224 MockRead reads[] = { 226 MockRead reads[] = {
225 MockRead(true, 2, "HTTP/1.1 200 OK\r\n"), 227 MockRead(true, 2, "HTTP/1.1 200 OK\r\n"),
226 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 228 MockRead(true, 3, "Content-Length: 7\r\n\r\n"),
227 MockRead(true, 4, "ok.html"), 229 MockRead(true, 4, "ok.html"),
228 MockRead(true, 5, "HTTP/1.1 200 OK\r\n"), 230 MockRead(true, 5, "HTTP/1.1 200 OK\r\n"),
229 MockRead(true, 6, "Content-Length: 7\r\n\r\n"), 231 MockRead(true, 6, "Content-Length: 7\r\n\r\n"),
230 MockRead(true, 7, "ko.html"), 232 MockRead(true, 7, "ko.html"),
231 }; 233 };
232 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 234 Initialize(reads, arraysize(reads), writes, arraysize(writes));
233 235
234 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 236 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
235 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 237 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
236 238
237 HttpRequestHeaders headers1; 239 HttpRequestHeaders headers1;
238 HttpResponseInfo response1; 240 HttpResponseInfo response1;
239 EXPECT_EQ(ERR_IO_PENDING, 241 EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, NULL, &response1,
240 stream1->SendRequest(headers1, NULL, &response1, &callback_)); 242 callback_.callback()));
241 243
242 HttpRequestHeaders headers2; 244 HttpRequestHeaders headers2;
243 HttpResponseInfo response2; 245 HttpResponseInfo response2;
244 EXPECT_EQ(ERR_IO_PENDING, 246 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, NULL, &response2,
245 stream2->SendRequest(headers2, NULL, &response2, &callback_)); 247 callback_.callback()));
246 248
247 data_->RunFor(1); 249 data_->RunFor(1);
248 EXPECT_LE(OK, callback_.WaitForResult()); 250 EXPECT_LE(OK, callback_.WaitForResult());
249 data_->RunFor(1); 251 data_->RunFor(1);
250 EXPECT_LE(OK, callback_.WaitForResult()); 252 EXPECT_LE(OK, callback_.WaitForResult());
251 253
252 EXPECT_EQ(ERR_IO_PENDING, stream1->ReadResponseHeaders(&callback_)); 254 EXPECT_EQ(ERR_IO_PENDING, stream1->ReadResponseHeaders(callback_.callback()));
253 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(&callback_)); 255 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback()));
254 256
255 data_->RunFor(2); 257 data_->RunFor(2);
256 EXPECT_LE(OK, callback_.WaitForResult()); 258 EXPECT_LE(OK, callback_.WaitForResult());
257 259
258 ExpectResponse("ok.html", stream1, true); 260 ExpectResponse("ok.html", stream1, true);
259 261
260 stream1->Close(false); 262 stream1->Close(false);
261 263
262 data_->RunFor(2); 264 data_->RunFor(2);
263 EXPECT_LE(OK, callback_.WaitForResult()); 265 EXPECT_LE(OK, callback_.WaitForResult());
(...skipping 17 matching lines...) Expand all
281 "Content-Length: 7\r\n\r\n" 283 "Content-Length: 7\r\n\r\n"
282 "ko.html"), 284 "ko.html"),
283 }; 285 };
284 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 286 Initialize(reads, arraysize(reads), writes, arraysize(writes));
285 287
286 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 288 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
287 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 289 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
288 290
289 HttpRequestHeaders headers1; 291 HttpRequestHeaders headers1;
290 HttpResponseInfo response1; 292 HttpResponseInfo response1;
291 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 293 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
294 callback_.callback()));
292 HttpRequestHeaders headers2; 295 HttpRequestHeaders headers2;
293 HttpResponseInfo response2; 296 HttpResponseInfo response2;
294 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 297 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
298 callback_.callback()));
295 299
296 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 300 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
297 ExpectResponse("ok.html", stream1, false); 301 ExpectResponse("ok.html", stream1, false);
298 stream1->Close(false); 302 stream1->Close(false);
299 303
300 EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_)); 304 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
301 ExpectResponse("ko.html", stream2, false); 305 ExpectResponse("ko.html", stream2, false);
302 stream2->Close(false); 306 stream2->Close(false);
303 } 307 }
304 308
305 TEST_F(HttpPipelinedConnectionImplTest, SendOrderSwapped) { 309 TEST_F(HttpPipelinedConnectionImplTest, SendOrderSwapped) {
306 MockWrite writes[] = { 310 MockWrite writes[] = {
307 MockWrite(false, 0, "GET /ko.html HTTP/1.1\r\n\r\n"), 311 MockWrite(false, 0, "GET /ko.html HTTP/1.1\r\n\r\n"),
308 MockWrite(false, 4, "GET /ok.html HTTP/1.1\r\n\r\n"), 312 MockWrite(false, 4, "GET /ok.html HTTP/1.1\r\n\r\n"),
309 }; 313 };
310 MockRead reads[] = { 314 MockRead reads[] = {
(...skipping 26 matching lines...) Expand all
337 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 341 MockRead(false, 6, "Content-Length: 7\r\n\r\n"),
338 MockRead(false, 7, "ko.html"), 342 MockRead(false, 7, "ko.html"),
339 }; 343 };
340 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 344 Initialize(reads, arraysize(reads), writes, arraysize(writes));
341 345
342 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 346 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
343 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 347 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
344 348
345 HttpRequestHeaders headers1; 349 HttpRequestHeaders headers1;
346 HttpResponseInfo response1; 350 HttpResponseInfo response1;
347 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 351 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
352 callback_.callback()));
348 353
349 HttpRequestHeaders headers2; 354 HttpRequestHeaders headers2;
350 HttpResponseInfo response2; 355 HttpResponseInfo response2;
351 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 356 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
357 callback_.callback()));
352 358
353 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(&callback_)); 359 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback()));
354 360
355 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 361 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
356 ExpectResponse("ok.html", stream1, false); 362 ExpectResponse("ok.html", stream1, false);
357 363
358 stream1->Close(false); 364 stream1->Close(false);
359 365
360 EXPECT_LE(OK, callback_.WaitForResult()); 366 EXPECT_LE(OK, callback_.WaitForResult());
361 ExpectResponse("ko.html", stream2, false); 367 ExpectResponse("ko.html", stream2, false);
362 368
363 stream2->Close(false); 369 stream2->Close(false);
364 } 370 }
365 371
(...skipping 10 matching lines...) Expand all
376 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 382 MockRead(false, 6, "Content-Length: 7\r\n\r\n"),
377 MockRead(false, 7, "ko.html"), 383 MockRead(false, 7, "ko.html"),
378 }; 384 };
379 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 385 Initialize(reads, arraysize(reads), writes, arraysize(writes));
380 386
381 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 387 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
382 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 388 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
383 389
384 HttpRequestHeaders headers1; 390 HttpRequestHeaders headers1;
385 HttpResponseInfo response1; 391 HttpResponseInfo response1;
386 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 392 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
387 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 393 callback_.callback()));
394 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
388 395
389 HttpRequestHeaders headers2; 396 HttpRequestHeaders headers2;
390 HttpResponseInfo response2; 397 HttpResponseInfo response2;
391 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 398 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
399 callback_.callback()));
392 400
393 ExpectResponse("ok.html", stream1, false); 401 ExpectResponse("ok.html", stream1, false);
394 stream1->Close(false); 402 stream1->Close(false);
395 403
396 EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_)); 404 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
397 ExpectResponse("ko.html", stream2, false); 405 ExpectResponse("ko.html", stream2, false);
398 stream2->Close(false); 406 stream2->Close(false);
399 } 407 }
400 408
401 TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) { 409 TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) {
402 MockWrite writes[] = { 410 MockWrite writes[] = {
403 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 411 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
404 MockWrite(true, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), 412 MockWrite(true, 3, "GET /ko.html HTTP/1.1\r\n\r\n"),
405 }; 413 };
406 MockRead reads[] = { 414 MockRead reads[] = {
407 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 415 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
408 MockRead(false, 2, "Content-Length: 7\r\n\r\n"), 416 MockRead(false, 2, "Content-Length: 7\r\n\r\n"),
409 MockRead(true, 4, "ok.html"), 417 MockRead(true, 4, "ok.html"),
410 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 418 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"),
411 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 419 MockRead(false, 6, "Content-Length: 7\r\n\r\n"),
412 MockRead(false, 7, "ko.html"), 420 MockRead(false, 7, "ko.html"),
413 }; 421 };
414 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 422 Initialize(reads, arraysize(reads), writes, arraysize(writes));
415 423
416 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); 424 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html"));
417 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); 425 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html"));
418 426
419 HttpRequestHeaders headers1; 427 HttpRequestHeaders headers1;
420 HttpResponseInfo response1; 428 HttpResponseInfo response1;
421 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 429 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
422 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 430 callback_.callback()));
423 TestOldCompletionCallback callback1; 431 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
432 TestCompletionCallback callback1;
424 std::string expected = "ok.html"; 433 std::string expected = "ok.html";
425 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); 434 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size()));
426 EXPECT_EQ(ERR_IO_PENDING, 435 EXPECT_EQ(ERR_IO_PENDING,
427 stream1->ReadResponseBody(buffer.get(), expected.size(), 436 stream1->ReadResponseBody(buffer.get(), expected.size(),
428 &callback1)); 437 callback1.callback()));
429 438
430 HttpRequestHeaders headers2; 439 HttpRequestHeaders headers2;
431 HttpResponseInfo response2; 440 HttpResponseInfo response2;
432 TestOldCompletionCallback callback2; 441 TestCompletionCallback callback2;
433 EXPECT_EQ(ERR_IO_PENDING, 442 EXPECT_EQ(ERR_IO_PENDING,
434 stream2->SendRequest(headers2, NULL, &response2, &callback2)); 443 stream2->SendRequest(headers2, NULL, &response2,
444 callback2.callback()));
435 445
436 data_->RunFor(1); 446 data_->RunFor(1);
437 EXPECT_LE(OK, callback2.WaitForResult()); 447 EXPECT_LE(OK, callback2.WaitForResult());
438 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(&callback2)); 448 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback2.callback()));
439 449
440 data_->RunFor(1); 450 data_->RunFor(1);
441 EXPECT_EQ(static_cast<int>(expected.size()), callback1.WaitForResult()); 451 EXPECT_EQ(static_cast<int>(expected.size()), callback1.WaitForResult());
442 std::string actual(buffer->data(), expected.size()); 452 std::string actual(buffer->data(), expected.size());
443 EXPECT_THAT(actual, StrEq(expected)); 453 EXPECT_THAT(actual, StrEq(expected));
444 stream1->Close(false); 454 stream1->Close(false);
445 455
446 data_->StopAfter(8); 456 data_->StopAfter(8);
447 EXPECT_LE(OK, callback2.WaitForResult()); 457 EXPECT_LE(OK, callback2.WaitForResult());
448 ExpectResponse("ko.html", stream2, false); 458 ExpectResponse("ko.html", stream2, false);
(...skipping 30 matching lines...) Expand all
479 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), 489 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"),
480 MockRead(false, 6, "Content-Length: 7\r\n\r\n"), 490 MockRead(false, 6, "Content-Length: 7\r\n\r\n"),
481 MockRead(false, 7, "ko.html"), 491 MockRead(false, 7, "ko.html"),
482 }; 492 };
483 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 493 Initialize(reads, arraysize(reads), writes, arraysize(writes));
484 494
485 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 495 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
486 496
487 HttpRequestHeaders headers; 497 HttpRequestHeaders headers;
488 HttpResponseInfo response; 498 HttpResponseInfo response;
489 EXPECT_EQ(ERR_IO_PENDING, 499 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
490 stream->SendRequest(headers, NULL, &response, &callback_)); 500 callback_.callback()));
491 501
492 scoped_ptr<HttpStream> unsent_stream(NewTestStream("unsent.html")); 502 scoped_ptr<HttpStream> unsent_stream(NewTestStream("unsent.html"));
493 HttpRequestHeaders unsent_headers; 503 HttpRequestHeaders unsent_headers;
494 HttpResponseInfo unsent_response; 504 HttpResponseInfo unsent_response;
495 EXPECT_EQ(ERR_IO_PENDING, 505 EXPECT_EQ(ERR_IO_PENDING,
496 unsent_stream->SendRequest(unsent_headers, NULL, &unsent_response, 506 unsent_stream->SendRequest(unsent_headers, NULL, &unsent_response,
497 &callback_)); 507 callback_.callback()));
498 unsent_stream->Close(false); 508 unsent_stream->Close(false);
499 509
500 data_->RunFor(1); 510 data_->RunFor(1);
501 EXPECT_LE(OK, callback_.WaitForResult()); 511 EXPECT_LE(OK, callback_.WaitForResult());
502 512
503 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(&callback_)); 513 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback()));
504 data_->RunFor(2); 514 data_->RunFor(2);
505 EXPECT_LE(OK, callback_.WaitForResult()); 515 EXPECT_LE(OK, callback_.WaitForResult());
506 516
507 ExpectResponse("ok.html", stream, true); 517 ExpectResponse("ok.html", stream, true);
508 518
509 stream->Close(false); 519 stream->Close(false);
510 520
511 data_->StopAfter(8); 521 data_->StopAfter(8);
512 scoped_ptr<HttpStream> later_stream(NewTestStream("ko.html")); 522 scoped_ptr<HttpStream> later_stream(NewTestStream("ko.html"));
513 TestSyncRequest(later_stream, "ko.html"); 523 TestSyncRequest(later_stream, "ko.html");
514 } 524 }
515 525
516 TEST_F(HttpPipelinedConnectionImplTest, FailedSend) { 526 TEST_F(HttpPipelinedConnectionImplTest, FailedSend) {
517 MockWrite writes[] = { 527 MockWrite writes[] = {
518 MockWrite(true, ERR_FAILED), 528 MockWrite(true, ERR_FAILED),
519 }; 529 };
520 Initialize(NULL, 0, writes, arraysize(writes)); 530 Initialize(NULL, 0, writes, arraysize(writes));
521 531
522 scoped_ptr<HttpStream> failed_stream(NewTestStream("ok.html")); 532 scoped_ptr<HttpStream> failed_stream(NewTestStream("ok.html"));
523 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 533 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
524 scoped_ptr<HttpStream> closed_stream(NewTestStream("closed.html")); 534 scoped_ptr<HttpStream> closed_stream(NewTestStream("closed.html"));
525 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); 535 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
526 536
527 HttpRequestHeaders headers; 537 HttpRequestHeaders headers;
528 HttpResponseInfo response; 538 HttpResponseInfo response;
529 TestOldCompletionCallback failed_callback; 539 TestCompletionCallback failed_callback;
530 EXPECT_EQ(ERR_IO_PENDING, 540 EXPECT_EQ(ERR_IO_PENDING,
531 failed_stream->SendRequest(headers, NULL, &response, 541 failed_stream->SendRequest(headers, NULL, &response,
532 &failed_callback)); 542 failed_callback.callback()));
533 TestOldCompletionCallback evicted_callback; 543 TestCompletionCallback evicted_callback;
534 EXPECT_EQ(ERR_IO_PENDING, 544 EXPECT_EQ(ERR_IO_PENDING,
535 evicted_stream->SendRequest(headers, NULL, &response, 545 evicted_stream->SendRequest(headers, NULL, &response,
536 &evicted_callback)); 546 evicted_callback.callback()));
537 EXPECT_EQ(ERR_IO_PENDING, 547 EXPECT_EQ(ERR_IO_PENDING,
538 closed_stream->SendRequest(headers, NULL, &response, 548 closed_stream->SendRequest(headers, NULL, &response,
539 &callback_)); 549 callback_.callback()));
540 closed_stream->Close(false); 550 closed_stream->Close(false);
541 551
542 data_->RunFor(1); 552 data_->RunFor(1);
543 EXPECT_EQ(ERR_FAILED, failed_callback.WaitForResult()); 553 EXPECT_EQ(ERR_FAILED, failed_callback.WaitForResult());
544 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 554 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
545 EXPECT_EQ(ERR_PIPELINE_EVICTION, 555 EXPECT_EQ(ERR_PIPELINE_EVICTION,
546 rejected_stream->SendRequest(headers, NULL, &response, 556 rejected_stream->SendRequest(headers, NULL, &response,
547 &callback_)); 557 callback_.callback()));
548 558
549 failed_stream->Close(true); 559 failed_stream->Close(true);
550 evicted_stream->Close(true); 560 evicted_stream->Close(true);
551 rejected_stream->Close(true); 561 rejected_stream->Close(true);
552 } 562 }
553 563
554 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) { 564 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
555 MockWrite writes[] = { 565 MockWrite writes[] = {
556 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 566 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
557 MockWrite(false, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"), 567 MockWrite(false, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"),
(...skipping 14 matching lines...) Expand all
572 scoped_ptr<HttpStream> send_closed_stream( 582 scoped_ptr<HttpStream> send_closed_stream(
573 NewTestStream("send_closed.html")); 583 NewTestStream("send_closed.html"));
574 scoped_ptr<HttpStream> send_evicted_stream( 584 scoped_ptr<HttpStream> send_evicted_stream(
575 NewTestStream("send_evicted.html")); 585 NewTestStream("send_evicted.html"));
576 scoped_ptr<HttpStream> send_rejected_stream( 586 scoped_ptr<HttpStream> send_rejected_stream(
577 NewTestStream("send_rejected.html")); 587 NewTestStream("send_rejected.html"));
578 588
579 HttpRequestHeaders headers; 589 HttpRequestHeaders headers;
580 HttpResponseInfo response; 590 HttpResponseInfo response;
581 EXPECT_EQ(OK, closed_stream->SendRequest(headers, NULL, &response, 591 EXPECT_EQ(OK, closed_stream->SendRequest(headers, NULL, &response,
582 &callback_)); 592 callback_.callback()));
583 EXPECT_EQ(OK, read_evicted_stream->SendRequest(headers, NULL, &response, 593 EXPECT_EQ(OK, read_evicted_stream->SendRequest(headers, NULL, &response,
584 &callback_)); 594 callback_.callback()));
585 EXPECT_EQ(OK, read_rejected_stream->SendRequest(headers, NULL, &response, 595 EXPECT_EQ(OK, read_rejected_stream->SendRequest(headers, NULL, &response,
586 &callback_)); 596 callback_.callback()));
587 TestOldCompletionCallback send_closed_callback; 597 TestCompletionCallback send_closed_callback;
588 EXPECT_EQ(ERR_IO_PENDING, 598 EXPECT_EQ(ERR_IO_PENDING,
589 send_closed_stream->SendRequest(headers, NULL, &response, 599 send_closed_stream->SendRequest(headers, NULL, &response,
590 &send_closed_callback)); 600 send_closed_callback.callback()));
591 TestOldCompletionCallback send_evicted_callback; 601 TestCompletionCallback send_evicted_callback;
592 EXPECT_EQ(ERR_IO_PENDING, 602 EXPECT_EQ(ERR_IO_PENDING,
593 send_evicted_stream->SendRequest(headers, NULL, &response, 603 send_evicted_stream->SendRequest(headers, NULL, &response,
594 &send_evicted_callback)); 604 send_evicted_callback.callback()));
595 605
596 TestOldCompletionCallback read_evicted_callback; 606 TestCompletionCallback read_evicted_callback;
597 EXPECT_EQ(ERR_IO_PENDING, 607 EXPECT_EQ(ERR_IO_PENDING,
598 read_evicted_stream->ReadResponseHeaders(&read_evicted_callback)); 608 read_evicted_stream->ReadResponseHeaders(
609 read_evicted_callback.callback()));
599 610
600 EXPECT_EQ(OK, closed_stream->ReadResponseHeaders(&callback_)); 611 EXPECT_EQ(OK, closed_stream->ReadResponseHeaders(callback_.callback()));
601 ExpectResponse("ok.html", closed_stream, false); 612 ExpectResponse("ok.html", closed_stream, false);
602 closed_stream->Close(true); 613 closed_stream->Close(true);
603 614
604 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_evicted_callback.WaitForResult()); 615 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_evicted_callback.WaitForResult());
605 read_evicted_stream->Close(true); 616 read_evicted_stream->Close(true);
606 617
607 EXPECT_EQ(ERR_PIPELINE_EVICTION, 618 EXPECT_EQ(ERR_PIPELINE_EVICTION,
608 read_rejected_stream->ReadResponseHeaders(&callback_)); 619 read_rejected_stream->ReadResponseHeaders(callback_.callback()));
609 read_rejected_stream->Close(true); 620 read_rejected_stream->Close(true);
610 621
611 data_->RunFor(1); 622 data_->RunFor(1);
612 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, send_closed_callback.WaitForResult()); 623 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, send_closed_callback.WaitForResult());
613 send_closed_stream->Close(true); 624 send_closed_stream->Close(true);
614 625
615 EXPECT_EQ(ERR_PIPELINE_EVICTION, send_evicted_callback.WaitForResult()); 626 EXPECT_EQ(ERR_PIPELINE_EVICTION, send_evicted_callback.WaitForResult());
616 send_evicted_stream->Close(true); 627 send_evicted_stream->Close(true);
617 628
618 EXPECT_EQ(ERR_PIPELINE_EVICTION, 629 EXPECT_EQ(ERR_PIPELINE_EVICTION,
619 send_rejected_stream->SendRequest(headers, NULL, &response, 630 send_rejected_stream->SendRequest(headers, NULL, &response,
620 &callback_)); 631 callback_.callback()));
621 send_rejected_stream->Close(true); 632 send_rejected_stream->Close(true);
622 } 633 }
623 634
624 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) { 635 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) {
625 MockWrite writes[] = { 636 MockWrite writes[] = {
626 MockWrite(true, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), 637 MockWrite(true, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"),
627 }; 638 };
628 Initialize(NULL, 0, writes, arraysize(writes)); 639 Initialize(NULL, 0, writes, arraysize(writes));
629 640
630 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); 641 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html"));
631 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 642 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
632 643
633 HttpRequestHeaders headers; 644 HttpRequestHeaders headers;
634 HttpResponseInfo response; 645 HttpResponseInfo response;
635 TestOldCompletionCallback aborted_callback; 646 TestCompletionCallback aborted_callback;
636 EXPECT_EQ(ERR_IO_PENDING, 647 EXPECT_EQ(ERR_IO_PENDING,
637 aborted_stream->SendRequest(headers, NULL, &response, 648 aborted_stream->SendRequest(headers, NULL, &response,
638 &aborted_callback)); 649 aborted_callback.callback()));
639 TestOldCompletionCallback evicted_callback; 650 TestCompletionCallback evicted_callback;
640 EXPECT_EQ(ERR_IO_PENDING, 651 EXPECT_EQ(ERR_IO_PENDING,
641 evicted_stream->SendRequest(headers, NULL, &response, 652 evicted_stream->SendRequest(headers, NULL, &response,
642 &evicted_callback)); 653 evicted_callback.callback()));
643 654
644 aborted_stream->Close(true); 655 aborted_stream->Close(true);
645 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 656 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
646 evicted_stream->Close(true); 657 evicted_stream->Close(true);
647 EXPECT_FALSE(aborted_callback.have_result()); 658 EXPECT_FALSE(aborted_callback.have_result());
648 } 659 }
649 660
650 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) { 661 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) {
651 MockWrite writes[] = { 662 MockWrite writes[] = {
652 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 663 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
653 MockWrite(true, 1, "GET /aborts.html HTTP/1.1\r\n\r\n"), 664 MockWrite(true, 1, "GET /aborts.html HTTP/1.1\r\n\r\n"),
654 }; 665 };
655 Initialize(NULL, 0, writes, arraysize(writes)); 666 Initialize(NULL, 0, writes, arraysize(writes));
656 667
657 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 668 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
658 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); 669 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html"));
659 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 670 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
660 671
661 HttpRequestHeaders headers; 672 HttpRequestHeaders headers;
662 HttpResponseInfo response; 673 HttpResponseInfo response;
663 TestOldCompletionCallback ok_callback; 674 TestCompletionCallback ok_callback;
664 EXPECT_EQ(ERR_IO_PENDING, 675 EXPECT_EQ(ERR_IO_PENDING,
665 ok_stream->SendRequest(headers, NULL, &response, 676 ok_stream->SendRequest(headers, NULL, &response,
666 &ok_callback)); 677 ok_callback.callback()));
667 TestOldCompletionCallback aborted_callback; 678 TestCompletionCallback aborted_callback;
668 EXPECT_EQ(ERR_IO_PENDING, 679 EXPECT_EQ(ERR_IO_PENDING,
669 aborted_stream->SendRequest(headers, NULL, &response, 680 aborted_stream->SendRequest(headers, NULL, &response,
670 &aborted_callback)); 681 aborted_callback.callback()));
671 TestOldCompletionCallback evicted_callback; 682 TestCompletionCallback evicted_callback;
672 EXPECT_EQ(ERR_IO_PENDING, 683 EXPECT_EQ(ERR_IO_PENDING,
673 evicted_stream->SendRequest(headers, NULL, &response, 684 evicted_stream->SendRequest(headers, NULL, &response,
674 &evicted_callback)); 685 evicted_callback.callback()));
675 686
676 data_->RunFor(1); 687 data_->RunFor(1);
677 EXPECT_LE(OK, ok_callback.WaitForResult()); 688 EXPECT_LE(OK, ok_callback.WaitForResult());
678 MessageLoop::current()->RunAllPending(); 689 MessageLoop::current()->RunAllPending();
679 aborted_stream->Close(true); 690 aborted_stream->Close(true);
680 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 691 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
681 evicted_stream->Close(true); 692 evicted_stream->Close(true);
682 EXPECT_FALSE(aborted_callback.have_result()); 693 EXPECT_FALSE(aborted_callback.have_result());
683 ok_stream->Close(true); 694 ok_stream->Close(true);
684 } 695 }
685 696
686 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) { 697 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) {
687 MockWrite writes[] = { 698 MockWrite writes[] = {
688 MockWrite(false, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), 699 MockWrite(false, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"),
689 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 700 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
690 }; 701 };
691 MockRead reads[] = { 702 MockRead reads[] = {
692 MockRead(true, ERR_FAILED, 2), 703 MockRead(true, ERR_FAILED, 2),
693 }; 704 };
694 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 705 Initialize(reads, arraysize(reads), writes, arraysize(writes));
695 706
696 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); 707 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html"));
697 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 708 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
698 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); 709 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
699 710
700 HttpRequestHeaders headers; 711 HttpRequestHeaders headers;
701 HttpResponseInfo response; 712 HttpResponseInfo response;
702 EXPECT_EQ(OK, aborted_stream->SendRequest(headers, NULL, &response, 713 EXPECT_EQ(OK, aborted_stream->SendRequest(headers, NULL, &response,
703 &callback_)); 714 callback_.callback()));
704 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response, 715 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
705 &callback_)); 716 callback_.callback()));
706 717
707 EXPECT_EQ(ERR_IO_PENDING, aborted_stream->ReadResponseHeaders(&callback_));
708 TestOldCompletionCallback evicted_callback;
709 EXPECT_EQ(ERR_IO_PENDING, 718 EXPECT_EQ(ERR_IO_PENDING,
710 evicted_stream->ReadResponseHeaders(&evicted_callback)); 719 aborted_stream->ReadResponseHeaders(callback_.callback()));
720 TestCompletionCallback evicted_callback;
721 EXPECT_EQ(ERR_IO_PENDING,
722 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
711 723
712 aborted_stream->Close(true); 724 aborted_stream->Close(true);
713 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 725 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
714 evicted_stream->Close(true); 726 evicted_stream->Close(true);
715 727
716 EXPECT_EQ(ERR_PIPELINE_EVICTION, 728 EXPECT_EQ(ERR_PIPELINE_EVICTION,
717 rejected_stream->SendRequest(headers, NULL, &response, &callback_)); 729 rejected_stream->SendRequest(headers, NULL, &response,
730 callback_.callback()));
718 rejected_stream->Close(true); 731 rejected_stream->Close(true);
719 } 732 }
720 733
721 TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) { 734 TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) {
722 MockWrite writes[] = { 735 MockWrite writes[] = {
723 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 736 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
724 MockWrite(false, 1, "GET /abandoned.html HTTP/1.1\r\n\r\n"), 737 MockWrite(false, 1, "GET /abandoned.html HTTP/1.1\r\n\r\n"),
725 MockWrite(false, 2, "GET /evicted.html HTTP/1.1\r\n\r\n"), 738 MockWrite(false, 2, "GET /evicted.html HTTP/1.1\r\n\r\n"),
726 }; 739 };
727 MockRead reads[] = { 740 MockRead reads[] = {
728 MockRead(false, 3, "HTTP/1.1 200 OK\r\n"), 741 MockRead(false, 3, "HTTP/1.1 200 OK\r\n"),
729 MockRead(false, 4, "Content-Length: 7\r\n\r\n"), 742 MockRead(false, 4, "Content-Length: 7\r\n\r\n"),
730 MockRead(false, 5, "ok.html"), 743 MockRead(false, 5, "ok.html"),
731 }; 744 };
732 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 745 Initialize(reads, arraysize(reads), writes, arraysize(writes));
733 746
734 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 747 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
735 scoped_ptr<HttpStream> abandoned_stream(NewTestStream("abandoned.html")); 748 scoped_ptr<HttpStream> abandoned_stream(NewTestStream("abandoned.html"));
736 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 749 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
737 750
738 HttpRequestHeaders headers; 751 HttpRequestHeaders headers;
739 HttpResponseInfo response; 752 HttpResponseInfo response;
740 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); 753 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
754 callback_.callback()));
741 EXPECT_EQ(OK, abandoned_stream->SendRequest(headers, NULL, &response, 755 EXPECT_EQ(OK, abandoned_stream->SendRequest(headers, NULL, &response,
742 &callback_)); 756 callback_.callback()));
743 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response, 757 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
744 &callback_)); 758 callback_.callback()));
745 759
746 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_)); 760 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
747 TestOldCompletionCallback abandoned_callback; 761 TestCompletionCallback abandoned_callback;
762 EXPECT_EQ(ERR_IO_PENDING, abandoned_stream->ReadResponseHeaders(
763 abandoned_callback.callback()));
764 TestCompletionCallback evicted_callback;
748 EXPECT_EQ(ERR_IO_PENDING, 765 EXPECT_EQ(ERR_IO_PENDING,
749 abandoned_stream->ReadResponseHeaders(&abandoned_callback)); 766 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
750 TestOldCompletionCallback evicted_callback;
751 EXPECT_EQ(ERR_IO_PENDING,
752 evicted_stream->ReadResponseHeaders(&evicted_callback));
753 767
754 abandoned_stream->Close(false); 768 abandoned_stream->Close(false);
755 769
756 ExpectResponse("ok.html", ok_stream, false); 770 ExpectResponse("ok.html", ok_stream, false);
757 ok_stream->Close(false); 771 ok_stream->Close(false);
758 772
759 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 773 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
760 evicted_stream->Close(true); 774 evicted_stream->Close(true);
761 EXPECT_FALSE(evicted_stream->IsConnectionReusable()); 775 EXPECT_FALSE(evicted_stream->IsConnectionReusable());
762 } 776 }
(...skipping 13 matching lines...) Expand all
776 }; 790 };
777 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 791 Initialize(reads, arraysize(reads), writes, arraysize(writes));
778 792
779 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 793 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
780 scoped_ptr<HttpStream> rejected_read_stream(NewTestStream("rejected.html")); 794 scoped_ptr<HttpStream> rejected_read_stream(NewTestStream("rejected.html"));
781 scoped_ptr<HttpStream> evicted_send_stream(NewTestStream("evicted.html")); 795 scoped_ptr<HttpStream> evicted_send_stream(NewTestStream("evicted.html"));
782 scoped_ptr<HttpStream> rejected_send_stream(NewTestStream("rejected.html")); 796 scoped_ptr<HttpStream> rejected_send_stream(NewTestStream("rejected.html"));
783 797
784 HttpRequestHeaders headers; 798 HttpRequestHeaders headers;
785 HttpResponseInfo response; 799 HttpResponseInfo response;
786 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); 800 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
801 callback_.callback()));
787 EXPECT_EQ(OK, rejected_read_stream->SendRequest( 802 EXPECT_EQ(OK, rejected_read_stream->SendRequest(
788 headers, NULL, &response, &callback_)); 803 headers, NULL, &response, callback_.callback()));
789 804
790 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_)); 805 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
791 ExpectResponse("ok.html", ok_stream, false); 806 ExpectResponse("ok.html", ok_stream, false);
792 ok_stream->Close(false); 807 ok_stream->Close(false);
793 808
794 TestOldCompletionCallback read_callback; 809 TestCompletionCallback read_callback;
795 EXPECT_EQ(ERR_IO_PENDING, 810 EXPECT_EQ(ERR_IO_PENDING,
796 evicted_send_stream->SendRequest(headers, NULL, &response, 811 evicted_send_stream->SendRequest(headers, NULL, &response,
797 &read_callback)); 812 read_callback.callback()));
798 data_->RunFor(1); 813 data_->RunFor(1);
799 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_callback.WaitForResult()); 814 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_callback.WaitForResult());
800 815
801 EXPECT_EQ(ERR_PIPELINE_EVICTION, 816 EXPECT_EQ(ERR_PIPELINE_EVICTION,
802 rejected_read_stream->ReadResponseHeaders(&callback_)); 817 rejected_read_stream->ReadResponseHeaders(callback_.callback()));
803 EXPECT_EQ(ERR_PIPELINE_EVICTION, 818 EXPECT_EQ(ERR_PIPELINE_EVICTION,
804 rejected_send_stream->SendRequest(headers, NULL, &response, 819 rejected_send_stream->SendRequest(headers, NULL, &response,
805 &callback_)); 820 callback_.callback()));
806 821
807 rejected_read_stream->Close(true); 822 rejected_read_stream->Close(true);
808 rejected_send_stream->Close(true); 823 rejected_send_stream->Close(true);
809 } 824 }
810 825
811 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) { 826 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) {
812 MockWrite writes[] = { 827 MockWrite writes[] = {
813 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 828 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
814 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 829 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
815 }; 830 };
816 MockRead reads[] = { 831 MockRead reads[] = {
817 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 832 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"),
818 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 833 MockRead(false, 3, "Content-Length: 7\r\n\r\n"),
819 MockRead(false, 4, "ok.html"), 834 MockRead(false, 4, "ok.html"),
820 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5), 835 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5),
821 }; 836 };
822 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 837 Initialize(reads, arraysize(reads), writes, arraysize(writes));
823 838
824 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 839 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
825 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 840 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
826 841
827 HttpRequestHeaders headers; 842 HttpRequestHeaders headers;
828 HttpResponseInfo response; 843 HttpResponseInfo response;
829 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); 844 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
845 callback_.callback()));
830 EXPECT_EQ(OK, evicted_stream->SendRequest( 846 EXPECT_EQ(OK, evicted_stream->SendRequest(
831 headers, NULL, &response, &callback_)); 847 headers, NULL, &response, callback_.callback()));
832 848
833 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_)); 849 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
834 ExpectResponse("ok.html", ok_stream, false); 850 ExpectResponse("ok.html", ok_stream, false);
835 851
836 TestOldCompletionCallback evicted_callback; 852 TestCompletionCallback evicted_callback;
837 EXPECT_EQ(ERR_IO_PENDING, 853 EXPECT_EQ(ERR_IO_PENDING,
838 evicted_stream->ReadResponseHeaders(&evicted_callback)); 854 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
839 855
840 ok_stream->Close(false); 856 ok_stream->Close(false);
841 857
842 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 858 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
843 evicted_stream->Close(false); 859 evicted_stream->Close(false);
844 } 860 }
845 861
846 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) { 862 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) {
847 MockWrite writes[] = { 863 MockWrite writes[] = {
848 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 864 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
849 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 865 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
850 }; 866 };
851 MockRead reads[] = { 867 MockRead reads[] = {
852 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 868 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"),
853 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 869 MockRead(false, 3, "Content-Length: 7\r\n\r\n"),
854 MockRead(false, 4, "ok.html"), 870 MockRead(false, 4, "ok.html"),
855 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5), 871 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5),
856 }; 872 };
857 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 873 Initialize(reads, arraysize(reads), writes, arraysize(writes));
858 874
859 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 875 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
860 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 876 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
861 877
862 HttpRequestHeaders headers; 878 HttpRequestHeaders headers;
863 HttpResponseInfo response; 879 HttpResponseInfo response;
864 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); 880 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
881 callback_.callback()));
865 EXPECT_EQ(OK, evicted_stream->SendRequest( 882 EXPECT_EQ(OK, evicted_stream->SendRequest(
866 headers, NULL, &response, &callback_)); 883 headers, NULL, &response, callback_.callback()));
867 884
868 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_)); 885 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
869 ExpectResponse("ok.html", ok_stream, false); 886 ExpectResponse("ok.html", ok_stream, false);
870 887
871 TestOldCompletionCallback evicted_callback; 888 TestCompletionCallback evicted_callback;
872 EXPECT_EQ(ERR_IO_PENDING, 889 EXPECT_EQ(ERR_IO_PENDING,
873 evicted_stream->ReadResponseHeaders(&evicted_callback)); 890 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
874 891
875 ok_stream->Close(false); 892 ok_stream->Close(false);
876 evicted_stream->Close(false); 893 evicted_stream->Close(false);
877 } 894 }
878 895
879 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) { 896 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) {
880 MockWrite writes[] = { 897 MockWrite writes[] = {
881 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 898 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
882 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 899 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
883 }; 900 };
884 MockRead reads[] = { 901 MockRead reads[] = {
885 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 902 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"),
886 MockRead(false, 3, "Content-Length: 7\r\n\r\n"), 903 MockRead(false, 3, "Content-Length: 7\r\n\r\n"),
887 MockRead(false, 4, "ok.html"), 904 MockRead(false, 4, "ok.html"),
888 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5), 905 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 5),
889 }; 906 };
890 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 907 Initialize(reads, arraysize(reads), writes, arraysize(writes));
891 908
892 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 909 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
893 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 910 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
894 911
895 HttpRequestHeaders headers; 912 HttpRequestHeaders headers;
896 HttpResponseInfo response; 913 HttpResponseInfo response;
897 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); 914 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
915 callback_.callback()));
898 EXPECT_EQ(OK, evicted_stream->SendRequest( 916 EXPECT_EQ(OK, evicted_stream->SendRequest(
899 headers, NULL, &response, &callback_)); 917 headers, NULL, &response, callback_.callback()));
900 918
901 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_)); 919 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
902 ExpectResponse("ok.html", ok_stream, false); 920 ExpectResponse("ok.html", ok_stream, false);
903 921
904 TestOldCompletionCallback evicted_callback; 922 TestCompletionCallback evicted_callback;
905 EXPECT_EQ(ERR_IO_PENDING, 923 EXPECT_EQ(ERR_IO_PENDING,
906 evicted_stream->ReadResponseHeaders(&evicted_callback)); 924 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
907 925
908 ok_stream->Close(false); 926 ok_stream->Close(false);
909 927
910 // The posted tasks should be: 928 // The posted tasks should be:
911 // 1. DoReadHeadersLoop, which will post: 929 // 1. DoReadHeadersLoop, which will post:
912 // 2. InvokeUserCallback 930 // 2. InvokeUserCallback
913 SuddenCloseObserver observer(evicted_stream.get(), 2); 931 SuddenCloseObserver observer(evicted_stream.get(), 2);
914 MessageLoop::current()->AddTaskObserver(&observer); 932 MessageLoop::current()->AddTaskObserver(&observer);
915 MessageLoop::current()->RunAllPending(); 933 MessageLoop::current()->RunAllPending();
916 EXPECT_FALSE(evicted_callback.have_result()); 934 EXPECT_FALSE(evicted_callback.have_result());
917 } 935 }
918 936
919 class StreamDeleter { 937 class StreamDeleter {
920 public: 938 public:
921 StreamDeleter(HttpStream* stream) : 939 StreamDeleter(HttpStream* stream) :
922 stream_(stream), 940 stream_(stream),
923 ALLOW_THIS_IN_INITIALIZER_LIST( 941 ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
924 callback_(this, &StreamDeleter::OnIOComplete)) { 942 base::Bind(&StreamDeleter::OnIOComplete, base::Unretained(this)))) {
925 } 943 }
926 944
927 OldCompletionCallbackImpl<StreamDeleter>* callback() { return &callback_; } 945 const CompletionCallback& callback() { return callback_; }
928 946
929 private: 947 private:
930 void OnIOComplete(int result) { 948 void OnIOComplete(int result) {
931 delete stream_; 949 delete stream_;
932 } 950 }
933 951
934 HttpStream* stream_; 952 HttpStream* stream_;
935 OldCompletionCallbackImpl<StreamDeleter> callback_; 953 CompletionCallback callback_;
936 }; 954 };
937 955
938 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) { 956 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) {
939 MockWrite writes[] = { 957 MockWrite writes[] = {
940 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 958 MockWrite(true, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
941 }; 959 };
942 Initialize(NULL, 0, writes, arraysize(writes)); 960 Initialize(NULL, 0, writes, arraysize(writes));
943 961
944 HttpStream* stream(NewTestStream("ok.html")); 962 HttpStream* stream(NewTestStream("ok.html"));
945 963
(...skipping 12 matching lines...) Expand all
958 MockRead reads[] = { 976 MockRead reads[] = {
959 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 977 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
960 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 978 MockRead(true, 2, "Content-Length: 7\r\n\r\n"),
961 }; 979 };
962 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 980 Initialize(reads, arraysize(reads), writes, arraysize(writes));
963 981
964 HttpStream* stream(NewTestStream("ok.html")); 982 HttpStream* stream(NewTestStream("ok.html"));
965 983
966 HttpRequestHeaders headers; 984 HttpRequestHeaders headers;
967 HttpResponseInfo response; 985 HttpResponseInfo response;
968 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_)); 986 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
987 callback_.callback()));
969 988
970 StreamDeleter deleter(stream); 989 StreamDeleter deleter(stream);
971 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback())); 990 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback()));
972 data_->RunFor(1); 991 data_->RunFor(1);
973 } 992 }
974 993
975 TEST_F(HttpPipelinedConnectionImplTest, 994 TEST_F(HttpPipelinedConnectionImplTest,
976 CloseCalledDuringReadCallbackWithPendingRead) { 995 CloseCalledDuringReadCallbackWithPendingRead) {
977 MockWrite writes[] = { 996 MockWrite writes[] = {
978 MockWrite(false, 0, "GET /failed.html HTTP/1.1\r\n\r\n"), 997 MockWrite(false, 0, "GET /failed.html HTTP/1.1\r\n\r\n"),
979 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 998 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
980 }; 999 };
981 MockRead reads[] = { 1000 MockRead reads[] = {
982 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 1001 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"),
983 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 1002 MockRead(true, 3, "Content-Length: 7\r\n\r\n"),
984 }; 1003 };
985 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1004 Initialize(reads, arraysize(reads), writes, arraysize(writes));
986 1005
987 HttpStream* failed_stream(NewTestStream("failed.html")); 1006 HttpStream* failed_stream(NewTestStream("failed.html"));
988 HttpStream* evicted_stream(NewTestStream("evicted.html")); 1007 HttpStream* evicted_stream(NewTestStream("evicted.html"));
989 1008
990 HttpRequestHeaders headers; 1009 HttpRequestHeaders headers;
991 HttpResponseInfo response; 1010 HttpResponseInfo response;
992 EXPECT_EQ(OK, 1011 EXPECT_EQ(OK, failed_stream->SendRequest(headers, NULL, &response,
993 failed_stream->SendRequest(headers, NULL, &response, &callback_)); 1012 callback_.callback()));
994 EXPECT_EQ(OK, 1013 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
995 evicted_stream->SendRequest(headers, NULL, &response, &callback_)); 1014 callback_.callback()));
996 1015
997 StreamDeleter failed_deleter(failed_stream); 1016 StreamDeleter failed_deleter(failed_stream);
998 EXPECT_EQ(ERR_IO_PENDING, 1017 EXPECT_EQ(ERR_IO_PENDING,
999 failed_stream->ReadResponseHeaders(failed_deleter.callback())); 1018 failed_stream->ReadResponseHeaders(failed_deleter.callback()));
1000 StreamDeleter evicted_deleter(evicted_stream); 1019 StreamDeleter evicted_deleter(evicted_stream);
1001 EXPECT_EQ(ERR_IO_PENDING, 1020 EXPECT_EQ(ERR_IO_PENDING,
1002 evicted_stream->ReadResponseHeaders(evicted_deleter.callback())); 1021 evicted_stream->ReadResponseHeaders(evicted_deleter.callback()));
1003 data_->RunFor(1); 1022 data_->RunFor(1);
1004 } 1023 }
1005 1024
1006 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) { 1025 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) {
1007 MockWrite writes[] = { 1026 MockWrite writes[] = {
1008 MockWrite(false, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"), 1027 MockWrite(false, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"),
1009 MockWrite(false, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"), 1028 MockWrite(false, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"),
1010 }; 1029 };
1011 MockRead reads[] = { 1030 MockRead reads[] = {
1012 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"), 1031 MockRead(false, 2, "HTTP/1.1 200 OK\r\n"),
1013 MockRead(true, 3, "Content-Length: 7\r\n\r\n"), 1032 MockRead(true, 3, "Content-Length: 7\r\n\r\n"),
1014 }; 1033 };
1015 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1034 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1016 1035
1017 scoped_ptr<HttpStream> deleter_stream(NewTestStream("deleter.html")); 1036 scoped_ptr<HttpStream> deleter_stream(NewTestStream("deleter.html"));
1018 HttpStream* deleted_stream(NewTestStream("deleted.html")); 1037 HttpStream* deleted_stream(NewTestStream("deleted.html"));
1019 1038
1020 HttpRequestHeaders headers; 1039 HttpRequestHeaders headers;
1021 HttpResponseInfo response; 1040 HttpResponseInfo response;
1022 EXPECT_EQ(OK, 1041 EXPECT_EQ(OK, deleter_stream->SendRequest(headers, NULL, &response,
1023 deleter_stream->SendRequest(headers, NULL, &response, &callback_)); 1042 callback_.callback()));
1024 EXPECT_EQ(OK, 1043 EXPECT_EQ(OK, deleted_stream->SendRequest(headers, NULL, &response,
1025 deleted_stream->SendRequest(headers, NULL, &response, &callback_)); 1044 callback_.callback()));
1026 1045
1027 StreamDeleter deleter(deleted_stream); 1046 StreamDeleter deleter(deleted_stream);
1028 EXPECT_EQ(ERR_IO_PENDING, 1047 EXPECT_EQ(ERR_IO_PENDING,
1029 deleter_stream->ReadResponseHeaders(deleter.callback())); 1048 deleter_stream->ReadResponseHeaders(deleter.callback()));
1030 EXPECT_EQ(ERR_IO_PENDING, deleted_stream->ReadResponseHeaders(&callback_)); 1049 EXPECT_EQ(ERR_IO_PENDING,
1050 deleted_stream->ReadResponseHeaders(callback_.callback()));
1031 data_->RunFor(1); 1051 data_->RunFor(1);
1032 } 1052 }
1033 1053
1034 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) { 1054 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) {
1035 MockWrite writes[] = { 1055 MockWrite writes[] = {
1036 MockWrite(true, 0, "GET /close.html HTTP/1.1\r\n\r\n"), 1056 MockWrite(true, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1037 MockWrite(true, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"), 1057 MockWrite(true, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1038 }; 1058 };
1039 Initialize(NULL, 0, writes, arraysize(writes)); 1059 Initialize(NULL, 0, writes, arraysize(writes));
1040 1060
1041 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); 1061 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1042 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); 1062 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1043 1063
1044 scoped_ptr<TestOldCompletionCallback> close_callback( 1064 scoped_ptr<TestCompletionCallback> close_callback(
1045 new TestOldCompletionCallback); 1065 new TestCompletionCallback);
1046 HttpRequestHeaders headers; 1066 HttpRequestHeaders headers;
1047 HttpResponseInfo response; 1067 HttpResponseInfo response;
1048 EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest( 1068 EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest(
1049 headers, NULL, &response, close_callback.get())); 1069 headers, NULL, &response, close_callback->callback()));
1050 1070
1051 data_->RunFor(1); 1071 data_->RunFor(1);
1052 EXPECT_FALSE(close_callback->have_result()); 1072 EXPECT_FALSE(close_callback->have_result());
1053 1073
1054 close_stream->Close(false); 1074 close_stream->Close(false);
1055 close_stream.reset(); 1075 close_stream.reset();
1056 close_callback.reset(); 1076 close_callback.reset();
1057 1077
1058 MessageLoop::current()->RunAllPending(); 1078 MessageLoop::current()->RunAllPending();
1059 } 1079 }
1060 1080
1061 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) { 1081 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
1062 MockWrite writes[] = { 1082 MockWrite writes[] = {
1063 MockWrite(false, 0, "GET /close.html HTTP/1.1\r\n\r\n"), 1083 MockWrite(false, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1064 MockWrite(false, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"), 1084 MockWrite(false, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1065 }; 1085 };
1066 MockRead reads[] = { 1086 MockRead reads[] = {
1067 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), 1087 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
1068 MockRead(true, 2, "Content-Length: 7\r\n\r\n"), 1088 MockRead(true, 2, "Content-Length: 7\r\n\r\n"),
1069 }; 1089 };
1070 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1090 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1071 1091
1072 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); 1092 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1073 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); 1093 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1074 1094
1075 HttpRequestHeaders headers; 1095 HttpRequestHeaders headers;
1076 HttpResponseInfo response; 1096 HttpResponseInfo response;
1077 EXPECT_EQ(OK, 1097 EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response,
1078 close_stream->SendRequest(headers, NULL, &response, &callback_)); 1098 callback_.callback()));
1079 1099
1080 scoped_ptr<TestOldCompletionCallback> close_callback( 1100 scoped_ptr<TestCompletionCallback> close_callback(
1081 new TestOldCompletionCallback); 1101 new TestCompletionCallback);
1082 EXPECT_EQ(ERR_IO_PENDING, 1102 EXPECT_EQ(ERR_IO_PENDING,
1083 close_stream->ReadResponseHeaders(close_callback.get())); 1103 close_stream->ReadResponseHeaders(close_callback->callback()));
1084 1104
1085 data_->RunFor(1); 1105 data_->RunFor(1);
1086 EXPECT_FALSE(close_callback->have_result()); 1106 EXPECT_FALSE(close_callback->have_result());
1087 1107
1088 close_stream->Close(false); 1108 close_stream->Close(false);
1089 close_stream.reset(); 1109 close_stream.reset();
1090 close_callback.reset(); 1110 close_callback.reset();
1091 1111
1092 MessageLoop::current()->RunAllPending(); 1112 MessageLoop::current()->RunAllPending();
1093 } 1113 }
(...skipping 13 matching lines...) Expand all
1107 "Content-Length: 7\r\n\r\n" 1127 "Content-Length: 7\r\n\r\n"
1108 "ok.html"), 1128 "ok.html"),
1109 }; 1129 };
1110 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1130 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1111 1131
1112 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1132 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1113 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1133 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1114 1134
1115 HttpRequestHeaders headers1; 1135 HttpRequestHeaders headers1;
1116 HttpResponseInfo response1; 1136 HttpResponseInfo response1;
1117 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 1137 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1138 callback_.callback()));
1118 HttpRequestHeaders headers2; 1139 HttpRequestHeaders headers2;
1119 HttpResponseInfo response2; 1140 HttpResponseInfo response2;
1120 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 1141 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1142 callback_.callback()));
1121 1143
1122 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 1144 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1123 stream1.release()->Drain(NULL); 1145 stream1.release()->Drain(NULL);
1124 1146
1125 EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_)); 1147 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
1126 ExpectResponse("ok.html", stream2, false); 1148 ExpectResponse("ok.html", stream2, false);
1127 stream2->Close(false); 1149 stream2->Close(false);
1128 } 1150 }
1129 1151
1130 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) { 1152 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) {
1131 MockWrite writes[] = { 1153 MockWrite writes[] = {
1132 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1154 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1133 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1155 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1134 }; 1156 };
1135 MockRead reads[] = { 1157 MockRead reads[] = {
1136 MockRead(false, 2, 1158 MockRead(false, 2,
1137 "HTTP/1.1 302 OK\r\n\r\n" 1159 "HTTP/1.1 302 OK\r\n\r\n"
1138 "redirect"), 1160 "redirect"),
1139 }; 1161 };
1140 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1162 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1141 1163
1142 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1164 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1143 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1165 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1144 1166
1145 HttpRequestHeaders headers1; 1167 HttpRequestHeaders headers1;
1146 HttpResponseInfo response1; 1168 HttpResponseInfo response1;
1147 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 1169 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1170 callback_.callback()));
1148 HttpRequestHeaders headers2; 1171 HttpRequestHeaders headers2;
1149 HttpResponseInfo response2; 1172 HttpResponseInfo response2;
1150 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 1173 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1174 callback_.callback()));
1151 1175
1152 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 1176 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1153 stream1.release()->Drain(NULL); 1177 stream1.release()->Drain(NULL);
1154 1178
1155 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); 1179 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1180 stream2->ReadResponseHeaders(callback_.callback()));
1156 stream2->Close(false); 1181 stream2->Close(false);
1157 } 1182 }
1158 1183
1159 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) { 1184 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) {
1160 MockWrite writes[] = { 1185 MockWrite writes[] = {
1161 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1186 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1162 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1187 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1163 }; 1188 };
1164 MockRead reads[] = { 1189 MockRead reads[] = {
1165 MockRead(false, 2, 1190 MockRead(false, 2,
1166 "HTTP/1.1 302 OK\r\n" 1191 "HTTP/1.1 302 OK\r\n"
1167 "Content-Length: 8\r\n\r\n"), 1192 "Content-Length: 8\r\n\r\n"),
1168 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 3), 1193 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 3),
1169 }; 1194 };
1170 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1195 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1171 1196
1172 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1197 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1173 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1198 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1174 1199
1175 HttpRequestHeaders headers1; 1200 HttpRequestHeaders headers1;
1176 HttpResponseInfo response1; 1201 HttpResponseInfo response1;
1177 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 1202 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1203 callback_.callback()));
1178 HttpRequestHeaders headers2; 1204 HttpRequestHeaders headers2;
1179 HttpResponseInfo response2; 1205 HttpResponseInfo response2;
1180 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 1206 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1207 callback_.callback()));
1181 1208
1182 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 1209 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1183 stream1.release()->Drain(NULL); 1210 stream1.release()->Drain(NULL);
1184 1211
1185 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); 1212 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1213 stream2->ReadResponseHeaders(callback_.callback()));
1186 stream2->Close(false); 1214 stream2->Close(false);
1187 } 1215 }
1188 1216
1189 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) { 1217 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) {
1190 MockWrite writes[] = { 1218 MockWrite writes[] = {
1191 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), 1219 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"),
1192 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), 1220 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"),
1193 }; 1221 };
1194 MockRead reads[] = { 1222 MockRead reads[] = {
1195 MockRead(false, 2, 1223 MockRead(false, 2,
1196 "HTTP/1.1 302 OK\r\n" 1224 "HTTP/1.1 302 OK\r\n"
1197 "Transfer-Encoding: chunked\r\n\r\n"), 1225 "Transfer-Encoding: chunked\r\n\r\n"),
1198 MockRead(false, 3, 1226 MockRead(false, 3,
1199 "jibberish"), 1227 "jibberish"),
1200 }; 1228 };
1201 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1229 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1202 1230
1203 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); 1231 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1204 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); 1232 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1205 1233
1206 HttpRequestHeaders headers1; 1234 HttpRequestHeaders headers1;
1207 HttpResponseInfo response1; 1235 HttpResponseInfo response1;
1208 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); 1236 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
1237 callback_.callback()));
1209 HttpRequestHeaders headers2; 1238 HttpRequestHeaders headers2;
1210 HttpResponseInfo response2; 1239 HttpResponseInfo response2;
1211 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); 1240 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
1241 callback_.callback()));
1212 1242
1213 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); 1243 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
1214 stream1.release()->Drain(NULL); 1244 stream1.release()->Drain(NULL);
1215 1245
1216 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); 1246 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1247 stream2->ReadResponseHeaders(callback_.callback()));
1217 stream2->Close(false); 1248 stream2->Close(false);
1218 } 1249 }
1219 1250
1220 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) { 1251 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
1221 MockWrite writes[] = { 1252 MockWrite writes[] = {
1222 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1253 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1223 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), 1254 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"),
1224 MockWrite(false, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"), 1255 MockWrite(false, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"),
1225 }; 1256 };
1226 MockRead reads[] = { 1257 MockRead reads[] = {
1227 MockRead(true, 3, "HTTP/1.1 200 OK\r\n\r\n"), 1258 MockRead(true, 3, "HTTP/1.1 200 OK\r\n\r\n"),
1228 MockRead(false, 4, "ok.html"), 1259 MockRead(false, 4, "ok.html"),
1229 MockRead(false, OK, 5), 1260 MockRead(false, OK, 5),
1230 }; 1261 };
1231 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1262 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1232 1263
1233 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); 1264 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html"));
1234 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); 1265 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html"));
1235 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); 1266 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html"));
1236 1267
1237 HttpRequestHeaders headers; 1268 HttpRequestHeaders headers;
1238 HttpResponseInfo response; 1269 HttpResponseInfo response;
1239 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); 1270 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
1271 callback_.callback()));
1240 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response, 1272 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
1241 &callback_)); 1273 callback_.callback()));
1242 EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response, 1274 EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response,
1243 &callback_)); 1275 callback_.callback()));
1244 1276
1245 TestOldCompletionCallback ok_callback; 1277 TestCompletionCallback ok_callback;
1246 EXPECT_EQ(ERR_IO_PENDING, ok_stream->ReadResponseHeaders(&ok_callback)); 1278 EXPECT_EQ(ERR_IO_PENDING,
1279 ok_stream->ReadResponseHeaders(ok_callback.callback()));
1247 1280
1248 TestOldCompletionCallback evicted_callback; 1281 TestCompletionCallback evicted_callback;
1249 EXPECT_EQ(ERR_IO_PENDING, 1282 EXPECT_EQ(ERR_IO_PENDING,
1250 evicted_stream->ReadResponseHeaders(&evicted_callback)); 1283 evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
1251 1284
1252 data_->RunFor(1); 1285 data_->RunFor(1);
1253 EXPECT_LE(OK, ok_callback.WaitForResult()); 1286 EXPECT_LE(OK, ok_callback.WaitForResult());
1254 data_->StopAfter(10); 1287 data_->StopAfter(10);
1255 1288
1256 ExpectResponse("ok.html", ok_stream, false); 1289 ExpectResponse("ok.html", ok_stream, false);
1257 ok_stream->Close(false); 1290 ok_stream->Close(false);
1258 1291
1259 EXPECT_EQ(ERR_PIPELINE_EVICTION, 1292 EXPECT_EQ(ERR_PIPELINE_EVICTION,
1260 rejected_stream->ReadResponseHeaders(&callback_)); 1293 rejected_stream->ReadResponseHeaders(callback_.callback()));
1261 rejected_stream->Close(true); 1294 rejected_stream->Close(true);
1262 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); 1295 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
1263 evicted_stream->Close(true); 1296 evicted_stream->Close(true);
1264 } 1297 }
1265 1298
1266 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) { 1299 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) {
1267 MockWrite writes[] = { 1300 MockWrite writes[] = {
1268 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1301 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1269 }; 1302 };
1270 MockRead reads[] = { 1303 MockRead reads[] = {
1271 MockRead(false, ERR_FAILED, 1), 1304 MockRead(false, ERR_FAILED, 1),
1272 }; 1305 };
1273 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1306 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1274 1307
1275 EXPECT_CALL(delegate_, 1308 EXPECT_CALL(delegate_,
1276 OnPipelineFeedback( 1309 OnPipelineFeedback(
1277 pipeline_.get(), 1310 pipeline_.get(),
1278 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR)) 1311 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR))
1279 .Times(1); 1312 .Times(1);
1280 1313
1281 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1314 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1282 HttpRequestHeaders headers; 1315 HttpRequestHeaders headers;
1283 HttpResponseInfo response; 1316 HttpResponseInfo response;
1284 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_)); 1317 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
1285 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(&callback_)); 1318 callback_.callback()));
1319 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback()));
1286 } 1320 }
1287 1321
1288 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) { 1322 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) {
1289 MockWrite writes[] = { 1323 MockWrite writes[] = {
1290 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1324 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1291 }; 1325 };
1292 MockRead reads[] = { 1326 MockRead reads[] = {
1293 MockRead(false, 1, "HTTP/1.0 200 OK\r\n"), 1327 MockRead(false, 1, "HTTP/1.0 200 OK\r\n"),
1294 MockRead(false, 2, "Content-Length: 7\r\n"), 1328 MockRead(false, 2, "Content-Length: 7\r\n"),
1295 MockRead(false, 3, "Connection: keep-alive\r\n\r\n"), 1329 MockRead(false, 3, "Connection: keep-alive\r\n\r\n"),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1387 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1354 }; 1388 };
1355 Initialize(NULL, 0, writes, arraysize(writes)); 1389 Initialize(NULL, 0, writes, arraysize(writes));
1356 1390
1357 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1391 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1358 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1392 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1359 1393
1360 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1394 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1361 HttpRequestHeaders headers; 1395 HttpRequestHeaders headers;
1362 HttpResponseInfo response; 1396 HttpResponseInfo response;
1363 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_)); 1397 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
1398 callback_.callback()));
1364 1399
1365 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1400 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1366 MessageLoop::current()->RunAllPending(); 1401 MessageLoop::current()->RunAllPending();
1367 1402
1368 stream->Close(false); 1403 stream->Close(false);
1369 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1404 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1370 stream.reset(NULL); 1405 stream.reset(NULL);
1371 } 1406 }
1372 1407
1373 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacityWithoutSend) { 1408 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacityWithoutSend) {
1374 MockWrite writes[] = { 1409 MockWrite writes[] = {
1375 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1410 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1376 }; 1411 };
1377 Initialize(NULL, 0, writes, arraysize(writes)); 1412 Initialize(NULL, 0, writes, arraysize(writes));
1378 1413
1379 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1414 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1380 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1415 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1381 1416
1382 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1417 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1383 MessageLoop::current()->RunAllPending(); 1418 MessageLoop::current()->RunAllPending();
1384 1419
1385 stream->Close(false); 1420 stream->Close(false);
1386 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1421 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1387 stream.reset(NULL); 1422 stream.reset(NULL);
1388 } 1423 }
1389 1424
1390 } // anonymous namespace 1425 } // anonymous namespace
1391 1426
1392 } // namespace net 1427 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698