OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 EXPECT_EQ(buffer.size(), webrtc_data_channel_->buffered_amount()); | 188 EXPECT_EQ(buffer.size(), webrtc_data_channel_->buffered_amount()); |
189 EXPECT_EQ(1U, observer_->on_buffered_amount_change_count()); | 189 EXPECT_EQ(1U, observer_->on_buffered_amount_change_count()); |
190 | 190 |
191 // Unblock the channel to send queued data again, there should be no crash. | 191 // Unblock the channel to send queued data again, there should be no crash. |
192 provider_->set_send_blocked(false); | 192 provider_->set_send_blocked(false); |
193 SetChannelReady(); | 193 SetChannelReady(); |
194 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); | 194 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); |
195 EXPECT_EQ(2U, observer_->on_buffered_amount_change_count()); | 195 EXPECT_EQ(2U, observer_->on_buffered_amount_change_count()); |
196 } | 196 } |
197 | 197 |
| 198 // Tests that DataChannel::messages_sent() and DataChannel::bytes_sent() are |
| 199 // correct, sending data both while unblocked and while blocked. |
| 200 TEST_F(SctpDataChannelTest, VerifyMessagesAndBytesSent) { |
| 201 AddObserver(); |
| 202 SetChannelReady(); |
| 203 std::vector<webrtc::DataBuffer> buffers({ |
| 204 webrtc::DataBuffer("message 1"), |
| 205 webrtc::DataBuffer("msg 2"), |
| 206 webrtc::DataBuffer("message three"), |
| 207 webrtc::DataBuffer("quadra message"), |
| 208 webrtc::DataBuffer("fifthmsg"), |
| 209 webrtc::DataBuffer("message of the beast"), |
| 210 }); |
| 211 |
| 212 // Default values. |
| 213 EXPECT_EQ(0U, webrtc_data_channel_->messages_sent()); |
| 214 EXPECT_EQ(0U, webrtc_data_channel_->bytes_sent()); |
| 215 |
| 216 // Send three buffers while not blocked. |
| 217 provider_->set_send_blocked(false); |
| 218 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[0])); |
| 219 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[1])); |
| 220 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[2])); |
| 221 size_t bytes_sent = buffers[0].size() + buffers[1].size() + buffers[2].size(); |
| 222 EXPECT_EQ_WAIT(0U, webrtc_data_channel_->buffered_amount(), kDefaultTimeout); |
| 223 EXPECT_EQ(3U, webrtc_data_channel_->messages_sent()); |
| 224 EXPECT_EQ(bytes_sent, webrtc_data_channel_->bytes_sent()); |
| 225 |
| 226 // Send three buffers while blocked, queuing the buffers. |
| 227 provider_->set_send_blocked(true); |
| 228 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[3])); |
| 229 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[4])); |
| 230 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[5])); |
| 231 size_t bytes_queued = |
| 232 buffers[3].size() + buffers[4].size() + buffers[5].size(); |
| 233 EXPECT_EQ(bytes_queued, webrtc_data_channel_->buffered_amount()); |
| 234 EXPECT_EQ(3U, webrtc_data_channel_->messages_sent()); |
| 235 EXPECT_EQ(bytes_sent, webrtc_data_channel_->bytes_sent()); |
| 236 |
| 237 // Unblock and make sure everything was sent. |
| 238 provider_->set_send_blocked(false); |
| 239 EXPECT_EQ_WAIT(0U, webrtc_data_channel_->buffered_amount(), kDefaultTimeout); |
| 240 bytes_sent += bytes_queued; |
| 241 EXPECT_EQ(6U, webrtc_data_channel_->messages_sent()); |
| 242 EXPECT_EQ(bytes_sent, webrtc_data_channel_->bytes_sent()); |
| 243 } |
| 244 |
198 // Tests that the queued control message is sent when channel is ready. | 245 // Tests that the queued control message is sent when channel is ready. |
199 TEST_F(SctpDataChannelTest, OpenMessageSent) { | 246 TEST_F(SctpDataChannelTest, OpenMessageSent) { |
200 // Initially the id is unassigned. | 247 // Initially the id is unassigned. |
201 EXPECT_EQ(-1, webrtc_data_channel_->id()); | 248 EXPECT_EQ(-1, webrtc_data_channel_->id()); |
202 | 249 |
203 SetChannelReady(); | 250 SetChannelReady(); |
204 EXPECT_GE(webrtc_data_channel_->id(), 0); | 251 EXPECT_GE(webrtc_data_channel_->id(), 0); |
205 EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); | 252 EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); |
206 EXPECT_EQ(provider_->last_send_data_params().ssrc, | 253 EXPECT_EQ(provider_->last_send_data_params().ssrc, |
207 static_cast<uint32_t>(webrtc_data_channel_->id())); | 254 static_cast<uint32_t>(webrtc_data_channel_->id())); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 config.open_handshake_role = webrtc::InternalDataChannelInit::kNone; | 414 config.open_handshake_role = webrtc::InternalDataChannelInit::kNone; |
368 | 415 |
369 SetChannelReady(); | 416 SetChannelReady(); |
370 rtc::scoped_refptr<DataChannel> dc = | 417 rtc::scoped_refptr<DataChannel> dc = |
371 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", config); | 418 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", config); |
372 | 419 |
373 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); | 420 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
374 EXPECT_EQ(0U, provider_->last_send_data_params().ssrc); | 421 EXPECT_EQ(0U, provider_->last_send_data_params().ssrc); |
375 } | 422 } |
376 | 423 |
| 424 // Tests that DataChannel::messages_received() and DataChannel::bytes_received() |
| 425 // are correct, receiving data both while not open and while open. |
| 426 TEST_F(SctpDataChannelTest, VerifyMessagesAndBytesReceived) { |
| 427 AddObserver(); |
| 428 std::vector<webrtc::DataBuffer> buffers({ |
| 429 webrtc::DataBuffer("message 1"), |
| 430 webrtc::DataBuffer("msg 2"), |
| 431 webrtc::DataBuffer("message three"), |
| 432 webrtc::DataBuffer("quadra message"), |
| 433 webrtc::DataBuffer("fifthmsg"), |
| 434 webrtc::DataBuffer("message of the beast"), |
| 435 }); |
| 436 |
| 437 webrtc_data_channel_->SetSctpSid(1); |
| 438 cricket::ReceiveDataParams params; |
| 439 params.ssrc = 1; |
| 440 |
| 441 // Default values. |
| 442 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); |
| 443 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); |
| 444 |
| 445 // Receive three buffers while data channel isn't open. |
| 446 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[0].data); |
| 447 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[1].data); |
| 448 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[2].data); |
| 449 EXPECT_EQ(0U, observer_->messages_received()); |
| 450 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); |
| 451 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); |
| 452 |
| 453 // Open channel and make sure everything was received. |
| 454 SetChannelReady(); |
| 455 size_t bytes_received = |
| 456 buffers[0].size() + buffers[1].size() + buffers[2].size(); |
| 457 EXPECT_EQ(3U, observer_->messages_received()); |
| 458 EXPECT_EQ(3U, webrtc_data_channel_->messages_received()); |
| 459 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); |
| 460 |
| 461 // Receive three buffers while open. |
| 462 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[3].data); |
| 463 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[4].data); |
| 464 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[5].data); |
| 465 bytes_received += buffers[3].size() + buffers[4].size() + buffers[5].size(); |
| 466 EXPECT_EQ(6U, observer_->messages_received()); |
| 467 EXPECT_EQ(6U, webrtc_data_channel_->messages_received()); |
| 468 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); |
| 469 } |
| 470 |
377 // Tests that OPEN_ACK message is sent if the datachannel is created from an | 471 // Tests that OPEN_ACK message is sent if the datachannel is created from an |
378 // OPEN message. | 472 // OPEN message. |
379 TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { | 473 TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { |
380 webrtc::InternalDataChannelInit config; | 474 webrtc::InternalDataChannelInit config; |
381 config.id = 1; | 475 config.id = 1; |
382 config.negotiated = true; | 476 config.negotiated = true; |
383 config.open_handshake_role = webrtc::InternalDataChannelInit::kAcker; | 477 config.open_handshake_role = webrtc::InternalDataChannelInit::kAcker; |
384 | 478 |
385 SetChannelReady(); | 479 SetChannelReady(); |
386 rtc::scoped_refptr<DataChannel> dc = | 480 rtc::scoped_refptr<DataChannel> dc = |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); | 676 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); |
583 EXPECT_EQ(even_id, allocated_id); | 677 EXPECT_EQ(even_id, allocated_id); |
584 | 678 |
585 // Verifies that used higher ids are not reused. | 679 // Verifies that used higher ids are not reused. |
586 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); | 680 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); |
587 EXPECT_EQ(odd_id + 6, allocated_id); | 681 EXPECT_EQ(odd_id + 6, allocated_id); |
588 | 682 |
589 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); | 683 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); |
590 EXPECT_EQ(even_id + 6, allocated_id); | 684 EXPECT_EQ(even_id + 6, allocated_id); |
591 } | 685 } |
OLD | NEW |