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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 webrtc::DataBuffer buffer("some data"); | 322 webrtc::DataBuffer buffer("some data"); |
323 ASSERT_TRUE(dc->Send(buffer)); | 323 ASSERT_TRUE(dc->Send(buffer)); |
324 EXPECT_TRUE(provider_->last_send_data_params().ordered); | 324 EXPECT_TRUE(provider_->last_send_data_params().ordered); |
325 | 325 |
326 // Emulates receiving an OPEN_ACK message. | 326 // Emulates receiving an OPEN_ACK message. |
327 cricket::ReceiveDataParams params; | 327 cricket::ReceiveDataParams params; |
328 params.ssrc = init.id; | 328 params.ssrc = init.id; |
329 params.type = cricket::DMT_CONTROL; | 329 params.type = cricket::DMT_CONTROL; |
330 rtc::CopyOnWriteBuffer payload; | 330 rtc::CopyOnWriteBuffer payload; |
331 webrtc::WriteDataChannelOpenAckMessage(&payload); | 331 webrtc::WriteDataChannelOpenAckMessage(&payload); |
332 dc->OnDataReceived(params, payload); | 332 dc->OnDataReceived(NULL, params, payload); |
333 | 333 |
334 // Sends another message and verifies it's unordered. | 334 // Sends another message and verifies it's unordered. |
335 ASSERT_TRUE(dc->Send(buffer)); | 335 ASSERT_TRUE(dc->Send(buffer)); |
336 EXPECT_FALSE(provider_->last_send_data_params().ordered); | 336 EXPECT_FALSE(provider_->last_send_data_params().ordered); |
337 } | 337 } |
338 | 338 |
339 // Tests that an unordered DataChannel sends unordered data after any DATA | 339 // Tests that an unordered DataChannel sends unordered data after any DATA |
340 // message is received. | 340 // message is received. |
341 TEST_F(SctpDataChannelTest, SendUnorderedAfterReceiveData) { | 341 TEST_F(SctpDataChannelTest, SendUnorderedAfterReceiveData) { |
342 SetChannelReady(); | 342 SetChannelReady(); |
343 webrtc::InternalDataChannelInit init; | 343 webrtc::InternalDataChannelInit init; |
344 init.id = 1; | 344 init.id = 1; |
345 init.ordered = false; | 345 init.ordered = false; |
346 rtc::scoped_refptr<DataChannel> dc = | 346 rtc::scoped_refptr<DataChannel> dc = |
347 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", init); | 347 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", init); |
348 | 348 |
349 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); | 349 EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
350 | 350 |
351 // Emulates receiving a DATA message. | 351 // Emulates receiving a DATA message. |
352 cricket::ReceiveDataParams params; | 352 cricket::ReceiveDataParams params; |
353 params.ssrc = init.id; | 353 params.ssrc = init.id; |
354 params.type = cricket::DMT_TEXT; | 354 params.type = cricket::DMT_TEXT; |
355 webrtc::DataBuffer buffer("data"); | 355 webrtc::DataBuffer buffer("data"); |
356 dc->OnDataReceived(params, buffer.data); | 356 dc->OnDataReceived(NULL, params, buffer.data); |
357 | 357 |
358 // Sends a message and verifies it's unordered. | 358 // Sends a message and verifies it's unordered. |
359 ASSERT_TRUE(dc->Send(buffer)); | 359 ASSERT_TRUE(dc->Send(buffer)); |
360 EXPECT_FALSE(provider_->last_send_data_params().ordered); | 360 EXPECT_FALSE(provider_->last_send_data_params().ordered); |
361 } | 361 } |
362 | 362 |
363 // Tests that the channel can't open until it's successfully sent the OPEN | 363 // Tests that the channel can't open until it's successfully sent the OPEN |
364 // message. | 364 // message. |
365 TEST_F(SctpDataChannelTest, OpenWaitsForOpenMesssage) { | 365 TEST_F(SctpDataChannelTest, OpenWaitsForOpenMesssage) { |
366 webrtc::DataBuffer buffer("foo"); | 366 webrtc::DataBuffer buffer("foo"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 // Tests that the incoming messages with wrong ssrcs are rejected. | 407 // Tests that the incoming messages with wrong ssrcs are rejected. |
408 TEST_F(SctpDataChannelTest, ReceiveDataWithInvalidSsrc) { | 408 TEST_F(SctpDataChannelTest, ReceiveDataWithInvalidSsrc) { |
409 webrtc_data_channel_->SetSctpSid(1); | 409 webrtc_data_channel_->SetSctpSid(1); |
410 SetChannelReady(); | 410 SetChannelReady(); |
411 | 411 |
412 AddObserver(); | 412 AddObserver(); |
413 | 413 |
414 cricket::ReceiveDataParams params; | 414 cricket::ReceiveDataParams params; |
415 params.ssrc = 0; | 415 params.ssrc = 0; |
416 webrtc::DataBuffer buffer("abcd"); | 416 webrtc::DataBuffer buffer("abcd"); |
417 webrtc_data_channel_->OnDataReceived(params, buffer.data); | 417 webrtc_data_channel_->OnDataReceived(NULL, params, buffer.data); |
418 | 418 |
419 EXPECT_EQ(0U, observer_->messages_received()); | 419 EXPECT_EQ(0U, observer_->messages_received()); |
420 } | 420 } |
421 | 421 |
422 // Tests that the incoming messages with right ssrcs are acceted. | 422 // Tests that the incoming messages with right ssrcs are acceted. |
423 TEST_F(SctpDataChannelTest, ReceiveDataWithValidSsrc) { | 423 TEST_F(SctpDataChannelTest, ReceiveDataWithValidSsrc) { |
424 webrtc_data_channel_->SetSctpSid(1); | 424 webrtc_data_channel_->SetSctpSid(1); |
425 SetChannelReady(); | 425 SetChannelReady(); |
426 | 426 |
427 AddObserver(); | 427 AddObserver(); |
428 | 428 |
429 cricket::ReceiveDataParams params; | 429 cricket::ReceiveDataParams params; |
430 params.ssrc = 1; | 430 params.ssrc = 1; |
431 webrtc::DataBuffer buffer("abcd"); | 431 webrtc::DataBuffer buffer("abcd"); |
432 | 432 |
433 webrtc_data_channel_->OnDataReceived(params, buffer.data); | 433 webrtc_data_channel_->OnDataReceived(NULL, params, buffer.data); |
434 EXPECT_EQ(1U, observer_->messages_received()); | 434 EXPECT_EQ(1U, observer_->messages_received()); |
435 } | 435 } |
436 | 436 |
437 // Tests that no CONTROL message is sent if the datachannel is negotiated and | 437 // Tests that no CONTROL message is sent if the datachannel is negotiated and |
438 // not created from an OPEN message. | 438 // not created from an OPEN message. |
439 TEST_F(SctpDataChannelTest, NoMsgSentIfNegotiatedAndNotFromOpenMsg) { | 439 TEST_F(SctpDataChannelTest, NoMsgSentIfNegotiatedAndNotFromOpenMsg) { |
440 webrtc::InternalDataChannelInit config; | 440 webrtc::InternalDataChannelInit config; |
441 config.id = 1; | 441 config.id = 1; |
442 config.negotiated = true; | 442 config.negotiated = true; |
443 config.open_handshake_role = webrtc::InternalDataChannelInit::kNone; | 443 config.open_handshake_role = webrtc::InternalDataChannelInit::kNone; |
(...skipping 21 matching lines...) Expand all Loading... |
465 | 465 |
466 webrtc_data_channel_->SetSctpSid(1); | 466 webrtc_data_channel_->SetSctpSid(1); |
467 cricket::ReceiveDataParams params; | 467 cricket::ReceiveDataParams params; |
468 params.ssrc = 1; | 468 params.ssrc = 1; |
469 | 469 |
470 // Default values. | 470 // Default values. |
471 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); | 471 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); |
472 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); | 472 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); |
473 | 473 |
474 // Receive three buffers while data channel isn't open. | 474 // Receive three buffers while data channel isn't open. |
475 webrtc_data_channel_->OnDataReceived(params, buffers[0].data); | 475 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[0].data); |
476 webrtc_data_channel_->OnDataReceived(params, buffers[1].data); | 476 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[1].data); |
477 webrtc_data_channel_->OnDataReceived(params, buffers[2].data); | 477 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[2].data); |
478 EXPECT_EQ(0U, observer_->messages_received()); | 478 EXPECT_EQ(0U, observer_->messages_received()); |
479 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); | 479 EXPECT_EQ(0U, webrtc_data_channel_->messages_received()); |
480 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); | 480 EXPECT_EQ(0U, webrtc_data_channel_->bytes_received()); |
481 | 481 |
482 // Open channel and make sure everything was received. | 482 // Open channel and make sure everything was received. |
483 SetChannelReady(); | 483 SetChannelReady(); |
484 size_t bytes_received = | 484 size_t bytes_received = |
485 buffers[0].size() + buffers[1].size() + buffers[2].size(); | 485 buffers[0].size() + buffers[1].size() + buffers[2].size(); |
486 EXPECT_EQ(3U, observer_->messages_received()); | 486 EXPECT_EQ(3U, observer_->messages_received()); |
487 EXPECT_EQ(3U, webrtc_data_channel_->messages_received()); | 487 EXPECT_EQ(3U, webrtc_data_channel_->messages_received()); |
488 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); | 488 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); |
489 | 489 |
490 // Receive three buffers while open. | 490 // Receive three buffers while open. |
491 webrtc_data_channel_->OnDataReceived(params, buffers[3].data); | 491 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[3].data); |
492 webrtc_data_channel_->OnDataReceived(params, buffers[4].data); | 492 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[4].data); |
493 webrtc_data_channel_->OnDataReceived(params, buffers[5].data); | 493 webrtc_data_channel_->OnDataReceived(nullptr, params, buffers[5].data); |
494 bytes_received += buffers[3].size() + buffers[4].size() + buffers[5].size(); | 494 bytes_received += buffers[3].size() + buffers[4].size() + buffers[5].size(); |
495 EXPECT_EQ(6U, observer_->messages_received()); | 495 EXPECT_EQ(6U, observer_->messages_received()); |
496 EXPECT_EQ(6U, webrtc_data_channel_->messages_received()); | 496 EXPECT_EQ(6U, webrtc_data_channel_->messages_received()); |
497 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); | 497 EXPECT_EQ(bytes_received, webrtc_data_channel_->bytes_received()); |
498 } | 498 } |
499 | 499 |
500 // Tests that OPEN_ACK message is sent if the datachannel is created from an | 500 // Tests that OPEN_ACK message is sent if the datachannel is created from an |
501 // OPEN message. | 501 // OPEN message. |
502 TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { | 502 TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { |
503 webrtc::InternalDataChannelInit config; | 503 webrtc::InternalDataChannelInit config; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 TEST_F(SctpDataChannelTest, ClosedWhenReceivedBufferFull) { | 586 TEST_F(SctpDataChannelTest, ClosedWhenReceivedBufferFull) { |
587 SetChannelReady(); | 587 SetChannelReady(); |
588 rtc::CopyOnWriteBuffer buffer(1024); | 588 rtc::CopyOnWriteBuffer buffer(1024); |
589 memset(buffer.data(), 0, buffer.size()); | 589 memset(buffer.data(), 0, buffer.size()); |
590 | 590 |
591 cricket::ReceiveDataParams params; | 591 cricket::ReceiveDataParams params; |
592 params.ssrc = 0; | 592 params.ssrc = 0; |
593 | 593 |
594 // Receiving data without having an observer will overflow the buffer. | 594 // Receiving data without having an observer will overflow the buffer. |
595 for (size_t i = 0; i < 16 * 1024 + 1; ++i) { | 595 for (size_t i = 0; i < 16 * 1024 + 1; ++i) { |
596 webrtc_data_channel_->OnDataReceived(params, buffer); | 596 webrtc_data_channel_->OnDataReceived(NULL, params, buffer); |
597 } | 597 } |
598 EXPECT_EQ(webrtc::DataChannelInterface::kClosed, | 598 EXPECT_EQ(webrtc::DataChannelInterface::kClosed, |
599 webrtc_data_channel_->state()); | 599 webrtc_data_channel_->state()); |
600 } | 600 } |
601 | 601 |
602 // Tests that sending empty data returns no error and keeps the channel open. | 602 // Tests that sending empty data returns no error and keeps the channel open. |
603 TEST_F(SctpDataChannelTest, SendEmptyData) { | 603 TEST_F(SctpDataChannelTest, SendEmptyData) { |
604 webrtc_data_channel_->SetSctpSid(1); | 604 webrtc_data_channel_->SetSctpSid(1); |
605 SetChannelReady(); | 605 SetChannelReady(); |
606 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, | 606 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); | 705 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); |
706 EXPECT_EQ(even_id, allocated_id); | 706 EXPECT_EQ(even_id, allocated_id); |
707 | 707 |
708 // Verifies that used higher ids are not reused. | 708 // Verifies that used higher ids are not reused. |
709 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); | 709 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); |
710 EXPECT_EQ(odd_id + 6, allocated_id); | 710 EXPECT_EQ(odd_id + 6, allocated_id); |
711 | 711 |
712 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); | 712 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); |
713 EXPECT_EQ(even_id + 6, allocated_id); | 713 EXPECT_EQ(even_id + 6, allocated_id); |
714 } | 714 } |
OLD | NEW |