blob: 104e3f41ea069ef906c94e4f59085255f95a0c80 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "api/peer_connection_interface.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <limits.h>
14#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080017#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010018#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
Steve Anton1c9c9fc2019-02-14 15:13:09 -080020#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "absl/types/optional.h"
22#include "api/audio/audio_mixer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "api/audio_codecs/builtin_audio_decoder_factory.h"
24#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010026#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/media_stream_interface.h"
30#include "api/media_types.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "api/rtc_error.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020032#include "api/rtc_event_log/rtc_event_log.h"
33#include "api/rtc_event_log/rtc_event_log_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "api/rtc_event_log_output.h"
35#include "api/rtp_receiver_interface.h"
36#include "api/rtp_sender_interface.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000037#include "api/rtp_transceiver_direction.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010038#include "api/scoped_refptr.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020039#include "api/task_queue/default_task_queue_factory.h"
Erik Språngceb44952020-09-22 11:36:35 +020040#include "api/transport/field_trial_based_config.h"
Anders Carlsson67537952018-05-03 11:28:29 +020041#include "api/video_codecs/builtin_video_decoder_factory.h"
42#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010043#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080044#include "media/base/media_config.h"
45#include "media/base/media_engine.h"
46#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080047#include "media/engine/webrtc_media_engine.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020048#include "media/engine/webrtc_media_engine_defaults.h"
Steve Anton10542f22019-01-11 09:11:00 -080049#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010050#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080052#include "p2p/base/fake_port_allocator.h"
53#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010054#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080055#include "p2p/base/port_allocator.h"
56#include "p2p/base/transport_description.h"
57#include "p2p/base/transport_info.h"
58#include "pc/audio_track.h"
59#include "pc/media_session.h"
60#include "pc/media_stream.h"
61#include "pc/peer_connection.h"
62#include "pc/peer_connection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080063#include "pc/rtp_sender.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000064#include "pc/rtp_sender_proxy.h"
Steve Anton10542f22019-01-11 09:11:00 -080065#include "pc/session_description.h"
66#include "pc/stream_collection.h"
67#include "pc/test/fake_audio_capture_module.h"
68#include "pc/test/fake_rtc_certificate_generator.h"
69#include "pc/test/fake_video_track_source.h"
70#include "pc/test/mock_peer_connection_observers.h"
71#include "pc/test/test_sdp_strings.h"
72#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010073#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 09:11:00 -080075#include "rtc_base/ref_counted_object.h"
76#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080077#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010078#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080079#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010081#include "test/gtest.h"
kwibergac9f8762016-09-30 22:29:43 -070082
83#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080084#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070085#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010087namespace webrtc {
88namespace {
89
Seth Hampson845e8782018-03-02 11:34:10 -080090static const char kStreamId1[] = "local_stream_1";
91static const char kStreamId2[] = "local_stream_2";
92static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const int kDefaultStunPort = 3478;
94static const char kStunAddressOnly[] = "stun:address";
95static const char kStunInvalidPort[] = "stun:address:-1";
96static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
97static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 16:53:59 +010098static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099static const char kTurnUsername[] = "user";
100static const char kTurnPassword[] = "password";
101static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
deadbeefab9b2d12015-10-14 11:33:11 -0700104static const char kStreams[][8] = {"stream1", "stream2"};
105static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
106static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
107
deadbeef5e97fb52015-10-15 12:49:08 -0700108static const char kRecvonly[] = "recvonly";
109static const char kSendrecv[] = "sendrecv";
110
deadbeefab9b2d12015-10-14 11:33:11 -0700111// Reference SDP with a MediaStream with label "stream1" and audio track with
112// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800113static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700114 "v=0\r\n"
115 "o=- 0 0 IN IP4 127.0.0.1\r\n"
116 "s=-\r\n"
117 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800118 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700119 "a=ice-ufrag:e5785931\r\n"
120 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
121 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
122 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700123 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700124 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800125 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700126 "a=rtpmap:103 ISAC/16000\r\n"
127 "a=ssrc:1 cname:stream1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000128 "a=ssrc:1 mslabel:stream1\r\n"
129 "a=ssrc:1 label:audiotrack0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700130 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800131 "a=ice-ufrag:e5785931\r\n"
132 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
133 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
134 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700136 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800137 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700138 "a=rtpmap:120 VP8/90000\r\n"
139 "a=ssrc:2 cname:stream1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000140 "a=ssrc:2 mslabel:stream1\r\n"
141 "a=ssrc:2 label:videotrack0\r\n";
142// Same string as above but with the MID changed to the Unified Plan default.
143// This is needed so that this SDP can be used as an answer for a Unified Plan
144// offer.
Steve Anton36da6ff2018-02-16 16:04:20 -0800145static const char kSdpStringWithStream1UnifiedPlan[] =
146 "v=0\r\n"
147 "o=- 0 0 IN IP4 127.0.0.1\r\n"
148 "s=-\r\n"
149 "t=0 0\r\n"
150 "m=audio 1 RTP/AVPF 103\r\n"
151 "a=ice-ufrag:e5785931\r\n"
152 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
153 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
154 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
155 "a=mid:0\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
158 "a=rtpmap:103 ISAC/16000\r\n"
159 "a=ssrc:1 cname:stream1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000160 "a=ssrc:1 mslabel:stream1\r\n"
161 "a=ssrc:1 label:audiotrack0\r\n"
Steve Anton36da6ff2018-02-16 16:04:20 -0800162 "m=video 1 RTP/AVPF 120\r\n"
163 "a=ice-ufrag:e5785931\r\n"
164 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
165 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
166 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
167 "a=mid:1\r\n"
168 "a=sendrecv\r\n"
169 "a=rtcp-mux\r\n"
170 "a=rtpmap:120 VP8/90000\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000171 "a=ssrc:2 cname:stream1\r\n"
172 "a=ssrc:2 mslabel:stream1\r\n"
173 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700174
zhihuang81c3a032016-11-17 12:06:24 -0800175// Reference SDP with a MediaStream with label "stream1" and audio track with
176// id "audio_1";
177static const char kSdpStringWithStream1AudioTrackOnly[] =
178 "v=0\r\n"
179 "o=- 0 0 IN IP4 127.0.0.1\r\n"
180 "s=-\r\n"
181 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800182 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800183 "a=ice-ufrag:e5785931\r\n"
184 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
185 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
186 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800187 "a=mid:audio\r\n"
188 "a=sendrecv\r\n"
189 "a=rtpmap:103 ISAC/16000\r\n"
190 "a=ssrc:1 cname:stream1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000191 "a=ssrc:1 mslabel:stream1\r\n"
192 "a=ssrc:1 label:audiotrack0\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800193 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800194
deadbeefab9b2d12015-10-14 11:33:11 -0700195// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
196// MediaStreams have one audio track and one video track.
197// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800198static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700199 "v=0\r\n"
200 "o=- 0 0 IN IP4 127.0.0.1\r\n"
201 "s=-\r\n"
202 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800203 "a=msid-semantic: WMS stream1 stream2\r\n"
204 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700205 "a=ice-ufrag:e5785931\r\n"
206 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
207 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
208 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700209 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700210 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800211 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700212 "a=rtpmap:103 ISAC/16000\r\n"
213 "a=ssrc:1 cname:stream1\r\n"
214 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
215 "a=ssrc:3 cname:stream2\r\n"
216 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
217 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800218 "a=ice-ufrag:e5785931\r\n"
219 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
220 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
221 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700222 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700223 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800224 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700225 "a=rtpmap:120 VP8/0\r\n"
226 "a=ssrc:2 cname:stream1\r\n"
227 "a=ssrc:2 msid:stream1 videotrack0\r\n"
228 "a=ssrc:4 cname:stream2\r\n"
229 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800230static const char kSdpStringWithStream1And2UnifiedPlan[] =
231 "v=0\r\n"
232 "o=- 0 0 IN IP4 127.0.0.1\r\n"
233 "s=-\r\n"
234 "t=0 0\r\n"
235 "a=msid-semantic: WMS stream1 stream2\r\n"
236 "m=audio 1 RTP/AVPF 103\r\n"
237 "a=ice-ufrag:e5785931\r\n"
238 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
239 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
240 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
241 "a=mid:0\r\n"
242 "a=sendrecv\r\n"
243 "a=rtcp-mux\r\n"
244 "a=rtpmap:103 ISAC/16000\r\n"
245 "a=ssrc:1 cname:stream1\r\n"
246 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
247 "m=video 1 RTP/AVPF 120\r\n"
248 "a=ice-ufrag:e5785931\r\n"
249 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
250 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
251 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
252 "a=mid:1\r\n"
253 "a=sendrecv\r\n"
254 "a=rtcp-mux\r\n"
255 "a=rtpmap:120 VP8/0\r\n"
256 "a=ssrc:2 cname:stream1\r\n"
257 "a=ssrc:2 msid:stream1 videotrack0\r\n"
258 "m=audio 1 RTP/AVPF 103\r\n"
259 "a=ice-ufrag:e5785931\r\n"
260 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
261 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
262 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
263 "a=mid:2\r\n"
264 "a=sendrecv\r\n"
265 "a=rtcp-mux\r\n"
266 "a=rtpmap:103 ISAC/16000\r\n"
267 "a=ssrc:3 cname:stream2\r\n"
268 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
269 "m=video 1 RTP/AVPF 120\r\n"
270 "a=ice-ufrag:e5785931\r\n"
271 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
272 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
273 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
274 "a=mid:3\r\n"
275 "a=sendrecv\r\n"
276 "a=rtcp-mux\r\n"
277 "a=rtpmap:120 VP8/0\r\n"
278 "a=ssrc:4 cname:stream2\r\n"
279 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700280
281// Reference SDP without MediaStreams. Msid is not supported.
282static const char kSdpStringWithoutStreams[] =
283 "v=0\r\n"
284 "o=- 0 0 IN IP4 127.0.0.1\r\n"
285 "s=-\r\n"
286 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800287 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700288 "a=ice-ufrag:e5785931\r\n"
289 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
290 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
291 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700292 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700293 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800294 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700295 "a=rtpmap:103 ISAC/16000\r\n"
296 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800297 "a=ice-ufrag:e5785931\r\n"
298 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
299 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
300 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700301 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700302 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800303 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700304 "a=rtpmap:120 VP8/90000\r\n";
305
306// Reference SDP without MediaStreams. Msid is supported.
307static const char kSdpStringWithMsidWithoutStreams[] =
308 "v=0\r\n"
309 "o=- 0 0 IN IP4 127.0.0.1\r\n"
310 "s=-\r\n"
311 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800312 "a=msid-semantic: WMS\r\n"
313 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700314 "a=ice-ufrag:e5785931\r\n"
315 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
316 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
317 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700318 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700319 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800320 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700321 "a=rtpmap:103 ISAC/16000\r\n"
322 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800323 "a=ice-ufrag:e5785931\r\n"
324 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
325 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
326 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700327 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700328 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700330 "a=rtpmap:120 VP8/90000\r\n";
331
332// Reference SDP without MediaStreams and audio only.
333static const char kSdpStringWithoutStreamsAudioOnly[] =
334 "v=0\r\n"
335 "o=- 0 0 IN IP4 127.0.0.1\r\n"
336 "s=-\r\n"
337 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800338 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700339 "a=ice-ufrag:e5785931\r\n"
340 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
341 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
342 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700343 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700344 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800345 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700346 "a=rtpmap:103 ISAC/16000\r\n";
347
348// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
349static const char kSdpStringSendOnlyWithoutStreams[] =
350 "v=0\r\n"
351 "o=- 0 0 IN IP4 127.0.0.1\r\n"
352 "s=-\r\n"
353 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800354 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=ice-ufrag:e5785931\r\n"
356 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
357 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
358 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700359 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700360 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700361 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800362 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700363 "a=rtpmap:103 ISAC/16000\r\n"
364 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800365 "a=ice-ufrag:e5785931\r\n"
366 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
367 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
368 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700369 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700370 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700371 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800372 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700373 "a=rtpmap:120 VP8/90000\r\n";
374
375static const char kSdpStringInit[] =
376 "v=0\r\n"
377 "o=- 0 0 IN IP4 127.0.0.1\r\n"
378 "s=-\r\n"
379 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=msid-semantic: WMS\r\n";
381
382static const char kSdpStringAudio[] =
383 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800384 "a=ice-ufrag:e5785931\r\n"
385 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
386 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
387 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700388 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700389 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800390 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700391 "a=rtpmap:103 ISAC/16000\r\n";
392
393static const char kSdpStringVideo[] =
394 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800395 "a=ice-ufrag:e5785931\r\n"
396 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
397 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
398 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700399 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700400 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800401 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700402 "a=rtpmap:120 VP8/90000\r\n";
403
404static const char kSdpStringMs1Audio0[] =
405 "a=ssrc:1 cname:stream1\r\n"
406 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
407
408static const char kSdpStringMs1Video0[] =
409 "a=ssrc:2 cname:stream1\r\n"
410 "a=ssrc:2 msid:stream1 videotrack0\r\n";
411
412static const char kSdpStringMs1Audio1[] =
413 "a=ssrc:3 cname:stream1\r\n"
414 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
415
416static const char kSdpStringMs1Video1[] =
417 "a=ssrc:4 cname:stream1\r\n"
418 "a=ssrc:4 msid:stream1 videotrack1\r\n";
419
deadbeef8662f942017-01-20 21:20:51 -0800420static const char kDtlsSdesFallbackSdp[] =
421 "v=0\r\n"
422 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
423 "s=-\r\n"
424 "c=IN IP4 0.0.0.0\r\n"
425 "t=0 0\r\n"
426 "a=group:BUNDLE audio\r\n"
427 "a=msid-semantic: WMS\r\n"
428 "m=audio 1 RTP/SAVPF 0\r\n"
429 "a=sendrecv\r\n"
430 "a=rtcp-mux\r\n"
431 "a=mid:audio\r\n"
432 "a=ssrc:1 cname:stream1\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000433 "a=ssrc:1 mslabel:stream1\r\n"
434 "a=ssrc:1 label:audiotrack0\r\n"
deadbeef8662f942017-01-20 21:20:51 -0800435 "a=ice-ufrag:e5785931\r\n"
436 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
437 "a=rtpmap:0 pcmu/8000\r\n"
438 "a=fingerprint:sha-1 "
439 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
440 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700441 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800442 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
443 "dummy_session_params\r\n";
444
Niels Möllerdec9f742019-06-03 15:25:20 +0200445class RtcEventLogOutputNull final : public RtcEventLogOutput {
446 public:
447 bool IsActive() const override { return true; }
448 bool Write(const std::string& output) override { return true; }
449};
450
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100451using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700452using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800453using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454
Steve Anton36da6ff2018-02-16 16:04:20 -0800455using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
456using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700457
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458// Gets the first ssrc of given content type from the ContentInfo.
459bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
460 if (!content_info || !ssrc) {
461 return false;
462 }
463 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800464 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 if (!media_desc || media_desc->streams().empty()) {
466 return false;
467 }
468 *ssrc = media_desc->streams().begin()->first_ssrc();
469 return true;
470}
471
deadbeefd1a38b52016-12-10 13:15:33 -0800472// Get the ufrags out of an SDP blob. Useful for testing ICE restart
473// behavior.
474std::vector<std::string> GetUfrags(
475 const webrtc::SessionDescriptionInterface* desc) {
476 std::vector<std::string> ufrags;
477 for (const cricket::TransportInfo& info :
478 desc->description()->transport_infos()) {
479 ufrags.push_back(info.description.ice_ufrag);
480 }
481 return ufrags;
482}
483
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484void SetSsrcToZero(std::string* sdp) {
485 const char kSdpSsrcAtribute[] = "a=ssrc:";
486 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
487 size_t ssrc_pos = 0;
488 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200489 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490 size_t end_ssrc = sdp->find(" ", ssrc_pos);
491 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
492 ssrc_pos = end_ssrc;
493 }
494}
495
Artem Titov880fa812021-07-30 22:30:23 +0200496// Check if `streams` contains the specified track.
deadbeefab9b2d12015-10-14 11:33:11 -0700497bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800498 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700499 const std::string& track_id) {
500 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800501 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700502 return true;
503 }
504 }
505 return false;
506}
507
Artem Titov880fa812021-07-30 22:30:23 +0200508// Check if `senders` contains the specified sender, by id.
deadbeefab9b2d12015-10-14 11:33:11 -0700509bool ContainsSender(
510 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
511 const std::string& id) {
512 for (const auto& sender : senders) {
513 if (sender->id() == id) {
514 return true;
515 }
516 }
517 return false;
518}
519
Artem Titov880fa812021-07-30 22:30:23 +0200520// Check if `senders` contains the specified sender, by id and stream id.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700521bool ContainsSender(
522 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
523 const std::string& id,
524 const std::string& stream_id) {
525 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700526 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700527 return true;
528 }
529 }
530 return false;
531}
532
deadbeefab9b2d12015-10-14 11:33:11 -0700533// Create a collection of streams.
534// CreateStreamCollection(1) creates a collection that
535// correspond to kSdpStringWithStream1.
536// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
537rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700538 int number_of_streams,
539 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700540 rtc::scoped_refptr<StreamCollection> local_collection(
541 StreamCollection::Create());
542
543 for (int i = 0; i < number_of_streams; ++i) {
544 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
545 webrtc::MediaStream::Create(kStreams[i]));
546
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700547 for (int j = 0; j < tracks_per_stream; ++j) {
548 // Add a local audio track.
549 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
550 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
551 nullptr));
Niels Möllerafb246b2022-04-20 14:26:50 +0200552 stream->AddTrack(audio_track.get());
deadbeefab9b2d12015-10-14 11:33:11 -0700553
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700554 // Add a local video track.
555 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
556 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700557 webrtc::FakeVideoTrackSource::Create(),
558 rtc::Thread::Current()));
Niels Möllerafb246b2022-04-20 14:26:50 +0200559 stream->AddTrack(video_track.get());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700560 }
deadbeefab9b2d12015-10-14 11:33:11 -0700561
562 local_collection->AddStream(stream);
563 }
564 return local_collection;
565}
566
567// Check equality of StreamCollections.
568bool CompareStreamCollections(StreamCollectionInterface* s1,
569 StreamCollectionInterface* s2) {
570 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
571 return false;
572 }
573
574 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700575 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700576 return false;
577 }
578 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
579 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
580 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
581 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
582
583 if (audio_tracks1.size() != audio_tracks2.size()) {
584 return false;
585 }
586 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
587 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
588 return false;
589 }
590 }
591 if (video_tracks1.size() != video_tracks2.size()) {
592 return false;
593 }
594 for (size_t j = 0; j != video_tracks1.size(); ++j) {
595 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
596 return false;
597 }
598 }
599 }
600 return true;
601}
602
perkjd61bf802016-03-24 03:16:19 -0700603// Helper class to test Observer.
604class MockTrackObserver : public ObserverInterface {
605 public:
606 explicit MockTrackObserver(NotifierInterface* notifier)
607 : notifier_(notifier) {
608 notifier_->RegisterObserver(this);
609 }
610
611 ~MockTrackObserver() { Unregister(); }
612
613 void Unregister() {
614 if (notifier_) {
615 notifier_->UnregisterObserver(this);
616 notifier_ = nullptr;
617 }
618 }
619
Danil Chapovalov3a353122020-05-15 11:16:53 +0200620 MOCK_METHOD(void, OnChanged, (), (override));
perkjd61bf802016-03-24 03:16:19 -0700621
622 private:
623 NotifierInterface* notifier_;
624};
625
nisse528b7932017-05-08 03:21:43 -0700626// The PeerConnectionMediaConfig tests below verify that configuration and
627// constraints are propagated into the PeerConnection's MediaConfig. These
628// settings are intended for MediaChannel constructors, but that is not
629// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700630class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
631 public:
zhihuang38ede132017-06-15 12:52:32 -0700632 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
633 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100634 PeerConnectionFactoryDependencies dependencies;
635 dependencies.worker_thread = rtc::Thread::Current();
636 dependencies.network_thread = rtc::Thread::Current();
637 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200638 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
Erik Språngceb44952020-09-22 11:36:35 +0200639 dependencies.trials = std::make_unique<FieldTrialBasedConfig>();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200640 cricket::MediaEngineDependencies media_deps;
641 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200642 // Use fake audio device module since we're only testing the interface
643 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200644 media_deps.adm = FakeAudioCaptureModule::Create();
645 SetMediaEngineDefaults(&media_deps);
Erik Språngceb44952020-09-22 11:36:35 +0200646 media_deps.trials = dependencies.trials.get();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200647 dependencies.media_engine =
648 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100649 dependencies.call_factory = webrtc::CreateCallFactory();
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200650 dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>(
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200651 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700652
Tommi87f70902021-04-27 14:43:08 +0200653 return rtc::make_ref_counted<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100654 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700655 }
656
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100657 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800658
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100659 private:
deadbeefd7850b22017-08-23 10:59:19 -0700660 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700661};
662
Steve Anton36da6ff2018-02-16 16:04:20 -0800663// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200664class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800666 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
667 : vss_(new rtc::VirtualSocketServer()),
668 main_(vss_.get()),
669 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800670#ifdef WEBRTC_ANDROID
671 webrtc::InitializeAndroidObjects();
672#endif
673 }
674
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200675 void SetUp() override {
deadbeefd7850b22017-08-23 10:59:19 -0700676 // Use fake audio capture module since we're only testing the interface
677 // level, and using a real one could make tests flaky when run in parallel.
678 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700680 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200681 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
682 fake_audio_capture_module_),
683 webrtc::CreateBuiltinAudioEncoderFactory(),
684 webrtc::CreateBuiltinAudioDecoderFactory(),
685 webrtc::CreateBuiltinVideoEncoderFactory(),
686 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
687 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700688 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700689 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700690 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 }
692
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200693 void TearDown() override {
694 if (pc_)
695 pc_->Close();
696 }
697
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200699 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 }
701
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000702 // DTLS does not work in a loopback call, so is disabled for many
deadbeef293e9262017-01-11 12:28:30 -0800703 // tests in this file.
704 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200705 RTCConfiguration config;
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000706 PeerConnectionFactoryInterface::Options options;
707 options.disable_encryption = true;
708 pc_factory_->SetOptions(options);
Niels Möllerf06f9232018-08-07 12:32:18 +0200709 CreatePeerConnection(config);
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000710 options.disable_encryption = false;
711 pc_factory_->SetOptions(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 }
713
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700714 void CreatePeerConnectionWithIceTransportsType(
715 PeerConnectionInterface::IceTransportsType type) {
716 PeerConnectionInterface::RTCConfiguration config;
717 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200718 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 }
720
721 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100722 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700723 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800724 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700726 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100727 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700728 server.password = password;
729 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200730 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700731 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732
Niels Möllerf06f9232018-08-07 12:32:18 +0200733 void CreatePeerConnection(const RTCConfiguration& config) {
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200734 if (pc_) {
735 pc_->Close();
736 pc_ = nullptr;
737 }
kwibergd1fe2812016-04-27 06:47:29 -0700738 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800739 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
740 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000741
deadbeef1dcb1642017-03-29 21:08:16 -0700742 // Create certificate generator unless DTLS constraint is explicitly set to
743 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200744 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200745
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000746 // These won't be used if encryption is turned off, but that's harmless.
747 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
748 cert_generator.reset(fake_certificate_generator_);
749
Steve Anton36da6ff2018-02-16 16:04:20 -0800750 RTCConfiguration modified_config = config;
751 modified_config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200752 PeerConnectionDependencies pc_dependencies(&observer_);
753 pc_dependencies.cert_generator = std::move(cert_generator);
754 pc_dependencies.allocator = std::move(port_allocator);
755 auto result = pc_factory_->CreatePeerConnectionOrError(
756 modified_config, std::move(pc_dependencies));
757 ASSERT_TRUE(result.ok());
758 pc_ = result.MoveValue();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 observer_.SetPeerConnectionInterface(pc_.get());
760 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
761 }
762
deadbeef0a6c4ca2015-10-06 11:38:28 -0700763 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800764 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700765 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800767 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800768 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200769 PeerConnectionDependencies pc_dependencies(&observer_);
770 auto result = pc_factory_->CreatePeerConnectionOrError(
771 config, std::move(pc_dependencies));
772 EXPECT_FALSE(result.ok());
deadbeef0a6c4ca2015-10-06 11:38:28 -0700773 }
774
Steve Anton038834f2017-07-14 15:59:59 -0700775 void CreatePeerConnectionExpectFail(
776 PeerConnectionInterface::RTCConfiguration config) {
777 PeerConnectionInterface::IceServer server;
778 server.uri = kTurnIceServerUri;
779 server.password = kTurnPassword;
780 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800781 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200782 PeerConnectionDependencies pc_dependencies(&observer_);
783 auto result = pc_factory_->CreatePeerConnectionOrError(
784 config, std::move(pc_dependencies));
785 EXPECT_FALSE(result.ok());
Steve Anton038834f2017-07-14 15:59:59 -0700786 }
787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100789 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800790 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
791 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
792 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795
deadbeef0a6c4ca2015-10-06 11:38:28 -0700796 CreatePeerConnectionExpectFail(kStunInvalidPort);
797 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
798 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799
Niels Möllerdb4def92019-03-18 16:53:59 +0100800 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
801 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
803 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800805 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800807 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800809 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 }
811
812 void ReleasePeerConnection() {
Niels Möllerafb246b2022-04-20 14:26:50 +0200813 pc_ = nullptr;
814 observer_.SetPeerConnectionInterface(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 }
816
Steve Anton36da6ff2018-02-16 16:04:20 -0800817 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
818 const std::string& label) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200819 return pc_factory_->CreateVideoTrack(label,
820 FakeVideoTrackSource::Create().get());
Steve Anton36da6ff2018-02-16 16:04:20 -0800821 }
822
823 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800824 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800826 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 }
829
Steve Anton36da6ff2018-02-16 16:04:20 -0800830 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700831 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 pc_factory_->CreateLocalMediaStream(label));
Niels Möllerafb246b2022-04-20 14:26:50 +0200833 stream->AddTrack(CreateVideoTrack(label + "v0").get());
834 ASSERT_TRUE(pc_->AddStream(stream.get()));
Steve Anton36da6ff2018-02-16 16:04:20 -0800835 }
836
837 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
838 const std::string& label) {
839 return pc_factory_->CreateAudioTrack(label, nullptr);
840 }
841
842 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800843 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800844 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800845 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800846 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800847 }
848
849 void AddAudioStream(const std::string& label) {
850 rtc::scoped_refptr<MediaStreamInterface> stream(
851 pc_factory_->CreateLocalMediaStream(label));
Niels Möllerafb246b2022-04-20 14:26:50 +0200852 stream->AddTrack(CreateAudioTrack(label + "a0").get());
853 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 }
855
Seth Hampson845e8782018-03-02 11:34:10 -0800856 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 const std::string& audio_track_label,
858 const std::string& video_track_label) {
859 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700860 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800861 pc_factory_->CreateLocalMediaStream(stream_id));
Niels Möllerafb246b2022-04-20 14:26:50 +0200862 stream->AddTrack(CreateAudioTrack(audio_track_label).get());
863 stream->AddTrack(CreateVideoTrack(video_track_label).get());
864 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 }
866
Steve Anton36da6ff2018-02-16 16:04:20 -0800867 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
868 cricket::MediaType media_type) {
869 for (auto receiver : pc_->GetReceivers()) {
870 if (receiver->media_type() == media_type) {
871 return receiver;
872 }
873 }
874 return nullptr;
875 }
876
kwibergd1fe2812016-04-27 06:47:29 -0700877 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200878 const RTCOfferAnswerOptions* options,
879 bool offer) {
Tommi87f70902021-04-27 14:43:08 +0200880 auto observer =
881 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 if (offer) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200883 pc_->CreateOffer(observer.get(),
884 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200886 pc_->CreateAnswer(observer.get(),
887 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 }
889 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700890 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 return observer->result();
892 }
893
kwibergd1fe2812016-04-27 06:47:29 -0700894 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200895 const RTCOfferAnswerOptions* options) {
896 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898
kwibergd1fe2812016-04-27 06:47:29 -0700899 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200900 const RTCOfferAnswerOptions* options) {
901 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 }
903
Steve Antondb45ca82017-09-11 18:27:34 -0700904 bool DoSetSessionDescription(
905 std::unique_ptr<SessionDescriptionInterface> desc,
906 bool local) {
Tommi87f70902021-04-27 14:43:08 +0200907 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 if (local) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200909 pc_->SetLocalDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200911 pc_->SetRemoteDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 }
zhihuang29ff8442016-07-27 11:07:25 -0700913 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
914 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
915 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 return observer->result();
917 }
918
Steve Antondb45ca82017-09-11 18:27:34 -0700919 bool DoSetLocalDescription(
920 std::unique_ptr<SessionDescriptionInterface> desc) {
921 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 }
923
Steve Antondb45ca82017-09-11 18:27:34 -0700924 bool DoSetRemoteDescription(
925 std::unique_ptr<SessionDescriptionInterface> desc) {
926 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 }
928
929 // Calls PeerConnection::GetStats and check the return value.
930 // It does not verify the values in the StatReports since a RTCP packet might
931 // be required.
932 bool DoGetStats(MediaStreamTrackInterface* track) {
Tommi87f70902021-04-27 14:43:08 +0200933 auto observer = rtc::make_ref_counted<MockStatsObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200934 if (!pc_->GetStats(observer.get(), track,
Yves Gerey665174f2018-06-19 15:03:05 +0200935 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 return false;
937 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
938 return observer->called();
939 }
940
Harald Alvestrand89061872018-01-02 14:08:34 +0100941 // Call the standards-compliant GetStats function.
942 bool DoGetRTCStats() {
Tommi87f70902021-04-27 14:43:08 +0200943 auto callback =
944 rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200945 pc_->GetStats(callback.get());
Harald Alvestrand89061872018-01-02 14:08:34 +0100946 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
947 return callback->called();
948 }
949
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800951 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 // Create a local stream with audio&video tracks.
Florent Castelli15a38de2022-04-06 00:38:21 +0200953 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson845e8782018-03-02 11:34:10 -0800954 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800955 } else {
956 // Unified Plan does not support AddStream, so just add an audio and video
957 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800958 AddAudioTrack(kAudioTracks[0], {kStreamId1});
959 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800960 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 CreateOfferReceiveAnswer();
962 }
963
964 // Verify that RTP Header extensions has been negotiated for audio and video.
965 void VerifyRemoteRtpHeaderExtensions() {
966 const cricket::MediaContentDescription* desc =
967 cricket::GetFirstAudioContentDescription(
968 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200969 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
971
972 desc = cricket::GetFirstVideoContentDescription(
973 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200974 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
976 }
977
978 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700979 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700980 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 std::string sdp;
982 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700983 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800984 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700985 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
987 }
988
deadbeefab9b2d12015-10-14 11:33:11 -0700989 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700990 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800991 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700992 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700993 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
994 }
995
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700997 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700998 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999
1000 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1001 // audio codec change, even if the parameter has nothing to do with
1002 // receiving. Not all parameters are serialized to SDP.
1003 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1004 // the SessionDescription, it is necessary to do that here to in order to
1005 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1006 // https://code.google.com/p/webrtc/issues/detail?id=1356
1007 std::string sdp;
1008 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001009 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001010 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001011 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1013 }
1014
1015 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001016 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001017 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018
1019 std::string sdp;
1020 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001021 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001022 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001023 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1025 }
1026
1027 void CreateOfferReceiveAnswer() {
1028 CreateOfferAsLocalDescription();
1029 std::string sdp;
1030 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1031 CreateAnswerAsRemoteDescription(sdp);
1032 }
1033
1034 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001035 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001036 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1038 // audio codec change, even if the parameter has nothing to do with
1039 // receiving. Not all parameters are serialized to SDP.
1040 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1041 // the SessionDescription, it is necessary to do that here to in order to
1042 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1043 // https://code.google.com/p/webrtc/issues/detail?id=1356
1044 std::string sdp;
1045 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001046 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001047 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048
Steve Antondb45ca82017-09-11 18:27:34 -07001049 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001051 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001052 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 }
1054
deadbeefab9b2d12015-10-14 11:33:11 -07001055 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001056 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001057 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001058 ASSERT_TRUE(answer);
1059 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1061 }
1062
deadbeefab9b2d12015-10-14 11:33:11 -07001063 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001064 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001065 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 ASSERT_TRUE(pr_answer);
1067 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001069 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001070 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001071 ASSERT_TRUE(answer);
1072 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1074 }
1075
Seth Hampson845e8782018-03-02 11:34:10 -08001076 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001077 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001078 // called with the given stream id and expected number of tracks.
1079 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001080 int expected_num_tracks) {
1081 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001082 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001083 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001084 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 }
1086
1087 // Creates an offer and applies it as a local session description.
1088 // Creates an answer with the same SDP an the offer but removes all lines
1089 // that start with a:ssrc"
1090 void CreateOfferReceiveAnswerWithoutSsrc() {
1091 CreateOfferAsLocalDescription();
1092 std::string sdp;
1093 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1094 SetSsrcToZero(&sdp);
1095 CreateAnswerAsRemoteDescription(sdp);
1096 }
1097
deadbeefab9b2d12015-10-14 11:33:11 -07001098 // This function creates a MediaStream with label kStreams[0] and
Artem Titov880fa812021-07-30 22:30:23 +02001099 // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the
deadbeefab9b2d12015-10-14 11:33:11 -07001100 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001101 // is returned and the MediaStream is stored in
Artem Titov880fa812021-07-30 22:30:23 +02001102 // `reference_collection_`
kwibergd1fe2812016-04-27 06:47:29 -07001103 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001104 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1105 size_t number_of_video_tracks) {
1106 EXPECT_LE(number_of_audio_tracks, 2u);
1107 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001108
1109 reference_collection_ = StreamCollection::Create();
1110 std::string sdp_ms1 = std::string(kSdpStringInit);
1111
Seth Hampson845e8782018-03-02 11:34:10 -08001112 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001113
1114 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001115 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001116 reference_collection_->AddStream(stream);
1117
1118 if (number_of_audio_tracks > 0) {
1119 sdp_ms1 += std::string(kSdpStringAudio);
1120 sdp_ms1 += std::string(kSdpStringMs1Audio0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001121 AddAudioTrack(kAudioTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001122 }
1123 if (number_of_audio_tracks > 1) {
1124 sdp_ms1 += kSdpStringMs1Audio1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001125 AddAudioTrack(kAudioTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001126 }
1127
1128 if (number_of_video_tracks > 0) {
1129 sdp_ms1 += std::string(kSdpStringVideo);
1130 sdp_ms1 += std::string(kSdpStringMs1Video0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001131 AddVideoTrack(kVideoTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001132 }
1133 if (number_of_video_tracks > 1) {
1134 sdp_ms1 += kSdpStringMs1Video1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001135 AddVideoTrack(kVideoTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001136 }
1137
kwibergd1fe2812016-04-27 06:47:29 -07001138 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001139 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001140 }
1141
1142 void AddAudioTrack(const std::string& track_id,
1143 MediaStreamInterface* stream) {
1144 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1145 webrtc::AudioTrack::Create(track_id, nullptr));
Niels Möllerafb246b2022-04-20 14:26:50 +02001146 ASSERT_TRUE(stream->AddTrack(audio_track.get()));
deadbeefab9b2d12015-10-14 11:33:11 -07001147 }
1148
1149 void AddVideoTrack(const std::string& track_id,
1150 MediaStreamInterface* stream) {
1151 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001152 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001153 webrtc::FakeVideoTrackSource::Create(),
1154 rtc::Thread::Current()));
Niels Möllerafb246b2022-04-20 14:26:50 +02001155 ASSERT_TRUE(stream->AddTrack(video_track.get()));
deadbeefab9b2d12015-10-14 11:33:11 -07001156 }
1157
Steve Anton36da6ff2018-02-16 16:04:20 -08001158 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001159 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001160 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001161 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001162 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1163 return offer;
1164 }
1165
Steve Anton36da6ff2018-02-16 16:04:20 -08001166 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1167 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001168 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001169 std::unique_ptr<SessionDescriptionInterface> offer;
1170 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1171 return offer;
1172 }
1173
1174 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1175 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1176 std::unique_ptr<SessionDescriptionInterface> answer;
1177 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1178 return answer;
1179 }
1180
kwibergfd8be342016-05-14 19:44:11 -07001181 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001182 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001183 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001184 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001185 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1186 return answer;
1187 }
1188
1189 const std::string& GetFirstAudioStreamCname(
1190 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001191 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001192 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001193 return audio_desc->streams()[0].cname;
1194 }
1195
zhihuang1c378ed2017-08-17 14:10:50 -07001196 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1197 const RTCOfferAnswerOptions& offer_answer_options) {
1198 RTC_DCHECK(pc_);
Tommi87f70902021-04-27 14:43:08 +02001199 auto observer =
1200 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02001201 pc_->CreateOffer(observer.get(), offer_answer_options);
zhihuang1c378ed2017-08-17 14:10:50 -07001202 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1203 return observer->MoveDescription();
1204 }
1205
1206 void CreateOfferWithOptionsAsRemoteDescription(
1207 std::unique_ptr<SessionDescriptionInterface>* desc,
1208 const RTCOfferAnswerOptions& offer_answer_options) {
1209 *desc = CreateOfferWithOptions(offer_answer_options);
1210 ASSERT_TRUE(desc != nullptr);
1211 std::string sdp;
1212 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001213 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001214 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001215 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001216 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1217 }
1218
1219 void CreateOfferWithOptionsAsLocalDescription(
1220 std::unique_ptr<SessionDescriptionInterface>* desc,
1221 const RTCOfferAnswerOptions& offer_answer_options) {
1222 *desc = CreateOfferWithOptions(offer_answer_options);
1223 ASSERT_TRUE(desc != nullptr);
1224 std::string sdp;
1225 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001226 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001227 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001228
Steve Antondb45ca82017-09-11 18:27:34 -07001229 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001230 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1231 }
1232
1233 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001234 RTC_DCHECK(content);
1235 RTC_DCHECK(content->media_description());
1236 for (const cricket::AudioCodec& codec :
1237 content->media_description()->as_audio()->codecs()) {
1238 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001239 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001240 }
zhihuang1c378ed2017-08-17 14:10:50 -07001241 }
1242 return false;
1243 }
1244
Steve Anton36da6ff2018-02-16 16:04:20 -08001245 const char* GetSdpStringWithStream1() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001246 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001247 return kSdpStringWithStream1PlanB;
1248 } else {
1249 return kSdpStringWithStream1UnifiedPlan;
1250 }
1251 }
1252
1253 const char* GetSdpStringWithStream1And2() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001254 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001255 return kSdpStringWithStream1And2PlanB;
1256 } else {
1257 return kSdpStringWithStream1And2UnifiedPlan;
1258 }
1259 }
1260
deadbeef9a6f4d42017-05-15 19:43:33 -07001261 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1262 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001263 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001264 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001265 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001266 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1267 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1268 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001270 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001271 const SdpSemantics sdp_semantics_;
1272};
1273
1274class PeerConnectionInterfaceTest
1275 : public PeerConnectionInterfaceBaseTest,
1276 public ::testing::WithParamInterface<SdpSemantics> {
1277 protected:
1278 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1279};
1280
1281class PeerConnectionInterfaceTestPlanB
1282 : public PeerConnectionInterfaceBaseTest {
1283 protected:
1284 PeerConnectionInterfaceTestPlanB()
Florent Castelli15a38de2022-04-06 00:38:21 +02001285 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286};
1287
zhihuang8f65cdf2016-05-06 18:40:30 -07001288// Generate different CNAMEs when PeerConnections are created.
1289// The CNAMEs are expected to be generated randomly. It is possible
1290// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001291TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001292 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001293 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001294 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001295 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001296 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1297 GetFirstAudioStreamCname(offer2.get()));
1298}
1299
Steve Anton36da6ff2018-02-16 16:04:20 -08001300TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001301 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001302 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001303 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001304 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001305 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1306 GetFirstAudioStreamCname(answer2.get()));
1307}
1308
Steve Anton36da6ff2018-02-16 16:04:20 -08001309TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 CreatePeerConnectionWithDifferentConfigurations) {
1311 CreatePeerConnectionWithDifferentConfigurations();
1312}
1313
Steve Anton36da6ff2018-02-16 16:04:20 -08001314TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001315 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1316 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1317 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1318 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1319 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1320 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1321 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1322 port_allocator_->candidate_filter());
1323 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1324 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1325}
1326
1327// Test that when a PeerConnection is created with a nonzero candidate pool
1328// size, the pooled PortAllocatorSession is created with all the attributes
1329// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001330TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001331 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001332 config.sdp_semantics = sdp_semantics_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001333 PeerConnectionInterface::IceServer server;
1334 server.uri = kStunAddressOnly;
1335 config.servers.push_back(server);
1336 config.type = PeerConnectionInterface::kRelay;
1337 config.disable_ipv6 = true;
1338 config.tcp_candidate_policy =
1339 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001340 config.candidate_network_policy =
1341 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001342 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001343 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001344
1345 const cricket::FakePortAllocatorSession* session =
1346 static_cast<const cricket::FakePortAllocatorSession*>(
1347 port_allocator_->GetPooledSession());
1348 ASSERT_NE(nullptr, session);
1349 EXPECT_EQ(1UL, session->stun_servers().size());
1350 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1351 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001352 EXPECT_LT(0U,
1353 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001354}
1355
deadbeefd21eab32017-07-26 16:50:11 -07001356// Test that network-related RTCConfiguration members are applied to the
1357// PortAllocator when CreatePeerConnection is called. Specifically:
1358// - disable_ipv6_on_wifi
1359// - max_ipv6_networks
1360// - tcp_candidate_policy
1361// - candidate_network_policy
1362// - prune_turn_ports
1363//
1364// Note that the candidate filter (RTCConfiguration::type) is already tested
1365// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001366TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001367 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1368 // Create fake port allocator.
1369 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1370 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1371 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1372
1373 // Create RTCConfiguration with some network-related fields relevant to
1374 // PortAllocator populated.
1375 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001376 config.sdp_semantics = sdp_semantics_;
deadbeefd21eab32017-07-26 16:50:11 -07001377 config.disable_ipv6_on_wifi = true;
1378 config.max_ipv6_networks = 10;
1379 config.tcp_candidate_policy =
1380 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1381 config.candidate_network_policy =
1382 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1383 config.prune_turn_ports = true;
1384
1385 // Create the PC factory and PC with the above config.
1386 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1387 webrtc::CreatePeerConnectionFactory(
1388 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001389 rtc::Thread::Current(), fake_audio_capture_module_,
1390 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001391 webrtc::CreateBuiltinAudioDecoderFactory(),
1392 webrtc::CreateBuiltinVideoEncoderFactory(),
1393 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1394 nullptr /* audio_processing */));
Florent Castelli72424402022-04-06 03:45:10 +02001395 PeerConnectionDependencies pc_dependencies(&observer_);
1396 pc_dependencies.allocator = std::move(port_allocator);
1397 auto result = pc_factory_->CreatePeerConnectionOrError(
1398 config, std::move(pc_dependencies));
1399 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02001400 observer_.SetPeerConnectionInterface(result.value().get());
deadbeefd21eab32017-07-26 16:50:11 -07001401
1402 // Now validate that the config fields set above were applied to the
1403 // PortAllocator, as flags or otherwise.
1404 EXPECT_FALSE(raw_port_allocator->flags() &
1405 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1406 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1407 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1408 EXPECT_TRUE(raw_port_allocator->flags() &
1409 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Honghai Zhangf8998cf2019-10-14 11:27:50 -07001410 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
1411 raw_port_allocator->turn_port_prune_policy());
deadbeefd21eab32017-07-26 16:50:11 -07001412}
1413
deadbeef46c73892016-11-16 19:42:04 -08001414// Check that GetConfiguration returns the configuration the PeerConnection was
1415// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001416TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001417 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001418 config.sdp_semantics = sdp_semantics_;
deadbeef46c73892016-11-16 19:42:04 -08001419 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001420 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001421
1422 PeerConnectionInterface::RTCConfiguration returned_config =
1423 pc_->GetConfiguration();
1424 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1425}
1426
1427// Check that GetConfiguration returns the last configuration passed into
1428// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001429TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001430 PeerConnectionInterface::RTCConfiguration starting_config;
Henrik Boström62995db2022-01-03 09:58:10 +01001431 starting_config.sdp_semantics = sdp_semantics_;
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001432 starting_config.bundle_policy =
1433 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1434 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001435
Steve Anton36da6ff2018-02-16 16:04:20 -08001436 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001437 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02001438 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef46c73892016-11-16 19:42:04 -08001439
1440 PeerConnectionInterface::RTCConfiguration returned_config =
1441 pc_->GetConfiguration();
1442 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1443}
1444
Steve Antonc79268f2018-04-24 09:54:10 -07001445TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1446 CreatePeerConnection();
1447
1448 pc_->Close();
1449
1450 EXPECT_FALSE(
Niels Möller2579f0c2019-08-19 09:58:17 +02001451 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok());
Steve Antonc79268f2018-04-24 09:54:10 -07001452}
1453
Steve Anton36da6ff2018-02-16 16:04:20 -08001454TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001455 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001456 AddVideoStream(kStreamId1);
1457 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 ASSERT_EQ(2u, pc_->local_streams()->count());
1459
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001460 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001461 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001462 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001463 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001464 pc_factory_->CreateAudioTrack(
1465 kStreamId3, static_cast<AudioSourceInterface*>(nullptr)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 stream->AddTrack(audio_track.get());
Niels Möllerafb246b2022-04-20 14:26:50 +02001467 EXPECT_TRUE(pc_->AddStream(stream.get()));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001468 EXPECT_EQ(3u, pc_->local_streams()->count());
1469
1470 // Remove the third stream.
1471 pc_->RemoveStream(pc_->local_streams()->at(2));
1472 EXPECT_EQ(2u, pc_->local_streams()->count());
1473
1474 // Remove the second stream.
1475 pc_->RemoveStream(pc_->local_streams()->at(1));
1476 EXPECT_EQ(1u, pc_->local_streams()->count());
1477
1478 // Remove the first stream.
1479 pc_->RemoveStream(pc_->local_streams()->at(0));
1480 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481}
1482
deadbeefab9b2d12015-10-14 11:33:11 -07001483// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001484// Don't run under Unified Plan since the stream API is not available.
1485TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001486 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001487 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001488 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001489 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001490
deadbeefab9b2d12015-10-14 11:33:11 -07001491 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001492 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001493 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001494
deadbeefab9b2d12015-10-14 11:33:11 -07001495 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001496 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001497 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001498
1499 // Add another stream and ensure the offer includes both the old and new
1500 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001501 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001502 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001503
Steve Antonb1c1de12017-12-21 15:14:30 -08001504 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001505 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1506 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001507
Steve Antonb1c1de12017-12-21 15:14:30 -08001508 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001509 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1510 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001511}
1512
Steve Anton36da6ff2018-02-16 16:04:20 -08001513// Don't run under Unified Plan since the stream API is not available.
1514TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001515 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001516 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 ASSERT_EQ(1u, pc_->local_streams()->count());
1518 pc_->RemoveStream(pc_->local_streams()->at(0));
1519 EXPECT_EQ(0u, pc_->local_streams()->count());
1520}
1521
deadbeefe1f9d832016-01-14 15:35:42 -08001522// Test for AddTrack and RemoveTrack methods.
1523// Tests that the created offer includes tracks we added,
1524// and that the RtpSenders are created correctly.
1525// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001526// Only tested with Plan B since Unified Plan is covered in more detail by tests
1527// in peerconnection_jsep_unittests.cc
1528TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001529 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001530 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001531 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001532 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001533 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001534 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1535 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001536 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001537 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001538 EXPECT_EQ("audio_track", audio_sender->id());
1539 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001540 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001541 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001542 EXPECT_EQ("video_track", video_sender->id());
1543 EXPECT_EQ(video_track, video_sender->track());
1544
1545 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001546 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001547 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001548
1549 const cricket::ContentInfo* audio_content =
1550 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001551 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001552 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001553
1554 const cricket::ContentInfo* video_content =
1555 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001556 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001557 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001558
Steve Antondb45ca82017-09-11 18:27:34 -07001559 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 // Now try removing the tracks.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001562 EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1563 EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001564
1565 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001566 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001567
1568 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001569 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001570 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001571
1572 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001573 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001574 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001575
Steve Antondb45ca82017-09-11 18:27:34 -07001576 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001577
1578 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1579 // should return false.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001580 EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok());
1581 EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001582}
1583
1584// Test creating senders without a stream specified,
1585// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001586TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001587 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001588 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001589 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001590 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001591 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001592 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001593 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001594 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001595 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001596 EXPECT_EQ("audio_track", audio_sender->id());
1597 EXPECT_EQ(audio_track, audio_sender->track());
1598 EXPECT_EQ("video_track", video_sender->id());
1599 EXPECT_EQ(video_track, video_sender->track());
Florent Castelli15a38de2022-04-06 00:38:21 +02001600 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001601 // If the ID is truly a random GUID, it should be infinitely unlikely they
1602 // will be the same.
1603 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1604 } else {
1605 // We allows creating tracks without stream ids under Unified Plan
1606 // semantics.
1607 EXPECT_EQ(0u, video_sender->stream_ids().size());
1608 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1609 }
deadbeefe1f9d832016-01-14 15:35:42 -08001610}
1611
Harald Alvestrand89061872018-01-02 14:08:34 +01001612// Test that we can call GetStats() after AddTrack but before connecting
1613// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001614TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001615 CreatePeerConnectionWithoutDtls();
1616 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001617 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001618 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001619 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001620 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1621 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001622 EXPECT_TRUE(DoGetStats(nullptr));
1623}
1624
Steve Anton36da6ff2018-02-16 16:04:20 -08001625TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001626 CreatePeerConnectionWithoutDtls();
1627 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001628 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001629 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001630 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001631 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001632 ASSERT_TRUE(audio_sender.ok());
1633 auto* audio_sender_proxy =
1634 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1635 audio_sender.value().get());
1636 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1637
Harald Alvestrandc72af932018-01-11 17:18:19 +01001638 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001639 ASSERT_TRUE(video_sender.ok());
1640 auto* video_sender_proxy =
1641 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1642 video_sender.value().get());
1643 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001644}
1645
Steve Anton36da6ff2018-02-16 16:04:20 -08001646// Don't run under Unified Plan since the stream API is not available.
1647TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001648 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001649 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001650 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001651 ASSERT_EQ(1u, senders.size());
1652 auto* sender_proxy =
1653 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1654 senders[0].get());
1655 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001656}
1657
Steve Anton36da6ff2018-02-16 16:04:20 -08001658TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001660 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 VerifyRemoteRtpHeaderExtensions();
1662}
1663
Steve Anton36da6ff2018-02-16 16:04:20 -08001664TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001665 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001666 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 CreateOfferAsLocalDescription();
1668 std::string offer;
1669 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1670 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001671 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672}
1673
Steve Anton36da6ff2018-02-16 16:04:20 -08001674TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001675 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001676 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677
1678 CreateOfferAsRemoteDescription();
1679 CreateAnswerAsLocalDescription();
1680
Seth Hampson845e8782018-03-02 11:34:10 -08001681 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001685 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001686 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 CreateOfferAsRemoteDescription();
1689 CreatePrAnswerAsLocalDescription();
1690 CreateAnswerAsLocalDescription();
1691
Seth Hampson845e8782018-03-02 11:34:10 -08001692 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693}
1694
Steve Anton36da6ff2018-02-16 16:04:20 -08001695// Don't run under Unified Plan since the stream API is not available.
1696TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 InitiateCall();
1698 ASSERT_EQ(1u, pc_->remote_streams()->count());
1699 pc_->RemoveStream(pc_->local_streams()->at(0));
1700 CreateOfferReceiveAnswer();
1701 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001702 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 CreateOfferReceiveAnswer();
1704}
1705
1706// Tests that after negotiating an audio only call, the respondent can perform a
1707// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001708TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001709 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001710 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 CreateOfferAsRemoteDescription();
1712 CreateAnswerAsLocalDescription();
1713
1714 ASSERT_EQ(1u, pc_->remote_streams()->count());
1715 pc_->RemoveStream(pc_->local_streams()->at(0));
1716 CreateOfferReceiveAnswer();
1717 EXPECT_EQ(0u, pc_->remote_streams()->count());
1718}
1719
1720// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001721TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001722 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723
Steve Antonf1c6db12017-10-13 11:13:35 -07001724 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001726 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001727 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001728 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001729 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730
1731 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001732 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001733 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001734 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735
Steve Antonf1c6db12017-10-13 11:13:35 -07001736 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001737 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738
Steve Antonf1c6db12017-10-13 11:13:35 -07001739 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740}
1741
deadbeefab9b2d12015-10-14 11:33:11 -07001742// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001744TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001745 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001747 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001748 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001749 EXPECT_TRUE(offer);
1750 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001753 AddAudioTrack("track_label", {kStreamId1});
1754 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755
1756 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001757 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
1759 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001760 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001761 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762}
1763
1764// Test that we will get different SSRCs for each tracks in the offer and answer
1765// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001766TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001767 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001769 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1770 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771
1772 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001773 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001774 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 int audio_ssrc = 0;
1776 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001777 EXPECT_TRUE(
1778 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1779 EXPECT_TRUE(
1780 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 EXPECT_NE(audio_ssrc, video_ssrc);
1782
1783 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001784 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001785 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001786 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 audio_ssrc = 0;
1788 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001789 EXPECT_TRUE(
1790 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1791 EXPECT_TRUE(
1792 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 EXPECT_NE(audio_ssrc, video_ssrc);
1794}
1795
deadbeefeb459812015-12-15 19:24:43 -08001796// Test that it's possible to call AddTrack on a MediaStream after adding
1797// the stream to a PeerConnection.
1798// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001799// Don't run under Unified Plan since the stream API is not available.
1800TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001801 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001802 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001803 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001804 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1805
1806 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001807 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001808 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001809 stream->AddTrack(video_track.get());
1810
kwibergd1fe2812016-04-27 06:47:29 -07001811 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001812 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001813
1814 const cricket::MediaContentDescription* video_desc =
1815 cricket::GetFirstVideoContentDescription(offer->description());
1816 EXPECT_TRUE(video_desc != nullptr);
1817}
1818
1819// Test that it's possible to call RemoveTrack on a MediaStream after adding
1820// the stream to a PeerConnection.
1821// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001822// Don't run under Unified Plan since the stream API is not available.
1823TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001824 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001825 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001826 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001827 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1828
1829 // Remove the video track.
Niels Möllerafb246b2022-04-20 14:26:50 +02001830 stream->RemoveTrack(stream->GetVideoTracks()[0].get());
deadbeefeb459812015-12-15 19:24:43 -08001831
kwibergd1fe2812016-04-27 06:47:29 -07001832 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001833 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001834
1835 const cricket::MediaContentDescription* video_desc =
1836 cricket::GetFirstVideoContentDescription(offer->description());
1837 EXPECT_TRUE(video_desc == nullptr);
1838}
1839
deadbeefbd7d8f72015-12-18 16:58:44 -08001840// Test creating a sender with a stream ID, and ensure the ID is populated
1841// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001842// Don't run under Unified Plan since the stream API is not available.
1843TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001844 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001845 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001846
kwibergd1fe2812016-04-27 06:47:29 -07001847 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001848 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001849
1850 const cricket::MediaContentDescription* video_desc =
1851 cricket::GetFirstVideoContentDescription(offer->description());
1852 ASSERT_TRUE(video_desc != nullptr);
1853 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001854 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001855}
1856
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001858TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001860 ASSERT_LT(0u, pc_->GetSenders().size());
1861 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001862 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001863 pc_->GetReceivers()[0]->track();
Niels Möllerafb246b2022-04-20 14:26:50 +02001864 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865
1866 // Remove the stream. Since we are sending to our selves the local
1867 // and the remote stream is the same.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001868 pc_->RemoveTrackOrError(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 // Do a re-negotiation.
1870 CreateOfferReceiveAnswer();
1871
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 // Test that we still can get statistics for the old track. Even if it is not
1873 // sent any longer.
Niels Möllerafb246b2022-04-20 14:26:50 +02001874 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875}
1876
1877// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001878TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001880 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1881 ASSERT_TRUE(video_receiver);
Niels Möllerafb246b2022-04-20 14:26:50 +02001882 EXPECT_TRUE(DoGetStats(video_receiver->track().get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883}
1884
1885// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001886TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001888 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001889 pc_factory_->CreateAudioTrack("unknown track", nullptr));
1890 EXPECT_FALSE(DoGetStats(unknown_audio_track.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891}
1892
Steve Anton36da6ff2018-02-16 16:04:20 -08001893TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001894 CreatePeerConnectionWithoutDtls();
1895 EXPECT_TRUE(DoGetRTCStats());
1896 // Clearing stats cache is needed now, but should be temporary.
1897 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1898 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001899 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1900 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001901 EXPECT_TRUE(DoGetRTCStats());
1902 pc_->ClearStatsCache();
1903 CreateOfferReceiveAnswer();
1904 EXPECT_TRUE(DoGetRTCStats());
1905}
1906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907// This tests that a SCTP data channel is returned using different
1908// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08001909TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001910 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001911 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912
1913 webrtc::DataChannelInit config;
Florent Castelli72424402022-04-06 03:45:10 +02001914 auto channel = pc_->CreateDataChannelOrError("1", &config);
1915 EXPECT_TRUE(channel.ok());
1916 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001917 EXPECT_TRUE(observer_.renegotiation_needed_);
1918 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919
1920 config.ordered = false;
Florent Castelli72424402022-04-06 03:45:10 +02001921 channel = pc_->CreateDataChannelOrError("2", &config);
1922 EXPECT_TRUE(channel.ok());
1923 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001924 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925
1926 config.ordered = true;
1927 config.maxRetransmits = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001928 channel = pc_->CreateDataChannelOrError("3", &config);
1929 EXPECT_TRUE(channel.ok());
1930 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001931 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001933 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 config.maxRetransmitTime = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001935 channel = pc_->CreateDataChannelOrError("4", &config);
1936 EXPECT_TRUE(channel.ok());
1937 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001938 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939}
1940
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001941// For backwards compatibility, we want people who "unset" maxRetransmits
1942// and maxRetransmitTime by setting them to -1 to get what they want.
1943TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
1944 RTCConfiguration rtc_config;
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001945 CreatePeerConnection(rtc_config);
1946
1947 webrtc::DataChannelInit config;
1948 config.maxRetransmitTime = -1;
1949 config.maxRetransmits = -1;
Florent Castelli72424402022-04-06 03:45:10 +02001950 auto channel = pc_->CreateDataChannelOrError("1", &config);
1951 EXPECT_TRUE(channel.ok());
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001952}
1953
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954// This tests that no data channel is returned if both maxRetransmits and
1955// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08001956TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001958 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001959 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960
1961 std::string label = "test";
1962 webrtc::DataChannelInit config;
1963 config.maxRetransmits = 0;
1964 config.maxRetransmitTime = 0;
1965
Florent Castelli72424402022-04-06 03:45:10 +02001966 auto channel = pc_->CreateDataChannelOrError(label, &config);
1967 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968}
1969
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970// The test verifies that creating a SCTP data channel with an id already in use
1971// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001972TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001974 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001975 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976
1977 webrtc::DataChannelInit config;
1978
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001979 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001980 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001981 auto channel = pc_->CreateDataChannelOrError("1", &config);
1982 EXPECT_TRUE(channel.ok());
1983 EXPECT_EQ(1, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984
Florent Castelli72424402022-04-06 03:45:10 +02001985 channel = pc_->CreateDataChannelOrError("x", &config);
1986 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987
1988 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001989 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001990 channel = pc_->CreateDataChannelOrError("max", &config);
1991 EXPECT_TRUE(channel.ok());
1992 EXPECT_EQ(config.id, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993
1994 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001995 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001996 channel = pc_->CreateDataChannelOrError("x", &config);
1997 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998}
1999
deadbeefab9b2d12015-10-14 11:33:11 -07002000// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002001TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002002 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002003 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002004
2005 std::string label = "test";
Florent Castelli72424402022-04-06 03:45:10 +02002006 auto channel = pc_->CreateDataChannelOrError(label, nullptr);
2007 EXPECT_TRUE(channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002008
Florent Castelli72424402022-04-06 03:45:10 +02002009 auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr);
2010 EXPECT_TRUE(dup_channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002011}
2012
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002013#ifdef WEBRTC_HAVE_SCTP
Zhi Huang644fde42018-04-02 19:16:26 -07002014// This tests that SCTP data channels can be rejected in an answer.
2015TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2016#else
2017TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2018#endif
2019{
Niels Möllerf06f9232018-08-07 12:32:18 +02002020 RTCConfiguration rtc_config;
2021 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002022
Florent Castelli72424402022-04-06 03:45:10 +02002023 auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL);
Zhi Huang644fde42018-04-02 19:16:26 -07002024
2025 CreateOfferAsLocalDescription();
2026
2027 // Create an answer where the m-line for data channels are rejected.
2028 std::string sdp;
2029 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2030 std::unique_ptr<SessionDescriptionInterface> answer(
2031 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2032 ASSERT_TRUE(answer);
2033 cricket::ContentInfo* data_info =
2034 cricket::GetFirstDataContent(answer->description());
2035 data_info->rejected = true;
2036
2037 DoSetRemoteDescription(std::move(answer));
Florent Castelli72424402022-04-06 03:45:10 +02002038 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state());
Zhi Huang644fde42018-04-02 19:16:26 -07002039}
2040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041// Test that we can create a session description from an SDP string from
2042// FireFox, use it as a remote session description, generate an answer and use
2043// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002044TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002045 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002046 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002047 AddAudioTrack("audio_label");
2048 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002049 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002050 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002051 webrtc::kFireFoxSdpOffer, nullptr));
2052 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 CreateAnswerAsLocalDescription();
Niels Möllerafb246b2022-04-20 14:26:50 +02002054 ASSERT_TRUE(pc_->local_description() != nullptr);
2055 ASSERT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
2057 const cricket::ContentInfo* content =
2058 cricket::GetFirstAudioContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002059 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 EXPECT_FALSE(content->rejected);
2061
2062 content =
2063 cricket::GetFirstVideoContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002064 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 EXPECT_FALSE(content->rejected);
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002066#ifdef WEBRTC_HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 content =
2068 cricket::GetFirstDataContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002069 ASSERT_TRUE(content != nullptr);
Zhi Huange830e682018-03-30 10:48:35 -07002070 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002071#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
Harald Alvestrand0d018412021-11-04 13:52:31 +00002074// Test that fallback from DTLS to SDES is not supported.
2075// The fallback was previously supported but was removed to simplify the code
2076// and because it's non-standard.
2077TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002078 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002079 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002080 // Wait for fake certificate to be generated. Previously, this is what caused
2081 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002082 AddAudioTrack("audio_label");
2083 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002084 ASSERT_NE(nullptr, fake_certificate_generator_);
2085 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2086 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002087 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002088 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2089 nullptr));
Harald Alvestrand0d018412021-11-04 13:52:31 +00002090 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002091}
2092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093// Test that we can create an audio only offer and receive an answer with a
2094// limited set of audio codecs and receive an updated offer with more audio
2095// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002096TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002097 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002098 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 CreateOfferAsLocalDescription();
2100
Florent Castelli15a38de2022-04-06 00:38:21 +02002101 const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2102 ? webrtc::kAudioSdpPlanB
2103 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002104 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002105 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002106 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
Steve Anton36da6ff2018-02-16 16:04:20 -08002108 const char* reoffer_sdp =
Florent Castelli15a38de2022-04-06 00:38:21 +02002109 (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
Steve Anton36da6ff2018-02-16 16:04:20 -08002110 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2111 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002112 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002113 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002114 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 CreateAnswerAsLocalDescription();
2116}
2117
deadbeefc80741f2015-10-22 13:14:45 -07002118// Test that if we're receiving (but not sending) a track, subsequent offers
2119// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002120TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002121 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002122 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002123 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002124 CreateAnswerAsLocalDescription();
2125
2126 // At this point we should be receiving stream 1, but not sending anything.
2127 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002128 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002129 DoCreateOffer(&offer, nullptr);
2130
2131 const cricket::ContentInfo* video_content =
2132 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002133 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2134 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002135
2136 const cricket::ContentInfo* audio_content =
2137 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002138 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2139 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002140}
2141
2142// Test that if we're receiving (but not sending) a track, and the
2143// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2144// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002145TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002146 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002147 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002148 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002149 CreateAnswerAsLocalDescription();
2150
2151 // At this point we should be receiving stream 1, but not sending anything.
2152 // A new offer would be recvonly, but we'll set the "no receive" constraints
2153 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002154 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002155 RTCOfferAnswerOptions options;
2156 options.offer_to_receive_audio = 0;
2157 options.offer_to_receive_video = 0;
2158 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002159
2160 const cricket::ContentInfo* video_content =
2161 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002162 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2163 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002164
2165 const cricket::ContentInfo* audio_content =
2166 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002167 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2168 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002169}
2170
deadbeef653b8e02015-11-11 12:55:10 -08002171// Test that we can use SetConfiguration to change the ICE servers of the
2172// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002173TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002174 CreatePeerConnection();
2175
Steve Anton36da6ff2018-02-16 16:04:20 -08002176 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002177 PeerConnectionInterface::IceServer server;
2178 server.uri = "stun:test_hostname";
2179 config.servers.push_back(server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002180 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef653b8e02015-11-11 12:55:10 -08002181
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002182 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2183 EXPECT_EQ("test_hostname",
2184 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002185}
2186
Steve Anton36da6ff2018-02-16 16:04:20 -08002187TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002188 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002189 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002190 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002191 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002192 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2193}
2194
Steve Anton36da6ff2018-02-16 16:04:20 -08002195TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002196 PeerConnectionInterface::RTCConfiguration config;
2197 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002198 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002199 config = pc_->GetConfiguration();
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002200 EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002201
2202 config.prune_turn_ports = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002203 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002204 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
2205 port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002206}
2207
skvladd1f5fda2017-02-03 16:54:05 -08002208// Test that the ice check interval can be changed. This does not verify that
2209// the setting makes it all the way to P2PTransportChannel, as that would
2210// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002211TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002212 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002213 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002214 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002215 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002216 config.ice_check_min_interval = 100;
Niels Möller2579f0c2019-08-19 09:58:17 +02002217 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002218 config = pc_->GetConfiguration();
2219 EXPECT_EQ(config.ice_check_min_interval, 100);
2220}
2221
2222TEST_P(PeerConnectionInterfaceTest,
2223 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2224 PeerConnectionInterface::RTCConfiguration config;
2225 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2226 CreatePeerConnection(config);
2227 config = pc_->GetConfiguration();
2228 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2229
2230 config.surface_ice_candidates_on_ice_transport_type_changed = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002231 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002232 config = pc_->GetConfiguration();
2233 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002234}
2235
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002236// Test that when SetConfiguration changes both the pool size and other
2237// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002238TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002239 SetConfigurationCreatesPooledSessionCorrectly) {
2240 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002241 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002242 config.ice_candidate_pool_size = 1;
2243 PeerConnectionInterface::IceServer server;
2244 server.uri = kStunAddressOnly;
2245 config.servers.push_back(server);
2246 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002247 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002248
2249 const cricket::FakePortAllocatorSession* session =
2250 static_cast<const cricket::FakePortAllocatorSession*>(
2251 port_allocator_->GetPooledSession());
2252 ASSERT_NE(nullptr, session);
2253 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002254}
2255
deadbeef293e9262017-01-11 12:28:30 -08002256// Test that after SetLocalDescription, changing the pool size is not allowed,
2257// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002258TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002259 CantChangePoolSizeAfterSetLocalDescription) {
2260 CreatePeerConnection();
2261 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002262 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002263 config.ice_candidate_pool_size = 1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002264 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002265
2266 // Set remote offer; can still change pool size at this point.
2267 CreateOfferAsRemoteDescription();
2268 config.ice_candidate_pool_size = 2;
Niels Möller2579f0c2019-08-19 09:58:17 +02002269 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002270
2271 // Set local answer; now it's too late.
2272 CreateAnswerAsLocalDescription();
2273 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002274 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002275 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2276}
2277
deadbeef42a42632017-03-10 15:18:00 -08002278// Test that after setting an answer, extra pooled sessions are discarded. The
2279// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002280TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002281 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2282 CreatePeerConnection();
2283
2284 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002285 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002286 config.ice_candidate_pool_size = 4;
Niels Möller2579f0c2019-08-19 09:58:17 +02002287 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002288
2289 // Do offer/answer.
2290 CreateOfferAsRemoteDescription();
2291 CreateAnswerAsLocalDescription();
2292
2293 // Expect no pooled sessions to be left.
2294 const cricket::PortAllocatorSession* session =
2295 port_allocator_->GetPooledSession();
2296 EXPECT_EQ(nullptr, session);
2297}
2298
2299// After Close is called, pooled candidates should be discarded so as to not
2300// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002301TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002302 CreatePeerConnection();
2303
Steve Anton36da6ff2018-02-16 16:04:20 -08002304 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002305 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002306 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002307 pc_->Close();
2308
2309 // Expect no pooled sessions to be left.
2310 const cricket::PortAllocatorSession* session =
2311 port_allocator_->GetPooledSession();
2312 EXPECT_EQ(nullptr, session);
2313}
2314
deadbeef293e9262017-01-11 12:28:30 -08002315// Test that SetConfiguration returns an invalid modification error if
2316// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002317TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002318 SetConfigurationReturnsInvalidModificationError) {
2319 PeerConnectionInterface::RTCConfiguration config;
2320 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2321 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2322 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002323 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002324
Steve Anton36da6ff2018-02-16 16:04:20 -08002325 PeerConnectionInterface::RTCConfiguration modified_config =
2326 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002327 modified_config.bundle_policy =
2328 PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möller2579f0c2019-08-19 09:58:17 +02002329 RTCError error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002330 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2331
Steve Anton36da6ff2018-02-16 16:04:20 -08002332 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002333 modified_config.rtcp_mux_policy =
2334 PeerConnectionInterface::kRtcpMuxPolicyRequire;
Niels Möller2579f0c2019-08-19 09:58:17 +02002335 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002336 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2337
Steve Anton36da6ff2018-02-16 16:04:20 -08002338 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002339 modified_config.continual_gathering_policy =
2340 PeerConnectionInterface::GATHER_CONTINUALLY;
Niels Möller2579f0c2019-08-19 09:58:17 +02002341 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002342 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2343}
2344
2345// Test that SetConfiguration returns a range error if the candidate pool size
2346// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002347TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002348 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2349 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002350 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002351 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002352
2353 config.ice_candidate_pool_size = -1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002354 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002355 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2356
2357 config.ice_candidate_pool_size = INT_MAX;
Niels Möller2579f0c2019-08-19 09:58:17 +02002358 error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002359 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2360}
2361
2362// Test that SetConfiguration returns a syntax error if parsing an ICE server
2363// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002364TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002365 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2366 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002367 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002368 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002369
2370 PeerConnectionInterface::IceServer bad_server;
2371 bad_server.uri = "stunn:www.example.com";
2372 config.servers.push_back(bad_server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002373 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002374 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2375}
2376
2377// Test that SetConfiguration returns an invalid parameter error if a TURN
2378// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002379TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002380 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2381 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002382 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002383 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002384
2385 PeerConnectionInterface::IceServer bad_server;
2386 bad_server.uri = "turn:www.example.com";
2387 // Missing password.
2388 bad_server.username = "foo";
2389 config.servers.push_back(bad_server);
2390 RTCError error;
Niels Möller340e0c52019-08-26 11:03:47 +02002391 EXPECT_EQ(pc_->SetConfiguration(config).type(),
2392 RTCErrorType::INVALID_PARAMETER);
deadbeef6de92f92016-12-12 18:49:32 -08002393}
2394
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395// Test that PeerConnection::Close changes the states to closed and all remote
2396// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002397TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 // Initialize a PeerConnection and negotiate local and remote session
2399 // description.
2400 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002401
2402 // With Plan B, verify the stream count. The analog with Unified Plan is the
2403 // RtpTransceiver count.
Florent Castelli15a38de2022-04-06 00:38:21 +02002404 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002405 ASSERT_EQ(1u, pc_->local_streams()->count());
2406 ASSERT_EQ(1u, pc_->remote_streams()->count());
2407 } else {
2408 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2409 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410
2411 pc_->Close();
2412
2413 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2414 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2415 pc_->ice_connection_state());
2416 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2417 pc_->ice_gathering_state());
2418
Florent Castelli15a38de2022-04-06 00:38:21 +02002419 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002420 EXPECT_EQ(1u, pc_->local_streams()->count());
2421 EXPECT_EQ(1u, pc_->remote_streams()->count());
2422 } else {
Harald Alvestrand936f1af2020-09-22 07:41:50 +00002423 // Verify that the RtpTransceivers are still returned.
2424 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Steve Anton36da6ff2018-02-16 16:04:20 -08002425 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426
Steve Anton36da6ff2018-02-16 16:04:20 -08002427 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
Steve Anton36da6ff2018-02-16 16:04:20 -08002428 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
Florent Castelli15a38de2022-04-06 00:38:21 +02002429 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Harald Alvestrand6060df52020-08-11 09:54:02 +02002430 ASSERT_TRUE(audio_receiver);
2431 ASSERT_TRUE(video_receiver);
2432 // Track state may be updated asynchronously.
2433 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2434 audio_receiver->track()->state(), kTimeout);
2435 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2436 video_receiver->track()->state(), kTimeout);
2437 } else {
2438 ASSERT_FALSE(audio_receiver);
2439 ASSERT_FALSE(video_receiver);
2440 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441}
2442
2443// Test that PeerConnection methods fails gracefully after
2444// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002445// Don't run under Unified Plan since the stream API is not available.
2446TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002447 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002448 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 CreateOfferAsRemoteDescription();
2450 CreateAnswerAsLocalDescription();
2451
2452 ASSERT_EQ(1u, pc_->local_streams()->count());
Niels Möllere7cc8832022-01-04 15:20:03 +01002453 rtc::scoped_refptr<MediaStreamInterface> local_stream(
2454 pc_->local_streams()->at(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455
2456 pc_->Close();
2457
Niels Möllerafb246b2022-04-20 14:26:50 +02002458 pc_->RemoveStream(local_stream.get());
2459 EXPECT_FALSE(pc_->AddStream(local_stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460
Florent Castelli72424402022-04-06 03:45:10 +02002461 EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462
Niels Möllerafb246b2022-04-20 14:26:50 +02002463 EXPECT_TRUE(pc_->local_description() != nullptr);
2464 EXPECT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465
kwibergd1fe2812016-04-27 06:47:29 -07002466 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002467 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002468 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002469 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470
2471 std::string sdp;
2472 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002473 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002474 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002475 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476
2477 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002478 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002479 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002480 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481}
2482
2483// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002484TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 InitiateCall();
2486 pc_->Close();
Niels Möllerafb246b2022-04-20 14:26:50 +02002487 DoGetStats(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488}
deadbeefab9b2d12015-10-14 11:33:11 -07002489
2490// NOTE: The series of tests below come from what used to be
2491// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2492// setting a remote or local description has the expected effects.
2493
2494// This test verifies that the remote MediaStreams corresponding to a received
2495// SDP string is created. In this test the two separate MediaStreams are
2496// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002497TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002498 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002499 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002500 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002501
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002502 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002503 EXPECT_TRUE(
2504 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2505 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2506 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2507
2508 // Create a session description based on another SDP with another
2509 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002510 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002511
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002512 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002513 EXPECT_TRUE(
2514 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2515}
2516
2517// This test verifies that when remote tracks are added/removed from SDP, the
2518// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002519// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2520// specific behavior.
2521TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002522 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002523 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002524 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002525 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002526 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002527 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002528 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002529 reference_collection_.get()));
deadbeefab9b2d12015-10-14 11:33:11 -07002530
2531 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002532 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002533 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002534 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002535 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002536 reference_collection_.get()));
zhihuang9763d562016-08-05 11:14:50 -07002537 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002538 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2539 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002540 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002541 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2542 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002543
2544 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002545 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002546 CreateSessionDescriptionAndReference(1, 1);
Niels Möllerafb246b2022-04-20 14:26:50 +02002547 MockTrackObserver audio_track_observer(audio_track2.get());
2548 MockTrackObserver video_track_observer(video_track2.get());
perkjd61bf802016-03-24 03:16:19 -07002549
2550 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2551 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002552 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002553 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002554 reference_collection_.get()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002555 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002556 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002557 audio_track2->state(), kTimeout);
2558 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2559 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002560}
2561
2562// This tests that remote tracks are ended if a local session description is set
2563// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002564TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002565 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002566 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002567 // First create and set a remote offer, then reject its video content in our
2568 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002569 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2570 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2571 ASSERT_TRUE(audio_receiver);
2572 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2573 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002574
Steve Anton36da6ff2018-02-16 16:04:20 -08002575 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2576 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002577 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002578 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2579 video_receiver->track();
2580 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002581
kwibergd1fe2812016-04-27 06:47:29 -07002582 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002583 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002584 cricket::ContentInfo* video_info =
2585 local_answer->description()->GetContentByName("video");
2586 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002587 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002588 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2589 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002590
2591 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002592 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002593 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002594 video_info = local_offer->description()->GetContentByName("video");
2595 ASSERT_TRUE(video_info != nullptr);
2596 video_info->rejected = true;
2597 cricket::ContentInfo* audio_info =
2598 local_offer->description()->GetContentByName("audio");
2599 ASSERT_TRUE(audio_info != nullptr);
2600 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002601 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002602 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002603 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2604 kTimeout);
2605 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2606 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002607}
2608
2609// This tests that we won't crash if the remote track has been removed outside
2610// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002611// Don't run under Unified Plan since the stream API is not available.
2612TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002613 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002614 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002615 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002616 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Niels Möllerafb246b2022-04-20 14:26:50 +02002617 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0].get());
2618 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0].get());
deadbeefab9b2d12015-10-14 11:33:11 -07002619
kwibergd1fe2812016-04-27 06:47:29 -07002620 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002621 webrtc::CreateSessionDescription(SdpType::kAnswer,
2622 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002623 cricket::ContentInfo* video_info =
2624 local_answer->description()->GetContentByName("video");
2625 video_info->rejected = true;
2626 cricket::ContentInfo* audio_info =
2627 local_answer->description()->GetContentByName("audio");
2628 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002629 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002630
2631 // No crash is a pass.
2632}
2633
deadbeef5e97fb52015-10-15 12:49:08 -07002634// This tests that if a recvonly remote description is set, no remote streams
2635// will be created, even if the description contains SSRCs/MSIDs.
2636// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002637TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002638 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002639 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002640
Steve Anton36da6ff2018-02-16 16:04:20 -08002641 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002642 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002643 CreateAndSetRemoteOffer(recvonly_offer);
2644
2645 EXPECT_EQ(0u, observer_.remote_streams()->count());
2646}
2647
deadbeefab9b2d12015-10-14 11:33:11 -07002648// This tests that a default MediaStream is created if a remote session
2649// description doesn't contain any streams and no MSID support.
2650// It also tests that the default stream is updated if a video m-line is added
2651// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002652// Don't run under Unified Plan since this behavior is Plan B specific.
2653TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002654 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002655 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002656 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2657
2658 ASSERT_EQ(1u, observer_.remote_streams()->count());
2659 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2660
2661 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2662 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002663 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002664
2665 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2666 ASSERT_EQ(1u, observer_.remote_streams()->count());
2667 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2668 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002669 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2670 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002671 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2672 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002673 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2674 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002675}
2676
2677// This tests that a default MediaStream is created if a remote session
2678// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002679// Don't run under Unified Plan since this behavior is Plan B specific.
2680TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002681 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002682 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002683 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002684 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2685
2686 ASSERT_EQ(1u, observer_.remote_streams()->count());
2687 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2688
2689 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2690 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002691 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002692}
2693
2694// This tests that it won't crash when PeerConnection tries to remove
2695// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002696// Don't run under Unified Plan since this behavior is Plan B specific.
2697TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002698 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002699 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002700 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002701 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Niels Möllerafb246b2022-04-20 14:26:50 +02002702 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0].get());
2703 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0].get());
deadbeefab9b2d12015-10-14 11:33:11 -07002704
2705 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2706
2707 // No crash is a pass.
2708}
2709
2710// This tests that a default MediaStream is created if the remote session
2711// description doesn't contain any streams and don't contain an indication if
2712// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002713// Don't run under Unified Plan since this behavior is Plan B specific.
2714TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002715 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002716 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002717 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002718 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2719
2720 ASSERT_EQ(1u, observer_.remote_streams()->count());
2721 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2722 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2723 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2724}
2725
2726// This tests that a default MediaStream is not created if the remote session
2727// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002728// Don't run under Unified Plan since this behavior is Plan B specific.
2729TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002730 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002731 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002732 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2733 EXPECT_EQ(0u, observer_.remote_streams()->count());
2734}
2735
deadbeefbda7e0b2015-12-08 17:13:40 -08002736// This tests that when setting a new description, the old default tracks are
2737// not destroyed and recreated.
2738// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002739// Don't run under Unified Plan since this behavior is Plan B specific.
2740TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002741 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002742 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002743 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002744 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2745
2746 ASSERT_EQ(1u, observer_.remote_streams()->count());
2747 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2748 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2749
2750 // Set the track to "disabled", then set a new description and ensure the
2751 // track is still disabled, which ensures it hasn't been recreated.
2752 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2753 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2754 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2755 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2756}
2757
deadbeefab9b2d12015-10-14 11:33:11 -07002758// This tests that a default MediaStream is not created if a remote session
2759// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08002760// Don't run under Unified Plan since this behavior is Plan B specific.
2761TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002762 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002763 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002764 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002765 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002766 EXPECT_TRUE(
2767 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2768
2769 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2770 EXPECT_EQ(0u, observer_.remote_streams()->count());
2771}
2772
Seth Hampson5897a6e2018-04-03 11:16:33 -07002773// This tests that a default MediaStream is created if a remote SDP comes from
2774// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
2775TEST_F(PeerConnectionInterfaceTestPlanB,
2776 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002777 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002778 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07002779 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
2780 // Add a=msid lines to simulate a Unified Plan endpoint that only
2781 // signals stream IDs with a=msid lines.
2782 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
2783
2784 CreateAndSetRemoteOffer(sdp_string);
2785
2786 ASSERT_EQ(1u, observer_.remote_streams()->count());
2787 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2788 EXPECT_EQ("default", remote_stream->id());
2789 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2790}
2791
Seth Hampson5b4f0752018-04-02 16:31:36 -07002792// This tests that when a Plan B endpoint receives an SDP that signals no media
2793// stream IDs indicated by the special character "-" in the a=msid line, that
2794// a default stream ID will be used for the MediaStream ID. This can occur
2795// when a Unified Plan endpoint signals no media stream IDs, but signals both
2796// a=ssrc msid and a=msid lines for interop signaling with Plan B.
2797TEST_F(PeerConnectionInterfaceTestPlanB,
2798 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002799 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002800 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07002801 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
2802 // the sender's stream ID will be interpreted as no stream IDs.
2803 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
2804 sdp_string.append("a=msid:- audiotrack0\n");
2805
2806 CreateAndSetRemoteOffer(sdp_string);
2807
2808 ASSERT_EQ(1u, observer_.remote_streams()->count());
2809 // Because SSRCs are signaled the track ID will be what was signaled in the
2810 // a=msid line.
2811 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2812 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2813 EXPECT_EQ("default", remote_stream->id());
2814 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07002815
2816 // Previously a bug ocurred when setting the remote description a second time.
2817 // This is because we checked equality of the remote StreamParams stream ID
2818 // (empty), and the previously set stream ID for the remote sender
2819 // ("default"). This cause a track to be removed, then added, when really
2820 // nothing should occur because it is the same track.
2821 CreateAndSetRemoteOffer(sdp_string);
2822 EXPECT_EQ(0u, observer_.remove_track_events_.size());
2823 EXPECT_EQ(1u, observer_.add_track_events_.size());
2824 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2825 remote_stream = observer_.remote_streams()->at(0);
2826 EXPECT_EQ("default", remote_stream->id());
2827 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07002828}
2829
deadbeefab9b2d12015-10-14 11:33:11 -07002830// This tests that an RtpSender is created when the local description is set
2831// after adding a local stream.
2832// TODO(deadbeef): This test and the one below it need to be updated when
2833// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08002834// Don't run under Unified Plan since this behavior is Plan B specific.
2835TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002836 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002837 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002838
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002839 // Create an offer with 1 stream with 2 tracks of each type.
2840 rtc::scoped_refptr<StreamCollection> stream_collection =
2841 CreateStreamCollection(1, 2);
2842 pc_->AddStream(stream_collection->at(0));
2843 std::unique_ptr<SessionDescriptionInterface> offer;
2844 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002845 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002846
deadbeefab9b2d12015-10-14 11:33:11 -07002847 auto senders = pc_->GetSenders();
2848 EXPECT_EQ(4u, senders.size());
2849 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2850 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2851 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2852 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2853
2854 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002855 pc_->RemoveStream(stream_collection->at(0));
2856 stream_collection = CreateStreamCollection(1, 1);
2857 pc_->AddStream(stream_collection->at(0));
2858 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002859 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002860
deadbeefab9b2d12015-10-14 11:33:11 -07002861 senders = pc_->GetSenders();
2862 EXPECT_EQ(2u, senders.size());
2863 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2864 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2865 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2866 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2867}
2868
2869// This tests that an RtpSender is created when the local description is set
2870// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002871// Don't run under Unified Plan since this behavior is Plan B specific.
2872TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002873 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002874 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002875 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002876
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002877 rtc::scoped_refptr<StreamCollection> stream_collection =
2878 CreateStreamCollection(1, 2);
2879 // Add a stream to create the offer, but remove it afterwards.
2880 pc_->AddStream(stream_collection->at(0));
2881 std::unique_ptr<SessionDescriptionInterface> offer;
2882 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2883 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002884
Steve Antondb45ca82017-09-11 18:27:34 -07002885 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002886 auto senders = pc_->GetSenders();
2887 EXPECT_EQ(0u, senders.size());
2888
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002889 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002890 senders = pc_->GetSenders();
2891 EXPECT_EQ(4u, senders.size());
2892 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2893 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2894 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2895 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2896}
2897
2898// This tests that the expected behavior occurs if the SSRC on a local track is
2899// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002900TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002901 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002902 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002903 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002904
Steve Anton36da6ff2018-02-16 16:04:20 -08002905 AddAudioTrack(kAudioTracks[0]);
2906 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002907 std::unique_ptr<SessionDescriptionInterface> offer;
2908 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2909 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07002910 std::unique_ptr<SessionDescriptionInterface> modified_offer =
2911 webrtc::CreateSessionDescription(
2912 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002913 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07002914 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002915
deadbeefab9b2d12015-10-14 11:33:11 -07002916 auto senders = pc_->GetSenders();
2917 EXPECT_EQ(2u, senders.size());
2918 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2919 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2920
2921 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002922 cricket::MediaContentDescription* desc =
2923 cricket::GetFirstAudioContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002924 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002925 for (StreamParams& stream : desc->mutable_streams()) {
2926 for (unsigned int& ssrc : stream.ssrcs) {
2927 ++ssrc;
2928 }
2929 }
deadbeefab9b2d12015-10-14 11:33:11 -07002930
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002931 desc =
2932 cricket::GetFirstVideoContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002933 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002934 for (StreamParams& stream : desc->mutable_streams()) {
2935 for (unsigned int& ssrc : stream.ssrcs) {
2936 ++ssrc;
2937 }
2938 }
2939
Steve Antondb45ca82017-09-11 18:27:34 -07002940 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002941 senders = pc_->GetSenders();
2942 EXPECT_EQ(2u, senders.size());
2943 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2944 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2945 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2946 // changed.
2947}
2948
2949// This tests that the expected behavior occurs if a new session description is
2950// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002951// Don't run under Unified Plan since the stream API is not available.
2952TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002953 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002954 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002955 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002956
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002957 rtc::scoped_refptr<StreamCollection> stream_collection =
2958 CreateStreamCollection(2, 1);
2959 pc_->AddStream(stream_collection->at(0));
2960 std::unique_ptr<SessionDescriptionInterface> offer;
2961 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002962 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002963
deadbeefab9b2d12015-10-14 11:33:11 -07002964 auto senders = pc_->GetSenders();
2965 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002966 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2967 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002968
2969 // Add a new MediaStream but with the same tracks as in the first stream.
2970 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2971 webrtc::MediaStream::Create(kStreams[1]));
Niels Möllerafb246b2022-04-20 14:26:50 +02002972 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0].get());
2973 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0].get());
2974 pc_->AddStream(stream_1.get());
deadbeefab9b2d12015-10-14 11:33:11 -07002975
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002976 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002977 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002978
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002979 auto new_senders = pc_->GetSenders();
2980 // Should be the same senders as before, but with updated stream id.
2981 // Note that this behavior is subject to change in the future.
2982 // We may decide the PC should ignore existing tracks in AddStream.
2983 EXPECT_EQ(senders, new_senders);
2984 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2985 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002986}
2987
zhihuang81c3a032016-11-17 12:06:24 -08002988// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002989TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002990 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002991 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08002992 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2993 EXPECT_EQ(observer_.num_added_tracks_, 1);
2994 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2995
2996 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08002997 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07002998 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08002999 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3000}
3001
deadbeefd1a38b52016-12-10 13:15:33 -08003002// Test that when SetConfiguration is called and the configuration is
3003// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003004TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003005 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003006 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003007 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003008 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003009 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003010 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3011 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003012
3013 // Do initial offer/answer so there's something to restart.
3014 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003015 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003016
3017 // Grab the ufrags.
3018 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3019
3020 // Change ICE policy, which should trigger an ICE restart on the next offer.
3021 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003022 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003023 CreateOfferAsLocalDescription();
3024
3025 // Grab the new ufrags.
3026 std::vector<std::string> subsequent_ufrags =
3027 GetUfrags(pc_->local_description());
3028
3029 // Sanity check.
3030 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3031 // Check that each ufrag is different.
3032 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3033 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3034 }
3035}
3036
3037// Test that when SetConfiguration is called and the configuration *isn't*
3038// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003039TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003040 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003041 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003042 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003043 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003044 config = pc_->GetConfiguration();
3045 AddAudioTrack(kAudioTracks[0]);
3046 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003047
3048 // Do initial offer/answer so there's something to restart.
3049 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003050 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003051
3052 // Grab the ufrags.
3053 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3054
3055 // Call SetConfiguration with a config identical to what the PC was
3056 // constructed with.
Niels Möller2579f0c2019-08-19 09:58:17 +02003057 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003058 CreateOfferAsLocalDescription();
3059
3060 // Grab the new ufrags.
3061 std::vector<std::string> subsequent_ufrags =
3062 GetUfrags(pc_->local_description());
3063
3064 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3065}
3066
3067// Test for a weird corner case scenario:
3068// 1. Audio/video session established.
3069// 2. SetConfiguration changes ICE config; ICE restart needed.
3070// 3. ICE restart initiated by remote peer, but only for one m= section.
3071// 4. Next createOffer should initiate an ICE restart, but only for the other
3072// m= section; it would be pointless to do an ICE restart for the m= section
3073// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003074TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003075 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003076 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003077 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003078 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003079 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003080 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3081 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003082
3083 // Do initial offer/answer so there's something to restart.
3084 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003085 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003086
3087 // Change ICE policy, which should set the "needs-ice-restart" flag.
3088 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003089 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003090
3091 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003092 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003093 webrtc::CreateSessionDescription(SdpType::kOffer,
3094 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003095 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003096 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3097 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003098 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003099 CreateAnswerAsLocalDescription();
3100
3101 // Grab the ufrags.
3102 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003103 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003104
3105 // Create offer and grab the new ufrags.
3106 CreateOfferAsLocalDescription();
3107 std::vector<std::string> subsequent_ufrags =
3108 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003109 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003110
3111 // Ensure that only the ufrag for the second m= section changed.
3112 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3113 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3114}
3115
deadbeeffe4a8a42016-12-20 17:56:17 -08003116// Tests that the methods to return current/pending descriptions work as
3117// expected at different points in the offer/answer exchange. This test does
3118// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003119TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003120 // This disables DTLS so we can apply an answer to ourselves.
3121 CreatePeerConnection();
3122
3123 // Create initial local offer and get SDP (which will also be used as
3124 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003125 std::unique_ptr<SessionDescriptionInterface> local_offer;
3126 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003127 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003128 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003129
3130 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003131 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3132 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3133 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003134 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3135 EXPECT_EQ(nullptr, pc_->current_local_description());
3136 EXPECT_EQ(nullptr, pc_->current_remote_description());
3137
3138 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003139 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003140 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003141 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3142 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3143 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3144 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003145 EXPECT_EQ(nullptr, pc_->current_local_description());
3146 EXPECT_EQ(nullptr, pc_->current_remote_description());
3147
3148 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003149 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003150 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003151 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3152 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003153 EXPECT_EQ(nullptr, pc_->pending_local_description());
3154 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003155 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3156 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003157
3158 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003159 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003160 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003161 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3162 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3163 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003164 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003165 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3166 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003167
3168 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003169 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003170 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003171 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3172 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3173 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3174 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3175 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3176 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003177
3178 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003179 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003180 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003181 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3182 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003183 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3184 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003185 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3186 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003187}
3188
zhihuang77985012017-02-07 15:45:16 -08003189// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3190// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003191// This version tests the StartRtcEventLog version that receives an object
Artem Titov880fa812021-07-30 22:30:23 +02003192// of type `RtcEventLogOutput`.
Steve Anton36da6ff2018-02-16 16:04:20 -08003193TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003194 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3195 CreatePeerConnection();
3196 // The RtcEventLog will be reset when the PeerConnection is closed.
3197 pc_->Close();
3198
Niels Möllerdec9f742019-06-03 15:25:20 +02003199 EXPECT_FALSE(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02003200 pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(),
Niels Möllerdec9f742019-06-03 15:25:20 +02003201 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003202 pc_->StopRtcEventLog();
3203}
3204
deadbeef30952b42017-04-21 02:41:29 -07003205// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003206TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003207 CreatePeerConnection();
3208
3209 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003210 RTCOfferAnswerOptions options;
3211 options.offer_to_receive_audio = 1;
3212 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003213 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003214 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003215 cricket::SessionDescription* desc = offer->description();
3216 ASSERT_EQ(2u, desc->transport_infos().size());
3217 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3218 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3219
3220 // Apply the offer as a remote description, then create an answer.
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003221 EXPECT_FALSE(pc_->can_trickle_ice_candidates());
Steve Antondb45ca82017-09-11 18:27:34 -07003222 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003223 ASSERT_TRUE(pc_->can_trickle_ice_candidates());
3224 EXPECT_TRUE(*(pc_->can_trickle_ice_candidates()));
deadbeef30952b42017-04-21 02:41:29 -07003225 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003226 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003227 desc = answer->description();
3228 ASSERT_EQ(2u, desc->transport_infos().size());
3229 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3230 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3231}
3232
deadbeef1dcb1642017-03-29 21:08:16 -07003233// Test that ICE renomination isn't offered if it's not enabled in the PC's
3234// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003235TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003236 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003237 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003238 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003239 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003240 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003241
3242 std::unique_ptr<SessionDescriptionInterface> offer;
3243 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3244 cricket::SessionDescription* desc = offer->description();
3245 EXPECT_EQ(1u, desc->transport_infos().size());
3246 EXPECT_FALSE(
3247 desc->transport_infos()[0].description.GetIceParameters().renomination);
3248}
3249
3250// Test that the ICE renomination option is present in generated offers/answers
3251// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003252TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003253 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003254 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003255 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003256 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003257 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003258
3259 std::unique_ptr<SessionDescriptionInterface> offer;
3260 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3261 cricket::SessionDescription* desc = offer->description();
3262 EXPECT_EQ(1u, desc->transport_infos().size());
3263 EXPECT_TRUE(
3264 desc->transport_infos()[0].description.GetIceParameters().renomination);
3265
3266 // Set the offer as a remote description, then create an answer and ensure it
3267 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003268 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003269 std::unique_ptr<SessionDescriptionInterface> answer;
3270 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3271 desc = answer->description();
3272 EXPECT_EQ(1u, desc->transport_infos().size());
3273 EXPECT_TRUE(
3274 desc->transport_infos()[0].description.GetIceParameters().renomination);
3275}
3276
3277// Test that if CreateOffer is called with the deprecated "offer to receive
3278// audio/video" constraints, they're processed and result in an offer with
3279// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003280TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003281 CreatePeerConnection();
3282
Niels Möllerf06f9232018-08-07 12:32:18 +02003283 RTCOfferAnswerOptions options;
3284 options.offer_to_receive_audio = 1;
3285 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003286 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003287 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003288
3289 cricket::SessionDescription* desc = offer->description();
3290 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3291 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3292 ASSERT_NE(nullptr, audio);
3293 ASSERT_NE(nullptr, video);
3294 EXPECT_FALSE(audio->rejected);
3295 EXPECT_FALSE(video->rejected);
3296}
3297
3298// Test that if CreateAnswer is called with the deprecated "offer to receive
3299// audio/video" constraints, they're processed and can be used to reject an
3300// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003301// Don't run under Unified Plan since this behavior is not supported.
3302TEST_F(PeerConnectionInterfaceTestPlanB,
3303 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003304 CreatePeerConnection();
3305
3306 // First, create an offer with audio/video and apply it as a remote
3307 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003308 RTCOfferAnswerOptions options;
3309 options.offer_to_receive_audio = 1;
3310 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003311 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003312 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003313 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003314
3315 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003316 options.offer_to_receive_audio = 0;
3317 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003318 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003319 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003320
3321 cricket::SessionDescription* desc = answer->description();
3322 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3323 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3324 ASSERT_NE(nullptr, audio);
3325 ASSERT_NE(nullptr, video);
3326 EXPECT_TRUE(audio->rejected);
3327 EXPECT_TRUE(video->rejected);
3328}
3329
deadbeef1dcb1642017-03-29 21:08:16 -07003330// Test that negotiation can succeed with a data channel only, and with the max
3331// bundle policy. Previously there was a bug that prevented this.
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003332#ifdef WEBRTC_HAVE_SCTP
Steve Anton36da6ff2018-02-16 16:04:20 -08003333TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3334#else
3335TEST_P(PeerConnectionInterfaceTest,
3336 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003337#endif // WEBRTC_HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003338 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003339 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003340 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003341 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003342
3343 // First, create an offer with only a data channel and apply it as a remote
3344 // description.
Florent Castelli72424402022-04-06 03:45:10 +02003345 pc_->CreateDataChannelOrError("test", nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07003346 std::unique_ptr<SessionDescriptionInterface> offer;
3347 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003348 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003349
3350 // Create and set answer as well.
3351 std::unique_ptr<SessionDescriptionInterface> answer;
3352 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003353 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003354}
3355
Steve Anton36da6ff2018-02-16 16:04:20 -08003356TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003357 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003358 BitrateSettings bitrate;
3359 bitrate.start_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003360 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3361}
3362
Steve Anton36da6ff2018-02-16 16:04:20 -08003363TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003364 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003365 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003366 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003367 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3368}
3369
Steve Anton36da6ff2018-02-16 16:04:20 -08003370TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003371 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003372 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003373 bitrate.min_bitrate_bps = 5;
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003374 bitrate.start_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003375 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3376}
3377
Steve Anton36da6ff2018-02-16 16:04:20 -08003378TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003379 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003380 BitrateSettings bitrate;
3381 bitrate.start_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003382 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3383}
3384
Steve Anton36da6ff2018-02-16 16:04:20 -08003385TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003386 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003387 BitrateSettings bitrate;
3388 bitrate.start_bitrate_bps = 10;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003389 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003390 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3391}
3392
Steve Anton36da6ff2018-02-16 16:04:20 -08003393TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003394 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003395 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003396 bitrate.min_bitrate_bps = 10;
3397 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003398 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3399}
3400
Steve Anton36da6ff2018-02-16 16:04:20 -08003401TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003402 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003403 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003404 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003405 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3406}
3407
Niels Möller0c4f7be2018-05-07 14:01:37 +02003408// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003409// by Call's BitrateConstraints, which comes from the SDP or a default value.
3410// This test checks that a call to SetBitrate with a current bitrate that will
3411// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003412TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003413 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003414 BitrateSettings bitrate;
3415 bitrate.start_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003416 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3417}
3418
zhihuang1c378ed2017-08-17 14:10:50 -07003419// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003420TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003421 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3422 RTCOfferAnswerOptions rtc_options;
3423
3424 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3425 // than kMaxOfferToReceiveMedia should be treated as invalid.
3426 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3427 CreatePeerConnection();
3428 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3429
3430 rtc_options.offer_to_receive_audio =
3431 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3432 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3433}
3434
Steve Anton36da6ff2018-02-16 16:04:20 -08003435TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003436 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3437 RTCOfferAnswerOptions rtc_options;
3438
3439 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3440 // than kMaxOfferToReceiveMedia should be treated as invalid.
3441 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3442 CreatePeerConnection();
3443 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3444
3445 rtc_options.offer_to_receive_video =
3446 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3447 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3448}
3449
3450// Test that the audio and video content will be added to an offer if both
Artem Titov880fa812021-07-30 22:30:23 +02003451// `offer_to_receive_audio` and `offer_to_receive_video` options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003452TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003453 RTCOfferAnswerOptions rtc_options;
3454 rtc_options.offer_to_receive_audio = 1;
3455 rtc_options.offer_to_receive_video = 1;
3456
3457 std::unique_ptr<SessionDescriptionInterface> offer;
3458 CreatePeerConnection();
3459 offer = CreateOfferWithOptions(rtc_options);
3460 ASSERT_TRUE(offer);
3461 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3462 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3463}
3464
3465// Test that only audio content will be added to the offer if only
Artem Titov880fa812021-07-30 22:30:23 +02003466// `offer_to_receive_audio` options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003467TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003468 RTCOfferAnswerOptions rtc_options;
3469 rtc_options.offer_to_receive_audio = 1;
3470 rtc_options.offer_to_receive_video = 0;
3471
3472 std::unique_ptr<SessionDescriptionInterface> offer;
3473 CreatePeerConnection();
3474 offer = CreateOfferWithOptions(rtc_options);
3475 ASSERT_TRUE(offer);
3476 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3477 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3478}
3479
Artem Titov880fa812021-07-30 22:30:23 +02003480// Test that only video content will be added if only `offer_to_receive_video`
zhihuang1c378ed2017-08-17 14:10:50 -07003481// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003482TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003483 RTCOfferAnswerOptions rtc_options;
3484 rtc_options.offer_to_receive_audio = 0;
3485 rtc_options.offer_to_receive_video = 1;
3486
3487 std::unique_ptr<SessionDescriptionInterface> offer;
3488 CreatePeerConnection();
3489 offer = CreateOfferWithOptions(rtc_options);
3490 ASSERT_TRUE(offer);
3491 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3492 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3493}
3494
zhihuang1c378ed2017-08-17 14:10:50 -07003495// Test that no media content will be added to the offer if using default
3496// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003497TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003498 RTCOfferAnswerOptions rtc_options;
3499
3500 std::unique_ptr<SessionDescriptionInterface> offer;
3501 CreatePeerConnection();
3502 offer = CreateOfferWithOptions(rtc_options);
3503 ASSERT_TRUE(offer);
3504 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3505 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3506}
3507
Artem Titov880fa812021-07-30 22:30:23 +02003508// Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise
zhihuang1c378ed2017-08-17 14:10:50 -07003509// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003510TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3511 CreatePeerConnection();
3512
zhihuang1c378ed2017-08-17 14:10:50 -07003513 RTCOfferAnswerOptions rtc_options;
3514 rtc_options.ice_restart = false;
3515 rtc_options.offer_to_receive_audio = 1;
3516
3517 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003518 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003519 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3520 auto ufrag1 =
3521 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3522 auto pwd1 =
3523 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003524
Artem Titov880fa812021-07-30 22:30:23 +02003525 // `ice_restart` is false, the ufrag/pwd shouldn't change.
zhihuang1c378ed2017-08-17 14:10:50 -07003526 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003527 auto ufrag2 =
3528 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3529 auto pwd2 =
3530 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003531
Artem Titov880fa812021-07-30 22:30:23 +02003532 // `ice_restart` is true, the ufrag/pwd should change.
zhihuang1c378ed2017-08-17 14:10:50 -07003533 rtc_options.ice_restart = true;
3534 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003535 auto ufrag3 =
3536 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3537 auto pwd3 =
3538 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003539
3540 EXPECT_EQ(ufrag1, ufrag2);
3541 EXPECT_EQ(pwd1, pwd2);
3542 EXPECT_NE(ufrag2, ufrag3);
3543 EXPECT_NE(pwd2, pwd3);
3544}
3545
Artem Titov880fa812021-07-30 22:30:23 +02003546// Test that if `use_rtp_mux` is true, the bundling will be enabled in the
zhihuang1c378ed2017-08-17 14:10:50 -07003547// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003548TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003549 RTCOfferAnswerOptions rtc_options;
3550 rtc_options.offer_to_receive_audio = 1;
3551 rtc_options.offer_to_receive_video = 1;
3552
3553 std::unique_ptr<SessionDescriptionInterface> offer;
3554 CreatePeerConnection();
3555
3556 rtc_options.use_rtp_mux = true;
3557 offer = CreateOfferWithOptions(rtc_options);
3558 ASSERT_TRUE(offer);
3559 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3560 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3561 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3562
3563 rtc_options.use_rtp_mux = false;
3564 offer = CreateOfferWithOptions(rtc_options);
3565 ASSERT_TRUE(offer);
3566 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3567 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3568 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3569}
3570
zhihuang141aacb2017-08-29 13:23:53 -07003571// This test ensures OnRenegotiationNeeded is called when we add track with
3572// MediaStream -> AddTrack in the same way it is called when we add track with
3573// PeerConnection -> AddTrack.
3574// The test can be removed once addStream is rewritten in terms of addTrack
3575// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003576// Don't run under Unified Plan since the stream API is not available.
3577TEST_F(PeerConnectionInterfaceTestPlanB,
3578 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003579 CreatePeerConnectionWithoutDtls();
3580 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003581 pc_factory_->CreateLocalMediaStream(kStreamId1));
Niels Möllerafb246b2022-04-20 14:26:50 +02003582 pc_->AddStream(stream.get());
zhihuang141aacb2017-08-29 13:23:53 -07003583 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003584 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003585 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003586 CreateVideoTrack("video_track"));
Niels Möllerafb246b2022-04-20 14:26:50 +02003587 stream->AddTrack(audio_track.get());
zhihuang141aacb2017-08-29 13:23:53 -07003588 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3589 observer_.renegotiation_needed_ = false;
3590
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003591 CreateOfferReceiveAnswer();
Niels Möllerafb246b2022-04-20 14:26:50 +02003592 stream->AddTrack(video_track.get());
zhihuang141aacb2017-08-29 13:23:53 -07003593 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3594 observer_.renegotiation_needed_ = false;
3595
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003596 CreateOfferReceiveAnswer();
Niels Möllerafb246b2022-04-20 14:26:50 +02003597 stream->RemoveTrack(audio_track.get());
zhihuang141aacb2017-08-29 13:23:53 -07003598 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3599 observer_.renegotiation_needed_ = false;
3600
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003601 CreateOfferReceiveAnswer();
Niels Möllerafb246b2022-04-20 14:26:50 +02003602 stream->RemoveTrack(video_track.get());
zhihuang141aacb2017-08-29 13:23:53 -07003603 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3604 observer_.renegotiation_needed_ = false;
3605}
3606
Zhi Huangb2d355e2017-10-26 17:26:37 -07003607// Tests that an error is returned if a description is applied that has fewer
3608// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003609TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003610 MediaSectionCountEnforcedForSubsequentOffer) {
3611 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003612 AddAudioTrack("audio_label");
3613 AddVideoTrack("video_label");
3614
Zhi Huangb2d355e2017-10-26 17:26:37 -07003615 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003616 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003617 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3618
3619 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003620 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003621 offer->description()->contents().pop_back();
3622 offer->description()->contents().pop_back();
3623 ASSERT_TRUE(offer->description()->contents().empty());
3624 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3625
3626 std::unique_ptr<SessionDescriptionInterface> answer;
3627 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3628 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3629
3630 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003631 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003632 offer->description()->contents().pop_back();
3633 offer->description()->contents().pop_back();
3634 ASSERT_TRUE(offer->description()->contents().empty());
3635 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3636}
3637
Johannes Kron89f874e2018-11-12 10:25:48 +01003638TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3639 RTCConfiguration config;
Emil Lundmark801c9992021-01-19 13:06:32 +01003640 // Default behavior is true.
Johannes Kron89f874e2018-11-12 10:25:48 +01003641 CreatePeerConnection(config);
3642 std::unique_ptr<SessionDescriptionInterface> offer;
3643 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003644 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3645 // Possible to set to false.
3646 config.offer_extmap_allow_mixed = false;
Johannes Kron89f874e2018-11-12 10:25:48 +01003647 CreatePeerConnection(config);
Artem Titov4f3a2eb2021-01-26 09:58:21 +01003648 offer = nullptr;
Johannes Kron89f874e2018-11-12 10:25:48 +01003649 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003650 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
Johannes Kron89f874e2018-11-12 10:25:48 +01003651}
3652
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003653INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3654 PeerConnectionInterfaceTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003655 Values(SdpSemantics::kPlanB_DEPRECATED,
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003656 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003657
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003658class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003659 protected:
3660 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003661 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003662 }
nisseeaabdf62017-05-05 02:23:02 -07003663 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003664 const RTCConfiguration& config) {
Florent Castelli72424402022-04-06 03:45:10 +02003665 PeerConnectionDependencies pc_dependencies(&observer_);
3666 auto result =
3667 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3668 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003669 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003670 return result.value()->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003671 }
3672
zhihuang9763d562016-08-05 11:14:50 -07003673 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003674 MockPeerConnectionObserver observer_;
3675};
3676
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003677// This sanity check validates the test infrastructure itself.
3678TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3679 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003680 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Florent Castelli72424402022-04-06 03:45:10 +02003681 PeerConnectionDependencies pc_dependencies(&observer_);
3682 auto result =
3683 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3684 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003685 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003686 result.value()->Close(); // No abort -> ok.
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003687 SUCCEED();
3688}
3689
nisse51542be2016-02-12 02:27:06 -08003690// This test verifies the default behaviour with no constraints and a
3691// default RTCConfiguration.
3692TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3693 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003694 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003695
Niels Möllerf06f9232018-08-07 12:32:18 +02003696 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003697
Henrik Boström35c5cc82022-04-14 09:23:20 +02003698 EXPECT_TRUE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003699 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3700 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003701 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003702 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003703}
3704
Niels Möller1d7ecd22018-01-18 15:25:12 +01003705// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003706// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003707TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3708 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003709 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003710
Niels Möller71bdda02016-03-31 12:59:59 +02003711 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003712 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003713
Niels Möller1d7ecd22018-01-18 15:25:12 +01003714 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003715}
3716
Niels Möller6539f692018-01-18 08:58:50 +01003717// This test verifies that the experiment_cpu_load_estimator flag is
3718// propagated from RTCConfiguration to the PeerConnection.
3719TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3720 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003721 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Niels Möller6539f692018-01-18 08:58:50 +01003722
3723 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003724 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003725
3726 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3727}
3728
deadbeef293e9262017-01-11 12:28:30 -08003729// Tests a few random fields being different.
3730TEST(RTCConfigurationTest, ComparisonOperators) {
3731 PeerConnectionInterface::RTCConfiguration a;
3732 PeerConnectionInterface::RTCConfiguration b;
3733 EXPECT_EQ(a, b);
3734
3735 PeerConnectionInterface::RTCConfiguration c;
3736 c.servers.push_back(PeerConnectionInterface::IceServer());
3737 EXPECT_NE(a, c);
3738
3739 PeerConnectionInterface::RTCConfiguration d;
3740 d.type = PeerConnectionInterface::kRelay;
3741 EXPECT_NE(a, d);
3742
3743 PeerConnectionInterface::RTCConfiguration e;
3744 e.audio_jitter_buffer_max_packets = 5;
3745 EXPECT_NE(a, e);
3746
3747 PeerConnectionInterface::RTCConfiguration f;
3748 f.ice_connection_receiving_timeout = 1337;
3749 EXPECT_NE(a, f);
3750
3751 PeerConnectionInterface::RTCConfiguration g;
3752 g.disable_ipv6 = true;
3753 EXPECT_NE(a, g);
3754
3755 PeerConnectionInterface::RTCConfiguration h(
3756 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3757 EXPECT_NE(a, h);
3758}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01003759
3760} // namespace
3761} // namespace webrtc