Add test for PR-Answer functionality

Bug: None
Change-Id: I29bf1e40d47361917eb6f52424df23f7697bde0d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360721
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42859}
This commit is contained in:
Harald Alvestrand 2024-08-27 07:25:00 +00:00 committed by WebRTC LUCI CQ
parent fd90f1aa05
commit 90e0829c59
2 changed files with 35 additions and 4 deletions

View File

@ -3872,6 +3872,21 @@ TEST_F(PeerConnectionIntegrationTestUnifiedPlan, VideoPacketLossCausesNack) {
EXPECT_TRUE_WAIT(NacksReceivedCount(*caller()) > 0, kDefaultTimeout);
}
TEST_F(PeerConnectionIntegrationTestUnifiedPlan, PrAnswerStateTransitions) {
RTCConfiguration config;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
ConnectFakeSignaling();
caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack());
callee()->SetAnswerWithPrAnswer(true);
caller()->CreateAndSetAndSignalOffer();
ASSERT_FALSE(HasFailure());
EXPECT_EQ(caller()->pc()->signaling_state(),
PeerConnectionInterface::kHaveRemotePrAnswer);
EXPECT_EQ(callee()->pc()->signaling_state(),
PeerConnectionInterface::kHaveLocalPrAnswer);
// Note: there should be code here for applying the permanent answer.
}
} // namespace
} // namespace webrtc

View File

@ -455,6 +455,10 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
return data_observers_;
}
std::unique_ptr<SessionDescriptionInterface> CreateAnswerForTest() {
return CreateAnswer();
}
int audio_frames_received() const {
return fake_audio_capture_module_->frames_received();
}
@ -654,6 +658,10 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
candidates_expected_ = candidate_count;
}
// For testing PR-Answer functionality
// If true, an offer will get a pr-answer back.
void SetAnswerWithPrAnswer(bool value) { answer_with_pr_answer_ = value; }
private:
// Constructor used by friend class PeerConnectionIntegrationBaseTest.
explicit PeerConnectionIntegrationWrapper(const std::string& debug_name)
@ -740,13 +748,19 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
}
auto answer = CreateAnswer();
ASSERT_NE(nullptr, answer);
if (answer_with_pr_answer_) {
std::string answer_string;
answer->ToString(&answer_string);
answer = CreateSessionDescription(SdpType::kPrAnswer, answer_string);
}
EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer)));
}
void HandleIncomingAnswer(const std::string& msg) {
RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer";
void HandleIncomingAnswer(SdpType type, const std::string& msg) {
RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer of type "
<< SdpTypeToString(type);
std::unique_ptr<SessionDescriptionInterface> desc =
CreateSessionDescription(SdpType::kAnswer, msg);
CreateSessionDescription(type, msg);
if (received_sdp_munger_) {
received_sdp_munger_(desc->description());
}
@ -888,7 +902,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
if (type == SdpType::kOffer) {
HandleIncomingOffer(msg);
} else {
HandleIncomingAnswer(msg);
HandleIncomingAnswer(type, msg);
}
}
@ -1083,6 +1097,8 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
uint64_t audio_concealed_stat_ = 0;
std::string rtp_stats_id_;
bool answer_with_pr_answer_ = false;
ScopedTaskSafety task_safety_;
friend class PeerConnectionIntegrationBaseTest;