OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic/quic_stream_sequencer.h" | 5 #include "net/quic/quic_stream_sequencer.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 #include <cstdint> |
| 9 #include <memory> |
7 #include <utility> | 10 #include <utility> |
8 #include <vector> | 11 #include <vector> |
9 | 12 |
10 #include "base/logging.h" | 13 #include "base/logging.h" |
11 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
12 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
13 #include "net/quic/quic_flags.h" | 16 #include "net/quic/quic_flags.h" |
14 #include "net/quic/quic_utils.h" | 17 #include "net/quic/quic_utils.h" |
15 #include "net/quic/reliable_quic_stream.h" | 18 #include "net/quic/reliable_quic_stream.h" |
16 #include "net/quic/test_tools/mock_clock.h" | 19 #include "net/quic/test_tools/mock_clock.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 char buffer[1024]; | 65 char buffer[1024]; |
63 ASSERT_GT(arraysize(buffer), num_bytes); | 66 ASSERT_GT(arraysize(buffer), num_bytes); |
64 struct iovec iov; | 67 struct iovec iov; |
65 iov.iov_base = buffer; | 68 iov.iov_base = buffer; |
66 iov.iov_len = num_bytes; | 69 iov.iov_len = num_bytes; |
67 ASSERT_EQ(static_cast<int>(num_bytes), sequencer_->Readv(&iov, 1)); | 70 ASSERT_EQ(static_cast<int>(num_bytes), sequencer_->Readv(&iov, 1)); |
68 } | 71 } |
69 | 72 |
70 protected: | 73 protected: |
71 QuicStreamSequencerTest() | 74 QuicStreamSequencerTest() |
72 : connection_(new MockConnection(&helper_, Perspective::IS_CLIENT)), | 75 : connection_(new MockConnection(&helper_, |
| 76 &alarm_factory_, |
| 77 Perspective::IS_CLIENT)), |
73 session_(connection_), | 78 session_(connection_), |
74 stream_(&session_, 1), | 79 stream_(&session_, 1), |
75 sequencer_(new QuicStreamSequencer(&stream_, &clock_)) {} | 80 sequencer_(new QuicStreamSequencer(&stream_, &clock_)) {} |
76 | 81 |
77 // Verify that the data in first region match with the expected[0]. | 82 // Verify that the data in first region match with the expected[0]. |
78 bool VerifyReadableRegion(const vector<string>& expected) { | 83 bool VerifyReadableRegion(const vector<string>& expected) { |
79 iovec iovecs[1]; | 84 iovec iovecs[1]; |
80 if (sequencer_->GetReadableRegions(iovecs, 1)) { | 85 if (sequencer_->GetReadableRegions(iovecs, 1)) { |
81 return (VerifyIovecs(iovecs, 1, vector<string>{expected[0]})); | 86 return (VerifyIovecs(iovecs, 1, vector<string>{expected[0]})); |
82 } | 87 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 frame.frame_length = strlen(data); | 144 frame.frame_length = strlen(data); |
140 frame.fin = false; | 145 frame.fin = false; |
141 sequencer_->OnStreamFrame(frame); | 146 sequencer_->OnStreamFrame(frame); |
142 } | 147 } |
143 | 148 |
144 size_t NumBufferedBytes() { | 149 size_t NumBufferedBytes() { |
145 return QuicStreamSequencerPeer::GetNumBufferedBytes(sequencer_.get()); | 150 return QuicStreamSequencerPeer::GetNumBufferedBytes(sequencer_.get()); |
146 } | 151 } |
147 | 152 |
148 MockConnectionHelper helper_; | 153 MockConnectionHelper helper_; |
| 154 MockAlarmFactory alarm_factory_; |
149 MockConnection* connection_; | 155 MockConnection* connection_; |
150 MockClock clock_; | 156 MockClock clock_; |
151 MockQuicSpdySession session_; | 157 MockQuicSpdySession session_; |
152 testing::StrictMock<MockStream> stream_; | 158 testing::StrictMock<MockStream> stream_; |
153 std::unique_ptr<QuicStreamSequencer> sequencer_; | 159 std::unique_ptr<QuicStreamSequencer> sequencer_; |
154 }; | 160 }; |
155 | 161 |
156 // TODO(rch): reorder these tests so they build on each other. | 162 // TODO(rch): reorder these tests so they build on each other. |
157 | 163 |
158 TEST_F(QuicStreamSequencerTest, RejectOldFrame) { | 164 TEST_F(QuicStreamSequencerTest, RejectOldFrame) { |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 562 } |
557 | 563 |
558 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { | 564 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { |
559 // The peer should never send us non-identical stream frames which contain | 565 // The peer should never send us non-identical stream frames which contain |
560 // overlapping byte ranges - if they do, we close the connection. | 566 // overlapping byte ranges - if they do, we close the connection. |
561 | 567 |
562 QuicStreamFrame frame1(kClientDataStreamId1, false, 1, StringPiece("hello")); | 568 QuicStreamFrame frame1(kClientDataStreamId1, false, 1, StringPiece("hello")); |
563 sequencer_->OnStreamFrame(frame1); | 569 sequencer_->OnStreamFrame(frame1); |
564 | 570 |
565 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, StringPiece("hello")); | 571 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, StringPiece("hello")); |
566 EXPECT_CALL(stream_, CloseConnectionWithDetails( | 572 EXPECT_CALL(stream_, |
567 FLAGS_quic_consolidate_onstreamframe_errors | 573 CloseConnectionWithDetails(QUIC_OVERLAPPING_STREAM_DATA, _)) |
568 ? QUIC_OVERLAPPING_STREAM_DATA | |
569 : QUIC_EMPTY_STREAM_FRAME_NO_FIN, | |
570 _)) | |
571 .Times(1); | 574 .Times(1); |
572 sequencer_->OnStreamFrame(frame2); | 575 sequencer_->OnStreamFrame(frame2); |
573 } | 576 } |
574 | 577 |
575 TEST_F(QuicStreamSequencerTest, InOrderTimestamps) { | 578 TEST_F(QuicStreamSequencerTest, InOrderTimestamps) { |
576 // This test verifies that timestamps returned by | 579 // This test verifies that timestamps returned by |
577 // GetReadableRegion() are in the correct sequence when frames | 580 // GetReadableRegion() are in the correct sequence when frames |
578 // arrive at the sequencer in order. | 581 // arrive at the sequencer in order. |
579 EXPECT_CALL(stream_, OnDataAvailable()); | 582 EXPECT_CALL(stream_, OnDataAvailable()); |
580 | 583 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 EXPECT_EQ(timestamp, t1); | 653 EXPECT_EQ(timestamp, t1); |
651 QuicStreamSequencerTest::ConsumeData(3); | 654 QuicStreamSequencerTest::ConsumeData(3); |
652 EXPECT_EQ(0u, NumBufferedBytes()); | 655 EXPECT_EQ(0u, NumBufferedBytes()); |
653 EXPECT_EQ(6u, sequencer_->NumBytesConsumed()); | 656 EXPECT_EQ(6u, sequencer_->NumBytesConsumed()); |
654 EXPECT_EQ(0u, sequencer_->NumBytesBuffered()); | 657 EXPECT_EQ(0u, sequencer_->NumBytesBuffered()); |
655 } | 658 } |
656 | 659 |
657 } // namespace | 660 } // namespace |
658 } // namespace test | 661 } // namespace test |
659 } // namespace net | 662 } // namespace net |
OLD | NEW |