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_spdy_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/epoll_server/epoll_server.h" | 10 #include "net/tools/epoll_server/epoll_server.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 using testing::StrictMock; | 21 using testing::StrictMock; |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 namespace tools { | 24 namespace tools { |
25 namespace test { | 25 namespace test { |
26 namespace { | 26 namespace { |
27 | 27 |
28 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> { | 28 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> { |
29 public: | 29 public: |
30 QuicSpdyClientStreamTest() | 30 QuicSpdyClientStreamTest() |
31 : connection_(new StrictMock<MockConnection>( | 31 : connection_( |
32 false, SupportedVersions(GetParam()))), | 32 new StrictMock<MockConnection>(false, |
| 33 SupportedVersions(GetParam()))), |
33 session_(QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED), | 34 session_(QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED), |
34 DefaultQuicConfig(), | 35 DefaultQuicConfig(), |
35 connection_, | 36 connection_, |
36 &crypto_config_), | 37 &crypto_config_), |
37 body_("hello world") { | 38 body_("hello world") { |
38 crypto_config_.SetDefaults(); | 39 crypto_config_.SetDefaults(); |
39 | 40 |
40 headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok"); | 41 headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok"); |
41 headers_.ReplaceOrAppendHeader("content-length", "11"); | 42 headers_.ReplaceOrAppendHeader("content-length", "11"); |
42 | 43 |
43 headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_); | 44 headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_); |
44 | 45 |
45 // New streams rely on having the peer's flow control receive window | 46 // New streams rely on having the peer's flow control receive window |
46 // negotiated in the config. | 47 // negotiated in the config. |
47 session_.config()->SetInitialFlowControlWindowToSend( | 48 session_.config()->SetInitialFlowControlWindowToSend( |
48 kInitialFlowControlWindowForTest); | 49 kInitialFlowControlWindowForTest); |
49 stream_.reset(new QuicSpdyClientStream(3, &session_)); | 50 stream_.reset(new QuicSpdyClientStream(3, &session_)); |
50 } | 51 } |
51 | 52 |
52 StrictMock<MockConnection>* connection_; | 53 StrictMock<MockConnection>* connection_; |
53 QuicClientSession session_; | 54 QuicClientSession session_; |
54 scoped_ptr<QuicSpdyClientStream> stream_; | 55 scoped_ptr<QuicSpdyClientStream> stream_; |
55 BalsaHeaders headers_; | 56 BalsaHeaders headers_; |
56 string headers_string_; | 57 string headers_string_; |
57 string body_; | 58 string body_; |
58 QuicCryptoClientConfig crypto_config_; | 59 QuicCryptoClientConfig crypto_config_; |
59 }; | 60 }; |
60 | 61 |
61 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest, | 62 INSTANTIATE_TEST_CASE_P(Tests, |
| 63 QuicSpdyClientStreamTest, |
62 ::testing::ValuesIn(QuicSupportedVersions())); | 64 ::testing::ValuesIn(QuicSupportedVersions())); |
63 | 65 |
64 TEST_P(QuicSpdyClientStreamTest, TestFraming) { | 66 TEST_P(QuicSpdyClientStreamTest, TestFraming) { |
65 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( | 67 EXPECT_EQ( |
66 headers_string_.c_str(), headers_string_.size())); | 68 headers_string_.size(), |
67 EXPECT_EQ(body_.size(), | 69 stream_->ProcessData(headers_string_.c_str(), headers_string_.size())); |
68 stream_->ProcessData(body_.c_str(), body_.size())); | 70 EXPECT_EQ(body_.size(), stream_->ProcessData(body_.c_str(), body_.size())); |
69 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); | 71 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); |
70 EXPECT_EQ(body_, stream_->data()); | 72 EXPECT_EQ(body_, stream_->data()); |
71 } | 73 } |
72 | 74 |
73 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) { | 75 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) { |
74 string message = headers_string_ + body_; | 76 string message = headers_string_ + body_; |
75 | 77 |
76 EXPECT_EQ(message.size(), stream_->ProcessData( | 78 EXPECT_EQ(message.size(), |
77 message.c_str(), message.size())); | 79 stream_->ProcessData(message.c_str(), message.size())); |
78 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); | 80 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); |
79 EXPECT_EQ(body_, stream_->data()); | 81 EXPECT_EQ(body_, stream_->data()); |
80 } | 82 } |
81 | 83 |
82 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) { | 84 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) { |
83 string large_body = "hello world!!!!!!"; | 85 string large_body = "hello world!!!!!!"; |
84 | 86 |
85 EXPECT_EQ(headers_string_.size(), stream_->ProcessData( | 87 EXPECT_EQ( |
86 headers_string_.c_str(), headers_string_.size())); | 88 headers_string_.size(), |
| 89 stream_->ProcessData(headers_string_.c_str(), headers_string_.size())); |
87 // The headers should parse successfully. | 90 // The headers should parse successfully. |
88 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 91 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
89 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); | 92 EXPECT_EQ(200u, stream_->headers().parsed_response_code()); |
90 | 93 |
91 EXPECT_CALL(*connection_, | 94 EXPECT_CALL(*connection_, |
92 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0)); | 95 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0)); |
93 stream_->ProcessData(large_body.c_str(), large_body.size()); | 96 stream_->ProcessData(large_body.c_str(), large_body.size()); |
94 | 97 |
95 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 98 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
96 } | 99 } |
97 | 100 |
98 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) { | 101 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) { |
99 QuicStreamFrame frame(3, false, 3, MakeIOVector("asd")); | 102 QuicStreamFrame frame(3, false, 3, MakeIOVector("asd")); |
100 | 103 |
101 EXPECT_FALSE(stream_->write_side_closed()); | 104 EXPECT_FALSE(stream_->write_side_closed()); |
102 EXPECT_TRUE(stream_->OnStreamFrame(frame)); | 105 EXPECT_TRUE(stream_->OnStreamFrame(frame)); |
103 EXPECT_TRUE(stream_->write_side_closed()); | 106 EXPECT_TRUE(stream_->write_side_closed()); |
104 } | 107 } |
105 | 108 |
106 } // namespace | 109 } // namespace |
107 } // namespace test | 110 } // namespace test |
108 } // namespace tools | 111 } // namespace tools |
109 } // namespace net | 112 } // namespace net |
OLD | NEW |