blob: 5b14f104735a5a06b6e3bc7c43d2b36d9f1286c7 [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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <limits.h>
12#include <stdint.h>
13#include <string.h>
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080016#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
Karl Wiberg918f50c2018-07-05 11:40:33 +020019#include "absl/memory/memory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "absl/types/optional.h"
21#include "api/audio/audio_mixer.h"
22#include "api/audio_codecs/audio_decoder_factory.h"
23#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/audio_codecs/builtin_audio_decoder_factory.h"
25#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "api/call/callfactoryinterface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010027#include "api/create_peerconnection_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "api/datachannelinterface.h"
29#include "api/jsep.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "api/jsepsessiondescription.h"
31#include "api/mediastreaminterface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010032#include "api/mediatypes.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "api/peerconnectioninterface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010034#include "api/rtcerror.h"
35#include "api/rtceventlogoutput.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "api/rtpreceiverinterface.h"
37#include "api/rtpsenderinterface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010038#include "api/rtptransceiverinterface.h"
Anders Carlsson67537952018-05-03 11:28:29 +020039#include "api/video_codecs/builtin_video_decoder_factory.h"
40#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010041#include "api/video_codecs/video_decoder_factory.h"
42#include "api/video_codecs/video_encoder_factory.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020043#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Yves Gerey3e707812018-11-28 16:47:49 +010044#include "logging/rtc_event_log/rtc_event_log.h"
45#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
46#include "media/base/codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020047#include "media/base/fakevideocapturer.h"
Yves Gerey3e707812018-11-28 16:47:49 +010048#include "media/base/mediaconfig.h"
49#include "media/base/mediaengine.h"
50#include "media/base/streamparams.h"
51#include "media/base/videocapturer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#include "media/engine/webrtcmediaengine.h"
53#include "media/sctp/sctptransportinternal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010054#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#include "modules/audio_processing/include/audio_processing.h"
56#include "p2p/base/fakeportallocator.h"
Yves Gerey3e707812018-11-28 16:47:49 +010057#include "p2p/base/p2pconstants.h"
58#include "p2p/base/port.h"
59#include "p2p/base/portallocator.h"
60#include "p2p/base/transportdescription.h"
61#include "p2p/base/transportinfo.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#include "pc/audiotrack.h"
63#include "pc/mediasession.h"
64#include "pc/mediastream.h"
65#include "pc/peerconnection.h"
Yves Gerey3e707812018-11-28 16:47:49 +010066#include "pc/peerconnectionfactory.h"
67#include "pc/rtcstatscollector.h"
Steve Anton57858b32018-02-15 15:19:50 -080068#include "pc/rtpsender.h"
Yves Gerey3e707812018-11-28 16:47:49 +010069#include "pc/sessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020070#include "pc/streamcollection.h"
71#include "pc/test/fakeaudiocapturemodule.h"
72#include "pc/test/fakertccertificategenerator.h"
73#include "pc/test/fakevideotracksource.h"
74#include "pc/test/mockpeerconnectionobservers.h"
75#include "pc/test/testsdpstrings.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#include "pc/videotrack.h"
Yves Gerey3e707812018-11-28 16:47:49 +010077#include "rtc_base/checks.h"
78#include "rtc_base/copyonwritebuffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010080#include "rtc_base/platform_file.h"
81#include "rtc_base/refcountedobject.h"
82#include "rtc_base/rtccertificategenerator.h"
83#include "rtc_base/scoped_ref_ptr.h"
84#include "rtc_base/socketaddress.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020085#include "rtc_base/stringutils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010086#include "rtc_base/thread.h"
87#include "rtc_base/timeutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#include "rtc_base/virtualsocketserver.h"
89#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010090#include "test/gtest.h"
Elad Alon9e6565b2017-10-11 16:04:13 +020091#include "test/testsupport/fileutils.h"
kwibergac9f8762016-09-30 22:29:43 -070092
93#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020094#include "pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070095#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
Seth Hampson845e8782018-03-02 11:34:10 -080097static const char kStreamId1[] = "local_stream_1";
98static const char kStreamId2[] = "local_stream_2";
99static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100static const int kDefaultStunPort = 3478;
101static const char kStunAddressOnly[] = "stun:address";
102static const char kStunInvalidPort[] = "stun:address:-1";
103static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
104static const char kStunAddressPortAndMore2[] = "stun:address:port more";
105static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
106static const char kTurnUsername[] = "user";
107static const char kTurnPassword[] = "password";
108static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200109static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
deadbeefab9b2d12015-10-14 11:33:11 -0700111static const char kStreams[][8] = {"stream1", "stream2"};
112static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
113static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
114
deadbeef5e97fb52015-10-15 12:49:08 -0700115static const char kRecvonly[] = "recvonly";
116static const char kSendrecv[] = "sendrecv";
117
deadbeefab9b2d12015-10-14 11:33:11 -0700118// Reference SDP with a MediaStream with label "stream1" and audio track with
119// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800120static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700121 "v=0\r\n"
122 "o=- 0 0 IN IP4 127.0.0.1\r\n"
123 "s=-\r\n"
124 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800125 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700126 "a=ice-ufrag:e5785931\r\n"
127 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
128 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
129 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700130 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700131 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800132 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700133 "a=rtpmap:103 ISAC/16000\r\n"
134 "a=ssrc:1 cname:stream1\r\n"
135 "a=ssrc:1 mslabel:stream1\r\n"
136 "a=ssrc:1 label:audiotrack0\r\n"
137 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800138 "a=ice-ufrag:e5785931\r\n"
139 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
140 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
141 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700142 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700143 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800144 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700145 "a=rtpmap:120 VP8/90000\r\n"
146 "a=ssrc:2 cname:stream1\r\n"
147 "a=ssrc:2 mslabel:stream1\r\n"
148 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800149// Same string as above but with the MID changed to the Unified Plan default.
150// This is needed so that this SDP can be used as an answer for a Unified Plan
151// offer.
152static const char kSdpStringWithStream1UnifiedPlan[] =
153 "v=0\r\n"
154 "o=- 0 0 IN IP4 127.0.0.1\r\n"
155 "s=-\r\n"
156 "t=0 0\r\n"
157 "m=audio 1 RTP/AVPF 103\r\n"
158 "a=ice-ufrag:e5785931\r\n"
159 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
160 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
161 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
162 "a=mid:0\r\n"
163 "a=sendrecv\r\n"
164 "a=rtcp-mux\r\n"
165 "a=rtpmap:103 ISAC/16000\r\n"
166 "a=ssrc:1 cname:stream1\r\n"
167 "a=ssrc:1 mslabel:stream1\r\n"
168 "a=ssrc:1 label:audiotrack0\r\n"
169 "m=video 1 RTP/AVPF 120\r\n"
170 "a=ice-ufrag:e5785931\r\n"
171 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
172 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
173 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
174 "a=mid:1\r\n"
175 "a=sendrecv\r\n"
176 "a=rtcp-mux\r\n"
177 "a=rtpmap:120 VP8/90000\r\n"
178 "a=ssrc:2 cname:stream1\r\n"
179 "a=ssrc:2 mslabel:stream1\r\n"
180 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700181
zhihuang81c3a032016-11-17 12:06:24 -0800182// Reference SDP with a MediaStream with label "stream1" and audio track with
183// id "audio_1";
184static const char kSdpStringWithStream1AudioTrackOnly[] =
185 "v=0\r\n"
186 "o=- 0 0 IN IP4 127.0.0.1\r\n"
187 "s=-\r\n"
188 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800189 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800190 "a=ice-ufrag:e5785931\r\n"
191 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
192 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
193 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800194 "a=mid:audio\r\n"
195 "a=sendrecv\r\n"
196 "a=rtpmap:103 ISAC/16000\r\n"
197 "a=ssrc:1 cname:stream1\r\n"
198 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800199 "a=ssrc:1 label:audiotrack0\r\n"
200 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800201
deadbeefab9b2d12015-10-14 11:33:11 -0700202// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
203// MediaStreams have one audio track and one video track.
204// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800205static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700206 "v=0\r\n"
207 "o=- 0 0 IN IP4 127.0.0.1\r\n"
208 "s=-\r\n"
209 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800210 "a=msid-semantic: WMS stream1 stream2\r\n"
211 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700212 "a=ice-ufrag:e5785931\r\n"
213 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
214 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
215 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700216 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700217 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800218 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=rtpmap:103 ISAC/16000\r\n"
220 "a=ssrc:1 cname:stream1\r\n"
221 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
222 "a=ssrc:3 cname:stream2\r\n"
223 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
224 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800225 "a=ice-ufrag:e5785931\r\n"
226 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
227 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
228 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700229 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700230 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800231 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700232 "a=rtpmap:120 VP8/0\r\n"
233 "a=ssrc:2 cname:stream1\r\n"
234 "a=ssrc:2 msid:stream1 videotrack0\r\n"
235 "a=ssrc:4 cname:stream2\r\n"
236 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800237static const char kSdpStringWithStream1And2UnifiedPlan[] =
238 "v=0\r\n"
239 "o=- 0 0 IN IP4 127.0.0.1\r\n"
240 "s=-\r\n"
241 "t=0 0\r\n"
242 "a=msid-semantic: WMS stream1 stream2\r\n"
243 "m=audio 1 RTP/AVPF 103\r\n"
244 "a=ice-ufrag:e5785931\r\n"
245 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
246 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
247 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
248 "a=mid:0\r\n"
249 "a=sendrecv\r\n"
250 "a=rtcp-mux\r\n"
251 "a=rtpmap:103 ISAC/16000\r\n"
252 "a=ssrc:1 cname:stream1\r\n"
253 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
254 "m=video 1 RTP/AVPF 120\r\n"
255 "a=ice-ufrag:e5785931\r\n"
256 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
257 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
258 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
259 "a=mid:1\r\n"
260 "a=sendrecv\r\n"
261 "a=rtcp-mux\r\n"
262 "a=rtpmap:120 VP8/0\r\n"
263 "a=ssrc:2 cname:stream1\r\n"
264 "a=ssrc:2 msid:stream1 videotrack0\r\n"
265 "m=audio 1 RTP/AVPF 103\r\n"
266 "a=ice-ufrag:e5785931\r\n"
267 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
268 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
269 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
270 "a=mid:2\r\n"
271 "a=sendrecv\r\n"
272 "a=rtcp-mux\r\n"
273 "a=rtpmap:103 ISAC/16000\r\n"
274 "a=ssrc:3 cname:stream2\r\n"
275 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
276 "m=video 1 RTP/AVPF 120\r\n"
277 "a=ice-ufrag:e5785931\r\n"
278 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
279 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
280 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
281 "a=mid:3\r\n"
282 "a=sendrecv\r\n"
283 "a=rtcp-mux\r\n"
284 "a=rtpmap:120 VP8/0\r\n"
285 "a=ssrc:4 cname:stream2\r\n"
286 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700287
288// Reference SDP without MediaStreams. Msid is not supported.
289static const char kSdpStringWithoutStreams[] =
290 "v=0\r\n"
291 "o=- 0 0 IN IP4 127.0.0.1\r\n"
292 "s=-\r\n"
293 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800294 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700295 "a=ice-ufrag:e5785931\r\n"
296 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
297 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
298 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700299 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700300 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800301 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700302 "a=rtpmap:103 ISAC/16000\r\n"
303 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800304 "a=ice-ufrag:e5785931\r\n"
305 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
306 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
307 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700308 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700309 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800310 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700311 "a=rtpmap:120 VP8/90000\r\n";
312
313// Reference SDP without MediaStreams. Msid is supported.
314static const char kSdpStringWithMsidWithoutStreams[] =
315 "v=0\r\n"
316 "o=- 0 0 IN IP4 127.0.0.1\r\n"
317 "s=-\r\n"
318 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800319 "a=msid-semantic: WMS\r\n"
320 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700321 "a=ice-ufrag:e5785931\r\n"
322 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
323 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
324 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700325 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700326 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800327 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=rtpmap:103 ISAC/16000\r\n"
329 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800330 "a=ice-ufrag:e5785931\r\n"
331 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
332 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
333 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700334 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700335 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800336 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700337 "a=rtpmap:120 VP8/90000\r\n";
338
339// Reference SDP without MediaStreams and audio only.
340static const char kSdpStringWithoutStreamsAudioOnly[] =
341 "v=0\r\n"
342 "o=- 0 0 IN IP4 127.0.0.1\r\n"
343 "s=-\r\n"
344 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800345 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700346 "a=ice-ufrag:e5785931\r\n"
347 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
348 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
349 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700350 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700351 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800352 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700353 "a=rtpmap:103 ISAC/16000\r\n";
354
355// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
356static const char kSdpStringSendOnlyWithoutStreams[] =
357 "v=0\r\n"
358 "o=- 0 0 IN IP4 127.0.0.1\r\n"
359 "s=-\r\n"
360 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800361 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700362 "a=ice-ufrag:e5785931\r\n"
363 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
364 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
365 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700366 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700367 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700368 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800369 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700370 "a=rtpmap:103 ISAC/16000\r\n"
371 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800372 "a=ice-ufrag:e5785931\r\n"
373 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
374 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
375 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700376 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700377 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700378 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800379 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=rtpmap:120 VP8/90000\r\n";
381
382static const char kSdpStringInit[] =
383 "v=0\r\n"
384 "o=- 0 0 IN IP4 127.0.0.1\r\n"
385 "s=-\r\n"
386 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700387 "a=msid-semantic: WMS\r\n";
388
389static const char kSdpStringAudio[] =
390 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800391 "a=ice-ufrag:e5785931\r\n"
392 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
393 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
394 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700395 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700396 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800397 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700398 "a=rtpmap:103 ISAC/16000\r\n";
399
400static const char kSdpStringVideo[] =
401 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800402 "a=ice-ufrag:e5785931\r\n"
403 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
404 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
405 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700406 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700407 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800408 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700409 "a=rtpmap:120 VP8/90000\r\n";
410
411static const char kSdpStringMs1Audio0[] =
412 "a=ssrc:1 cname:stream1\r\n"
413 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
414
415static const char kSdpStringMs1Video0[] =
416 "a=ssrc:2 cname:stream1\r\n"
417 "a=ssrc:2 msid:stream1 videotrack0\r\n";
418
419static const char kSdpStringMs1Audio1[] =
420 "a=ssrc:3 cname:stream1\r\n"
421 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
422
423static const char kSdpStringMs1Video1[] =
424 "a=ssrc:4 cname:stream1\r\n"
425 "a=ssrc:4 msid:stream1 videotrack1\r\n";
426
deadbeef8662f942017-01-20 21:20:51 -0800427static const char kDtlsSdesFallbackSdp[] =
428 "v=0\r\n"
429 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
430 "s=-\r\n"
431 "c=IN IP4 0.0.0.0\r\n"
432 "t=0 0\r\n"
433 "a=group:BUNDLE audio\r\n"
434 "a=msid-semantic: WMS\r\n"
435 "m=audio 1 RTP/SAVPF 0\r\n"
436 "a=sendrecv\r\n"
437 "a=rtcp-mux\r\n"
438 "a=mid:audio\r\n"
439 "a=ssrc:1 cname:stream1\r\n"
440 "a=ssrc:1 mslabel:stream1\r\n"
441 "a=ssrc:1 label:audiotrack0\r\n"
442 "a=ice-ufrag:e5785931\r\n"
443 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
444 "a=rtpmap:0 pcmu/8000\r\n"
445 "a=fingerprint:sha-1 "
446 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
447 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700448 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800449 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
450 "dummy_session_params\r\n";
451
perkjd61bf802016-03-24 03:16:19 -0700452using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800453using ::testing::Values;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700454using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700456using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457using webrtc::AudioTrackInterface;
458using webrtc::DataBuffer;
459using webrtc::DataChannelInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460using webrtc::IceCandidateInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700461using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462using webrtc::MediaStreamInterface;
463using webrtc::MediaStreamTrackInterface;
464using webrtc::MockCreateSessionDescriptionObserver;
465using webrtc::MockDataChannelObserver;
Steve Anton94286cb2017-09-26 16:20:19 -0700466using webrtc::MockPeerConnectionObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467using webrtc::MockSetSessionDescriptionObserver;
468using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700469using webrtc::NotifierInterface;
470using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471using webrtc::PeerConnectionInterface;
472using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800473using webrtc::RTCError;
474using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700475using webrtc::RtpReceiverInterface;
476using webrtc::RtpSenderInterface;
Steve Anton57858b32018-02-15 15:19:50 -0800477using webrtc::RtpSenderProxyWithInternal;
478using webrtc::RtpSenderInternal;
Steve Anton4e70a722017-11-28 14:57:10 -0800479using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480using webrtc::SdpParseError;
Steve Anton36da6ff2018-02-16 16:04:20 -0800481using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800482using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700484using webrtc::StreamCollection;
485using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100486using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700487using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488using webrtc::VideoTrackInterface;
489
Steve Anton36da6ff2018-02-16 16:04:20 -0800490using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
491using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493namespace {
494
495// Gets the first ssrc of given content type from the ContentInfo.
496bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
497 if (!content_info || !ssrc) {
498 return false;
499 }
500 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800501 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 if (!media_desc || media_desc->streams().empty()) {
503 return false;
504 }
505 *ssrc = media_desc->streams().begin()->first_ssrc();
506 return true;
507}
508
deadbeefd1a38b52016-12-10 13:15:33 -0800509// Get the ufrags out of an SDP blob. Useful for testing ICE restart
510// behavior.
511std::vector<std::string> GetUfrags(
512 const webrtc::SessionDescriptionInterface* desc) {
513 std::vector<std::string> ufrags;
514 for (const cricket::TransportInfo& info :
515 desc->description()->transport_infos()) {
516 ufrags.push_back(info.description.ice_ufrag);
517 }
518 return ufrags;
519}
520
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521void SetSsrcToZero(std::string* sdp) {
522 const char kSdpSsrcAtribute[] = "a=ssrc:";
523 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
524 size_t ssrc_pos = 0;
525 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200526 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 size_t end_ssrc = sdp->find(" ", ssrc_pos);
528 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
529 ssrc_pos = end_ssrc;
530 }
531}
532
deadbeefab9b2d12015-10-14 11:33:11 -0700533// Check if |streams| contains the specified track.
534bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800535 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700536 const std::string& track_id) {
537 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800538 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700539 return true;
540 }
541 }
542 return false;
543}
544
545// Check if |senders| contains the specified sender, by id.
546bool ContainsSender(
547 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
548 const std::string& id) {
549 for (const auto& sender : senders) {
550 if (sender->id() == id) {
551 return true;
552 }
553 }
554 return false;
555}
556
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700557// Check if |senders| contains the specified sender, by id and stream id.
558bool ContainsSender(
559 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
560 const std::string& id,
561 const std::string& stream_id) {
562 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700563 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700564 return true;
565 }
566 }
567 return false;
568}
569
deadbeefab9b2d12015-10-14 11:33:11 -0700570// Create a collection of streams.
571// CreateStreamCollection(1) creates a collection that
572// correspond to kSdpStringWithStream1.
573// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
574rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700575 int number_of_streams,
576 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700577 rtc::scoped_refptr<StreamCollection> local_collection(
578 StreamCollection::Create());
579
580 for (int i = 0; i < number_of_streams; ++i) {
581 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
582 webrtc::MediaStream::Create(kStreams[i]));
583
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700584 for (int j = 0; j < tracks_per_stream; ++j) {
585 // Add a local audio track.
586 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
587 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
588 nullptr));
589 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700590
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700591 // Add a local video track.
592 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
593 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700594 webrtc::FakeVideoTrackSource::Create(),
595 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700596 stream->AddTrack(video_track);
597 }
deadbeefab9b2d12015-10-14 11:33:11 -0700598
599 local_collection->AddStream(stream);
600 }
601 return local_collection;
602}
603
604// Check equality of StreamCollections.
605bool CompareStreamCollections(StreamCollectionInterface* s1,
606 StreamCollectionInterface* s2) {
607 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
608 return false;
609 }
610
611 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700612 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700613 return false;
614 }
615 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
616 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
617 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
618 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
619
620 if (audio_tracks1.size() != audio_tracks2.size()) {
621 return false;
622 }
623 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
624 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
625 return false;
626 }
627 }
628 if (video_tracks1.size() != video_tracks2.size()) {
629 return false;
630 }
631 for (size_t j = 0; j != video_tracks1.size(); ++j) {
632 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
633 return false;
634 }
635 }
636 }
637 return true;
638}
639
perkjd61bf802016-03-24 03:16:19 -0700640// Helper class to test Observer.
641class MockTrackObserver : public ObserverInterface {
642 public:
643 explicit MockTrackObserver(NotifierInterface* notifier)
644 : notifier_(notifier) {
645 notifier_->RegisterObserver(this);
646 }
647
648 ~MockTrackObserver() { Unregister(); }
649
650 void Unregister() {
651 if (notifier_) {
652 notifier_->UnregisterObserver(this);
653 notifier_ = nullptr;
654 }
655 }
656
657 MOCK_METHOD0(OnChanged, void());
658
659 private:
660 NotifierInterface* notifier_;
661};
662
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700664
nisse528b7932017-05-08 03:21:43 -0700665// The PeerConnectionMediaConfig tests below verify that configuration and
666// constraints are propagated into the PeerConnection's MediaConfig. These
667// settings are intended for MediaChannel constructors, but that is not
668// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700669class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
670 public:
zhihuang38ede132017-06-15 12:52:32 -0700671 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
672 CreatePeerConnectionFactoryForTest() {
673 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
674 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200675 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
676 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700677
henrika919dc2e2017-10-12 14:24:55 +0200678 // Use fake audio device module since we're only testing the interface
679 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700680 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
681 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200682 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200683 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000684 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100685 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700686
687 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
688 webrtc::CreateCallFactory();
689
690 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
691 webrtc::CreateRtcEventLogFactory();
692
693 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
694 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200695 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700696 std::move(event_log_factory));
697 }
698
699 PeerConnectionFactoryForTest(
700 rtc::Thread* network_thread,
701 rtc::Thread* worker_thread,
702 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700703 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
704 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
705 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
706 : webrtc::PeerConnectionFactory(network_thread,
707 worker_thread,
708 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700709 std::move(media_engine),
710 std::move(call_factory),
711 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800712
deadbeefd7850b22017-08-23 10:59:19 -0700713 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700714};
715
Steve Anton36da6ff2018-02-16 16:04:20 -0800716// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
717class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800719 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
720 : vss_(new rtc::VirtualSocketServer()),
721 main_(vss_.get()),
722 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800723#ifdef WEBRTC_ANDROID
724 webrtc::InitializeAndroidObjects();
725#endif
726 }
727
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700729 // Use fake audio capture module since we're only testing the interface
730 // level, and using a real one could make tests flaky when run in parallel.
731 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700733 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200734 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
735 fake_audio_capture_module_),
736 webrtc::CreateBuiltinAudioEncoderFactory(),
737 webrtc::CreateBuiltinAudioDecoderFactory(),
738 webrtc::CreateBuiltinVideoEncoderFactory(),
739 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
740 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700741 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700742 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700743 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700744 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 }
746
747 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200748 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 }
750
deadbeef293e9262017-01-11 12:28:30 -0800751 // DTLS does not work in a loopback call, so is disabled for most of the
752 // tests in this file.
753 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200754 RTCConfiguration config;
755 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800756
Niels Möllerf06f9232018-08-07 12:32:18 +0200757 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 }
759
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700760 void CreatePeerConnectionWithIceTransportsType(
761 PeerConnectionInterface::IceTransportsType type) {
762 PeerConnectionInterface::RTCConfiguration config;
763 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200764 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700765 }
766
767 void CreatePeerConnectionWithIceServer(const std::string& uri,
768 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800769 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700771 server.uri = uri;
772 server.password = password;
773 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200774 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700775 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776
Niels Möllerf06f9232018-08-07 12:32:18 +0200777 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700778 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800779 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
780 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000781
deadbeef1dcb1642017-03-29 21:08:16 -0700782 // Create certificate generator unless DTLS constraint is explicitly set to
783 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200784 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200785
786 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800787 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
788 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000789 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800790 RTCConfiguration modified_config = config;
791 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200792 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200793 modified_config, std::move(port_allocator), std::move(cert_generator),
794 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 ASSERT_TRUE(pc_.get() != NULL);
796 observer_.SetPeerConnectionInterface(pc_.get());
797 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
798 }
799
deadbeef0a6c4ca2015-10-06 11:38:28 -0700800 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700802 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700803 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800805 config.sdp_semantics = sdp_semantics_;
806 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200807 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800808 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700809 }
810
Steve Anton038834f2017-07-14 15:59:59 -0700811 void CreatePeerConnectionExpectFail(
812 PeerConnectionInterface::RTCConfiguration config) {
813 PeerConnectionInterface::IceServer server;
814 server.uri = kTurnIceServerUri;
815 server.password = kTurnPassword;
816 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800817 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700818 rtc::scoped_refptr<PeerConnectionInterface> pc =
819 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
820 EXPECT_EQ(nullptr, pc);
821 }
822
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700824 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800825 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
826 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
827 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800829 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830
deadbeef0a6c4ca2015-10-06 11:38:28 -0700831 CreatePeerConnectionExpectFail(kStunInvalidPort);
832 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
833 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700835 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800836 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
837 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800839 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800841 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800843 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 }
845
846 void ReleasePeerConnection() {
847 pc_ = NULL;
848 observer_.SetPeerConnectionInterface(NULL);
849 }
850
Steve Anton36da6ff2018-02-16 16:04:20 -0800851 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
852 const std::string& label) {
853 auto video_source = pc_factory_->CreateVideoSource(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200854 absl::make_unique<cricket::FakeVideoCapturer>(), nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -0800855 return pc_factory_->CreateVideoTrack(label, video_source);
856 }
857
858 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800859 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800860 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800861 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800862 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
864 observer_.renegotiation_needed_ = false;
865 }
866
Steve Anton36da6ff2018-02-16 16:04:20 -0800867 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700868 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800870 stream->AddTrack(CreateVideoTrack(label + "v0"));
871 ASSERT_TRUE(pc_->AddStream(stream));
872 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
873 observer_.renegotiation_needed_ = false;
874 }
875
876 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
877 const std::string& label) {
878 return pc_factory_->CreateAudioTrack(label, nullptr);
879 }
880
881 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800882 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800883 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800884 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800885 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
886 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
887 observer_.renegotiation_needed_ = false;
888 }
889
890 void AddAudioStream(const std::string& label) {
891 rtc::scoped_refptr<MediaStreamInterface> stream(
892 pc_factory_->CreateLocalMediaStream(label));
893 stream->AddTrack(CreateAudioTrack(label + "a0"));
894 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
896 observer_.renegotiation_needed_ = false;
897 }
898
Seth Hampson845e8782018-03-02 11:34:10 -0800899 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 const std::string& audio_track_label,
901 const std::string& video_track_label) {
902 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700903 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800904 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800905 stream->AddTrack(CreateAudioTrack(audio_track_label));
906 stream->AddTrack(CreateVideoTrack(video_track_label));
907 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
909 observer_.renegotiation_needed_ = false;
910 }
911
Steve Anton36da6ff2018-02-16 16:04:20 -0800912 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
913 cricket::MediaType media_type) {
914 for (auto receiver : pc_->GetReceivers()) {
915 if (receiver->media_type() == media_type) {
916 return receiver;
917 }
918 }
919 return nullptr;
920 }
921
kwibergd1fe2812016-04-27 06:47:29 -0700922 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200923 const RTCOfferAnswerOptions* options,
924 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200925 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
926 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200928 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200930 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 }
932 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700933 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 return observer->result();
935 }
936
kwibergd1fe2812016-04-27 06:47:29 -0700937 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200938 const RTCOfferAnswerOptions* options) {
939 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 }
941
kwibergd1fe2812016-04-27 06:47:29 -0700942 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200943 const RTCOfferAnswerOptions* options) {
944 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 }
946
Steve Antondb45ca82017-09-11 18:27:34 -0700947 bool DoSetSessionDescription(
948 std::unique_ptr<SessionDescriptionInterface> desc,
949 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200950 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
951 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700953 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700955 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 }
zhihuang29ff8442016-07-27 11:07:25 -0700957 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
958 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
959 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 return observer->result();
961 }
962
Steve Antondb45ca82017-09-11 18:27:34 -0700963 bool DoSetLocalDescription(
964 std::unique_ptr<SessionDescriptionInterface> desc) {
965 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 }
967
Steve Antondb45ca82017-09-11 18:27:34 -0700968 bool DoSetRemoteDescription(
969 std::unique_ptr<SessionDescriptionInterface> desc) {
970 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 }
972
973 // Calls PeerConnection::GetStats and check the return value.
974 // It does not verify the values in the StatReports since a RTCP packet might
975 // be required.
976 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000977 rtc::scoped_refptr<MockStatsObserver> observer(
978 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200979 if (!pc_->GetStats(observer, track,
980 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 return false;
982 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
983 return observer->called();
984 }
985
Harald Alvestrand89061872018-01-02 14:08:34 +0100986 // Call the standards-compliant GetStats function.
987 bool DoGetRTCStats() {
988 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
989 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
990 pc_->GetStats(callback);
991 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
992 return callback->called();
993 }
994
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800996 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800998 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800999 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -08001000 } else {
1001 // Unified Plan does not support AddStream, so just add an audio and video
1002 // track.
Seth Hampson845e8782018-03-02 11:34:10 -08001003 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1004 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -08001005 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 CreateOfferReceiveAnswer();
1007 }
1008
1009 // Verify that RTP Header extensions has been negotiated for audio and video.
1010 void VerifyRemoteRtpHeaderExtensions() {
1011 const cricket::MediaContentDescription* desc =
1012 cricket::GetFirstAudioContentDescription(
1013 pc_->remote_description()->description());
1014 ASSERT_TRUE(desc != NULL);
1015 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
1016
1017 desc = cricket::GetFirstVideoContentDescription(
1018 pc_->remote_description()->description());
1019 ASSERT_TRUE(desc != NULL);
1020 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
1021 }
1022
1023 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001024 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001025 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 std::string sdp;
1027 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001028 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001029 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001030 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1032 }
1033
deadbeefab9b2d12015-10-14 11:33:11 -07001034 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001035 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001036 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001037 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001038 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1039 }
1040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001042 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001043 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044
1045 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1046 // audio codec change, even if the parameter has nothing to do with
1047 // receiving. Not all parameters are serialized to SDP.
1048 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1049 // the SessionDescription, it is necessary to do that here to in order to
1050 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1051 // https://code.google.com/p/webrtc/issues/detail?id=1356
1052 std::string sdp;
1053 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001054 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001055 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001056 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1058 }
1059
1060 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001061 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001062 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063
1064 std::string sdp;
1065 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001067 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001068 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1070 }
1071
1072 void CreateOfferReceiveAnswer() {
1073 CreateOfferAsLocalDescription();
1074 std::string sdp;
1075 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1076 CreateAnswerAsRemoteDescription(sdp);
1077 }
1078
1079 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001080 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001081 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1083 // audio codec change, even if the parameter has nothing to do with
1084 // receiving. Not all parameters are serialized to SDP.
1085 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1086 // the SessionDescription, it is necessary to do that here to in order to
1087 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1088 // https://code.google.com/p/webrtc/issues/detail?id=1356
1089 std::string sdp;
1090 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001091 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001092 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093
Steve Antondb45ca82017-09-11 18:27:34 -07001094 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001096 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001097 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 }
1099
deadbeefab9b2d12015-10-14 11:33:11 -07001100 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001101 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001102 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001103 ASSERT_TRUE(answer);
1104 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1106 }
1107
deadbeefab9b2d12015-10-14 11:33:11 -07001108 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001109 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001110 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001111 ASSERT_TRUE(pr_answer);
1112 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001114 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001115 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001116 ASSERT_TRUE(answer);
1117 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1119 }
1120
Seth Hampson845e8782018-03-02 11:34:10 -08001121 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001122 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001123 // called with the given stream id and expected number of tracks.
1124 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001125 int expected_num_tracks) {
1126 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001127 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001128 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001129 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 }
1131
1132 // Creates an offer and applies it as a local session description.
1133 // Creates an answer with the same SDP an the offer but removes all lines
1134 // that start with a:ssrc"
1135 void CreateOfferReceiveAnswerWithoutSsrc() {
1136 CreateOfferAsLocalDescription();
1137 std::string sdp;
1138 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1139 SetSsrcToZero(&sdp);
1140 CreateAnswerAsRemoteDescription(sdp);
1141 }
1142
deadbeefab9b2d12015-10-14 11:33:11 -07001143 // This function creates a MediaStream with label kStreams[0] and
1144 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1145 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001146 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001147 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001148 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001149 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1150 size_t number_of_video_tracks) {
1151 EXPECT_LE(number_of_audio_tracks, 2u);
1152 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001153
1154 reference_collection_ = StreamCollection::Create();
1155 std::string sdp_ms1 = std::string(kSdpStringInit);
1156
Seth Hampson845e8782018-03-02 11:34:10 -08001157 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001158
1159 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001160 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001161 reference_collection_->AddStream(stream);
1162
1163 if (number_of_audio_tracks > 0) {
1164 sdp_ms1 += std::string(kSdpStringAudio);
1165 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1166 AddAudioTrack(kAudioTracks[0], stream);
1167 }
1168 if (number_of_audio_tracks > 1) {
1169 sdp_ms1 += kSdpStringMs1Audio1;
1170 AddAudioTrack(kAudioTracks[1], stream);
1171 }
1172
1173 if (number_of_video_tracks > 0) {
1174 sdp_ms1 += std::string(kSdpStringVideo);
1175 sdp_ms1 += std::string(kSdpStringMs1Video0);
1176 AddVideoTrack(kVideoTracks[0], stream);
1177 }
1178 if (number_of_video_tracks > 1) {
1179 sdp_ms1 += kSdpStringMs1Video1;
1180 AddVideoTrack(kVideoTracks[1], stream);
1181 }
1182
kwibergd1fe2812016-04-27 06:47:29 -07001183 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001184 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001185 }
1186
1187 void AddAudioTrack(const std::string& track_id,
1188 MediaStreamInterface* stream) {
1189 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1190 webrtc::AudioTrack::Create(track_id, nullptr));
1191 ASSERT_TRUE(stream->AddTrack(audio_track));
1192 }
1193
1194 void AddVideoTrack(const std::string& track_id,
1195 MediaStreamInterface* stream) {
1196 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001197 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001198 webrtc::FakeVideoTrackSource::Create(),
1199 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001200 ASSERT_TRUE(stream->AddTrack(video_track));
1201 }
1202
Steve Anton36da6ff2018-02-16 16:04:20 -08001203 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001204 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001205 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001206 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001207 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1208 return offer;
1209 }
1210
Steve Anton36da6ff2018-02-16 16:04:20 -08001211 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1212 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001213 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001214 std::unique_ptr<SessionDescriptionInterface> offer;
1215 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1216 return offer;
1217 }
1218
1219 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1220 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1221 std::unique_ptr<SessionDescriptionInterface> answer;
1222 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1223 return answer;
1224 }
1225
kwibergfd8be342016-05-14 19:44:11 -07001226 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001227 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001228 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001229 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001230 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1231 return answer;
1232 }
1233
1234 const std::string& GetFirstAudioStreamCname(
1235 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001236 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001237 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001238 return audio_desc->streams()[0].cname;
1239 }
1240
zhihuang1c378ed2017-08-17 14:10:50 -07001241 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1242 const RTCOfferAnswerOptions& offer_answer_options) {
1243 RTC_DCHECK(pc_);
1244 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1245 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1246 pc_->CreateOffer(observer, offer_answer_options);
1247 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1248 return observer->MoveDescription();
1249 }
1250
1251 void CreateOfferWithOptionsAsRemoteDescription(
1252 std::unique_ptr<SessionDescriptionInterface>* desc,
1253 const RTCOfferAnswerOptions& offer_answer_options) {
1254 *desc = CreateOfferWithOptions(offer_answer_options);
1255 ASSERT_TRUE(desc != nullptr);
1256 std::string sdp;
1257 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001258 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001259 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001260 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001261 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1262 }
1263
1264 void CreateOfferWithOptionsAsLocalDescription(
1265 std::unique_ptr<SessionDescriptionInterface>* desc,
1266 const RTCOfferAnswerOptions& offer_answer_options) {
1267 *desc = CreateOfferWithOptions(offer_answer_options);
1268 ASSERT_TRUE(desc != nullptr);
1269 std::string sdp;
1270 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001271 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001272 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001273
Steve Antondb45ca82017-09-11 18:27:34 -07001274 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001275 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1276 }
1277
1278 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001279 RTC_DCHECK(content);
1280 RTC_DCHECK(content->media_description());
1281 for (const cricket::AudioCodec& codec :
1282 content->media_description()->as_audio()->codecs()) {
1283 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001284 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001285 }
zhihuang1c378ed2017-08-17 14:10:50 -07001286 }
1287 return false;
1288 }
1289
Steve Anton36da6ff2018-02-16 16:04:20 -08001290 const char* GetSdpStringWithStream1() const {
1291 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1292 return kSdpStringWithStream1PlanB;
1293 } else {
1294 return kSdpStringWithStream1UnifiedPlan;
1295 }
1296 }
1297
1298 const char* GetSdpStringWithStream1And2() const {
1299 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1300 return kSdpStringWithStream1And2PlanB;
1301 } else {
1302 return kSdpStringWithStream1And2UnifiedPlan;
1303 }
1304 }
1305
deadbeef9a6f4d42017-05-15 19:43:33 -07001306 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1307 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001308 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001309 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001310 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001311 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1312 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1313 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001315 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001316 const SdpSemantics sdp_semantics_;
1317};
1318
1319class PeerConnectionInterfaceTest
1320 : public PeerConnectionInterfaceBaseTest,
1321 public ::testing::WithParamInterface<SdpSemantics> {
1322 protected:
1323 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1324};
1325
1326class PeerConnectionInterfaceTestPlanB
1327 : public PeerConnectionInterfaceBaseTest {
1328 protected:
1329 PeerConnectionInterfaceTestPlanB()
1330 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331};
1332
zhihuang8f65cdf2016-05-06 18:40:30 -07001333// Generate different CNAMEs when PeerConnections are created.
1334// The CNAMEs are expected to be generated randomly. It is possible
1335// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001336TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001337 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001338 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001339 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001340 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001341 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1342 GetFirstAudioStreamCname(offer2.get()));
1343}
1344
Steve Anton36da6ff2018-02-16 16:04:20 -08001345TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001346 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001347 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001348 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001349 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001350 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1351 GetFirstAudioStreamCname(answer2.get()));
1352}
1353
Steve Anton36da6ff2018-02-16 16:04:20 -08001354TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 CreatePeerConnectionWithDifferentConfigurations) {
1356 CreatePeerConnectionWithDifferentConfigurations();
1357}
1358
Steve Anton36da6ff2018-02-16 16:04:20 -08001359TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001360 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1361 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1362 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1363 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1364 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1365 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1366 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1367 port_allocator_->candidate_filter());
1368 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1369 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1370}
1371
1372// Test that when a PeerConnection is created with a nonzero candidate pool
1373// size, the pooled PortAllocatorSession is created with all the attributes
1374// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001375TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001376 PeerConnectionInterface::RTCConfiguration config;
1377 PeerConnectionInterface::IceServer server;
1378 server.uri = kStunAddressOnly;
1379 config.servers.push_back(server);
1380 config.type = PeerConnectionInterface::kRelay;
1381 config.disable_ipv6 = true;
1382 config.tcp_candidate_policy =
1383 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001384 config.candidate_network_policy =
1385 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001386 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001387 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001388
1389 const cricket::FakePortAllocatorSession* session =
1390 static_cast<const cricket::FakePortAllocatorSession*>(
1391 port_allocator_->GetPooledSession());
1392 ASSERT_NE(nullptr, session);
1393 EXPECT_EQ(1UL, session->stun_servers().size());
1394 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1395 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001396 EXPECT_LT(0U,
1397 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001398}
1399
deadbeefd21eab32017-07-26 16:50:11 -07001400// Test that network-related RTCConfiguration members are applied to the
1401// PortAllocator when CreatePeerConnection is called. Specifically:
1402// - disable_ipv6_on_wifi
1403// - max_ipv6_networks
1404// - tcp_candidate_policy
1405// - candidate_network_policy
1406// - prune_turn_ports
1407//
1408// Note that the candidate filter (RTCConfiguration::type) is already tested
1409// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001410TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001411 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1412 // Create fake port allocator.
1413 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1414 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1415 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1416
1417 // Create RTCConfiguration with some network-related fields relevant to
1418 // PortAllocator populated.
1419 PeerConnectionInterface::RTCConfiguration config;
1420 config.disable_ipv6_on_wifi = true;
1421 config.max_ipv6_networks = 10;
1422 config.tcp_candidate_policy =
1423 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1424 config.candidate_network_policy =
1425 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1426 config.prune_turn_ports = true;
1427
1428 // Create the PC factory and PC with the above config.
1429 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1430 webrtc::CreatePeerConnectionFactory(
1431 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001432 rtc::Thread::Current(), fake_audio_capture_module_,
1433 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001434 webrtc::CreateBuiltinAudioDecoderFactory(),
1435 webrtc::CreateBuiltinVideoEncoderFactory(),
1436 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1437 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001438 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001439 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1440 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001441 EXPECT_TRUE(pc.get());
1442 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001443
1444 // Now validate that the config fields set above were applied to the
1445 // PortAllocator, as flags or otherwise.
1446 EXPECT_FALSE(raw_port_allocator->flags() &
1447 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1448 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1449 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1450 EXPECT_TRUE(raw_port_allocator->flags() &
1451 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1452 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1453}
1454
deadbeef46c73892016-11-16 19:42:04 -08001455// Check that GetConfiguration returns the configuration the PeerConnection was
1456// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001457TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001458 PeerConnectionInterface::RTCConfiguration config;
1459 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001460 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001461
1462 PeerConnectionInterface::RTCConfiguration returned_config =
1463 pc_->GetConfiguration();
1464 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1465}
1466
1467// Check that GetConfiguration returns the last configuration passed into
1468// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001469TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001470 PeerConnectionInterface::RTCConfiguration starting_config;
1471 starting_config.bundle_policy =
1472 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1473 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001474
Steve Anton36da6ff2018-02-16 16:04:20 -08001475 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001476 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001477 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001478 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001479 EXPECT_TRUE(pc_->SetConfiguration(config));
1480
1481 PeerConnectionInterface::RTCConfiguration returned_config =
1482 pc_->GetConfiguration();
1483 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001484 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001485 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001486}
1487
Steve Antonc79268f2018-04-24 09:54:10 -07001488TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1489 CreatePeerConnection();
1490
1491 pc_->Close();
1492
1493 EXPECT_FALSE(
1494 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1495}
1496
Steve Anton36da6ff2018-02-16 16:04:20 -08001497TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001498 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001499 AddVideoStream(kStreamId1);
1500 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 ASSERT_EQ(2u, pc_->local_streams()->count());
1502
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001503 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001504 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001505 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001506 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001507 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001508 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001510 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001511 EXPECT_EQ(3u, pc_->local_streams()->count());
1512
1513 // Remove the third stream.
1514 pc_->RemoveStream(pc_->local_streams()->at(2));
1515 EXPECT_EQ(2u, pc_->local_streams()->count());
1516
1517 // Remove the second stream.
1518 pc_->RemoveStream(pc_->local_streams()->at(1));
1519 EXPECT_EQ(1u, pc_->local_streams()->count());
1520
1521 // Remove the first stream.
1522 pc_->RemoveStream(pc_->local_streams()->at(0));
1523 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524}
1525
deadbeefab9b2d12015-10-14 11:33:11 -07001526// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001527// Don't run under Unified Plan since the stream API is not available.
1528TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001529 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001530 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001531 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001532 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001533
deadbeefab9b2d12015-10-14 11:33:11 -07001534 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001535 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001536 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001537
deadbeefab9b2d12015-10-14 11:33:11 -07001538 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001539 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001540 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001541
1542 // Add another stream and ensure the offer includes both the old and new
1543 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001544 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001545 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001546
Steve Antonb1c1de12017-12-21 15:14:30 -08001547 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001548 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1549 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001550
Steve Antonb1c1de12017-12-21 15:14:30 -08001551 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001552 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1553 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001554}
1555
Steve Anton36da6ff2018-02-16 16:04:20 -08001556// Don't run under Unified Plan since the stream API is not available.
1557TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001558 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001559 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 ASSERT_EQ(1u, pc_->local_streams()->count());
1561 pc_->RemoveStream(pc_->local_streams()->at(0));
1562 EXPECT_EQ(0u, pc_->local_streams()->count());
1563}
1564
deadbeefe1f9d832016-01-14 15:35:42 -08001565// Test for AddTrack and RemoveTrack methods.
1566// Tests that the created offer includes tracks we added,
1567// and that the RtpSenders are created correctly.
1568// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001569// Only tested with Plan B since Unified Plan is covered in more detail by tests
1570// in peerconnection_jsep_unittests.cc
1571TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001572 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001573 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001574 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001575 rtc::scoped_refptr<VideoTrackInterface> video_track(
1576 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001577 "video_track", pc_factory_->CreateVideoSource(
1578 std::unique_ptr<cricket::VideoCapturer>(
1579 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001580 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1581 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001582 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001583 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001584 EXPECT_EQ("audio_track", audio_sender->id());
1585 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001586 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001587 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001588 EXPECT_EQ("video_track", video_sender->id());
1589 EXPECT_EQ(video_track, video_sender->track());
1590
1591 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001592 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001593 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001594
1595 const cricket::ContentInfo* audio_content =
1596 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001597 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001598 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001599
1600 const cricket::ContentInfo* video_content =
1601 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001602 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001603 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001604
Steve Antondb45ca82017-09-11 18:27:34 -07001605 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001606
1607 // Now try removing the tracks.
1608 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1609 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1610
1611 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001612 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001613
1614 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001615 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001616 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001617
1618 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001619 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001620 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001621
Steve Antondb45ca82017-09-11 18:27:34 -07001622 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001623
1624 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1625 // should return false.
1626 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1627 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1628}
1629
1630// Test creating senders without a stream specified,
1631// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001632TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001633 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001634 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001635 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001636 rtc::scoped_refptr<VideoTrackInterface> video_track(
1637 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001638 "video_track", pc_factory_->CreateVideoSource(
1639 std::unique_ptr<cricket::VideoCapturer>(
1640 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001641 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001642 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001643 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001644 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001645 EXPECT_EQ("audio_track", audio_sender->id());
1646 EXPECT_EQ(audio_track, audio_sender->track());
1647 EXPECT_EQ("video_track", video_sender->id());
1648 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001649 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1650 // If the ID is truly a random GUID, it should be infinitely unlikely they
1651 // will be the same.
1652 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1653 } else {
1654 // We allows creating tracks without stream ids under Unified Plan
1655 // semantics.
1656 EXPECT_EQ(0u, video_sender->stream_ids().size());
1657 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1658 }
deadbeefe1f9d832016-01-14 15:35:42 -08001659}
1660
Harald Alvestrand89061872018-01-02 14:08:34 +01001661// Test that we can call GetStats() after AddTrack but before connecting
1662// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001663TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001664 CreatePeerConnectionWithoutDtls();
1665 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1666 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1667 rtc::scoped_refptr<VideoTrackInterface> video_track(
1668 pc_factory_->CreateVideoTrack(
1669 "video_track", pc_factory_->CreateVideoSource(
1670 std::unique_ptr<cricket::VideoCapturer>(
1671 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001672 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1673 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001674 EXPECT_TRUE(DoGetStats(nullptr));
1675}
1676
Steve Anton36da6ff2018-02-16 16:04:20 -08001677TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001678 CreatePeerConnectionWithoutDtls();
1679 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1680 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1681 rtc::scoped_refptr<VideoTrackInterface> video_track(
1682 pc_factory_->CreateVideoTrack(
1683 "video_track", pc_factory_->CreateVideoSource(
1684 std::unique_ptr<cricket::VideoCapturer>(
1685 new cricket::FakeVideoCapturer()))));
1686 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001687 ASSERT_TRUE(audio_sender.ok());
1688 auto* audio_sender_proxy =
1689 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1690 audio_sender.value().get());
1691 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1692
Harald Alvestrandc72af932018-01-11 17:18:19 +01001693 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001694 ASSERT_TRUE(video_sender.ok());
1695 auto* video_sender_proxy =
1696 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1697 video_sender.value().get());
1698 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001699}
1700
Steve Anton36da6ff2018-02-16 16:04:20 -08001701// Don't run under Unified Plan since the stream API is not available.
1702TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001703 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001704 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001705 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001706 ASSERT_EQ(1u, senders.size());
1707 auto* sender_proxy =
1708 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1709 senders[0].get());
1710 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001711}
1712
Steve Anton36da6ff2018-02-16 16:04:20 -08001713TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001715 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 VerifyRemoteRtpHeaderExtensions();
1717}
1718
Steve Anton36da6ff2018-02-16 16:04:20 -08001719TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001720 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001721 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 CreateOfferAsLocalDescription();
1723 std::string offer;
1724 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1725 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001726 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727}
1728
Steve Anton36da6ff2018-02-16 16:04:20 -08001729TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001730 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001731 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732
1733 CreateOfferAsRemoteDescription();
1734 CreateAnswerAsLocalDescription();
1735
Seth Hampson845e8782018-03-02 11:34:10 -08001736 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737}
1738
Steve Anton36da6ff2018-02-16 16:04:20 -08001739TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001740 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001741 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742
1743 CreateOfferAsRemoteDescription();
1744 CreatePrAnswerAsLocalDescription();
1745 CreateAnswerAsLocalDescription();
1746
Seth Hampson845e8782018-03-02 11:34:10 -08001747 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748}
1749
Steve Anton36da6ff2018-02-16 16:04:20 -08001750// Don't run under Unified Plan since the stream API is not available.
1751TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 InitiateCall();
1753 ASSERT_EQ(1u, pc_->remote_streams()->count());
1754 pc_->RemoveStream(pc_->local_streams()->at(0));
1755 CreateOfferReceiveAnswer();
1756 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001757 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 CreateOfferReceiveAnswer();
1759}
1760
1761// Tests that after negotiating an audio only call, the respondent can perform a
1762// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001763TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001764 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001765 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 CreateOfferAsRemoteDescription();
1767 CreateAnswerAsLocalDescription();
1768
1769 ASSERT_EQ(1u, pc_->remote_streams()->count());
1770 pc_->RemoveStream(pc_->local_streams()->at(0));
1771 CreateOfferReceiveAnswer();
1772 EXPECT_EQ(0u, pc_->remote_streams()->count());
1773}
1774
1775// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001776TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001777 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778
Steve Antonf1c6db12017-10-13 11:13:35 -07001779 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001781 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001782 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001783 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001784 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785
1786 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001787 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001788 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001789 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790
Steve Antonf1c6db12017-10-13 11:13:35 -07001791 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001792 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793
Steve Antonf1c6db12017-10-13 11:13:35 -07001794 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795}
1796
deadbeefab9b2d12015-10-14 11:33:11 -07001797// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001799TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001800 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001802 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001803 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001804 EXPECT_TRUE(offer);
1805 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806
1807 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001808 AddAudioTrack("track_label", {kStreamId1});
1809 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810
1811 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001812 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813
1814 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001815 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001816 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817}
1818
1819// Test that we will get different SSRCs for each tracks in the offer and answer
1820// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001821TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001822 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001824 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1825 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826
1827 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001828 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001829 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 int audio_ssrc = 0;
1831 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001832 EXPECT_TRUE(
1833 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1834 EXPECT_TRUE(
1835 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 EXPECT_NE(audio_ssrc, video_ssrc);
1837
1838 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001839 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001840 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001841 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 audio_ssrc = 0;
1843 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001844 EXPECT_TRUE(
1845 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1846 EXPECT_TRUE(
1847 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 EXPECT_NE(audio_ssrc, video_ssrc);
1849}
1850
deadbeefeb459812015-12-15 19:24:43 -08001851// Test that it's possible to call AddTrack on a MediaStream after adding
1852// the stream to a PeerConnection.
1853// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001854// Don't run under Unified Plan since the stream API is not available.
1855TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001856 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001857 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001858 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001859 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1860
1861 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001862 rtc::scoped_refptr<VideoTrackInterface> video_track(
1863 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001864 "video_label", pc_factory_->CreateVideoSource(
1865 std::unique_ptr<cricket::VideoCapturer>(
1866 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001867 stream->AddTrack(video_track.get());
1868
kwibergd1fe2812016-04-27 06:47:29 -07001869 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001870 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001871
1872 const cricket::MediaContentDescription* video_desc =
1873 cricket::GetFirstVideoContentDescription(offer->description());
1874 EXPECT_TRUE(video_desc != nullptr);
1875}
1876
1877// Test that it's possible to call RemoveTrack on a MediaStream after adding
1878// the stream to a PeerConnection.
1879// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001880// Don't run under Unified Plan since the stream API is not available.
1881TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001882 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001883 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001884 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001885 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1886
1887 // Remove the video track.
1888 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1889
kwibergd1fe2812016-04-27 06:47:29 -07001890 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001891 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001892
1893 const cricket::MediaContentDescription* video_desc =
1894 cricket::GetFirstVideoContentDescription(offer->description());
1895 EXPECT_TRUE(video_desc == nullptr);
1896}
1897
deadbeefbd7d8f72015-12-18 16:58:44 -08001898// Test creating a sender with a stream ID, and ensure the ID is populated
1899// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001900// Don't run under Unified Plan since the stream API is not available.
1901TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001902 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001903 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001904
kwibergd1fe2812016-04-27 06:47:29 -07001905 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001906 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001907
1908 const cricket::MediaContentDescription* video_desc =
1909 cricket::GetFirstVideoContentDescription(offer->description());
1910 ASSERT_TRUE(video_desc != nullptr);
1911 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001912 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001913}
1914
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001916TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001918 ASSERT_LT(0u, pc_->GetSenders().size());
1919 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001920 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001921 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 EXPECT_TRUE(DoGetStats(remote_audio));
1923
1924 // Remove the stream. Since we are sending to our selves the local
1925 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001926 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 // Do a re-negotiation.
1928 CreateOfferReceiveAnswer();
1929
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 // Test that we still can get statistics for the old track. Even if it is not
1931 // sent any longer.
1932 EXPECT_TRUE(DoGetStats(remote_audio));
1933}
1934
1935// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001936TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001938 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1939 ASSERT_TRUE(video_receiver);
1940 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941}
1942
1943// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001944TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001946 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 pc_factory_->CreateAudioTrack("unknown track", NULL));
1948 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1949}
1950
Steve Anton36da6ff2018-02-16 16:04:20 -08001951TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001952 CreatePeerConnectionWithoutDtls();
1953 EXPECT_TRUE(DoGetRTCStats());
1954 // Clearing stats cache is needed now, but should be temporary.
1955 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1956 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001957 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1958 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001959 EXPECT_TRUE(DoGetRTCStats());
1960 pc_->ClearStatsCache();
1961 CreateOfferReceiveAnswer();
1962 EXPECT_TRUE(DoGetRTCStats());
1963}
1964
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001966TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001967 RTCConfiguration config;
1968 config.enable_rtp_data_channel = true;
1969 config.enable_dtls_srtp = false;
1970 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001971 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001973 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 pc_->CreateDataChannel("test2", NULL);
1975 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001976 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001978 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 new MockDataChannelObserver(data2));
1980
1981 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1982 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1983 std::string data_to_send1 = "testing testing";
1984 std::string data_to_send2 = "testing something else";
1985 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1986
1987 CreateOfferReceiveAnswer();
1988 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1989 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1990
1991 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1992 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1993 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1994 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1995
1996 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1997 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1998
1999 data1->Close();
2000 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2001 CreateOfferReceiveAnswer();
2002 EXPECT_FALSE(observer1->IsOpen());
2003 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2004 EXPECT_TRUE(observer2->IsOpen());
2005
2006 data_to_send2 = "testing something else again";
2007 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
2008
2009 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
2010}
2011
2012// This test verifies that sendnig binary data over RTP data channels should
2013// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002014TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002015 RTCConfiguration config;
2016 config.enable_rtp_data_channel = true;
2017 config.enable_dtls_srtp = false;
2018 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002019 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002021 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 pc_->CreateDataChannel("test2", NULL);
2023 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002024 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002026 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 new MockDataChannelObserver(data2));
2028
2029 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
2030 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
2031
2032 CreateOfferReceiveAnswer();
2033 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2034 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2035
2036 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2037 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2038
jbaucheec21bd2016-03-20 06:15:43 -07002039 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2041}
2042
2043// This test setup a RTP data channels in loop back and test that a channel is
2044// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002045TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002046 RTCConfiguration config;
2047 config.enable_rtp_data_channel = true;
2048 config.enable_dtls_srtp = false;
2049 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002050 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002052 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 new MockDataChannelObserver(data1));
2054
2055 CreateOfferReceiveAnswerWithoutSsrc();
2056
2057 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2058
2059 data1->Close();
2060 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2061 CreateOfferReceiveAnswerWithoutSsrc();
2062 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2063 EXPECT_FALSE(observer1->IsOpen());
2064}
2065
2066// This test that if a data channel is added in an answer a receive only channel
2067// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002068TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002069 RTCConfiguration config;
2070 config.enable_rtp_data_channel = true;
2071 config.enable_dtls_srtp = false;
2072
2073 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
2075 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002076 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 pc_->CreateDataChannel(offer_label, NULL);
2078
2079 CreateOfferAsLocalDescription();
2080
2081 // Replace the data channel label in the offer and apply it as an answer.
2082 std::string receive_label = "answer_channel";
2083 std::string sdp;
2084 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002085 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002086 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 CreateAnswerAsRemoteDescription(sdp);
2088
2089 // Verify that a new incoming data channel has been created and that
2090 // it is open but can't we written to.
2091 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2092 DataChannelInterface* received_channel = observer_.last_datachannel_;
2093 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2094 EXPECT_EQ(receive_label, received_channel->label());
2095 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2096
2097 // Verify that the channel we initially offered has been rejected.
2098 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2099
2100 // Do another offer / answer exchange and verify that the data channel is
2101 // opened.
2102 CreateOfferReceiveAnswer();
2103 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2104 kTimeout);
2105}
2106
2107// This test that no data channel is returned if a reliable channel is
2108// requested.
2109// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002110TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002111 RTCConfiguration rtc_config;
2112 rtc_config.enable_rtp_data_channel = true;
2113 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 std::string label = "test";
2116 webrtc::DataChannelInit config;
2117 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002118 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 pc_->CreateDataChannel(label, &config);
2120 EXPECT_TRUE(channel == NULL);
2121}
2122
deadbeefab9b2d12015-10-14 11:33:11 -07002123// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002124TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002125 RTCConfiguration config;
2126 config.enable_rtp_data_channel = true;
2127 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002128
2129 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002130 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002131 pc_->CreateDataChannel(label, nullptr);
2132 EXPECT_NE(channel, nullptr);
2133
zhihuang9763d562016-08-05 11:14:50 -07002134 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002135 pc_->CreateDataChannel(label, nullptr);
2136 EXPECT_EQ(dup_channel, nullptr);
2137}
2138
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139// This tests that a SCTP data channel is returned using different
2140// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002141TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002142 RTCConfiguration rtc_config;
2143 rtc_config.enable_dtls_srtp = true;
2144 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145
2146 webrtc::DataChannelInit config;
2147
zhihuang9763d562016-08-05 11:14:50 -07002148 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 pc_->CreateDataChannel("1", &config);
2150 EXPECT_TRUE(channel != NULL);
2151 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002152 EXPECT_TRUE(observer_.renegotiation_needed_);
2153 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154
2155 config.ordered = false;
2156 channel = pc_->CreateDataChannel("2", &config);
2157 EXPECT_TRUE(channel != NULL);
2158 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002159 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160
2161 config.ordered = true;
2162 config.maxRetransmits = 0;
2163 channel = pc_->CreateDataChannel("3", &config);
2164 EXPECT_TRUE(channel != NULL);
2165 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002166 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167
2168 config.maxRetransmits = -1;
2169 config.maxRetransmitTime = 0;
2170 channel = pc_->CreateDataChannel("4", &config);
2171 EXPECT_TRUE(channel != NULL);
2172 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002173 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174}
2175
2176// This tests that no data channel is returned if both maxRetransmits and
2177// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002178TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002180 RTCConfiguration rtc_config;
2181 rtc_config.enable_dtls_srtp = true;
2182 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183
2184 std::string label = "test";
2185 webrtc::DataChannelInit config;
2186 config.maxRetransmits = 0;
2187 config.maxRetransmitTime = 0;
2188
zhihuang9763d562016-08-05 11:14:50 -07002189 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 pc_->CreateDataChannel(label, &config);
2191 EXPECT_TRUE(channel == NULL);
2192}
2193
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194// The test verifies that creating a SCTP data channel with an id already in use
2195// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002196TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002198 RTCConfiguration rtc_config;
2199 rtc_config.enable_dtls_srtp = true;
2200 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201
2202 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002203 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002205 config.id = 1;
2206 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 EXPECT_TRUE(channel != NULL);
2208 EXPECT_EQ(1, channel->id());
2209
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 channel = pc_->CreateDataChannel("x", &config);
2211 EXPECT_TRUE(channel == NULL);
2212
2213 config.id = cricket::kMaxSctpSid;
2214 channel = pc_->CreateDataChannel("max", &config);
2215 EXPECT_TRUE(channel != NULL);
2216 EXPECT_EQ(config.id, channel->id());
2217
2218 config.id = cricket::kMaxSctpSid + 1;
2219 channel = pc_->CreateDataChannel("x", &config);
2220 EXPECT_TRUE(channel == NULL);
2221}
2222
deadbeefab9b2d12015-10-14 11:33:11 -07002223// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002224TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002225 RTCConfiguration rtc_config;
2226 rtc_config.enable_dtls_srtp = true;
2227 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002228
2229 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002230 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002231 pc_->CreateDataChannel(label, nullptr);
2232 EXPECT_NE(channel, nullptr);
2233
zhihuang9763d562016-08-05 11:14:50 -07002234 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002235 pc_->CreateDataChannel(label, nullptr);
2236 EXPECT_NE(dup_channel, nullptr);
2237}
2238
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002239// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2240// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002241TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002242 RTCConfiguration rtc_config;
2243 rtc_config.enable_rtp_data_channel = true;
2244 rtc_config.enable_dtls_srtp = false;
2245 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002246
zhihuang9763d562016-08-05 11:14:50 -07002247 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002248 pc_->CreateDataChannel("test1", NULL);
2249 EXPECT_TRUE(observer_.renegotiation_needed_);
2250 observer_.renegotiation_needed_ = false;
2251
zhihuang9763d562016-08-05 11:14:50 -07002252 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002253 pc_->CreateDataChannel("test2", NULL);
2254 EXPECT_TRUE(observer_.renegotiation_needed_);
2255}
2256
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002258TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002259 RTCConfiguration rtc_config;
2260 rtc_config.enable_rtp_data_channel = true;
2261 rtc_config.enable_dtls_srtp = false;
2262 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263
zhihuang9763d562016-08-05 11:14:50 -07002264 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002266 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 pc_->CreateDataChannel("test2", NULL);
2268 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002269 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002271 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 new MockDataChannelObserver(data2));
2273
2274 CreateOfferReceiveAnswer();
2275 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2276 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2277
2278 ReleasePeerConnection();
2279 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2280 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2281}
2282
Zhi Huang644fde42018-04-02 19:16:26 -07002283// This tests that RTP data channels can be rejected in an answer.
2284TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002285 RTCConfiguration rtc_config;
2286 rtc_config.enable_rtp_data_channel = true;
2287 rtc_config.enable_dtls_srtp = false;
2288 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
zhihuang9763d562016-08-05 11:14:50 -07002290 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 pc_->CreateDataChannel("offer_channel", NULL));
2292
2293 CreateOfferAsLocalDescription();
2294
2295 // Create an answer where the m-line for data channels are rejected.
2296 std::string sdp;
2297 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002298 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002299 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002300 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002302 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 data_info->rejected = true;
2304
Steve Antondb45ca82017-09-11 18:27:34 -07002305 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2307}
2308
Zhi Huang644fde42018-04-02 19:16:26 -07002309#ifdef HAVE_SCTP
2310// This tests that SCTP data channels can be rejected in an answer.
2311TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2312#else
2313TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2314#endif
2315{
Niels Möllerf06f9232018-08-07 12:32:18 +02002316 RTCConfiguration rtc_config;
2317 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002318
2319 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2320 pc_->CreateDataChannel("offer_channel", NULL));
2321
2322 CreateOfferAsLocalDescription();
2323
2324 // Create an answer where the m-line for data channels are rejected.
2325 std::string sdp;
2326 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2327 std::unique_ptr<SessionDescriptionInterface> answer(
2328 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2329 ASSERT_TRUE(answer);
2330 cricket::ContentInfo* data_info =
2331 cricket::GetFirstDataContent(answer->description());
2332 data_info->rejected = true;
2333
2334 DoSetRemoteDescription(std::move(answer));
2335 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2336}
2337
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338// Test that we can create a session description from an SDP string from
2339// FireFox, use it as a remote session description, generate an answer and use
2340// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002341TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002342 RTCConfiguration rtc_config;
2343 rtc_config.enable_dtls_srtp = true;
2344 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002345 AddAudioTrack("audio_label");
2346 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002347 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002348 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002349 webrtc::kFireFoxSdpOffer, nullptr));
2350 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 CreateAnswerAsLocalDescription();
2352 ASSERT_TRUE(pc_->local_description() != NULL);
2353 ASSERT_TRUE(pc_->remote_description() != NULL);
2354
2355 const cricket::ContentInfo* content =
2356 cricket::GetFirstAudioContent(pc_->local_description()->description());
2357 ASSERT_TRUE(content != NULL);
2358 EXPECT_FALSE(content->rejected);
2359
2360 content =
2361 cricket::GetFirstVideoContent(pc_->local_description()->description());
2362 ASSERT_TRUE(content != NULL);
2363 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002364#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 content =
2366 cricket::GetFirstDataContent(pc_->local_description()->description());
2367 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002368 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002369#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370}
2371
zhihuangb19012e2017-09-19 13:47:59 -07002372// Test that fallback from DTLS to SDES is not supported.
2373// The fallback was previously supported but was removed to simplify the code
2374// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002375TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002376 RTCConfiguration rtc_config;
2377 rtc_config.enable_dtls_srtp = true;
2378 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002379 // Wait for fake certificate to be generated. Previously, this is what caused
2380 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002381 AddAudioTrack("audio_label");
2382 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002383 ASSERT_NE(nullptr, fake_certificate_generator_);
2384 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2385 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002386 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002387 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2388 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002389 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002390}
2391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392// Test that we can create an audio only offer and receive an answer with a
2393// limited set of audio codecs and receive an updated offer with more audio
2394// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002395TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002396 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002397 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 CreateOfferAsLocalDescription();
2399
Steve Anton36da6ff2018-02-16 16:04:20 -08002400 const char* answer_sdp =
2401 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2402 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002403 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002404 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002405 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406
Steve Anton36da6ff2018-02-16 16:04:20 -08002407 const char* reoffer_sdp =
2408 (sdp_semantics_ == SdpSemantics::kPlanB
2409 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2410 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002411 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002412 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002413 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 CreateAnswerAsLocalDescription();
2415}
2416
deadbeefc80741f2015-10-22 13:14:45 -07002417// Test that if we're receiving (but not sending) a track, subsequent offers
2418// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002419TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002420 RTCConfiguration rtc_config;
2421 rtc_config.enable_dtls_srtp = true;
2422 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002423 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002424 CreateAnswerAsLocalDescription();
2425
2426 // At this point we should be receiving stream 1, but not sending anything.
2427 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002428 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002429 DoCreateOffer(&offer, nullptr);
2430
2431 const cricket::ContentInfo* video_content =
2432 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002433 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2434 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002435
2436 const cricket::ContentInfo* audio_content =
2437 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002438 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2439 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002440}
2441
2442// Test that if we're receiving (but not sending) a track, and the
2443// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2444// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002445TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002446 RTCConfiguration rtc_config;
2447 rtc_config.enable_dtls_srtp = true;
2448 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002449 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002450 CreateAnswerAsLocalDescription();
2451
2452 // At this point we should be receiving stream 1, but not sending anything.
2453 // A new offer would be recvonly, but we'll set the "no receive" constraints
2454 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002455 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002456 RTCOfferAnswerOptions options;
2457 options.offer_to_receive_audio = 0;
2458 options.offer_to_receive_video = 0;
2459 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002460
2461 const cricket::ContentInfo* video_content =
2462 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002463 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2464 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002465
2466 const cricket::ContentInfo* audio_content =
2467 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002468 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2469 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002470}
2471
deadbeef653b8e02015-11-11 12:55:10 -08002472// Test that we can use SetConfiguration to change the ICE servers of the
2473// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002474TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002475 CreatePeerConnection();
2476
Steve Anton36da6ff2018-02-16 16:04:20 -08002477 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002478 PeerConnectionInterface::IceServer server;
2479 server.uri = "stun:test_hostname";
2480 config.servers.push_back(server);
2481 EXPECT_TRUE(pc_->SetConfiguration(config));
2482
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002483 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2484 EXPECT_EQ("test_hostname",
2485 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002486}
2487
Steve Anton36da6ff2018-02-16 16:04:20 -08002488TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002489 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002490 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002491 config.type = PeerConnectionInterface::kRelay;
2492 EXPECT_TRUE(pc_->SetConfiguration(config));
2493 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2494}
2495
Steve Anton36da6ff2018-02-16 16:04:20 -08002496TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002497 PeerConnectionInterface::RTCConfiguration config;
2498 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002499 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002500 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002501 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2502
2503 config.prune_turn_ports = true;
2504 EXPECT_TRUE(pc_->SetConfiguration(config));
2505 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2506}
2507
skvladd1f5fda2017-02-03 16:54:05 -08002508// Test that the ice check interval can be changed. This does not verify that
2509// the setting makes it all the way to P2PTransportChannel, as that would
2510// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002511TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002512 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002513 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002514 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002515 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002516 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002517 EXPECT_TRUE(pc_->SetConfiguration(config));
2518 PeerConnectionInterface::RTCConfiguration new_config =
2519 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002520 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002521}
2522
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002523// Test that when SetConfiguration changes both the pool size and other
2524// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002525TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002526 SetConfigurationCreatesPooledSessionCorrectly) {
2527 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002528 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002529 config.ice_candidate_pool_size = 1;
2530 PeerConnectionInterface::IceServer server;
2531 server.uri = kStunAddressOnly;
2532 config.servers.push_back(server);
2533 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002534 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002535
2536 const cricket::FakePortAllocatorSession* session =
2537 static_cast<const cricket::FakePortAllocatorSession*>(
2538 port_allocator_->GetPooledSession());
2539 ASSERT_NE(nullptr, session);
2540 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002541}
2542
deadbeef293e9262017-01-11 12:28:30 -08002543// Test that after SetLocalDescription, changing the pool size is not allowed,
2544// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002545TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002546 CantChangePoolSizeAfterSetLocalDescription) {
2547 CreatePeerConnection();
2548 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002549 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002550 config.ice_candidate_pool_size = 1;
2551 EXPECT_TRUE(pc_->SetConfiguration(config));
2552
2553 // Set remote offer; can still change pool size at this point.
2554 CreateOfferAsRemoteDescription();
2555 config.ice_candidate_pool_size = 2;
2556 EXPECT_TRUE(pc_->SetConfiguration(config));
2557
2558 // Set local answer; now it's too late.
2559 CreateAnswerAsLocalDescription();
2560 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002561 RTCError error;
2562 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2563 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2564}
2565
deadbeef42a42632017-03-10 15:18:00 -08002566// Test that after setting an answer, extra pooled sessions are discarded. The
2567// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002568TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002569 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2570 CreatePeerConnection();
2571
2572 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002573 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002574 config.ice_candidate_pool_size = 4;
2575 EXPECT_TRUE(pc_->SetConfiguration(config));
2576
2577 // Do offer/answer.
2578 CreateOfferAsRemoteDescription();
2579 CreateAnswerAsLocalDescription();
2580
2581 // Expect no pooled sessions to be left.
2582 const cricket::PortAllocatorSession* session =
2583 port_allocator_->GetPooledSession();
2584 EXPECT_EQ(nullptr, session);
2585}
2586
2587// After Close is called, pooled candidates should be discarded so as to not
2588// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002589TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002590 CreatePeerConnection();
2591
Steve Anton36da6ff2018-02-16 16:04:20 -08002592 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002593 config.ice_candidate_pool_size = 3;
2594 EXPECT_TRUE(pc_->SetConfiguration(config));
2595 pc_->Close();
2596
2597 // Expect no pooled sessions to be left.
2598 const cricket::PortAllocatorSession* session =
2599 port_allocator_->GetPooledSession();
2600 EXPECT_EQ(nullptr, session);
2601}
2602
deadbeef293e9262017-01-11 12:28:30 -08002603// Test that SetConfiguration returns an invalid modification error if
2604// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002605TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002606 SetConfigurationReturnsInvalidModificationError) {
2607 PeerConnectionInterface::RTCConfiguration config;
2608 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2609 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2610 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002611 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002612
Steve Anton36da6ff2018-02-16 16:04:20 -08002613 PeerConnectionInterface::RTCConfiguration modified_config =
2614 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002615 modified_config.bundle_policy =
2616 PeerConnectionInterface::kBundlePolicyMaxBundle;
2617 RTCError error;
2618 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2619 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2620
Steve Anton36da6ff2018-02-16 16:04:20 -08002621 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002622 modified_config.rtcp_mux_policy =
2623 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2624 error.set_type(RTCErrorType::NONE);
2625 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2626 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2627
Steve Anton36da6ff2018-02-16 16:04:20 -08002628 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002629 modified_config.continual_gathering_policy =
2630 PeerConnectionInterface::GATHER_CONTINUALLY;
2631 error.set_type(RTCErrorType::NONE);
2632 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2633 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2634}
2635
2636// Test that SetConfiguration returns a range error if the candidate pool size
2637// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002638TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002639 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2640 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002641 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002642 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002643
2644 config.ice_candidate_pool_size = -1;
2645 RTCError error;
2646 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2647 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2648
2649 config.ice_candidate_pool_size = INT_MAX;
2650 error.set_type(RTCErrorType::NONE);
2651 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2652 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2653}
2654
2655// Test that SetConfiguration returns a syntax error if parsing an ICE server
2656// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002657TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002658 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2659 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002660 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002661 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002662
2663 PeerConnectionInterface::IceServer bad_server;
2664 bad_server.uri = "stunn:www.example.com";
2665 config.servers.push_back(bad_server);
2666 RTCError error;
2667 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2668 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2669}
2670
2671// Test that SetConfiguration returns an invalid parameter error if a TURN
2672// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002673TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002674 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2675 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002676 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002677 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002678
2679 PeerConnectionInterface::IceServer bad_server;
2680 bad_server.uri = "turn:www.example.com";
2681 // Missing password.
2682 bad_server.username = "foo";
2683 config.servers.push_back(bad_server);
2684 RTCError error;
2685 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2686 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002687}
2688
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689// Test that PeerConnection::Close changes the states to closed and all remote
2690// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002691TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 // Initialize a PeerConnection and negotiate local and remote session
2693 // description.
2694 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002695
2696 // With Plan B, verify the stream count. The analog with Unified Plan is the
2697 // RtpTransceiver count.
2698 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2699 ASSERT_EQ(1u, pc_->local_streams()->count());
2700 ASSERT_EQ(1u, pc_->remote_streams()->count());
2701 } else {
2702 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2703 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704
2705 pc_->Close();
2706
2707 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2708 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2709 pc_->ice_connection_state());
2710 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2711 pc_->ice_gathering_state());
2712
Steve Anton36da6ff2018-02-16 16:04:20 -08002713 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2714 EXPECT_EQ(1u, pc_->local_streams()->count());
2715 EXPECT_EQ(1u, pc_->remote_streams()->count());
2716 } else {
2717 // Verify that the RtpTransceivers are still present but all stopped.
2718 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2719 for (auto transceiver : pc_->GetTransceivers()) {
2720 EXPECT_TRUE(transceiver->stopped());
2721 }
2722 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723
Steve Anton36da6ff2018-02-16 16:04:20 -08002724 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2725 ASSERT_TRUE(audio_receiver);
2726 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2727 ASSERT_TRUE(video_receiver);
2728
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002729 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002730 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002731 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002732 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002733 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734}
2735
2736// Test that PeerConnection methods fails gracefully after
2737// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002738// Don't run under Unified Plan since the stream API is not available.
2739TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002740 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002741 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 CreateOfferAsRemoteDescription();
2743 CreateAnswerAsLocalDescription();
2744
2745 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002746 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747 pc_->local_streams()->at(0);
2748
2749 pc_->Close();
2750
2751 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002752 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2755
2756 EXPECT_TRUE(pc_->local_description() != NULL);
2757 EXPECT_TRUE(pc_->remote_description() != NULL);
2758
kwibergd1fe2812016-04-27 06:47:29 -07002759 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002760 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002761 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002762 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763
2764 std::string sdp;
2765 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002766 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002767 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002768 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769
2770 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002771 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002772 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002773 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774}
2775
2776// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002777TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778 InitiateCall();
2779 pc_->Close();
2780 DoGetStats(NULL);
2781}
deadbeefab9b2d12015-10-14 11:33:11 -07002782
2783// NOTE: The series of tests below come from what used to be
2784// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2785// setting a remote or local description has the expected effects.
2786
2787// This test verifies that the remote MediaStreams corresponding to a received
2788// SDP string is created. In this test the two separate MediaStreams are
2789// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002790TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002791 RTCConfiguration config;
2792 config.enable_dtls_srtp = true;
2793 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002794 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002795
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002796 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002797 EXPECT_TRUE(
2798 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2799 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2800 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2801
2802 // Create a session description based on another SDP with another
2803 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002804 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002805
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002806 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002807 EXPECT_TRUE(
2808 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2809}
2810
2811// This test verifies that when remote tracks are added/removed from SDP, the
2812// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002813// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2814// specific behavior.
2815TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002816 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002817 RTCConfiguration config;
2818 config.enable_dtls_srtp = true;
2819 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002820 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002821 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002822 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002823 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2824 reference_collection_));
2825
2826 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002827 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002828 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002829 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002830 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2831 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002832 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002833 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2834 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002835 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002836 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2837 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002838
2839 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002840 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002841 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002842 MockTrackObserver audio_track_observer(audio_track2);
2843 MockTrackObserver video_track_observer(video_track2);
2844
2845 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2846 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002847 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002848 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2849 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002850 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002851 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002852 audio_track2->state(), kTimeout);
2853 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2854 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002855}
2856
2857// This tests that remote tracks are ended if a local session description is set
2858// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002859TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002860 RTCConfiguration config;
2861 config.enable_dtls_srtp = true;
2862 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002863 // First create and set a remote offer, then reject its video content in our
2864 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002865 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2866 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2867 ASSERT_TRUE(audio_receiver);
2868 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2869 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002870
Steve Anton36da6ff2018-02-16 16:04:20 -08002871 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2872 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002873 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002874 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2875 video_receiver->track();
2876 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002877
kwibergd1fe2812016-04-27 06:47:29 -07002878 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002879 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002880 cricket::ContentInfo* video_info =
2881 local_answer->description()->GetContentByName("video");
2882 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002883 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002884 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2885 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002886
2887 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002888 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002889 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002890 video_info = local_offer->description()->GetContentByName("video");
2891 ASSERT_TRUE(video_info != nullptr);
2892 video_info->rejected = true;
2893 cricket::ContentInfo* audio_info =
2894 local_offer->description()->GetContentByName("audio");
2895 ASSERT_TRUE(audio_info != nullptr);
2896 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002897 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002898 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002899 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2900 kTimeout);
2901 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2902 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002903}
2904
2905// This tests that we won't crash if the remote track has been removed outside
2906// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002907// Don't run under Unified Plan since the stream API is not available.
2908TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002909 RTCConfiguration config;
2910 config.enable_dtls_srtp = true;
2911 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002912 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002913 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2914 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2915 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2916
kwibergd1fe2812016-04-27 06:47:29 -07002917 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002918 webrtc::CreateSessionDescription(SdpType::kAnswer,
2919 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002920 cricket::ContentInfo* video_info =
2921 local_answer->description()->GetContentByName("video");
2922 video_info->rejected = true;
2923 cricket::ContentInfo* audio_info =
2924 local_answer->description()->GetContentByName("audio");
2925 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002926 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002927
2928 // No crash is a pass.
2929}
2930
deadbeef5e97fb52015-10-15 12:49:08 -07002931// This tests that if a recvonly remote description is set, no remote streams
2932// will be created, even if the description contains SSRCs/MSIDs.
2933// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002934TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002935 RTCConfiguration config;
2936 config.enable_dtls_srtp = true;
2937 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002938
Steve Anton36da6ff2018-02-16 16:04:20 -08002939 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002940 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2941 strlen(kRecvonly), &recvonly_offer);
2942 CreateAndSetRemoteOffer(recvonly_offer);
2943
2944 EXPECT_EQ(0u, observer_.remote_streams()->count());
2945}
2946
deadbeefab9b2d12015-10-14 11:33:11 -07002947// This tests that a default MediaStream is created if a remote session
2948// description doesn't contain any streams and no MSID support.
2949// It also tests that the default stream is updated if a video m-line is added
2950// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002951// Don't run under Unified Plan since this behavior is Plan B specific.
2952TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002953 RTCConfiguration config;
2954 config.enable_dtls_srtp = true;
2955 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002956 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2957
2958 ASSERT_EQ(1u, observer_.remote_streams()->count());
2959 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2960
2961 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2962 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002963 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002964
2965 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2966 ASSERT_EQ(1u, observer_.remote_streams()->count());
2967 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2968 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002969 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2970 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002971 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2972 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002973 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2974 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002975}
2976
2977// This tests that a default MediaStream is created if a remote session
2978// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002979// Don't run under Unified Plan since this behavior is Plan B specific.
2980TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002981 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002982 RTCConfiguration config;
2983 config.enable_dtls_srtp = true;
2984 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002985 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2986
2987 ASSERT_EQ(1u, observer_.remote_streams()->count());
2988 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2989
2990 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2991 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002992 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002993}
2994
2995// This tests that it won't crash when PeerConnection tries to remove
2996// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002997// Don't run under Unified Plan since this behavior is Plan B specific.
2998TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002999 RTCConfiguration config;
3000 config.enable_dtls_srtp = true;
3001 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003002 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07003003 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3004 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
3005 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
3006
3007 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3008
3009 // No crash is a pass.
3010}
3011
3012// This tests that a default MediaStream is created if the remote session
3013// description doesn't contain any streams and don't contain an indication if
3014// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08003015// Don't run under Unified Plan since this behavior is Plan B specific.
3016TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003017 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003018 RTCConfiguration config;
3019 config.enable_dtls_srtp = true;
3020 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003021 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3022
3023 ASSERT_EQ(1u, observer_.remote_streams()->count());
3024 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3025 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
3026 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3027}
3028
3029// This tests that a default MediaStream is not created if the remote session
3030// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003031// Don't run under Unified Plan since this behavior is Plan B specific.
3032TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003033 RTCConfiguration config;
3034 config.enable_dtls_srtp = true;
3035 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003036 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3037 EXPECT_EQ(0u, observer_.remote_streams()->count());
3038}
3039
deadbeefbda7e0b2015-12-08 17:13:40 -08003040// This tests that when setting a new description, the old default tracks are
3041// not destroyed and recreated.
3042// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003043// Don't run under Unified Plan since this behavior is Plan B specific.
3044TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003045 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003046 RTCConfiguration config;
3047 config.enable_dtls_srtp = true;
3048 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003049 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3050
3051 ASSERT_EQ(1u, observer_.remote_streams()->count());
3052 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3053 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3054
3055 // Set the track to "disabled", then set a new description and ensure the
3056 // track is still disabled, which ensures it hasn't been recreated.
3057 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3058 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3059 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3060 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3061}
3062
deadbeefab9b2d12015-10-14 11:33:11 -07003063// This tests that a default MediaStream is not created if a remote session
3064// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003065// Don't run under Unified Plan since this behavior is Plan B specific.
3066TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003067 RTCConfiguration config;
3068 config.enable_dtls_srtp = true;
3069 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003070 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003071 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003072 EXPECT_TRUE(
3073 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3074
3075 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3076 EXPECT_EQ(0u, observer_.remote_streams()->count());
3077}
3078
Seth Hampson5897a6e2018-04-03 11:16:33 -07003079// This tests that a default MediaStream is created if a remote SDP comes from
3080// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3081TEST_F(PeerConnectionInterfaceTestPlanB,
3082 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003083 RTCConfiguration config;
3084 config.enable_dtls_srtp = true;
3085 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003086 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3087 // Add a=msid lines to simulate a Unified Plan endpoint that only
3088 // signals stream IDs with a=msid lines.
3089 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3090
3091 CreateAndSetRemoteOffer(sdp_string);
3092
3093 ASSERT_EQ(1u, observer_.remote_streams()->count());
3094 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3095 EXPECT_EQ("default", remote_stream->id());
3096 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3097}
3098
Seth Hampson5b4f0752018-04-02 16:31:36 -07003099// This tests that when a Plan B endpoint receives an SDP that signals no media
3100// stream IDs indicated by the special character "-" in the a=msid line, that
3101// a default stream ID will be used for the MediaStream ID. This can occur
3102// when a Unified Plan endpoint signals no media stream IDs, but signals both
3103// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3104TEST_F(PeerConnectionInterfaceTestPlanB,
3105 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003106 RTCConfiguration config;
3107 config.enable_dtls_srtp = true;
3108 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003109 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3110 // the sender's stream ID will be interpreted as no stream IDs.
3111 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3112 sdp_string.append("a=msid:- audiotrack0\n");
3113
3114 CreateAndSetRemoteOffer(sdp_string);
3115
3116 ASSERT_EQ(1u, observer_.remote_streams()->count());
3117 // Because SSRCs are signaled the track ID will be what was signaled in the
3118 // a=msid line.
3119 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3120 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3121 EXPECT_EQ("default", remote_stream->id());
3122 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003123
3124 // Previously a bug ocurred when setting the remote description a second time.
3125 // This is because we checked equality of the remote StreamParams stream ID
3126 // (empty), and the previously set stream ID for the remote sender
3127 // ("default"). This cause a track to be removed, then added, when really
3128 // nothing should occur because it is the same track.
3129 CreateAndSetRemoteOffer(sdp_string);
3130 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3131 EXPECT_EQ(1u, observer_.add_track_events_.size());
3132 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3133 remote_stream = observer_.remote_streams()->at(0);
3134 EXPECT_EQ("default", remote_stream->id());
3135 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003136}
3137
deadbeefab9b2d12015-10-14 11:33:11 -07003138// This tests that an RtpSender is created when the local description is set
3139// after adding a local stream.
3140// TODO(deadbeef): This test and the one below it need to be updated when
3141// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003142// Don't run under Unified Plan since this behavior is Plan B specific.
3143TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003144 RTCConfiguration config;
3145 config.enable_dtls_srtp = true;
3146 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003147
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003148 // Create an offer with 1 stream with 2 tracks of each type.
3149 rtc::scoped_refptr<StreamCollection> stream_collection =
3150 CreateStreamCollection(1, 2);
3151 pc_->AddStream(stream_collection->at(0));
3152 std::unique_ptr<SessionDescriptionInterface> offer;
3153 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003154 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003155
deadbeefab9b2d12015-10-14 11:33:11 -07003156 auto senders = pc_->GetSenders();
3157 EXPECT_EQ(4u, senders.size());
3158 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3159 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3160 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3161 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3162
3163 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003164 pc_->RemoveStream(stream_collection->at(0));
3165 stream_collection = CreateStreamCollection(1, 1);
3166 pc_->AddStream(stream_collection->at(0));
3167 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003168 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003169
deadbeefab9b2d12015-10-14 11:33:11 -07003170 senders = pc_->GetSenders();
3171 EXPECT_EQ(2u, senders.size());
3172 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3173 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3174 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3175 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3176}
3177
3178// This tests that an RtpSender is created when the local description is set
3179// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003180// Don't run under Unified Plan since this behavior is Plan B specific.
3181TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003182 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003183 RTCConfiguration config;
3184 config.enable_dtls_srtp = true;
3185 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003186
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003187 rtc::scoped_refptr<StreamCollection> stream_collection =
3188 CreateStreamCollection(1, 2);
3189 // Add a stream to create the offer, but remove it afterwards.
3190 pc_->AddStream(stream_collection->at(0));
3191 std::unique_ptr<SessionDescriptionInterface> offer;
3192 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3193 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003194
Steve Antondb45ca82017-09-11 18:27:34 -07003195 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003196 auto senders = pc_->GetSenders();
3197 EXPECT_EQ(0u, senders.size());
3198
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003199 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003200 senders = pc_->GetSenders();
3201 EXPECT_EQ(4u, senders.size());
3202 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3203 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3204 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3205 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3206}
3207
3208// This tests that the expected behavior occurs if the SSRC on a local track is
3209// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003210TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003211 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003212 RTCConfiguration config;
3213 config.enable_dtls_srtp = true;
3214 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003215
Steve Anton36da6ff2018-02-16 16:04:20 -08003216 AddAudioTrack(kAudioTracks[0]);
3217 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003218 std::unique_ptr<SessionDescriptionInterface> offer;
3219 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3220 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003221 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3222 webrtc::CreateSessionDescription(
3223 webrtc::SdpType::kOffer, offer->session_id(),
3224 offer->session_version(),
3225 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003226 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003227
deadbeefab9b2d12015-10-14 11:33:11 -07003228 auto senders = pc_->GetSenders();
3229 EXPECT_EQ(2u, senders.size());
3230 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3231 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3232
3233 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003234 cricket::MediaContentDescription* desc =
3235 cricket::GetFirstAudioContentDescription(modified_offer->description());
3236 ASSERT_TRUE(desc != NULL);
3237 for (StreamParams& stream : desc->mutable_streams()) {
3238 for (unsigned int& ssrc : stream.ssrcs) {
3239 ++ssrc;
3240 }
3241 }
deadbeefab9b2d12015-10-14 11:33:11 -07003242
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003243 desc =
3244 cricket::GetFirstVideoContentDescription(modified_offer->description());
3245 ASSERT_TRUE(desc != NULL);
3246 for (StreamParams& stream : desc->mutable_streams()) {
3247 for (unsigned int& ssrc : stream.ssrcs) {
3248 ++ssrc;
3249 }
3250 }
3251
Steve Antondb45ca82017-09-11 18:27:34 -07003252 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003253 senders = pc_->GetSenders();
3254 EXPECT_EQ(2u, senders.size());
3255 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3256 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3257 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3258 // changed.
3259}
3260
3261// This tests that the expected behavior occurs if a new session description is
3262// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003263// Don't run under Unified Plan since the stream API is not available.
3264TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003265 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003266 RTCConfiguration config;
3267 config.enable_dtls_srtp = true;
3268 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003269
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003270 rtc::scoped_refptr<StreamCollection> stream_collection =
3271 CreateStreamCollection(2, 1);
3272 pc_->AddStream(stream_collection->at(0));
3273 std::unique_ptr<SessionDescriptionInterface> offer;
3274 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003275 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003276
deadbeefab9b2d12015-10-14 11:33:11 -07003277 auto senders = pc_->GetSenders();
3278 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003279 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3280 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003281
3282 // Add a new MediaStream but with the same tracks as in the first stream.
3283 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3284 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003285 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3286 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003287 pc_->AddStream(stream_1);
3288
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003289 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003290 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003291
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003292 auto new_senders = pc_->GetSenders();
3293 // Should be the same senders as before, but with updated stream id.
3294 // Note that this behavior is subject to change in the future.
3295 // We may decide the PC should ignore existing tracks in AddStream.
3296 EXPECT_EQ(senders, new_senders);
3297 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3298 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003299}
3300
zhihuang81c3a032016-11-17 12:06:24 -08003301// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003302TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003303 RTCConfiguration config;
3304 config.enable_dtls_srtp = true;
3305 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003306 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3307 EXPECT_EQ(observer_.num_added_tracks_, 1);
3308 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3309
3310 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003311 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003312 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003313 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3314}
3315
deadbeefd1a38b52016-12-10 13:15:33 -08003316// Test that when SetConfiguration is called and the configuration is
3317// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003318TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003319 PeerConnectionInterface::RTCConfiguration config;
3320 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003321 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003322 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003323 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3324 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003325
3326 // Do initial offer/answer so there's something to restart.
3327 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003328 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003329
3330 // Grab the ufrags.
3331 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3332
3333 // Change ICE policy, which should trigger an ICE restart on the next offer.
3334 config.type = PeerConnectionInterface::kAll;
3335 EXPECT_TRUE(pc_->SetConfiguration(config));
3336 CreateOfferAsLocalDescription();
3337
3338 // Grab the new ufrags.
3339 std::vector<std::string> subsequent_ufrags =
3340 GetUfrags(pc_->local_description());
3341
3342 // Sanity check.
3343 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3344 // Check that each ufrag is different.
3345 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3346 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3347 }
3348}
3349
3350// Test that when SetConfiguration is called and the configuration *isn't*
3351// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003352TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003353 PeerConnectionInterface::RTCConfiguration config;
3354 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003355 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003356 config = pc_->GetConfiguration();
3357 AddAudioTrack(kAudioTracks[0]);
3358 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003359
3360 // Do initial offer/answer so there's something to restart.
3361 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003362 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003363
3364 // Grab the ufrags.
3365 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3366
3367 // Call SetConfiguration with a config identical to what the PC was
3368 // constructed with.
3369 EXPECT_TRUE(pc_->SetConfiguration(config));
3370 CreateOfferAsLocalDescription();
3371
3372 // Grab the new ufrags.
3373 std::vector<std::string> subsequent_ufrags =
3374 GetUfrags(pc_->local_description());
3375
3376 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3377}
3378
3379// Test for a weird corner case scenario:
3380// 1. Audio/video session established.
3381// 2. SetConfiguration changes ICE config; ICE restart needed.
3382// 3. ICE restart initiated by remote peer, but only for one m= section.
3383// 4. Next createOffer should initiate an ICE restart, but only for the other
3384// m= section; it would be pointless to do an ICE restart for the m= section
3385// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003386TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003387 PeerConnectionInterface::RTCConfiguration config;
3388 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003389 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003390 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003391 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3392 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003393
3394 // Do initial offer/answer so there's something to restart.
3395 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003396 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003397
3398 // Change ICE policy, which should set the "needs-ice-restart" flag.
3399 config.type = PeerConnectionInterface::kAll;
3400 EXPECT_TRUE(pc_->SetConfiguration(config));
3401
3402 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003403 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003404 webrtc::CreateSessionDescription(SdpType::kOffer,
3405 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003406 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003407 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3408 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003409 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003410 CreateAnswerAsLocalDescription();
3411
3412 // Grab the ufrags.
3413 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003414 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003415
3416 // Create offer and grab the new ufrags.
3417 CreateOfferAsLocalDescription();
3418 std::vector<std::string> subsequent_ufrags =
3419 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003420 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003421
3422 // Ensure that only the ufrag for the second m= section changed.
3423 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3424 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3425}
3426
deadbeeffe4a8a42016-12-20 17:56:17 -08003427// Tests that the methods to return current/pending descriptions work as
3428// expected at different points in the offer/answer exchange. This test does
3429// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003430TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003431 // This disables DTLS so we can apply an answer to ourselves.
3432 CreatePeerConnection();
3433
3434 // Create initial local offer and get SDP (which will also be used as
3435 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003436 std::unique_ptr<SessionDescriptionInterface> local_offer;
3437 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003438 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003439 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003440
3441 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003442 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3443 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3444 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003445 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3446 EXPECT_EQ(nullptr, pc_->current_local_description());
3447 EXPECT_EQ(nullptr, pc_->current_remote_description());
3448
3449 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003450 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003451 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003452 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3453 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3454 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3455 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003456 EXPECT_EQ(nullptr, pc_->current_local_description());
3457 EXPECT_EQ(nullptr, pc_->current_remote_description());
3458
3459 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003460 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003461 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003462 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3463 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003464 EXPECT_EQ(nullptr, pc_->pending_local_description());
3465 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003466 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3467 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003468
3469 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003470 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003471 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003472 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3473 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3474 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003475 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003476 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3477 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003478
3479 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003480 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003481 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003482 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3483 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3484 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3485 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3486 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3487 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003488
3489 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003490 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003491 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003492 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3493 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003494 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3495 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003496 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3497 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003498}
3499
zhihuang77985012017-02-07 15:45:16 -08003500// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3501// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003502// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003503TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003504 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003505 CreatePeerConnection();
3506 // The RtcEventLog will be reset when the PeerConnection is closed.
3507 pc_->Close();
3508
Elad Alon9e6565b2017-10-11 16:04:13 +02003509 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3510 std::string filename = webrtc::test::OutputPath() +
3511 test_info->test_case_name() + test_info->name();
3512 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3513
3514 constexpr int64_t max_size_bytes = 1024;
3515
zhihuang77985012017-02-07 15:45:16 -08003516 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3517 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003518
3519 // Cleanup.
3520 rtc::ClosePlatformFile(file);
3521 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003522}
3523
Elad Alon99c3fe52017-10-13 16:29:40 +02003524// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3525// after the PeerConnection is closed.
3526// This version tests the StartRtcEventLog version that receives an object
3527// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003528TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003529 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3530 CreatePeerConnection();
3531 // The RtcEventLog will be reset when the PeerConnection is closed.
3532 pc_->Close();
3533
3534 rtc::PlatformFile file = 0;
3535 int64_t max_size_bytes = 1024;
3536 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003537 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003538 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003539 pc_->StopRtcEventLog();
3540}
3541
deadbeef30952b42017-04-21 02:41:29 -07003542// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003543TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003544 CreatePeerConnection();
3545
3546 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003547 RTCOfferAnswerOptions options;
3548 options.offer_to_receive_audio = 1;
3549 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003550 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003551 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003552 cricket::SessionDescription* desc = offer->description();
3553 ASSERT_EQ(2u, desc->transport_infos().size());
3554 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3555 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3556
3557 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003558 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003559 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003560 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003561 desc = answer->description();
3562 ASSERT_EQ(2u, desc->transport_infos().size());
3563 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3564 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3565}
3566
deadbeef1dcb1642017-03-29 21:08:16 -07003567// Test that ICE renomination isn't offered if it's not enabled in the PC's
3568// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003569TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003570 PeerConnectionInterface::RTCConfiguration config;
3571 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003572 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003573 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003574
3575 std::unique_ptr<SessionDescriptionInterface> offer;
3576 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3577 cricket::SessionDescription* desc = offer->description();
3578 EXPECT_EQ(1u, desc->transport_infos().size());
3579 EXPECT_FALSE(
3580 desc->transport_infos()[0].description.GetIceParameters().renomination);
3581}
3582
3583// Test that the ICE renomination option is present in generated offers/answers
3584// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003585TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003586 PeerConnectionInterface::RTCConfiguration config;
3587 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003588 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003589 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003590
3591 std::unique_ptr<SessionDescriptionInterface> offer;
3592 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3593 cricket::SessionDescription* desc = offer->description();
3594 EXPECT_EQ(1u, desc->transport_infos().size());
3595 EXPECT_TRUE(
3596 desc->transport_infos()[0].description.GetIceParameters().renomination);
3597
3598 // Set the offer as a remote description, then create an answer and ensure it
3599 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003600 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003601 std::unique_ptr<SessionDescriptionInterface> answer;
3602 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3603 desc = answer->description();
3604 EXPECT_EQ(1u, desc->transport_infos().size());
3605 EXPECT_TRUE(
3606 desc->transport_infos()[0].description.GetIceParameters().renomination);
3607}
3608
3609// Test that if CreateOffer is called with the deprecated "offer to receive
3610// audio/video" constraints, they're processed and result in an offer with
3611// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003612TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003613 CreatePeerConnection();
3614
Niels Möllerf06f9232018-08-07 12:32:18 +02003615 RTCOfferAnswerOptions options;
3616 options.offer_to_receive_audio = 1;
3617 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003618 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003619 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003620
3621 cricket::SessionDescription* desc = offer->description();
3622 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3623 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3624 ASSERT_NE(nullptr, audio);
3625 ASSERT_NE(nullptr, video);
3626 EXPECT_FALSE(audio->rejected);
3627 EXPECT_FALSE(video->rejected);
3628}
3629
3630// Test that if CreateAnswer is called with the deprecated "offer to receive
3631// audio/video" constraints, they're processed and can be used to reject an
3632// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003633// Don't run under Unified Plan since this behavior is not supported.
3634TEST_F(PeerConnectionInterfaceTestPlanB,
3635 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003636 CreatePeerConnection();
3637
3638 // First, create an offer with audio/video and apply it as a remote
3639 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003640 RTCOfferAnswerOptions options;
3641 options.offer_to_receive_audio = 1;
3642 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003643 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003644 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003645 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003646
3647 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003648 options.offer_to_receive_audio = 0;
3649 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003650 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003651 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003652
3653 cricket::SessionDescription* desc = answer->description();
3654 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3655 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3656 ASSERT_NE(nullptr, audio);
3657 ASSERT_NE(nullptr, video);
3658 EXPECT_TRUE(audio->rejected);
3659 EXPECT_TRUE(video->rejected);
3660}
3661
deadbeef1dcb1642017-03-29 21:08:16 -07003662// Test that negotiation can succeed with a data channel only, and with the max
3663// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003664#ifdef HAVE_SCTP
3665TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3666#else
3667TEST_P(PeerConnectionInterfaceTest,
3668 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3669#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003670 PeerConnectionInterface::RTCConfiguration config;
3671 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003672 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003673
3674 // First, create an offer with only a data channel and apply it as a remote
3675 // description.
3676 pc_->CreateDataChannel("test", nullptr);
3677 std::unique_ptr<SessionDescriptionInterface> offer;
3678 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003679 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003680
3681 // Create and set answer as well.
3682 std::unique_ptr<SessionDescriptionInterface> answer;
3683 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003684 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003685}
3686
Steve Anton36da6ff2018-02-16 16:04:20 -08003687TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003688 CreatePeerConnection();
3689 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003690 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003691 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3692}
3693
Steve Anton36da6ff2018-02-16 16:04:20 -08003694TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003695 CreatePeerConnection();
3696 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003697 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003698 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3699}
3700
Steve Anton36da6ff2018-02-16 16:04:20 -08003701TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003702 CreatePeerConnection();
3703 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003704 bitrate.min_bitrate_bps = 5;
3705 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003706 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3707}
3708
Steve Anton36da6ff2018-02-16 16:04:20 -08003709TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003710 CreatePeerConnection();
3711 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003712 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003713 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3714}
3715
Steve Anton36da6ff2018-02-16 16:04:20 -08003716TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003717 CreatePeerConnection();
3718 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003719 bitrate.current_bitrate_bps = 10;
3720 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003721 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3722}
3723
Steve Anton36da6ff2018-02-16 16:04:20 -08003724TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003725 CreatePeerConnection();
3726 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003727 bitrate.min_bitrate_bps = 10;
3728 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003729 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3730}
3731
Steve Anton36da6ff2018-02-16 16:04:20 -08003732TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003733 CreatePeerConnection();
3734 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003735 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003736 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3737}
3738
Steve Anton038834f2017-07-14 15:59:59 -07003739// ice_regather_interval_range requires WebRTC to be configured for continual
3740// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003741TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003742 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3743 PeerConnectionInterface::RTCConfiguration config;
3744 config.ice_regather_interval_range.emplace(1000, 2000);
3745 config.continual_gathering_policy =
3746 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3747 CreatePeerConnectionExpectFail(config);
3748}
3749
3750// Ensures that there is no error when ice_regather_interval_range is set with
3751// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003752TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003753 SetIceRegatherIntervalRangeWithContinualGathering) {
3754 PeerConnectionInterface::RTCConfiguration config;
3755 config.ice_regather_interval_range.emplace(1000, 2000);
3756 config.continual_gathering_policy =
3757 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003758 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003759}
3760
Niels Möller0c4f7be2018-05-07 14:01:37 +02003761// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003762// by Call's BitrateConstraints, which comes from the SDP or a default value.
3763// This test checks that a call to SetBitrate with a current bitrate that will
3764// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003765TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003766 CreatePeerConnection();
3767 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003768 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003769 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3770}
3771
zhihuang1c378ed2017-08-17 14:10:50 -07003772// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003773TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003774 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3775 RTCOfferAnswerOptions rtc_options;
3776
3777 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3778 // than kMaxOfferToReceiveMedia should be treated as invalid.
3779 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3780 CreatePeerConnection();
3781 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3782
3783 rtc_options.offer_to_receive_audio =
3784 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3785 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3786}
3787
Steve Anton36da6ff2018-02-16 16:04:20 -08003788TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003789 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3790 RTCOfferAnswerOptions rtc_options;
3791
3792 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3793 // than kMaxOfferToReceiveMedia should be treated as invalid.
3794 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3795 CreatePeerConnection();
3796 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3797
3798 rtc_options.offer_to_receive_video =
3799 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3800 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3801}
3802
3803// Test that the audio and video content will be added to an offer if both
3804// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003805TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003806 RTCOfferAnswerOptions rtc_options;
3807 rtc_options.offer_to_receive_audio = 1;
3808 rtc_options.offer_to_receive_video = 1;
3809
3810 std::unique_ptr<SessionDescriptionInterface> offer;
3811 CreatePeerConnection();
3812 offer = CreateOfferWithOptions(rtc_options);
3813 ASSERT_TRUE(offer);
3814 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3815 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3816}
3817
3818// Test that only audio content will be added to the offer if only
3819// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003820TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003821 RTCOfferAnswerOptions rtc_options;
3822 rtc_options.offer_to_receive_audio = 1;
3823 rtc_options.offer_to_receive_video = 0;
3824
3825 std::unique_ptr<SessionDescriptionInterface> offer;
3826 CreatePeerConnection();
3827 offer = CreateOfferWithOptions(rtc_options);
3828 ASSERT_TRUE(offer);
3829 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3830 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3831}
3832
3833// Test that only video content will be added if only |offer_to_receive_video|
3834// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003835TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003836 RTCOfferAnswerOptions rtc_options;
3837 rtc_options.offer_to_receive_audio = 0;
3838 rtc_options.offer_to_receive_video = 1;
3839
3840 std::unique_ptr<SessionDescriptionInterface> offer;
3841 CreatePeerConnection();
3842 offer = CreateOfferWithOptions(rtc_options);
3843 ASSERT_TRUE(offer);
3844 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3845 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3846}
3847
zhihuang1c378ed2017-08-17 14:10:50 -07003848// Test that no media content will be added to the offer if using default
3849// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003850TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003851 RTCOfferAnswerOptions rtc_options;
3852
3853 std::unique_ptr<SessionDescriptionInterface> offer;
3854 CreatePeerConnection();
3855 offer = CreateOfferWithOptions(rtc_options);
3856 ASSERT_TRUE(offer);
3857 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3858 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3859}
3860
3861// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3862// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003863TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3864 CreatePeerConnection();
3865
zhihuang1c378ed2017-08-17 14:10:50 -07003866 RTCOfferAnswerOptions rtc_options;
3867 rtc_options.ice_restart = false;
3868 rtc_options.offer_to_receive_audio = 1;
3869
3870 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003871 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003872 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3873 auto ufrag1 =
3874 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3875 auto pwd1 =
3876 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003877
3878 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3879 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003880 auto ufrag2 =
3881 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3882 auto pwd2 =
3883 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003884
3885 // |ice_restart| is true, the ufrag/pwd should change.
3886 rtc_options.ice_restart = true;
3887 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003888 auto ufrag3 =
3889 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3890 auto pwd3 =
3891 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003892
3893 EXPECT_EQ(ufrag1, ufrag2);
3894 EXPECT_EQ(pwd1, pwd2);
3895 EXPECT_NE(ufrag2, ufrag3);
3896 EXPECT_NE(pwd2, pwd3);
3897}
3898
3899// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3900// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003901TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003902 RTCOfferAnswerOptions rtc_options;
3903 rtc_options.offer_to_receive_audio = 1;
3904 rtc_options.offer_to_receive_video = 1;
3905
3906 std::unique_ptr<SessionDescriptionInterface> offer;
3907 CreatePeerConnection();
3908
3909 rtc_options.use_rtp_mux = true;
3910 offer = CreateOfferWithOptions(rtc_options);
3911 ASSERT_TRUE(offer);
3912 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3913 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3914 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3915
3916 rtc_options.use_rtp_mux = false;
3917 offer = CreateOfferWithOptions(rtc_options);
3918 ASSERT_TRUE(offer);
3919 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3920 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3921 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3922}
3923
zhihuang141aacb2017-08-29 13:23:53 -07003924// This test ensures OnRenegotiationNeeded is called when we add track with
3925// MediaStream -> AddTrack in the same way it is called when we add track with
3926// PeerConnection -> AddTrack.
3927// The test can be removed once addStream is rewritten in terms of addTrack
3928// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003929// Don't run under Unified Plan since the stream API is not available.
3930TEST_F(PeerConnectionInterfaceTestPlanB,
3931 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003932 CreatePeerConnectionWithoutDtls();
3933 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003934 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003935 pc_->AddStream(stream);
3936 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3937 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3938 rtc::scoped_refptr<VideoTrackInterface> video_track(
3939 pc_factory_->CreateVideoTrack(
3940 "video_track", pc_factory_->CreateVideoSource(
3941 std::unique_ptr<cricket::VideoCapturer>(
3942 new cricket::FakeVideoCapturer()))));
3943 stream->AddTrack(audio_track);
3944 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3945 observer_.renegotiation_needed_ = false;
3946
3947 stream->AddTrack(video_track);
3948 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3949 observer_.renegotiation_needed_ = false;
3950
3951 stream->RemoveTrack(audio_track);
3952 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3953 observer_.renegotiation_needed_ = false;
3954
3955 stream->RemoveTrack(video_track);
3956 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3957 observer_.renegotiation_needed_ = false;
3958}
3959
Zhi Huangb2d355e2017-10-26 17:26:37 -07003960// Tests that an error is returned if a description is applied that has fewer
3961// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003962TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003963 MediaSectionCountEnforcedForSubsequentOffer) {
3964 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003965 AddAudioTrack("audio_label");
3966 AddVideoTrack("video_label");
3967
Zhi Huangb2d355e2017-10-26 17:26:37 -07003968 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003969 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003970 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3971
3972 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003973 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003974 offer->description()->contents().pop_back();
3975 offer->description()->contents().pop_back();
3976 ASSERT_TRUE(offer->description()->contents().empty());
3977 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3978
3979 std::unique_ptr<SessionDescriptionInterface> answer;
3980 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3981 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3982
3983 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003984 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003985 offer->description()->contents().pop_back();
3986 offer->description()->contents().pop_back();
3987 ASSERT_TRUE(offer->description()->contents().empty());
3988 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3989}
3990
Johannes Kron89f874e2018-11-12 10:25:48 +01003991TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3992 RTCConfiguration config;
3993 // Default behavior is false.
3994 CreatePeerConnection(config);
3995 std::unique_ptr<SessionDescriptionInterface> offer;
3996 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3997 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3998 // Possible to set to true.
3999 config.offer_extmap_allow_mixed = true;
4000 CreatePeerConnection(config);
4001 offer.release();
4002 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
4003 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
4004}
4005
Steve Anton36da6ff2018-02-16 16:04:20 -08004006INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
4007 PeerConnectionInterfaceTest,
4008 Values(SdpSemantics::kPlanB,
4009 SdpSemantics::kUnifiedPlan));
4010
nisse51542be2016-02-12 02:27:06 -08004011class PeerConnectionMediaConfigTest : public testing::Test {
4012 protected:
4013 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07004014 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08004015 pcf_->Initialize();
4016 }
nisseeaabdf62017-05-05 02:23:02 -07004017 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02004018 const RTCConfiguration& config) {
4019 rtc::scoped_refptr<PeerConnectionInterface> pc(
4020 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08004021 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02004022 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07004023 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08004024 }
4025
zhihuang9763d562016-08-05 11:14:50 -07004026 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08004027 MockPeerConnectionObserver observer_;
4028};
4029
Yves Gereyf3ff14c2018-10-25 10:28:12 +02004030// This sanity check validates the test infrastructure itself.
4031TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
4032 PeerConnectionInterface::RTCConfiguration config;
4033 rtc::scoped_refptr<PeerConnectionInterface> pc(
4034 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
4035 EXPECT_TRUE(pc.get());
4036 observer_.SetPeerConnectionInterface(pc.get()); // Required.
4037 pc->Close(); // No abort -> ok.
4038 SUCCEED();
4039}
4040
nisse51542be2016-02-12 02:27:06 -08004041// This test verifies the default behaviour with no constraints and a
4042// default RTCConfiguration.
4043TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4044 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004045
Niels Möllerf06f9232018-08-07 12:32:18 +02004046 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004047
4048 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004049 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4050 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004051 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004052 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004053}
4054
Niels Möller1d7ecd22018-01-18 15:25:12 +01004055// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004056// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004057TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4058 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004059
Niels Möller71bdda02016-03-31 12:59:59 +02004060 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004061 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004062
Niels Möller1d7ecd22018-01-18 15:25:12 +01004063 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004064}
4065
Niels Möller6539f692018-01-18 08:58:50 +01004066// This test verifies that the experiment_cpu_load_estimator flag is
4067// propagated from RTCConfiguration to the PeerConnection.
4068TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4069 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004070
4071 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004072 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004073
4074 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4075}
4076
deadbeef293e9262017-01-11 12:28:30 -08004077// Tests a few random fields being different.
4078TEST(RTCConfigurationTest, ComparisonOperators) {
4079 PeerConnectionInterface::RTCConfiguration a;
4080 PeerConnectionInterface::RTCConfiguration b;
4081 EXPECT_EQ(a, b);
4082
4083 PeerConnectionInterface::RTCConfiguration c;
4084 c.servers.push_back(PeerConnectionInterface::IceServer());
4085 EXPECT_NE(a, c);
4086
4087 PeerConnectionInterface::RTCConfiguration d;
4088 d.type = PeerConnectionInterface::kRelay;
4089 EXPECT_NE(a, d);
4090
4091 PeerConnectionInterface::RTCConfiguration e;
4092 e.audio_jitter_buffer_max_packets = 5;
4093 EXPECT_NE(a, e);
4094
4095 PeerConnectionInterface::RTCConfiguration f;
4096 f.ice_connection_receiving_timeout = 1337;
4097 EXPECT_NE(a, f);
4098
4099 PeerConnectionInterface::RTCConfiguration g;
4100 g.disable_ipv6 = true;
4101 EXPECT_NE(a, g);
4102
4103 PeerConnectionInterface::RTCConfiguration h(
4104 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4105 EXPECT_NE(a, h);
4106}