| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 QuicConnection* connection = new QuicConnection( | 156 QuicConnection* connection = new QuicConnection( |
| 157 0, IPEndPoint(ip, 0), quic_helper, new DummyPacketWriter(), owns_writer, | 157 0, IPEndPoint(ip, 0), quic_helper, new DummyPacketWriter(), owns_writer, |
| 158 perspective, net::QuicSupportedVersions()); | 158 perspective, net::QuicSupportedVersions()); |
| 159 | 159 |
| 160 session_.reset( | 160 session_.reset( |
| 161 new MockQuicSession(connection, QuicConfig(), &write_buffer_)); | 161 new MockQuicSession(connection, QuicConfig(), &write_buffer_)); |
| 162 stream_.reset(new ReliableQuicStream(kStreamId, session_.get())); | 162 stream_.reset(new ReliableQuicStream(kStreamId, session_.get())); |
| 163 stream_->SignalDataReceived.connect( | 163 stream_->SignalDataReceived.connect( |
| 164 this, &ReliableQuicStreamTest::OnDataReceived); | 164 this, &ReliableQuicStreamTest::OnDataReceived); |
| 165 stream_->SignalClosed.connect(this, &ReliableQuicStreamTest::OnClosed); | 165 stream_->SignalClosed.connect(this, &ReliableQuicStreamTest::OnClosed); |
| 166 stream_->SignalQueuedBytesWritten.connect( |
| 167 this, &ReliableQuicStreamTest::OnQueuedBytesWritten); |
| 166 | 168 |
| 167 session_->register_write_blocked_stream(stream_->id(), kDefaultPriority); | 169 session_->register_write_blocked_stream(stream_->id(), kDefaultPriority); |
| 168 } | 170 } |
| 169 | 171 |
| 170 void OnDataReceived(QuicStreamId id, const char* data, size_t length) { | 172 void OnDataReceived(QuicStreamId id, const char* data, size_t length) { |
| 171 ASSERT_EQ(id, stream_->id()); | 173 ASSERT_EQ(id, stream_->id()); |
| 172 read_buffer_.append(data, length); | 174 read_buffer_.append(data, length); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void OnClosed(QuicStreamId id, QuicErrorCode err) { closed_ = true; } | 177 void OnClosed(QuicStreamId id, int err) { closed_ = true; } |
| 178 |
| 179 void OnQueuedBytesWritten(QuicStreamId id, uint64_t queued_bytes_written) { |
| 180 queued_bytes_written_ = queued_bytes_written; |
| 181 } |
| 176 | 182 |
| 177 protected: | 183 protected: |
| 178 rtc::scoped_ptr<ReliableQuicStream> stream_; | 184 rtc::scoped_ptr<ReliableQuicStream> stream_; |
| 179 rtc::scoped_ptr<MockQuicSession> session_; | 185 rtc::scoped_ptr<MockQuicSession> session_; |
| 180 | 186 |
| 181 // Data written by the ReliableQuicStream. | 187 // Data written by the ReliableQuicStream. |
| 182 std::string write_buffer_; | 188 std::string write_buffer_; |
| 183 // Data read by the ReliableQuicStream. | 189 // Data read by the ReliableQuicStream. |
| 184 std::string read_buffer_; | 190 std::string read_buffer_; |
| 185 // Whether the ReliableQuicStream is closed. | 191 // Whether the ReliableQuicStream is closed. |
| 186 bool closed_ = false; | 192 bool closed_ = false; |
| 193 // Bytes written by OnCanWrite(). |
| 194 uint64_t queued_bytes_written_; |
| 187 }; | 195 }; |
| 188 | 196 |
| 189 // Write an entire string. | 197 // Write an entire string. |
| 190 TEST_F(ReliableQuicStreamTest, WriteDataWhole) { | 198 TEST_F(ReliableQuicStreamTest, WriteDataWhole) { |
| 191 CreateReliableQuicStream(); | 199 CreateReliableQuicStream(); |
| 192 EXPECT_EQ(SR_SUCCESS, stream_->Write("Foo bar", 7)); | 200 EXPECT_EQ(SR_SUCCESS, stream_->Write("Foo bar", 7)); |
| 193 | 201 |
| 194 EXPECT_EQ("Foo bar", write_buffer_); | 202 EXPECT_EQ("Foo bar", write_buffer_); |
| 195 } | 203 } |
| 196 | 204 |
| 197 // Write part of a string. | 205 // Write part of a string. |
| 198 TEST_F(ReliableQuicStreamTest, WriteDataPartial) { | 206 TEST_F(ReliableQuicStreamTest, WriteDataPartial) { |
| 199 CreateReliableQuicStream(); | 207 CreateReliableQuicStream(); |
| 200 EXPECT_EQ(SR_SUCCESS, stream_->Write("Hello, World!", 8)); | 208 EXPECT_EQ(SR_SUCCESS, stream_->Write("Hello, World!", 8)); |
| 201 EXPECT_EQ("Hello, W", write_buffer_); | 209 EXPECT_EQ("Hello, W", write_buffer_); |
| 202 } | 210 } |
| 203 | 211 |
| 204 // Test that strings are buffered correctly. | 212 // Test that strings are buffered correctly. |
| 205 TEST_F(ReliableQuicStreamTest, BufferData) { | 213 TEST_F(ReliableQuicStreamTest, BufferData) { |
| 206 CreateReliableQuicStream(); | 214 CreateReliableQuicStream(); |
| 207 | 215 |
| 208 session_->set_writable(false); | 216 session_->set_writable(false); |
| 209 EXPECT_EQ(SR_BLOCK, stream_->Write("Foo bar", 7)); | 217 EXPECT_EQ(SR_BLOCK, stream_->Write("Foo bar", 7)); |
| 210 | 218 |
| 211 EXPECT_EQ(0ul, write_buffer_.size()); | 219 EXPECT_EQ(0ul, write_buffer_.size()); |
| 212 EXPECT_TRUE(stream_->HasBufferedData()); | 220 EXPECT_TRUE(stream_->HasBufferedData()); |
| 213 | 221 |
| 214 session_->set_writable(true); | 222 session_->set_writable(true); |
| 215 stream_->OnCanWrite(); | 223 stream_->OnCanWrite(); |
| 224 EXPECT_EQ(7ul, queued_bytes_written_); |
| 216 | 225 |
| 217 EXPECT_FALSE(stream_->HasBufferedData()); | 226 EXPECT_FALSE(stream_->HasBufferedData()); |
| 218 EXPECT_EQ("Foo bar", write_buffer_); | 227 EXPECT_EQ("Foo bar", write_buffer_); |
| 219 | 228 |
| 220 EXPECT_EQ(SR_SUCCESS, stream_->Write("xyzzy", 5)); | 229 EXPECT_EQ(SR_SUCCESS, stream_->Write("xyzzy", 5)); |
| 221 EXPECT_EQ("Foo barxyzzy", write_buffer_); | 230 EXPECT_EQ("Foo barxyzzy", write_buffer_); |
| 222 } | 231 } |
| 223 | 232 |
| 224 // Read an entire string. | 233 // Read an entire string. |
| 225 TEST_F(ReliableQuicStreamTest, ReadDataWhole) { | 234 TEST_F(ReliableQuicStreamTest, ReadDataWhole) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 240 EXPECT_EQ("Hello", read_buffer_); | 249 EXPECT_EQ("Hello", read_buffer_); |
| 241 } | 250 } |
| 242 | 251 |
| 243 // Test that closing the stream results in a callback. | 252 // Test that closing the stream results in a callback. |
| 244 TEST_F(ReliableQuicStreamTest, CloseStream) { | 253 TEST_F(ReliableQuicStreamTest, CloseStream) { |
| 245 CreateReliableQuicStream(); | 254 CreateReliableQuicStream(); |
| 246 EXPECT_FALSE(closed_); | 255 EXPECT_FALSE(closed_); |
| 247 stream_->OnClose(); | 256 stream_->OnClose(); |
| 248 EXPECT_TRUE(closed_); | 257 EXPECT_TRUE(closed_); |
| 249 } | 258 } |
| OLD | NEW |