Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: webrtc/pc/channel_unittest.cc

Issue 2997983002: Completed the functionalities of SrtpTransport. (Closed)
Patch Set: Fix the chromimum issue. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/pc/channel.cc ('k') | webrtc/pc/rtptransport.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2009 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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 int flags, 574 int flags,
575 typename T::Content* content) { 575 typename T::Content* content) {
576 // Base implementation. 576 // Base implementation.
577 } 577 }
578 578
579 // Tests that can be used by derived classes. 579 // Tests that can be used by derived classes.
580 580
581 // Basic sanity check. 581 // Basic sanity check.
582 void TestInit() { 582 void TestInit() {
583 CreateChannels(0, 0); 583 CreateChannels(0, 0);
584 EXPECT_FALSE(channel1_->secure()); 584 EXPECT_FALSE(channel1_->srtp_active());
585 EXPECT_FALSE(media_channel1_->sending()); 585 EXPECT_FALSE(media_channel1_->sending());
586 if (verify_playout_) { 586 if (verify_playout_) {
587 EXPECT_FALSE(media_channel1_->playout()); 587 EXPECT_FALSE(media_channel1_->playout());
588 } 588 }
589 EXPECT_TRUE(media_channel1_->codecs().empty()); 589 EXPECT_TRUE(media_channel1_->codecs().empty());
590 EXPECT_TRUE(media_channel1_->recv_streams().empty()); 590 EXPECT_TRUE(media_channel1_->recv_streams().empty());
591 EXPECT_TRUE(media_channel1_->rtp_packets().empty()); 591 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
592 EXPECT_TRUE(media_channel1_->rtcp_packets().empty()); 592 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
593 } 593 }
594 594
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 889
890 // Channel 1 replies but stop sending stream1. 890 // Channel 1 replies but stop sending stream1.
891 typename T::Content content4; 891 typename T::Content content4;
892 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4); 892 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
893 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL)); 893 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
894 EXPECT_EQ(0u, media_channel1_->send_streams().size()); 894 EXPECT_EQ(0u, media_channel1_->send_streams().size());
895 895
896 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL)); 896 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
897 EXPECT_EQ(0u, media_channel2_->recv_streams().size()); 897 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
898 898
899 EXPECT_TRUE(channel1_->secure()); 899 EXPECT_TRUE(channel1_->srtp_active());
900 EXPECT_TRUE(channel2_->secure()); 900 EXPECT_TRUE(channel2_->srtp_active());
901 SendCustomRtp2(kSsrc2, 0); 901 SendCustomRtp2(kSsrc2, 0);
902 WaitForThreads(); 902 WaitForThreads();
903 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0)); 903 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
904 } 904 }
905 905
906 enum EncryptedHeaderTestScenario { 906 enum EncryptedHeaderTestScenario {
907 // Offer/Answer are processed before DTLS completes. 907 // Offer/Answer are processed before DTLS completes.
908 DEFAULT, 908 DEFAULT,
909 // DTLS completes before any Offer/Answer have been sent. 909 // DTLS completes before any Offer/Answer have been sent.
910 DTLS_BEFORE_OFFER_ANSWER, 910 DTLS_BEFORE_OFFER_ANSWER,
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 EXPECT_EQ(kLastPacketId, 1246 EXPECT_EQ(kLastPacketId,
1247 media_channel1->last_network_route().last_sent_packet_id); 1247 media_channel1->last_network_route().last_sent_packet_id);
1248 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8). 1248 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
1249 EXPECT_EQ(kTransportOverheadPerPacket, 1249 EXPECT_EQ(kTransportOverheadPerPacket,
1250 media_channel1->transport_overhead_per_packet()); 1250 media_channel1->transport_overhead_per_packet());
1251 } 1251 }
1252 1252
1253 // Test setting up a call. 1253 // Test setting up a call.
1254 void TestCallSetup() { 1254 void TestCallSetup() {
1255 CreateChannels(0, 0); 1255 CreateChannels(0, 0);
1256 EXPECT_FALSE(channel1_->secure()); 1256 EXPECT_FALSE(channel1_->srtp_active());
1257 EXPECT_TRUE(SendInitiate()); 1257 EXPECT_TRUE(SendInitiate());
1258 if (verify_playout_) { 1258 if (verify_playout_) {
1259 EXPECT_TRUE(media_channel1_->playout()); 1259 EXPECT_TRUE(media_channel1_->playout());
1260 } 1260 }
1261 EXPECT_FALSE(media_channel1_->sending()); 1261 EXPECT_FALSE(media_channel1_->sending());
1262 EXPECT_TRUE(SendAccept()); 1262 EXPECT_TRUE(SendAccept());
1263 EXPECT_FALSE(channel1_->secure()); 1263 EXPECT_FALSE(channel1_->srtp_active());
1264 EXPECT_TRUE(media_channel1_->sending()); 1264 EXPECT_TRUE(media_channel1_->sending());
1265 EXPECT_EQ(1U, media_channel1_->codecs().size()); 1265 EXPECT_EQ(1U, media_channel1_->codecs().size());
1266 if (verify_playout_) { 1266 if (verify_playout_) {
1267 EXPECT_TRUE(media_channel2_->playout()); 1267 EXPECT_TRUE(media_channel2_->playout());
1268 } 1268 }
1269 EXPECT_TRUE(media_channel2_->sending()); 1269 EXPECT_TRUE(media_channel2_->sending());
1270 EXPECT_EQ(1U, media_channel2_->codecs().size()); 1270 EXPECT_EQ(1U, media_channel2_->codecs().size());
1271 } 1271 }
1272 1272
1273 // Test that we don't crash if packets are sent during call teardown 1273 // Test that we don't crash if packets are sent during call teardown
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 // You can pass in DTLS, RTCP_MUX, and RAW_PACKET_TRANSPORT as flags. 1528 // You can pass in DTLS, RTCP_MUX, and RAW_PACKET_TRANSPORT as flags.
1529 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) { 1529 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1530 RTC_CHECK((flags1_in & ~(RTCP_MUX | DTLS | RAW_PACKET_TRANSPORT)) == 0); 1530 RTC_CHECK((flags1_in & ~(RTCP_MUX | DTLS | RAW_PACKET_TRANSPORT)) == 0);
1531 RTC_CHECK((flags2_in & ~(RTCP_MUX | DTLS | RAW_PACKET_TRANSPORT)) == 0); 1531 RTC_CHECK((flags2_in & ~(RTCP_MUX | DTLS | RAW_PACKET_TRANSPORT)) == 0);
1532 1532
1533 int flags1 = SECURE | flags1_in; 1533 int flags1 = SECURE | flags1_in;
1534 int flags2 = SECURE | flags2_in; 1534 int flags2 = SECURE | flags2_in;
1535 bool dtls1 = !!(flags1_in & DTLS); 1535 bool dtls1 = !!(flags1_in & DTLS);
1536 bool dtls2 = !!(flags2_in & DTLS); 1536 bool dtls2 = !!(flags2_in & DTLS);
1537 CreateChannels(flags1, flags2); 1537 CreateChannels(flags1, flags2);
1538 EXPECT_FALSE(channel1_->secure()); 1538 EXPECT_FALSE(channel1_->srtp_active());
1539 EXPECT_FALSE(channel2_->secure()); 1539 EXPECT_FALSE(channel2_->srtp_active());
1540 EXPECT_TRUE(SendInitiate()); 1540 EXPECT_TRUE(SendInitiate());
1541 WaitForThreads(); 1541 WaitForThreads();
1542 EXPECT_TRUE(channel1_->writable()); 1542 EXPECT_TRUE(channel1_->writable());
1543 EXPECT_TRUE(channel2_->writable()); 1543 EXPECT_TRUE(channel2_->writable());
1544 EXPECT_TRUE(SendAccept()); 1544 EXPECT_TRUE(SendAccept());
1545 EXPECT_TRUE(channel1_->secure()); 1545 EXPECT_TRUE(channel1_->srtp_active());
1546 EXPECT_TRUE(channel2_->secure()); 1546 EXPECT_TRUE(channel2_->srtp_active());
1547 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls()); 1547 EXPECT_EQ(dtls1 && dtls2, channel1_->dtls_active());
1548 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls()); 1548 EXPECT_EQ(dtls1 && dtls2, channel2_->dtls_active());
1549 SendRtp1(); 1549 SendRtp1();
1550 SendRtp2(); 1550 SendRtp2();
1551 SendRtcp1(); 1551 SendRtcp1();
1552 SendRtcp2(); 1552 SendRtcp2();
1553 WaitForThreads(); 1553 WaitForThreads();
1554 EXPECT_TRUE(CheckRtp1()); 1554 EXPECT_TRUE(CheckRtp1());
1555 EXPECT_TRUE(CheckRtp2()); 1555 EXPECT_TRUE(CheckRtp2());
1556 EXPECT_TRUE(CheckNoRtp1()); 1556 EXPECT_TRUE(CheckNoRtp1());
1557 EXPECT_TRUE(CheckNoRtp2()); 1557 EXPECT_TRUE(CheckNoRtp2());
1558 EXPECT_TRUE(CheckRtcp1()); 1558 EXPECT_TRUE(CheckRtcp1());
1559 EXPECT_TRUE(CheckRtcp2()); 1559 EXPECT_TRUE(CheckRtcp2());
1560 EXPECT_TRUE(CheckNoRtcp1()); 1560 EXPECT_TRUE(CheckNoRtcp1());
1561 EXPECT_TRUE(CheckNoRtcp2()); 1561 EXPECT_TRUE(CheckNoRtcp2());
1562 } 1562 }
1563 1563
1564 // Test that we properly handling SRTP negotiating down to RTP. 1564 // Test that we properly handling SRTP negotiating down to RTP.
1565 void SendSrtpToRtp() { 1565 void SendSrtpToRtp() {
1566 CreateChannels(SECURE, 0); 1566 CreateChannels(SECURE, 0);
1567 EXPECT_FALSE(channel1_->secure()); 1567 EXPECT_FALSE(channel1_->srtp_active());
1568 EXPECT_FALSE(channel2_->secure()); 1568 EXPECT_FALSE(channel2_->srtp_active());
1569 EXPECT_TRUE(SendInitiate()); 1569 EXPECT_TRUE(SendInitiate());
1570 EXPECT_TRUE(SendAccept()); 1570 EXPECT_TRUE(SendAccept());
1571 EXPECT_FALSE(channel1_->secure()); 1571 EXPECT_FALSE(channel1_->srtp_active());
1572 EXPECT_FALSE(channel2_->secure()); 1572 EXPECT_FALSE(channel2_->srtp_active());
1573 SendRtp1(); 1573 SendRtp1();
1574 SendRtp2(); 1574 SendRtp2();
1575 SendRtcp1(); 1575 SendRtcp1();
1576 SendRtcp2(); 1576 SendRtcp2();
1577 WaitForThreads(); 1577 WaitForThreads();
1578 EXPECT_TRUE(CheckRtp1()); 1578 EXPECT_TRUE(CheckRtp1());
1579 EXPECT_TRUE(CheckRtp2()); 1579 EXPECT_TRUE(CheckRtp2());
1580 EXPECT_TRUE(CheckNoRtp1()); 1580 EXPECT_TRUE(CheckNoRtp1());
1581 EXPECT_TRUE(CheckNoRtp2()); 1581 EXPECT_TRUE(CheckNoRtp2());
1582 EXPECT_TRUE(CheckRtcp1()); 1582 EXPECT_TRUE(CheckRtcp1());
1583 EXPECT_TRUE(CheckRtcp2()); 1583 EXPECT_TRUE(CheckRtcp2());
1584 EXPECT_TRUE(CheckNoRtcp1()); 1584 EXPECT_TRUE(CheckNoRtcp1());
1585 EXPECT_TRUE(CheckNoRtcp2()); 1585 EXPECT_TRUE(CheckNoRtcp2());
1586 } 1586 }
1587 1587
1588 // Test that we can send and receive early media when a provisional answer is 1588 // Test that we can send and receive early media when a provisional answer is
1589 // sent and received. The test uses SRTP, RTCP mux and SSRC mux. 1589 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1590 void SendEarlyMediaUsingRtcpMuxSrtp() { 1590 void SendEarlyMediaUsingRtcpMuxSrtp() {
1591 int sequence_number1_1 = 0, sequence_number2_2 = 0; 1591 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1592 1592
1593 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE, 1593 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE,
1594 SSRC_MUX | RTCP_MUX | SECURE); 1594 SSRC_MUX | RTCP_MUX | SECURE);
1595 EXPECT_TRUE(SendOffer()); 1595 EXPECT_TRUE(SendOffer());
1596 EXPECT_TRUE(SendProvisionalAnswer()); 1596 EXPECT_TRUE(SendProvisionalAnswer());
1597 EXPECT_TRUE(channel1_->secure()); 1597 EXPECT_TRUE(channel1_->srtp_active());
1598 EXPECT_TRUE(channel2_->secure()); 1598 EXPECT_TRUE(channel2_->srtp_active());
1599 EXPECT_TRUE(channel1_->NeedsRtcpTransport()); 1599 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1600 EXPECT_TRUE(channel2_->NeedsRtcpTransport()); 1600 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
1601 WaitForThreads(); // Wait for 'sending' flag go through network thread. 1601 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1602 SendCustomRtcp1(kSsrc1); 1602 SendCustomRtcp1(kSsrc1);
1603 SendCustomRtp1(kSsrc1, ++sequence_number1_1); 1603 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1604 WaitForThreads(); 1604 WaitForThreads();
1605 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); 1605 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1606 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); 1606 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1607 1607
1608 // Send packets from callee and verify that it is received. 1608 // Send packets from callee and verify that it is received.
1609 SendCustomRtcp2(kSsrc2); 1609 SendCustomRtcp2(kSsrc2);
1610 SendCustomRtp2(kSsrc2, ++sequence_number2_2); 1610 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1611 WaitForThreads(); 1611 WaitForThreads();
1612 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); 1612 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1613 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); 1613 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1614 1614
1615 // Complete call setup and ensure everything is still OK. 1615 // Complete call setup and ensure everything is still OK.
1616 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_); 1616 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
1617 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_); 1617 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_);
1618 EXPECT_TRUE(SendFinalAnswer()); 1618 EXPECT_TRUE(SendFinalAnswer());
1619 EXPECT_FALSE(channel1_->NeedsRtcpTransport()); 1619 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1620 EXPECT_FALSE(channel2_->NeedsRtcpTransport()); 1620 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1621 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_); 1621 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
1622 EXPECT_EQ(1, rtcp_mux_activated_callbacks2_); 1622 EXPECT_EQ(1, rtcp_mux_activated_callbacks2_);
1623 EXPECT_TRUE(channel1_->secure()); 1623 EXPECT_TRUE(channel1_->srtp_active());
1624 EXPECT_TRUE(channel2_->secure()); 1624 EXPECT_TRUE(channel2_->srtp_active());
1625 SendCustomRtcp1(kSsrc1); 1625 SendCustomRtcp1(kSsrc1);
1626 SendCustomRtp1(kSsrc1, ++sequence_number1_1); 1626 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1627 SendCustomRtcp2(kSsrc2); 1627 SendCustomRtcp2(kSsrc2);
1628 SendCustomRtp2(kSsrc2, ++sequence_number2_2); 1628 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1629 WaitForThreads(); 1629 WaitForThreads();
1630 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); 1630 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1631 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); 1631 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1632 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); 1632 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1633 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); 1633 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1634 } 1634 }
(...skipping 2262 matching lines...) Expand 10 before | Expand all | Expand 10 after
3897 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_, 3897 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_,
3898 &fake_rtcp_dtls_transport_)); 3898 &fake_rtcp_dtls_transport_));
3899 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_, 3899 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_,
3900 &fake_rtp_dtls_transport_), 3900 &fake_rtp_dtls_transport_),
3901 ""); 3901 "");
3902 } 3902 }
3903 3903
3904 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 3904 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3905 3905
3906 // TODO(pthatcher): TestSetReceiver? 3906 // TODO(pthatcher): TestSetReceiver?
OLDNEW
« no previous file with comments | « webrtc/pc/channel.cc ('k') | webrtc/pc/rtptransport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698