blob: 0528247f8519de569f8613c8ede980232c55cf4b [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
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010097namespace webrtc {
98namespace {
99
Seth Hampson845e8782018-03-02 11:34:10 -0800100static const char kStreamId1[] = "local_stream_1";
101static const char kStreamId2[] = "local_stream_2";
102static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const int kDefaultStunPort = 3478;
104static const char kStunAddressOnly[] = "stun:address";
105static const char kStunInvalidPort[] = "stun:address:-1";
106static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
107static const char kStunAddressPortAndMore2[] = "stun:address:port more";
108static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
109static const char kTurnUsername[] = "user";
110static const char kTurnPassword[] = "password";
111static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200112static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
deadbeefab9b2d12015-10-14 11:33:11 -0700114static const char kStreams[][8] = {"stream1", "stream2"};
115static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
116static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
117
deadbeef5e97fb52015-10-15 12:49:08 -0700118static const char kRecvonly[] = "recvonly";
119static const char kSendrecv[] = "sendrecv";
120
deadbeefab9b2d12015-10-14 11:33:11 -0700121// Reference SDP with a MediaStream with label "stream1" and audio track with
122// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800123static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700124 "v=0\r\n"
125 "o=- 0 0 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800128 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700129 "a=ice-ufrag:e5785931\r\n"
130 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
131 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
132 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700133 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700134 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800135 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700136 "a=rtpmap:103 ISAC/16000\r\n"
137 "a=ssrc:1 cname:stream1\r\n"
138 "a=ssrc:1 mslabel:stream1\r\n"
139 "a=ssrc:1 label:audiotrack0\r\n"
140 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800141 "a=ice-ufrag:e5785931\r\n"
142 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
143 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
144 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700145 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700146 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800147 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700148 "a=rtpmap:120 VP8/90000\r\n"
149 "a=ssrc:2 cname:stream1\r\n"
150 "a=ssrc:2 mslabel:stream1\r\n"
151 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800152// Same string as above but with the MID changed to the Unified Plan default.
153// This is needed so that this SDP can be used as an answer for a Unified Plan
154// offer.
155static const char kSdpStringWithStream1UnifiedPlan[] =
156 "v=0\r\n"
157 "o=- 0 0 IN IP4 127.0.0.1\r\n"
158 "s=-\r\n"
159 "t=0 0\r\n"
160 "m=audio 1 RTP/AVPF 103\r\n"
161 "a=ice-ufrag:e5785931\r\n"
162 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
163 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
164 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
165 "a=mid:0\r\n"
166 "a=sendrecv\r\n"
167 "a=rtcp-mux\r\n"
168 "a=rtpmap:103 ISAC/16000\r\n"
169 "a=ssrc:1 cname:stream1\r\n"
170 "a=ssrc:1 mslabel:stream1\r\n"
171 "a=ssrc:1 label:audiotrack0\r\n"
172 "m=video 1 RTP/AVPF 120\r\n"
173 "a=ice-ufrag:e5785931\r\n"
174 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
175 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
176 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
177 "a=mid:1\r\n"
178 "a=sendrecv\r\n"
179 "a=rtcp-mux\r\n"
180 "a=rtpmap:120 VP8/90000\r\n"
181 "a=ssrc:2 cname:stream1\r\n"
182 "a=ssrc:2 mslabel:stream1\r\n"
183 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700184
zhihuang81c3a032016-11-17 12:06:24 -0800185// Reference SDP with a MediaStream with label "stream1" and audio track with
186// id "audio_1";
187static const char kSdpStringWithStream1AudioTrackOnly[] =
188 "v=0\r\n"
189 "o=- 0 0 IN IP4 127.0.0.1\r\n"
190 "s=-\r\n"
191 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800192 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800193 "a=ice-ufrag:e5785931\r\n"
194 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
195 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
196 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800197 "a=mid:audio\r\n"
198 "a=sendrecv\r\n"
199 "a=rtpmap:103 ISAC/16000\r\n"
200 "a=ssrc:1 cname:stream1\r\n"
201 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800202 "a=ssrc:1 label:audiotrack0\r\n"
203 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800204
deadbeefab9b2d12015-10-14 11:33:11 -0700205// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
206// MediaStreams have one audio track and one video track.
207// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800208static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700209 "v=0\r\n"
210 "o=- 0 0 IN IP4 127.0.0.1\r\n"
211 "s=-\r\n"
212 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800213 "a=msid-semantic: WMS stream1 stream2\r\n"
214 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700215 "a=ice-ufrag:e5785931\r\n"
216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700220 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800221 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700222 "a=rtpmap:103 ISAC/16000\r\n"
223 "a=ssrc:1 cname:stream1\r\n"
224 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
225 "a=ssrc:3 cname:stream2\r\n"
226 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
227 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800228 "a=ice-ufrag:e5785931\r\n"
229 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
230 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
231 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700232 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700233 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800234 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700235 "a=rtpmap:120 VP8/0\r\n"
236 "a=ssrc:2 cname:stream1\r\n"
237 "a=ssrc:2 msid:stream1 videotrack0\r\n"
238 "a=ssrc:4 cname:stream2\r\n"
239 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800240static const char kSdpStringWithStream1And2UnifiedPlan[] =
241 "v=0\r\n"
242 "o=- 0 0 IN IP4 127.0.0.1\r\n"
243 "s=-\r\n"
244 "t=0 0\r\n"
245 "a=msid-semantic: WMS stream1 stream2\r\n"
246 "m=audio 1 RTP/AVPF 103\r\n"
247 "a=ice-ufrag:e5785931\r\n"
248 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
249 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
250 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
251 "a=mid:0\r\n"
252 "a=sendrecv\r\n"
253 "a=rtcp-mux\r\n"
254 "a=rtpmap:103 ISAC/16000\r\n"
255 "a=ssrc:1 cname:stream1\r\n"
256 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
257 "m=video 1 RTP/AVPF 120\r\n"
258 "a=ice-ufrag:e5785931\r\n"
259 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
260 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
261 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
262 "a=mid:1\r\n"
263 "a=sendrecv\r\n"
264 "a=rtcp-mux\r\n"
265 "a=rtpmap:120 VP8/0\r\n"
266 "a=ssrc:2 cname:stream1\r\n"
267 "a=ssrc:2 msid:stream1 videotrack0\r\n"
268 "m=audio 1 RTP/AVPF 103\r\n"
269 "a=ice-ufrag:e5785931\r\n"
270 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
271 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
272 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
273 "a=mid:2\r\n"
274 "a=sendrecv\r\n"
275 "a=rtcp-mux\r\n"
276 "a=rtpmap:103 ISAC/16000\r\n"
277 "a=ssrc:3 cname:stream2\r\n"
278 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
279 "m=video 1 RTP/AVPF 120\r\n"
280 "a=ice-ufrag:e5785931\r\n"
281 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
282 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
283 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
284 "a=mid:3\r\n"
285 "a=sendrecv\r\n"
286 "a=rtcp-mux\r\n"
287 "a=rtpmap:120 VP8/0\r\n"
288 "a=ssrc:4 cname:stream2\r\n"
289 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700290
291// Reference SDP without MediaStreams. Msid is not supported.
292static const char kSdpStringWithoutStreams[] =
293 "v=0\r\n"
294 "o=- 0 0 IN IP4 127.0.0.1\r\n"
295 "s=-\r\n"
296 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800297 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700298 "a=ice-ufrag:e5785931\r\n"
299 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
300 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
301 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700302 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700303 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800304 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700305 "a=rtpmap:103 ISAC/16000\r\n"
306 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800307 "a=ice-ufrag:e5785931\r\n"
308 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
309 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
310 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700311 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700312 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800313 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700314 "a=rtpmap:120 VP8/90000\r\n";
315
316// Reference SDP without MediaStreams. Msid is supported.
317static const char kSdpStringWithMsidWithoutStreams[] =
318 "v=0\r\n"
319 "o=- 0 0 IN IP4 127.0.0.1\r\n"
320 "s=-\r\n"
321 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800322 "a=msid-semantic: WMS\r\n"
323 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700324 "a=ice-ufrag:e5785931\r\n"
325 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
326 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
327 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700329 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800330 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700331 "a=rtpmap:103 ISAC/16000\r\n"
332 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800333 "a=ice-ufrag:e5785931\r\n"
334 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
335 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
336 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700337 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700338 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800339 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700340 "a=rtpmap:120 VP8/90000\r\n";
341
342// Reference SDP without MediaStreams and audio only.
343static const char kSdpStringWithoutStreamsAudioOnly[] =
344 "v=0\r\n"
345 "o=- 0 0 IN IP4 127.0.0.1\r\n"
346 "s=-\r\n"
347 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800348 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700349 "a=ice-ufrag:e5785931\r\n"
350 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
351 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
352 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700353 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700354 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800355 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700356 "a=rtpmap:103 ISAC/16000\r\n";
357
358// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
359static const char kSdpStringSendOnlyWithoutStreams[] =
360 "v=0\r\n"
361 "o=- 0 0 IN IP4 127.0.0.1\r\n"
362 "s=-\r\n"
363 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800364 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700365 "a=ice-ufrag:e5785931\r\n"
366 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
367 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
368 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700369 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700370 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700371 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800372 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700373 "a=rtpmap:103 ISAC/16000\r\n"
374 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800375 "a=ice-ufrag:e5785931\r\n"
376 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
377 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
378 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700379 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700380 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700381 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800382 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700383 "a=rtpmap:120 VP8/90000\r\n";
384
385static const char kSdpStringInit[] =
386 "v=0\r\n"
387 "o=- 0 0 IN IP4 127.0.0.1\r\n"
388 "s=-\r\n"
389 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700390 "a=msid-semantic: WMS\r\n";
391
392static const char kSdpStringAudio[] =
393 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800394 "a=ice-ufrag:e5785931\r\n"
395 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
396 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
397 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700398 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700399 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800400 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700401 "a=rtpmap:103 ISAC/16000\r\n";
402
403static const char kSdpStringVideo[] =
404 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800405 "a=ice-ufrag:e5785931\r\n"
406 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
407 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
408 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700409 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700410 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800411 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700412 "a=rtpmap:120 VP8/90000\r\n";
413
414static const char kSdpStringMs1Audio0[] =
415 "a=ssrc:1 cname:stream1\r\n"
416 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
417
418static const char kSdpStringMs1Video0[] =
419 "a=ssrc:2 cname:stream1\r\n"
420 "a=ssrc:2 msid:stream1 videotrack0\r\n";
421
422static const char kSdpStringMs1Audio1[] =
423 "a=ssrc:3 cname:stream1\r\n"
424 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
425
426static const char kSdpStringMs1Video1[] =
427 "a=ssrc:4 cname:stream1\r\n"
428 "a=ssrc:4 msid:stream1 videotrack1\r\n";
429
deadbeef8662f942017-01-20 21:20:51 -0800430static const char kDtlsSdesFallbackSdp[] =
431 "v=0\r\n"
432 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
433 "s=-\r\n"
434 "c=IN IP4 0.0.0.0\r\n"
435 "t=0 0\r\n"
436 "a=group:BUNDLE audio\r\n"
437 "a=msid-semantic: WMS\r\n"
438 "m=audio 1 RTP/SAVPF 0\r\n"
439 "a=sendrecv\r\n"
440 "a=rtcp-mux\r\n"
441 "a=mid:audio\r\n"
442 "a=ssrc:1 cname:stream1\r\n"
443 "a=ssrc:1 mslabel:stream1\r\n"
444 "a=ssrc:1 label:audiotrack0\r\n"
445 "a=ice-ufrag:e5785931\r\n"
446 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
447 "a=rtpmap:0 pcmu/8000\r\n"
448 "a=fingerprint:sha-1 "
449 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
450 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700451 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800452 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
453 "dummy_session_params\r\n";
454
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100455using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700456using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800457using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458
Steve Anton36da6ff2018-02-16 16:04:20 -0800459using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
460using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700461
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462// Gets the first ssrc of given content type from the ContentInfo.
463bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
464 if (!content_info || !ssrc) {
465 return false;
466 }
467 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800468 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 if (!media_desc || media_desc->streams().empty()) {
470 return false;
471 }
472 *ssrc = media_desc->streams().begin()->first_ssrc();
473 return true;
474}
475
deadbeefd1a38b52016-12-10 13:15:33 -0800476// Get the ufrags out of an SDP blob. Useful for testing ICE restart
477// behavior.
478std::vector<std::string> GetUfrags(
479 const webrtc::SessionDescriptionInterface* desc) {
480 std::vector<std::string> ufrags;
481 for (const cricket::TransportInfo& info :
482 desc->description()->transport_infos()) {
483 ufrags.push_back(info.description.ice_ufrag);
484 }
485 return ufrags;
486}
487
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488void SetSsrcToZero(std::string* sdp) {
489 const char kSdpSsrcAtribute[] = "a=ssrc:";
490 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
491 size_t ssrc_pos = 0;
492 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200493 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 size_t end_ssrc = sdp->find(" ", ssrc_pos);
495 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
496 ssrc_pos = end_ssrc;
497 }
498}
499
deadbeefab9b2d12015-10-14 11:33:11 -0700500// Check if |streams| contains the specified track.
501bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800502 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700503 const std::string& track_id) {
504 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800505 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700506 return true;
507 }
508 }
509 return false;
510}
511
512// Check if |senders| contains the specified sender, by id.
513bool ContainsSender(
514 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
515 const std::string& id) {
516 for (const auto& sender : senders) {
517 if (sender->id() == id) {
518 return true;
519 }
520 }
521 return false;
522}
523
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700524// Check if |senders| contains the specified sender, by id and stream id.
525bool ContainsSender(
526 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
527 const std::string& id,
528 const std::string& stream_id) {
529 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700530 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700531 return true;
532 }
533 }
534 return false;
535}
536
deadbeefab9b2d12015-10-14 11:33:11 -0700537// Create a collection of streams.
538// CreateStreamCollection(1) creates a collection that
539// correspond to kSdpStringWithStream1.
540// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
541rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700542 int number_of_streams,
543 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700544 rtc::scoped_refptr<StreamCollection> local_collection(
545 StreamCollection::Create());
546
547 for (int i = 0; i < number_of_streams; ++i) {
548 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
549 webrtc::MediaStream::Create(kStreams[i]));
550
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700551 for (int j = 0; j < tracks_per_stream; ++j) {
552 // Add a local audio track.
553 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
554 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
555 nullptr));
556 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700557
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700558 // Add a local video track.
559 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
560 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700561 webrtc::FakeVideoTrackSource::Create(),
562 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700563 stream->AddTrack(video_track);
564 }
deadbeefab9b2d12015-10-14 11:33:11 -0700565
566 local_collection->AddStream(stream);
567 }
568 return local_collection;
569}
570
571// Check equality of StreamCollections.
572bool CompareStreamCollections(StreamCollectionInterface* s1,
573 StreamCollectionInterface* s2) {
574 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
575 return false;
576 }
577
578 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700579 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700580 return false;
581 }
582 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
583 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
584 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
585 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
586
587 if (audio_tracks1.size() != audio_tracks2.size()) {
588 return false;
589 }
590 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
591 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
592 return false;
593 }
594 }
595 if (video_tracks1.size() != video_tracks2.size()) {
596 return false;
597 }
598 for (size_t j = 0; j != video_tracks1.size(); ++j) {
599 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
600 return false;
601 }
602 }
603 }
604 return true;
605}
606
perkjd61bf802016-03-24 03:16:19 -0700607// Helper class to test Observer.
608class MockTrackObserver : public ObserverInterface {
609 public:
610 explicit MockTrackObserver(NotifierInterface* notifier)
611 : notifier_(notifier) {
612 notifier_->RegisterObserver(this);
613 }
614
615 ~MockTrackObserver() { Unregister(); }
616
617 void Unregister() {
618 if (notifier_) {
619 notifier_->UnregisterObserver(this);
620 notifier_ = nullptr;
621 }
622 }
623
624 MOCK_METHOD0(OnChanged, void());
625
626 private:
627 NotifierInterface* notifier_;
628};
629
nisse528b7932017-05-08 03:21:43 -0700630// The PeerConnectionMediaConfig tests below verify that configuration and
631// constraints are propagated into the PeerConnection's MediaConfig. These
632// settings are intended for MediaChannel constructors, but that is not
633// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700634class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
635 public:
zhihuang38ede132017-06-15 12:52:32 -0700636 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
637 CreatePeerConnectionFactoryForTest() {
638 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
639 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200640 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
641 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700642
henrika919dc2e2017-10-12 14:24:55 +0200643 // Use fake audio device module since we're only testing the interface
644 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700645 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
646 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200647 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200648 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000649 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100650 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700651
652 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
653 webrtc::CreateCallFactory();
654
655 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
656 webrtc::CreateRtcEventLogFactory();
657
658 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
659 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200660 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700661 std::move(event_log_factory));
662 }
663
664 PeerConnectionFactoryForTest(
665 rtc::Thread* network_thread,
666 rtc::Thread* worker_thread,
667 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700668 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
669 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
670 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
671 : webrtc::PeerConnectionFactory(network_thread,
672 worker_thread,
673 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700674 std::move(media_engine),
675 std::move(call_factory),
676 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800677
deadbeefd7850b22017-08-23 10:59:19 -0700678 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700679};
680
Steve Anton36da6ff2018-02-16 16:04:20 -0800681// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
682class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800684 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
685 : vss_(new rtc::VirtualSocketServer()),
686 main_(vss_.get()),
687 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800688#ifdef WEBRTC_ANDROID
689 webrtc::InitializeAndroidObjects();
690#endif
691 }
692
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700694 // Use fake audio capture module since we're only testing the interface
695 // level, and using a real one could make tests flaky when run in parallel.
696 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700698 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200699 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
700 fake_audio_capture_module_),
701 webrtc::CreateBuiltinAudioEncoderFactory(),
702 webrtc::CreateBuiltinAudioDecoderFactory(),
703 webrtc::CreateBuiltinVideoEncoderFactory(),
704 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
705 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700706 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700707 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700708 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700709 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 }
711
712 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200713 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 }
715
deadbeef293e9262017-01-11 12:28:30 -0800716 // DTLS does not work in a loopback call, so is disabled for most of the
717 // tests in this file.
718 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200719 RTCConfiguration config;
720 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800721
Niels Möllerf06f9232018-08-07 12:32:18 +0200722 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 }
724
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700725 void CreatePeerConnectionWithIceTransportsType(
726 PeerConnectionInterface::IceTransportsType type) {
727 PeerConnectionInterface::RTCConfiguration config;
728 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200729 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 }
731
732 void CreatePeerConnectionWithIceServer(const std::string& uri,
733 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800734 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700736 server.uri = uri;
737 server.password = password;
738 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200739 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700740 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741
Niels Möllerf06f9232018-08-07 12:32:18 +0200742 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700743 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800744 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
745 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000746
deadbeef1dcb1642017-03-29 21:08:16 -0700747 // Create certificate generator unless DTLS constraint is explicitly set to
748 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200749 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200750
751 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800752 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
753 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000754 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800755 RTCConfiguration modified_config = config;
756 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200757 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200758 modified_config, std::move(port_allocator), std::move(cert_generator),
759 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 ASSERT_TRUE(pc_.get() != NULL);
761 observer_.SetPeerConnectionInterface(pc_.get());
762 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
763 }
764
deadbeef0a6c4ca2015-10-06 11:38:28 -0700765 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800766 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700767 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700768 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800769 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800770 config.sdp_semantics = sdp_semantics_;
771 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200772 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800773 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700774 }
775
Steve Anton038834f2017-07-14 15:59:59 -0700776 void CreatePeerConnectionExpectFail(
777 PeerConnectionInterface::RTCConfiguration config) {
778 PeerConnectionInterface::IceServer server;
779 server.uri = kTurnIceServerUri;
780 server.password = kTurnPassword;
781 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800782 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700783 rtc::scoped_refptr<PeerConnectionInterface> pc =
784 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
785 EXPECT_EQ(nullptr, pc);
786 }
787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700789 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800790 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
791 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
792 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795
deadbeef0a6c4ca2015-10-06 11:38:28 -0700796 CreatePeerConnectionExpectFail(kStunInvalidPort);
797 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
798 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700800 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
802 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800806 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800808 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 }
810
811 void ReleasePeerConnection() {
812 pc_ = NULL;
813 observer_.SetPeerConnectionInterface(NULL);
814 }
815
Steve Anton36da6ff2018-02-16 16:04:20 -0800816 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
817 const std::string& label) {
818 auto video_source = pc_factory_->CreateVideoSource(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200819 absl::make_unique<cricket::FakeVideoCapturer>(), nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -0800820 return pc_factory_->CreateVideoTrack(label, video_source);
821 }
822
823 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800824 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800826 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
829 observer_.renegotiation_needed_ = false;
830 }
831
Steve Anton36da6ff2018-02-16 16:04:20 -0800832 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700833 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800835 stream->AddTrack(CreateVideoTrack(label + "v0"));
836 ASSERT_TRUE(pc_->AddStream(stream));
837 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
838 observer_.renegotiation_needed_ = false;
839 }
840
841 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
842 const std::string& label) {
843 return pc_factory_->CreateAudioTrack(label, nullptr);
844 }
845
846 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800847 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800848 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800849 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800850 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
851 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
852 observer_.renegotiation_needed_ = false;
853 }
854
855 void AddAudioStream(const std::string& label) {
856 rtc::scoped_refptr<MediaStreamInterface> stream(
857 pc_factory_->CreateLocalMediaStream(label));
858 stream->AddTrack(CreateAudioTrack(label + "a0"));
859 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
861 observer_.renegotiation_needed_ = false;
862 }
863
Seth Hampson845e8782018-03-02 11:34:10 -0800864 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 const std::string& audio_track_label,
866 const std::string& video_track_label) {
867 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700868 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800869 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800870 stream->AddTrack(CreateAudioTrack(audio_track_label));
871 stream->AddTrack(CreateVideoTrack(video_track_label));
872 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
874 observer_.renegotiation_needed_ = false;
875 }
876
Steve Anton36da6ff2018-02-16 16:04:20 -0800877 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
878 cricket::MediaType media_type) {
879 for (auto receiver : pc_->GetReceivers()) {
880 if (receiver->media_type() == media_type) {
881 return receiver;
882 }
883 }
884 return nullptr;
885 }
886
kwibergd1fe2812016-04-27 06:47:29 -0700887 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200888 const RTCOfferAnswerOptions* options,
889 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200890 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
891 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200893 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200895 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 }
897 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700898 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 return observer->result();
900 }
901
kwibergd1fe2812016-04-27 06:47:29 -0700902 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200903 const RTCOfferAnswerOptions* options) {
904 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 }
906
kwibergd1fe2812016-04-27 06:47:29 -0700907 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200908 const RTCOfferAnswerOptions* options) {
909 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 }
911
Steve Antondb45ca82017-09-11 18:27:34 -0700912 bool DoSetSessionDescription(
913 std::unique_ptr<SessionDescriptionInterface> desc,
914 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200915 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
916 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700918 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700920 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 }
zhihuang29ff8442016-07-27 11:07:25 -0700922 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
923 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
924 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 return observer->result();
926 }
927
Steve Antondb45ca82017-09-11 18:27:34 -0700928 bool DoSetLocalDescription(
929 std::unique_ptr<SessionDescriptionInterface> desc) {
930 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 }
932
Steve Antondb45ca82017-09-11 18:27:34 -0700933 bool DoSetRemoteDescription(
934 std::unique_ptr<SessionDescriptionInterface> desc) {
935 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 }
937
938 // Calls PeerConnection::GetStats and check the return value.
939 // It does not verify the values in the StatReports since a RTCP packet might
940 // be required.
941 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000942 rtc::scoped_refptr<MockStatsObserver> observer(
943 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200944 if (!pc_->GetStats(observer, track,
945 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 return false;
947 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
948 return observer->called();
949 }
950
Harald Alvestrand89061872018-01-02 14:08:34 +0100951 // Call the standards-compliant GetStats function.
952 bool DoGetRTCStats() {
953 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
954 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
955 pc_->GetStats(callback);
956 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
957 return callback->called();
958 }
959
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800961 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800963 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800964 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800965 } else {
966 // Unified Plan does not support AddStream, so just add an audio and video
967 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800968 AddAudioTrack(kAudioTracks[0], {kStreamId1});
969 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800970 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 CreateOfferReceiveAnswer();
972 }
973
974 // Verify that RTP Header extensions has been negotiated for audio and video.
975 void VerifyRemoteRtpHeaderExtensions() {
976 const cricket::MediaContentDescription* desc =
977 cricket::GetFirstAudioContentDescription(
978 pc_->remote_description()->description());
979 ASSERT_TRUE(desc != NULL);
980 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
981
982 desc = cricket::GetFirstVideoContentDescription(
983 pc_->remote_description()->description());
984 ASSERT_TRUE(desc != NULL);
985 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
986 }
987
988 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700989 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700990 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 std::string sdp;
992 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700993 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800994 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700995 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
997 }
998
deadbeefab9b2d12015-10-14 11:33:11 -0700999 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001000 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001001 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001002 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001003 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1004 }
1005
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001007 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001008 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009
1010 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1011 // audio codec change, even if the parameter has nothing to do with
1012 // receiving. Not all parameters are serialized to SDP.
1013 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1014 // the SessionDescription, it is necessary to do that here to in order to
1015 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1016 // https://code.google.com/p/webrtc/issues/detail?id=1356
1017 std::string sdp;
1018 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001019 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001020 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001021 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1023 }
1024
1025 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001026 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001027 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028
1029 std::string sdp;
1030 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001031 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001032 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001033 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1035 }
1036
1037 void CreateOfferReceiveAnswer() {
1038 CreateOfferAsLocalDescription();
1039 std::string sdp;
1040 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1041 CreateAnswerAsRemoteDescription(sdp);
1042 }
1043
1044 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001045 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001046 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1048 // audio codec change, even if the parameter has nothing to do with
1049 // receiving. Not all parameters are serialized to SDP.
1050 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1051 // the SessionDescription, it is necessary to do that here to in order to
1052 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1053 // https://code.google.com/p/webrtc/issues/detail?id=1356
1054 std::string sdp;
1055 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001056 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001057 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058
Steve Antondb45ca82017-09-11 18:27:34 -07001059 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001061 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001062 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 }
1064
deadbeefab9b2d12015-10-14 11:33:11 -07001065 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001066 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001067 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001068 ASSERT_TRUE(answer);
1069 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1071 }
1072
deadbeefab9b2d12015-10-14 11:33:11 -07001073 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001074 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001075 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001076 ASSERT_TRUE(pr_answer);
1077 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001079 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001080 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001081 ASSERT_TRUE(answer);
1082 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1084 }
1085
Seth Hampson845e8782018-03-02 11:34:10 -08001086 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001087 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001088 // called with the given stream id and expected number of tracks.
1089 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001090 int expected_num_tracks) {
1091 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001092 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001093 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001094 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 }
1096
1097 // Creates an offer and applies it as a local session description.
1098 // Creates an answer with the same SDP an the offer but removes all lines
1099 // that start with a:ssrc"
1100 void CreateOfferReceiveAnswerWithoutSsrc() {
1101 CreateOfferAsLocalDescription();
1102 std::string sdp;
1103 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1104 SetSsrcToZero(&sdp);
1105 CreateAnswerAsRemoteDescription(sdp);
1106 }
1107
deadbeefab9b2d12015-10-14 11:33:11 -07001108 // This function creates a MediaStream with label kStreams[0] and
1109 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1110 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001111 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001112 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001113 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001114 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1115 size_t number_of_video_tracks) {
1116 EXPECT_LE(number_of_audio_tracks, 2u);
1117 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001118
1119 reference_collection_ = StreamCollection::Create();
1120 std::string sdp_ms1 = std::string(kSdpStringInit);
1121
Seth Hampson845e8782018-03-02 11:34:10 -08001122 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001123
1124 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001125 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001126 reference_collection_->AddStream(stream);
1127
1128 if (number_of_audio_tracks > 0) {
1129 sdp_ms1 += std::string(kSdpStringAudio);
1130 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1131 AddAudioTrack(kAudioTracks[0], stream);
1132 }
1133 if (number_of_audio_tracks > 1) {
1134 sdp_ms1 += kSdpStringMs1Audio1;
1135 AddAudioTrack(kAudioTracks[1], stream);
1136 }
1137
1138 if (number_of_video_tracks > 0) {
1139 sdp_ms1 += std::string(kSdpStringVideo);
1140 sdp_ms1 += std::string(kSdpStringMs1Video0);
1141 AddVideoTrack(kVideoTracks[0], stream);
1142 }
1143 if (number_of_video_tracks > 1) {
1144 sdp_ms1 += kSdpStringMs1Video1;
1145 AddVideoTrack(kVideoTracks[1], stream);
1146 }
1147
kwibergd1fe2812016-04-27 06:47:29 -07001148 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001149 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001150 }
1151
1152 void AddAudioTrack(const std::string& track_id,
1153 MediaStreamInterface* stream) {
1154 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1155 webrtc::AudioTrack::Create(track_id, nullptr));
1156 ASSERT_TRUE(stream->AddTrack(audio_track));
1157 }
1158
1159 void AddVideoTrack(const std::string& track_id,
1160 MediaStreamInterface* stream) {
1161 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001162 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001163 webrtc::FakeVideoTrackSource::Create(),
1164 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001165 ASSERT_TRUE(stream->AddTrack(video_track));
1166 }
1167
Steve Anton36da6ff2018-02-16 16:04:20 -08001168 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001169 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001170 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001171 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001172 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1173 return offer;
1174 }
1175
Steve Anton36da6ff2018-02-16 16:04:20 -08001176 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1177 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001178 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001179 std::unique_ptr<SessionDescriptionInterface> offer;
1180 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1181 return offer;
1182 }
1183
1184 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1185 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1186 std::unique_ptr<SessionDescriptionInterface> answer;
1187 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1188 return answer;
1189 }
1190
kwibergfd8be342016-05-14 19:44:11 -07001191 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001192 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001193 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001194 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001195 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1196 return answer;
1197 }
1198
1199 const std::string& GetFirstAudioStreamCname(
1200 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001201 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001202 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001203 return audio_desc->streams()[0].cname;
1204 }
1205
zhihuang1c378ed2017-08-17 14:10:50 -07001206 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1207 const RTCOfferAnswerOptions& offer_answer_options) {
1208 RTC_DCHECK(pc_);
1209 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1210 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1211 pc_->CreateOffer(observer, offer_answer_options);
1212 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1213 return observer->MoveDescription();
1214 }
1215
1216 void CreateOfferWithOptionsAsRemoteDescription(
1217 std::unique_ptr<SessionDescriptionInterface>* desc,
1218 const RTCOfferAnswerOptions& offer_answer_options) {
1219 *desc = CreateOfferWithOptions(offer_answer_options);
1220 ASSERT_TRUE(desc != nullptr);
1221 std::string sdp;
1222 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001223 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001224 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001225 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001226 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1227 }
1228
1229 void CreateOfferWithOptionsAsLocalDescription(
1230 std::unique_ptr<SessionDescriptionInterface>* desc,
1231 const RTCOfferAnswerOptions& offer_answer_options) {
1232 *desc = CreateOfferWithOptions(offer_answer_options);
1233 ASSERT_TRUE(desc != nullptr);
1234 std::string sdp;
1235 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001236 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001237 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001238
Steve Antondb45ca82017-09-11 18:27:34 -07001239 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001240 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1241 }
1242
1243 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001244 RTC_DCHECK(content);
1245 RTC_DCHECK(content->media_description());
1246 for (const cricket::AudioCodec& codec :
1247 content->media_description()->as_audio()->codecs()) {
1248 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001249 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001250 }
zhihuang1c378ed2017-08-17 14:10:50 -07001251 }
1252 return false;
1253 }
1254
Steve Anton36da6ff2018-02-16 16:04:20 -08001255 const char* GetSdpStringWithStream1() const {
1256 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1257 return kSdpStringWithStream1PlanB;
1258 } else {
1259 return kSdpStringWithStream1UnifiedPlan;
1260 }
1261 }
1262
1263 const char* GetSdpStringWithStream1And2() const {
1264 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1265 return kSdpStringWithStream1And2PlanB;
1266 } else {
1267 return kSdpStringWithStream1And2UnifiedPlan;
1268 }
1269 }
1270
deadbeef9a6f4d42017-05-15 19:43:33 -07001271 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1272 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001273 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001274 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001275 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001276 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1277 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1278 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001280 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001281 const SdpSemantics sdp_semantics_;
1282};
1283
1284class PeerConnectionInterfaceTest
1285 : public PeerConnectionInterfaceBaseTest,
1286 public ::testing::WithParamInterface<SdpSemantics> {
1287 protected:
1288 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1289};
1290
1291class PeerConnectionInterfaceTestPlanB
1292 : public PeerConnectionInterfaceBaseTest {
1293 protected:
1294 PeerConnectionInterfaceTestPlanB()
1295 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296};
1297
zhihuang8f65cdf2016-05-06 18:40:30 -07001298// Generate different CNAMEs when PeerConnections are created.
1299// The CNAMEs are expected to be generated randomly. It is possible
1300// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001301TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001302 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001303 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001304 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001305 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001306 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1307 GetFirstAudioStreamCname(offer2.get()));
1308}
1309
Steve Anton36da6ff2018-02-16 16:04:20 -08001310TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001311 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001312 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001313 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001314 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001315 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1316 GetFirstAudioStreamCname(answer2.get()));
1317}
1318
Steve Anton36da6ff2018-02-16 16:04:20 -08001319TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 CreatePeerConnectionWithDifferentConfigurations) {
1321 CreatePeerConnectionWithDifferentConfigurations();
1322}
1323
Steve Anton36da6ff2018-02-16 16:04:20 -08001324TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001325 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1326 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1327 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1328 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1329 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1330 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1331 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1332 port_allocator_->candidate_filter());
1333 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1334 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1335}
1336
1337// Test that when a PeerConnection is created with a nonzero candidate pool
1338// size, the pooled PortAllocatorSession is created with all the attributes
1339// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001340TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001341 PeerConnectionInterface::RTCConfiguration config;
1342 PeerConnectionInterface::IceServer server;
1343 server.uri = kStunAddressOnly;
1344 config.servers.push_back(server);
1345 config.type = PeerConnectionInterface::kRelay;
1346 config.disable_ipv6 = true;
1347 config.tcp_candidate_policy =
1348 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001349 config.candidate_network_policy =
1350 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001351 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001352 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001353
1354 const cricket::FakePortAllocatorSession* session =
1355 static_cast<const cricket::FakePortAllocatorSession*>(
1356 port_allocator_->GetPooledSession());
1357 ASSERT_NE(nullptr, session);
1358 EXPECT_EQ(1UL, session->stun_servers().size());
1359 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1360 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001361 EXPECT_LT(0U,
1362 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001363}
1364
deadbeefd21eab32017-07-26 16:50:11 -07001365// Test that network-related RTCConfiguration members are applied to the
1366// PortAllocator when CreatePeerConnection is called. Specifically:
1367// - disable_ipv6_on_wifi
1368// - max_ipv6_networks
1369// - tcp_candidate_policy
1370// - candidate_network_policy
1371// - prune_turn_ports
1372//
1373// Note that the candidate filter (RTCConfiguration::type) is already tested
1374// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001375TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001376 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1377 // Create fake port allocator.
1378 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1379 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1380 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1381
1382 // Create RTCConfiguration with some network-related fields relevant to
1383 // PortAllocator populated.
1384 PeerConnectionInterface::RTCConfiguration config;
1385 config.disable_ipv6_on_wifi = true;
1386 config.max_ipv6_networks = 10;
1387 config.tcp_candidate_policy =
1388 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1389 config.candidate_network_policy =
1390 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1391 config.prune_turn_ports = true;
1392
1393 // Create the PC factory and PC with the above config.
1394 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1395 webrtc::CreatePeerConnectionFactory(
1396 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001397 rtc::Thread::Current(), fake_audio_capture_module_,
1398 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001399 webrtc::CreateBuiltinAudioDecoderFactory(),
1400 webrtc::CreateBuiltinVideoEncoderFactory(),
1401 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1402 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001403 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001404 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1405 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001406 EXPECT_TRUE(pc.get());
1407 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001408
1409 // Now validate that the config fields set above were applied to the
1410 // PortAllocator, as flags or otherwise.
1411 EXPECT_FALSE(raw_port_allocator->flags() &
1412 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1413 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1414 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1415 EXPECT_TRUE(raw_port_allocator->flags() &
1416 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1417 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1418}
1419
deadbeef46c73892016-11-16 19:42:04 -08001420// Check that GetConfiguration returns the configuration the PeerConnection was
1421// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001422TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001423 PeerConnectionInterface::RTCConfiguration config;
1424 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001425 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001426
1427 PeerConnectionInterface::RTCConfiguration returned_config =
1428 pc_->GetConfiguration();
1429 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1430}
1431
1432// Check that GetConfiguration returns the last configuration passed into
1433// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001434TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001435 PeerConnectionInterface::RTCConfiguration starting_config;
1436 starting_config.bundle_policy =
1437 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1438 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001439
Steve Anton36da6ff2018-02-16 16:04:20 -08001440 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001441 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001442 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001443 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001444 EXPECT_TRUE(pc_->SetConfiguration(config));
1445
1446 PeerConnectionInterface::RTCConfiguration returned_config =
1447 pc_->GetConfiguration();
1448 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001449 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001450 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001451}
1452
Steve Antonc79268f2018-04-24 09:54:10 -07001453TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1454 CreatePeerConnection();
1455
1456 pc_->Close();
1457
1458 EXPECT_FALSE(
1459 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1460}
1461
Steve Anton36da6ff2018-02-16 16:04:20 -08001462TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001463 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001464 AddVideoStream(kStreamId1);
1465 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 ASSERT_EQ(2u, pc_->local_streams()->count());
1467
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001468 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001469 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001470 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001471 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001472 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001473 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001475 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001476 EXPECT_EQ(3u, pc_->local_streams()->count());
1477
1478 // Remove the third stream.
1479 pc_->RemoveStream(pc_->local_streams()->at(2));
1480 EXPECT_EQ(2u, pc_->local_streams()->count());
1481
1482 // Remove the second stream.
1483 pc_->RemoveStream(pc_->local_streams()->at(1));
1484 EXPECT_EQ(1u, pc_->local_streams()->count());
1485
1486 // Remove the first stream.
1487 pc_->RemoveStream(pc_->local_streams()->at(0));
1488 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489}
1490
deadbeefab9b2d12015-10-14 11:33:11 -07001491// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001492// Don't run under Unified Plan since the stream API is not available.
1493TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001494 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001495 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001496 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001497 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001498
deadbeefab9b2d12015-10-14 11:33:11 -07001499 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001500 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001501 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001502
deadbeefab9b2d12015-10-14 11:33:11 -07001503 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001504 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001505 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001506
1507 // Add another stream and ensure the offer includes both the old and new
1508 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001509 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001510 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001511
Steve Antonb1c1de12017-12-21 15:14:30 -08001512 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001513 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1514 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001515
Steve Antonb1c1de12017-12-21 15:14:30 -08001516 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001517 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1518 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001519}
1520
Steve Anton36da6ff2018-02-16 16:04:20 -08001521// Don't run under Unified Plan since the stream API is not available.
1522TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001523 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001524 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 ASSERT_EQ(1u, pc_->local_streams()->count());
1526 pc_->RemoveStream(pc_->local_streams()->at(0));
1527 EXPECT_EQ(0u, pc_->local_streams()->count());
1528}
1529
deadbeefe1f9d832016-01-14 15:35:42 -08001530// Test for AddTrack and RemoveTrack methods.
1531// Tests that the created offer includes tracks we added,
1532// and that the RtpSenders are created correctly.
1533// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001534// Only tested with Plan B since Unified Plan is covered in more detail by tests
1535// in peerconnection_jsep_unittests.cc
1536TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001537 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001538 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001539 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001540 rtc::scoped_refptr<VideoTrackInterface> video_track(
1541 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001542 "video_track", pc_factory_->CreateVideoSource(
1543 std::unique_ptr<cricket::VideoCapturer>(
1544 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001545 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1546 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001547 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001548 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001549 EXPECT_EQ("audio_track", audio_sender->id());
1550 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001551 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001552 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001553 EXPECT_EQ("video_track", video_sender->id());
1554 EXPECT_EQ(video_track, video_sender->track());
1555
1556 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001557 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001558 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 const cricket::ContentInfo* audio_content =
1561 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
1565 const cricket::ContentInfo* video_content =
1566 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001567 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001568 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001569
Steve Antondb45ca82017-09-11 18:27:34 -07001570 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001571
1572 // Now try removing the tracks.
1573 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1574 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1575
1576 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001577 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001578
1579 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001580 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001581 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001582
1583 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001584 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001585 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001586
Steve Antondb45ca82017-09-11 18:27:34 -07001587 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001588
1589 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1590 // should return false.
1591 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1592 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1593}
1594
1595// Test creating senders without a stream specified,
1596// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001597TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001598 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001599 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001600 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001601 rtc::scoped_refptr<VideoTrackInterface> video_track(
1602 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001603 "video_track", pc_factory_->CreateVideoSource(
1604 std::unique_ptr<cricket::VideoCapturer>(
1605 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001606 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001607 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001608 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001609 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001610 EXPECT_EQ("audio_track", audio_sender->id());
1611 EXPECT_EQ(audio_track, audio_sender->track());
1612 EXPECT_EQ("video_track", video_sender->id());
1613 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001614 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1615 // If the ID is truly a random GUID, it should be infinitely unlikely they
1616 // will be the same.
1617 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1618 } else {
1619 // We allows creating tracks without stream ids under Unified Plan
1620 // semantics.
1621 EXPECT_EQ(0u, video_sender->stream_ids().size());
1622 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1623 }
deadbeefe1f9d832016-01-14 15:35:42 -08001624}
1625
Harald Alvestrand89061872018-01-02 14:08:34 +01001626// Test that we can call GetStats() after AddTrack but before connecting
1627// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001628TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001629 CreatePeerConnectionWithoutDtls();
1630 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1631 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1632 rtc::scoped_refptr<VideoTrackInterface> video_track(
1633 pc_factory_->CreateVideoTrack(
1634 "video_track", pc_factory_->CreateVideoSource(
1635 std::unique_ptr<cricket::VideoCapturer>(
1636 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001637 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1638 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001639 EXPECT_TRUE(DoGetStats(nullptr));
1640}
1641
Steve Anton36da6ff2018-02-16 16:04:20 -08001642TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001643 CreatePeerConnectionWithoutDtls();
1644 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1645 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1646 rtc::scoped_refptr<VideoTrackInterface> video_track(
1647 pc_factory_->CreateVideoTrack(
1648 "video_track", pc_factory_->CreateVideoSource(
1649 std::unique_ptr<cricket::VideoCapturer>(
1650 new cricket::FakeVideoCapturer()))));
1651 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001652 ASSERT_TRUE(audio_sender.ok());
1653 auto* audio_sender_proxy =
1654 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1655 audio_sender.value().get());
1656 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1657
Harald Alvestrandc72af932018-01-11 17:18:19 +01001658 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001659 ASSERT_TRUE(video_sender.ok());
1660 auto* video_sender_proxy =
1661 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1662 video_sender.value().get());
1663 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001664}
1665
Steve Anton36da6ff2018-02-16 16:04:20 -08001666// Don't run under Unified Plan since the stream API is not available.
1667TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001668 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001669 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001670 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001671 ASSERT_EQ(1u, senders.size());
1672 auto* sender_proxy =
1673 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1674 senders[0].get());
1675 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001676}
1677
Steve Anton36da6ff2018-02-16 16:04:20 -08001678TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001680 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 VerifyRemoteRtpHeaderExtensions();
1682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001685 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001686 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 CreateOfferAsLocalDescription();
1688 std::string offer;
1689 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1690 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001691 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692}
1693
Steve Anton36da6ff2018-02-16 16:04:20 -08001694TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001695 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001696 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697
1698 CreateOfferAsRemoteDescription();
1699 CreateAnswerAsLocalDescription();
1700
Seth Hampson845e8782018-03-02 11:34:10 -08001701 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702}
1703
Steve Anton36da6ff2018-02-16 16:04:20 -08001704TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001705 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001706 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707
1708 CreateOfferAsRemoteDescription();
1709 CreatePrAnswerAsLocalDescription();
1710 CreateAnswerAsLocalDescription();
1711
Seth Hampson845e8782018-03-02 11:34:10 -08001712 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713}
1714
Steve Anton36da6ff2018-02-16 16:04:20 -08001715// Don't run under Unified Plan since the stream API is not available.
1716TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 InitiateCall();
1718 ASSERT_EQ(1u, pc_->remote_streams()->count());
1719 pc_->RemoveStream(pc_->local_streams()->at(0));
1720 CreateOfferReceiveAnswer();
1721 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001722 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 CreateOfferReceiveAnswer();
1724}
1725
1726// Tests that after negotiating an audio only call, the respondent can perform a
1727// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001728TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001729 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001730 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 CreateOfferAsRemoteDescription();
1732 CreateAnswerAsLocalDescription();
1733
1734 ASSERT_EQ(1u, pc_->remote_streams()->count());
1735 pc_->RemoveStream(pc_->local_streams()->at(0));
1736 CreateOfferReceiveAnswer();
1737 EXPECT_EQ(0u, pc_->remote_streams()->count());
1738}
1739
1740// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001741TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001742 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743
Steve Antonf1c6db12017-10-13 11:13:35 -07001744 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001746 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001747 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001748 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001749 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
1751 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001752 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001753 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001754 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755
Steve Antonf1c6db12017-10-13 11:13:35 -07001756 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001757 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
Steve Antonf1c6db12017-10-13 11:13:35 -07001759 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760}
1761
deadbeefab9b2d12015-10-14 11:33:11 -07001762// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001764TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001765 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001767 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001768 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001769 EXPECT_TRUE(offer);
1770 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771
1772 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001773 AddAudioTrack("track_label", {kStreamId1});
1774 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775
1776 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001777 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778
1779 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001780 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001781 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782}
1783
1784// Test that we will get different SSRCs for each tracks in the offer and answer
1785// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001786TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001787 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001789 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1790 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791
1792 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001793 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001794 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 int audio_ssrc = 0;
1796 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001797 EXPECT_TRUE(
1798 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1799 EXPECT_TRUE(
1800 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 EXPECT_NE(audio_ssrc, video_ssrc);
1802
1803 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001804 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001805 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001806 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 audio_ssrc = 0;
1808 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001809 EXPECT_TRUE(
1810 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1811 EXPECT_TRUE(
1812 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 EXPECT_NE(audio_ssrc, video_ssrc);
1814}
1815
deadbeefeb459812015-12-15 19:24:43 -08001816// Test that it's possible to call AddTrack on a MediaStream after adding
1817// the stream to a PeerConnection.
1818// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001819// Don't run under Unified Plan since the stream API is not available.
1820TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001821 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001822 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001823 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001824 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1825
1826 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001827 rtc::scoped_refptr<VideoTrackInterface> video_track(
1828 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001829 "video_label", pc_factory_->CreateVideoSource(
1830 std::unique_ptr<cricket::VideoCapturer>(
1831 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001832 stream->AddTrack(video_track.get());
1833
kwibergd1fe2812016-04-27 06:47:29 -07001834 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001835 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001836
1837 const cricket::MediaContentDescription* video_desc =
1838 cricket::GetFirstVideoContentDescription(offer->description());
1839 EXPECT_TRUE(video_desc != nullptr);
1840}
1841
1842// Test that it's possible to call RemoveTrack on a MediaStream after adding
1843// the stream to a PeerConnection.
1844// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001845// Don't run under Unified Plan since the stream API is not available.
1846TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001847 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001848 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001849 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001850 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1851
1852 // Remove the video track.
1853 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1854
kwibergd1fe2812016-04-27 06:47:29 -07001855 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001856 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001857
1858 const cricket::MediaContentDescription* video_desc =
1859 cricket::GetFirstVideoContentDescription(offer->description());
1860 EXPECT_TRUE(video_desc == nullptr);
1861}
1862
deadbeefbd7d8f72015-12-18 16:58:44 -08001863// Test creating a sender with a stream ID, and ensure the ID is populated
1864// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001865// Don't run under Unified Plan since the stream API is not available.
1866TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001867 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001868 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001869
kwibergd1fe2812016-04-27 06:47:29 -07001870 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001871 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001872
1873 const cricket::MediaContentDescription* video_desc =
1874 cricket::GetFirstVideoContentDescription(offer->description());
1875 ASSERT_TRUE(video_desc != nullptr);
1876 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001877 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001878}
1879
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001881TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001883 ASSERT_LT(0u, pc_->GetSenders().size());
1884 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001885 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001886 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 EXPECT_TRUE(DoGetStats(remote_audio));
1888
1889 // Remove the stream. Since we are sending to our selves the local
1890 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001891 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 // Do a re-negotiation.
1893 CreateOfferReceiveAnswer();
1894
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 // Test that we still can get statistics for the old track. Even if it is not
1896 // sent any longer.
1897 EXPECT_TRUE(DoGetStats(remote_audio));
1898}
1899
1900// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001901TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001903 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1904 ASSERT_TRUE(video_receiver);
1905 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906}
1907
1908// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001909TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001911 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 pc_factory_->CreateAudioTrack("unknown track", NULL));
1913 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1914}
1915
Steve Anton36da6ff2018-02-16 16:04:20 -08001916TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001917 CreatePeerConnectionWithoutDtls();
1918 EXPECT_TRUE(DoGetRTCStats());
1919 // Clearing stats cache is needed now, but should be temporary.
1920 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1921 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001922 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1923 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001924 EXPECT_TRUE(DoGetRTCStats());
1925 pc_->ClearStatsCache();
1926 CreateOfferReceiveAnswer();
1927 EXPECT_TRUE(DoGetRTCStats());
1928}
1929
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001931TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001932 RTCConfiguration config;
1933 config.enable_rtp_data_channel = true;
1934 config.enable_dtls_srtp = false;
1935 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001936 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001938 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939 pc_->CreateDataChannel("test2", NULL);
1940 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001941 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001943 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 new MockDataChannelObserver(data2));
1945
1946 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1947 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1948 std::string data_to_send1 = "testing testing";
1949 std::string data_to_send2 = "testing something else";
1950 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1951
1952 CreateOfferReceiveAnswer();
1953 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1954 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1955
1956 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1957 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1958 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1959 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1960
1961 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1962 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1963
1964 data1->Close();
1965 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1966 CreateOfferReceiveAnswer();
1967 EXPECT_FALSE(observer1->IsOpen());
1968 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1969 EXPECT_TRUE(observer2->IsOpen());
1970
1971 data_to_send2 = "testing something else again";
1972 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1973
1974 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1975}
1976
1977// This test verifies that sendnig binary data over RTP data channels should
1978// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001979TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001980 RTCConfiguration config;
1981 config.enable_rtp_data_channel = true;
1982 config.enable_dtls_srtp = false;
1983 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001984 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001986 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 pc_->CreateDataChannel("test2", NULL);
1988 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001989 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001991 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 new MockDataChannelObserver(data2));
1993
1994 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1995 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1996
1997 CreateOfferReceiveAnswer();
1998 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1999 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2000
2001 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2002 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2003
jbaucheec21bd2016-03-20 06:15:43 -07002004 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2006}
2007
2008// This test setup a RTP data channels in loop back and test that a channel is
2009// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002010TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002011 RTCConfiguration config;
2012 config.enable_rtp_data_channel = true;
2013 config.enable_dtls_srtp = false;
2014 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002015 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002017 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 new MockDataChannelObserver(data1));
2019
2020 CreateOfferReceiveAnswerWithoutSsrc();
2021
2022 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2023
2024 data1->Close();
2025 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2026 CreateOfferReceiveAnswerWithoutSsrc();
2027 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2028 EXPECT_FALSE(observer1->IsOpen());
2029}
2030
2031// This test that if a data channel is added in an answer a receive only channel
2032// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002033TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002034 RTCConfiguration config;
2035 config.enable_rtp_data_channel = true;
2036 config.enable_dtls_srtp = false;
2037
2038 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002041 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 pc_->CreateDataChannel(offer_label, NULL);
2043
2044 CreateOfferAsLocalDescription();
2045
2046 // Replace the data channel label in the offer and apply it as an answer.
2047 std::string receive_label = "answer_channel";
2048 std::string sdp;
2049 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002050 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002051 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 CreateAnswerAsRemoteDescription(sdp);
2053
2054 // Verify that a new incoming data channel has been created and that
2055 // it is open but can't we written to.
2056 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2057 DataChannelInterface* received_channel = observer_.last_datachannel_;
2058 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2059 EXPECT_EQ(receive_label, received_channel->label());
2060 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2061
2062 // Verify that the channel we initially offered has been rejected.
2063 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2064
2065 // Do another offer / answer exchange and verify that the data channel is
2066 // opened.
2067 CreateOfferReceiveAnswer();
2068 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2069 kTimeout);
2070}
2071
2072// This test that no data channel is returned if a reliable channel is
2073// requested.
2074// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002075TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002076 RTCConfiguration rtc_config;
2077 rtc_config.enable_rtp_data_channel = true;
2078 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079
2080 std::string label = "test";
2081 webrtc::DataChannelInit config;
2082 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002083 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 pc_->CreateDataChannel(label, &config);
2085 EXPECT_TRUE(channel == NULL);
2086}
2087
deadbeefab9b2d12015-10-14 11:33:11 -07002088// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002089TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002090 RTCConfiguration config;
2091 config.enable_rtp_data_channel = true;
2092 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002093
2094 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002095 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002096 pc_->CreateDataChannel(label, nullptr);
2097 EXPECT_NE(channel, nullptr);
2098
zhihuang9763d562016-08-05 11:14:50 -07002099 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002100 pc_->CreateDataChannel(label, nullptr);
2101 EXPECT_EQ(dup_channel, nullptr);
2102}
2103
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104// This tests that a SCTP data channel is returned using different
2105// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002106TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002107 RTCConfiguration rtc_config;
2108 rtc_config.enable_dtls_srtp = true;
2109 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
2111 webrtc::DataChannelInit config;
2112
zhihuang9763d562016-08-05 11:14:50 -07002113 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 pc_->CreateDataChannel("1", &config);
2115 EXPECT_TRUE(channel != NULL);
2116 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002117 EXPECT_TRUE(observer_.renegotiation_needed_);
2118 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119
2120 config.ordered = false;
2121 channel = pc_->CreateDataChannel("2", &config);
2122 EXPECT_TRUE(channel != NULL);
2123 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002124 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
2126 config.ordered = true;
2127 config.maxRetransmits = 0;
2128 channel = pc_->CreateDataChannel("3", &config);
2129 EXPECT_TRUE(channel != NULL);
2130 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002131 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132
2133 config.maxRetransmits = -1;
2134 config.maxRetransmitTime = 0;
2135 channel = pc_->CreateDataChannel("4", &config);
2136 EXPECT_TRUE(channel != NULL);
2137 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002138 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139}
2140
2141// This tests that no data channel is returned if both maxRetransmits and
2142// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002143TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002145 RTCConfiguration rtc_config;
2146 rtc_config.enable_dtls_srtp = true;
2147 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148
2149 std::string label = "test";
2150 webrtc::DataChannelInit config;
2151 config.maxRetransmits = 0;
2152 config.maxRetransmitTime = 0;
2153
zhihuang9763d562016-08-05 11:14:50 -07002154 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 pc_->CreateDataChannel(label, &config);
2156 EXPECT_TRUE(channel == NULL);
2157}
2158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159// The test verifies that creating a SCTP data channel with an id already in use
2160// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002161TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002163 RTCConfiguration rtc_config;
2164 rtc_config.enable_dtls_srtp = true;
2165 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166
2167 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002168 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002170 config.id = 1;
2171 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 EXPECT_TRUE(channel != NULL);
2173 EXPECT_EQ(1, channel->id());
2174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 channel = pc_->CreateDataChannel("x", &config);
2176 EXPECT_TRUE(channel == NULL);
2177
2178 config.id = cricket::kMaxSctpSid;
2179 channel = pc_->CreateDataChannel("max", &config);
2180 EXPECT_TRUE(channel != NULL);
2181 EXPECT_EQ(config.id, channel->id());
2182
2183 config.id = cricket::kMaxSctpSid + 1;
2184 channel = pc_->CreateDataChannel("x", &config);
2185 EXPECT_TRUE(channel == NULL);
2186}
2187
deadbeefab9b2d12015-10-14 11:33:11 -07002188// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002189TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002190 RTCConfiguration rtc_config;
2191 rtc_config.enable_dtls_srtp = true;
2192 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002193
2194 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002195 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002196 pc_->CreateDataChannel(label, nullptr);
2197 EXPECT_NE(channel, nullptr);
2198
zhihuang9763d562016-08-05 11:14:50 -07002199 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002200 pc_->CreateDataChannel(label, nullptr);
2201 EXPECT_NE(dup_channel, nullptr);
2202}
2203
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002204// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2205// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002206TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002207 RTCConfiguration rtc_config;
2208 rtc_config.enable_rtp_data_channel = true;
2209 rtc_config.enable_dtls_srtp = false;
2210 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002211
zhihuang9763d562016-08-05 11:14:50 -07002212 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002213 pc_->CreateDataChannel("test1", NULL);
2214 EXPECT_TRUE(observer_.renegotiation_needed_);
2215 observer_.renegotiation_needed_ = false;
2216
zhihuang9763d562016-08-05 11:14:50 -07002217 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002218 pc_->CreateDataChannel("test2", NULL);
2219 EXPECT_TRUE(observer_.renegotiation_needed_);
2220}
2221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002223TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002224 RTCConfiguration rtc_config;
2225 rtc_config.enable_rtp_data_channel = true;
2226 rtc_config.enable_dtls_srtp = false;
2227 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228
zhihuang9763d562016-08-05 11:14:50 -07002229 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002231 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 pc_->CreateDataChannel("test2", NULL);
2233 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002234 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002236 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 new MockDataChannelObserver(data2));
2238
2239 CreateOfferReceiveAnswer();
2240 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2241 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2242
2243 ReleasePeerConnection();
2244 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2245 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2246}
2247
Zhi Huang644fde42018-04-02 19:16:26 -07002248// This tests that RTP data channels can be rejected in an answer.
2249TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002250 RTCConfiguration rtc_config;
2251 rtc_config.enable_rtp_data_channel = true;
2252 rtc_config.enable_dtls_srtp = false;
2253 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254
zhihuang9763d562016-08-05 11:14:50 -07002255 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 pc_->CreateDataChannel("offer_channel", NULL));
2257
2258 CreateOfferAsLocalDescription();
2259
2260 // Create an answer where the m-line for data channels are rejected.
2261 std::string sdp;
2262 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002263 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002264 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002265 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002267 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 data_info->rejected = true;
2269
Steve Antondb45ca82017-09-11 18:27:34 -07002270 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2272}
2273
Zhi Huang644fde42018-04-02 19:16:26 -07002274#ifdef HAVE_SCTP
2275// This tests that SCTP data channels can be rejected in an answer.
2276TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2277#else
2278TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2279#endif
2280{
Niels Möllerf06f9232018-08-07 12:32:18 +02002281 RTCConfiguration rtc_config;
2282 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002283
2284 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2285 pc_->CreateDataChannel("offer_channel", NULL));
2286
2287 CreateOfferAsLocalDescription();
2288
2289 // Create an answer where the m-line for data channels are rejected.
2290 std::string sdp;
2291 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2292 std::unique_ptr<SessionDescriptionInterface> answer(
2293 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2294 ASSERT_TRUE(answer);
2295 cricket::ContentInfo* data_info =
2296 cricket::GetFirstDataContent(answer->description());
2297 data_info->rejected = true;
2298
2299 DoSetRemoteDescription(std::move(answer));
2300 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2301}
2302
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303// Test that we can create a session description from an SDP string from
2304// FireFox, use it as a remote session description, generate an answer and use
2305// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002306TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002307 RTCConfiguration rtc_config;
2308 rtc_config.enable_dtls_srtp = true;
2309 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002310 AddAudioTrack("audio_label");
2311 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002312 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002313 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002314 webrtc::kFireFoxSdpOffer, nullptr));
2315 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 CreateAnswerAsLocalDescription();
2317 ASSERT_TRUE(pc_->local_description() != NULL);
2318 ASSERT_TRUE(pc_->remote_description() != NULL);
2319
2320 const cricket::ContentInfo* content =
2321 cricket::GetFirstAudioContent(pc_->local_description()->description());
2322 ASSERT_TRUE(content != NULL);
2323 EXPECT_FALSE(content->rejected);
2324
2325 content =
2326 cricket::GetFirstVideoContent(pc_->local_description()->description());
2327 ASSERT_TRUE(content != NULL);
2328 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002329#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 content =
2331 cricket::GetFirstDataContent(pc_->local_description()->description());
2332 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002333 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002334#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335}
2336
zhihuangb19012e2017-09-19 13:47:59 -07002337// Test that fallback from DTLS to SDES is not supported.
2338// The fallback was previously supported but was removed to simplify the code
2339// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002340TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002341 RTCConfiguration rtc_config;
2342 rtc_config.enable_dtls_srtp = true;
2343 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002344 // Wait for fake certificate to be generated. Previously, this is what caused
2345 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002346 AddAudioTrack("audio_label");
2347 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002348 ASSERT_NE(nullptr, fake_certificate_generator_);
2349 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2350 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002351 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002352 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2353 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002354 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002355}
2356
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357// Test that we can create an audio only offer and receive an answer with a
2358// limited set of audio codecs and receive an updated offer with more audio
2359// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002360TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002361 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002362 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 CreateOfferAsLocalDescription();
2364
Steve Anton36da6ff2018-02-16 16:04:20 -08002365 const char* answer_sdp =
2366 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2367 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002368 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002369 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002370 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371
Steve Anton36da6ff2018-02-16 16:04:20 -08002372 const char* reoffer_sdp =
2373 (sdp_semantics_ == SdpSemantics::kPlanB
2374 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2375 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002376 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002377 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002378 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 CreateAnswerAsLocalDescription();
2380}
2381
deadbeefc80741f2015-10-22 13:14:45 -07002382// Test that if we're receiving (but not sending) a track, subsequent offers
2383// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002384TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002385 RTCConfiguration rtc_config;
2386 rtc_config.enable_dtls_srtp = true;
2387 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002388 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002389 CreateAnswerAsLocalDescription();
2390
2391 // At this point we should be receiving stream 1, but not sending anything.
2392 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002393 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002394 DoCreateOffer(&offer, nullptr);
2395
2396 const cricket::ContentInfo* video_content =
2397 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002398 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2399 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002400
2401 const cricket::ContentInfo* audio_content =
2402 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002403 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2404 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002405}
2406
2407// Test that if we're receiving (but not sending) a track, and the
2408// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2409// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002410TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002411 RTCConfiguration rtc_config;
2412 rtc_config.enable_dtls_srtp = true;
2413 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002414 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002415 CreateAnswerAsLocalDescription();
2416
2417 // At this point we should be receiving stream 1, but not sending anything.
2418 // A new offer would be recvonly, but we'll set the "no receive" constraints
2419 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002420 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002421 RTCOfferAnswerOptions options;
2422 options.offer_to_receive_audio = 0;
2423 options.offer_to_receive_video = 0;
2424 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002425
2426 const cricket::ContentInfo* video_content =
2427 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002428 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2429 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002430
2431 const cricket::ContentInfo* audio_content =
2432 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002433 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2434 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002435}
2436
deadbeef653b8e02015-11-11 12:55:10 -08002437// Test that we can use SetConfiguration to change the ICE servers of the
2438// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002439TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002440 CreatePeerConnection();
2441
Steve Anton36da6ff2018-02-16 16:04:20 -08002442 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002443 PeerConnectionInterface::IceServer server;
2444 server.uri = "stun:test_hostname";
2445 config.servers.push_back(server);
2446 EXPECT_TRUE(pc_->SetConfiguration(config));
2447
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002448 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2449 EXPECT_EQ("test_hostname",
2450 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002451}
2452
Steve Anton36da6ff2018-02-16 16:04:20 -08002453TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002454 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002455 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002456 config.type = PeerConnectionInterface::kRelay;
2457 EXPECT_TRUE(pc_->SetConfiguration(config));
2458 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2459}
2460
Steve Anton36da6ff2018-02-16 16:04:20 -08002461TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002462 PeerConnectionInterface::RTCConfiguration config;
2463 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002464 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002465 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002466 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2467
2468 config.prune_turn_ports = true;
2469 EXPECT_TRUE(pc_->SetConfiguration(config));
2470 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2471}
2472
skvladd1f5fda2017-02-03 16:54:05 -08002473// Test that the ice check interval can be changed. This does not verify that
2474// the setting makes it all the way to P2PTransportChannel, as that would
2475// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002476TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002477 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002478 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002479 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002480 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002481 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002482 EXPECT_TRUE(pc_->SetConfiguration(config));
2483 PeerConnectionInterface::RTCConfiguration new_config =
2484 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002485 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002486}
2487
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002488// Test that when SetConfiguration changes both the pool size and other
2489// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002490TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002491 SetConfigurationCreatesPooledSessionCorrectly) {
2492 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002493 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002494 config.ice_candidate_pool_size = 1;
2495 PeerConnectionInterface::IceServer server;
2496 server.uri = kStunAddressOnly;
2497 config.servers.push_back(server);
2498 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002499 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002500
2501 const cricket::FakePortAllocatorSession* session =
2502 static_cast<const cricket::FakePortAllocatorSession*>(
2503 port_allocator_->GetPooledSession());
2504 ASSERT_NE(nullptr, session);
2505 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002506}
2507
deadbeef293e9262017-01-11 12:28:30 -08002508// Test that after SetLocalDescription, changing the pool size is not allowed,
2509// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002510TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002511 CantChangePoolSizeAfterSetLocalDescription) {
2512 CreatePeerConnection();
2513 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002514 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002515 config.ice_candidate_pool_size = 1;
2516 EXPECT_TRUE(pc_->SetConfiguration(config));
2517
2518 // Set remote offer; can still change pool size at this point.
2519 CreateOfferAsRemoteDescription();
2520 config.ice_candidate_pool_size = 2;
2521 EXPECT_TRUE(pc_->SetConfiguration(config));
2522
2523 // Set local answer; now it's too late.
2524 CreateAnswerAsLocalDescription();
2525 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002526 RTCError error;
2527 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2528 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2529}
2530
deadbeef42a42632017-03-10 15:18:00 -08002531// Test that after setting an answer, extra pooled sessions are discarded. The
2532// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002533TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002534 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2535 CreatePeerConnection();
2536
2537 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002538 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002539 config.ice_candidate_pool_size = 4;
2540 EXPECT_TRUE(pc_->SetConfiguration(config));
2541
2542 // Do offer/answer.
2543 CreateOfferAsRemoteDescription();
2544 CreateAnswerAsLocalDescription();
2545
2546 // Expect no pooled sessions to be left.
2547 const cricket::PortAllocatorSession* session =
2548 port_allocator_->GetPooledSession();
2549 EXPECT_EQ(nullptr, session);
2550}
2551
2552// After Close is called, pooled candidates should be discarded so as to not
2553// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002554TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002555 CreatePeerConnection();
2556
Steve Anton36da6ff2018-02-16 16:04:20 -08002557 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002558 config.ice_candidate_pool_size = 3;
2559 EXPECT_TRUE(pc_->SetConfiguration(config));
2560 pc_->Close();
2561
2562 // Expect no pooled sessions to be left.
2563 const cricket::PortAllocatorSession* session =
2564 port_allocator_->GetPooledSession();
2565 EXPECT_EQ(nullptr, session);
2566}
2567
deadbeef293e9262017-01-11 12:28:30 -08002568// Test that SetConfiguration returns an invalid modification error if
2569// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002570TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002571 SetConfigurationReturnsInvalidModificationError) {
2572 PeerConnectionInterface::RTCConfiguration config;
2573 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2574 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2575 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002576 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002577
Steve Anton36da6ff2018-02-16 16:04:20 -08002578 PeerConnectionInterface::RTCConfiguration modified_config =
2579 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002580 modified_config.bundle_policy =
2581 PeerConnectionInterface::kBundlePolicyMaxBundle;
2582 RTCError error;
2583 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2584 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2585
Steve Anton36da6ff2018-02-16 16:04:20 -08002586 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002587 modified_config.rtcp_mux_policy =
2588 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2589 error.set_type(RTCErrorType::NONE);
2590 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2591 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2592
Steve Anton36da6ff2018-02-16 16:04:20 -08002593 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002594 modified_config.continual_gathering_policy =
2595 PeerConnectionInterface::GATHER_CONTINUALLY;
2596 error.set_type(RTCErrorType::NONE);
2597 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2598 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2599}
2600
2601// Test that SetConfiguration returns a range error if the candidate pool size
2602// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002603TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002604 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2605 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002606 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002607 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002608
2609 config.ice_candidate_pool_size = -1;
2610 RTCError error;
2611 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2612 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2613
2614 config.ice_candidate_pool_size = INT_MAX;
2615 error.set_type(RTCErrorType::NONE);
2616 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2617 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2618}
2619
2620// Test that SetConfiguration returns a syntax error if parsing an ICE server
2621// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002622TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002623 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2624 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002625 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002626 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002627
2628 PeerConnectionInterface::IceServer bad_server;
2629 bad_server.uri = "stunn:www.example.com";
2630 config.servers.push_back(bad_server);
2631 RTCError error;
2632 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2633 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2634}
2635
2636// Test that SetConfiguration returns an invalid parameter error if a TURN
2637// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002638TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002639 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
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 PeerConnectionInterface::IceServer bad_server;
2645 bad_server.uri = "turn:www.example.com";
2646 // Missing password.
2647 bad_server.username = "foo";
2648 config.servers.push_back(bad_server);
2649 RTCError error;
2650 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2651 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002652}
2653
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654// Test that PeerConnection::Close changes the states to closed and all remote
2655// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002656TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657 // Initialize a PeerConnection and negotiate local and remote session
2658 // description.
2659 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002660
2661 // With Plan B, verify the stream count. The analog with Unified Plan is the
2662 // RtpTransceiver count.
2663 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2664 ASSERT_EQ(1u, pc_->local_streams()->count());
2665 ASSERT_EQ(1u, pc_->remote_streams()->count());
2666 } else {
2667 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2668 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669
2670 pc_->Close();
2671
2672 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2673 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2674 pc_->ice_connection_state());
2675 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2676 pc_->ice_gathering_state());
2677
Steve Anton36da6ff2018-02-16 16:04:20 -08002678 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2679 EXPECT_EQ(1u, pc_->local_streams()->count());
2680 EXPECT_EQ(1u, pc_->remote_streams()->count());
2681 } else {
2682 // Verify that the RtpTransceivers are still present but all stopped.
2683 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2684 for (auto transceiver : pc_->GetTransceivers()) {
2685 EXPECT_TRUE(transceiver->stopped());
2686 }
2687 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688
Steve Anton36da6ff2018-02-16 16:04:20 -08002689 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2690 ASSERT_TRUE(audio_receiver);
2691 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2692 ASSERT_TRUE(video_receiver);
2693
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002694 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002695 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002696 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002697 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002698 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699}
2700
2701// Test that PeerConnection methods fails gracefully after
2702// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002703// Don't run under Unified Plan since the stream API is not available.
2704TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002705 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002706 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 CreateOfferAsRemoteDescription();
2708 CreateAnswerAsLocalDescription();
2709
2710 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002711 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 pc_->local_streams()->at(0);
2713
2714 pc_->Close();
2715
2716 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002717 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2720
2721 EXPECT_TRUE(pc_->local_description() != NULL);
2722 EXPECT_TRUE(pc_->remote_description() != NULL);
2723
kwibergd1fe2812016-04-27 06:47:29 -07002724 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002725 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002726 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002727 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728
2729 std::string sdp;
2730 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002731 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002732 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002733 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734
2735 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002736 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002737 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002738 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739}
2740
2741// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002742TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 InitiateCall();
2744 pc_->Close();
2745 DoGetStats(NULL);
2746}
deadbeefab9b2d12015-10-14 11:33:11 -07002747
2748// NOTE: The series of tests below come from what used to be
2749// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2750// setting a remote or local description has the expected effects.
2751
2752// This test verifies that the remote MediaStreams corresponding to a received
2753// SDP string is created. In this test the two separate MediaStreams are
2754// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002755TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002756 RTCConfiguration config;
2757 config.enable_dtls_srtp = true;
2758 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002759 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002760
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002761 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002762 EXPECT_TRUE(
2763 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2764 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2765 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2766
2767 // Create a session description based on another SDP with another
2768 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002769 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002770
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002771 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002772 EXPECT_TRUE(
2773 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2774}
2775
2776// This test verifies that when remote tracks are added/removed from SDP, the
2777// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002778// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2779// specific behavior.
2780TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002781 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002782 RTCConfiguration config;
2783 config.enable_dtls_srtp = true;
2784 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002785 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002786 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002787 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002788 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2789 reference_collection_));
2790
2791 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002792 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002793 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002794 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002795 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2796 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002797 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002798 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2799 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002800 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002801 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2802 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002803
2804 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002805 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002806 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002807 MockTrackObserver audio_track_observer(audio_track2);
2808 MockTrackObserver video_track_observer(video_track2);
2809
2810 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2811 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002812 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002813 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2814 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002815 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002816 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002817 audio_track2->state(), kTimeout);
2818 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2819 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002820}
2821
2822// This tests that remote tracks are ended if a local session description is set
2823// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002824TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002825 RTCConfiguration config;
2826 config.enable_dtls_srtp = true;
2827 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002828 // First create and set a remote offer, then reject its video content in our
2829 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002830 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2831 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2832 ASSERT_TRUE(audio_receiver);
2833 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2834 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002835
Steve Anton36da6ff2018-02-16 16:04:20 -08002836 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2837 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002838 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002839 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2840 video_receiver->track();
2841 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002842
kwibergd1fe2812016-04-27 06:47:29 -07002843 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002844 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002845 cricket::ContentInfo* video_info =
2846 local_answer->description()->GetContentByName("video");
2847 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002848 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002849 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2850 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002851
2852 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002853 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002854 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002855 video_info = local_offer->description()->GetContentByName("video");
2856 ASSERT_TRUE(video_info != nullptr);
2857 video_info->rejected = true;
2858 cricket::ContentInfo* audio_info =
2859 local_offer->description()->GetContentByName("audio");
2860 ASSERT_TRUE(audio_info != nullptr);
2861 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002862 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002863 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002864 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2865 kTimeout);
2866 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2867 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002868}
2869
2870// This tests that we won't crash if the remote track has been removed outside
2871// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002872// Don't run under Unified Plan since the stream API is not available.
2873TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002874 RTCConfiguration config;
2875 config.enable_dtls_srtp = true;
2876 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002877 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002878 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2879 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2880 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2881
kwibergd1fe2812016-04-27 06:47:29 -07002882 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002883 webrtc::CreateSessionDescription(SdpType::kAnswer,
2884 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002885 cricket::ContentInfo* video_info =
2886 local_answer->description()->GetContentByName("video");
2887 video_info->rejected = true;
2888 cricket::ContentInfo* audio_info =
2889 local_answer->description()->GetContentByName("audio");
2890 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002891 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002892
2893 // No crash is a pass.
2894}
2895
deadbeef5e97fb52015-10-15 12:49:08 -07002896// This tests that if a recvonly remote description is set, no remote streams
2897// will be created, even if the description contains SSRCs/MSIDs.
2898// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002899TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002900 RTCConfiguration config;
2901 config.enable_dtls_srtp = true;
2902 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002903
Steve Anton36da6ff2018-02-16 16:04:20 -08002904 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002905 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2906 strlen(kRecvonly), &recvonly_offer);
2907 CreateAndSetRemoteOffer(recvonly_offer);
2908
2909 EXPECT_EQ(0u, observer_.remote_streams()->count());
2910}
2911
deadbeefab9b2d12015-10-14 11:33:11 -07002912// This tests that a default MediaStream is created if a remote session
2913// description doesn't contain any streams and no MSID support.
2914// It also tests that the default stream is updated if a video m-line is added
2915// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002916// Don't run under Unified Plan since this behavior is Plan B specific.
2917TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002918 RTCConfiguration config;
2919 config.enable_dtls_srtp = true;
2920 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002921 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2922
2923 ASSERT_EQ(1u, observer_.remote_streams()->count());
2924 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2925
2926 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2927 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002928 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002929
2930 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2931 ASSERT_EQ(1u, observer_.remote_streams()->count());
2932 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2933 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002934 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2935 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002936 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2937 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002938 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2939 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002940}
2941
2942// This tests that a default MediaStream is created if a remote session
2943// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002944// Don't run under Unified Plan since this behavior is Plan B specific.
2945TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002946 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002947 RTCConfiguration config;
2948 config.enable_dtls_srtp = true;
2949 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002950 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2951
2952 ASSERT_EQ(1u, observer_.remote_streams()->count());
2953 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2954
2955 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2956 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002957 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002958}
2959
2960// This tests that it won't crash when PeerConnection tries to remove
2961// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002962// Don't run under Unified Plan since this behavior is Plan B specific.
2963TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002964 RTCConfiguration config;
2965 config.enable_dtls_srtp = true;
2966 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002967 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002968 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2969 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2970 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2971
2972 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2973
2974 // No crash is a pass.
2975}
2976
2977// This tests that a default MediaStream is created if the remote session
2978// description doesn't contain any streams and don't contain an indication if
2979// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002980// Don't run under Unified Plan since this behavior is Plan B specific.
2981TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002982 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002983 RTCConfiguration config;
2984 config.enable_dtls_srtp = true;
2985 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002986 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2987
2988 ASSERT_EQ(1u, observer_.remote_streams()->count());
2989 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2990 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2991 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2992}
2993
2994// This tests that a default MediaStream is not created if the remote session
2995// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002996// Don't run under Unified Plan since this behavior is Plan B specific.
2997TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002998 RTCConfiguration config;
2999 config.enable_dtls_srtp = true;
3000 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003001 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3002 EXPECT_EQ(0u, observer_.remote_streams()->count());
3003}
3004
deadbeefbda7e0b2015-12-08 17:13:40 -08003005// This tests that when setting a new description, the old default tracks are
3006// not destroyed and recreated.
3007// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003008// Don't run under Unified Plan since this behavior is Plan B specific.
3009TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003010 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003011 RTCConfiguration config;
3012 config.enable_dtls_srtp = true;
3013 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003014 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3015
3016 ASSERT_EQ(1u, observer_.remote_streams()->count());
3017 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3018 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3019
3020 // Set the track to "disabled", then set a new description and ensure the
3021 // track is still disabled, which ensures it hasn't been recreated.
3022 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3023 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3024 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3025 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3026}
3027
deadbeefab9b2d12015-10-14 11:33:11 -07003028// This tests that a default MediaStream is not created if a remote session
3029// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003030// Don't run under Unified Plan since this behavior is Plan B specific.
3031TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003032 RTCConfiguration config;
3033 config.enable_dtls_srtp = true;
3034 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003035 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003036 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003037 EXPECT_TRUE(
3038 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3039
3040 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3041 EXPECT_EQ(0u, observer_.remote_streams()->count());
3042}
3043
Seth Hampson5897a6e2018-04-03 11:16:33 -07003044// This tests that a default MediaStream is created if a remote SDP comes from
3045// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3046TEST_F(PeerConnectionInterfaceTestPlanB,
3047 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003048 RTCConfiguration config;
3049 config.enable_dtls_srtp = true;
3050 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003051 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3052 // Add a=msid lines to simulate a Unified Plan endpoint that only
3053 // signals stream IDs with a=msid lines.
3054 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3055
3056 CreateAndSetRemoteOffer(sdp_string);
3057
3058 ASSERT_EQ(1u, observer_.remote_streams()->count());
3059 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3060 EXPECT_EQ("default", remote_stream->id());
3061 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3062}
3063
Seth Hampson5b4f0752018-04-02 16:31:36 -07003064// This tests that when a Plan B endpoint receives an SDP that signals no media
3065// stream IDs indicated by the special character "-" in the a=msid line, that
3066// a default stream ID will be used for the MediaStream ID. This can occur
3067// when a Unified Plan endpoint signals no media stream IDs, but signals both
3068// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3069TEST_F(PeerConnectionInterfaceTestPlanB,
3070 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003071 RTCConfiguration config;
3072 config.enable_dtls_srtp = true;
3073 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003074 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3075 // the sender's stream ID will be interpreted as no stream IDs.
3076 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3077 sdp_string.append("a=msid:- audiotrack0\n");
3078
3079 CreateAndSetRemoteOffer(sdp_string);
3080
3081 ASSERT_EQ(1u, observer_.remote_streams()->count());
3082 // Because SSRCs are signaled the track ID will be what was signaled in the
3083 // a=msid line.
3084 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3085 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3086 EXPECT_EQ("default", remote_stream->id());
3087 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003088
3089 // Previously a bug ocurred when setting the remote description a second time.
3090 // This is because we checked equality of the remote StreamParams stream ID
3091 // (empty), and the previously set stream ID for the remote sender
3092 // ("default"). This cause a track to be removed, then added, when really
3093 // nothing should occur because it is the same track.
3094 CreateAndSetRemoteOffer(sdp_string);
3095 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3096 EXPECT_EQ(1u, observer_.add_track_events_.size());
3097 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3098 remote_stream = observer_.remote_streams()->at(0);
3099 EXPECT_EQ("default", remote_stream->id());
3100 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003101}
3102
deadbeefab9b2d12015-10-14 11:33:11 -07003103// This tests that an RtpSender is created when the local description is set
3104// after adding a local stream.
3105// TODO(deadbeef): This test and the one below it need to be updated when
3106// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003107// Don't run under Unified Plan since this behavior is Plan B specific.
3108TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003109 RTCConfiguration config;
3110 config.enable_dtls_srtp = true;
3111 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003112
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003113 // Create an offer with 1 stream with 2 tracks of each type.
3114 rtc::scoped_refptr<StreamCollection> stream_collection =
3115 CreateStreamCollection(1, 2);
3116 pc_->AddStream(stream_collection->at(0));
3117 std::unique_ptr<SessionDescriptionInterface> offer;
3118 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003119 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003120
deadbeefab9b2d12015-10-14 11:33:11 -07003121 auto senders = pc_->GetSenders();
3122 EXPECT_EQ(4u, senders.size());
3123 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3124 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3125 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3126 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3127
3128 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003129 pc_->RemoveStream(stream_collection->at(0));
3130 stream_collection = CreateStreamCollection(1, 1);
3131 pc_->AddStream(stream_collection->at(0));
3132 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003133 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003134
deadbeefab9b2d12015-10-14 11:33:11 -07003135 senders = pc_->GetSenders();
3136 EXPECT_EQ(2u, senders.size());
3137 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3138 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3139 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3140 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3141}
3142
3143// This tests that an RtpSender is created when the local description is set
3144// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003145// Don't run under Unified Plan since this behavior is Plan B specific.
3146TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003147 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003148 RTCConfiguration config;
3149 config.enable_dtls_srtp = true;
3150 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003151
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003152 rtc::scoped_refptr<StreamCollection> stream_collection =
3153 CreateStreamCollection(1, 2);
3154 // Add a stream to create the offer, but remove it afterwards.
3155 pc_->AddStream(stream_collection->at(0));
3156 std::unique_ptr<SessionDescriptionInterface> offer;
3157 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3158 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003159
Steve Antondb45ca82017-09-11 18:27:34 -07003160 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003161 auto senders = pc_->GetSenders();
3162 EXPECT_EQ(0u, senders.size());
3163
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003164 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003165 senders = pc_->GetSenders();
3166 EXPECT_EQ(4u, senders.size());
3167 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3168 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3169 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3170 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3171}
3172
3173// This tests that the expected behavior occurs if the SSRC on a local track is
3174// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003175TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003176 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003177 RTCConfiguration config;
3178 config.enable_dtls_srtp = true;
3179 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003180
Steve Anton36da6ff2018-02-16 16:04:20 -08003181 AddAudioTrack(kAudioTracks[0]);
3182 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003183 std::unique_ptr<SessionDescriptionInterface> offer;
3184 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3185 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003186 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3187 webrtc::CreateSessionDescription(
3188 webrtc::SdpType::kOffer, offer->session_id(),
3189 offer->session_version(),
3190 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003191 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003192
deadbeefab9b2d12015-10-14 11:33:11 -07003193 auto senders = pc_->GetSenders();
3194 EXPECT_EQ(2u, senders.size());
3195 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3196 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3197
3198 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003199 cricket::MediaContentDescription* desc =
3200 cricket::GetFirstAudioContentDescription(modified_offer->description());
3201 ASSERT_TRUE(desc != NULL);
3202 for (StreamParams& stream : desc->mutable_streams()) {
3203 for (unsigned int& ssrc : stream.ssrcs) {
3204 ++ssrc;
3205 }
3206 }
deadbeefab9b2d12015-10-14 11:33:11 -07003207
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003208 desc =
3209 cricket::GetFirstVideoContentDescription(modified_offer->description());
3210 ASSERT_TRUE(desc != NULL);
3211 for (StreamParams& stream : desc->mutable_streams()) {
3212 for (unsigned int& ssrc : stream.ssrcs) {
3213 ++ssrc;
3214 }
3215 }
3216
Steve Antondb45ca82017-09-11 18:27:34 -07003217 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003218 senders = pc_->GetSenders();
3219 EXPECT_EQ(2u, senders.size());
3220 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3221 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3222 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3223 // changed.
3224}
3225
3226// This tests that the expected behavior occurs if a new session description is
3227// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003228// Don't run under Unified Plan since the stream API is not available.
3229TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003230 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003231 RTCConfiguration config;
3232 config.enable_dtls_srtp = true;
3233 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003234
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003235 rtc::scoped_refptr<StreamCollection> stream_collection =
3236 CreateStreamCollection(2, 1);
3237 pc_->AddStream(stream_collection->at(0));
3238 std::unique_ptr<SessionDescriptionInterface> offer;
3239 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003240 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003241
deadbeefab9b2d12015-10-14 11:33:11 -07003242 auto senders = pc_->GetSenders();
3243 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003244 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3245 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003246
3247 // Add a new MediaStream but with the same tracks as in the first stream.
3248 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3249 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003250 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3251 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003252 pc_->AddStream(stream_1);
3253
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003254 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003255 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003256
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003257 auto new_senders = pc_->GetSenders();
3258 // Should be the same senders as before, but with updated stream id.
3259 // Note that this behavior is subject to change in the future.
3260 // We may decide the PC should ignore existing tracks in AddStream.
3261 EXPECT_EQ(senders, new_senders);
3262 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3263 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003264}
3265
zhihuang81c3a032016-11-17 12:06:24 -08003266// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003267TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003268 RTCConfiguration config;
3269 config.enable_dtls_srtp = true;
3270 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003271 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3272 EXPECT_EQ(observer_.num_added_tracks_, 1);
3273 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3274
3275 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003276 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003277 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003278 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3279}
3280
deadbeefd1a38b52016-12-10 13:15:33 -08003281// Test that when SetConfiguration is called and the configuration is
3282// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003283TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003284 PeerConnectionInterface::RTCConfiguration config;
3285 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003286 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003287 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003288 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3289 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003290
3291 // Do initial offer/answer so there's something to restart.
3292 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003293 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003294
3295 // Grab the ufrags.
3296 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3297
3298 // Change ICE policy, which should trigger an ICE restart on the next offer.
3299 config.type = PeerConnectionInterface::kAll;
3300 EXPECT_TRUE(pc_->SetConfiguration(config));
3301 CreateOfferAsLocalDescription();
3302
3303 // Grab the new ufrags.
3304 std::vector<std::string> subsequent_ufrags =
3305 GetUfrags(pc_->local_description());
3306
3307 // Sanity check.
3308 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3309 // Check that each ufrag is different.
3310 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3311 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3312 }
3313}
3314
3315// Test that when SetConfiguration is called and the configuration *isn't*
3316// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003317TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003318 PeerConnectionInterface::RTCConfiguration config;
3319 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003320 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003321 config = pc_->GetConfiguration();
3322 AddAudioTrack(kAudioTracks[0]);
3323 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003324
3325 // Do initial offer/answer so there's something to restart.
3326 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003327 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003328
3329 // Grab the ufrags.
3330 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3331
3332 // Call SetConfiguration with a config identical to what the PC was
3333 // constructed with.
3334 EXPECT_TRUE(pc_->SetConfiguration(config));
3335 CreateOfferAsLocalDescription();
3336
3337 // Grab the new ufrags.
3338 std::vector<std::string> subsequent_ufrags =
3339 GetUfrags(pc_->local_description());
3340
3341 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3342}
3343
3344// Test for a weird corner case scenario:
3345// 1. Audio/video session established.
3346// 2. SetConfiguration changes ICE config; ICE restart needed.
3347// 3. ICE restart initiated by remote peer, but only for one m= section.
3348// 4. Next createOffer should initiate an ICE restart, but only for the other
3349// m= section; it would be pointless to do an ICE restart for the m= section
3350// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003351TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003352 PeerConnectionInterface::RTCConfiguration config;
3353 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003354 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003355 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003356 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3357 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003358
3359 // Do initial offer/answer so there's something to restart.
3360 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003361 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003362
3363 // Change ICE policy, which should set the "needs-ice-restart" flag.
3364 config.type = PeerConnectionInterface::kAll;
3365 EXPECT_TRUE(pc_->SetConfiguration(config));
3366
3367 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003368 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003369 webrtc::CreateSessionDescription(SdpType::kOffer,
3370 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003371 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003372 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3373 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003374 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003375 CreateAnswerAsLocalDescription();
3376
3377 // Grab the ufrags.
3378 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003379 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003380
3381 // Create offer and grab the new ufrags.
3382 CreateOfferAsLocalDescription();
3383 std::vector<std::string> subsequent_ufrags =
3384 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003385 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003386
3387 // Ensure that only the ufrag for the second m= section changed.
3388 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3389 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3390}
3391
deadbeeffe4a8a42016-12-20 17:56:17 -08003392// Tests that the methods to return current/pending descriptions work as
3393// expected at different points in the offer/answer exchange. This test does
3394// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003395TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003396 // This disables DTLS so we can apply an answer to ourselves.
3397 CreatePeerConnection();
3398
3399 // Create initial local offer and get SDP (which will also be used as
3400 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003401 std::unique_ptr<SessionDescriptionInterface> local_offer;
3402 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003403 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003404 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003405
3406 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003407 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3408 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3409 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003410 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3411 EXPECT_EQ(nullptr, pc_->current_local_description());
3412 EXPECT_EQ(nullptr, pc_->current_remote_description());
3413
3414 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003415 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003416 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003417 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3418 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3419 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3420 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003421 EXPECT_EQ(nullptr, pc_->current_local_description());
3422 EXPECT_EQ(nullptr, pc_->current_remote_description());
3423
3424 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003425 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003426 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003427 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3428 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003429 EXPECT_EQ(nullptr, pc_->pending_local_description());
3430 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003431 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3432 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003433
3434 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003435 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003436 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003437 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3438 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3439 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003440 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003441 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3442 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003443
3444 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003445 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003446 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003447 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3448 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3449 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3450 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3451 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3452 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003453
3454 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003455 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003456 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003457 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3458 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003459 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3460 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003461 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3462 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003463}
3464
zhihuang77985012017-02-07 15:45:16 -08003465// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3466// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003467// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003468TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003469 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003470 CreatePeerConnection();
3471 // The RtcEventLog will be reset when the PeerConnection is closed.
3472 pc_->Close();
3473
Elad Alon9e6565b2017-10-11 16:04:13 +02003474 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3475 std::string filename = webrtc::test::OutputPath() +
3476 test_info->test_case_name() + test_info->name();
3477 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3478
3479 constexpr int64_t max_size_bytes = 1024;
3480
zhihuang77985012017-02-07 15:45:16 -08003481 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3482 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003483
3484 // Cleanup.
3485 rtc::ClosePlatformFile(file);
3486 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003487}
3488
Elad Alon99c3fe52017-10-13 16:29:40 +02003489// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3490// after the PeerConnection is closed.
3491// This version tests the StartRtcEventLog version that receives an object
3492// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003493TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003494 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3495 CreatePeerConnection();
3496 // The RtcEventLog will be reset when the PeerConnection is closed.
3497 pc_->Close();
3498
3499 rtc::PlatformFile file = 0;
3500 int64_t max_size_bytes = 1024;
3501 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003502 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003503 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003504 pc_->StopRtcEventLog();
3505}
3506
deadbeef30952b42017-04-21 02:41:29 -07003507// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003508TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003509 CreatePeerConnection();
3510
3511 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003512 RTCOfferAnswerOptions options;
3513 options.offer_to_receive_audio = 1;
3514 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003515 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003516 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003517 cricket::SessionDescription* desc = offer->description();
3518 ASSERT_EQ(2u, desc->transport_infos().size());
3519 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3520 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3521
3522 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003523 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003524 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003525 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003526 desc = answer->description();
3527 ASSERT_EQ(2u, desc->transport_infos().size());
3528 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3529 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3530}
3531
deadbeef1dcb1642017-03-29 21:08:16 -07003532// Test that ICE renomination isn't offered if it's not enabled in the PC's
3533// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003534TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003535 PeerConnectionInterface::RTCConfiguration config;
3536 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003537 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003538 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003539
3540 std::unique_ptr<SessionDescriptionInterface> offer;
3541 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3542 cricket::SessionDescription* desc = offer->description();
3543 EXPECT_EQ(1u, desc->transport_infos().size());
3544 EXPECT_FALSE(
3545 desc->transport_infos()[0].description.GetIceParameters().renomination);
3546}
3547
3548// Test that the ICE renomination option is present in generated offers/answers
3549// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003550TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003551 PeerConnectionInterface::RTCConfiguration config;
3552 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003553 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003554 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003555
3556 std::unique_ptr<SessionDescriptionInterface> offer;
3557 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3558 cricket::SessionDescription* desc = offer->description();
3559 EXPECT_EQ(1u, desc->transport_infos().size());
3560 EXPECT_TRUE(
3561 desc->transport_infos()[0].description.GetIceParameters().renomination);
3562
3563 // Set the offer as a remote description, then create an answer and ensure it
3564 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003565 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003566 std::unique_ptr<SessionDescriptionInterface> answer;
3567 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3568 desc = answer->description();
3569 EXPECT_EQ(1u, desc->transport_infos().size());
3570 EXPECT_TRUE(
3571 desc->transport_infos()[0].description.GetIceParameters().renomination);
3572}
3573
3574// Test that if CreateOffer is called with the deprecated "offer to receive
3575// audio/video" constraints, they're processed and result in an offer with
3576// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003577TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003578 CreatePeerConnection();
3579
Niels Möllerf06f9232018-08-07 12:32:18 +02003580 RTCOfferAnswerOptions options;
3581 options.offer_to_receive_audio = 1;
3582 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003583 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003584 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003585
3586 cricket::SessionDescription* desc = offer->description();
3587 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3588 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3589 ASSERT_NE(nullptr, audio);
3590 ASSERT_NE(nullptr, video);
3591 EXPECT_FALSE(audio->rejected);
3592 EXPECT_FALSE(video->rejected);
3593}
3594
3595// Test that if CreateAnswer is called with the deprecated "offer to receive
3596// audio/video" constraints, they're processed and can be used to reject an
3597// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003598// Don't run under Unified Plan since this behavior is not supported.
3599TEST_F(PeerConnectionInterfaceTestPlanB,
3600 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003601 CreatePeerConnection();
3602
3603 // First, create an offer with audio/video and apply it as a remote
3604 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003605 RTCOfferAnswerOptions options;
3606 options.offer_to_receive_audio = 1;
3607 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003608 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003609 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003610 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003611
3612 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003613 options.offer_to_receive_audio = 0;
3614 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003615 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003616 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003617
3618 cricket::SessionDescription* desc = answer->description();
3619 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3620 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3621 ASSERT_NE(nullptr, audio);
3622 ASSERT_NE(nullptr, video);
3623 EXPECT_TRUE(audio->rejected);
3624 EXPECT_TRUE(video->rejected);
3625}
3626
deadbeef1dcb1642017-03-29 21:08:16 -07003627// Test that negotiation can succeed with a data channel only, and with the max
3628// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003629#ifdef HAVE_SCTP
3630TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3631#else
3632TEST_P(PeerConnectionInterfaceTest,
3633 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3634#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003635 PeerConnectionInterface::RTCConfiguration config;
3636 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003637 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003638
3639 // First, create an offer with only a data channel and apply it as a remote
3640 // description.
3641 pc_->CreateDataChannel("test", nullptr);
3642 std::unique_ptr<SessionDescriptionInterface> offer;
3643 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003644 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003645
3646 // Create and set answer as well.
3647 std::unique_ptr<SessionDescriptionInterface> answer;
3648 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003649 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003650}
3651
Steve Anton36da6ff2018-02-16 16:04:20 -08003652TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003653 CreatePeerConnection();
3654 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003655 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003656 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3657}
3658
Steve Anton36da6ff2018-02-16 16:04:20 -08003659TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003660 CreatePeerConnection();
3661 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003662 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003663 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3664}
3665
Steve Anton36da6ff2018-02-16 16:04:20 -08003666TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003667 CreatePeerConnection();
3668 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003669 bitrate.min_bitrate_bps = 5;
3670 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003671 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3672}
3673
Steve Anton36da6ff2018-02-16 16:04:20 -08003674TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003675 CreatePeerConnection();
3676 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003677 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003678 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3679}
3680
Steve Anton36da6ff2018-02-16 16:04:20 -08003681TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003682 CreatePeerConnection();
3683 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003684 bitrate.current_bitrate_bps = 10;
3685 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003686 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3687}
3688
Steve Anton36da6ff2018-02-16 16:04:20 -08003689TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003690 CreatePeerConnection();
3691 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003692 bitrate.min_bitrate_bps = 10;
3693 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003694 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3695}
3696
Steve Anton36da6ff2018-02-16 16:04:20 -08003697TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003698 CreatePeerConnection();
3699 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003700 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003701 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3702}
3703
Steve Anton038834f2017-07-14 15:59:59 -07003704// ice_regather_interval_range requires WebRTC to be configured for continual
3705// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003706TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003707 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3708 PeerConnectionInterface::RTCConfiguration config;
3709 config.ice_regather_interval_range.emplace(1000, 2000);
3710 config.continual_gathering_policy =
3711 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3712 CreatePeerConnectionExpectFail(config);
3713}
3714
3715// Ensures that there is no error when ice_regather_interval_range is set with
3716// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003717TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003718 SetIceRegatherIntervalRangeWithContinualGathering) {
3719 PeerConnectionInterface::RTCConfiguration config;
3720 config.ice_regather_interval_range.emplace(1000, 2000);
3721 config.continual_gathering_policy =
3722 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003723 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003724}
3725
Niels Möller0c4f7be2018-05-07 14:01:37 +02003726// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003727// by Call's BitrateConstraints, which comes from the SDP or a default value.
3728// This test checks that a call to SetBitrate with a current bitrate that will
3729// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003730TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003731 CreatePeerConnection();
3732 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003733 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003734 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3735}
3736
zhihuang1c378ed2017-08-17 14:10:50 -07003737// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003738TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003739 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3740 RTCOfferAnswerOptions rtc_options;
3741
3742 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3743 // than kMaxOfferToReceiveMedia should be treated as invalid.
3744 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3745 CreatePeerConnection();
3746 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3747
3748 rtc_options.offer_to_receive_audio =
3749 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3750 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3751}
3752
Steve Anton36da6ff2018-02-16 16:04:20 -08003753TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003754 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3755 RTCOfferAnswerOptions rtc_options;
3756
3757 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3758 // than kMaxOfferToReceiveMedia should be treated as invalid.
3759 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3760 CreatePeerConnection();
3761 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3762
3763 rtc_options.offer_to_receive_video =
3764 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3765 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3766}
3767
3768// Test that the audio and video content will be added to an offer if both
3769// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003770TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003771 RTCOfferAnswerOptions rtc_options;
3772 rtc_options.offer_to_receive_audio = 1;
3773 rtc_options.offer_to_receive_video = 1;
3774
3775 std::unique_ptr<SessionDescriptionInterface> offer;
3776 CreatePeerConnection();
3777 offer = CreateOfferWithOptions(rtc_options);
3778 ASSERT_TRUE(offer);
3779 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3780 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3781}
3782
3783// Test that only audio content will be added to the offer if only
3784// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003785TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003786 RTCOfferAnswerOptions rtc_options;
3787 rtc_options.offer_to_receive_audio = 1;
3788 rtc_options.offer_to_receive_video = 0;
3789
3790 std::unique_ptr<SessionDescriptionInterface> offer;
3791 CreatePeerConnection();
3792 offer = CreateOfferWithOptions(rtc_options);
3793 ASSERT_TRUE(offer);
3794 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3795 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3796}
3797
3798// Test that only video content will be added if only |offer_to_receive_video|
3799// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003800TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003801 RTCOfferAnswerOptions rtc_options;
3802 rtc_options.offer_to_receive_audio = 0;
3803 rtc_options.offer_to_receive_video = 1;
3804
3805 std::unique_ptr<SessionDescriptionInterface> offer;
3806 CreatePeerConnection();
3807 offer = CreateOfferWithOptions(rtc_options);
3808 ASSERT_TRUE(offer);
3809 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3810 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3811}
3812
zhihuang1c378ed2017-08-17 14:10:50 -07003813// Test that no media content will be added to the offer if using default
3814// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003815TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003816 RTCOfferAnswerOptions rtc_options;
3817
3818 std::unique_ptr<SessionDescriptionInterface> offer;
3819 CreatePeerConnection();
3820 offer = CreateOfferWithOptions(rtc_options);
3821 ASSERT_TRUE(offer);
3822 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3823 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3824}
3825
3826// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3827// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003828TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3829 CreatePeerConnection();
3830
zhihuang1c378ed2017-08-17 14:10:50 -07003831 RTCOfferAnswerOptions rtc_options;
3832 rtc_options.ice_restart = false;
3833 rtc_options.offer_to_receive_audio = 1;
3834
3835 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003836 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003837 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3838 auto ufrag1 =
3839 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3840 auto pwd1 =
3841 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003842
3843 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3844 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003845 auto ufrag2 =
3846 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3847 auto pwd2 =
3848 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003849
3850 // |ice_restart| is true, the ufrag/pwd should change.
3851 rtc_options.ice_restart = true;
3852 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003853 auto ufrag3 =
3854 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3855 auto pwd3 =
3856 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003857
3858 EXPECT_EQ(ufrag1, ufrag2);
3859 EXPECT_EQ(pwd1, pwd2);
3860 EXPECT_NE(ufrag2, ufrag3);
3861 EXPECT_NE(pwd2, pwd3);
3862}
3863
3864// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3865// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003866TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003867 RTCOfferAnswerOptions rtc_options;
3868 rtc_options.offer_to_receive_audio = 1;
3869 rtc_options.offer_to_receive_video = 1;
3870
3871 std::unique_ptr<SessionDescriptionInterface> offer;
3872 CreatePeerConnection();
3873
3874 rtc_options.use_rtp_mux = true;
3875 offer = CreateOfferWithOptions(rtc_options);
3876 ASSERT_TRUE(offer);
3877 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3878 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3879 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3880
3881 rtc_options.use_rtp_mux = false;
3882 offer = CreateOfferWithOptions(rtc_options);
3883 ASSERT_TRUE(offer);
3884 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3885 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3886 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3887}
3888
zhihuang141aacb2017-08-29 13:23:53 -07003889// This test ensures OnRenegotiationNeeded is called when we add track with
3890// MediaStream -> AddTrack in the same way it is called when we add track with
3891// PeerConnection -> AddTrack.
3892// The test can be removed once addStream is rewritten in terms of addTrack
3893// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003894// Don't run under Unified Plan since the stream API is not available.
3895TEST_F(PeerConnectionInterfaceTestPlanB,
3896 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003897 CreatePeerConnectionWithoutDtls();
3898 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003899 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003900 pc_->AddStream(stream);
3901 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3902 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3903 rtc::scoped_refptr<VideoTrackInterface> video_track(
3904 pc_factory_->CreateVideoTrack(
3905 "video_track", pc_factory_->CreateVideoSource(
3906 std::unique_ptr<cricket::VideoCapturer>(
3907 new cricket::FakeVideoCapturer()))));
3908 stream->AddTrack(audio_track);
3909 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3910 observer_.renegotiation_needed_ = false;
3911
3912 stream->AddTrack(video_track);
3913 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3914 observer_.renegotiation_needed_ = false;
3915
3916 stream->RemoveTrack(audio_track);
3917 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3918 observer_.renegotiation_needed_ = false;
3919
3920 stream->RemoveTrack(video_track);
3921 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3922 observer_.renegotiation_needed_ = false;
3923}
3924
Zhi Huangb2d355e2017-10-26 17:26:37 -07003925// Tests that an error is returned if a description is applied that has fewer
3926// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003927TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003928 MediaSectionCountEnforcedForSubsequentOffer) {
3929 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003930 AddAudioTrack("audio_label");
3931 AddVideoTrack("video_label");
3932
Zhi Huangb2d355e2017-10-26 17:26:37 -07003933 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003934 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003935 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3936
3937 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003938 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003939 offer->description()->contents().pop_back();
3940 offer->description()->contents().pop_back();
3941 ASSERT_TRUE(offer->description()->contents().empty());
3942 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3943
3944 std::unique_ptr<SessionDescriptionInterface> answer;
3945 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3946 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3947
3948 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003949 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003950 offer->description()->contents().pop_back();
3951 offer->description()->contents().pop_back();
3952 ASSERT_TRUE(offer->description()->contents().empty());
3953 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3954}
3955
Johannes Kron89f874e2018-11-12 10:25:48 +01003956TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3957 RTCConfiguration config;
3958 // Default behavior is false.
3959 CreatePeerConnection(config);
3960 std::unique_ptr<SessionDescriptionInterface> offer;
3961 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3962 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3963 // Possible to set to true.
3964 config.offer_extmap_allow_mixed = true;
3965 CreatePeerConnection(config);
3966 offer.release();
3967 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3968 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3969}
3970
Steve Anton36da6ff2018-02-16 16:04:20 -08003971INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3972 PeerConnectionInterfaceTest,
3973 Values(SdpSemantics::kPlanB,
3974 SdpSemantics::kUnifiedPlan));
3975
nisse51542be2016-02-12 02:27:06 -08003976class PeerConnectionMediaConfigTest : public testing::Test {
3977 protected:
3978 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003979 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003980 pcf_->Initialize();
3981 }
nisseeaabdf62017-05-05 02:23:02 -07003982 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003983 const RTCConfiguration& config) {
3984 rtc::scoped_refptr<PeerConnectionInterface> pc(
3985 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003986 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003987 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003988 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003989 }
3990
zhihuang9763d562016-08-05 11:14:50 -07003991 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003992 MockPeerConnectionObserver observer_;
3993};
3994
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003995// This sanity check validates the test infrastructure itself.
3996TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3997 PeerConnectionInterface::RTCConfiguration config;
3998 rtc::scoped_refptr<PeerConnectionInterface> pc(
3999 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
4000 EXPECT_TRUE(pc.get());
4001 observer_.SetPeerConnectionInterface(pc.get()); // Required.
4002 pc->Close(); // No abort -> ok.
4003 SUCCEED();
4004}
4005
nisse51542be2016-02-12 02:27:06 -08004006// This test verifies the default behaviour with no constraints and a
4007// default RTCConfiguration.
4008TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4009 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004010
Niels Möllerf06f9232018-08-07 12:32:18 +02004011 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004012
4013 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004014 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4015 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004016 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004017 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004018}
4019
Niels Möller1d7ecd22018-01-18 15:25:12 +01004020// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004021// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004022TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4023 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004024
Niels Möller71bdda02016-03-31 12:59:59 +02004025 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004026 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004027
Niels Möller1d7ecd22018-01-18 15:25:12 +01004028 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004029}
4030
Niels Möller6539f692018-01-18 08:58:50 +01004031// This test verifies that the experiment_cpu_load_estimator flag is
4032// propagated from RTCConfiguration to the PeerConnection.
4033TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4034 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004035
4036 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004037 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004038
4039 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4040}
4041
deadbeef293e9262017-01-11 12:28:30 -08004042// Tests a few random fields being different.
4043TEST(RTCConfigurationTest, ComparisonOperators) {
4044 PeerConnectionInterface::RTCConfiguration a;
4045 PeerConnectionInterface::RTCConfiguration b;
4046 EXPECT_EQ(a, b);
4047
4048 PeerConnectionInterface::RTCConfiguration c;
4049 c.servers.push_back(PeerConnectionInterface::IceServer());
4050 EXPECT_NE(a, c);
4051
4052 PeerConnectionInterface::RTCConfiguration d;
4053 d.type = PeerConnectionInterface::kRelay;
4054 EXPECT_NE(a, d);
4055
4056 PeerConnectionInterface::RTCConfiguration e;
4057 e.audio_jitter_buffer_max_packets = 5;
4058 EXPECT_NE(a, e);
4059
4060 PeerConnectionInterface::RTCConfiguration f;
4061 f.ice_connection_receiving_timeout = 1337;
4062 EXPECT_NE(a, f);
4063
4064 PeerConnectionInterface::RTCConfiguration g;
4065 g.disable_ipv6 = true;
4066 EXPECT_NE(a, g);
4067
4068 PeerConnectionInterface::RTCConfiguration h(
4069 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4070 EXPECT_NE(a, h);
4071}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004072
4073} // namespace
4074} // namespace webrtc