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_simple_server_session.h" | 5 #include "net/tools/quic/quic_simple_server_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { | 228 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { |
229 // Open a stream, then reset it. | 229 // Open a stream, then reset it. |
230 // Send two bytes of payload to open it. | 230 // Send two bytes of payload to open it. |
231 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 231 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
232 session_->OnStreamFrame(data1); | 232 session_->OnStreamFrame(data1); |
233 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 233 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
234 | 234 |
235 // Receive a reset (and send a RST in response). | 235 // Receive a reset (and send a RST in response). |
236 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 236 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, |
237 0); | 237 0); |
| 238 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
238 EXPECT_CALL(*connection_, | 239 EXPECT_CALL(*connection_, |
239 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 240 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
240 visitor_->OnRstStream(rst1); | 241 visitor_->OnRstStream(rst1); |
241 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 242 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
242 | 243 |
243 // Send the same two bytes of payload in a new packet. | 244 // Send the same two bytes of payload in a new packet. |
244 visitor_->OnStreamFrame(data1); | 245 visitor_->OnStreamFrame(data1); |
245 | 246 |
246 // The stream should not be re-opened. | 247 // The stream should not be re-opened. |
247 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 248 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
248 EXPECT_TRUE(connection_->connected()); | 249 EXPECT_TRUE(connection_->connected()); |
249 } | 250 } |
250 | 251 |
251 TEST_P(QuicSimpleServerSessionTest, NeverOpenStreamDueToReset) { | 252 TEST_P(QuicSimpleServerSessionTest, NeverOpenStreamDueToReset) { |
252 // Send a reset (and expect the peer to send a RST in response). | 253 // Send a reset (and expect the peer to send a RST in response). |
253 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 254 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, |
254 0); | 255 0); |
| 256 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
255 EXPECT_CALL(*connection_, | 257 EXPECT_CALL(*connection_, |
256 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 258 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
257 visitor_->OnRstStream(rst1); | 259 visitor_->OnRstStream(rst1); |
258 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 260 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
259 | 261 |
260 // Send two bytes of payload. | 262 // Send two bytes of payload. |
261 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 263 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
262 visitor_->OnStreamFrame(data1); | 264 visitor_->OnStreamFrame(data1); |
263 | 265 |
264 // The stream should never be opened, now that the reset is received. | 266 // The stream should never be opened, now that the reset is received. |
265 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 267 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
266 EXPECT_TRUE(connection_->connected()); | 268 EXPECT_TRUE(connection_->connected()); |
267 } | 269 } |
268 | 270 |
269 TEST_P(QuicSimpleServerSessionTest, AcceptClosedStream) { | 271 TEST_P(QuicSimpleServerSessionTest, AcceptClosedStream) { |
270 // Send (empty) compressed headers followed by two bytes of data. | 272 // Send (empty) compressed headers followed by two bytes of data. |
271 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, | 273 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, |
272 StringPiece("\1\0\0\0\0\0\0\0HT")); | 274 StringPiece("\1\0\0\0\0\0\0\0HT")); |
273 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, | 275 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, |
274 StringPiece("\2\0\0\0\0\0\0\0HT")); | 276 StringPiece("\2\0\0\0\0\0\0\0HT")); |
275 visitor_->OnStreamFrame(frame1); | 277 visitor_->OnStreamFrame(frame1); |
276 visitor_->OnStreamFrame(frame2); | 278 visitor_->OnStreamFrame(frame2); |
277 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); | 279 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); |
278 | 280 |
279 // Send a reset (and expect the peer to send a RST in response). | 281 // Send a reset (and expect the peer to send a RST in response). |
280 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0); | 282 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0); |
| 283 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
281 EXPECT_CALL(*connection_, | 284 EXPECT_CALL(*connection_, |
282 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 285 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
283 visitor_->OnRstStream(rst); | 286 visitor_->OnRstStream(rst); |
284 | 287 |
285 // If we were tracking, we'd probably want to reject this because it's data | 288 // If we were tracking, we'd probably want to reject this because it's data |
286 // past the reset point of stream 3. As it's a closed stream we just drop the | 289 // past the reset point of stream 3. As it's a closed stream we just drop the |
287 // data on the floor, but accept the packet because it has data for stream 5. | 290 // data on the floor, but accept the packet because it has data for stream 5. |
288 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, StringPiece("TP")); | 291 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, StringPiece("TP")); |
289 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, StringPiece("TP")); | 292 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, StringPiece("TP")); |
290 visitor_->OnStreamFrame(frame3); | 293 visitor_->OnStreamFrame(frame3); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // prevent a promised resource to be send out. | 565 // prevent a promised resource to be send out. |
563 | 566 |
564 // Having two extra resources to be send later. One of them will be reset, so | 567 // Having two extra resources to be send later. One of them will be reset, so |
565 // when opened stream become close, only one will become open. | 568 // when opened stream become close, only one will become open. |
566 size_t num_resources = kMaxStreamsForTest + 2; | 569 size_t num_resources = kMaxStreamsForTest + 2; |
567 PromisePushResources(num_resources); | 570 PromisePushResources(num_resources); |
568 | 571 |
569 // Reset the last stream in the queue. It should be marked cancelled. | 572 // Reset the last stream in the queue. It should be marked cancelled. |
570 QuicStreamId stream_got_reset = num_resources * 2; | 573 QuicStreamId stream_got_reset = num_resources * 2; |
571 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 574 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 575 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
572 EXPECT_CALL(*connection_, | 576 EXPECT_CALL(*connection_, |
573 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 577 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
574 visitor_->OnRstStream(rst); | 578 visitor_->OnRstStream(rst); |
575 | 579 |
576 // When the first 2 streams becomes draining, the two queued up stream could | 580 // When the first 2 streams becomes draining, the two queued up stream could |
577 // be created. But since one of them was marked cancelled due to RST frame, | 581 // be created. But since one of them was marked cancelled due to RST frame, |
578 // only one queued resource will be sent out. | 582 // only one queued resource will be sent out. |
579 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; | 583 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; |
580 InSequence s; | 584 InSequence s; |
581 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, | 585 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, |
(...skipping 24 matching lines...) Expand all Loading... |
606 // stream to be opened. | 610 // stream to be opened. |
607 QuicStreamId stream_got_reset = 2; | 611 QuicStreamId stream_got_reset = 2; |
608 EXPECT_CALL(*connection_, | 612 EXPECT_CALL(*connection_, |
609 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); | 613 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); |
610 EXPECT_CALL(*session_, | 614 EXPECT_CALL(*session_, |
611 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); | 615 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); |
612 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, false, _)) | 616 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, false, _)) |
613 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 617 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
614 | 618 |
615 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 619 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 620 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
616 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 621 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
617 visitor_->OnRstStream(rst); | 622 visitor_->OnRstStream(rst); |
618 } | 623 } |
619 | 624 |
620 } // namespace | 625 } // namespace |
621 } // namespace test | 626 } // namespace test |
622 } // namespace net | 627 } // namespace net |
OLD | NEW |