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