OLD | NEW |
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/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 119 } |
120 IoMode mode; | 120 IoMode mode; |
121 QuicEncryptedPacket* packet; | 121 QuicEncryptedPacket* packet; |
122 }; | 122 }; |
123 | 123 |
124 QuicHttpStreamTest() | 124 QuicHttpStreamTest() |
125 : net_log_(BoundNetLog()), | 125 : net_log_(BoundNetLog()), |
126 use_closing_stream_(false), | 126 use_closing_stream_(false), |
127 read_buffer_(new IOBufferWithSize(4096)), | 127 read_buffer_(new IOBufferWithSize(4096)), |
128 connection_id_(2), | 128 connection_id_(2), |
129 stream_id_(GetParam() > QUIC_VERSION_12 ? 5 : 3), | 129 stream_id_(5), |
130 maker_(GetParam(), connection_id_), | 130 maker_(GetParam(), connection_id_), |
131 random_generator_(0) { | 131 random_generator_(0) { |
132 IPAddressNumber ip; | 132 IPAddressNumber ip; |
133 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 133 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
134 peer_addr_ = IPEndPoint(ip, 443); | 134 peer_addr_ = IPEndPoint(ip, 443); |
135 self_addr_ = IPEndPoint(ip, 8435); | 135 self_addr_ = IPEndPoint(ip, 8435); |
136 } | 136 } |
137 | 137 |
138 ~QuicHttpStreamTest() { | 138 ~QuicHttpStreamTest() { |
139 session_->CloseSessionOnError(ERR_ABORTED); | 139 session_->CloseSessionOnError(ERR_ABORTED); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); | 212 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); |
213 stream_.reset(use_closing_stream_ ? | 213 stream_.reset(use_closing_stream_ ? |
214 new AutoClosingStream(session_->GetWeakPtr()) : | 214 new AutoClosingStream(session_->GetWeakPtr()) : |
215 new QuicHttpStream(session_->GetWeakPtr())); | 215 new QuicHttpStream(session_->GetWeakPtr())); |
216 } | 216 } |
217 | 217 |
218 void SetRequest(const std::string& method, | 218 void SetRequest(const std::string& method, |
219 const std::string& path, | 219 const std::string& path, |
220 RequestPriority priority) { | 220 RequestPriority priority) { |
221 request_headers_ = maker_.GetRequestHeaders(method, "http", path); | 221 request_headers_ = maker_.GetRequestHeaders(method, "http", path); |
222 request_data_ = GetParam() > QUIC_VERSION_12 ? "" : | |
223 SerializeHeaderBlock(request_headers_, true, priority); | |
224 } | 222 } |
225 | 223 |
226 void SetResponse(const std::string& status, const std::string& body) { | 224 void SetResponse(const std::string& status, const std::string& body) { |
227 response_headers_ = maker_.GetResponseHeaders(status); | 225 response_headers_ = maker_.GetResponseHeaders(status); |
228 if (GetParam() > QUIC_VERSION_12) { | 226 response_data_ = body; |
229 response_data_ = body; | |
230 } else { | |
231 response_data_ = | |
232 SerializeHeaderBlock(response_headers_, false, DEFAULT_PRIORITY) + | |
233 body; | |
234 } | |
235 } | 227 } |
236 | 228 |
237 scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( | 229 scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
238 QuicPacketSequenceNumber sequence_number, | 230 QuicPacketSequenceNumber sequence_number, |
239 bool should_include_version, | 231 bool should_include_version, |
240 bool fin, | 232 bool fin, |
241 QuicStreamOffset offset, | 233 QuicStreamOffset offset, |
242 base::StringPiece data) { | 234 base::StringPiece data) { |
243 return maker_.MakeDataPacket( | 235 return maker_.MakeDataPacket( |
244 sequence_number, stream_id_, should_include_version, fin, offset, data); | 236 sequence_number, stream_id_, should_include_version, fin, offset, data); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 HttpRequestInfo request_; | 289 HttpRequestInfo request_; |
298 HttpRequestHeaders headers_; | 290 HttpRequestHeaders headers_; |
299 HttpResponseInfo response_; | 291 HttpResponseInfo response_; |
300 scoped_refptr<IOBufferWithSize> read_buffer_; | 292 scoped_refptr<IOBufferWithSize> read_buffer_; |
301 SpdyHeaderBlock request_headers_; | 293 SpdyHeaderBlock request_headers_; |
302 SpdyHeaderBlock response_headers_; | 294 SpdyHeaderBlock response_headers_; |
303 std::string request_data_; | 295 std::string request_data_; |
304 std::string response_data_; | 296 std::string response_data_; |
305 | 297 |
306 private: | 298 private: |
307 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers, | |
308 bool write_priority, | |
309 RequestPriority priority) { | |
310 QuicSpdyCompressor compressor; | |
311 if (write_priority) { | |
312 return compressor.CompressHeadersWithPriority( | |
313 ConvertRequestPriorityToQuicPriority(priority), headers); | |
314 } | |
315 return compressor.CompressHeaders(headers); | |
316 } | |
317 | |
318 const QuicConnectionId connection_id_; | 299 const QuicConnectionId connection_id_; |
319 const QuicStreamId stream_id_; | 300 const QuicStreamId stream_id_; |
320 QuicTestPacketMaker maker_; | 301 QuicTestPacketMaker maker_; |
321 IPEndPoint self_addr_; | 302 IPEndPoint self_addr_; |
322 IPEndPoint peer_addr_; | 303 IPEndPoint peer_addr_; |
323 MockRandom random_generator_; | 304 MockRandom random_generator_; |
324 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 305 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
325 scoped_ptr<StaticSocketDataProvider> socket_data_; | 306 scoped_ptr<StaticSocketDataProvider> socket_data_; |
326 std::vector<PacketToWrite> writes_; | 307 std::vector<PacketToWrite> writes_; |
327 }; | 308 }; |
(...skipping 11 matching lines...) Expand all Loading... |
339 EXPECT_TRUE(stream_->CanFindEndOfResponse()); | 320 EXPECT_TRUE(stream_->CanFindEndOfResponse()); |
340 } | 321 } |
341 | 322 |
342 TEST_P(QuicHttpStreamTest, IsConnectionReusable) { | 323 TEST_P(QuicHttpStreamTest, IsConnectionReusable) { |
343 Initialize(); | 324 Initialize(); |
344 EXPECT_FALSE(stream_->IsConnectionReusable()); | 325 EXPECT_FALSE(stream_->IsConnectionReusable()); |
345 } | 326 } |
346 | 327 |
347 TEST_P(QuicHttpStreamTest, GetRequest) { | 328 TEST_P(QuicHttpStreamTest, GetRequest) { |
348 SetRequest("GET", "/", DEFAULT_PRIORITY); | 329 SetRequest("GET", "/", DEFAULT_PRIORITY); |
349 if (GetParam() > QUIC_VERSION_12) { | 330 AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
350 AddWrite(ConstructRequestHeadersPacket(1, kFin)); | |
351 } else { | |
352 AddWrite(ConstructDataPacket(1, kIncludeVersion, kFin, 0, request_data_)); | |
353 } | |
354 Initialize(); | 331 Initialize(); |
355 | 332 |
356 request_.method = "GET"; | 333 request_.method = "GET"; |
357 request_.url = GURL("http://www.google.com/"); | 334 request_.url = GURL("http://www.google.com/"); |
358 | 335 |
359 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 336 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
360 net_log_, callback_.callback())); | 337 net_log_, callback_.callback())); |
361 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | 338 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
362 callback_.callback())); | 339 callback_.callback())); |
363 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | 340 EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
364 | 341 |
365 // Ack the request. | 342 // Ack the request. |
366 ProcessPacket(ConstructAckPacket(1, 0, 0)); | 343 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
367 | 344 |
368 EXPECT_EQ(ERR_IO_PENDING, | 345 EXPECT_EQ(ERR_IO_PENDING, |
369 stream_->ReadResponseHeaders(callback_.callback())); | 346 stream_->ReadResponseHeaders(callback_.callback())); |
370 | 347 |
371 SetResponse("404 Not Found", std::string()); | 348 SetResponse("404 Not Found", std::string()); |
372 if (GetParam() > QUIC_VERSION_12) { | 349 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
373 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); | |
374 } else { | |
375 ProcessPacket(ConstructDataPacket(2, false, kFin, 0, response_data_)); | |
376 } | |
377 | 350 |
378 // Now that the headers have been processed, the callback will return. | 351 // Now that the headers have been processed, the callback will return. |
379 EXPECT_EQ(OK, callback_.WaitForResult()); | 352 EXPECT_EQ(OK, callback_.WaitForResult()); |
380 ASSERT_TRUE(response_.headers.get()); | 353 ASSERT_TRUE(response_.headers.get()); |
381 EXPECT_EQ(404, response_.headers->response_code()); | 354 EXPECT_EQ(404, response_.headers->response_code()); |
382 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 355 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
383 | 356 |
384 // There is no body, so this should return immediately. | 357 // There is no body, so this should return immediately. |
385 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), | 358 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
386 read_buffer_->size(), | 359 read_buffer_->size(), |
387 callback_.callback())); | 360 callback_.callback())); |
388 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 361 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
389 EXPECT_TRUE(AtEof()); | 362 EXPECT_TRUE(AtEof()); |
390 } | 363 } |
391 | 364 |
392 // Regression test for http://crbug.com/288128 | 365 // Regression test for http://crbug.com/288128 |
393 TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) { | 366 TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) { |
394 SetRequest("GET", "/", DEFAULT_PRIORITY); | 367 SetRequest("GET", "/", DEFAULT_PRIORITY); |
395 if (GetParam() > QUIC_VERSION_12) { | 368 AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
396 AddWrite(ConstructRequestHeadersPacket(1, kFin)); | |
397 } else { | |
398 AddWrite(ConstructDataPacket(1, kIncludeVersion, kFin, 0, request_data_)); | |
399 } | |
400 Initialize(); | 369 Initialize(); |
401 | 370 |
402 request_.method = "GET"; | 371 request_.method = "GET"; |
403 request_.url = GURL("http://www.google.com/"); | 372 request_.url = GURL("http://www.google.com/"); |
404 | 373 |
405 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 374 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
406 net_log_, callback_.callback())); | 375 net_log_, callback_.callback())); |
407 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | 376 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
408 callback_.callback())); | 377 callback_.callback())); |
409 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | 378 EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
(...skipping 22 matching lines...) Expand all Loading... |
432 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 401 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
433 | 402 |
434 // There is no body, so this should return immediately. | 403 // There is no body, so this should return immediately. |
435 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), | 404 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
436 read_buffer_->size(), | 405 read_buffer_->size(), |
437 callback_.callback())); | 406 callback_.callback())); |
438 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 407 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
439 EXPECT_TRUE(AtEof()); | 408 EXPECT_TRUE(AtEof()); |
440 } | 409 } |
441 | 410 |
442 TEST_P(QuicHttpStreamTest, GetRequestFullResponseInSinglePacket) { | |
443 SetRequest("GET", "/", DEFAULT_PRIORITY); | |
444 AddWrite(ConstructDataPacket(1, kIncludeVersion, kFin, 0, request_data_)); | |
445 Initialize(); | |
446 | |
447 if (GetParam() > QUIC_VERSION_12) { | |
448 // we can't put the request and response into a single frame. | |
449 return; | |
450 } | |
451 | |
452 request_.method = "GET"; | |
453 request_.url = GURL("http://www.google.com/"); | |
454 | |
455 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | |
456 net_log_, callback_.callback())); | |
457 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | |
458 callback_.callback())); | |
459 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | |
460 | |
461 // Ack the request. | |
462 ProcessPacket(ConstructAckPacket(1, 0, 0)); | |
463 | |
464 EXPECT_EQ(ERR_IO_PENDING, | |
465 stream_->ReadResponseHeaders(callback_.callback())); | |
466 | |
467 // Send the response with a body. | |
468 SetResponse("200 OK", "hello world!"); | |
469 ProcessPacket(ConstructDataPacket(2, false, kFin, 0, response_data_)); | |
470 | |
471 // Now that the headers have been processed, the callback will return. | |
472 EXPECT_EQ(OK, callback_.WaitForResult()); | |
473 ASSERT_TRUE(response_.headers.get()); | |
474 EXPECT_EQ(200, response_.headers->response_code()); | |
475 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | |
476 | |
477 // There is no body, so this should return immediately. | |
478 // Since the body has already arrived, this should return immediately. | |
479 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), | |
480 read_buffer_->size(), | |
481 callback_.callback())); | |
482 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | |
483 EXPECT_TRUE(AtEof()); | |
484 } | |
485 | |
486 TEST_P(QuicHttpStreamTest, SendPostRequest) { | 411 TEST_P(QuicHttpStreamTest, SendPostRequest) { |
487 SetRequest("POST", "/", DEFAULT_PRIORITY); | 412 SetRequest("POST", "/", DEFAULT_PRIORITY); |
488 if (GetParam() > QUIC_VERSION_12) { | 413 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
489 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); | 414 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData)); |
490 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData)); | |
491 } else { | |
492 AddWrite(ConstructDataPacket(1, kIncludeVersion, !kFin, 0, request_data_)); | |
493 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, | |
494 request_data_.length(), kUploadData)); | |
495 } | |
496 AddWrite(ConstructAckPacket(3, 3, 1)); | 415 AddWrite(ConstructAckPacket(3, 3, 1)); |
497 | 416 |
498 Initialize(); | 417 Initialize(); |
499 | 418 |
500 ScopedVector<UploadElementReader> element_readers; | 419 ScopedVector<UploadElementReader> element_readers; |
501 element_readers.push_back( | 420 element_readers.push_back( |
502 new UploadBytesElementReader(kUploadData, strlen(kUploadData))); | 421 new UploadBytesElementReader(kUploadData, strlen(kUploadData))); |
503 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 422 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
504 request_.method = "POST"; | 423 request_.method = "POST"; |
505 request_.url = GURL("http://www.google.com/"); | 424 request_.url = GURL("http://www.google.com/"); |
506 request_.upload_data_stream = &upload_data_stream; | 425 request_.upload_data_stream = &upload_data_stream; |
507 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); | 426 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
508 | 427 |
509 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 428 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
510 net_log_, callback_.callback())); | 429 net_log_, callback_.callback())); |
511 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | 430 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
512 callback_.callback())); | 431 callback_.callback())); |
513 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | 432 EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
514 | 433 |
515 // Ack both packets in the request. | 434 // Ack both packets in the request. |
516 ProcessPacket(ConstructAckPacket(1, 0, 0)); | 435 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
517 | 436 |
518 // Send the response headers (but not the body). | 437 // Send the response headers (but not the body). |
519 SetResponse("200 OK", std::string()); | 438 SetResponse("200 OK", std::string()); |
520 if (GetParam() > QUIC_VERSION_12) { | 439 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
521 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); | |
522 } else { | |
523 ProcessPacket(ConstructDataPacket(2, false, !kFin, 0, response_data_)); | |
524 } | |
525 | 440 |
526 // Since the headers have already arrived, this should return immediately. | 441 // Since the headers have already arrived, this should return immediately. |
527 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | 442 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
528 ASSERT_TRUE(response_.headers.get()); | 443 ASSERT_TRUE(response_.headers.get()); |
529 EXPECT_EQ(200, response_.headers->response_code()); | 444 EXPECT_EQ(200, response_.headers->response_code()); |
530 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 445 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
531 | 446 |
532 // Send the response body. | 447 // Send the response body. |
533 const char kResponseBody[] = "Hello world!"; | 448 const char kResponseBody[] = "Hello world!"; |
534 if (GetParam() > QUIC_VERSION_12) { | 449 ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody)); |
535 ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody)); | |
536 } else { | |
537 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), | |
538 kResponseBody)); | |
539 } | |
540 // Since the body has already arrived, this should return immediately. | 450 // Since the body has already arrived, this should return immediately. |
541 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), | 451 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), |
542 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | 452 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
543 callback_.callback())); | 453 callback_.callback())); |
544 | 454 |
545 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 455 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
546 EXPECT_TRUE(AtEof()); | 456 EXPECT_TRUE(AtEof()); |
547 } | 457 } |
548 | 458 |
549 TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { | 459 TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { |
550 SetRequest("POST", "/", DEFAULT_PRIORITY); | 460 SetRequest("POST", "/", DEFAULT_PRIORITY); |
551 size_t chunk_size = strlen(kUploadData); | 461 size_t chunk_size = strlen(kUploadData); |
552 if (GetParam() > QUIC_VERSION_12) { | 462 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
553 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); | 463 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
554 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); | 464 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, |
555 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, | 465 kUploadData)); |
556 kUploadData)); | |
557 } else { | |
558 AddWrite(ConstructDataPacket(1, kIncludeVersion, !kFin, 0, request_data_)); | |
559 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, | |
560 request_data_.length(), kUploadData)); | |
561 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, | |
562 request_data_.length() + chunk_size, | |
563 kUploadData)); | |
564 } | |
565 AddWrite(ConstructAckPacket(4, 3, 1)); | 466 AddWrite(ConstructAckPacket(4, 3, 1)); |
566 Initialize(); | 467 Initialize(); |
567 | 468 |
568 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); | 469 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); |
569 upload_data_stream.AppendChunk(kUploadData, chunk_size, false); | 470 upload_data_stream.AppendChunk(kUploadData, chunk_size, false); |
570 | 471 |
571 request_.method = "POST"; | 472 request_.method = "POST"; |
572 request_.url = GURL("http://www.google.com/"); | 473 request_.url = GURL("http://www.google.com/"); |
573 request_.upload_data_stream = &upload_data_stream; | 474 request_.upload_data_stream = &upload_data_stream; |
574 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); | 475 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
575 | 476 |
576 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 477 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
577 net_log_, callback_.callback())); | 478 net_log_, callback_.callback())); |
578 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, | 479 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
579 callback_.callback())); | 480 callback_.callback())); |
580 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | 481 EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
581 | 482 |
582 upload_data_stream.AppendChunk(kUploadData, chunk_size, true); | 483 upload_data_stream.AppendChunk(kUploadData, chunk_size, true); |
583 | 484 |
584 // Ack both packets in the request. | 485 // Ack both packets in the request. |
585 ProcessPacket(ConstructAckPacket(1, 0, 0)); | 486 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
586 | 487 |
587 // Send the response headers (but not the body). | 488 // Send the response headers (but not the body). |
588 SetResponse("200 OK", std::string()); | 489 SetResponse("200 OK", std::string()); |
589 if (GetParam() > QUIC_VERSION_12) { | 490 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
590 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); | |
591 } else { | |
592 ProcessPacket(ConstructDataPacket(2, false, !kFin, 0, response_data_)); | |
593 } | |
594 | 491 |
595 // Since the headers have already arrived, this should return immediately. | 492 // Since the headers have already arrived, this should return immediately. |
596 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | 493 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
597 ASSERT_TRUE(response_.headers.get()); | 494 ASSERT_TRUE(response_.headers.get()); |
598 EXPECT_EQ(200, response_.headers->response_code()); | 495 EXPECT_EQ(200, response_.headers->response_code()); |
599 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 496 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
600 | 497 |
601 // Send the response body. | 498 // Send the response body. |
602 const char kResponseBody[] = "Hello world!"; | 499 const char kResponseBody[] = "Hello world!"; |
603 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), | 500 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
604 kResponseBody)); | 501 kResponseBody)); |
605 | 502 |
606 // Since the body has already arrived, this should return immediately. | 503 // Since the body has already arrived, this should return immediately. |
607 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), | 504 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
608 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | 505 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
609 callback_.callback())); | 506 callback_.callback())); |
610 | 507 |
611 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 508 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
612 EXPECT_TRUE(AtEof()); | 509 EXPECT_TRUE(AtEof()); |
613 } | 510 } |
614 | 511 |
615 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 512 TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
616 SetRequest("GET", "/", DEFAULT_PRIORITY); | 513 SetRequest("GET", "/", DEFAULT_PRIORITY); |
617 if (GetParam() > QUIC_VERSION_12) { | 514 AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
618 AddWrite(ConstructRequestHeadersPacket(1, kFin)); | |
619 } else { | |
620 AddWrite(ConstructDataPacket(1, kIncludeVersion, kFin, 0, request_data_)); | |
621 } | |
622 AddWrite(ConstructAckAndRstStreamPacket(2)); | 515 AddWrite(ConstructAckAndRstStreamPacket(2)); |
623 use_closing_stream_ = true; | 516 use_closing_stream_ = true; |
624 Initialize(); | 517 Initialize(); |
625 | 518 |
626 request_.method = "GET"; | 519 request_.method = "GET"; |
627 request_.url = GURL("http://www.google.com/"); | 520 request_.url = GURL("http://www.google.com/"); |
628 | 521 |
629 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 522 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
630 net_log_, callback_.callback())); | 523 net_log_, callback_.callback())); |
631 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | 524 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
632 callback_.callback())); | 525 callback_.callback())); |
633 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | 526 EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
634 | 527 |
635 // Ack the request. | 528 // Ack the request. |
636 ProcessPacket(ConstructAckPacket(1, 0, 0)); | 529 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
637 EXPECT_EQ(ERR_IO_PENDING, | 530 EXPECT_EQ(ERR_IO_PENDING, |
638 stream_->ReadResponseHeaders(callback_.callback())); | 531 stream_->ReadResponseHeaders(callback_.callback())); |
639 | 532 |
640 // Send the response with a body. | 533 // Send the response with a body. |
641 SetResponse("404 OK", "hello world!"); | 534 SetResponse("404 OK", "hello world!"); |
642 // In the course of processing this packet, the QuicHttpStream close itself. | 535 // In the course of processing this packet, the QuicHttpStream close itself. |
643 if (GetParam() > QUIC_VERSION_12) { | 536 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
644 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); | |
645 } else { | |
646 ProcessPacket(ConstructDataPacket(2, false, kFin, 0, response_data_)); | |
647 } | |
648 | 537 |
649 EXPECT_TRUE(AtEof()); | 538 EXPECT_TRUE(AtEof()); |
650 } | 539 } |
651 | 540 |
652 TEST_P(QuicHttpStreamTest, Priority) { | 541 TEST_P(QuicHttpStreamTest, Priority) { |
653 SetRequest("GET", "/", MEDIUM); | 542 SetRequest("GET", "/", MEDIUM); |
654 if (GetParam() > QUIC_VERSION_12) { | 543 AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
655 AddWrite(ConstructRequestHeadersPacket(1, kFin)); | |
656 } else { | |
657 AddWrite(ConstructDataPacket(1, kIncludeVersion, kFin, 0, request_data_)); | |
658 } | |
659 AddWrite(ConstructAckAndRstStreamPacket(2)); | 544 AddWrite(ConstructAckAndRstStreamPacket(2)); |
660 use_closing_stream_ = true; | 545 use_closing_stream_ = true; |
661 Initialize(); | 546 Initialize(); |
662 | 547 |
663 request_.method = "GET"; | 548 request_.method = "GET"; |
664 request_.url = GURL("http://www.google.com/"); | 549 request_.url = GURL("http://www.google.com/"); |
665 | 550 |
666 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, | 551 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, |
667 net_log_, callback_.callback())); | 552 net_log_, callback_.callback())); |
668 | 553 |
(...skipping 13 matching lines...) Expand all Loading... |
682 reliable_stream->EffectivePriority())); | 567 reliable_stream->EffectivePriority())); |
683 | 568 |
684 // Ack the request. | 569 // Ack the request. |
685 ProcessPacket(ConstructAckPacket(1, 0, 0)); | 570 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
686 EXPECT_EQ(ERR_IO_PENDING, | 571 EXPECT_EQ(ERR_IO_PENDING, |
687 stream_->ReadResponseHeaders(callback_.callback())); | 572 stream_->ReadResponseHeaders(callback_.callback())); |
688 | 573 |
689 // Send the response with a body. | 574 // Send the response with a body. |
690 SetResponse("404 OK", "hello world!"); | 575 SetResponse("404 OK", "hello world!"); |
691 // In the course of processing this packet, the QuicHttpStream close itself. | 576 // In the course of processing this packet, the QuicHttpStream close itself. |
692 if (GetParam() > QUIC_VERSION_12) { | 577 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
693 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); | |
694 } else { | |
695 ProcessPacket(ConstructDataPacket(2, !kIncludeVersion, kFin, 0, | |
696 response_data_)); | |
697 } | |
698 | 578 |
699 EXPECT_TRUE(AtEof()); | 579 EXPECT_TRUE(AtEof()); |
700 } | 580 } |
701 | 581 |
702 // Regression test for http://crbug.com/294870 | 582 // Regression test for http://crbug.com/294870 |
703 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { | 583 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { |
704 SetRequest("GET", "/", MEDIUM); | 584 SetRequest("GET", "/", MEDIUM); |
705 use_closing_stream_ = true; | 585 use_closing_stream_ = true; |
706 | 586 |
707 if (GetParam() > QUIC_VERSION_13) { | 587 if (GetParam() > QUIC_VERSION_13) { |
(...skipping 18 matching lines...) Expand all Loading... |
726 reliable_stream->EffectivePriority()); | 606 reliable_stream->EffectivePriority()); |
727 | 607 |
728 // Set Delegate to NULL and make sure EffectivePriority returns highest | 608 // Set Delegate to NULL and make sure EffectivePriority returns highest |
729 // priority. | 609 // priority. |
730 reliable_stream->SetDelegate(NULL); | 610 reliable_stream->SetDelegate(NULL); |
731 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, | 611 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
732 reliable_stream->EffectivePriority()); | 612 reliable_stream->EffectivePriority()); |
733 reliable_stream->SetDelegate(delegate); | 613 reliable_stream->SetDelegate(delegate); |
734 } | 614 } |
735 | 615 |
736 TEST_P(QuicHttpStreamTest, DontCompressHeadersWhenNotWritable) { | |
737 SetRequest("GET", "/", MEDIUM); | |
738 AddWrite(ConstructDataPacket(1, kIncludeVersion, kFin, 0, request_data_)); | |
739 Initialize(); | |
740 | |
741 if (GetParam() > QUIC_VERSION_12) { | |
742 // The behavior tested here is obsolete. | |
743 return; | |
744 } | |
745 request_.method = "GET"; | |
746 request_.url = GURL("http://www.google.com/"); | |
747 | |
748 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). | |
749 WillRepeatedly(Return(QuicTime::Delta::Infinite())); | |
750 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, | |
751 net_log_, callback_.callback())); | |
752 EXPECT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, | |
753 callback_.callback())); | |
754 | |
755 // Verify that the headers have not been compressed and buffered in | |
756 // the stream. | |
757 QuicReliableClientStream* reliable_stream = | |
758 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); | |
759 EXPECT_FALSE(reliable_stream->HasBufferedData()); | |
760 EXPECT_FALSE(AtEof()); | |
761 | |
762 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). | |
763 WillRepeatedly(Return(QuicTime::Delta::Zero())); | |
764 | |
765 // Data should flush out now. | |
766 connection_->OnCanWrite(); | |
767 EXPECT_FALSE(reliable_stream->HasBufferedData()); | |
768 EXPECT_TRUE(AtEof()); | |
769 } | |
770 | |
771 } // namespace test | 616 } // namespace test |
772 } // namespace net | 617 } // namespace net |
OLD | NEW |