OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_server_stream.h" | 5 #include "net/tools/quic/quic_spdy_server_stream.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 using testing::InSequence; | 30 using testing::InSequence; |
31 using testing::Return; | 31 using testing::Return; |
32 using testing::StrEq; | 32 using testing::StrEq; |
33 using testing::StrictMock; | 33 using testing::StrictMock; |
34 using testing::WithArgs; | 34 using testing::WithArgs; |
35 | 35 |
36 namespace net { | 36 namespace net { |
37 namespace tools { | 37 namespace tools { |
38 namespace test { | 38 namespace test { |
39 | 39 |
40 class QuicSpdyServerStreamPeer { | 40 class QuicSpdyServerStreamPeer : public QuicSpdyServerStream { |
41 public: | 41 public: |
42 static BalsaHeaders* GetMutableHeaders( | 42 QuicSpdyServerStreamPeer(QuicStreamId stream_id, QuicSession* session) |
43 QuicSpdyServerStream* stream) { | 43 : QuicSpdyServerStream(stream_id, session) { |
44 return &(stream->headers_); | 44 } |
| 45 |
| 46 using QuicSpdyServerStream::SendResponse; |
| 47 using QuicSpdyServerStream::SendErrorResponse; |
| 48 |
| 49 const string& body() { |
| 50 return body_; |
| 51 } |
| 52 |
| 53 const BalsaHeaders& headers() { |
| 54 return headers_; |
| 55 } |
| 56 |
| 57 BalsaHeaders* mutable_headers() { |
| 58 return &headers_; |
45 } | 59 } |
46 }; | 60 }; |
47 | 61 |
48 namespace { | 62 namespace { |
49 | 63 |
50 class QuicSpdyServerStreamTest : public ::testing::Test { | 64 class QuicSpdyServerStreamTest : public ::testing::Test { |
51 public: | 65 public: |
52 QuicSpdyServerStreamTest() | 66 QuicSpdyServerStreamTest() |
53 : session_(new MockConnection(1, IPEndPoint(), true), true), | 67 : session_(new MockConnection(1, IPEndPoint(), true), true), |
54 body_("hello world") { | 68 body_("hello world") { |
55 BalsaHeaders request_headers; | 69 BalsaHeaders request_headers; |
56 request_headers.SetRequestFirstlineFromStringPieces( | 70 request_headers.SetRequestFirstlineFromStringPieces( |
57 "POST", "https://www.google.com/", "HTTP/1.1"); | 71 "POST", "https://www.google.com/", "HTTP/1.1"); |
58 request_headers.ReplaceOrAppendHeader("content-length", "11"); | 72 request_headers.ReplaceOrAppendHeader("content-length", "11"); |
59 | 73 |
60 headers_string_ = SpdyUtils::SerializeRequestHeaders(request_headers); | 74 headers_string_ = SpdyUtils::SerializeRequestHeaders(request_headers); |
61 stream_.reset(new QuicSpdyServerStream(3, &session_)); | 75 stream_.reset(new QuicSpdyServerStreamPeer(3, &session_)); |
62 } | 76 } |
63 | 77 |
64 QuicConsumedData ValidateHeaders(const struct iovec* iov) { | 78 QuicConsumedData ValidateHeaders(const struct iovec* iov) { |
65 StringPiece headers = | 79 StringPiece headers = |
66 StringPiece(static_cast<const char*>(iov[0].iov_base), iov[0].iov_len); | 80 StringPiece(static_cast<const char*>(iov[0].iov_base), iov[0].iov_len); |
67 headers_string_ = SpdyUtils::SerializeResponseHeaders( | 81 headers_string_ = SpdyUtils::SerializeResponseHeaders( |
68 response_headers_); | 82 response_headers_); |
69 QuicSpdyDecompressor decompressor; | 83 QuicSpdyDecompressor decompressor; |
70 TestDecompressorVisitor visitor; | 84 TestDecompressorVisitor visitor; |
71 | 85 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 CHECK_EQ(cached_response->body(), body); | 126 CHECK_EQ(cached_response->body(), body); |
113 return; | 127 return; |
114 } | 128 } |
115 | 129 |
116 cache->AddResponse(request_headers, response_headers, body); | 130 cache->AddResponse(request_headers, response_headers, body); |
117 } | 131 } |
118 | 132 |
119 BalsaHeaders response_headers_; | 133 BalsaHeaders response_headers_; |
120 EpollServer eps_; | 134 EpollServer eps_; |
121 StrictMock<MockSession> session_; | 135 StrictMock<MockSession> session_; |
122 scoped_ptr<QuicSpdyServerStream> stream_; | 136 scoped_ptr<QuicSpdyServerStreamPeer> stream_; |
123 string headers_string_; | 137 string headers_string_; |
124 string body_; | 138 string body_; |
125 }; | 139 }; |
126 | 140 |
127 QuicConsumedData ConsumeAllData( | 141 QuicConsumedData ConsumeAllData( |
128 QuicStreamId id, | 142 QuicStreamId id, |
129 const struct iovec* iov, | 143 const struct iovec* iov, |
130 int iov_count, | 144 int iov_count, |
131 QuicStreamOffset offset, | 145 QuicStreamOffset offset, |
132 bool fin, | 146 bool fin, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 headers_string_.c_str(), headers_string_.size())); | 191 headers_string_.c_str(), headers_string_.size())); |
178 // Content length is still 11. This will register as an error and we won't | 192 // Content length is still 11. This will register as an error and we won't |
179 // accept the bytes. | 193 // accept the bytes. |
180 stream_->ProcessData(large_body.c_str(), large_body.size()); | 194 stream_->ProcessData(large_body.c_str(), large_body.size()); |
181 EXPECT_EQ(11u, stream_->headers().content_length()); | 195 EXPECT_EQ(11u, stream_->headers().content_length()); |
182 EXPECT_EQ("https://www.google.com/", stream_->headers().request_uri()); | 196 EXPECT_EQ("https://www.google.com/", stream_->headers().request_uri()); |
183 EXPECT_EQ("POST", stream_->headers().request_method()); | 197 EXPECT_EQ("POST", stream_->headers().request_method()); |
184 } | 198 } |
185 | 199 |
186 TEST_F(QuicSpdyServerStreamTest, TestSendResponse) { | 200 TEST_F(QuicSpdyServerStreamTest, TestSendResponse) { |
187 BalsaHeaders* request_headers = | 201 BalsaHeaders* request_headers = stream_->mutable_headers(); |
188 QuicSpdyServerStreamPeer::GetMutableHeaders(stream_.get()); | |
189 request_headers->SetRequestFirstlineFromStringPieces( | 202 request_headers->SetRequestFirstlineFromStringPieces( |
190 "GET", | 203 "GET", |
191 "https://www.google.com/foo", | 204 "https://www.google.com/foo", |
192 "HTTP/1.1"); | 205 "HTTP/1.1"); |
193 | 206 |
194 response_headers_.SetResponseFirstlineFromStringPieces( | 207 response_headers_.SetResponseFirstlineFromStringPieces( |
195 "HTTP/1.1", "200", "OK"); | 208 "HTTP/1.1", "200", "OK"); |
196 response_headers_.ReplaceOrAppendHeader("content-length", "3"); | 209 response_headers_.ReplaceOrAppendHeader("content-length", "3"); |
197 | 210 |
198 InSequence s; | 211 InSequence s; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 QuicStreamFrame frame( | 268 QuicStreamFrame frame( |
256 stream_->id(), true, 0, MakeIOVector(StringPiece(arr, arraysize(arr)))); | 269 stream_->id(), true, 0, MakeIOVector(StringPiece(arr, arraysize(arr)))); |
257 // Verify that we don't crash when we get a invalid headers in stream frame. | 270 // Verify that we don't crash when we get a invalid headers in stream frame. |
258 stream_->OnStreamFrame(frame); | 271 stream_->OnStreamFrame(frame); |
259 } | 272 } |
260 | 273 |
261 } // namespace | 274 } // namespace |
262 } // namespace test | 275 } // namespace test |
263 } // namespace tools | 276 } // namespace tools |
264 } // namespace net | 277 } // namespace net |
OLD | NEW |