Chromium Code Reviews| 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 // Send three buffers while not blocked. | |
| 213 provider_->set_send_blocked(false); | |
|
hta-webrtc
2016/10/12 17:25:28
check that messages_sent and bytes_sent are zero a
hbos
2016/10/12 18:25:07
Done. Did the same for messages_received and bytes
| |
| 214 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[0])); | |
| 215 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[1])); | |
| 216 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[2])); | |
| 217 size_t bytes_sent = buffers[0].size() + buffers[1].size() + buffers[2].size(); | |
| 218 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); | |
|
hta-webrtc
2016/10/12 17:25:28
Is this 100% reliable, or do we need it to be EXPE
hbos
2016/10/12 18:25:07
Yes, but there are interfaces and stuff involved s
| |
| 219 EXPECT_EQ(3U, webrtc_data_channel_->messages_sent()); | |
| 220 EXPECT_EQ(bytes_sent, webrtc_data_channel_->bytes_sent()); | |
| 221 | |
| 222 // Send three buffers while blocked, queuing the buffers. | |
| 223 provider_->set_send_blocked(true); | |
| 224 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[3])); | |
| 225 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[4])); | |
| 226 EXPECT_TRUE(webrtc_data_channel_->Send(buffers[5])); | |
| 227 size_t bytes_queued = | |
| 228 buffers[3].size() + buffers[4].size() + buffers[5].size(); | |
| 229 EXPECT_EQ(bytes_queued, webrtc_data_channel_->buffered_amount()); | |
| 230 EXPECT_EQ(3U, webrtc_data_channel_->messages_sent()); | |
| 231 EXPECT_EQ(bytes_sent, webrtc_data_channel_->bytes_sent()); | |
| 232 | |
| 233 // Unblock and make sure everything was sent. | |
| 234 provider_->set_send_blocked(false); | |
| 235 EXPECT_EQ_WAIT(0U, webrtc_data_channel_->buffered_amount(), 1000); | |
| 236 bytes_sent += bytes_queued; | |
| 237 EXPECT_EQ(6U, webrtc_data_channel_->messages_sent()); | |
| 238 EXPECT_EQ(bytes_sent, webrtc_data_channel_->bytes_sent()); | |
| 239 } | |
| 240 | |
| 198 // Tests that the queued control message is sent when channel is ready. | 241 // Tests that the queued control message is sent when channel is ready. |
| 199 TEST_F(SctpDataChannelTest, OpenMessageSent) { | 242 TEST_F(SctpDataChannelTest, OpenMessageSent) { |
| 200 // Initially the id is unassigned. | 243 // Initially the id is unassigned. |
| 201 EXPECT_EQ(-1, webrtc_data_channel_->id()); | 244 EXPECT_EQ(-1, webrtc_data_channel_->id()); |
| 202 | 245 |
| 203 SetChannelReady(); | 246 SetChannelReady(); |
| 204 EXPECT_GE(webrtc_data_channel_->id(), 0); | 247 EXPECT_GE(webrtc_data_channel_->id(), 0); |
| 205 EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); | 248 EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); |
| 206 EXPECT_EQ(provider_->last_send_data_params().ssrc, | 249 EXPECT_EQ(provider_->last_send_data_params().ssrc, |
| 207 static_cast<uint32_t>(webrtc_data_channel_->id())); | 250 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; | 410 config.open_handshake_role = webrtc::InternalDataChannelInit::kNone; |
| 368 | 411 |
| 369 SetChannelReady(); | 412 SetChannelReady(); |
| 370 rtc::scoped_refptr<DataChannel> dc = | 413 rtc::scoped_refptr<DataChannel> dc = |
| 371 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", config); | 414 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", config); |
| 372 | 415 |
| 373 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); | 416 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
| 374 EXPECT_EQ(0U, provider_->last_send_data_params().ssrc); | 417 EXPECT_EQ(0U, provider_->last_send_data_params().ssrc); |
| 375 } | 418 } |
| 376 | 419 |
| 420 // Tests that DataChannel::messages_received() and DataChannel::bytes_received() | |
| 421 // are correct, receiving data both while blocked and while unblocked. | |
| 422 TEST_F(SctpDataChannelTest, VerifyMessagesAndBytesReceived) { | |
| 423 AddObserver(); | |
| 424 std::vector<webrtc::DataBuffer> buffers({ | |
| 425 webrtc::DataBuffer("message 1"), | |
| 426 webrtc::DataBuffer("msg 2"), | |
| 427 webrtc::DataBuffer("message three"), | |
| 428 webrtc::DataBuffer("quadra message"), | |
| 429 webrtc::DataBuffer("fifthmsg"), | |
| 430 webrtc::DataBuffer("message of the beast"), | |
| 431 }); | |
| 432 | |
| 433 webrtc_data_channel_->SetSctpSid(1); | |
| 434 cricket::ReceiveDataParams params; | |
| 435 params.ssrc = 1; | |
| 436 | |
| 437 // Receive three buffers while blocked. | |
| 438 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[0].data); | |
| 439 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[1].data); | |
| 440 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[2].data); | |
| 441 EXPECT_EQ(0U, observer_->messages_received()); | |
| 442 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); | |
| 443 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); | |
| 444 | |
| 445 // Unblock and make sure everything was received. | |
| 446 SetChannelReady(); | |
| 447 size_t bytes_received = | |
| 448 buffers[0].size() + buffers[1].size() + buffers[2].size(); | |
| 449 EXPECT_EQ(3U, observer_->messages_received()); | |
| 450 EXPECT_EQ(3U, webrtc_data_channel_->messages_received()); | |
| 451 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); | |
| 452 | |
| 453 // Receive three buffers while unblocked. | |
| 454 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[3].data); | |
| 455 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[4].data); | |
| 456 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[5].data); | |
| 457 bytes_received += buffers[3].size() + buffers[4].size() + buffers[5].size(); | |
| 458 EXPECT_EQ(6U, observer_->messages_received()); | |
| 459 EXPECT_EQ(6U, webrtc_data_channel_->messages_received()); | |
| 460 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); | |
| 461 } | |
| 462 | |
| 377 // Tests that OPEN_ACK message is sent if the datachannel is created from an | 463 // Tests that OPEN_ACK message is sent if the datachannel is created from an |
| 378 // OPEN message. | 464 // OPEN message. |
| 379 TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { | 465 TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { |
| 380 webrtc::InternalDataChannelInit config; | 466 webrtc::InternalDataChannelInit config; |
| 381 config.id = 1; | 467 config.id = 1; |
| 382 config.negotiated = true; | 468 config.negotiated = true; |
| 383 config.open_handshake_role = webrtc::InternalDataChannelInit::kAcker; | 469 config.open_handshake_role = webrtc::InternalDataChannelInit::kAcker; |
| 384 | 470 |
| 385 SetChannelReady(); | 471 SetChannelReady(); |
| 386 rtc::scoped_refptr<DataChannel> dc = | 472 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)); | 668 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); |
| 583 EXPECT_EQ(even_id, allocated_id); | 669 EXPECT_EQ(even_id, allocated_id); |
| 584 | 670 |
| 585 // Verifies that used higher ids are not reused. | 671 // Verifies that used higher ids are not reused. |
| 586 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); | 672 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); |
| 587 EXPECT_EQ(odd_id + 6, allocated_id); | 673 EXPECT_EQ(odd_id + 6, allocated_id); |
| 588 | 674 |
| 589 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); | 675 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); |
| 590 EXPECT_EQ(even_id + 6, allocated_id); | 676 EXPECT_EQ(even_id + 6, allocated_id); |
| 591 } | 677 } |
| OLD | NEW |