blob: 5e345739f17e9ad963f03fdfd6db16bd74369295 [file] [log] [blame]
Amit Hilbuchdd9390c2018-11-13 16:26:05 -08001/*
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 Anton10542f22019-01-11 09:11:00 -080013#include "pc/rtp_transceiver.h"
Yves Gerey3e707812018-11-28 16:47:49 +010014
Markus Handell0357b3e2020-03-16 13:40:51 +010015#include <memory>
16
17#include "media/base/fake_media_engine.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "pc/test/mock_channel_interface.h"
Markus Handell0357b3e2020-03-16 13:40:51 +010019#include "pc/test/mock_rtp_receiver_internal.h"
20#include "pc/test/mock_rtp_sender_internal.h"
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080021#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "test/gtest.h"
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080023
Markus Handell0357b3e2020-03-16 13:40:51 +010024using ::testing::ElementsAre;
25using ::testing::Eq;
26using ::testing::Field;
27using ::testing::Not;
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080028using ::testing::Return;
29using ::testing::ReturnRef;
30
31namespace webrtc {
32
33// Checks that a channel cannot be set on a stopped |RtpTransceiver|.
34TEST(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|
60TEST(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 Handell0357b3e2020-03-16 13:40:51 +010081TEST(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 Hilbuchdd9390c2018-11-13 16:26:05 -0800104} // namespace webrtc