OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 using net::QuicSession; | 42 using net::QuicSession; |
43 using net::QuicStreamId; | 43 using net::QuicStreamId; |
44 using net::QuicStreamOffset; | 44 using net::QuicStreamOffset; |
45 using net::SpdyPriority; | 45 using net::SpdyPriority; |
46 | 46 |
47 using rtc::SR_SUCCESS; | 47 using rtc::SR_SUCCESS; |
48 using rtc::SR_BLOCK; | 48 using rtc::SR_BLOCK; |
49 | 49 |
50 // Arbitrary number for a stream's write blocked priority. | 50 // Arbitrary number for a stream's write blocked priority. |
51 static const SpdyPriority kDefaultPriority = 3; | 51 static const SpdyPriority kDefaultPriority = 3; |
| 52 static const net::QuicStreamId kStreamId = 5; |
52 | 53 |
53 // QuicSession that does not create streams and writes data from | 54 // QuicSession that does not create streams and writes data from |
54 // ReliableQuicStream to a string. | 55 // ReliableQuicStream to a string. |
55 class MockQuicSession : public QuicSession { | 56 class MockQuicSession : public QuicSession { |
56 public: | 57 public: |
57 MockQuicSession(QuicConnection* connection, | 58 MockQuicSession(QuicConnection* connection, |
58 const QuicConfig& config, | 59 const QuicConfig& config, |
59 std::string* write_buffer) | 60 std::string* write_buffer) |
60 : QuicSession(connection, config), write_buffer_(write_buffer) {} | 61 : QuicSession(connection, config), write_buffer_(write_buffer) {} |
61 | 62 |
62 // Writes outgoing data from ReliableQuicStream to a string. | 63 // Writes outgoing data from ReliableQuicStream to a string. |
63 QuicConsumedData WritevData( | 64 QuicConsumedData WritevData( |
64 QuicStreamId id, | 65 QuicStreamId id, |
65 QuicIOVector iovector, | 66 QuicIOVector iovector, |
66 QuicStreamOffset offset, | 67 QuicStreamOffset offset, |
67 bool fin, | 68 bool fin, |
68 QuicAckListenerInterface* ack_notifier_delegate) override { | 69 QuicAckListenerInterface* ack_notifier_delegate) override { |
69 if (!writable_) { | 70 if (!writable_) { |
70 return QuicConsumedData(0, false); | 71 return QuicConsumedData(0, false); |
71 } | 72 } |
72 | 73 |
73 const char* data = reinterpret_cast<const char*>(iovector.iov->iov_base); | 74 const char* data = reinterpret_cast<const char*>(iovector.iov->iov_base); |
74 size_t len = iovector.total_length; | 75 size_t len = iovector.total_length; |
75 write_buffer_->append(data, len); | 76 write_buffer_->append(data, len); |
76 return QuicConsumedData(len, false); | 77 return QuicConsumedData(len, false); |
77 } | 78 } |
78 | 79 |
79 net::ReliableQuicStream* CreateIncomingDynamicStream( | 80 net::ReliableQuicStream* CreateIncomingDynamicStream( |
80 QuicStreamId id) override { | 81 QuicStreamId id) override { |
81 return nullptr; | 82 return new ReliableQuicStream(kStreamId, this); |
82 } | 83 } |
83 | 84 |
84 net::ReliableQuicStream* CreateOutgoingDynamicStream( | 85 net::ReliableQuicStream* CreateOutgoingDynamicStream( |
85 SpdyPriority priority) override { | 86 SpdyPriority priority) override { |
86 return nullptr; | 87 return nullptr; |
87 } | 88 } |
88 | 89 |
89 QuicCryptoStream* GetCryptoStream() override { return nullptr; } | 90 QuicCryptoStream* GetCryptoStream() override { return nullptr; } |
90 | 91 |
91 // Called by ReliableQuicStream when they want to close stream. | 92 // Called by ReliableQuicStream when they want to close stream. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 net::QuicByteCount GetMaxPacketSize( | 134 net::QuicByteCount GetMaxPacketSize( |
134 const net::IPEndPoint& peer_address) const override { | 135 const net::IPEndPoint& peer_address) const override { |
135 return 0; | 136 return 0; |
136 } | 137 } |
137 }; | 138 }; |
138 | 139 |
139 class ReliableQuicStreamTest : public ::testing::Test, | 140 class ReliableQuicStreamTest : public ::testing::Test, |
140 public sigslot::has_slots<> { | 141 public sigslot::has_slots<> { |
141 public: | 142 public: |
| 143 |
142 ReliableQuicStreamTest() {} | 144 ReliableQuicStreamTest() {} |
143 | 145 |
144 void CreateReliableQuicStream() { | 146 void CreateReliableQuicStream() { |
145 const net::QuicStreamId kStreamId = 5; | |
146 | 147 |
147 // Arbitrary values for QuicConnection. | 148 // Arbitrary values for QuicConnection. |
148 QuicConnectionHelper* quic_helper = | 149 QuicConnectionHelper* quic_helper = |
149 new QuicConnectionHelper(rtc::Thread::Current()); | 150 new QuicConnectionHelper(rtc::Thread::Current()); |
150 Perspective perspective = Perspective::IS_SERVER; | 151 Perspective perspective = Perspective::IS_SERVER; |
151 net::IPAddress ip(0, 0, 0, 0); | 152 net::IPAddress ip(0, 0, 0, 0); |
152 | 153 |
153 bool owns_writer = true; | 154 bool owns_writer = true; |
154 | 155 |
155 QuicConnection* connection = new QuicConnection( | 156 QuicConnection* connection = new QuicConnection( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_FALSE(stream_->HasBufferedData()); | 226 EXPECT_FALSE(stream_->HasBufferedData()); |
226 EXPECT_EQ("Foo bar", write_buffer_); | 227 EXPECT_EQ("Foo bar", write_buffer_); |
227 | 228 |
228 EXPECT_EQ(SR_SUCCESS, stream_->Write("xyzzy", 5)); | 229 EXPECT_EQ(SR_SUCCESS, stream_->Write("xyzzy", 5)); |
229 EXPECT_EQ("Foo barxyzzy", write_buffer_); | 230 EXPECT_EQ("Foo barxyzzy", write_buffer_); |
230 } | 231 } |
231 | 232 |
232 // Read an entire string. | 233 // Read an entire string. |
233 TEST_F(ReliableQuicStreamTest, ReadDataWhole) { | 234 TEST_F(ReliableQuicStreamTest, ReadDataWhole) { |
234 CreateReliableQuicStream(); | 235 CreateReliableQuicStream(); |
235 net::QuicStreamFrame frame(-1, false, 0, "Hello, World!"); | 236 net::QuicStreamFrame frame(kStreamId, false, 0, "Hello, World!"); |
236 stream_->OnStreamFrame(frame); | 237 stream_->OnStreamFrame(frame); |
237 | 238 |
238 EXPECT_EQ("Hello, World!", read_buffer_); | 239 EXPECT_EQ("Hello, World!", read_buffer_); |
239 } | 240 } |
240 | 241 |
241 // Read part of a string. | 242 // Read part of a string. |
242 TEST_F(ReliableQuicStreamTest, ReadDataPartial) { | 243 TEST_F(ReliableQuicStreamTest, ReadDataPartial) { |
243 CreateReliableQuicStream(); | 244 CreateReliableQuicStream(); |
244 net::QuicStreamFrame frame(-1, false, 0, "Hello, World!"); | 245 net::QuicStreamFrame frame(kStreamId, false, 0, "Hello, World!"); |
245 frame.frame_length = 5; | 246 frame.frame_length = 5; |
246 stream_->OnStreamFrame(frame); | 247 stream_->OnStreamFrame(frame); |
247 | 248 |
248 EXPECT_EQ("Hello", read_buffer_); | 249 EXPECT_EQ("Hello", read_buffer_); |
249 } | 250 } |
250 | 251 |
251 // Test that closing the stream results in a callback. | 252 // Test that closing the stream results in a callback. |
252 TEST_F(ReliableQuicStreamTest, CloseStream) { | 253 TEST_F(ReliableQuicStreamTest, CloseStream) { |
253 CreateReliableQuicStream(); | 254 CreateReliableQuicStream(); |
254 EXPECT_FALSE(closed_); | 255 EXPECT_FALSE(closed_); |
255 stream_->OnClose(); | 256 stream_->OnClose(); |
256 EXPECT_TRUE(closed_); | 257 EXPECT_TRUE(closed_); |
257 } | 258 } |
OLD | NEW |