| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 43 | 43 |
| 44 using testing::_; | 44 using testing::_; |
| 45 using testing::AnyNumber; | 45 using testing::AnyNumber; |
| 46 using testing::Return; | 46 using testing::Return; |
| 47 | 47 |
| 48 namespace net { | 48 namespace net { |
| 49 namespace test { | 49 namespace test { |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 const char kUploadData[] = "hello world!"; | 52 const char kUploadData[] = "Really nifty data!"; |
| 53 const char kServerHostname[] = "www.google.com"; | 53 const char kServerHostname[] = "www.google.com"; |
| 54 const uint16 kServerPort = 80; | 54 const uint16 kServerPort = 80; |
| 55 | 55 |
| 56 class TestQuicConnection : public QuicConnection { | 56 class TestQuicConnection : public QuicConnection { |
| 57 public: | 57 public: |
| 58 TestQuicConnection(const QuicVersionVector& versions, | 58 TestQuicConnection(const QuicVersionVector& versions, |
| 59 QuicConnectionId connection_id, | 59 QuicConnectionId connection_id, |
| 60 IPEndPoint address, | 60 IPEndPoint address, |
| 61 QuicConnectionHelper* helper, | 61 QuicConnectionHelper* helper, |
| 62 QuicPacketWriter* writer) | 62 QuicPacketWriter* writer) |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 519 |
| 520 // Since the body has already arrived, this should return immediately. | 520 // Since the body has already arrived, this should return immediately. |
| 521 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), | 521 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 522 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | 522 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 523 callback_.callback())); | 523 callback_.callback())); |
| 524 | 524 |
| 525 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 525 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 526 EXPECT_TRUE(AtEof()); | 526 EXPECT_TRUE(AtEof()); |
| 527 } | 527 } |
| 528 | 528 |
| 529 TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithFinalEmptyDataPacket) { |
| 530 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 531 size_t chunk_size = strlen(kUploadData); |
| 532 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
| 533 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 534 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, "")); |
| 535 AddWrite(ConstructAckPacket(4, 3, 1)); |
| 536 Initialize(); |
| 537 |
| 538 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); |
| 539 upload_data_stream.AppendChunk(kUploadData, chunk_size, false); |
| 540 |
| 541 request_.method = "POST"; |
| 542 request_.url = GURL("http://www.google.com/"); |
| 543 request_.upload_data_stream = &upload_data_stream; |
| 544 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
| 545 |
| 546 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 547 net_log_, callback_.callback())); |
| 548 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| 549 callback_.callback())); |
| 550 |
| 551 upload_data_stream.AppendChunk(NULL, 0, true); |
| 552 |
| 553 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
| 554 |
| 555 // Send the response headers (but not the body). |
| 556 SetResponse("200 OK", std::string()); |
| 557 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
| 558 |
| 559 // Since the headers have already arrived, this should return immediately. |
| 560 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
| 561 ASSERT_TRUE(response_.headers.get()); |
| 562 EXPECT_EQ(200, response_.headers->response_code()); |
| 563 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 564 |
| 565 // Send the response body. |
| 566 const char kResponseBody[] = "Hello world!"; |
| 567 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 568 kResponseBody)); |
| 569 |
| 570 // Since the body has already arrived, this should return immediately. |
| 571 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 572 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 573 callback_.callback())); |
| 574 |
| 575 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 576 EXPECT_TRUE(AtEof()); |
| 577 } |
| 578 |
| 579 TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) { |
| 580 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 581 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
| 582 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, "")); |
| 583 AddWrite(ConstructAckPacket(3, 3, 1)); |
| 584 Initialize(); |
| 585 |
| 586 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); |
| 587 |
| 588 request_.method = "POST"; |
| 589 request_.url = GURL("http://www.google.com/"); |
| 590 request_.upload_data_stream = &upload_data_stream; |
| 591 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
| 592 |
| 593 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 594 net_log_, callback_.callback())); |
| 595 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| 596 callback_.callback())); |
| 597 |
| 598 upload_data_stream.AppendChunk(NULL, 0, true); |
| 599 |
| 600 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
| 601 |
| 602 // Send the response headers (but not the body). |
| 603 SetResponse("200 OK", std::string()); |
| 604 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
| 605 |
| 606 // Since the headers have already arrived, this should return immediately. |
| 607 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
| 608 ASSERT_TRUE(response_.headers.get()); |
| 609 EXPECT_EQ(200, response_.headers->response_code()); |
| 610 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 611 |
| 612 // Send the response body. |
| 613 const char kResponseBody[] = "Hello world!"; |
| 614 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 615 kResponseBody)); |
| 616 |
| 617 // Since the body has already arrived, this should return immediately. |
| 618 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 619 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 620 callback_.callback())); |
| 621 |
| 622 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 623 EXPECT_TRUE(AtEof()); |
| 624 } |
| 625 |
| 529 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 626 TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| 530 SetRequest("GET", "/", DEFAULT_PRIORITY); | 627 SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 531 AddWrite(ConstructRequestHeadersPacket(1, kFin)); | 628 AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
| 532 AddWrite(ConstructAckAndRstStreamPacket(2)); | 629 AddWrite(ConstructAckAndRstStreamPacket(2)); |
| 533 use_closing_stream_ = true; | 630 use_closing_stream_ = true; |
| 534 Initialize(); | 631 Initialize(); |
| 535 | 632 |
| 536 request_.method = "GET"; | 633 request_.method = "GET"; |
| 537 request_.url = GURL("http://www.google.com/"); | 634 request_.url = GURL("http://www.google.com/"); |
| 538 | 635 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 // Set Delegate to NULL and make sure EffectivePriority returns highest | 718 // Set Delegate to NULL and make sure EffectivePriority returns highest |
| 622 // priority. | 719 // priority. |
| 623 reliable_stream->SetDelegate(NULL); | 720 reliable_stream->SetDelegate(NULL); |
| 624 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, | 721 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
| 625 reliable_stream->EffectivePriority()); | 722 reliable_stream->EffectivePriority()); |
| 626 reliable_stream->SetDelegate(delegate); | 723 reliable_stream->SetDelegate(delegate); |
| 627 } | 724 } |
| 628 | 725 |
| 629 } // namespace test | 726 } // namespace test |
| 630 } // namespace net | 727 } // namespace net |
| OLD | NEW |