blob: 20badb3d5052a12a445c1da4a627a2558f532423 [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"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000128 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700129 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800130 "a=ice-ufrag:e5785931\r\n"
131 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
132 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
133 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700134 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700135 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800136 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700137 "a=rtpmap:120 VP8/90000\r\n"
138 "a=ssrc:2 cname:stream1\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000139 "a=ssrc:2 msid:stream1 videotrack0\r\n";
140// Same string as above but with the MID changed to the Unified Plan default and
141// a=msid added. This is needed so that this SDP can be used as an answer for a
142// Unified Plan offer.
Steve Anton36da6ff2018-02-16 16:04:20 -0800143static const char kSdpStringWithStream1UnifiedPlan[] =
144 "v=0\r\n"
145 "o=- 0 0 IN IP4 127.0.0.1\r\n"
146 "s=-\r\n"
147 "t=0 0\r\n"
148 "m=audio 1 RTP/AVPF 103\r\n"
149 "a=ice-ufrag:e5785931\r\n"
150 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
151 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
152 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
153 "a=mid:0\r\n"
154 "a=sendrecv\r\n"
155 "a=rtcp-mux\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000157 "a=msid:stream1 audiotrack0\r\n"
Steve Anton36da6ff2018-02-16 16:04:20 -0800158 "a=ssrc:1 cname:stream1\r\n"
Steve Anton36da6ff2018-02-16 16:04:20 -0800159 "m=video 1 RTP/AVPF 120\r\n"
160 "a=ice-ufrag:e5785931\r\n"
161 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
162 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
163 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
164 "a=mid:1\r\n"
165 "a=sendrecv\r\n"
166 "a=rtcp-mux\r\n"
167 "a=rtpmap:120 VP8/90000\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000168 "a=msid:stream1 videotrack0\r\n"
169 "a=ssrc:2 cname:stream1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700170
zhihuang81c3a032016-11-17 12:06:24 -0800171// Reference SDP with a MediaStream with label "stream1" and audio track with
172// id "audio_1";
173static const char kSdpStringWithStream1AudioTrackOnly[] =
174 "v=0\r\n"
175 "o=- 0 0 IN IP4 127.0.0.1\r\n"
176 "s=-\r\n"
177 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800178 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800179 "a=ice-ufrag:e5785931\r\n"
180 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
181 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
182 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800183 "a=mid:audio\r\n"
184 "a=sendrecv\r\n"
185 "a=rtpmap:103 ISAC/16000\r\n"
186 "a=ssrc:1 cname:stream1\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000187 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800188 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800189
deadbeefab9b2d12015-10-14 11:33:11 -0700190// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
191// MediaStreams have one audio track and one video track.
192// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800193static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700194 "v=0\r\n"
195 "o=- 0 0 IN IP4 127.0.0.1\r\n"
196 "s=-\r\n"
197 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800198 "a=msid-semantic: WMS stream1 stream2\r\n"
199 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700200 "a=ice-ufrag:e5785931\r\n"
201 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
202 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
203 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700204 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700205 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800206 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700207 "a=rtpmap:103 ISAC/16000\r\n"
208 "a=ssrc:1 cname:stream1\r\n"
209 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
210 "a=ssrc:3 cname:stream2\r\n"
211 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
212 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800213 "a=ice-ufrag:e5785931\r\n"
214 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
215 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
216 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700217 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700218 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800219 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700220 "a=rtpmap:120 VP8/0\r\n"
221 "a=ssrc:2 cname:stream1\r\n"
222 "a=ssrc:2 msid:stream1 videotrack0\r\n"
223 "a=ssrc:4 cname:stream2\r\n"
224 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800225static const char kSdpStringWithStream1And2UnifiedPlan[] =
226 "v=0\r\n"
227 "o=- 0 0 IN IP4 127.0.0.1\r\n"
228 "s=-\r\n"
229 "t=0 0\r\n"
230 "a=msid-semantic: WMS stream1 stream2\r\n"
231 "m=audio 1 RTP/AVPF 103\r\n"
232 "a=ice-ufrag:e5785931\r\n"
233 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
234 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
235 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
236 "a=mid:0\r\n"
237 "a=sendrecv\r\n"
238 "a=rtcp-mux\r\n"
239 "a=rtpmap:103 ISAC/16000\r\n"
240 "a=ssrc:1 cname:stream1\r\n"
241 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
242 "m=video 1 RTP/AVPF 120\r\n"
243 "a=ice-ufrag:e5785931\r\n"
244 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
245 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
246 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
247 "a=mid:1\r\n"
248 "a=sendrecv\r\n"
249 "a=rtcp-mux\r\n"
250 "a=rtpmap:120 VP8/0\r\n"
251 "a=ssrc:2 cname:stream1\r\n"
252 "a=ssrc:2 msid:stream1 videotrack0\r\n"
253 "m=audio 1 RTP/AVPF 103\r\n"
254 "a=ice-ufrag:e5785931\r\n"
255 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
256 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
257 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
258 "a=mid:2\r\n"
259 "a=sendrecv\r\n"
260 "a=rtcp-mux\r\n"
261 "a=rtpmap:103 ISAC/16000\r\n"
262 "a=ssrc:3 cname:stream2\r\n"
263 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
264 "m=video 1 RTP/AVPF 120\r\n"
265 "a=ice-ufrag:e5785931\r\n"
266 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
267 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
268 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
269 "a=mid:3\r\n"
270 "a=sendrecv\r\n"
271 "a=rtcp-mux\r\n"
272 "a=rtpmap:120 VP8/0\r\n"
273 "a=ssrc:4 cname:stream2\r\n"
274 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700275
276// Reference SDP without MediaStreams. Msid is not supported.
277static const char kSdpStringWithoutStreams[] =
278 "v=0\r\n"
279 "o=- 0 0 IN IP4 127.0.0.1\r\n"
280 "s=-\r\n"
281 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800282 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700283 "a=ice-ufrag:e5785931\r\n"
284 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
285 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
286 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700287 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700288 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800289 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700290 "a=rtpmap:103 ISAC/16000\r\n"
291 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800292 "a=ice-ufrag:e5785931\r\n"
293 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
294 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
295 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700296 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700297 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800298 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700299 "a=rtpmap:120 VP8/90000\r\n";
300
301// Reference SDP without MediaStreams. Msid is supported.
302static const char kSdpStringWithMsidWithoutStreams[] =
303 "v=0\r\n"
304 "o=- 0 0 IN IP4 127.0.0.1\r\n"
305 "s=-\r\n"
306 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800307 "a=msid-semantic: WMS\r\n"
308 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700309 "a=ice-ufrag:e5785931\r\n"
310 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
311 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
312 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700313 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700314 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800315 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700316 "a=rtpmap:103 ISAC/16000\r\n"
317 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800318 "a=ice-ufrag:e5785931\r\n"
319 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
320 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
321 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700322 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700323 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800324 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700325 "a=rtpmap:120 VP8/90000\r\n";
326
327// Reference SDP without MediaStreams and audio only.
328static const char kSdpStringWithoutStreamsAudioOnly[] =
329 "v=0\r\n"
330 "o=- 0 0 IN IP4 127.0.0.1\r\n"
331 "s=-\r\n"
332 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800333 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700334 "a=ice-ufrag:e5785931\r\n"
335 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
336 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
337 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700338 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700339 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800340 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700341 "a=rtpmap:103 ISAC/16000\r\n";
342
343// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
344static const char kSdpStringSendOnlyWithoutStreams[] =
345 "v=0\r\n"
346 "o=- 0 0 IN IP4 127.0.0.1\r\n"
347 "s=-\r\n"
348 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800349 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700350 "a=ice-ufrag:e5785931\r\n"
351 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
352 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
353 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700354 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700355 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700356 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800357 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700358 "a=rtpmap:103 ISAC/16000\r\n"
359 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800360 "a=ice-ufrag:e5785931\r\n"
361 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
362 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
363 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700364 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700365 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700366 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800367 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700368 "a=rtpmap:120 VP8/90000\r\n";
369
370static const char kSdpStringInit[] =
371 "v=0\r\n"
372 "o=- 0 0 IN IP4 127.0.0.1\r\n"
373 "s=-\r\n"
374 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700375 "a=msid-semantic: WMS\r\n";
376
377static const char kSdpStringAudio[] =
378 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800379 "a=ice-ufrag:e5785931\r\n"
380 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
381 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
382 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700383 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700384 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800385 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700386 "a=rtpmap:103 ISAC/16000\r\n";
387
388static const char kSdpStringVideo[] =
389 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800390 "a=ice-ufrag:e5785931\r\n"
391 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
392 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
393 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700394 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700395 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800396 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700397 "a=rtpmap:120 VP8/90000\r\n";
398
399static const char kSdpStringMs1Audio0[] =
400 "a=ssrc:1 cname:stream1\r\n"
401 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
402
403static const char kSdpStringMs1Video0[] =
404 "a=ssrc:2 cname:stream1\r\n"
405 "a=ssrc:2 msid:stream1 videotrack0\r\n";
406
407static const char kSdpStringMs1Audio1[] =
408 "a=ssrc:3 cname:stream1\r\n"
409 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
410
411static const char kSdpStringMs1Video1[] =
412 "a=ssrc:4 cname:stream1\r\n"
413 "a=ssrc:4 msid:stream1 videotrack1\r\n";
414
deadbeef8662f942017-01-20 21:20:51 -0800415static const char kDtlsSdesFallbackSdp[] =
416 "v=0\r\n"
417 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
418 "s=-\r\n"
419 "c=IN IP4 0.0.0.0\r\n"
420 "t=0 0\r\n"
421 "a=group:BUNDLE audio\r\n"
422 "a=msid-semantic: WMS\r\n"
423 "m=audio 1 RTP/SAVPF 0\r\n"
424 "a=sendrecv\r\n"
425 "a=rtcp-mux\r\n"
426 "a=mid:audio\r\n"
427 "a=ssrc:1 cname:stream1\r\n"
deadbeef8662f942017-01-20 21:20:51 -0800428 "a=ice-ufrag:e5785931\r\n"
429 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
430 "a=rtpmap:0 pcmu/8000\r\n"
431 "a=fingerprint:sha-1 "
432 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
433 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700434 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800435 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
436 "dummy_session_params\r\n";
437
Niels Möllerdec9f742019-06-03 15:25:20 +0200438class RtcEventLogOutputNull final : public RtcEventLogOutput {
439 public:
440 bool IsActive() const override { return true; }
441 bool Write(const std::string& output) override { return true; }
442};
443
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100444using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700445using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800446using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447
Steve Anton36da6ff2018-02-16 16:04:20 -0800448using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
449using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700450
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451// Gets the first ssrc of given content type from the ContentInfo.
452bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
453 if (!content_info || !ssrc) {
454 return false;
455 }
456 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800457 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 if (!media_desc || media_desc->streams().empty()) {
459 return false;
460 }
461 *ssrc = media_desc->streams().begin()->first_ssrc();
462 return true;
463}
464
deadbeefd1a38b52016-12-10 13:15:33 -0800465// Get the ufrags out of an SDP blob. Useful for testing ICE restart
466// behavior.
467std::vector<std::string> GetUfrags(
468 const webrtc::SessionDescriptionInterface* desc) {
469 std::vector<std::string> ufrags;
470 for (const cricket::TransportInfo& info :
471 desc->description()->transport_infos()) {
472 ufrags.push_back(info.description.ice_ufrag);
473 }
474 return ufrags;
475}
476
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477void SetSsrcToZero(std::string* sdp) {
478 const char kSdpSsrcAtribute[] = "a=ssrc:";
479 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
480 size_t ssrc_pos = 0;
481 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200482 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 size_t end_ssrc = sdp->find(" ", ssrc_pos);
484 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
485 ssrc_pos = end_ssrc;
486 }
487}
488
Artem Titov880fa812021-07-30 22:30:23 +0200489// Check if `streams` contains the specified track.
deadbeefab9b2d12015-10-14 11:33:11 -0700490bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800491 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700492 const std::string& track_id) {
493 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800494 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700495 return true;
496 }
497 }
498 return false;
499}
500
Artem Titov880fa812021-07-30 22:30:23 +0200501// Check if `senders` contains the specified sender, by id.
deadbeefab9b2d12015-10-14 11:33:11 -0700502bool ContainsSender(
503 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
504 const std::string& id) {
505 for (const auto& sender : senders) {
506 if (sender->id() == id) {
507 return true;
508 }
509 }
510 return false;
511}
512
Artem Titov880fa812021-07-30 22:30:23 +0200513// Check if `senders` contains the specified sender, by id and stream id.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700514bool ContainsSender(
515 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
516 const std::string& id,
517 const std::string& stream_id) {
518 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700519 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700520 return true;
521 }
522 }
523 return false;
524}
525
deadbeefab9b2d12015-10-14 11:33:11 -0700526// Create a collection of streams.
527// CreateStreamCollection(1) creates a collection that
528// correspond to kSdpStringWithStream1.
529// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
530rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700531 int number_of_streams,
532 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700533 rtc::scoped_refptr<StreamCollection> local_collection(
534 StreamCollection::Create());
535
536 for (int i = 0; i < number_of_streams; ++i) {
537 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
538 webrtc::MediaStream::Create(kStreams[i]));
539
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700540 for (int j = 0; j < tracks_per_stream; ++j) {
541 // Add a local audio track.
542 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
543 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
544 nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000545 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700546
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700547 // Add a local video track.
548 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
549 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700550 webrtc::FakeVideoTrackSource::Create(),
551 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000552 stream->AddTrack(video_track);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700553 }
deadbeefab9b2d12015-10-14 11:33:11 -0700554
555 local_collection->AddStream(stream);
556 }
557 return local_collection;
558}
559
560// Check equality of StreamCollections.
561bool CompareStreamCollections(StreamCollectionInterface* s1,
562 StreamCollectionInterface* s2) {
563 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
564 return false;
565 }
566
567 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700568 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700569 return false;
570 }
571 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
572 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
573 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
574 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
575
576 if (audio_tracks1.size() != audio_tracks2.size()) {
577 return false;
578 }
579 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
580 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
581 return false;
582 }
583 }
584 if (video_tracks1.size() != video_tracks2.size()) {
585 return false;
586 }
587 for (size_t j = 0; j != video_tracks1.size(); ++j) {
588 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
589 return false;
590 }
591 }
592 }
593 return true;
594}
595
perkjd61bf802016-03-24 03:16:19 -0700596// Helper class to test Observer.
597class MockTrackObserver : public ObserverInterface {
598 public:
599 explicit MockTrackObserver(NotifierInterface* notifier)
600 : notifier_(notifier) {
601 notifier_->RegisterObserver(this);
602 }
603
604 ~MockTrackObserver() { Unregister(); }
605
606 void Unregister() {
607 if (notifier_) {
608 notifier_->UnregisterObserver(this);
609 notifier_ = nullptr;
610 }
611 }
612
Danil Chapovalov3a353122020-05-15 11:16:53 +0200613 MOCK_METHOD(void, OnChanged, (), (override));
perkjd61bf802016-03-24 03:16:19 -0700614
615 private:
616 NotifierInterface* notifier_;
617};
618
nisse528b7932017-05-08 03:21:43 -0700619// The PeerConnectionMediaConfig tests below verify that configuration and
620// constraints are propagated into the PeerConnection's MediaConfig. These
621// settings are intended for MediaChannel constructors, but that is not
622// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700623class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
624 public:
zhihuang38ede132017-06-15 12:52:32 -0700625 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
626 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100627 PeerConnectionFactoryDependencies dependencies;
628 dependencies.worker_thread = rtc::Thread::Current();
629 dependencies.network_thread = rtc::Thread::Current();
630 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200631 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
Erik Språngceb44952020-09-22 11:36:35 +0200632 dependencies.trials = std::make_unique<FieldTrialBasedConfig>();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200633 cricket::MediaEngineDependencies media_deps;
634 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200635 // Use fake audio device module since we're only testing the interface
636 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200637 media_deps.adm = FakeAudioCaptureModule::Create();
638 SetMediaEngineDefaults(&media_deps);
Erik Språngceb44952020-09-22 11:36:35 +0200639 media_deps.trials = dependencies.trials.get();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200640 dependencies.media_engine =
641 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100642 dependencies.call_factory = webrtc::CreateCallFactory();
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200643 dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>(
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200644 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700645
Tommi87f70902021-04-27 14:43:08 +0200646 return rtc::make_ref_counted<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100647 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700648 }
649
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100650 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800651
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100652 private:
deadbeefd7850b22017-08-23 10:59:19 -0700653 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700654};
655
Steve Anton36da6ff2018-02-16 16:04:20 -0800656// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200657class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800659 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
660 : vss_(new rtc::VirtualSocketServer()),
661 main_(vss_.get()),
662 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800663#ifdef WEBRTC_ANDROID
664 webrtc::InitializeAndroidObjects();
665#endif
666 }
667
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200668 void SetUp() override {
deadbeefd7850b22017-08-23 10:59:19 -0700669 // Use fake audio capture module since we're only testing the interface
670 // level, and using a real one could make tests flaky when run in parallel.
671 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700673 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200674 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
675 fake_audio_capture_module_),
676 webrtc::CreateBuiltinAudioEncoderFactory(),
677 webrtc::CreateBuiltinAudioDecoderFactory(),
678 webrtc::CreateBuiltinVideoEncoderFactory(),
679 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
680 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700681 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700682 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700683 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684 }
685
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200686 void TearDown() override {
687 if (pc_)
688 pc_->Close();
689 }
690
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200692 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 }
694
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000695 // DTLS does not work in a loopback call, so is disabled for many
deadbeef293e9262017-01-11 12:28:30 -0800696 // tests in this file.
697 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200698 RTCConfiguration config;
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000699 PeerConnectionFactoryInterface::Options options;
700 options.disable_encryption = true;
701 pc_factory_->SetOptions(options);
Niels Möllerf06f9232018-08-07 12:32:18 +0200702 CreatePeerConnection(config);
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000703 options.disable_encryption = false;
704 pc_factory_->SetOptions(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 }
706
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700707 void CreatePeerConnectionWithIceTransportsType(
708 PeerConnectionInterface::IceTransportsType type) {
709 PeerConnectionInterface::RTCConfiguration config;
710 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200711 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700712 }
713
714 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100715 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700716 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800717 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100720 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700721 server.password = password;
722 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200723 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700724 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725
Niels Möllerf06f9232018-08-07 12:32:18 +0200726 void CreatePeerConnection(const RTCConfiguration& config) {
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200727 if (pc_) {
728 pc_->Close();
729 pc_ = nullptr;
730 }
kwibergd1fe2812016-04-27 06:47:29 -0700731 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800732 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
733 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000734
deadbeef1dcb1642017-03-29 21:08:16 -0700735 // Create certificate generator unless DTLS constraint is explicitly set to
736 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200737 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200738
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000739 // These won't be used if encryption is turned off, but that's harmless.
740 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
741 cert_generator.reset(fake_certificate_generator_);
742
Steve Anton36da6ff2018-02-16 16:04:20 -0800743 RTCConfiguration modified_config = config;
744 modified_config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200745 PeerConnectionDependencies pc_dependencies(&observer_);
746 pc_dependencies.cert_generator = std::move(cert_generator);
747 pc_dependencies.allocator = std::move(port_allocator);
748 auto result = pc_factory_->CreatePeerConnectionOrError(
749 modified_config, std::move(pc_dependencies));
750 ASSERT_TRUE(result.ok());
751 pc_ = result.MoveValue();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 observer_.SetPeerConnectionInterface(pc_.get());
753 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
754 }
755
deadbeef0a6c4ca2015-10-06 11:38:28 -0700756 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800757 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700758 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700759 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800760 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800761 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200762 PeerConnectionDependencies pc_dependencies(&observer_);
763 auto result = pc_factory_->CreatePeerConnectionOrError(
764 config, std::move(pc_dependencies));
765 EXPECT_FALSE(result.ok());
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 }
767
Steve Anton038834f2017-07-14 15:59:59 -0700768 void CreatePeerConnectionExpectFail(
769 PeerConnectionInterface::RTCConfiguration config) {
770 PeerConnectionInterface::IceServer server;
771 server.uri = kTurnIceServerUri;
772 server.password = kTurnPassword;
773 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800774 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200775 PeerConnectionDependencies pc_dependencies(&observer_);
776 auto result = pc_factory_->CreatePeerConnectionOrError(
777 config, std::move(pc_dependencies));
778 EXPECT_FALSE(result.ok());
Steve Anton038834f2017-07-14 15:59:59 -0700779 }
780
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100782 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800783 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
784 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
785 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800787 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788
deadbeef0a6c4ca2015-10-06 11:38:28 -0700789 CreatePeerConnectionExpectFail(kStunInvalidPort);
790 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
791 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792
Niels Möllerdb4def92019-03-18 16:53:59 +0100793 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
794 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800795 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
796 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 }
804
805 void ReleasePeerConnection() {
Niels Möllerafb246b2022-04-20 14:26:50 +0200806 pc_ = nullptr;
807 observer_.SetPeerConnectionInterface(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 }
809
Steve Anton36da6ff2018-02-16 16:04:20 -0800810 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
811 const std::string& label) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200812 return pc_factory_->CreateVideoTrack(label,
813 FakeVideoTrackSource::Create().get());
Steve Anton36da6ff2018-02-16 16:04:20 -0800814 }
815
816 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800817 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800818 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800819 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800820 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 }
822
Steve Anton36da6ff2018-02-16 16:04:20 -0800823 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700824 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000826 stream->AddTrack(CreateVideoTrack(label + "v0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200827 ASSERT_TRUE(pc_->AddStream(stream.get()));
Steve Anton36da6ff2018-02-16 16:04:20 -0800828 }
829
830 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
831 const std::string& label) {
832 return pc_factory_->CreateAudioTrack(label, nullptr);
833 }
834
835 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800836 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800837 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800838 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800839 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800840 }
841
842 void AddAudioStream(const std::string& label) {
843 rtc::scoped_refptr<MediaStreamInterface> stream(
844 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000845 stream->AddTrack(CreateAudioTrack(label + "a0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200846 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 }
848
Seth Hampson845e8782018-03-02 11:34:10 -0800849 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 const std::string& audio_track_label,
851 const std::string& video_track_label) {
852 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700853 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800854 pc_factory_->CreateLocalMediaStream(stream_id));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000855 stream->AddTrack(CreateAudioTrack(audio_track_label));
856 stream->AddTrack(CreateVideoTrack(video_track_label));
Niels Möllerafb246b2022-04-20 14:26:50 +0200857 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 }
859
Steve Anton36da6ff2018-02-16 16:04:20 -0800860 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
861 cricket::MediaType media_type) {
862 for (auto receiver : pc_->GetReceivers()) {
863 if (receiver->media_type() == media_type) {
864 return receiver;
865 }
866 }
867 return nullptr;
868 }
869
kwibergd1fe2812016-04-27 06:47:29 -0700870 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200871 const RTCOfferAnswerOptions* options,
872 bool offer) {
Tommi87f70902021-04-27 14:43:08 +0200873 auto observer =
874 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 if (offer) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200876 pc_->CreateOffer(observer.get(),
877 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200879 pc_->CreateAnswer(observer.get(),
880 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 }
882 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700883 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 return observer->result();
885 }
886
kwibergd1fe2812016-04-27 06:47:29 -0700887 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200888 const RTCOfferAnswerOptions* options) {
889 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891
kwibergd1fe2812016-04-27 06:47:29 -0700892 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200893 const RTCOfferAnswerOptions* options) {
894 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 }
896
Steve Antondb45ca82017-09-11 18:27:34 -0700897 bool DoSetSessionDescription(
898 std::unique_ptr<SessionDescriptionInterface> desc,
899 bool local) {
Tommi87f70902021-04-27 14:43:08 +0200900 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 if (local) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200902 pc_->SetLocalDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200904 pc_->SetRemoteDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 }
zhihuang29ff8442016-07-27 11:07:25 -0700906 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
907 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
908 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 return observer->result();
910 }
911
Steve Antondb45ca82017-09-11 18:27:34 -0700912 bool DoSetLocalDescription(
913 std::unique_ptr<SessionDescriptionInterface> desc) {
914 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 }
916
Steve Antondb45ca82017-09-11 18:27:34 -0700917 bool DoSetRemoteDescription(
918 std::unique_ptr<SessionDescriptionInterface> desc) {
919 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 }
921
922 // Calls PeerConnection::GetStats and check the return value.
923 // It does not verify the values in the StatReports since a RTCP packet might
924 // be required.
925 bool DoGetStats(MediaStreamTrackInterface* track) {
Tommi87f70902021-04-27 14:43:08 +0200926 auto observer = rtc::make_ref_counted<MockStatsObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200927 if (!pc_->GetStats(observer.get(), track,
Yves Gerey665174f2018-06-19 15:03:05 +0200928 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 return false;
930 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
931 return observer->called();
932 }
933
Harald Alvestrand89061872018-01-02 14:08:34 +0100934 // Call the standards-compliant GetStats function.
935 bool DoGetRTCStats() {
Tommi87f70902021-04-27 14:43:08 +0200936 auto callback =
937 rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200938 pc_->GetStats(callback.get());
Harald Alvestrand89061872018-01-02 14:08:34 +0100939 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
940 return callback->called();
941 }
942
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800944 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 // Create a local stream with audio&video tracks.
Florent Castelli15a38de2022-04-06 00:38:21 +0200946 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson845e8782018-03-02 11:34:10 -0800947 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800948 } else {
949 // Unified Plan does not support AddStream, so just add an audio and video
950 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800951 AddAudioTrack(kAudioTracks[0], {kStreamId1});
952 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800953 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 CreateOfferReceiveAnswer();
955 }
956
957 // Verify that RTP Header extensions has been negotiated for audio and video.
958 void VerifyRemoteRtpHeaderExtensions() {
959 const cricket::MediaContentDescription* desc =
960 cricket::GetFirstAudioContentDescription(
961 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200962 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
964
965 desc = cricket::GetFirstVideoContentDescription(
966 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200967 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
969 }
970
971 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700972 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700973 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 std::string sdp;
975 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700976 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800977 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700978 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
980 }
981
deadbeefab9b2d12015-10-14 11:33:11 -0700982 void CreateAndSetRemoteOffer(const std::string& 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)));
deadbeefab9b2d12015-10-14 11:33:11 -0700986 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
987 }
988
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700990 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700991 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
993 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
994 // audio codec change, even if the parameter has nothing to do with
995 // receiving. Not all parameters are serialized to SDP.
996 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
997 // the SessionDescription, it is necessary to do that here to in order to
998 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
999 // https://code.google.com/p/webrtc/issues/detail?id=1356
1000 std::string sdp;
1001 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001002 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001003 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001004 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1006 }
1007
1008 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001009 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001010 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011
1012 std::string sdp;
1013 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001014 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001015 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001016 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1018 }
1019
1020 void CreateOfferReceiveAnswer() {
1021 CreateOfferAsLocalDescription();
1022 std::string sdp;
1023 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1024 CreateAnswerAsRemoteDescription(sdp);
1025 }
1026
1027 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001028 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001029 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1031 // audio codec change, even if the parameter has nothing to do with
1032 // receiving. Not all parameters are serialized to SDP.
1033 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1034 // the SessionDescription, it is necessary to do that here to in order to
1035 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1036 // https://code.google.com/p/webrtc/issues/detail?id=1356
1037 std::string sdp;
1038 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001039 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001040 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041
Steve Antondb45ca82017-09-11 18:27:34 -07001042 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001044 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001045 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 }
1047
deadbeefab9b2d12015-10-14 11:33:11 -07001048 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001049 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001050 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001051 ASSERT_TRUE(answer);
1052 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1054 }
1055
deadbeefab9b2d12015-10-14 11:33:11 -07001056 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001057 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001058 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001059 ASSERT_TRUE(pr_answer);
1060 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001062 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001063 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001064 ASSERT_TRUE(answer);
1065 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1067 }
1068
Seth Hampson845e8782018-03-02 11:34:10 -08001069 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001070 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001071 // called with the given stream id and expected number of tracks.
1072 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001073 int expected_num_tracks) {
1074 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001075 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001076 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001077 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 }
1079
1080 // Creates an offer and applies it as a local session description.
1081 // Creates an answer with the same SDP an the offer but removes all lines
1082 // that start with a:ssrc"
1083 void CreateOfferReceiveAnswerWithoutSsrc() {
1084 CreateOfferAsLocalDescription();
1085 std::string sdp;
1086 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1087 SetSsrcToZero(&sdp);
1088 CreateAnswerAsRemoteDescription(sdp);
1089 }
1090
deadbeefab9b2d12015-10-14 11:33:11 -07001091 // This function creates a MediaStream with label kStreams[0] and
Artem Titov880fa812021-07-30 22:30:23 +02001092 // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the
deadbeefab9b2d12015-10-14 11:33:11 -07001093 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001094 // is returned and the MediaStream is stored in
Artem Titov880fa812021-07-30 22:30:23 +02001095 // `reference_collection_`
kwibergd1fe2812016-04-27 06:47:29 -07001096 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001097 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1098 size_t number_of_video_tracks) {
1099 EXPECT_LE(number_of_audio_tracks, 2u);
1100 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001101
1102 reference_collection_ = StreamCollection::Create();
1103 std::string sdp_ms1 = std::string(kSdpStringInit);
1104
Seth Hampson845e8782018-03-02 11:34:10 -08001105 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001106
1107 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001108 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001109 reference_collection_->AddStream(stream);
1110
1111 if (number_of_audio_tracks > 0) {
1112 sdp_ms1 += std::string(kSdpStringAudio);
1113 sdp_ms1 += std::string(kSdpStringMs1Audio0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001114 AddAudioTrack(kAudioTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001115 }
1116 if (number_of_audio_tracks > 1) {
1117 sdp_ms1 += kSdpStringMs1Audio1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001118 AddAudioTrack(kAudioTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001119 }
1120
1121 if (number_of_video_tracks > 0) {
1122 sdp_ms1 += std::string(kSdpStringVideo);
1123 sdp_ms1 += std::string(kSdpStringMs1Video0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001124 AddVideoTrack(kVideoTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001125 }
1126 if (number_of_video_tracks > 1) {
1127 sdp_ms1 += kSdpStringMs1Video1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001128 AddVideoTrack(kVideoTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001129 }
1130
kwibergd1fe2812016-04-27 06:47:29 -07001131 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001132 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001133 }
1134
1135 void AddAudioTrack(const std::string& track_id,
1136 MediaStreamInterface* stream) {
1137 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1138 webrtc::AudioTrack::Create(track_id, nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001139 ASSERT_TRUE(stream->AddTrack(audio_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001140 }
1141
1142 void AddVideoTrack(const std::string& track_id,
1143 MediaStreamInterface* stream) {
1144 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001145 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001146 webrtc::FakeVideoTrackSource::Create(),
1147 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001148 ASSERT_TRUE(stream->AddTrack(video_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001149 }
1150
Steve Anton36da6ff2018-02-16 16:04:20 -08001151 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001152 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001153 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001154 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001155 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1156 return offer;
1157 }
1158
Steve Anton36da6ff2018-02-16 16:04:20 -08001159 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1160 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001161 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001162 std::unique_ptr<SessionDescriptionInterface> offer;
1163 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1164 return offer;
1165 }
1166
1167 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1168 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1169 std::unique_ptr<SessionDescriptionInterface> answer;
1170 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1171 return answer;
1172 }
1173
kwibergfd8be342016-05-14 19:44:11 -07001174 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001175 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001176 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001177 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001178 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1179 return answer;
1180 }
1181
1182 const std::string& GetFirstAudioStreamCname(
1183 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001184 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001185 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001186 return audio_desc->streams()[0].cname;
1187 }
1188
zhihuang1c378ed2017-08-17 14:10:50 -07001189 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1190 const RTCOfferAnswerOptions& offer_answer_options) {
1191 RTC_DCHECK(pc_);
Tommi87f70902021-04-27 14:43:08 +02001192 auto observer =
1193 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02001194 pc_->CreateOffer(observer.get(), offer_answer_options);
zhihuang1c378ed2017-08-17 14:10:50 -07001195 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1196 return observer->MoveDescription();
1197 }
1198
1199 void CreateOfferWithOptionsAsRemoteDescription(
1200 std::unique_ptr<SessionDescriptionInterface>* desc,
1201 const RTCOfferAnswerOptions& offer_answer_options) {
1202 *desc = CreateOfferWithOptions(offer_answer_options);
1203 ASSERT_TRUE(desc != nullptr);
1204 std::string sdp;
1205 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001206 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001207 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001208 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001209 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1210 }
1211
1212 void CreateOfferWithOptionsAsLocalDescription(
1213 std::unique_ptr<SessionDescriptionInterface>* desc,
1214 const RTCOfferAnswerOptions& offer_answer_options) {
1215 *desc = CreateOfferWithOptions(offer_answer_options);
1216 ASSERT_TRUE(desc != nullptr);
1217 std::string sdp;
1218 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001219 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001220 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001221
Steve Antondb45ca82017-09-11 18:27:34 -07001222 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001223 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1224 }
1225
1226 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001227 RTC_DCHECK(content);
1228 RTC_DCHECK(content->media_description());
1229 for (const cricket::AudioCodec& codec :
1230 content->media_description()->as_audio()->codecs()) {
1231 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001232 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001233 }
zhihuang1c378ed2017-08-17 14:10:50 -07001234 }
1235 return false;
1236 }
1237
Steve Anton36da6ff2018-02-16 16:04:20 -08001238 const char* GetSdpStringWithStream1() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001239 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001240 return kSdpStringWithStream1PlanB;
1241 } else {
1242 return kSdpStringWithStream1UnifiedPlan;
1243 }
1244 }
1245
1246 const char* GetSdpStringWithStream1And2() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001247 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001248 return kSdpStringWithStream1And2PlanB;
1249 } else {
1250 return kSdpStringWithStream1And2UnifiedPlan;
1251 }
1252 }
1253
deadbeef9a6f4d42017-05-15 19:43:33 -07001254 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1255 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001256 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001257 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001258 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001259 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1260 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1261 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001263 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001264 const SdpSemantics sdp_semantics_;
1265};
1266
1267class PeerConnectionInterfaceTest
1268 : public PeerConnectionInterfaceBaseTest,
1269 public ::testing::WithParamInterface<SdpSemantics> {
1270 protected:
1271 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1272};
1273
1274class PeerConnectionInterfaceTestPlanB
1275 : public PeerConnectionInterfaceBaseTest {
1276 protected:
1277 PeerConnectionInterfaceTestPlanB()
Florent Castelli15a38de2022-04-06 00:38:21 +02001278 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279};
1280
zhihuang8f65cdf2016-05-06 18:40:30 -07001281// Generate different CNAMEs when PeerConnections are created.
1282// The CNAMEs are expected to be generated randomly. It is possible
1283// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001284TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001285 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001286 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001287 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001288 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001289 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1290 GetFirstAudioStreamCname(offer2.get()));
1291}
1292
Steve Anton36da6ff2018-02-16 16:04:20 -08001293TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001294 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001295 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001296 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001297 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001298 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1299 GetFirstAudioStreamCname(answer2.get()));
1300}
1301
Steve Anton36da6ff2018-02-16 16:04:20 -08001302TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 CreatePeerConnectionWithDifferentConfigurations) {
1304 CreatePeerConnectionWithDifferentConfigurations();
1305}
1306
Steve Anton36da6ff2018-02-16 16:04:20 -08001307TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001308 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1309 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1310 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1311 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1312 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1313 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1314 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1315 port_allocator_->candidate_filter());
1316 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1317 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1318}
1319
1320// Test that when a PeerConnection is created with a nonzero candidate pool
1321// size, the pooled PortAllocatorSession is created with all the attributes
1322// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001323TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001324 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001325 config.sdp_semantics = sdp_semantics_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001326 PeerConnectionInterface::IceServer server;
1327 server.uri = kStunAddressOnly;
1328 config.servers.push_back(server);
1329 config.type = PeerConnectionInterface::kRelay;
1330 config.disable_ipv6 = true;
1331 config.tcp_candidate_policy =
1332 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001333 config.candidate_network_policy =
1334 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001335 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001336 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001337
1338 const cricket::FakePortAllocatorSession* session =
1339 static_cast<const cricket::FakePortAllocatorSession*>(
1340 port_allocator_->GetPooledSession());
1341 ASSERT_NE(nullptr, session);
1342 EXPECT_EQ(1UL, session->stun_servers().size());
1343 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1344 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001345 EXPECT_LT(0U,
1346 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001347}
1348
deadbeefd21eab32017-07-26 16:50:11 -07001349// Test that network-related RTCConfiguration members are applied to the
1350// PortAllocator when CreatePeerConnection is called. Specifically:
1351// - disable_ipv6_on_wifi
1352// - max_ipv6_networks
1353// - tcp_candidate_policy
1354// - candidate_network_policy
1355// - prune_turn_ports
1356//
1357// Note that the candidate filter (RTCConfiguration::type) is already tested
1358// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001359TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001360 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1361 // Create fake port allocator.
1362 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1363 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1364 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1365
1366 // Create RTCConfiguration with some network-related fields relevant to
1367 // PortAllocator populated.
1368 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001369 config.sdp_semantics = sdp_semantics_;
deadbeefd21eab32017-07-26 16:50:11 -07001370 config.disable_ipv6_on_wifi = true;
1371 config.max_ipv6_networks = 10;
1372 config.tcp_candidate_policy =
1373 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1374 config.candidate_network_policy =
1375 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1376 config.prune_turn_ports = true;
1377
1378 // Create the PC factory and PC with the above config.
1379 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1380 webrtc::CreatePeerConnectionFactory(
1381 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001382 rtc::Thread::Current(), fake_audio_capture_module_,
1383 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001384 webrtc::CreateBuiltinAudioDecoderFactory(),
1385 webrtc::CreateBuiltinVideoEncoderFactory(),
1386 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1387 nullptr /* audio_processing */));
Florent Castelli72424402022-04-06 03:45:10 +02001388 PeerConnectionDependencies pc_dependencies(&observer_);
1389 pc_dependencies.allocator = std::move(port_allocator);
1390 auto result = pc_factory_->CreatePeerConnectionOrError(
1391 config, std::move(pc_dependencies));
1392 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02001393 observer_.SetPeerConnectionInterface(result.value().get());
deadbeefd21eab32017-07-26 16:50:11 -07001394
1395 // Now validate that the config fields set above were applied to the
1396 // PortAllocator, as flags or otherwise.
1397 EXPECT_FALSE(raw_port_allocator->flags() &
1398 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1399 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1400 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1401 EXPECT_TRUE(raw_port_allocator->flags() &
1402 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Honghai Zhangf8998cf2019-10-14 11:27:50 -07001403 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
1404 raw_port_allocator->turn_port_prune_policy());
deadbeefd21eab32017-07-26 16:50:11 -07001405}
1406
deadbeef46c73892016-11-16 19:42:04 -08001407// Check that GetConfiguration returns the configuration the PeerConnection was
1408// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001409TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001410 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001411 config.sdp_semantics = sdp_semantics_;
deadbeef46c73892016-11-16 19:42:04 -08001412 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001413 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001414
1415 PeerConnectionInterface::RTCConfiguration returned_config =
1416 pc_->GetConfiguration();
1417 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1418}
1419
1420// Check that GetConfiguration returns the last configuration passed into
1421// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001422TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001423 PeerConnectionInterface::RTCConfiguration starting_config;
Henrik Boström62995db2022-01-03 09:58:10 +01001424 starting_config.sdp_semantics = sdp_semantics_;
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001425 starting_config.bundle_policy =
1426 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1427 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001428
Steve Anton36da6ff2018-02-16 16:04:20 -08001429 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001430 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02001431 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef46c73892016-11-16 19:42:04 -08001432
1433 PeerConnectionInterface::RTCConfiguration returned_config =
1434 pc_->GetConfiguration();
1435 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1436}
1437
Steve Antonc79268f2018-04-24 09:54:10 -07001438TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1439 CreatePeerConnection();
1440
1441 pc_->Close();
1442
1443 EXPECT_FALSE(
Niels Möller2579f0c2019-08-19 09:58:17 +02001444 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok());
Steve Antonc79268f2018-04-24 09:54:10 -07001445}
1446
Steve Anton36da6ff2018-02-16 16:04:20 -08001447TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001448 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001449 AddVideoStream(kStreamId1);
1450 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 ASSERT_EQ(2u, pc_->local_streams()->count());
1452
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001453 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001454 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001455 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001456 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001457 pc_factory_->CreateAudioTrack(
1458 kStreamId3, static_cast<AudioSourceInterface*>(nullptr)));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001459 stream->AddTrack(audio_track);
Niels Möllerafb246b2022-04-20 14:26:50 +02001460 EXPECT_TRUE(pc_->AddStream(stream.get()));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001461 EXPECT_EQ(3u, pc_->local_streams()->count());
1462
1463 // Remove the third stream.
1464 pc_->RemoveStream(pc_->local_streams()->at(2));
1465 EXPECT_EQ(2u, pc_->local_streams()->count());
1466
1467 // Remove the second stream.
1468 pc_->RemoveStream(pc_->local_streams()->at(1));
1469 EXPECT_EQ(1u, pc_->local_streams()->count());
1470
1471 // Remove the first stream.
1472 pc_->RemoveStream(pc_->local_streams()->at(0));
1473 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474}
1475
deadbeefab9b2d12015-10-14 11:33:11 -07001476// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001477// Don't run under Unified Plan since the stream API is not available.
1478TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001479 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001480 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001481 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001482 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001483
deadbeefab9b2d12015-10-14 11:33:11 -07001484 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001485 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001486 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001487
deadbeefab9b2d12015-10-14 11:33:11 -07001488 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001489 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001490 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001491
1492 // Add another stream and ensure the offer includes both the old and new
1493 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001494 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001495 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001496
Steve Antonb1c1de12017-12-21 15:14:30 -08001497 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001498 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1499 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001500
Steve Antonb1c1de12017-12-21 15:14:30 -08001501 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001502 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1503 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001504}
1505
Steve Anton36da6ff2018-02-16 16:04:20 -08001506// Don't run under Unified Plan since the stream API is not available.
1507TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001508 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001509 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 ASSERT_EQ(1u, pc_->local_streams()->count());
1511 pc_->RemoveStream(pc_->local_streams()->at(0));
1512 EXPECT_EQ(0u, pc_->local_streams()->count());
1513}
1514
deadbeefe1f9d832016-01-14 15:35:42 -08001515// Test for AddTrack and RemoveTrack methods.
1516// Tests that the created offer includes tracks we added,
1517// and that the RtpSenders are created correctly.
1518// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001519// Only tested with Plan B since Unified Plan is covered in more detail by tests
1520// in peerconnection_jsep_unittests.cc
1521TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001522 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001523 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001524 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001525 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001526 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001527 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1528 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001529 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001530 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001531 EXPECT_EQ("audio_track", audio_sender->id());
1532 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001533 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001534 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001535 EXPECT_EQ("video_track", video_sender->id());
1536 EXPECT_EQ(video_track, video_sender->track());
1537
1538 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001539 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001540 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001541
1542 const cricket::ContentInfo* audio_content =
1543 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001544 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001545 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001546
1547 const cricket::ContentInfo* video_content =
1548 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001549 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001550 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001551
Steve Antondb45ca82017-09-11 18:27:34 -07001552 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001553
1554 // Now try removing the tracks.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001555 EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1556 EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001557
1558 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001559 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
1565 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001566 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001567 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001568
Steve Antondb45ca82017-09-11 18:27:34 -07001569 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001570
1571 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1572 // should return false.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001573 EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok());
1574 EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001575}
1576
1577// Test creating senders without a stream specified,
1578// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001579TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001580 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001581 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001582 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001583 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001584 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001585 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001586 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001587 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001588 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001589 EXPECT_EQ("audio_track", audio_sender->id());
1590 EXPECT_EQ(audio_track, audio_sender->track());
1591 EXPECT_EQ("video_track", video_sender->id());
1592 EXPECT_EQ(video_track, video_sender->track());
Florent Castelli15a38de2022-04-06 00:38:21 +02001593 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001594 // If the ID is truly a random GUID, it should be infinitely unlikely they
1595 // will be the same.
1596 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1597 } else {
1598 // We allows creating tracks without stream ids under Unified Plan
1599 // semantics.
1600 EXPECT_EQ(0u, video_sender->stream_ids().size());
1601 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1602 }
deadbeefe1f9d832016-01-14 15:35:42 -08001603}
1604
Harald Alvestrand89061872018-01-02 14:08:34 +01001605// Test that we can call GetStats() after AddTrack but before connecting
1606// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001607TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001608 CreatePeerConnectionWithoutDtls();
1609 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001610 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001611 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001612 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001613 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1614 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001615 EXPECT_TRUE(DoGetStats(nullptr));
1616}
1617
Steve Anton36da6ff2018-02-16 16:04:20 -08001618TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001619 CreatePeerConnectionWithoutDtls();
1620 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001621 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001622 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001623 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001624 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001625 ASSERT_TRUE(audio_sender.ok());
1626 auto* audio_sender_proxy =
1627 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1628 audio_sender.value().get());
1629 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1630
Harald Alvestrandc72af932018-01-11 17:18:19 +01001631 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001632 ASSERT_TRUE(video_sender.ok());
1633 auto* video_sender_proxy =
1634 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1635 video_sender.value().get());
1636 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001637}
1638
Steve Anton36da6ff2018-02-16 16:04:20 -08001639// Don't run under Unified Plan since the stream API is not available.
1640TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001641 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001642 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001643 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001644 ASSERT_EQ(1u, senders.size());
1645 auto* sender_proxy =
1646 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1647 senders[0].get());
1648 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001649}
1650
Steve Anton36da6ff2018-02-16 16:04:20 -08001651TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001653 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 VerifyRemoteRtpHeaderExtensions();
1655}
1656
Steve Anton36da6ff2018-02-16 16:04:20 -08001657TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001658 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001659 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 CreateOfferAsLocalDescription();
1661 std::string offer;
1662 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1663 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001664 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665}
1666
Steve Anton36da6ff2018-02-16 16:04:20 -08001667TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001668 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001669 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670
1671 CreateOfferAsRemoteDescription();
1672 CreateAnswerAsLocalDescription();
1673
Seth Hampson845e8782018-03-02 11:34:10 -08001674 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675}
1676
Steve Anton36da6ff2018-02-16 16:04:20 -08001677TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001678 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001679 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680
1681 CreateOfferAsRemoteDescription();
1682 CreatePrAnswerAsLocalDescription();
1683 CreateAnswerAsLocalDescription();
1684
Seth Hampson845e8782018-03-02 11:34:10 -08001685 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686}
1687
Steve Anton36da6ff2018-02-16 16:04:20 -08001688// Don't run under Unified Plan since the stream API is not available.
1689TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 InitiateCall();
1691 ASSERT_EQ(1u, pc_->remote_streams()->count());
1692 pc_->RemoveStream(pc_->local_streams()->at(0));
1693 CreateOfferReceiveAnswer();
1694 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001695 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 CreateOfferReceiveAnswer();
1697}
1698
1699// Tests that after negotiating an audio only call, the respondent can perform a
1700// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001701TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001702 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001703 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 CreateOfferAsRemoteDescription();
1705 CreateAnswerAsLocalDescription();
1706
1707 ASSERT_EQ(1u, pc_->remote_streams()->count());
1708 pc_->RemoveStream(pc_->local_streams()->at(0));
1709 CreateOfferReceiveAnswer();
1710 EXPECT_EQ(0u, pc_->remote_streams()->count());
1711}
1712
1713// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001714TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001715 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716
Steve Antonf1c6db12017-10-13 11:13:35 -07001717 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001719 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001720 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001721 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001722 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723
1724 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001725 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001726 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001727 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728
Steve Antonf1c6db12017-10-13 11:13:35 -07001729 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001730 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731
Steve Antonf1c6db12017-10-13 11:13:35 -07001732 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733}
1734
deadbeefab9b2d12015-10-14 11:33:11 -07001735// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001737TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001738 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001740 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001741 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001742 EXPECT_TRUE(offer);
1743 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
1745 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001746 AddAudioTrack("track_label", {kStreamId1});
1747 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748
1749 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001750 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001753 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001754 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755}
1756
1757// Test that we will get different SSRCs for each tracks in the offer and answer
1758// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001759TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001760 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001762 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1763 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764
1765 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001766 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001767 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 int audio_ssrc = 0;
1769 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001770 EXPECT_TRUE(
1771 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1772 EXPECT_TRUE(
1773 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 EXPECT_NE(audio_ssrc, video_ssrc);
1775
1776 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001777 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001778 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001779 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 audio_ssrc = 0;
1781 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001782 EXPECT_TRUE(
1783 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1784 EXPECT_TRUE(
1785 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 EXPECT_NE(audio_ssrc, video_ssrc);
1787}
1788
deadbeefeb459812015-12-15 19:24:43 -08001789// Test that it's possible to call AddTrack on a MediaStream after adding
1790// the stream to a PeerConnection.
1791// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001792// Don't run under Unified Plan since the stream API is not available.
1793TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001794 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001795 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001796 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001797 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1798
1799 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001800 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001801 CreateVideoTrack("video_label"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001802 stream->AddTrack(video_track);
deadbeefeb459812015-12-15 19:24:43 -08001803
kwibergd1fe2812016-04-27 06:47:29 -07001804 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001805 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001806
1807 const cricket::MediaContentDescription* video_desc =
1808 cricket::GetFirstVideoContentDescription(offer->description());
1809 EXPECT_TRUE(video_desc != nullptr);
1810}
1811
1812// Test that it's possible to call RemoveTrack on a MediaStream after adding
1813// the stream to a PeerConnection.
1814// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001815// Don't run under Unified Plan since the stream API is not available.
1816TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001817 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001818 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001819 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001820 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1821
1822 // Remove the video track.
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001823 stream->RemoveTrack(stream->GetVideoTracks()[0]);
deadbeefeb459812015-12-15 19:24:43 -08001824
kwibergd1fe2812016-04-27 06:47:29 -07001825 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001826 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001827
1828 const cricket::MediaContentDescription* video_desc =
1829 cricket::GetFirstVideoContentDescription(offer->description());
1830 EXPECT_TRUE(video_desc == nullptr);
1831}
1832
deadbeefbd7d8f72015-12-18 16:58:44 -08001833// Test creating a sender with a stream ID, and ensure the ID is populated
1834// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001835// Don't run under Unified Plan since the stream API is not available.
1836TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001837 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001838 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001839
kwibergd1fe2812016-04-27 06:47:29 -07001840 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001841 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001842
1843 const cricket::MediaContentDescription* video_desc =
1844 cricket::GetFirstVideoContentDescription(offer->description());
1845 ASSERT_TRUE(video_desc != nullptr);
1846 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001847 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001848}
1849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001851TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001853 ASSERT_LT(0u, pc_->GetSenders().size());
1854 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001855 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001856 pc_->GetReceivers()[0]->track();
Niels Möllerafb246b2022-04-20 14:26:50 +02001857 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858
1859 // Remove the stream. Since we are sending to our selves the local
1860 // and the remote stream is the same.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001861 pc_->RemoveTrackOrError(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 // Do a re-negotiation.
1863 CreateOfferReceiveAnswer();
1864
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 // Test that we still can get statistics for the old track. Even if it is not
1866 // sent any longer.
Niels Möllerafb246b2022-04-20 14:26:50 +02001867 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868}
1869
1870// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001871TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001873 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1874 ASSERT_TRUE(video_receiver);
Niels Möllerafb246b2022-04-20 14:26:50 +02001875 EXPECT_TRUE(DoGetStats(video_receiver->track().get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876}
1877
1878// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001879TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001881 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001882 pc_factory_->CreateAudioTrack("unknown track", nullptr));
1883 EXPECT_FALSE(DoGetStats(unknown_audio_track.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884}
1885
Steve Anton36da6ff2018-02-16 16:04:20 -08001886TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001887 CreatePeerConnectionWithoutDtls();
1888 EXPECT_TRUE(DoGetRTCStats());
1889 // Clearing stats cache is needed now, but should be temporary.
1890 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1891 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001892 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1893 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001894 EXPECT_TRUE(DoGetRTCStats());
1895 pc_->ClearStatsCache();
1896 CreateOfferReceiveAnswer();
1897 EXPECT_TRUE(DoGetRTCStats());
1898}
1899
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900// This tests that a SCTP data channel is returned using different
1901// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08001902TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001903 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001904 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905
1906 webrtc::DataChannelInit config;
Florent Castelli72424402022-04-06 03:45:10 +02001907 auto channel = pc_->CreateDataChannelOrError("1", &config);
1908 EXPECT_TRUE(channel.ok());
1909 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001910 EXPECT_TRUE(observer_.renegotiation_needed_);
1911 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912
1913 config.ordered = false;
Florent Castelli72424402022-04-06 03:45:10 +02001914 channel = pc_->CreateDataChannelOrError("2", &config);
1915 EXPECT_TRUE(channel.ok());
1916 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001917 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918
1919 config.ordered = true;
1920 config.maxRetransmits = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001921 channel = pc_->CreateDataChannelOrError("3", &config);
1922 EXPECT_TRUE(channel.ok());
1923 EXPECT_FALSE(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
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001926 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 config.maxRetransmitTime = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001928 channel = pc_->CreateDataChannelOrError("4", &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}
1933
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001934// For backwards compatibility, we want people who "unset" maxRetransmits
1935// and maxRetransmitTime by setting them to -1 to get what they want.
1936TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
1937 RTCConfiguration rtc_config;
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001938 CreatePeerConnection(rtc_config);
1939
1940 webrtc::DataChannelInit config;
1941 config.maxRetransmitTime = -1;
1942 config.maxRetransmits = -1;
Florent Castelli72424402022-04-06 03:45:10 +02001943 auto channel = pc_->CreateDataChannelOrError("1", &config);
1944 EXPECT_TRUE(channel.ok());
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001945}
1946
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947// This tests that no data channel is returned if both maxRetransmits and
1948// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08001949TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001951 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001952 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953
1954 std::string label = "test";
1955 webrtc::DataChannelInit config;
1956 config.maxRetransmits = 0;
1957 config.maxRetransmitTime = 0;
1958
Florent Castelli72424402022-04-06 03:45:10 +02001959 auto channel = pc_->CreateDataChannelOrError(label, &config);
1960 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961}
1962
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963// The test verifies that creating a SCTP data channel with an id already in use
1964// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001965TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001967 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001968 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969
1970 webrtc::DataChannelInit config;
1971
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001972 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001973 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001974 auto channel = pc_->CreateDataChannelOrError("1", &config);
1975 EXPECT_TRUE(channel.ok());
1976 EXPECT_EQ(1, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977
Florent Castelli72424402022-04-06 03:45:10 +02001978 channel = pc_->CreateDataChannelOrError("x", &config);
1979 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980
1981 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001982 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001983 channel = pc_->CreateDataChannelOrError("max", &config);
1984 EXPECT_TRUE(channel.ok());
1985 EXPECT_EQ(config.id, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986
1987 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001988 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001989 channel = pc_->CreateDataChannelOrError("x", &config);
1990 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991}
1992
deadbeefab9b2d12015-10-14 11:33:11 -07001993// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08001994TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001995 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001996 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07001997
1998 std::string label = "test";
Florent Castelli72424402022-04-06 03:45:10 +02001999 auto channel = pc_->CreateDataChannelOrError(label, nullptr);
2000 EXPECT_TRUE(channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002001
Florent Castelli72424402022-04-06 03:45:10 +02002002 auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr);
2003 EXPECT_TRUE(dup_channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002004}
2005
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002006#ifdef WEBRTC_HAVE_SCTP
Zhi Huang644fde42018-04-02 19:16:26 -07002007// This tests that SCTP data channels can be rejected in an answer.
2008TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2009#else
2010TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2011#endif
2012{
Niels Möllerf06f9232018-08-07 12:32:18 +02002013 RTCConfiguration rtc_config;
2014 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002015
Florent Castelli72424402022-04-06 03:45:10 +02002016 auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL);
Zhi Huang644fde42018-04-02 19:16:26 -07002017
2018 CreateOfferAsLocalDescription();
2019
2020 // Create an answer where the m-line for data channels are rejected.
2021 std::string sdp;
2022 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2023 std::unique_ptr<SessionDescriptionInterface> answer(
2024 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2025 ASSERT_TRUE(answer);
2026 cricket::ContentInfo* data_info =
2027 cricket::GetFirstDataContent(answer->description());
2028 data_info->rejected = true;
2029
2030 DoSetRemoteDescription(std::move(answer));
Florent Castelli72424402022-04-06 03:45:10 +02002031 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state());
Zhi Huang644fde42018-04-02 19:16:26 -07002032}
2033
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034// Test that we can create a session description from an SDP string from
2035// FireFox, use it as a remote session description, generate an answer and use
2036// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002037TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002038 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002039 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002040 AddAudioTrack("audio_label");
2041 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002042 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002043 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002044 webrtc::kFireFoxSdpOffer, nullptr));
2045 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 CreateAnswerAsLocalDescription();
Niels Möllerafb246b2022-04-20 14:26:50 +02002047 ASSERT_TRUE(pc_->local_description() != nullptr);
2048 ASSERT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
2050 const cricket::ContentInfo* content =
2051 cricket::GetFirstAudioContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002052 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 EXPECT_FALSE(content->rejected);
2054
2055 content =
2056 cricket::GetFirstVideoContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002057 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 EXPECT_FALSE(content->rejected);
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002059#ifdef WEBRTC_HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 content =
2061 cricket::GetFirstDataContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002062 ASSERT_TRUE(content != nullptr);
Zhi Huange830e682018-03-30 10:48:35 -07002063 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002064#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065}
2066
Harald Alvestrand0d018412021-11-04 13:52:31 +00002067// Test that fallback from DTLS to SDES is not supported.
2068// The fallback was previously supported but was removed to simplify the code
2069// and because it's non-standard.
2070TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002071 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002072 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002073 // Wait for fake certificate to be generated. Previously, this is what caused
2074 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002075 AddAudioTrack("audio_label");
2076 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002077 ASSERT_NE(nullptr, fake_certificate_generator_);
2078 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2079 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002080 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002081 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2082 nullptr));
Harald Alvestrand0d018412021-11-04 13:52:31 +00002083 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002084}
2085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086// Test that we can create an audio only offer and receive an answer with a
2087// limited set of audio codecs and receive an updated offer with more audio
2088// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002089TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002090 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002091 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 CreateOfferAsLocalDescription();
2093
Florent Castelli15a38de2022-04-06 00:38:21 +02002094 const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2095 ? webrtc::kAudioSdpPlanB
2096 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002097 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002098 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002099 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
Steve Anton36da6ff2018-02-16 16:04:20 -08002101 const char* reoffer_sdp =
Florent Castelli15a38de2022-04-06 00:38:21 +02002102 (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
Steve Anton36da6ff2018-02-16 16:04:20 -08002103 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2104 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002105 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002106 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002107 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 CreateAnswerAsLocalDescription();
2109}
2110
deadbeefc80741f2015-10-22 13:14:45 -07002111// Test that if we're receiving (but not sending) a track, subsequent offers
2112// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002113TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002114 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002115 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002116 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002117 CreateAnswerAsLocalDescription();
2118
2119 // At this point we should be receiving stream 1, but not sending anything.
2120 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002121 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002122 DoCreateOffer(&offer, nullptr);
2123
2124 const cricket::ContentInfo* video_content =
2125 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002126 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2127 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002128
2129 const cricket::ContentInfo* audio_content =
2130 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002131 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2132 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002133}
2134
2135// Test that if we're receiving (but not sending) a track, and the
2136// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2137// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002138TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002139 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002140 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002141 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002142 CreateAnswerAsLocalDescription();
2143
2144 // At this point we should be receiving stream 1, but not sending anything.
2145 // A new offer would be recvonly, but we'll set the "no receive" constraints
2146 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002147 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002148 RTCOfferAnswerOptions options;
2149 options.offer_to_receive_audio = 0;
2150 options.offer_to_receive_video = 0;
2151 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002152
2153 const cricket::ContentInfo* video_content =
2154 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002155 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2156 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002157
2158 const cricket::ContentInfo* audio_content =
2159 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002160 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2161 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002162}
2163
deadbeef653b8e02015-11-11 12:55:10 -08002164// Test that we can use SetConfiguration to change the ICE servers of the
2165// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002166TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002167 CreatePeerConnection();
2168
Steve Anton36da6ff2018-02-16 16:04:20 -08002169 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002170 PeerConnectionInterface::IceServer server;
2171 server.uri = "stun:test_hostname";
2172 config.servers.push_back(server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002173 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef653b8e02015-11-11 12:55:10 -08002174
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002175 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2176 EXPECT_EQ("test_hostname",
2177 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002178}
2179
Steve Anton36da6ff2018-02-16 16:04:20 -08002180TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002181 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002182 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002183 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002184 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002185 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2186}
2187
Steve Anton36da6ff2018-02-16 16:04:20 -08002188TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002189 PeerConnectionInterface::RTCConfiguration config;
2190 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002191 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002192 config = pc_->GetConfiguration();
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002193 EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002194
2195 config.prune_turn_ports = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002196 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002197 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
2198 port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002199}
2200
skvladd1f5fda2017-02-03 16:54:05 -08002201// Test that the ice check interval can be changed. This does not verify that
2202// the setting makes it all the way to P2PTransportChannel, as that would
2203// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002204TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002205 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002206 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002207 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002208 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002209 config.ice_check_min_interval = 100;
Niels Möller2579f0c2019-08-19 09:58:17 +02002210 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002211 config = pc_->GetConfiguration();
2212 EXPECT_EQ(config.ice_check_min_interval, 100);
2213}
2214
2215TEST_P(PeerConnectionInterfaceTest,
2216 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2217 PeerConnectionInterface::RTCConfiguration config;
2218 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2219 CreatePeerConnection(config);
2220 config = pc_->GetConfiguration();
2221 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2222
2223 config.surface_ice_candidates_on_ice_transport_type_changed = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002224 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002225 config = pc_->GetConfiguration();
2226 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002227}
2228
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002229// Test that when SetConfiguration changes both the pool size and other
2230// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002231TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002232 SetConfigurationCreatesPooledSessionCorrectly) {
2233 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002234 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002235 config.ice_candidate_pool_size = 1;
2236 PeerConnectionInterface::IceServer server;
2237 server.uri = kStunAddressOnly;
2238 config.servers.push_back(server);
2239 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002240 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002241
2242 const cricket::FakePortAllocatorSession* session =
2243 static_cast<const cricket::FakePortAllocatorSession*>(
2244 port_allocator_->GetPooledSession());
2245 ASSERT_NE(nullptr, session);
2246 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002247}
2248
deadbeef293e9262017-01-11 12:28:30 -08002249// Test that after SetLocalDescription, changing the pool size is not allowed,
2250// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002251TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002252 CantChangePoolSizeAfterSetLocalDescription) {
2253 CreatePeerConnection();
2254 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002255 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002256 config.ice_candidate_pool_size = 1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002257 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002258
2259 // Set remote offer; can still change pool size at this point.
2260 CreateOfferAsRemoteDescription();
2261 config.ice_candidate_pool_size = 2;
Niels Möller2579f0c2019-08-19 09:58:17 +02002262 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002263
2264 // Set local answer; now it's too late.
2265 CreateAnswerAsLocalDescription();
2266 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002267 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002268 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2269}
2270
deadbeef42a42632017-03-10 15:18:00 -08002271// Test that after setting an answer, extra pooled sessions are discarded. The
2272// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002273TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002274 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2275 CreatePeerConnection();
2276
2277 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002278 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002279 config.ice_candidate_pool_size = 4;
Niels Möller2579f0c2019-08-19 09:58:17 +02002280 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002281
2282 // Do offer/answer.
2283 CreateOfferAsRemoteDescription();
2284 CreateAnswerAsLocalDescription();
2285
2286 // Expect no pooled sessions to be left.
2287 const cricket::PortAllocatorSession* session =
2288 port_allocator_->GetPooledSession();
2289 EXPECT_EQ(nullptr, session);
2290}
2291
2292// After Close is called, pooled candidates should be discarded so as to not
2293// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002294TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002295 CreatePeerConnection();
2296
Steve Anton36da6ff2018-02-16 16:04:20 -08002297 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002298 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002299 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002300 pc_->Close();
2301
2302 // Expect no pooled sessions to be left.
2303 const cricket::PortAllocatorSession* session =
2304 port_allocator_->GetPooledSession();
2305 EXPECT_EQ(nullptr, session);
2306}
2307
deadbeef293e9262017-01-11 12:28:30 -08002308// Test that SetConfiguration returns an invalid modification error if
2309// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002310TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002311 SetConfigurationReturnsInvalidModificationError) {
2312 PeerConnectionInterface::RTCConfiguration config;
2313 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2314 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2315 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002316 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002317
Steve Anton36da6ff2018-02-16 16:04:20 -08002318 PeerConnectionInterface::RTCConfiguration modified_config =
2319 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002320 modified_config.bundle_policy =
2321 PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möller2579f0c2019-08-19 09:58:17 +02002322 RTCError error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002323 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2324
Steve Anton36da6ff2018-02-16 16:04:20 -08002325 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002326 modified_config.rtcp_mux_policy =
2327 PeerConnectionInterface::kRtcpMuxPolicyRequire;
Niels Möller2579f0c2019-08-19 09:58:17 +02002328 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002329 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2330
Steve Anton36da6ff2018-02-16 16:04:20 -08002331 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002332 modified_config.continual_gathering_policy =
2333 PeerConnectionInterface::GATHER_CONTINUALLY;
Niels Möller2579f0c2019-08-19 09:58:17 +02002334 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002335 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2336}
2337
2338// Test that SetConfiguration returns a range error if the candidate pool size
2339// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002340TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002341 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2342 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002343 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002344 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002345
2346 config.ice_candidate_pool_size = -1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002347 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002348 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2349
2350 config.ice_candidate_pool_size = INT_MAX;
Niels Möller2579f0c2019-08-19 09:58:17 +02002351 error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002352 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2353}
2354
2355// Test that SetConfiguration returns a syntax error if parsing an ICE server
2356// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002357TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002358 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2359 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002360 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002361 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002362
2363 PeerConnectionInterface::IceServer bad_server;
2364 bad_server.uri = "stunn:www.example.com";
2365 config.servers.push_back(bad_server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002366 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002367 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2368}
2369
2370// Test that SetConfiguration returns an invalid parameter error if a TURN
2371// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002372TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002373 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2374 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002375 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002376 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002377
2378 PeerConnectionInterface::IceServer bad_server;
2379 bad_server.uri = "turn:www.example.com";
2380 // Missing password.
2381 bad_server.username = "foo";
2382 config.servers.push_back(bad_server);
2383 RTCError error;
Niels Möller340e0c52019-08-26 11:03:47 +02002384 EXPECT_EQ(pc_->SetConfiguration(config).type(),
2385 RTCErrorType::INVALID_PARAMETER);
deadbeef6de92f92016-12-12 18:49:32 -08002386}
2387
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388// Test that PeerConnection::Close changes the states to closed and all remote
2389// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002390TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 // Initialize a PeerConnection and negotiate local and remote session
2392 // description.
2393 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002394
2395 // With Plan B, verify the stream count. The analog with Unified Plan is the
2396 // RtpTransceiver count.
Florent Castelli15a38de2022-04-06 00:38:21 +02002397 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002398 ASSERT_EQ(1u, pc_->local_streams()->count());
2399 ASSERT_EQ(1u, pc_->remote_streams()->count());
2400 } else {
2401 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2402 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403
2404 pc_->Close();
2405
2406 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2407 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2408 pc_->ice_connection_state());
2409 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2410 pc_->ice_gathering_state());
2411
Florent Castelli15a38de2022-04-06 00:38:21 +02002412 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002413 EXPECT_EQ(1u, pc_->local_streams()->count());
2414 EXPECT_EQ(1u, pc_->remote_streams()->count());
2415 } else {
Harald Alvestrand936f1af2020-09-22 07:41:50 +00002416 // Verify that the RtpTransceivers are still returned.
2417 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Steve Anton36da6ff2018-02-16 16:04:20 -08002418 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419
Steve Anton36da6ff2018-02-16 16:04:20 -08002420 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
Steve Anton36da6ff2018-02-16 16:04:20 -08002421 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
Florent Castelli15a38de2022-04-06 00:38:21 +02002422 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Harald Alvestrand6060df52020-08-11 09:54:02 +02002423 ASSERT_TRUE(audio_receiver);
2424 ASSERT_TRUE(video_receiver);
2425 // Track state may be updated asynchronously.
2426 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2427 audio_receiver->track()->state(), kTimeout);
2428 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2429 video_receiver->track()->state(), kTimeout);
2430 } else {
2431 ASSERT_FALSE(audio_receiver);
2432 ASSERT_FALSE(video_receiver);
2433 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
2436// Test that PeerConnection methods fails gracefully after
2437// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002438// Don't run under Unified Plan since the stream API is not available.
2439TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002440 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002441 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 CreateOfferAsRemoteDescription();
2443 CreateAnswerAsLocalDescription();
2444
2445 ASSERT_EQ(1u, pc_->local_streams()->count());
Niels Möllere7cc8832022-01-04 15:20:03 +01002446 rtc::scoped_refptr<MediaStreamInterface> local_stream(
2447 pc_->local_streams()->at(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448
2449 pc_->Close();
2450
Niels Möllerafb246b2022-04-20 14:26:50 +02002451 pc_->RemoveStream(local_stream.get());
2452 EXPECT_FALSE(pc_->AddStream(local_stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453
Florent Castelli72424402022-04-06 03:45:10 +02002454 EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455
Niels Möllerafb246b2022-04-20 14:26:50 +02002456 EXPECT_TRUE(pc_->local_description() != nullptr);
2457 EXPECT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458
kwibergd1fe2812016-04-27 06:47:29 -07002459 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002460 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002461 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002462 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463
2464 std::string sdp;
2465 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002466 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002467 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002468 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469
2470 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002471 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002472 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002473 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474}
2475
2476// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002477TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 InitiateCall();
2479 pc_->Close();
Niels Möllerafb246b2022-04-20 14:26:50 +02002480 DoGetStats(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481}
deadbeefab9b2d12015-10-14 11:33:11 -07002482
2483// NOTE: The series of tests below come from what used to be
2484// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2485// setting a remote or local description has the expected effects.
2486
2487// This test verifies that the remote MediaStreams corresponding to a received
2488// SDP string is created. In this test the two separate MediaStreams are
2489// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002490TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002491 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002492 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002493 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002494
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002495 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002496 EXPECT_TRUE(
2497 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2498 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2499 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2500
2501 // Create a session description based on another SDP with another
2502 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002503 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002504
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002505 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002506 EXPECT_TRUE(
2507 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2508}
2509
2510// This test verifies that when remote tracks are added/removed from SDP, the
2511// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002512// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2513// specific behavior.
2514TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002515 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002516 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002517 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002518 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002519 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002520 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002521 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002522 reference_collection_.get()));
deadbeefab9b2d12015-10-14 11:33:11 -07002523
2524 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002525 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002526 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002527 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
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()));
zhihuang9763d562016-08-05 11:14:50 -07002530 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002531 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2532 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002533 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002534 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2535 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002536
2537 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002538 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002539 CreateSessionDescriptionAndReference(1, 1);
Niels Möllerafb246b2022-04-20 14:26:50 +02002540 MockTrackObserver audio_track_observer(audio_track2.get());
2541 MockTrackObserver video_track_observer(video_track2.get());
perkjd61bf802016-03-24 03:16:19 -07002542
2543 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2544 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002545 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002546 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002547 reference_collection_.get()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002548 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002549 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002550 audio_track2->state(), kTimeout);
2551 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2552 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002553}
2554
2555// This tests that remote tracks are ended if a local session description is set
2556// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002557TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002558 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002559 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002560 // First create and set a remote offer, then reject its video content in our
2561 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002562 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2563 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2564 ASSERT_TRUE(audio_receiver);
2565 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2566 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002567
Steve Anton36da6ff2018-02-16 16:04:20 -08002568 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2569 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002570 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002571 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2572 video_receiver->track();
2573 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002574
kwibergd1fe2812016-04-27 06:47:29 -07002575 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002576 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002577 cricket::ContentInfo* video_info =
2578 local_answer->description()->GetContentByName("video");
2579 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002580 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002581 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2582 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002583
2584 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002585 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002586 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002587 video_info = local_offer->description()->GetContentByName("video");
2588 ASSERT_TRUE(video_info != nullptr);
2589 video_info->rejected = true;
2590 cricket::ContentInfo* audio_info =
2591 local_offer->description()->GetContentByName("audio");
2592 ASSERT_TRUE(audio_info != nullptr);
2593 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002594 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002595 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002596 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2597 kTimeout);
2598 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2599 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002600}
2601
2602// This tests that we won't crash if the remote track has been removed outside
2603// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002604// Don't run under Unified Plan since the stream API is not available.
2605TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002606 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002607 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002608 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002609 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002610 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2611 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002612
kwibergd1fe2812016-04-27 06:47:29 -07002613 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002614 webrtc::CreateSessionDescription(SdpType::kAnswer,
2615 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002616 cricket::ContentInfo* video_info =
2617 local_answer->description()->GetContentByName("video");
2618 video_info->rejected = true;
2619 cricket::ContentInfo* audio_info =
2620 local_answer->description()->GetContentByName("audio");
2621 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002622 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002623
2624 // No crash is a pass.
2625}
2626
deadbeef5e97fb52015-10-15 12:49:08 -07002627// This tests that if a recvonly remote description is set, no remote streams
2628// will be created, even if the description contains SSRCs/MSIDs.
2629// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002630TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002631 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002632 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002633
Steve Anton36da6ff2018-02-16 16:04:20 -08002634 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002635 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002636 CreateAndSetRemoteOffer(recvonly_offer);
2637
2638 EXPECT_EQ(0u, observer_.remote_streams()->count());
2639}
2640
deadbeefab9b2d12015-10-14 11:33:11 -07002641// This tests that a default MediaStream is created if a remote session
2642// description doesn't contain any streams and no MSID support.
2643// It also tests that the default stream is updated if a video m-line is added
2644// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002645// Don't run under Unified Plan since this behavior is Plan B specific.
2646TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002647 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002648 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002649 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2650
2651 ASSERT_EQ(1u, observer_.remote_streams()->count());
2652 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2653
2654 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2655 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002656 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002657
2658 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2659 ASSERT_EQ(1u, observer_.remote_streams()->count());
2660 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2661 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002662 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2663 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002664 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2665 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002666 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2667 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002668}
2669
2670// This tests that a default MediaStream is created if a remote session
2671// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002672// Don't run under Unified Plan since this behavior is Plan B specific.
2673TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002674 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002675 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002676 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002677 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2678
2679 ASSERT_EQ(1u, observer_.remote_streams()->count());
2680 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2681
2682 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2683 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002684 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002685}
2686
2687// This tests that it won't crash when PeerConnection tries to remove
2688// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002689// Don't run under Unified Plan since this behavior is Plan B specific.
2690TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002691 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002692 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002693 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002694 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002695 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2696 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002697
2698 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2699
2700 // No crash is a pass.
2701}
2702
2703// This tests that a default MediaStream is created if the remote session
2704// description doesn't contain any streams and don't contain an indication if
2705// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002706// Don't run under Unified Plan since this behavior is Plan B specific.
2707TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002708 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002709 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002710 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002711 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2712
2713 ASSERT_EQ(1u, observer_.remote_streams()->count());
2714 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2715 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2716 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2717}
2718
2719// This tests that a default MediaStream is not created if the remote session
2720// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002721// Don't run under Unified Plan since this behavior is Plan B specific.
2722TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002723 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002724 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002725 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2726 EXPECT_EQ(0u, observer_.remote_streams()->count());
2727}
2728
deadbeefbda7e0b2015-12-08 17:13:40 -08002729// This tests that when setting a new description, the old default tracks are
2730// not destroyed and recreated.
2731// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002732// Don't run under Unified Plan since this behavior is Plan B specific.
2733TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002734 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002735 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002736 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002737 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2738
2739 ASSERT_EQ(1u, observer_.remote_streams()->count());
2740 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2741 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2742
2743 // Set the track to "disabled", then set a new description and ensure the
2744 // track is still disabled, which ensures it hasn't been recreated.
2745 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2746 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2747 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2748 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2749}
2750
deadbeefab9b2d12015-10-14 11:33:11 -07002751// This tests that a default MediaStream is not created if a remote session
2752// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08002753// Don't run under Unified Plan since this behavior is Plan B specific.
2754TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002755 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002756 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002757 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002758 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002759 EXPECT_TRUE(
2760 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2761
2762 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2763 EXPECT_EQ(0u, observer_.remote_streams()->count());
2764}
2765
Seth Hampson5897a6e2018-04-03 11:16:33 -07002766// This tests that a default MediaStream is created if a remote SDP comes from
2767// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
2768TEST_F(PeerConnectionInterfaceTestPlanB,
2769 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002770 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002771 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07002772 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
2773 // Add a=msid lines to simulate a Unified Plan endpoint that only
2774 // signals stream IDs with a=msid lines.
2775 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
2776
2777 CreateAndSetRemoteOffer(sdp_string);
2778
2779 ASSERT_EQ(1u, observer_.remote_streams()->count());
2780 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2781 EXPECT_EQ("default", remote_stream->id());
2782 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2783}
2784
Seth Hampson5b4f0752018-04-02 16:31:36 -07002785// This tests that when a Plan B endpoint receives an SDP that signals no media
2786// stream IDs indicated by the special character "-" in the a=msid line, that
2787// a default stream ID will be used for the MediaStream ID. This can occur
2788// when a Unified Plan endpoint signals no media stream IDs, but signals both
2789// a=ssrc msid and a=msid lines for interop signaling with Plan B.
2790TEST_F(PeerConnectionInterfaceTestPlanB,
2791 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002792 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002793 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07002794 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
2795 // the sender's stream ID will be interpreted as no stream IDs.
2796 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
2797 sdp_string.append("a=msid:- audiotrack0\n");
2798
2799 CreateAndSetRemoteOffer(sdp_string);
2800
2801 ASSERT_EQ(1u, observer_.remote_streams()->count());
2802 // Because SSRCs are signaled the track ID will be what was signaled in the
2803 // a=msid line.
2804 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2805 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2806 EXPECT_EQ("default", remote_stream->id());
2807 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07002808
2809 // Previously a bug ocurred when setting the remote description a second time.
2810 // This is because we checked equality of the remote StreamParams stream ID
2811 // (empty), and the previously set stream ID for the remote sender
2812 // ("default"). This cause a track to be removed, then added, when really
2813 // nothing should occur because it is the same track.
2814 CreateAndSetRemoteOffer(sdp_string);
2815 EXPECT_EQ(0u, observer_.remove_track_events_.size());
2816 EXPECT_EQ(1u, observer_.add_track_events_.size());
2817 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2818 remote_stream = observer_.remote_streams()->at(0);
2819 EXPECT_EQ("default", remote_stream->id());
2820 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07002821}
2822
deadbeefab9b2d12015-10-14 11:33:11 -07002823// This tests that an RtpSender is created when the local description is set
2824// after adding a local stream.
2825// TODO(deadbeef): This test and the one below it need to be updated when
2826// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08002827// Don't run under Unified Plan since this behavior is Plan B specific.
2828TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002829 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002830 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002831
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002832 // Create an offer with 1 stream with 2 tracks of each type.
2833 rtc::scoped_refptr<StreamCollection> stream_collection =
2834 CreateStreamCollection(1, 2);
2835 pc_->AddStream(stream_collection->at(0));
2836 std::unique_ptr<SessionDescriptionInterface> offer;
2837 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002838 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002839
deadbeefab9b2d12015-10-14 11:33:11 -07002840 auto senders = pc_->GetSenders();
2841 EXPECT_EQ(4u, senders.size());
2842 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2843 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2844 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2845 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2846
2847 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002848 pc_->RemoveStream(stream_collection->at(0));
2849 stream_collection = CreateStreamCollection(1, 1);
2850 pc_->AddStream(stream_collection->at(0));
2851 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002852 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002853
deadbeefab9b2d12015-10-14 11:33:11 -07002854 senders = pc_->GetSenders();
2855 EXPECT_EQ(2u, senders.size());
2856 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2857 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2858 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2859 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2860}
2861
2862// This tests that an RtpSender is created when the local description is set
2863// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002864// Don't run under Unified Plan since this behavior is Plan B specific.
2865TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002866 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002867 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002868 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002869
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002870 rtc::scoped_refptr<StreamCollection> stream_collection =
2871 CreateStreamCollection(1, 2);
2872 // Add a stream to create the offer, but remove it afterwards.
2873 pc_->AddStream(stream_collection->at(0));
2874 std::unique_ptr<SessionDescriptionInterface> offer;
2875 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2876 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002877
Steve Antondb45ca82017-09-11 18:27:34 -07002878 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002879 auto senders = pc_->GetSenders();
2880 EXPECT_EQ(0u, senders.size());
2881
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002882 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002883 senders = pc_->GetSenders();
2884 EXPECT_EQ(4u, senders.size());
2885 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2886 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2887 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2888 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2889}
2890
2891// This tests that the expected behavior occurs if the SSRC on a local track is
2892// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002893TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002894 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002895 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002896 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002897
Steve Anton36da6ff2018-02-16 16:04:20 -08002898 AddAudioTrack(kAudioTracks[0]);
2899 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002900 std::unique_ptr<SessionDescriptionInterface> offer;
2901 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2902 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07002903 std::unique_ptr<SessionDescriptionInterface> modified_offer =
2904 webrtc::CreateSessionDescription(
2905 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002906 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07002907 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002908
deadbeefab9b2d12015-10-14 11:33:11 -07002909 auto senders = pc_->GetSenders();
2910 EXPECT_EQ(2u, senders.size());
2911 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2912 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2913
2914 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002915 cricket::MediaContentDescription* desc =
2916 cricket::GetFirstAudioContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002917 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002918 for (StreamParams& stream : desc->mutable_streams()) {
2919 for (unsigned int& ssrc : stream.ssrcs) {
2920 ++ssrc;
2921 }
2922 }
deadbeefab9b2d12015-10-14 11:33:11 -07002923
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002924 desc =
2925 cricket::GetFirstVideoContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002926 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002927 for (StreamParams& stream : desc->mutable_streams()) {
2928 for (unsigned int& ssrc : stream.ssrcs) {
2929 ++ssrc;
2930 }
2931 }
2932
Steve Antondb45ca82017-09-11 18:27:34 -07002933 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002934 senders = pc_->GetSenders();
2935 EXPECT_EQ(2u, senders.size());
2936 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2937 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2938 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2939 // changed.
2940}
2941
2942// This tests that the expected behavior occurs if a new session description is
2943// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002944// Don't run under Unified Plan since the stream API is not available.
2945TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002946 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002947 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002948 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002949
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002950 rtc::scoped_refptr<StreamCollection> stream_collection =
2951 CreateStreamCollection(2, 1);
2952 pc_->AddStream(stream_collection->at(0));
2953 std::unique_ptr<SessionDescriptionInterface> offer;
2954 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002955 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002956
deadbeefab9b2d12015-10-14 11:33:11 -07002957 auto senders = pc_->GetSenders();
2958 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002959 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2960 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002961
2962 // Add a new MediaStream but with the same tracks as in the first stream.
2963 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2964 webrtc::MediaStream::Create(kStreams[1]));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002965 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2966 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
Niels Möllerafb246b2022-04-20 14:26:50 +02002967 pc_->AddStream(stream_1.get());
deadbeefab9b2d12015-10-14 11:33:11 -07002968
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002969 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002970 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002971
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002972 auto new_senders = pc_->GetSenders();
2973 // Should be the same senders as before, but with updated stream id.
2974 // Note that this behavior is subject to change in the future.
2975 // We may decide the PC should ignore existing tracks in AddStream.
2976 EXPECT_EQ(senders, new_senders);
2977 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2978 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002979}
2980
zhihuang81c3a032016-11-17 12:06:24 -08002981// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002982TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002983 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002984 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08002985 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2986 EXPECT_EQ(observer_.num_added_tracks_, 1);
2987 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2988
2989 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08002990 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07002991 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08002992 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2993}
2994
deadbeefd1a38b52016-12-10 13:15:33 -08002995// Test that when SetConfiguration is called and the configuration is
2996// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08002997TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08002998 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01002999 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003000 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003001 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003002 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003003 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3004 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003005
3006 // Do initial offer/answer so there's something to restart.
3007 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003008 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003009
3010 // Grab the ufrags.
3011 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3012
3013 // Change ICE policy, which should trigger an ICE restart on the next offer.
3014 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003015 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003016 CreateOfferAsLocalDescription();
3017
3018 // Grab the new ufrags.
3019 std::vector<std::string> subsequent_ufrags =
3020 GetUfrags(pc_->local_description());
3021
3022 // Sanity check.
3023 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3024 // Check that each ufrag is different.
3025 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3026 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3027 }
3028}
3029
3030// Test that when SetConfiguration is called and the configuration *isn't*
3031// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003032TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003033 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003034 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003035 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003036 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003037 config = pc_->GetConfiguration();
3038 AddAudioTrack(kAudioTracks[0]);
3039 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003040
3041 // Do initial offer/answer so there's something to restart.
3042 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003043 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003044
3045 // Grab the ufrags.
3046 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3047
3048 // Call SetConfiguration with a config identical to what the PC was
3049 // constructed with.
Niels Möller2579f0c2019-08-19 09:58:17 +02003050 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003051 CreateOfferAsLocalDescription();
3052
3053 // Grab the new ufrags.
3054 std::vector<std::string> subsequent_ufrags =
3055 GetUfrags(pc_->local_description());
3056
3057 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3058}
3059
3060// Test for a weird corner case scenario:
3061// 1. Audio/video session established.
3062// 2. SetConfiguration changes ICE config; ICE restart needed.
3063// 3. ICE restart initiated by remote peer, but only for one m= section.
3064// 4. Next createOffer should initiate an ICE restart, but only for the other
3065// m= section; it would be pointless to do an ICE restart for the m= section
3066// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003067TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003068 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003069 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003070 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003071 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003072 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003073 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3074 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003075
3076 // Do initial offer/answer so there's something to restart.
3077 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003078 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003079
3080 // Change ICE policy, which should set the "needs-ice-restart" flag.
3081 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003082 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003083
3084 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003085 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003086 webrtc::CreateSessionDescription(SdpType::kOffer,
3087 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003088 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003089 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3090 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003091 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003092 CreateAnswerAsLocalDescription();
3093
3094 // Grab the ufrags.
3095 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003096 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003097
3098 // Create offer and grab the new ufrags.
3099 CreateOfferAsLocalDescription();
3100 std::vector<std::string> subsequent_ufrags =
3101 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003102 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003103
3104 // Ensure that only the ufrag for the second m= section changed.
3105 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3106 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3107}
3108
deadbeeffe4a8a42016-12-20 17:56:17 -08003109// Tests that the methods to return current/pending descriptions work as
3110// expected at different points in the offer/answer exchange. This test does
3111// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003112TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003113 // This disables DTLS so we can apply an answer to ourselves.
3114 CreatePeerConnection();
3115
3116 // Create initial local offer and get SDP (which will also be used as
3117 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003118 std::unique_ptr<SessionDescriptionInterface> local_offer;
3119 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003120 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003121 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003122
3123 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003124 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3125 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3126 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003127 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3128 EXPECT_EQ(nullptr, pc_->current_local_description());
3129 EXPECT_EQ(nullptr, pc_->current_remote_description());
3130
3131 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003132 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003133 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003134 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3135 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3136 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3137 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003138 EXPECT_EQ(nullptr, pc_->current_local_description());
3139 EXPECT_EQ(nullptr, pc_->current_remote_description());
3140
3141 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003142 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003143 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003144 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3145 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003146 EXPECT_EQ(nullptr, pc_->pending_local_description());
3147 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003148 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3149 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003150
3151 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003152 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003153 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003154 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3155 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3156 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003157 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003158 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3159 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003160
3161 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003162 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003163 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003164 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3165 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3166 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3167 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3168 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3169 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003170
3171 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003172 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003173 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003174 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3175 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003176 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3177 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003178 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3179 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003180}
3181
zhihuang77985012017-02-07 15:45:16 -08003182// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3183// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003184// This version tests the StartRtcEventLog version that receives an object
Artem Titov880fa812021-07-30 22:30:23 +02003185// of type `RtcEventLogOutput`.
Steve Anton36da6ff2018-02-16 16:04:20 -08003186TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003187 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3188 CreatePeerConnection();
3189 // The RtcEventLog will be reset when the PeerConnection is closed.
3190 pc_->Close();
3191
Niels Möllerdec9f742019-06-03 15:25:20 +02003192 EXPECT_FALSE(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02003193 pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(),
Niels Möllerdec9f742019-06-03 15:25:20 +02003194 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003195 pc_->StopRtcEventLog();
3196}
3197
deadbeef30952b42017-04-21 02:41:29 -07003198// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003199TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003200 CreatePeerConnection();
3201
3202 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003203 RTCOfferAnswerOptions options;
3204 options.offer_to_receive_audio = 1;
3205 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003206 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003207 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003208 cricket::SessionDescription* desc = offer->description();
3209 ASSERT_EQ(2u, desc->transport_infos().size());
3210 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3211 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3212
3213 // Apply the offer as a remote description, then create an answer.
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003214 EXPECT_FALSE(pc_->can_trickle_ice_candidates());
Steve Antondb45ca82017-09-11 18:27:34 -07003215 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003216 ASSERT_TRUE(pc_->can_trickle_ice_candidates());
3217 EXPECT_TRUE(*(pc_->can_trickle_ice_candidates()));
deadbeef30952b42017-04-21 02:41:29 -07003218 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003219 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003220 desc = answer->description();
3221 ASSERT_EQ(2u, desc->transport_infos().size());
3222 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3223 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3224}
3225
deadbeef1dcb1642017-03-29 21:08:16 -07003226// Test that ICE renomination isn't offered if it's not enabled in the PC's
3227// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003228TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003229 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003230 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003231 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003232 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003233 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003234
3235 std::unique_ptr<SessionDescriptionInterface> offer;
3236 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3237 cricket::SessionDescription* desc = offer->description();
3238 EXPECT_EQ(1u, desc->transport_infos().size());
3239 EXPECT_FALSE(
3240 desc->transport_infos()[0].description.GetIceParameters().renomination);
3241}
3242
3243// Test that the ICE renomination option is present in generated offers/answers
3244// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003245TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003246 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003247 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003248 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003249 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003250 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003251
3252 std::unique_ptr<SessionDescriptionInterface> offer;
3253 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3254 cricket::SessionDescription* desc = offer->description();
3255 EXPECT_EQ(1u, desc->transport_infos().size());
3256 EXPECT_TRUE(
3257 desc->transport_infos()[0].description.GetIceParameters().renomination);
3258
3259 // Set the offer as a remote description, then create an answer and ensure it
3260 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003261 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003262 std::unique_ptr<SessionDescriptionInterface> answer;
3263 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3264 desc = answer->description();
3265 EXPECT_EQ(1u, desc->transport_infos().size());
3266 EXPECT_TRUE(
3267 desc->transport_infos()[0].description.GetIceParameters().renomination);
3268}
3269
3270// Test that if CreateOffer is called with the deprecated "offer to receive
3271// audio/video" constraints, they're processed and result in an offer with
3272// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003273TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003274 CreatePeerConnection();
3275
Niels Möllerf06f9232018-08-07 12:32:18 +02003276 RTCOfferAnswerOptions options;
3277 options.offer_to_receive_audio = 1;
3278 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003279 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003280 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003281
3282 cricket::SessionDescription* desc = offer->description();
3283 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3284 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3285 ASSERT_NE(nullptr, audio);
3286 ASSERT_NE(nullptr, video);
3287 EXPECT_FALSE(audio->rejected);
3288 EXPECT_FALSE(video->rejected);
3289}
3290
3291// Test that if CreateAnswer is called with the deprecated "offer to receive
3292// audio/video" constraints, they're processed and can be used to reject an
3293// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003294// Don't run under Unified Plan since this behavior is not supported.
3295TEST_F(PeerConnectionInterfaceTestPlanB,
3296 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003297 CreatePeerConnection();
3298
3299 // First, create an offer with audio/video and apply it as a remote
3300 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003301 RTCOfferAnswerOptions options;
3302 options.offer_to_receive_audio = 1;
3303 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003304 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003305 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003306 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003307
3308 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003309 options.offer_to_receive_audio = 0;
3310 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003311 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003312 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003313
3314 cricket::SessionDescription* desc = answer->description();
3315 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3316 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3317 ASSERT_NE(nullptr, audio);
3318 ASSERT_NE(nullptr, video);
3319 EXPECT_TRUE(audio->rejected);
3320 EXPECT_TRUE(video->rejected);
3321}
3322
deadbeef1dcb1642017-03-29 21:08:16 -07003323// Test that negotiation can succeed with a data channel only, and with the max
3324// bundle policy. Previously there was a bug that prevented this.
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003325#ifdef WEBRTC_HAVE_SCTP
Steve Anton36da6ff2018-02-16 16:04:20 -08003326TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3327#else
3328TEST_P(PeerConnectionInterfaceTest,
3329 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003330#endif // WEBRTC_HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003331 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003332 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003333 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003334 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003335
3336 // First, create an offer with only a data channel and apply it as a remote
3337 // description.
Florent Castelli72424402022-04-06 03:45:10 +02003338 pc_->CreateDataChannelOrError("test", nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07003339 std::unique_ptr<SessionDescriptionInterface> offer;
3340 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003341 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003342
3343 // Create and set answer as well.
3344 std::unique_ptr<SessionDescriptionInterface> answer;
3345 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003346 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003347}
3348
Steve Anton36da6ff2018-02-16 16:04:20 -08003349TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003350 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003351 BitrateSettings bitrate;
3352 bitrate.start_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003353 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3354}
3355
Steve Anton36da6ff2018-02-16 16:04:20 -08003356TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003357 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003358 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003359 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003360 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3361}
3362
Steve Anton36da6ff2018-02-16 16:04:20 -08003363TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
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 = 5;
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003367 bitrate.start_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003368 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3369}
3370
Steve Anton36da6ff2018-02-16 16:04:20 -08003371TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003372 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003373 BitrateSettings bitrate;
3374 bitrate.start_bitrate_bps = -1;
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, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003379 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003380 BitrateSettings bitrate;
3381 bitrate.start_bitrate_bps = 10;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003382 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003383 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3384}
3385
Steve Anton36da6ff2018-02-16 16:04:20 -08003386TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003387 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003388 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003389 bitrate.min_bitrate_bps = 10;
3390 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003391 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3392}
3393
Steve Anton36da6ff2018-02-16 16:04:20 -08003394TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003395 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003396 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003397 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003398 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3399}
3400
Niels Möller0c4f7be2018-05-07 14:01:37 +02003401// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003402// by Call's BitrateConstraints, which comes from the SDP or a default value.
3403// This test checks that a call to SetBitrate with a current bitrate that will
3404// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003405TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003406 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003407 BitrateSettings bitrate;
3408 bitrate.start_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003409 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3410}
3411
zhihuang1c378ed2017-08-17 14:10:50 -07003412// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003413TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003414 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3415 RTCOfferAnswerOptions rtc_options;
3416
3417 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3418 // than kMaxOfferToReceiveMedia should be treated as invalid.
3419 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3420 CreatePeerConnection();
3421 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3422
3423 rtc_options.offer_to_receive_audio =
3424 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3425 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3426}
3427
Steve Anton36da6ff2018-02-16 16:04:20 -08003428TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003429 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3430 RTCOfferAnswerOptions rtc_options;
3431
3432 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3433 // than kMaxOfferToReceiveMedia should be treated as invalid.
3434 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3435 CreatePeerConnection();
3436 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3437
3438 rtc_options.offer_to_receive_video =
3439 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3440 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3441}
3442
3443// Test that the audio and video content will be added to an offer if both
Artem Titov880fa812021-07-30 22:30:23 +02003444// `offer_to_receive_audio` and `offer_to_receive_video` options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003445TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003446 RTCOfferAnswerOptions rtc_options;
3447 rtc_options.offer_to_receive_audio = 1;
3448 rtc_options.offer_to_receive_video = 1;
3449
3450 std::unique_ptr<SessionDescriptionInterface> offer;
3451 CreatePeerConnection();
3452 offer = CreateOfferWithOptions(rtc_options);
3453 ASSERT_TRUE(offer);
3454 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3455 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3456}
3457
3458// Test that only audio content will be added to the offer if only
Artem Titov880fa812021-07-30 22:30:23 +02003459// `offer_to_receive_audio` options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003460TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003461 RTCOfferAnswerOptions rtc_options;
3462 rtc_options.offer_to_receive_audio = 1;
3463 rtc_options.offer_to_receive_video = 0;
3464
3465 std::unique_ptr<SessionDescriptionInterface> offer;
3466 CreatePeerConnection();
3467 offer = CreateOfferWithOptions(rtc_options);
3468 ASSERT_TRUE(offer);
3469 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3470 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3471}
3472
Artem Titov880fa812021-07-30 22:30:23 +02003473// Test that only video content will be added if only `offer_to_receive_video`
zhihuang1c378ed2017-08-17 14:10:50 -07003474// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003475TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003476 RTCOfferAnswerOptions rtc_options;
3477 rtc_options.offer_to_receive_audio = 0;
3478 rtc_options.offer_to_receive_video = 1;
3479
3480 std::unique_ptr<SessionDescriptionInterface> offer;
3481 CreatePeerConnection();
3482 offer = CreateOfferWithOptions(rtc_options);
3483 ASSERT_TRUE(offer);
3484 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3485 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3486}
3487
zhihuang1c378ed2017-08-17 14:10:50 -07003488// Test that no media content will be added to the offer if using default
3489// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003490TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003491 RTCOfferAnswerOptions rtc_options;
3492
3493 std::unique_ptr<SessionDescriptionInterface> offer;
3494 CreatePeerConnection();
3495 offer = CreateOfferWithOptions(rtc_options);
3496 ASSERT_TRUE(offer);
3497 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3498 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3499}
3500
Artem Titov880fa812021-07-30 22:30:23 +02003501// Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise
zhihuang1c378ed2017-08-17 14:10:50 -07003502// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003503TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3504 CreatePeerConnection();
3505
zhihuang1c378ed2017-08-17 14:10:50 -07003506 RTCOfferAnswerOptions rtc_options;
3507 rtc_options.ice_restart = false;
3508 rtc_options.offer_to_receive_audio = 1;
3509
3510 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003511 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003512 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3513 auto ufrag1 =
3514 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3515 auto pwd1 =
3516 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003517
Artem Titov880fa812021-07-30 22:30:23 +02003518 // `ice_restart` is false, the ufrag/pwd shouldn't change.
zhihuang1c378ed2017-08-17 14:10:50 -07003519 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003520 auto ufrag2 =
3521 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3522 auto pwd2 =
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 true, the ufrag/pwd should change.
zhihuang1c378ed2017-08-17 14:10:50 -07003526 rtc_options.ice_restart = true;
3527 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003528 auto ufrag3 =
3529 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3530 auto pwd3 =
3531 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003532
3533 EXPECT_EQ(ufrag1, ufrag2);
3534 EXPECT_EQ(pwd1, pwd2);
3535 EXPECT_NE(ufrag2, ufrag3);
3536 EXPECT_NE(pwd2, pwd3);
3537}
3538
Artem Titov880fa812021-07-30 22:30:23 +02003539// Test that if `use_rtp_mux` is true, the bundling will be enabled in the
zhihuang1c378ed2017-08-17 14:10:50 -07003540// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003541TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003542 RTCOfferAnswerOptions rtc_options;
3543 rtc_options.offer_to_receive_audio = 1;
3544 rtc_options.offer_to_receive_video = 1;
3545
3546 std::unique_ptr<SessionDescriptionInterface> offer;
3547 CreatePeerConnection();
3548
3549 rtc_options.use_rtp_mux = true;
3550 offer = CreateOfferWithOptions(rtc_options);
3551 ASSERT_TRUE(offer);
3552 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3553 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3554 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3555
3556 rtc_options.use_rtp_mux = false;
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_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3562}
3563
zhihuang141aacb2017-08-29 13:23:53 -07003564// This test ensures OnRenegotiationNeeded is called when we add track with
3565// MediaStream -> AddTrack in the same way it is called when we add track with
3566// PeerConnection -> AddTrack.
3567// The test can be removed once addStream is rewritten in terms of addTrack
3568// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003569// Don't run under Unified Plan since the stream API is not available.
3570TEST_F(PeerConnectionInterfaceTestPlanB,
3571 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003572 CreatePeerConnectionWithoutDtls();
3573 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003574 pc_factory_->CreateLocalMediaStream(kStreamId1));
Niels Möllerafb246b2022-04-20 14:26:50 +02003575 pc_->AddStream(stream.get());
zhihuang141aacb2017-08-29 13:23:53 -07003576 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003577 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003578 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003579 CreateVideoTrack("video_track"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003580 stream->AddTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003581 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3582 observer_.renegotiation_needed_ = false;
3583
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003584 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003585 stream->AddTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003586 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3587 observer_.renegotiation_needed_ = false;
3588
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003589 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003590 stream->RemoveTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003591 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3592 observer_.renegotiation_needed_ = false;
3593
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003594 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003595 stream->RemoveTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003596 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3597 observer_.renegotiation_needed_ = false;
3598}
3599
Zhi Huangb2d355e2017-10-26 17:26:37 -07003600// Tests that an error is returned if a description is applied that has fewer
3601// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003602TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003603 MediaSectionCountEnforcedForSubsequentOffer) {
3604 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003605 AddAudioTrack("audio_label");
3606 AddVideoTrack("video_label");
3607
Zhi Huangb2d355e2017-10-26 17:26:37 -07003608 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003609 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003610 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3611
3612 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003613 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003614 offer->description()->contents().pop_back();
3615 offer->description()->contents().pop_back();
3616 ASSERT_TRUE(offer->description()->contents().empty());
3617 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3618
3619 std::unique_ptr<SessionDescriptionInterface> answer;
3620 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3621 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3622
3623 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003624 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003625 offer->description()->contents().pop_back();
3626 offer->description()->contents().pop_back();
3627 ASSERT_TRUE(offer->description()->contents().empty());
3628 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3629}
3630
Johannes Kron89f874e2018-11-12 10:25:48 +01003631TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3632 RTCConfiguration config;
Emil Lundmark801c9992021-01-19 13:06:32 +01003633 // Default behavior is true.
Johannes Kron89f874e2018-11-12 10:25:48 +01003634 CreatePeerConnection(config);
3635 std::unique_ptr<SessionDescriptionInterface> offer;
3636 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003637 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3638 // Possible to set to false.
3639 config.offer_extmap_allow_mixed = false;
Johannes Kron89f874e2018-11-12 10:25:48 +01003640 CreatePeerConnection(config);
Artem Titov4f3a2eb2021-01-26 09:58:21 +01003641 offer = nullptr;
Johannes Kron89f874e2018-11-12 10:25:48 +01003642 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003643 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
Johannes Kron89f874e2018-11-12 10:25:48 +01003644}
3645
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003646INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3647 PeerConnectionInterfaceTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003648 Values(SdpSemantics::kPlanB_DEPRECATED,
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003649 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003650
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003651class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003652 protected:
3653 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003654 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003655 }
nisseeaabdf62017-05-05 02:23:02 -07003656 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003657 const RTCConfiguration& config) {
Florent Castelli72424402022-04-06 03:45:10 +02003658 PeerConnectionDependencies pc_dependencies(&observer_);
3659 auto result =
3660 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3661 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003662 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003663 return result.value()->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003664 }
3665
zhihuang9763d562016-08-05 11:14:50 -07003666 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003667 MockPeerConnectionObserver observer_;
3668};
3669
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003670// This sanity check validates the test infrastructure itself.
3671TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3672 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003673 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Florent Castelli72424402022-04-06 03:45:10 +02003674 PeerConnectionDependencies pc_dependencies(&observer_);
3675 auto result =
3676 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3677 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003678 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003679 result.value()->Close(); // No abort -> ok.
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003680 SUCCEED();
3681}
3682
nisse51542be2016-02-12 02:27:06 -08003683// This test verifies the default behaviour with no constraints and a
3684// default RTCConfiguration.
3685TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3686 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003687 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003688
Niels Möllerf06f9232018-08-07 12:32:18 +02003689 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003690
Henrik Boström35c5cc82022-04-14 09:23:20 +02003691 EXPECT_TRUE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003692 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3693 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003694 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003695 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003696}
3697
Niels Möller1d7ecd22018-01-18 15:25:12 +01003698// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003699// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003700TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3701 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003702 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003703
Niels Möller71bdda02016-03-31 12:59:59 +02003704 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003705 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003706
Niels Möller1d7ecd22018-01-18 15:25:12 +01003707 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003708}
3709
Niels Möller6539f692018-01-18 08:58:50 +01003710// This test verifies that the experiment_cpu_load_estimator flag is
3711// propagated from RTCConfiguration to the PeerConnection.
3712TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3713 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003714 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Niels Möller6539f692018-01-18 08:58:50 +01003715
3716 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003717 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003718
3719 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3720}
3721
deadbeef293e9262017-01-11 12:28:30 -08003722// Tests a few random fields being different.
3723TEST(RTCConfigurationTest, ComparisonOperators) {
3724 PeerConnectionInterface::RTCConfiguration a;
3725 PeerConnectionInterface::RTCConfiguration b;
3726 EXPECT_EQ(a, b);
3727
3728 PeerConnectionInterface::RTCConfiguration c;
3729 c.servers.push_back(PeerConnectionInterface::IceServer());
3730 EXPECT_NE(a, c);
3731
3732 PeerConnectionInterface::RTCConfiguration d;
3733 d.type = PeerConnectionInterface::kRelay;
3734 EXPECT_NE(a, d);
3735
3736 PeerConnectionInterface::RTCConfiguration e;
3737 e.audio_jitter_buffer_max_packets = 5;
3738 EXPECT_NE(a, e);
3739
3740 PeerConnectionInterface::RTCConfiguration f;
3741 f.ice_connection_receiving_timeout = 1337;
3742 EXPECT_NE(a, f);
3743
3744 PeerConnectionInterface::RTCConfiguration g;
3745 g.disable_ipv6 = true;
3746 EXPECT_NE(a, g);
3747
3748 PeerConnectionInterface::RTCConfiguration h(
3749 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3750 EXPECT_NE(a, h);
3751}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01003752
3753} // namespace
3754} // namespace webrtc