Chromium Code Reviews| 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!"; |
|
mmenke
2014/08/21 20:52:35
Sending upload data of "hello world!" to get a res
Ryan Hamilton
2014/08/21 21:06:44
Good point.
| |
| 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 // Ack all packets in the request. | |
| 554 ProcessPacket(ConstructAckPacket(1, 0, 0)); | |
| 555 | |
| 556 // Send the response headers (but not the body). | |
| 557 SetResponse("200 OK", std::string()); | |
| 558 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); | |
| 559 | |
| 560 // Since the headers have already arrived, this should return immediately. | |
| 561 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | |
| 562 ASSERT_TRUE(response_.headers.get()); | |
| 563 EXPECT_EQ(200, response_.headers->response_code()); | |
| 564 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | |
| 565 | |
| 566 // Send the response body. | |
| 567 const char kResponseBody[] = "Hello world!"; | |
| 568 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), | |
| 569 kResponseBody)); | |
| 570 | |
| 571 // Since the body has already arrived, this should return immediately. | |
| 572 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), | |
| 573 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | |
| 574 callback_.callback())); | |
| 575 | |
| 576 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | |
| 577 EXPECT_TRUE(AtEof()); | |
| 578 } | |
| 579 | |
| 580 TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) { | |
| 581 SetRequest("POST", "/", DEFAULT_PRIORITY); | |
| 582 AddWrite(ConstructRequestHeadersPacket(1, !kFin)); | |
| 583 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, "")); | |
| 584 AddWrite(ConstructAckPacket(3, 3, 1)); | |
| 585 Initialize(); | |
| 586 | |
| 587 UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); | |
| 588 | |
| 589 request_.method = "POST"; | |
| 590 request_.url = GURL("http://www.google.com/"); | |
| 591 request_.upload_data_stream = &upload_data_stream; | |
| 592 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); | |
| 593 | |
| 594 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | |
| 595 net_log_, callback_.callback())); | |
| 596 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, | |
| 597 callback_.callback())); | |
| 598 | |
| 599 upload_data_stream.AppendChunk(NULL, 0, true); | |
| 600 | |
| 601 // Ack both packets in the request. | |
| 602 ProcessPacket(ConstructAckPacket(1, 0, 0)); | |
|
mmenke
2014/08/21 20:52:36
I really can't make sense of ConstructAckPacket's
Ryan Hamilton
2014/08/21 21:06:44
The second argument should be the sequence number
mmenke
2014/08/21 21:20:47
I tried that, but it results in a GMOCK warning, a
| |
| 603 | |
| 604 // Send the response headers (but not the body). | |
| 605 SetResponse("200 OK", std::string()); | |
| 606 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); | |
| 607 | |
| 608 // Since the headers have already arrived, this should return immediately. | |
| 609 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | |
| 610 ASSERT_TRUE(response_.headers.get()); | |
| 611 EXPECT_EQ(200, response_.headers->response_code()); | |
| 612 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | |
| 613 | |
| 614 // Send the response body. | |
| 615 const char kResponseBody[] = "Hello world!"; | |
| 616 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), | |
| 617 kResponseBody)); | |
| 618 | |
| 619 // Since the body has already arrived, this should return immediately. | |
| 620 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), | |
| 621 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | |
| 622 callback_.callback())); | |
| 623 | |
| 624 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | |
| 625 EXPECT_TRUE(AtEof()); | |
| 626 } | |
| 627 | |
| 529 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 628 TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| 530 SetRequest("GET", "/", DEFAULT_PRIORITY); | 629 SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 531 AddWrite(ConstructRequestHeadersPacket(1, kFin)); | 630 AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
| 532 AddWrite(ConstructAckAndRstStreamPacket(2)); | 631 AddWrite(ConstructAckAndRstStreamPacket(2)); |
| 533 use_closing_stream_ = true; | 632 use_closing_stream_ = true; |
| 534 Initialize(); | 633 Initialize(); |
| 535 | 634 |
| 536 request_.method = "GET"; | 635 request_.method = "GET"; |
| 537 request_.url = GURL("http://www.google.com/"); | 636 request_.url = GURL("http://www.google.com/"); |
| 538 | 637 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 // Set Delegate to NULL and make sure EffectivePriority returns highest | 720 // Set Delegate to NULL and make sure EffectivePriority returns highest |
| 622 // priority. | 721 // priority. |
| 623 reliable_stream->SetDelegate(NULL); | 722 reliable_stream->SetDelegate(NULL); |
| 624 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, | 723 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
| 625 reliable_stream->EffectivePriority()); | 724 reliable_stream->EffectivePriority()); |
| 626 reliable_stream->SetDelegate(delegate); | 725 reliable_stream->SetDelegate(delegate); |
| 627 } | 726 } |
| 628 | 727 |
| 629 } // namespace test | 728 } // namespace test |
| 630 } // namespace net | 729 } // namespace net |
| OLD | NEW |