Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This file contains tests for |RtpTransceiver|. |
| 12 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 13 | #include "pc/rtp_transceiver.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame^] | 15 | #include <memory> |
| 16 | |
| 17 | #include "media/base/fake_media_engine.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "pc/test/mock_channel_interface.h" |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame^] | 19 | #include "pc/test/mock_rtp_receiver_internal.h" |
| 20 | #include "pc/test/mock_rtp_sender_internal.h" |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 21 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "test/gtest.h" |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 23 | |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame^] | 24 | using ::testing::ElementsAre; |
| 25 | using ::testing::Eq; |
| 26 | using ::testing::Field; |
| 27 | using ::testing::Not; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 28 | using ::testing::Return; |
| 29 | using ::testing::ReturnRef; |
| 30 | |
| 31 | namespace webrtc { |
| 32 | |
| 33 | // Checks that a channel cannot be set on a stopped |RtpTransceiver|. |
| 34 | TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) { |
| 35 | RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 36 | cricket::MockChannelInterface channel1; |
| 37 | sigslot::signal1<cricket::ChannelInterface*> signal; |
| 38 | EXPECT_CALL(channel1, media_type()) |
| 39 | .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO)); |
| 40 | EXPECT_CALL(channel1, SignalFirstPacketReceived()) |
| 41 | .WillRepeatedly(ReturnRef(signal)); |
| 42 | |
| 43 | transceiver.SetChannel(&channel1); |
| 44 | EXPECT_EQ(&channel1, transceiver.channel()); |
| 45 | |
| 46 | // Stop the transceiver. |
| 47 | transceiver.Stop(); |
| 48 | EXPECT_EQ(&channel1, transceiver.channel()); |
| 49 | |
| 50 | cricket::MockChannelInterface channel2; |
| 51 | EXPECT_CALL(channel2, media_type()) |
| 52 | .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO)); |
| 53 | |
| 54 | // Channel can no longer be set, so this call should be a no-op. |
| 55 | transceiver.SetChannel(&channel2); |
| 56 | EXPECT_EQ(&channel1, transceiver.channel()); |
| 57 | } |
| 58 | |
| 59 | // Checks that a channel can be unset on a stopped |RtpTransceiver| |
| 60 | TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) { |
| 61 | RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_VIDEO); |
| 62 | cricket::MockChannelInterface channel; |
| 63 | sigslot::signal1<cricket::ChannelInterface*> signal; |
| 64 | EXPECT_CALL(channel, media_type()) |
| 65 | .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO)); |
| 66 | EXPECT_CALL(channel, SignalFirstPacketReceived()) |
| 67 | .WillRepeatedly(ReturnRef(signal)); |
| 68 | |
| 69 | transceiver.SetChannel(&channel); |
| 70 | EXPECT_EQ(&channel, transceiver.channel()); |
| 71 | |
| 72 | // Stop the transceiver. |
| 73 | transceiver.Stop(); |
| 74 | EXPECT_EQ(&channel, transceiver.channel()); |
| 75 | |
| 76 | // Set the channel to |nullptr|. |
| 77 | transceiver.SetChannel(nullptr); |
| 78 | EXPECT_EQ(nullptr, transceiver.channel()); |
| 79 | } |
| 80 | |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame^] | 81 | TEST(RtpTransceiverTest, |
| 82 | InitsWithChannelManagerRtpHeaderExtensionCapabilities) { |
| 83 | cricket::ChannelManager channel_manager( |
| 84 | std::make_unique<cricket::FakeMediaEngine>(), |
| 85 | std::make_unique<cricket::FakeDataEngine>(), rtc::Thread::Current(), |
| 86 | rtc::Thread::Current()); |
| 87 | std::vector<RtpHeaderExtensionCapability> extensions({ |
| 88 | RtpHeaderExtensionCapability("uri1", 1, |
| 89 | RtpTransceiverDirection::kSendRecv), |
| 90 | RtpHeaderExtensionCapability("uri2", 2, |
| 91 | RtpTransceiverDirection::kRecvOnly), |
| 92 | }); |
| 93 | RtpTransceiver transceiver( |
| 94 | RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
| 95 | rtc::Thread::Current(), |
| 96 | new rtc::RefCountedObject<MockRtpSenderInternal>()), |
| 97 | RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
| 98 | rtc::Thread::Current(), |
| 99 | new rtc::RefCountedObject<MockRtpReceiverInternal>()), |
| 100 | &channel_manager, extensions); |
| 101 | EXPECT_EQ(transceiver.HeaderExtensionsToOffer(), extensions); |
| 102 | } |
| 103 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 104 | } // namespace webrtc |