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_simple_server_stream.h" | 5 #include "net/tools/quic/quic_simple_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_flags.h" | 10 #include "net/quic/quic_flags.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 public: | 80 public: |
81 QuicSimpleServerStreamTest() | 81 QuicSimpleServerStreamTest() |
82 : connection_( | 82 : connection_( |
83 new StrictMock<MockConnection>(&helper_, | 83 new StrictMock<MockConnection>(&helper_, |
84 Perspective::IS_SERVER, | 84 Perspective::IS_SERVER, |
85 SupportedVersions(GetParam()))), | 85 SupportedVersions(GetParam()))), |
86 session_(connection_), | 86 session_(connection_), |
87 body_("hello world") { | 87 body_("hello world") { |
88 SpdyHeaderBlock request_headers; | 88 SpdyHeaderBlock request_headers; |
89 request_headers[":host"] = ""; | 89 request_headers[":host"] = ""; |
90 request_headers[":authority"] = ""; | 90 request_headers[":authority"] = "www.google.com"; |
91 request_headers[":path"] = "/"; | 91 request_headers[":path"] = "/"; |
92 request_headers[":method"] = "POST"; | 92 request_headers[":method"] = "POST"; |
93 request_headers[":version"] = "HTTP/1.1"; | 93 request_headers[":version"] = "HTTP/1.1"; |
94 request_headers["content-length"] = "11"; | 94 request_headers["content-length"] = "11"; |
95 | 95 |
96 headers_string_ = | 96 headers_string_ = |
97 net::SpdyUtils::SerializeUncompressedHeaders(request_headers); | 97 net::SpdyUtils::SerializeUncompressedHeaders(request_headers); |
98 | 98 |
99 // New streams rely on having the peer's flow control receive window | 99 // New streams rely on having the peer's flow control receive window |
100 // negotiated in the config. | 100 // negotiated in the config. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 QuicStreamFrame(stream_->id(), /*fin=*/true, body_.size(), large_body)); | 202 QuicStreamFrame(stream_->id(), /*fin=*/true, body_.size(), large_body)); |
203 EXPECT_EQ("11", StreamHeadersValue("content-length")); | 203 EXPECT_EQ("11", StreamHeadersValue("content-length")); |
204 EXPECT_EQ("/", StreamHeadersValue(":path")); | 204 EXPECT_EQ("/", StreamHeadersValue(":path")); |
205 EXPECT_EQ("POST", StreamHeadersValue(":method")); | 205 EXPECT_EQ("POST", StreamHeadersValue(":method")); |
206 } | 206 } |
207 | 207 |
208 TEST_P(QuicSimpleServerStreamTest, SendResponseWithIllegalResponseStatus) { | 208 TEST_P(QuicSimpleServerStreamTest, SendResponseWithIllegalResponseStatus) { |
209 // Send a illegal response with response status not supported by HTTP/2. | 209 // Send a illegal response with response status not supported by HTTP/2. |
210 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); | 210 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); |
211 (*request_headers)[":path"] = "/bar"; | 211 (*request_headers)[":path"] = "/bar"; |
212 (*request_headers)[":authority"] = ""; | 212 (*request_headers)[":authority"] = "www.google.com"; |
213 (*request_headers)[":version"] = "HTTP/1.1"; | 213 (*request_headers)[":version"] = "HTTP/1.1"; |
214 (*request_headers)[":method"] = "GET"; | 214 (*request_headers)[":method"] = "GET"; |
215 | 215 |
216 response_headers_[":version"] = "HTTP/1.1"; | 216 response_headers_[":version"] = "HTTP/1.1"; |
217 // HTTP/2 only supports integer responsecode, so "200 OK" is illegal. | 217 // HTTP/2 only supports integer responsecode, so "200 OK" is illegal. |
218 response_headers_[":status"] = "200 OK"; | 218 response_headers_[":status"] = "200 OK"; |
219 response_headers_["content-length"] = "5"; | 219 response_headers_["content-length"] = "5"; |
220 string body = "Yummm"; | 220 string body = "Yummm"; |
221 QuicInMemoryCache::GetInstance()->AddResponse("", "/bar", response_headers_, | 221 QuicInMemoryCache::GetInstance()->AddResponse("www.google.com", "/bar", |
222 body); | 222 response_headers_, body); |
223 | 223 |
224 stream_->set_fin_received(true); | 224 stream_->set_fin_received(true); |
225 | 225 |
226 InSequence s; | 226 InSequence s; |
227 EXPECT_CALL(session_, WriteHeaders(stream_->id(), _, false, _, nullptr)); | 227 EXPECT_CALL(session_, WriteHeaders(stream_->id(), _, false, _, nullptr)); |
228 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 228 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
229 .Times(1) | 229 .Times(1) |
230 .WillOnce(Return(QuicConsumedData( | 230 .WillOnce(Return(QuicConsumedData( |
231 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); | 231 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); |
232 | 232 |
233 QuicSimpleServerStreamPeer::SendResponse(stream_); | 233 QuicSimpleServerStreamPeer::SendResponse(stream_); |
234 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); | 234 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); |
235 EXPECT_TRUE(stream_->reading_stopped()); | 235 EXPECT_TRUE(stream_->reading_stopped()); |
236 EXPECT_TRUE(stream_->write_side_closed()); | 236 EXPECT_TRUE(stream_->write_side_closed()); |
237 } | 237 } |
238 | 238 |
239 TEST_P(QuicSimpleServerStreamTest, SendPushResponseWith404Response) { | 239 TEST_P(QuicSimpleServerStreamTest, SendPushResponseWith404Response) { |
240 // Create a new promised stream with even id(). | 240 // Create a new promised stream with even id(). |
241 QuicSimpleServerStreamPeer* promised_stream = | 241 QuicSimpleServerStreamPeer* promised_stream = |
242 new QuicSimpleServerStreamPeer(2, &session_); | 242 new QuicSimpleServerStreamPeer(2, &session_); |
243 session_.ActivateStream(promised_stream); | 243 session_.ActivateStream(promised_stream); |
244 | 244 |
245 // Send a push response with response status 404, which will be regarded as | 245 // Send a push response with response status 404, which will be regarded as |
246 // invalid server push response. | 246 // invalid server push response. |
247 SpdyHeaderBlock* request_headers = promised_stream->mutable_headers(); | 247 SpdyHeaderBlock* request_headers = promised_stream->mutable_headers(); |
248 (*request_headers)[":path"] = "/bar"; | 248 (*request_headers)[":path"] = "/bar"; |
249 (*request_headers)[":authority"] = ""; | 249 (*request_headers)[":authority"] = "www.google.com"; |
250 (*request_headers)[":version"] = "HTTP/1.1"; | 250 (*request_headers)[":version"] = "HTTP/1.1"; |
251 (*request_headers)[":method"] = "GET"; | 251 (*request_headers)[":method"] = "GET"; |
252 | 252 |
253 response_headers_[":version"] = "HTTP/1.1"; | 253 response_headers_[":version"] = "HTTP/1.1"; |
254 response_headers_[":status"] = "404"; | 254 response_headers_[":status"] = "404"; |
255 response_headers_["content-length"] = "8"; | 255 response_headers_["content-length"] = "8"; |
256 string body = "NotFound"; | 256 string body = "NotFound"; |
257 QuicInMemoryCache::GetInstance()->AddResponse("", "/bar", response_headers_, | 257 QuicInMemoryCache::GetInstance()->AddResponse("www.google.com", "/bar", |
258 body); | 258 response_headers_, body); |
259 | 259 |
260 InSequence s; | 260 InSequence s; |
261 EXPECT_CALL(session_, | 261 EXPECT_CALL(session_, |
262 SendRstStream(promised_stream->id(), QUIC_STREAM_CANCELLED, 0)); | 262 SendRstStream(promised_stream->id(), QUIC_STREAM_CANCELLED, 0)); |
263 | 263 |
264 QuicSimpleServerStreamPeer::SendResponse(promised_stream); | 264 QuicSimpleServerStreamPeer::SendResponse(promised_stream); |
265 } | 265 } |
266 | 266 |
267 TEST_P(QuicSimpleServerStreamTest, SendResponseWithValidHeaders) { | 267 TEST_P(QuicSimpleServerStreamTest, SendResponseWithValidHeaders) { |
268 // Add a request and response with valid headers. | 268 // Add a request and response with valid headers. |
269 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); | 269 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); |
270 (*request_headers)[":path"] = "/bar"; | 270 (*request_headers)[":path"] = "/bar"; |
271 (*request_headers)[":authority"] = ""; | 271 (*request_headers)[":authority"] = "www.google.com"; |
272 (*request_headers)[":version"] = "HTTP/1.1"; | 272 (*request_headers)[":version"] = "HTTP/1.1"; |
273 (*request_headers)[":method"] = "GET"; | 273 (*request_headers)[":method"] = "GET"; |
274 | 274 |
275 response_headers_[":version"] = "HTTP/1.1"; | 275 response_headers_[":version"] = "HTTP/1.1"; |
276 response_headers_[":status"] = "200"; | 276 response_headers_[":status"] = "200"; |
277 response_headers_["content-length"] = "5"; | 277 response_headers_["content-length"] = "5"; |
278 string body = "Yummm"; | 278 string body = "Yummm"; |
279 QuicInMemoryCache::GetInstance()->AddResponse("", "/bar", response_headers_, | 279 QuicInMemoryCache::GetInstance()->AddResponse("www.google.com", "/bar", |
280 body); | 280 response_headers_, body); |
281 stream_->set_fin_received(true); | 281 stream_->set_fin_received(true); |
282 | 282 |
283 InSequence s; | 283 InSequence s; |
284 EXPECT_CALL(session_, WriteHeaders(stream_->id(), _, false, _, nullptr)); | 284 EXPECT_CALL(session_, WriteHeaders(stream_->id(), _, false, _, nullptr)); |
285 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 285 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
286 .Times(1) | 286 .Times(1) |
287 .WillOnce(Return(QuicConsumedData(body.length(), true))); | 287 .WillOnce(Return(QuicConsumedData(body.length(), true))); |
288 | 288 |
289 QuicSimpleServerStreamPeer::SendResponse(stream_); | 289 QuicSimpleServerStreamPeer::SendResponse(stream_); |
290 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); | 290 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 StringPiece data(arr, arraysize(arr)); | 436 StringPiece data(arr, arraysize(arr)); |
437 QuicStreamFrame frame(stream_->id(), true, 0, data); | 437 QuicStreamFrame frame(stream_->id(), true, 0, data); |
438 // Verify that we don't crash when we get a invalid headers in stream frame. | 438 // Verify that we don't crash when we get a invalid headers in stream frame. |
439 stream_->OnStreamFrame(frame); | 439 stream_->OnStreamFrame(frame); |
440 } | 440 } |
441 | 441 |
442 } // namespace | 442 } // namespace |
443 } // namespace test | 443 } // namespace test |
444 } // namespace tools | 444 } // namespace tools |
445 } // namespace net | 445 } // namespace net |
OLD | NEW |