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; | |
53 | 52 |
54 // QuicSession that does not create streams and writes data from | 53 // QuicSession that does not create streams and writes data from |
55 // ReliableQuicStream to a string. | 54 // ReliableQuicStream to a string. |
56 class MockQuicSession : public QuicSession { | 55 class MockQuicSession : public QuicSession { |
57 public: | 56 public: |
58 MockQuicSession(QuicConnection* connection, | 57 MockQuicSession(QuicConnection* connection, |
59 const QuicConfig& config, | 58 const QuicConfig& config, |
60 std::string* write_buffer) | 59 std::string* write_buffer) |
61 : QuicSession(connection, config), write_buffer_(write_buffer) {} | 60 : QuicSession(connection, config), write_buffer_(write_buffer) {} |
62 | 61 |
63 // Writes outgoing data from ReliableQuicStream to a string. | 62 // Writes outgoing data from ReliableQuicStream to a string. |
64 QuicConsumedData WritevData( | 63 QuicConsumedData WritevData( |
65 QuicStreamId id, | 64 QuicStreamId id, |
66 QuicIOVector iovector, | 65 QuicIOVector iovector, |
67 QuicStreamOffset offset, | 66 QuicStreamOffset offset, |
68 bool fin, | 67 bool fin, |
69 QuicAckListenerInterface* ack_notifier_delegate) override { | 68 QuicAckListenerInterface* ack_notifier_delegate) override { |
70 if (!writable_) { | 69 if (!writable_) { |
71 return QuicConsumedData(0, false); | 70 return QuicConsumedData(0, false); |
72 } | 71 } |
73 | 72 |
74 const char* data = reinterpret_cast<const char*>(iovector.iov->iov_base); | 73 const char* data = reinterpret_cast<const char*>(iovector.iov->iov_base); |
75 size_t len = iovector.total_length; | 74 size_t len = iovector.total_length; |
76 write_buffer_->append(data, len); | 75 write_buffer_->append(data, len); |
77 return QuicConsumedData(len, false); | 76 return QuicConsumedData(len, false); |
78 } | 77 } |
79 | 78 |
80 net::ReliableQuicStream* CreateIncomingDynamicStream( | 79 net::ReliableQuicStream* CreateIncomingDynamicStream( |
81 QuicStreamId id) override { | 80 QuicStreamId id) override { |
82 return new ReliableQuicStream(kStreamId, this); | 81 return nullptr; |
83 } | 82 } |
84 | 83 |
85 net::ReliableQuicStream* CreateOutgoingDynamicStream( | 84 net::ReliableQuicStream* CreateOutgoingDynamicStream( |
86 SpdyPriority priority) override { | 85 SpdyPriority priority) override { |
87 return nullptr; | 86 return nullptr; |
88 } | 87 } |
89 | 88 |
90 QuicCryptoStream* GetCryptoStream() override { return nullptr; } | 89 QuicCryptoStream* GetCryptoStream() override { return nullptr; } |
91 | 90 |
92 // Called by ReliableQuicStream when they want to close stream. | 91 // Called by ReliableQuicStream when they want to close stream. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return 0; | 135 return 0; |
137 } | 136 } |
138 }; | 137 }; |
139 | 138 |
140 class ReliableQuicStreamTest : public ::testing::Test, | 139 class ReliableQuicStreamTest : public ::testing::Test, |
141 public sigslot::has_slots<> { | 140 public sigslot::has_slots<> { |
142 public: | 141 public: |
143 ReliableQuicStreamTest() {} | 142 ReliableQuicStreamTest() {} |
144 | 143 |
145 void CreateReliableQuicStream() { | 144 void CreateReliableQuicStream() { |
| 145 const net::QuicStreamId kStreamId = 5; |
146 | 146 |
147 // Arbitrary values for QuicConnection. | 147 // Arbitrary values for QuicConnection. |
148 QuicConnectionHelper* quic_helper = | 148 QuicConnectionHelper* quic_helper = |
149 new QuicConnectionHelper(rtc::Thread::Current()); | 149 new QuicConnectionHelper(rtc::Thread::Current()); |
150 Perspective perspective = Perspective::IS_SERVER; | 150 Perspective perspective = Perspective::IS_SERVER; |
151 net::IPAddress ip(0, 0, 0, 0); | 151 net::IPAddress ip(0, 0, 0, 0); |
152 | 152 |
153 bool owns_writer = true; | 153 bool owns_writer = true; |
154 | 154 |
155 QuicConnection* connection = new QuicConnection( | 155 QuicConnection* connection = new QuicConnection( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_FALSE(stream_->HasBufferedData()); | 225 EXPECT_FALSE(stream_->HasBufferedData()); |
226 EXPECT_EQ("Foo bar", write_buffer_); | 226 EXPECT_EQ("Foo bar", write_buffer_); |
227 | 227 |
228 EXPECT_EQ(SR_SUCCESS, stream_->Write("xyzzy", 5)); | 228 EXPECT_EQ(SR_SUCCESS, stream_->Write("xyzzy", 5)); |
229 EXPECT_EQ("Foo barxyzzy", write_buffer_); | 229 EXPECT_EQ("Foo barxyzzy", write_buffer_); |
230 } | 230 } |
231 | 231 |
232 // Read an entire string. | 232 // Read an entire string. |
233 TEST_F(ReliableQuicStreamTest, ReadDataWhole) { | 233 TEST_F(ReliableQuicStreamTest, ReadDataWhole) { |
234 CreateReliableQuicStream(); | 234 CreateReliableQuicStream(); |
235 net::QuicStreamFrame frame(kStreamId, false, 0, "Hello, World!"); | 235 net::QuicStreamFrame frame(-1, false, 0, "Hello, World!"); |
236 stream_->OnStreamFrame(frame); | 236 stream_->OnStreamFrame(frame); |
237 | 237 |
238 EXPECT_EQ("Hello, World!", read_buffer_); | 238 EXPECT_EQ("Hello, World!", read_buffer_); |
239 } | 239 } |
240 | 240 |
241 // Read part of a string. | 241 // Read part of a string. |
242 TEST_F(ReliableQuicStreamTest, ReadDataPartial) { | 242 TEST_F(ReliableQuicStreamTest, ReadDataPartial) { |
243 CreateReliableQuicStream(); | 243 CreateReliableQuicStream(); |
244 net::QuicStreamFrame frame(kStreamId, false, 0, "Hello, World!"); | 244 net::QuicStreamFrame frame(-1, false, 0, "Hello, World!"); |
245 frame.frame_length = 5; | 245 frame.frame_length = 5; |
246 stream_->OnStreamFrame(frame); | 246 stream_->OnStreamFrame(frame); |
247 | 247 |
248 EXPECT_EQ("Hello", read_buffer_); | 248 EXPECT_EQ("Hello", read_buffer_); |
249 } | 249 } |
250 | 250 |
251 // Test that closing the stream results in a callback. | 251 // Test that closing the stream results in a callback. |
252 TEST_F(ReliableQuicStreamTest, CloseStream) { | 252 TEST_F(ReliableQuicStreamTest, CloseStream) { |
253 CreateReliableQuicStream(); | 253 CreateReliableQuicStream(); |
254 EXPECT_FALSE(closed_); | 254 EXPECT_FALSE(closed_); |
255 stream_->OnClose(); | 255 stream_->OnClose(); |
256 EXPECT_TRUE(closed_); | 256 EXPECT_TRUE(closed_); |
257 } | 257 } |
OLD | NEW |