blob: 8f44c395d9e499ae02f5f68fbe568a95eea2b6ce [file] [log] [blame]
Steve Anton6f25b092017-10-23 09:39:20 -07001/*
2 * Copyright 2017 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
Karl Wiberg32df86e2017-11-03 10:24:27 +010011#include "api/audio_codecs/builtin_audio_decoder_factory.h"
12#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010013#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080014#include "api/peer_connection_proxy.h"
Anders Carlsson67537952018-05-03 11:28:29 +020015#include "api/video_codecs/builtin_video_decoder_factory.h"
16#include "api/video_codecs/builtin_video_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080017#include "p2p/base/fake_port_allocator.h"
18#include "p2p/base/test_stun_server.h"
19#include "p2p/client/basic_port_allocator.h"
20#include "pc/media_session.h"
21#include "pc/peer_connection.h"
22#include "pc/peer_connection_wrapper.h"
23#include "pc/sdp_utils.h"
Steve Anton6f25b092017-10-23 09:39:20 -070024#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080025#include "pc/test/android_test_initializer.h"
Steve Anton6f25b092017-10-23 09:39:20 -070026#endif
Karl Wiberg918f50c2018-07-05 11:40:33 +020027#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "pc/test/fake_audio_capture_module.h"
29#include "rtc_base/fake_network.h"
Steve Anton6f25b092017-10-23 09:39:20 -070030#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "rtc_base/virtual_socket_server.h"
Steve Anton6f25b092017-10-23 09:39:20 -070032#include "test/gmock.h"
33
34namespace webrtc {
35
36using BundlePolicy = PeerConnectionInterface::BundlePolicy;
37using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
38using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
39using RtcpMuxPolicy = PeerConnectionInterface::RtcpMuxPolicy;
40using rtc::SocketAddress;
Steve Anton7464fca2018-01-19 11:10:37 -080041using ::testing::Combine;
Steve Anton6f25b092017-10-23 09:39:20 -070042using ::testing::ElementsAre;
43using ::testing::UnorderedElementsAre;
44using ::testing::Values;
45
46constexpr int kDefaultTimeout = 10000;
47
48// TODO(steveanton): These tests should be rewritten to use the standard
49// RtpSenderInterface/DtlsTransportInterface objects once they're available in
50// the API. The RtpSender can be used to determine which transport a given media
51// will use: https://www.w3.org/TR/webrtc/#dom-rtcrtpsender-transport
Steve Anton7464fca2018-01-19 11:10:37 -080052// Should also be able to remove GetTransceiversForTesting at that point.
Steve Anton6f25b092017-10-23 09:39:20 -070053
Harald Alvestrandad88c882018-11-28 16:47:46 +010054class FakeNetworkManagerWithNoAnyNetwork : public rtc::FakeNetworkManager {
55 public:
56 void GetAnyAddressNetworks(NetworkList* networks) override {
57 // This function allocates networks that are owned by the
58 // NetworkManager. But some tests assume that they can release
59 // all networks independent of the network manager.
60 // In order to prevent use-after-free issues, don't allow this
61 // function to have any effect when run in tests.
62 RTC_LOG(LS_INFO) << "FakeNetworkManager::GetAnyAddressNetworks ignored";
63 }
64};
65
Steve Anton6f25b092017-10-23 09:39:20 -070066class PeerConnectionWrapperForBundleTest : public PeerConnectionWrapper {
67 public:
68 using PeerConnectionWrapper::PeerConnectionWrapper;
69
70 bool AddIceCandidateToMedia(cricket::Candidate* candidate,
71 cricket::MediaType media_type) {
72 auto* desc = pc()->remote_description()->description();
73 for (size_t i = 0; i < desc->contents().size(); i++) {
74 const auto& content = desc->contents()[i];
Steve Antonb1c1de12017-12-21 15:14:30 -080075 if (content.media_description()->type() == media_type) {
Steve Anton6f25b092017-10-23 09:39:20 -070076 candidate->set_transport_name(content.name);
Steve Anton27ab0e52018-07-23 15:11:53 -070077 std::unique_ptr<IceCandidateInterface> jsep_candidate =
78 CreateIceCandidate(content.name, i, *candidate);
79 return pc()->AddIceCandidate(jsep_candidate.get());
Steve Anton6f25b092017-10-23 09:39:20 -070080 }
81 }
82 RTC_NOTREACHED();
83 return false;
84 }
85
Zhi Huange830e682018-03-30 10:48:35 -070086 rtc::PacketTransportInternal* voice_rtp_transport() {
87 return (voice_channel() ? voice_channel()->rtp_packet_transport()
88 : nullptr);
Steve Anton6f25b092017-10-23 09:39:20 -070089 }
90
Zhi Huange830e682018-03-30 10:48:35 -070091 rtc::PacketTransportInternal* voice_rtcp_transport() {
92 return (voice_channel() ? voice_channel()->rtcp_packet_transport()
93 : nullptr);
Steve Anton6f25b092017-10-23 09:39:20 -070094 }
95
96 cricket::VoiceChannel* voice_channel() {
Steve Antonb8867112018-02-13 10:07:54 -080097 auto transceivers = GetInternalPeerConnection()->GetTransceiversInternal();
Steve Anton7464fca2018-01-19 11:10:37 -080098 for (auto transceiver : transceivers) {
Steve Anton69470252018-02-09 11:43:08 -080099 if (transceiver->media_type() == cricket::MEDIA_TYPE_AUDIO) {
Steve Anton7464fca2018-01-19 11:10:37 -0800100 return static_cast<cricket::VoiceChannel*>(
101 transceiver->internal()->channel());
102 }
103 }
104 return nullptr;
Steve Anton6f25b092017-10-23 09:39:20 -0700105 }
106
Zhi Huange830e682018-03-30 10:48:35 -0700107 rtc::PacketTransportInternal* video_rtp_transport() {
108 return (video_channel() ? video_channel()->rtp_packet_transport()
109 : nullptr);
Steve Anton6f25b092017-10-23 09:39:20 -0700110 }
111
Zhi Huange830e682018-03-30 10:48:35 -0700112 rtc::PacketTransportInternal* video_rtcp_transport() {
113 return (video_channel() ? video_channel()->rtcp_packet_transport()
114 : nullptr);
Steve Anton6f25b092017-10-23 09:39:20 -0700115 }
116
117 cricket::VideoChannel* video_channel() {
Steve Antonb8867112018-02-13 10:07:54 -0800118 auto transceivers = GetInternalPeerConnection()->GetTransceiversInternal();
Steve Anton7464fca2018-01-19 11:10:37 -0800119 for (auto transceiver : transceivers) {
Steve Anton69470252018-02-09 11:43:08 -0800120 if (transceiver->media_type() == cricket::MEDIA_TYPE_VIDEO) {
Steve Anton7464fca2018-01-19 11:10:37 -0800121 return static_cast<cricket::VideoChannel*>(
122 transceiver->internal()->channel());
123 }
124 }
125 return nullptr;
Steve Anton6f25b092017-10-23 09:39:20 -0700126 }
127
128 PeerConnection* GetInternalPeerConnection() {
Mirko Bonadeie97de912017-12-13 11:29:34 +0100129 auto* pci =
130 static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>(
131 pc());
132 return static_cast<PeerConnection*>(pci->internal());
Steve Anton6f25b092017-10-23 09:39:20 -0700133 }
134
135 // Returns true if the stats indicate that an ICE connection is either in
136 // progress or established with the given remote address.
137 bool HasConnectionWithRemoteAddress(const SocketAddress& address) {
138 auto report = GetStats();
139 if (!report) {
140 return false;
141 }
142 std::string matching_candidate_id;
143 for (auto* ice_candidate_stats :
144 report->GetStatsOfType<RTCRemoteIceCandidateStats>()) {
145 if (*ice_candidate_stats->ip == address.HostAsURIString() &&
146 *ice_candidate_stats->port == address.port()) {
147 matching_candidate_id = ice_candidate_stats->id();
148 break;
149 }
150 }
151 if (matching_candidate_id.empty()) {
152 return false;
153 }
154 for (auto* pair_stats :
155 report->GetStatsOfType<RTCIceCandidatePairStats>()) {
156 if (*pair_stats->remote_candidate_id == matching_candidate_id) {
157 if (*pair_stats->state == RTCStatsIceCandidatePairState::kInProgress ||
158 *pair_stats->state == RTCStatsIceCandidatePairState::kSucceeded) {
159 return true;
160 }
161 }
162 }
163 return false;
164 }
165
166 rtc::FakeNetworkManager* network() { return network_; }
167
168 void set_network(rtc::FakeNetworkManager* network) { network_ = network; }
169
170 private:
171 rtc::FakeNetworkManager* network_;
172};
173
Steve Anton7464fca2018-01-19 11:10:37 -0800174class PeerConnectionBundleBaseTest : public ::testing::Test {
Steve Anton6f25b092017-10-23 09:39:20 -0700175 protected:
176 typedef std::unique_ptr<PeerConnectionWrapperForBundleTest> WrapperPtr;
177
Steve Anton7464fca2018-01-19 11:10:37 -0800178 explicit PeerConnectionBundleBaseTest(SdpSemantics sdp_semantics)
179 : vss_(new rtc::VirtualSocketServer()),
180 main_(vss_.get()),
181 sdp_semantics_(sdp_semantics) {
Steve Anton6f25b092017-10-23 09:39:20 -0700182#ifdef WEBRTC_ANDROID
183 InitializeAndroidObjects();
184#endif
185 pc_factory_ = CreatePeerConnectionFactory(
186 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200187 rtc::scoped_refptr<AudioDeviceModule>(FakeAudioCaptureModule::Create()),
188 CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
189 CreateBuiltinVideoEncoderFactory(), CreateBuiltinVideoDecoderFactory(),
190 nullptr /* audio_mixer */, nullptr /* audio_processing */);
Steve Anton6f25b092017-10-23 09:39:20 -0700191 }
192
193 WrapperPtr CreatePeerConnection() {
194 return CreatePeerConnection(RTCConfiguration());
195 }
196
197 WrapperPtr CreatePeerConnection(const RTCConfiguration& config) {
198 auto* fake_network = NewFakeNetwork();
199 auto port_allocator =
Karl Wiberg918f50c2018-07-05 11:40:33 +0200200 absl::make_unique<cricket::BasicPortAllocator>(fake_network);
Steve Anton6f25b092017-10-23 09:39:20 -0700201 port_allocator->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
202 cricket::PORTALLOCATOR_DISABLE_RELAY);
203 port_allocator->set_step_delay(cricket::kMinimumStepDelay);
Karl Wiberg918f50c2018-07-05 11:40:33 +0200204 auto observer = absl::make_unique<MockPeerConnectionObserver>();
Steve Anton7464fca2018-01-19 11:10:37 -0800205 RTCConfiguration modified_config = config;
206 modified_config.sdp_semantics = sdp_semantics_;
Steve Anton6f25b092017-10-23 09:39:20 -0700207 auto pc = pc_factory_->CreatePeerConnection(
Steve Anton7464fca2018-01-19 11:10:37 -0800208 modified_config, std::move(port_allocator), nullptr, observer.get());
Steve Anton6f25b092017-10-23 09:39:20 -0700209 if (!pc) {
210 return nullptr;
211 }
212
Karl Wiberg918f50c2018-07-05 11:40:33 +0200213 auto wrapper = absl::make_unique<PeerConnectionWrapperForBundleTest>(
Steve Anton6f25b092017-10-23 09:39:20 -0700214 pc_factory_, pc, std::move(observer));
215 wrapper->set_network(fake_network);
216 return wrapper;
217 }
218
219 // Accepts the same arguments as CreatePeerConnection and adds default audio
220 // and video tracks.
221 template <typename... Args>
222 WrapperPtr CreatePeerConnectionWithAudioVideo(Args&&... args) {
223 auto wrapper = CreatePeerConnection(std::forward<Args>(args)...);
224 if (!wrapper) {
225 return nullptr;
226 }
227 wrapper->AddAudioTrack("a");
228 wrapper->AddVideoTrack("v");
229 return wrapper;
230 }
231
232 cricket::Candidate CreateLocalUdpCandidate(
233 const rtc::SocketAddress& address) {
234 cricket::Candidate candidate;
235 candidate.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
236 candidate.set_protocol(cricket::UDP_PROTOCOL_NAME);
237 candidate.set_address(address);
238 candidate.set_type(cricket::LOCAL_PORT_TYPE);
239 return candidate;
240 }
241
242 rtc::FakeNetworkManager* NewFakeNetwork() {
243 // The PeerConnection's port allocator is tied to the PeerConnection's
244 // lifetime and expects the underlying NetworkManager to outlive it. If
245 // PeerConnectionWrapper owned the NetworkManager, it would be destroyed
246 // before the PeerConnection (since subclass members are destroyed before
247 // base class members). Therefore, the test fixture will own all the fake
248 // networks even though tests should access the fake network through the
249 // PeerConnectionWrapper.
Harald Alvestrandad88c882018-11-28 16:47:46 +0100250 auto* fake_network = new FakeNetworkManagerWithNoAnyNetwork();
Steve Anton6f25b092017-10-23 09:39:20 -0700251 fake_networks_.emplace_back(fake_network);
252 return fake_network;
253 }
254
255 std::unique_ptr<rtc::VirtualSocketServer> vss_;
256 rtc::AutoSocketServerThread main_;
257 rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_;
258 std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_networks_;
Steve Anton7464fca2018-01-19 11:10:37 -0800259 const SdpSemantics sdp_semantics_;
260};
261
262class PeerConnectionBundleTest
263 : public PeerConnectionBundleBaseTest,
264 public ::testing::WithParamInterface<SdpSemantics> {
265 protected:
266 PeerConnectionBundleTest() : PeerConnectionBundleBaseTest(GetParam()) {}
Steve Anton6f25b092017-10-23 09:39:20 -0700267};
268
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700269class PeerConnectionBundleTestUnifiedPlan
270 : public PeerConnectionBundleBaseTest {
271 protected:
272 PeerConnectionBundleTestUnifiedPlan()
273 : PeerConnectionBundleBaseTest(SdpSemantics::kUnifiedPlan) {}
274};
275
Steve Anton6f25b092017-10-23 09:39:20 -0700276SdpContentMutator RemoveRtcpMux() {
277 return [](cricket::ContentInfo* content, cricket::TransportInfo* transport) {
Steve Antonb1c1de12017-12-21 15:14:30 -0800278 content->media_description()->set_rtcp_mux(false);
Steve Anton6f25b092017-10-23 09:39:20 -0700279 };
280}
281
282std::vector<int> GetCandidateComponents(
283 const std::vector<IceCandidateInterface*> candidates) {
284 std::vector<int> components;
285 for (auto* candidate : candidates) {
286 components.push_back(candidate->candidate().component());
287 }
288 return components;
289}
290
291// Test that there are 2 local UDP candidates (1 RTP and 1 RTCP candidate) for
292// each media section when disabling bundling and disabling RTCP multiplexing.
Steve Anton7464fca2018-01-19 11:10:37 -0800293TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700294 TwoCandidatesForEachTransportWhenNoBundleNoRtcpMux) {
295 const SocketAddress kCallerAddress("1.1.1.1", 0);
296 const SocketAddress kCalleeAddress("2.2.2.2", 0);
297
298 RTCConfiguration config;
299 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
300 auto caller = CreatePeerConnectionWithAudioVideo(config);
301 caller->network()->AddInterface(kCallerAddress);
302 auto callee = CreatePeerConnectionWithAudioVideo(config);
303 callee->network()->AddInterface(kCalleeAddress);
304
305 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
306 RTCOfferAnswerOptions options_no_bundle;
307 options_no_bundle.use_rtp_mux = false;
308 auto answer = callee->CreateAnswer(options_no_bundle);
309 SdpContentsForEach(RemoveRtcpMux(), answer->description());
310 ASSERT_TRUE(
311 callee->SetLocalDescription(CloneSessionDescription(answer.get())));
312 ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer)));
313
314 // Check that caller has separate RTP and RTCP candidates for each media.
315 EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeout);
316 EXPECT_THAT(
317 GetCandidateComponents(caller->observer()->GetCandidatesByMline(0)),
318 UnorderedElementsAre(cricket::ICE_CANDIDATE_COMPONENT_RTP,
319 cricket::ICE_CANDIDATE_COMPONENT_RTCP));
320 EXPECT_THAT(
321 GetCandidateComponents(caller->observer()->GetCandidatesByMline(1)),
322 UnorderedElementsAre(cricket::ICE_CANDIDATE_COMPONENT_RTP,
323 cricket::ICE_CANDIDATE_COMPONENT_RTCP));
324
325 // Check that callee has separate RTP and RTCP candidates for each media.
326 EXPECT_TRUE_WAIT(callee->IsIceGatheringDone(), kDefaultTimeout);
327 EXPECT_THAT(
328 GetCandidateComponents(callee->observer()->GetCandidatesByMline(0)),
329 UnorderedElementsAre(cricket::ICE_CANDIDATE_COMPONENT_RTP,
330 cricket::ICE_CANDIDATE_COMPONENT_RTCP));
331 EXPECT_THAT(
332 GetCandidateComponents(callee->observer()->GetCandidatesByMline(1)),
333 UnorderedElementsAre(cricket::ICE_CANDIDATE_COMPONENT_RTP,
334 cricket::ICE_CANDIDATE_COMPONENT_RTCP));
335}
336
337// Test that there is 1 local UDP candidate for both RTP and RTCP for each media
338// section when disabling bundle but enabling RTCP multiplexing.
Steve Anton7464fca2018-01-19 11:10:37 -0800339TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700340 OneCandidateForEachTransportWhenNoBundleButRtcpMux) {
341 const SocketAddress kCallerAddress("1.1.1.1", 0);
342
343 auto caller = CreatePeerConnectionWithAudioVideo();
344 caller->network()->AddInterface(kCallerAddress);
345 auto callee = CreatePeerConnectionWithAudioVideo();
346
347 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
348 RTCOfferAnswerOptions options_no_bundle;
349 options_no_bundle.use_rtp_mux = false;
350 ASSERT_TRUE(
351 caller->SetRemoteDescription(callee->CreateAnswer(options_no_bundle)));
352
353 EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeout);
354
355 EXPECT_EQ(1u, caller->observer()->GetCandidatesByMline(0).size());
356 EXPECT_EQ(1u, caller->observer()->GetCandidatesByMline(1).size());
357}
358
359// Test that there is 1 local UDP candidate in only the first media section when
360// bundling and enabling RTCP multiplexing.
Steve Anton7464fca2018-01-19 11:10:37 -0800361TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700362 OneCandidateOnlyOnFirstTransportWhenBundleAndRtcpMux) {
363 const SocketAddress kCallerAddress("1.1.1.1", 0);
364
365 RTCConfiguration config;
366 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
367 auto caller = CreatePeerConnectionWithAudioVideo(config);
368 caller->network()->AddInterface(kCallerAddress);
369 auto callee = CreatePeerConnectionWithAudioVideo(config);
370
371 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
372 ASSERT_TRUE(caller->SetRemoteDescription(callee->CreateAnswer()));
373
374 EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeout);
375
376 EXPECT_EQ(1u, caller->observer()->GetCandidatesByMline(0).size());
377 EXPECT_EQ(0u, caller->observer()->GetCandidatesByMline(1).size());
378}
379
Zhi Huange830e682018-03-30 10:48:35 -0700380// It will fail if the offerer uses the mux-BUNDLE policy but the answerer
381// doesn't support BUNDLE.
382TEST_P(PeerConnectionBundleTest, MaxBundleNotSupportedInAnswer) {
383 RTCConfiguration config;
384 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
385 auto caller = CreatePeerConnectionWithAudioVideo(config);
386 auto callee = CreatePeerConnectionWithAudioVideo();
387
388 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
389 bool equal_before =
390 (caller->voice_rtp_transport() == caller->video_rtp_transport());
391 EXPECT_EQ(true, equal_before);
392 RTCOfferAnswerOptions options;
393 options.use_rtp_mux = false;
394 EXPECT_FALSE(
395 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(options)));
396}
397
Steve Anton6f25b092017-10-23 09:39:20 -0700398// The following parameterized test verifies that an offer/answer with varying
399// bundle policies and either bundle in the answer or not will produce the
400// expected RTP transports for audio and video. In particular, for bundling we
401// care about whether they are separate transports or the same.
402
403enum class BundleIncluded { kBundleInAnswer, kBundleNotInAnswer };
404std::ostream& operator<<(std::ostream& out, BundleIncluded value) {
405 switch (value) {
406 case BundleIncluded::kBundleInAnswer:
407 return out << "bundle in answer";
408 case BundleIncluded::kBundleNotInAnswer:
409 return out << "bundle not in answer";
410 }
411 return out << "unknown";
412}
413
414class PeerConnectionBundleMatrixTest
Steve Anton7464fca2018-01-19 11:10:37 -0800415 : public PeerConnectionBundleBaseTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700416 public ::testing::WithParamInterface<
Steve Anton7464fca2018-01-19 11:10:37 -0800417 std::tuple<SdpSemantics,
418 std::tuple<BundlePolicy, BundleIncluded, bool, bool>>> {
Steve Anton6f25b092017-10-23 09:39:20 -0700419 protected:
Steve Anton7464fca2018-01-19 11:10:37 -0800420 PeerConnectionBundleMatrixTest()
421 : PeerConnectionBundleBaseTest(std::get<0>(GetParam())) {
422 auto param = std::get<1>(GetParam());
423 bundle_policy_ = std::get<0>(param);
424 bundle_included_ = std::get<1>(param);
425 expected_same_before_ = std::get<2>(param);
426 expected_same_after_ = std::get<3>(param);
Steve Anton6f25b092017-10-23 09:39:20 -0700427 }
428
429 PeerConnectionInterface::BundlePolicy bundle_policy_;
430 BundleIncluded bundle_included_;
431 bool expected_same_before_;
432 bool expected_same_after_;
433};
434
435TEST_P(PeerConnectionBundleMatrixTest,
436 VerifyTransportsBeforeAndAfterSettingRemoteAnswer) {
437 RTCConfiguration config;
438 config.bundle_policy = bundle_policy_;
439 auto caller = CreatePeerConnectionWithAudioVideo(config);
440 auto callee = CreatePeerConnectionWithAudioVideo();
441
442 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
Zhi Huange830e682018-03-30 10:48:35 -0700443 bool equal_before =
444 (caller->voice_rtp_transport() == caller->video_rtp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700445 EXPECT_EQ(expected_same_before_, equal_before);
446
447 RTCOfferAnswerOptions options;
448 options.use_rtp_mux = (bundle_included_ == BundleIncluded::kBundleInAnswer);
449 ASSERT_TRUE(
450 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(options)));
Zhi Huange830e682018-03-30 10:48:35 -0700451 bool equal_after =
452 (caller->voice_rtp_transport() == caller->video_rtp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700453 EXPECT_EQ(expected_same_after_, equal_after);
454}
455
456// The max-bundle policy means we should anticipate bundling being negotiated,
457// and multiplex audio/video from the start.
458// For all other policies, bundling should only be enabled if negotiated by the
459// answer.
460INSTANTIATE_TEST_CASE_P(
461 PeerConnectionBundleTest,
462 PeerConnectionBundleMatrixTest,
Steve Anton7464fca2018-01-19 11:10:37 -0800463 Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan),
464 Values(std::make_tuple(BundlePolicy::kBundlePolicyBalanced,
465 BundleIncluded::kBundleInAnswer,
466 false,
467 true),
468 std::make_tuple(BundlePolicy::kBundlePolicyBalanced,
469 BundleIncluded::kBundleNotInAnswer,
470 false,
471 false),
472 std::make_tuple(BundlePolicy::kBundlePolicyMaxBundle,
473 BundleIncluded::kBundleInAnswer,
474 true,
475 true),
Steve Anton7464fca2018-01-19 11:10:37 -0800476 std::make_tuple(BundlePolicy::kBundlePolicyMaxCompat,
477 BundleIncluded::kBundleInAnswer,
478 false,
479 true),
480 std::make_tuple(BundlePolicy::kBundlePolicyMaxCompat,
481 BundleIncluded::kBundleNotInAnswer,
482 false,
483 false))));
Steve Anton6f25b092017-10-23 09:39:20 -0700484
485// Test that the audio/video transports on the callee side are the same before
486// and after setting a local answer when max BUNDLE is enabled and an offer with
487// BUNDLE is received.
Steve Anton7464fca2018-01-19 11:10:37 -0800488TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700489 TransportsSameForMaxBundleWithBundleInRemoteOffer) {
490 auto caller = CreatePeerConnectionWithAudioVideo();
491 RTCConfiguration config;
492 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
493 auto callee = CreatePeerConnectionWithAudioVideo(config);
494
495 RTCOfferAnswerOptions options_with_bundle;
496 options_with_bundle.use_rtp_mux = true;
497 ASSERT_TRUE(callee->SetRemoteDescription(
498 caller->CreateOfferAndSetAsLocal(options_with_bundle)));
499
Zhi Huange830e682018-03-30 10:48:35 -0700500 EXPECT_EQ(callee->voice_rtp_transport(), callee->video_rtp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700501
502 ASSERT_TRUE(callee->SetLocalDescription(callee->CreateAnswer()));
503
Zhi Huange830e682018-03-30 10:48:35 -0700504 EXPECT_EQ(callee->voice_rtp_transport(), callee->video_rtp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700505}
506
Steve Anton7464fca2018-01-19 11:10:37 -0800507TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700508 FailToSetRemoteOfferWithNoBundleWhenBundlePolicyMaxBundle) {
509 auto caller = CreatePeerConnectionWithAudioVideo();
510 RTCConfiguration config;
511 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
512 auto callee = CreatePeerConnectionWithAudioVideo(config);
513
514 RTCOfferAnswerOptions options_no_bundle;
515 options_no_bundle.use_rtp_mux = false;
516 EXPECT_FALSE(callee->SetRemoteDescription(
517 caller->CreateOfferAndSetAsLocal(options_no_bundle)));
518}
519
520// Test that if the media section which has the bundled transport is rejected,
521// then the peers still connect and the bundled transport switches to the other
522// media section.
523// Note: This is currently failing because of the following bug:
524// https://bugs.chromium.org/p/webrtc/issues/detail?id=6280
Steve Anton7464fca2018-01-19 11:10:37 -0800525TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700526 DISABLED_SuccessfullyNegotiateMaxBundleIfBundleTransportMediaRejected) {
527 RTCConfiguration config;
528 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
529 auto caller = CreatePeerConnectionWithAudioVideo(config);
530 auto callee = CreatePeerConnection();
531 callee->AddVideoTrack("v");
532
533 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
534
535 RTCOfferAnswerOptions options;
536 options.offer_to_receive_audio = 0;
537 ASSERT_TRUE(
538 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(options)));
539
Zhi Huange830e682018-03-30 10:48:35 -0700540 EXPECT_FALSE(caller->voice_rtp_transport());
541 EXPECT_TRUE(caller->video_rtp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700542}
543
544// When requiring RTCP multiplexing, the PeerConnection never makes RTCP
545// transport channels.
Steve Anton7464fca2018-01-19 11:10:37 -0800546TEST_P(PeerConnectionBundleTest, NeverCreateRtcpTransportWithRtcpMuxRequired) {
Steve Anton6f25b092017-10-23 09:39:20 -0700547 RTCConfiguration config;
548 config.rtcp_mux_policy = RtcpMuxPolicy::kRtcpMuxPolicyRequire;
549 auto caller = CreatePeerConnectionWithAudioVideo(config);
550 auto callee = CreatePeerConnectionWithAudioVideo();
551
552 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
553
Zhi Huange830e682018-03-30 10:48:35 -0700554 EXPECT_FALSE(caller->voice_rtcp_transport());
555 EXPECT_FALSE(caller->video_rtcp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700556
557 ASSERT_TRUE(
558 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
559
Zhi Huange830e682018-03-30 10:48:35 -0700560 EXPECT_FALSE(caller->voice_rtcp_transport());
561 EXPECT_FALSE(caller->video_rtcp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700562}
563
Zhi Huange830e682018-03-30 10:48:35 -0700564// When negotiating RTCP multiplexing, the PeerConnection makes RTCP transports
565// when the offer is sent, but will destroy them once the remote answer is set.
Steve Anton7464fca2018-01-19 11:10:37 -0800566TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700567 CreateRtcpTransportOnlyBeforeAnswerWithRtcpMuxNegotiate) {
568 RTCConfiguration config;
569 config.rtcp_mux_policy = RtcpMuxPolicy::kRtcpMuxPolicyNegotiate;
570 auto caller = CreatePeerConnectionWithAudioVideo(config);
571 auto callee = CreatePeerConnectionWithAudioVideo();
572
573 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
574
Zhi Huange830e682018-03-30 10:48:35 -0700575 EXPECT_TRUE(caller->voice_rtcp_transport());
576 EXPECT_TRUE(caller->video_rtcp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700577
578 ASSERT_TRUE(
579 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
580
Zhi Huange830e682018-03-30 10:48:35 -0700581 EXPECT_FALSE(caller->voice_rtcp_transport());
582 EXPECT_FALSE(caller->video_rtcp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700583}
584
Steve Anton7464fca2018-01-19 11:10:37 -0800585TEST_P(PeerConnectionBundleTest, FailToSetDescriptionWithBundleAndNoRtcpMux) {
Steve Anton6f25b092017-10-23 09:39:20 -0700586 auto caller = CreatePeerConnectionWithAudioVideo();
587 auto callee = CreatePeerConnectionWithAudioVideo();
588
589 RTCOfferAnswerOptions options;
590 options.use_rtp_mux = true;
591
592 auto offer = caller->CreateOffer(options);
593 SdpContentsForEach(RemoveRtcpMux(), offer->description());
594
595 std::string error;
596 EXPECT_FALSE(caller->SetLocalDescription(CloneSessionDescription(offer.get()),
597 &error));
598 EXPECT_EQ(
599 "Failed to set local offer sdp: rtcp-mux must be enabled when BUNDLE is "
600 "enabled.",
601 error);
602
603 EXPECT_FALSE(callee->SetRemoteDescription(std::move(offer), &error));
604 EXPECT_EQ(
605 "Failed to set remote offer sdp: rtcp-mux must be enabled when BUNDLE is "
606 "enabled.",
607 error);
608}
609
610// Test that candidates sent to the "video" transport do not get pushed down to
611// the "audio" transport channel when bundling.
Steve Anton7464fca2018-01-19 11:10:37 -0800612TEST_P(PeerConnectionBundleTest,
Steve Anton6f25b092017-10-23 09:39:20 -0700613 IgnoreCandidatesForUnusedTransportWhenBundling) {
614 const SocketAddress kAudioAddress1("1.1.1.1", 1111);
615 const SocketAddress kAudioAddress2("2.2.2.2", 2222);
616 const SocketAddress kVideoAddress("3.3.3.3", 3333);
617 const SocketAddress kCallerAddress("4.4.4.4", 0);
618 const SocketAddress kCalleeAddress("5.5.5.5", 0);
619
620 auto caller = CreatePeerConnectionWithAudioVideo();
621 auto callee = CreatePeerConnectionWithAudioVideo();
622
623 caller->network()->AddInterface(kCallerAddress);
624 callee->network()->AddInterface(kCalleeAddress);
625
626 RTCOfferAnswerOptions options;
627 options.use_rtp_mux = true;
628
629 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
630 ASSERT_TRUE(
Zhi Huange830e682018-03-30 10:48:35 -0700631 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(options)));
Steve Anton6f25b092017-10-23 09:39:20 -0700632
633 // The way the *_WAIT checks work is they only wait if the condition fails,
634 // which does not help in the case where state is not changing. This is
635 // problematic in this test since we want to verify that adding a video
636 // candidate does _not_ change state. So we interleave candidates and assume
637 // that messages are executed in the order they were posted.
638
639 cricket::Candidate audio_candidate1 = CreateLocalUdpCandidate(kAudioAddress1);
640 ASSERT_TRUE(caller->AddIceCandidateToMedia(&audio_candidate1,
641 cricket::MEDIA_TYPE_AUDIO));
642
643 cricket::Candidate video_candidate = CreateLocalUdpCandidate(kVideoAddress);
644 ASSERT_TRUE(caller->AddIceCandidateToMedia(&video_candidate,
645 cricket::MEDIA_TYPE_VIDEO));
646
647 cricket::Candidate audio_candidate2 = CreateLocalUdpCandidate(kAudioAddress2);
648 ASSERT_TRUE(caller->AddIceCandidateToMedia(&audio_candidate2,
649 cricket::MEDIA_TYPE_AUDIO));
650
651 EXPECT_TRUE_WAIT(caller->HasConnectionWithRemoteAddress(kAudioAddress1),
652 kDefaultTimeout);
653 EXPECT_TRUE_WAIT(caller->HasConnectionWithRemoteAddress(kAudioAddress2),
654 kDefaultTimeout);
655 EXPECT_FALSE(caller->HasConnectionWithRemoteAddress(kVideoAddress));
656}
657
658// Test that the transport used by both audio and video is the transport
659// associated with the first MID in the answer BUNDLE group, even if it's in a
660// different order from the offer.
Steve Anton7464fca2018-01-19 11:10:37 -0800661TEST_P(PeerConnectionBundleTest, BundleOnFirstMidInAnswer) {
Steve Anton6f25b092017-10-23 09:39:20 -0700662 auto caller = CreatePeerConnectionWithAudioVideo();
663 auto callee = CreatePeerConnectionWithAudioVideo();
664
665 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
666
Zhi Huange830e682018-03-30 10:48:35 -0700667 auto* old_video_transport = caller->video_rtp_transport();
Steve Anton6f25b092017-10-23 09:39:20 -0700668
669 auto answer = callee->CreateAnswer();
670 auto* old_bundle_group =
671 answer->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
Steve Anton7464fca2018-01-19 11:10:37 -0800672 std::string first_mid = old_bundle_group->content_names()[0];
673 std::string second_mid = old_bundle_group->content_names()[1];
Steve Anton6f25b092017-10-23 09:39:20 -0700674 answer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
675
676 cricket::ContentGroup new_bundle_group(cricket::GROUP_TYPE_BUNDLE);
Steve Anton7464fca2018-01-19 11:10:37 -0800677 new_bundle_group.AddContentName(second_mid);
678 new_bundle_group.AddContentName(first_mid);
Steve Anton6f25b092017-10-23 09:39:20 -0700679 answer->description()->AddGroup(new_bundle_group);
680
681 ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer)));
682
Zhi Huange830e682018-03-30 10:48:35 -0700683 EXPECT_EQ(old_video_transport, caller->video_rtp_transport());
684 EXPECT_EQ(caller->voice_rtp_transport(), caller->video_rtp_transport());
Steve Anton6f25b092017-10-23 09:39:20 -0700685}
686
Zhi Huang365381f2018-04-13 16:44:34 -0700687// This tests that applying description with conflicted RTP demuxing criteria
688// will fail.
689TEST_P(PeerConnectionBundleTest,
690 ApplyDescriptionWithConflictedDemuxCriteriaFail) {
691 auto caller = CreatePeerConnectionWithAudioVideo();
692 auto callee = CreatePeerConnectionWithAudioVideo();
693
694 RTCOfferAnswerOptions options;
695 options.use_rtp_mux = false;
696 auto offer = caller->CreateOffer(options);
697 // Modified the SDP to make two m= sections have the same SSRC.
698 ASSERT_GE(offer->description()->contents().size(), 2U);
699 offer->description()
700 ->contents()[0]
701 .description->mutable_streams()[0]
702 .ssrcs[0] = 1111222;
703 offer->description()
704 ->contents()[1]
705 .description->mutable_streams()[0]
706 .ssrcs[0] = 1111222;
707 EXPECT_TRUE(
708 caller->SetLocalDescription(CloneSessionDescription(offer.get())));
709 EXPECT_TRUE(callee->SetRemoteDescription(std::move(offer)));
710 EXPECT_TRUE(callee->CreateAnswerAndSetAsLocal(options));
711
712 // Enable BUNDLE in subsequent offer/answer exchange and two m= sections are
713 // expectd to use one RtpTransport underneath.
714 options.use_rtp_mux = true;
715 EXPECT_TRUE(
716 callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal(options)));
717 auto answer = callee->CreateAnswer(options);
718 // When BUNDLE is enabled, applying the description is expected to fail
719 // because the demuxing criteria is conflicted.
720 EXPECT_FALSE(callee->SetLocalDescription(std::move(answer)));
721}
722
Zhi Huangd2248f82018-04-10 14:41:03 -0700723// This tests that changing the pre-negotiated BUNDLE tag is not supported.
724TEST_P(PeerConnectionBundleTest, RejectDescriptionChangingBundleTag) {
725 RTCConfiguration config;
726 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
727 auto caller = CreatePeerConnectionWithAudioVideo(config);
728 auto callee = CreatePeerConnectionWithAudioVideo(config);
729
730 RTCOfferAnswerOptions options;
731 options.use_rtp_mux = true;
732 auto offer = caller->CreateOfferAndSetAsLocal(options);
733
734 // Create a new bundle-group with different bundled_mid.
735 auto* old_bundle_group =
736 offer->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
737 std::string first_mid = old_bundle_group->content_names()[0];
738 std::string second_mid = old_bundle_group->content_names()[1];
739 cricket::ContentGroup new_bundle_group(cricket::GROUP_TYPE_BUNDLE);
740 new_bundle_group.AddContentName(second_mid);
741
742 auto re_offer = CloneSessionDescription(offer.get());
743 callee->SetRemoteDescription(std::move(offer));
744 auto answer = callee->CreateAnswer(options);
745 // Reject the first MID.
746 answer->description()->contents()[0].rejected = true;
747 // Remove the first MID from the bundle group.
748 answer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
749 answer->description()->AddGroup(new_bundle_group);
750 // The answer is expected to be rejected.
751 EXPECT_FALSE(caller->SetRemoteDescription(std::move(answer)));
752
753 // Do the same thing for re-offer.
754 re_offer->description()->contents()[0].rejected = true;
755 re_offer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
756 re_offer->description()->AddGroup(new_bundle_group);
757 // The re-offer is expected to be rejected.
758 EXPECT_FALSE(caller->SetLocalDescription(std::move(re_offer)));
759}
760
761// This tests that removing contents from BUNDLE group and reject the whole
762// BUNDLE group could work. This is a regression test for
763// (https://bugs.chromium.org/p/chromium/issues/detail?id=827917)
764TEST_P(PeerConnectionBundleTest, RemovingContentAndRejectBundleGroup) {
765 RTCConfiguration config;
766#ifndef HAVE_SCTP
767 config.enable_rtp_data_channel = true;
768#endif
769 config.bundle_policy = BundlePolicy::kBundlePolicyMaxBundle;
770 auto caller = CreatePeerConnectionWithAudioVideo(config);
771 caller->CreateDataChannel("dc");
772
773 auto offer = caller->CreateOfferAndSetAsLocal();
774 auto re_offer = CloneSessionDescription(offer.get());
775
776 // Removing the second MID from the BUNDLE group.
777 auto* old_bundle_group =
778 offer->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
779 std::string first_mid = old_bundle_group->content_names()[0];
780 std::string third_mid = old_bundle_group->content_names()[2];
781 cricket::ContentGroup new_bundle_group(cricket::GROUP_TYPE_BUNDLE);
782 new_bundle_group.AddContentName(first_mid);
783 new_bundle_group.AddContentName(third_mid);
784
785 // Reject the entire new bundle group.
786 re_offer->description()->contents()[0].rejected = true;
787 re_offer->description()->contents()[2].rejected = true;
788 re_offer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
789 re_offer->description()->AddGroup(new_bundle_group);
790
791 EXPECT_TRUE(caller->SetLocalDescription(std::move(re_offer)));
792}
793
794// This tests that the BUNDLE group in answer should be a subset of the offered
795// group.
796TEST_P(PeerConnectionBundleTest, AddContentToBundleGroupInAnswerNotSupported) {
797 auto caller = CreatePeerConnectionWithAudioVideo();
798 auto callee = CreatePeerConnectionWithAudioVideo();
799
800 auto offer = caller->CreateOffer();
801 std::string first_mid = offer->description()->contents()[0].name;
802 std::string second_mid = offer->description()->contents()[1].name;
803
804 cricket::ContentGroup bundle_group(cricket::GROUP_TYPE_BUNDLE);
805 bundle_group.AddContentName(first_mid);
806 offer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
807 offer->description()->AddGroup(bundle_group);
808 EXPECT_TRUE(
809 caller->SetLocalDescription(CloneSessionDescription(offer.get())));
810 EXPECT_TRUE(callee->SetRemoteDescription(std::move(offer)));
811
812 auto answer = callee->CreateAnswer();
813 bundle_group.AddContentName(second_mid);
814 answer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
815 answer->description()->AddGroup(bundle_group);
816
817 // The answer is expected to be rejected because second mid is not in the
818 // offered BUNDLE group.
819 EXPECT_FALSE(callee->SetLocalDescription(std::move(answer)));
820}
821
822// This tests that the BUNDLE group with non-existing MID should be rejectd.
823TEST_P(PeerConnectionBundleTest, RejectBundleGroupWithNonExistingMid) {
824 auto caller = CreatePeerConnectionWithAudioVideo();
825 auto callee = CreatePeerConnectionWithAudioVideo();
826
827 auto offer = caller->CreateOffer();
828 auto invalid_bundle_group =
829 *offer->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
830 invalid_bundle_group.AddContentName("non-existing-MID");
831 offer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
832 offer->description()->AddGroup(invalid_bundle_group);
833
834 EXPECT_FALSE(
835 caller->SetLocalDescription(CloneSessionDescription(offer.get())));
836 EXPECT_FALSE(callee->SetRemoteDescription(std::move(offer)));
837}
838
839// This tests that an answer shouldn't be able to remove an m= section from an
840// established group without rejecting it.
841TEST_P(PeerConnectionBundleTest, RemoveContentFromBundleGroup) {
842 auto caller = CreatePeerConnectionWithAudioVideo();
843 auto callee = CreatePeerConnectionWithAudioVideo();
844
845 EXPECT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
846 EXPECT_TRUE(
847 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
848
849 EXPECT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
850 auto answer = callee->CreateAnswer();
851 std::string second_mid = answer->description()->contents()[1].name;
852
853 auto invalid_bundle_group =
854 *answer->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
855 invalid_bundle_group.RemoveContentName(second_mid);
856 answer->description()->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
857 answer->description()->AddGroup(invalid_bundle_group);
858
859 EXPECT_FALSE(
860 callee->SetLocalDescription(CloneSessionDescription(answer.get())));
861}
862
Steve Anton7464fca2018-01-19 11:10:37 -0800863INSTANTIATE_TEST_CASE_P(PeerConnectionBundleTest,
864 PeerConnectionBundleTest,
865 Values(SdpSemantics::kPlanB,
866 SdpSemantics::kUnifiedPlan));
867
Taylor Brandstetter0ab56512018-04-12 10:30:48 -0700868// According to RFC5888, if an endpoint understands the semantics of an
869// "a=group", it MUST return an answer with that group. So, an empty BUNDLE
870// group is valid when the answerer rejects all m= sections (by stopping all
871// transceivers), meaning there's nothing to bundle.
872//
873// Only writing this test for Unified Plan mode, since there's no way to reject
874// m= sections in answers for Plan B without SDP munging.
875TEST_F(PeerConnectionBundleTestUnifiedPlan,
876 EmptyBundleGroupCreatedInAnswerWhenAppropriate) {
877 auto caller = CreatePeerConnectionWithAudioVideo();
878 auto callee = CreatePeerConnection();
879
880 EXPECT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
881
882 // Stop all transceivers, causing all m= sections to be rejected.
883 for (const auto& transceiver : callee->pc()->GetTransceivers()) {
884 transceiver->Stop();
885 }
886 EXPECT_TRUE(
887 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
888
889 // Verify that the answer actually contained an empty bundle group.
890 const SessionDescriptionInterface* desc = callee->pc()->local_description();
891 ASSERT_NE(nullptr, desc);
892 const cricket::ContentGroup* bundle_group =
893 desc->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE);
894 ASSERT_NE(nullptr, bundle_group);
895 EXPECT_TRUE(bundle_group->content_names().empty());
896}
897
Steve Anton6f25b092017-10-23 09:39:20 -0700898} // namespace webrtc