| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tools/quic/quic_spdy_client_stream.h" | 5 #include "net/tools/quic/quic_simple_client_stream.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "net/quic/quic_utils.h" | 8 #include "net/quic/quic_utils.h" |
| 9 #include "net/quic/test_tools/quic_test_utils.h" | 9 #include "net/quic/test_tools/quic_test_utils.h" |
| 10 #include "net/tools/quic/quic_client_session.h" | 10 #include "net/spdy/spdy_http_utils.h" |
| 11 #include "net/tools/quic/quic_spdy_client_stream.h" | 11 #include "net/tools/quic/quic_simple_client_session.h" |
| 12 #include "net/tools/quic/spdy_utils.h" | 12 #include "net/tools/quic/spdy_utils.h" |
| 13 #include "net/tools/quic/test_tools/quic_test_utils.h" | 13 #include "net/tools/quic/test_tools/quic_test_utils.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using net::test::DefaultQuicConfig; | 17 using net::test::DefaultQuicConfig; |
| 18 using net::test::MockConnection; | 18 using net::test::MockConnection; |
| 19 using net::test::SupportedVersions; | 19 using net::test::SupportedVersions; |
| 20 using std::string; | 20 using std::string; |
| 21 using testing::StrictMock; | 21 using testing::StrictMock; |
| 22 using testing::TestWithParam; | 22 using testing::TestWithParam; |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 namespace tools { | 25 namespace tools { |
| 26 namespace test { | 26 namespace test { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> { | 29 class QuicSimpleClientStreamTest : public TestWithParam<QuicVersion> { |
| 30 public: | 30 public: |
| 31 QuicSpdyClientStreamTest() | 31 QuicSimpleClientStreamTest() |
| 32 : connection_( | 32 : connection_( |
| 33 new StrictMock<MockConnection>(Perspective::IS_CLIENT, | 33 new StrictMock<MockConnection>(Perspective::IS_CLIENT, |
| 34 SupportedVersions(GetParam()))), | 34 SupportedVersions(GetParam()))), |
| 35 session_(DefaultQuicConfig(), connection_), | 35 session_(DefaultQuicConfig(), connection_), |
| 36 headers_(new HttpResponseHeaders("")), |
| 36 body_("hello world") { | 37 body_("hello world") { |
| 37 session_.InitializeSession( | 38 session_.InitializeSession( |
| 38 QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED), | 39 QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED), |
| 39 &crypto_config_); | 40 &crypto_config_); |
| 40 | 41 |
| 41 headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok"); | 42 headers_->ReplaceStatusLine("HTTP/1.1 200 Ok"); |
| 42 headers_.ReplaceOrAppendHeader("content-length", "11"); | 43 headers_->AddHeader("content-length: 11"); |
| 43 | 44 |
| 44 headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_); | 45 SpdyHeaderBlock header_block; |
| 46 CreateSpdyHeadersFromHttpResponse(*headers_, SPDY3, &header_block); |
| 47 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(header_block); |
| 45 | 48 |
| 46 // New streams rely on having the peer's flow control receive window | 49 // New streams rely on having the peer's flow control receive window |
| 47 // negotiated in the config. | 50 // negotiated in the config. |
| 48 session_.config()->SetInitialStreamFlowControlWindowToSend( | 51 session_.config()->SetInitialStreamFlowControlWindowToSend( |
| 49 kInitialStreamFlowControlWindowForTest); | 52 kInitialStreamFlowControlWindowForTest); |
| 50 session_.config()->SetInitialSessionFlowControlWindowToSend( | 53 session_.config()->SetInitialSessionFlowControlWindowToSend( |
| 51 kInitialSessionFlowControlWindowForTest); | 54 kInitialSessionFlowControlWindowForTest); |
| 52 stream_.reset(new QuicSpdyClientStream(3, &session_)); | 55 stream_.reset(new QuicSimpleClientStream(3, &session_)); |
| 53 } | 56 } |
| 54 | 57 |
| 55 StrictMock<MockConnection>* connection_; | 58 StrictMock<MockConnection>* connection_; |
| 56 QuicClientSession session_; | 59 QuicSimpleClientSession session_; |
| 57 scoped_ptr<QuicSpdyClientStream> stream_; | 60 scoped_ptr<QuicSimpleClientStream> stream_; |
| 58 BalsaHeaders headers_; | 61 scoped_refptr<HttpResponseHeaders> headers_; |
| 59 string headers_string_; | 62 string headers_string_; |
| 60 string body_; | 63 string body_; |
| 61 QuicCryptoClientConfig crypto_config_; | 64 QuicCryptoClientConfig crypto_config_; |
| 62 }; | 65 }; |
| 63 | 66 |
| 64 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest, | 67 INSTANTIATE_TEST_CASE_P(Tests, QuicSimpleClientStreamTest, |
| 65 ::testing::ValuesIn(QuicSupportedVersions())); | 68 ::testing::ValuesIn(QuicSupportedVersions())); |
| 66 | 69 |
| 67 TEST_P(QuicSpdyClientStreamTest, TestFraming) { | 70 TEST_P(QuicSimpleClientStreamTest, TestFraming) { |
| 68 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( | 71 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( |
| 69 headers_string_.c_str(), headers_string_.size())); | 72 headers_string_.c_str(), headers_string_.size())); |
| 70 EXPECT_EQ(body_.size(), | 73 EXPECT_EQ(body_.size(), |
| 71 stream_->ProcessData(body_.c_str(), body_.size())); | 74 stream_->ProcessData(body_.c_str(), body_.size())); |
| 72 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); | 75 EXPECT_EQ(200, stream_->headers()->response_code()); |
| 73 EXPECT_EQ(body_, stream_->data()); | 76 EXPECT_EQ(body_, stream_->data()); |
| 74 } | 77 } |
| 75 | 78 |
| 76 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) { | 79 TEST_P(QuicSimpleClientStreamTest, TestFramingOnePacket) { |
| 77 string message = headers_string_ + body_; | 80 string message = headers_string_ + body_; |
| 78 | 81 |
| 79 EXPECT_EQ(message.size(), stream_->ProcessData( | 82 EXPECT_EQ(message.size(), stream_->ProcessData( |
| 80 message.c_str(), message.size())); | 83 message.c_str(), message.size())); |
| 81 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); | 84 EXPECT_EQ(200, stream_->headers()->response_code()); |
| 82 EXPECT_EQ(body_, stream_->data()); | 85 EXPECT_EQ(body_, stream_->data()); |
| 83 } | 86 } |
| 84 | 87 |
| 85 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) { | 88 TEST_P(QuicSimpleClientStreamTest, DISABLED_TestFramingExtraData) { |
| 86 string large_body = "hello world!!!!!!"; | 89 string large_body = "hello world!!!!!!"; |
| 87 | 90 |
| 88 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( | 91 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( |
| 89 headers_string_.c_str(), headers_string_.size())); | 92 headers_string_.c_str(), headers_string_.size())); |
| 90 // The headers should parse successfully. | 93 // The headers should parse successfully. |
| 91 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 94 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
| 92 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); | 95 EXPECT_EQ(200, stream_->headers()->response_code()); |
| 93 | 96 |
| 94 EXPECT_CALL(*connection_, | 97 EXPECT_CALL(*connection_, |
| 95 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0)); | 98 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0)); |
| 96 stream_->ProcessData(large_body.c_str(), large_body.size()); | 99 stream_->ProcessData(large_body.c_str(), large_body.size()); |
| 97 | 100 |
| 98 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 101 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
| 99 } | 102 } |
| 100 | 103 |
| 101 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) { | 104 TEST_P(QuicSimpleClientStreamTest, TestNoBidirectionalStreaming) { |
| 102 QuicStreamFrame frame(3, false, 3, MakeIOVector("asd")); | 105 QuicStreamFrame frame(3, false, 3, MakeIOVector("asd")); |
| 103 | 106 |
| 104 EXPECT_FALSE(stream_->write_side_closed()); | 107 EXPECT_FALSE(stream_->write_side_closed()); |
| 105 stream_->OnStreamFrame(frame); | 108 stream_->OnStreamFrame(frame); |
| 106 EXPECT_TRUE(stream_->write_side_closed()); | 109 EXPECT_TRUE(stream_->write_side_closed()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 } // namespace | 112 } // namespace |
| 110 } // namespace test | 113 } // namespace test |
| 111 } // namespace tools | 114 } // namespace tools |
| 112 } // namespace net | 115 } // namespace net |
| OLD | NEW |