aboutsummaryrefslogtreecommitdiff
path: root/pc/video_rtp_receiver_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pc/video_rtp_receiver_unittest.cc')
-rw-r--r--pc/video_rtp_receiver_unittest.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/pc/video_rtp_receiver_unittest.cc b/pc/video_rtp_receiver_unittest.cc
index b3eb6e6e35..3a8099d30f 100644
--- a/pc/video_rtp_receiver_unittest.cc
+++ b/pc/video_rtp_receiver_unittest.cc
@@ -17,8 +17,10 @@
#include "test/gmock.h"
using ::testing::_;
+using ::testing::AnyNumber;
using ::testing::InSequence;
using ::testing::Mock;
+using ::testing::NiceMock;
using ::testing::SaveArg;
using ::testing::StrictMock;
@@ -29,9 +31,11 @@ class VideoRtpReceiverTest : public testing::Test {
protected:
class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
public:
- MockVideoMediaChannel(cricket::FakeVideoEngine* engine,
- const cricket::VideoOptions& options)
- : FakeVideoMediaChannel(engine, options) {}
+ MockVideoMediaChannel(
+ cricket::FakeVideoEngine* engine,
+ const cricket::VideoOptions& options,
+ TaskQueueBase* network_thread = rtc::Thread::Current())
+ : FakeVideoMediaChannel(engine, options, network_thread) {}
MOCK_METHOD(void,
SetRecordableEncodedFrameCallback,
(uint32_t, std::function<void(const RecordableEncodedFrame&)>),
@@ -51,19 +55,26 @@ class VideoRtpReceiverTest : public testing::Test {
VideoRtpReceiverTest()
: worker_thread_(rtc::Thread::Create()),
channel_(nullptr, cricket::VideoOptions()),
- receiver_(new VideoRtpReceiver(worker_thread_.get(),
- "receiver",
- {"stream"})) {
+ receiver_(rtc::make_ref_counted<VideoRtpReceiver>(
+ worker_thread_.get(),
+ std::string("receiver"),
+ std::vector<std::string>({"stream"}))) {
worker_thread_->Start();
receiver_->SetMediaChannel(&channel_);
}
+ ~VideoRtpReceiverTest() override {
+ // Clear expectations that tests may have set up before calling Stop().
+ Mock::VerifyAndClearExpectations(&channel_);
+ receiver_->Stop();
+ }
+
webrtc::VideoTrackSourceInterface* Source() {
return receiver_->streams()[0]->FindVideoTrack("receiver")->GetSource();
}
std::unique_ptr<rtc::Thread> worker_thread_;
- MockVideoMediaChannel channel_;
+ NiceMock<MockVideoMediaChannel> channel_;
rtc::scoped_refptr<VideoRtpReceiver> receiver_;
};
@@ -96,6 +107,10 @@ TEST_F(VideoRtpReceiverTest,
// Switching to a new channel should now not cause calls to GenerateKeyFrame.
StrictMock<MockVideoMediaChannel> channel4(nullptr, cricket::VideoOptions());
receiver_->SetMediaChannel(&channel4);
+
+ // We must call Stop() here since the mock media channels live on the stack
+ // and `receiver_` still has a pointer to those objects.
+ receiver_->Stop();
}
TEST_F(VideoRtpReceiverTest, EnablesEncodedOutput) {
@@ -129,6 +144,10 @@ TEST_F(VideoRtpReceiverTest, DisablesEnablesEncodedOutputOnChannelSwitch) {
Source()->RemoveEncodedSink(&sink);
StrictMock<MockVideoMediaChannel> channel3(nullptr, cricket::VideoOptions());
receiver_->SetMediaChannel(&channel3);
+
+ // We must call Stop() here since the mock media channels live on the stack
+ // and `receiver_` still has a pointer to those objects.
+ receiver_->Stop();
}
TEST_F(VideoRtpReceiverTest, BroadcastsEncodedFramesWhenEnabled) {