blob: 5b9f7756079fd0f9ef77cc208aaefdb5333d380e [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"
Bjorn Tereliusb8b3c992019-01-09 11:15:34 +010045#include "logging/rtc_event_log/rtc_event_log_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
47#include "media/base/codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "media/base/fakevideocapturer.h"
Yves Gerey3e707812018-11-28 16:47:49 +010049#include "media/base/mediaconfig.h"
50#include "media/base/mediaengine.h"
51#include "media/base/streamparams.h"
52#include "media/base/videocapturer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#include "media/engine/webrtcmediaengine.h"
54#include "media/sctp/sctptransportinternal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010055#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020056#include "modules/audio_processing/include/audio_processing.h"
57#include "p2p/base/fakeportallocator.h"
Yves Gerey3e707812018-11-28 16:47:49 +010058#include "p2p/base/p2pconstants.h"
59#include "p2p/base/port.h"
60#include "p2p/base/portallocator.h"
61#include "p2p/base/transportdescription.h"
62#include "p2p/base/transportinfo.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020063#include "pc/audiotrack.h"
64#include "pc/mediasession.h"
65#include "pc/mediastream.h"
66#include "pc/peerconnection.h"
Yves Gerey3e707812018-11-28 16:47:49 +010067#include "pc/peerconnectionfactory.h"
68#include "pc/rtcstatscollector.h"
Steve Anton57858b32018-02-15 15:19:50 -080069#include "pc/rtpsender.h"
Yves Gerey3e707812018-11-28 16:47:49 +010070#include "pc/sessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020071#include "pc/streamcollection.h"
72#include "pc/test/fakeaudiocapturemodule.h"
73#include "pc/test/fakertccertificategenerator.h"
74#include "pc/test/fakevideotracksource.h"
75#include "pc/test/mockpeerconnectionobservers.h"
76#include "pc/test/testsdpstrings.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020077#include "pc/videotrack.h"
Yves Gerey3e707812018-11-28 16:47:49 +010078#include "rtc_base/checks.h"
79#include "rtc_base/copyonwritebuffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010081#include "rtc_base/platform_file.h"
82#include "rtc_base/refcountedobject.h"
83#include "rtc_base/rtccertificategenerator.h"
84#include "rtc_base/scoped_ref_ptr.h"
85#include "rtc_base/socketaddress.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020086#include "rtc_base/stringutils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010087#include "rtc_base/thread.h"
88#include "rtc_base/timeutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020089#include "rtc_base/virtualsocketserver.h"
90#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010091#include "test/gtest.h"
Elad Alon9e6565b2017-10-11 16:04:13 +020092#include "test/testsupport/fileutils.h"
kwibergac9f8762016-09-30 22:29:43 -070093
94#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020095#include "pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070096#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010098namespace webrtc {
99namespace {
100
Seth Hampson845e8782018-03-02 11:34:10 -0800101static const char kStreamId1[] = "local_stream_1";
102static const char kStreamId2[] = "local_stream_2";
103static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104static const int kDefaultStunPort = 3478;
105static const char kStunAddressOnly[] = "stun:address";
106static const char kStunInvalidPort[] = "stun:address:-1";
107static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
108static const char kStunAddressPortAndMore2[] = "stun:address:port more";
109static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
110static const char kTurnUsername[] = "user";
111static const char kTurnPassword[] = "password";
112static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200113static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
deadbeefab9b2d12015-10-14 11:33:11 -0700115static const char kStreams[][8] = {"stream1", "stream2"};
116static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
117static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
118
deadbeef5e97fb52015-10-15 12:49:08 -0700119static const char kRecvonly[] = "recvonly";
120static const char kSendrecv[] = "sendrecv";
121
deadbeefab9b2d12015-10-14 11:33:11 -0700122// Reference SDP with a MediaStream with label "stream1" and audio track with
123// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800124static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700125 "v=0\r\n"
126 "o=- 0 0 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800129 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700130 "a=ice-ufrag:e5785931\r\n"
131 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
132 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
133 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700134 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700135 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800136 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700137 "a=rtpmap:103 ISAC/16000\r\n"
138 "a=ssrc:1 cname:stream1\r\n"
139 "a=ssrc:1 mslabel:stream1\r\n"
140 "a=ssrc:1 label:audiotrack0\r\n"
141 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800142 "a=ice-ufrag:e5785931\r\n"
143 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
144 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
145 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700146 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700147 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800148 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700149 "a=rtpmap:120 VP8/90000\r\n"
150 "a=ssrc:2 cname:stream1\r\n"
151 "a=ssrc:2 mslabel:stream1\r\n"
152 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800153// Same string as above but with the MID changed to the Unified Plan default.
154// This is needed so that this SDP can be used as an answer for a Unified Plan
155// offer.
156static const char kSdpStringWithStream1UnifiedPlan[] =
157 "v=0\r\n"
158 "o=- 0 0 IN IP4 127.0.0.1\r\n"
159 "s=-\r\n"
160 "t=0 0\r\n"
161 "m=audio 1 RTP/AVPF 103\r\n"
162 "a=ice-ufrag:e5785931\r\n"
163 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
164 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
165 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
166 "a=mid:0\r\n"
167 "a=sendrecv\r\n"
168 "a=rtcp-mux\r\n"
169 "a=rtpmap:103 ISAC/16000\r\n"
170 "a=ssrc:1 cname:stream1\r\n"
171 "a=ssrc:1 mslabel:stream1\r\n"
172 "a=ssrc:1 label:audiotrack0\r\n"
173 "m=video 1 RTP/AVPF 120\r\n"
174 "a=ice-ufrag:e5785931\r\n"
175 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
176 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
177 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
178 "a=mid:1\r\n"
179 "a=sendrecv\r\n"
180 "a=rtcp-mux\r\n"
181 "a=rtpmap:120 VP8/90000\r\n"
182 "a=ssrc:2 cname:stream1\r\n"
183 "a=ssrc:2 mslabel:stream1\r\n"
184 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700185
zhihuang81c3a032016-11-17 12:06:24 -0800186// Reference SDP with a MediaStream with label "stream1" and audio track with
187// id "audio_1";
188static const char kSdpStringWithStream1AudioTrackOnly[] =
189 "v=0\r\n"
190 "o=- 0 0 IN IP4 127.0.0.1\r\n"
191 "s=-\r\n"
192 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800193 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800194 "a=ice-ufrag:e5785931\r\n"
195 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
196 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
197 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800198 "a=mid:audio\r\n"
199 "a=sendrecv\r\n"
200 "a=rtpmap:103 ISAC/16000\r\n"
201 "a=ssrc:1 cname:stream1\r\n"
202 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800203 "a=ssrc:1 label:audiotrack0\r\n"
204 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800205
deadbeefab9b2d12015-10-14 11:33:11 -0700206// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
207// MediaStreams have one audio track and one video track.
208// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800209static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700210 "v=0\r\n"
211 "o=- 0 0 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800214 "a=msid-semantic: WMS stream1 stream2\r\n"
215 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700216 "a=ice-ufrag:e5785931\r\n"
217 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
218 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
219 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700220 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700221 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800222 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700223 "a=rtpmap:103 ISAC/16000\r\n"
224 "a=ssrc:1 cname:stream1\r\n"
225 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
226 "a=ssrc:3 cname:stream2\r\n"
227 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
228 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800229 "a=ice-ufrag:e5785931\r\n"
230 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
231 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
232 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700233 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700234 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800235 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700236 "a=rtpmap:120 VP8/0\r\n"
237 "a=ssrc:2 cname:stream1\r\n"
238 "a=ssrc:2 msid:stream1 videotrack0\r\n"
239 "a=ssrc:4 cname:stream2\r\n"
240 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800241static const char kSdpStringWithStream1And2UnifiedPlan[] =
242 "v=0\r\n"
243 "o=- 0 0 IN IP4 127.0.0.1\r\n"
244 "s=-\r\n"
245 "t=0 0\r\n"
246 "a=msid-semantic: WMS stream1 stream2\r\n"
247 "m=audio 1 RTP/AVPF 103\r\n"
248 "a=ice-ufrag:e5785931\r\n"
249 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
250 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
251 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
252 "a=mid:0\r\n"
253 "a=sendrecv\r\n"
254 "a=rtcp-mux\r\n"
255 "a=rtpmap:103 ISAC/16000\r\n"
256 "a=ssrc:1 cname:stream1\r\n"
257 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
258 "m=video 1 RTP/AVPF 120\r\n"
259 "a=ice-ufrag:e5785931\r\n"
260 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
261 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
262 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
263 "a=mid:1\r\n"
264 "a=sendrecv\r\n"
265 "a=rtcp-mux\r\n"
266 "a=rtpmap:120 VP8/0\r\n"
267 "a=ssrc:2 cname:stream1\r\n"
268 "a=ssrc:2 msid:stream1 videotrack0\r\n"
269 "m=audio 1 RTP/AVPF 103\r\n"
270 "a=ice-ufrag:e5785931\r\n"
271 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
272 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
273 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
274 "a=mid:2\r\n"
275 "a=sendrecv\r\n"
276 "a=rtcp-mux\r\n"
277 "a=rtpmap:103 ISAC/16000\r\n"
278 "a=ssrc:3 cname:stream2\r\n"
279 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
280 "m=video 1 RTP/AVPF 120\r\n"
281 "a=ice-ufrag:e5785931\r\n"
282 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
283 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
284 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
285 "a=mid:3\r\n"
286 "a=sendrecv\r\n"
287 "a=rtcp-mux\r\n"
288 "a=rtpmap:120 VP8/0\r\n"
289 "a=ssrc:4 cname:stream2\r\n"
290 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700291
292// Reference SDP without MediaStreams. Msid is not supported.
293static const char kSdpStringWithoutStreams[] =
294 "v=0\r\n"
295 "o=- 0 0 IN IP4 127.0.0.1\r\n"
296 "s=-\r\n"
297 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800298 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700299 "a=ice-ufrag:e5785931\r\n"
300 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
301 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
302 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700303 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700304 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800305 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700306 "a=rtpmap:103 ISAC/16000\r\n"
307 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800308 "a=ice-ufrag:e5785931\r\n"
309 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
310 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
311 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700312 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700313 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800314 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700315 "a=rtpmap:120 VP8/90000\r\n";
316
317// Reference SDP without MediaStreams. Msid is supported.
318static const char kSdpStringWithMsidWithoutStreams[] =
319 "v=0\r\n"
320 "o=- 0 0 IN IP4 127.0.0.1\r\n"
321 "s=-\r\n"
322 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800323 "a=msid-semantic: WMS\r\n"
324 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700325 "a=ice-ufrag:e5785931\r\n"
326 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
327 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
328 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700329 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700330 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800331 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700332 "a=rtpmap:103 ISAC/16000\r\n"
333 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800334 "a=ice-ufrag:e5785931\r\n"
335 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
336 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
337 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700338 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700339 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800340 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700341 "a=rtpmap:120 VP8/90000\r\n";
342
343// Reference SDP without MediaStreams and audio only.
344static const char kSdpStringWithoutStreamsAudioOnly[] =
345 "v=0\r\n"
346 "o=- 0 0 IN IP4 127.0.0.1\r\n"
347 "s=-\r\n"
348 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800349 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700350 "a=ice-ufrag:e5785931\r\n"
351 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
352 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
353 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700354 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700355 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800356 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700357 "a=rtpmap:103 ISAC/16000\r\n";
358
359// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
360static const char kSdpStringSendOnlyWithoutStreams[] =
361 "v=0\r\n"
362 "o=- 0 0 IN IP4 127.0.0.1\r\n"
363 "s=-\r\n"
364 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800365 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700366 "a=ice-ufrag:e5785931\r\n"
367 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
368 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
369 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700370 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700371 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700372 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800373 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700374 "a=rtpmap:103 ISAC/16000\r\n"
375 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800376 "a=ice-ufrag:e5785931\r\n"
377 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
378 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
379 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700381 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700382 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800383 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700384 "a=rtpmap:120 VP8/90000\r\n";
385
386static const char kSdpStringInit[] =
387 "v=0\r\n"
388 "o=- 0 0 IN IP4 127.0.0.1\r\n"
389 "s=-\r\n"
390 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700391 "a=msid-semantic: WMS\r\n";
392
393static const char kSdpStringAudio[] =
394 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800395 "a=ice-ufrag:e5785931\r\n"
396 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
397 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
398 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700399 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700400 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800401 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700402 "a=rtpmap:103 ISAC/16000\r\n";
403
404static const char kSdpStringVideo[] =
405 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800406 "a=ice-ufrag:e5785931\r\n"
407 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
408 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
409 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700410 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700411 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800412 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700413 "a=rtpmap:120 VP8/90000\r\n";
414
415static const char kSdpStringMs1Audio0[] =
416 "a=ssrc:1 cname:stream1\r\n"
417 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
418
419static const char kSdpStringMs1Video0[] =
420 "a=ssrc:2 cname:stream1\r\n"
421 "a=ssrc:2 msid:stream1 videotrack0\r\n";
422
423static const char kSdpStringMs1Audio1[] =
424 "a=ssrc:3 cname:stream1\r\n"
425 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
426
427static const char kSdpStringMs1Video1[] =
428 "a=ssrc:4 cname:stream1\r\n"
429 "a=ssrc:4 msid:stream1 videotrack1\r\n";
430
deadbeef8662f942017-01-20 21:20:51 -0800431static const char kDtlsSdesFallbackSdp[] =
432 "v=0\r\n"
433 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
434 "s=-\r\n"
435 "c=IN IP4 0.0.0.0\r\n"
436 "t=0 0\r\n"
437 "a=group:BUNDLE audio\r\n"
438 "a=msid-semantic: WMS\r\n"
439 "m=audio 1 RTP/SAVPF 0\r\n"
440 "a=sendrecv\r\n"
441 "a=rtcp-mux\r\n"
442 "a=mid:audio\r\n"
443 "a=ssrc:1 cname:stream1\r\n"
444 "a=ssrc:1 mslabel:stream1\r\n"
445 "a=ssrc:1 label:audiotrack0\r\n"
446 "a=ice-ufrag:e5785931\r\n"
447 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
448 "a=rtpmap:0 pcmu/8000\r\n"
449 "a=fingerprint:sha-1 "
450 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
451 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700452 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800453 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
454 "dummy_session_params\r\n";
455
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100456using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700457using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800458using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459
Steve Anton36da6ff2018-02-16 16:04:20 -0800460using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
461using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700462
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463// Gets the first ssrc of given content type from the ContentInfo.
464bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
465 if (!content_info || !ssrc) {
466 return false;
467 }
468 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800469 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 if (!media_desc || media_desc->streams().empty()) {
471 return false;
472 }
473 *ssrc = media_desc->streams().begin()->first_ssrc();
474 return true;
475}
476
deadbeefd1a38b52016-12-10 13:15:33 -0800477// Get the ufrags out of an SDP blob. Useful for testing ICE restart
478// behavior.
479std::vector<std::string> GetUfrags(
480 const webrtc::SessionDescriptionInterface* desc) {
481 std::vector<std::string> ufrags;
482 for (const cricket::TransportInfo& info :
483 desc->description()->transport_infos()) {
484 ufrags.push_back(info.description.ice_ufrag);
485 }
486 return ufrags;
487}
488
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489void SetSsrcToZero(std::string* sdp) {
490 const char kSdpSsrcAtribute[] = "a=ssrc:";
491 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
492 size_t ssrc_pos = 0;
493 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200494 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 size_t end_ssrc = sdp->find(" ", ssrc_pos);
496 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
497 ssrc_pos = end_ssrc;
498 }
499}
500
deadbeefab9b2d12015-10-14 11:33:11 -0700501// Check if |streams| contains the specified track.
502bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800503 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700504 const std::string& track_id) {
505 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800506 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700507 return true;
508 }
509 }
510 return false;
511}
512
513// Check if |senders| contains the specified sender, by id.
514bool ContainsSender(
515 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
516 const std::string& id) {
517 for (const auto& sender : senders) {
518 if (sender->id() == id) {
519 return true;
520 }
521 }
522 return false;
523}
524
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700525// Check if |senders| contains the specified sender, by id and stream id.
526bool ContainsSender(
527 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
528 const std::string& id,
529 const std::string& stream_id) {
530 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700531 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700532 return true;
533 }
534 }
535 return false;
536}
537
deadbeefab9b2d12015-10-14 11:33:11 -0700538// Create a collection of streams.
539// CreateStreamCollection(1) creates a collection that
540// correspond to kSdpStringWithStream1.
541// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
542rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700543 int number_of_streams,
544 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700545 rtc::scoped_refptr<StreamCollection> local_collection(
546 StreamCollection::Create());
547
548 for (int i = 0; i < number_of_streams; ++i) {
549 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
550 webrtc::MediaStream::Create(kStreams[i]));
551
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700552 for (int j = 0; j < tracks_per_stream; ++j) {
553 // Add a local audio track.
554 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
555 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
556 nullptr));
557 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700558
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700559 // Add a local video track.
560 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
561 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700562 webrtc::FakeVideoTrackSource::Create(),
563 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700564 stream->AddTrack(video_track);
565 }
deadbeefab9b2d12015-10-14 11:33:11 -0700566
567 local_collection->AddStream(stream);
568 }
569 return local_collection;
570}
571
572// Check equality of StreamCollections.
573bool CompareStreamCollections(StreamCollectionInterface* s1,
574 StreamCollectionInterface* s2) {
575 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
576 return false;
577 }
578
579 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700580 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700581 return false;
582 }
583 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
584 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
585 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
586 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
587
588 if (audio_tracks1.size() != audio_tracks2.size()) {
589 return false;
590 }
591 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
592 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
593 return false;
594 }
595 }
596 if (video_tracks1.size() != video_tracks2.size()) {
597 return false;
598 }
599 for (size_t j = 0; j != video_tracks1.size(); ++j) {
600 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
601 return false;
602 }
603 }
604 }
605 return true;
606}
607
perkjd61bf802016-03-24 03:16:19 -0700608// Helper class to test Observer.
609class MockTrackObserver : public ObserverInterface {
610 public:
611 explicit MockTrackObserver(NotifierInterface* notifier)
612 : notifier_(notifier) {
613 notifier_->RegisterObserver(this);
614 }
615
616 ~MockTrackObserver() { Unregister(); }
617
618 void Unregister() {
619 if (notifier_) {
620 notifier_->UnregisterObserver(this);
621 notifier_ = nullptr;
622 }
623 }
624
625 MOCK_METHOD0(OnChanged, void());
626
627 private:
628 NotifierInterface* notifier_;
629};
630
nisse528b7932017-05-08 03:21:43 -0700631// The PeerConnectionMediaConfig tests below verify that configuration and
632// constraints are propagated into the PeerConnection's MediaConfig. These
633// settings are intended for MediaChannel constructors, but that is not
634// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700635class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
636 public:
zhihuang38ede132017-06-15 12:52:32 -0700637 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
638 CreatePeerConnectionFactoryForTest() {
639 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
640 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200641 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
642 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700643
henrika919dc2e2017-10-12 14:24:55 +0200644 // Use fake audio device module since we're only testing the interface
645 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700646 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
647 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200648 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200649 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000650 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100651 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700652
653 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
654 webrtc::CreateCallFactory();
655
656 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
657 webrtc::CreateRtcEventLogFactory();
658
659 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
660 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200661 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700662 std::move(event_log_factory));
663 }
664
665 PeerConnectionFactoryForTest(
666 rtc::Thread* network_thread,
667 rtc::Thread* worker_thread,
668 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700669 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
670 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
671 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
672 : webrtc::PeerConnectionFactory(network_thread,
673 worker_thread,
674 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700675 std::move(media_engine),
676 std::move(call_factory),
677 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800678
deadbeefd7850b22017-08-23 10:59:19 -0700679 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700680};
681
Steve Anton36da6ff2018-02-16 16:04:20 -0800682// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
683class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800685 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
686 : vss_(new rtc::VirtualSocketServer()),
687 main_(vss_.get()),
688 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800689#ifdef WEBRTC_ANDROID
690 webrtc::InitializeAndroidObjects();
691#endif
692 }
693
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700695 // Use fake audio capture module since we're only testing the interface
696 // level, and using a real one could make tests flaky when run in parallel.
697 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700699 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200700 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
701 fake_audio_capture_module_),
702 webrtc::CreateBuiltinAudioEncoderFactory(),
703 webrtc::CreateBuiltinAudioDecoderFactory(),
704 webrtc::CreateBuiltinVideoEncoderFactory(),
705 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
706 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700707 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700708 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700709 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700710 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 }
712
713 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200714 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 }
716
deadbeef293e9262017-01-11 12:28:30 -0800717 // DTLS does not work in a loopback call, so is disabled for most of the
718 // tests in this file.
719 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200720 RTCConfiguration config;
721 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800722
Niels Möllerf06f9232018-08-07 12:32:18 +0200723 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 }
725
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700726 void CreatePeerConnectionWithIceTransportsType(
727 PeerConnectionInterface::IceTransportsType type) {
728 PeerConnectionInterface::RTCConfiguration config;
729 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200730 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700731 }
732
733 void CreatePeerConnectionWithIceServer(const std::string& uri,
734 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800735 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700737 server.uri = uri;
738 server.password = password;
739 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200740 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700741 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742
Niels Möllerf06f9232018-08-07 12:32:18 +0200743 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700744 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800745 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
746 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000747
deadbeef1dcb1642017-03-29 21:08:16 -0700748 // Create certificate generator unless DTLS constraint is explicitly set to
749 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200750 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200751
752 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800753 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
754 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000755 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800756 RTCConfiguration modified_config = config;
757 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200758 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200759 modified_config, std::move(port_allocator), std::move(cert_generator),
760 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 ASSERT_TRUE(pc_.get() != NULL);
762 observer_.SetPeerConnectionInterface(pc_.get());
763 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
764 }
765
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800767 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700768 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700769 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800770 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800771 config.sdp_semantics = sdp_semantics_;
772 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200773 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800774 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700775 }
776
Steve Anton038834f2017-07-14 15:59:59 -0700777 void CreatePeerConnectionExpectFail(
778 PeerConnectionInterface::RTCConfiguration config) {
779 PeerConnectionInterface::IceServer server;
780 server.uri = kTurnIceServerUri;
781 server.password = kTurnPassword;
782 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800783 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700784 rtc::scoped_refptr<PeerConnectionInterface> pc =
785 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
786 EXPECT_EQ(nullptr, pc);
787 }
788
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700790 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800791 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
792 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
793 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800795 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796
deadbeef0a6c4ca2015-10-06 11:38:28 -0700797 CreatePeerConnectionExpectFail(kStunInvalidPort);
798 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
799 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700801 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
803 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800805 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800807 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800809 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 }
811
812 void ReleasePeerConnection() {
813 pc_ = NULL;
814 observer_.SetPeerConnectionInterface(NULL);
815 }
816
Steve Anton36da6ff2018-02-16 16:04:20 -0800817 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
818 const std::string& label) {
819 auto video_source = pc_factory_->CreateVideoSource(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200820 absl::make_unique<cricket::FakeVideoCapturer>(), nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -0800821 return pc_factory_->CreateVideoTrack(label, video_source);
822 }
823
824 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800825 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800826 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800827 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800828 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
830 observer_.renegotiation_needed_ = false;
831 }
832
Steve Anton36da6ff2018-02-16 16:04:20 -0800833 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700834 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800836 stream->AddTrack(CreateVideoTrack(label + "v0"));
837 ASSERT_TRUE(pc_->AddStream(stream));
838 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
839 observer_.renegotiation_needed_ = false;
840 }
841
842 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
843 const std::string& label) {
844 return pc_factory_->CreateAudioTrack(label, nullptr);
845 }
846
847 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800848 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800849 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800850 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800851 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
852 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
853 observer_.renegotiation_needed_ = false;
854 }
855
856 void AddAudioStream(const std::string& label) {
857 rtc::scoped_refptr<MediaStreamInterface> stream(
858 pc_factory_->CreateLocalMediaStream(label));
859 stream->AddTrack(CreateAudioTrack(label + "a0"));
860 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
862 observer_.renegotiation_needed_ = false;
863 }
864
Seth Hampson845e8782018-03-02 11:34:10 -0800865 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 const std::string& audio_track_label,
867 const std::string& video_track_label) {
868 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700869 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800870 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800871 stream->AddTrack(CreateAudioTrack(audio_track_label));
872 stream->AddTrack(CreateVideoTrack(video_track_label));
873 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
875 observer_.renegotiation_needed_ = false;
876 }
877
Steve Anton36da6ff2018-02-16 16:04:20 -0800878 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
879 cricket::MediaType media_type) {
880 for (auto receiver : pc_->GetReceivers()) {
881 if (receiver->media_type() == media_type) {
882 return receiver;
883 }
884 }
885 return nullptr;
886 }
887
kwibergd1fe2812016-04-27 06:47:29 -0700888 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200889 const RTCOfferAnswerOptions* options,
890 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200891 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
892 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200894 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200896 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700899 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 return observer->result();
901 }
902
kwibergd1fe2812016-04-27 06:47:29 -0700903 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200904 const RTCOfferAnswerOptions* options) {
905 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 }
907
kwibergd1fe2812016-04-27 06:47:29 -0700908 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200909 const RTCOfferAnswerOptions* options) {
910 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 }
912
Steve Antondb45ca82017-09-11 18:27:34 -0700913 bool DoSetSessionDescription(
914 std::unique_ptr<SessionDescriptionInterface> desc,
915 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200916 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
917 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700919 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700921 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 }
zhihuang29ff8442016-07-27 11:07:25 -0700923 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
924 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
925 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 return observer->result();
927 }
928
Steve Antondb45ca82017-09-11 18:27:34 -0700929 bool DoSetLocalDescription(
930 std::unique_ptr<SessionDescriptionInterface> desc) {
931 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 }
933
Steve Antondb45ca82017-09-11 18:27:34 -0700934 bool DoSetRemoteDescription(
935 std::unique_ptr<SessionDescriptionInterface> desc) {
936 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 }
938
939 // Calls PeerConnection::GetStats and check the return value.
940 // It does not verify the values in the StatReports since a RTCP packet might
941 // be required.
942 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000943 rtc::scoped_refptr<MockStatsObserver> observer(
944 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200945 if (!pc_->GetStats(observer, track,
946 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 return false;
948 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
949 return observer->called();
950 }
951
Harald Alvestrand89061872018-01-02 14:08:34 +0100952 // Call the standards-compliant GetStats function.
953 bool DoGetRTCStats() {
954 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
955 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
956 pc_->GetStats(callback);
957 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
958 return callback->called();
959 }
960
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800962 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800964 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800965 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800966 } else {
967 // Unified Plan does not support AddStream, so just add an audio and video
968 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800969 AddAudioTrack(kAudioTracks[0], {kStreamId1});
970 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800971 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 CreateOfferReceiveAnswer();
973 }
974
975 // Verify that RTP Header extensions has been negotiated for audio and video.
976 void VerifyRemoteRtpHeaderExtensions() {
977 const cricket::MediaContentDescription* desc =
978 cricket::GetFirstAudioContentDescription(
979 pc_->remote_description()->description());
980 ASSERT_TRUE(desc != NULL);
981 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
982
983 desc = cricket::GetFirstVideoContentDescription(
984 pc_->remote_description()->description());
985 ASSERT_TRUE(desc != NULL);
986 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
987 }
988
989 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700990 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700991 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 std::string sdp;
993 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700994 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800995 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700996 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
998 }
999
deadbeefab9b2d12015-10-14 11:33:11 -07001000 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001001 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001002 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001003 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001004 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1005 }
1006
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001008 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001009 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1012 // audio codec change, even if the parameter has nothing to do with
1013 // receiving. Not all parameters are serialized to SDP.
1014 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1015 // the SessionDescription, it is necessary to do that here to in order to
1016 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1017 // https://code.google.com/p/webrtc/issues/detail?id=1356
1018 std::string sdp;
1019 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001020 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001021 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001022 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1024 }
1025
1026 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001027 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001028 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029
1030 std::string sdp;
1031 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001032 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001033 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001034 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1036 }
1037
1038 void CreateOfferReceiveAnswer() {
1039 CreateOfferAsLocalDescription();
1040 std::string sdp;
1041 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1042 CreateAnswerAsRemoteDescription(sdp);
1043 }
1044
1045 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001046 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001047 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1049 // audio codec change, even if the parameter has nothing to do with
1050 // receiving. Not all parameters are serialized to SDP.
1051 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1052 // the SessionDescription, it is necessary to do that here to in order to
1053 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1054 // https://code.google.com/p/webrtc/issues/detail?id=1356
1055 std::string sdp;
1056 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001057 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001058 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059
Steve Antondb45ca82017-09-11 18:27:34 -07001060 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001062 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001063 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 }
1065
deadbeefab9b2d12015-10-14 11:33:11 -07001066 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001067 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001068 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001069 ASSERT_TRUE(answer);
1070 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1072 }
1073
deadbeefab9b2d12015-10-14 11:33:11 -07001074 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001075 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001076 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001077 ASSERT_TRUE(pr_answer);
1078 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001080 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001081 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001082 ASSERT_TRUE(answer);
1083 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1085 }
1086
Seth Hampson845e8782018-03-02 11:34:10 -08001087 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001088 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001089 // called with the given stream id and expected number of tracks.
1090 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001091 int expected_num_tracks) {
1092 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001093 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001094 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001095 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 }
1097
1098 // Creates an offer and applies it as a local session description.
1099 // Creates an answer with the same SDP an the offer but removes all lines
1100 // that start with a:ssrc"
1101 void CreateOfferReceiveAnswerWithoutSsrc() {
1102 CreateOfferAsLocalDescription();
1103 std::string sdp;
1104 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1105 SetSsrcToZero(&sdp);
1106 CreateAnswerAsRemoteDescription(sdp);
1107 }
1108
deadbeefab9b2d12015-10-14 11:33:11 -07001109 // This function creates a MediaStream with label kStreams[0] and
1110 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1111 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001112 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001113 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001114 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001115 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1116 size_t number_of_video_tracks) {
1117 EXPECT_LE(number_of_audio_tracks, 2u);
1118 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001119
1120 reference_collection_ = StreamCollection::Create();
1121 std::string sdp_ms1 = std::string(kSdpStringInit);
1122
Seth Hampson845e8782018-03-02 11:34:10 -08001123 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001124
1125 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001126 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001127 reference_collection_->AddStream(stream);
1128
1129 if (number_of_audio_tracks > 0) {
1130 sdp_ms1 += std::string(kSdpStringAudio);
1131 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1132 AddAudioTrack(kAudioTracks[0], stream);
1133 }
1134 if (number_of_audio_tracks > 1) {
1135 sdp_ms1 += kSdpStringMs1Audio1;
1136 AddAudioTrack(kAudioTracks[1], stream);
1137 }
1138
1139 if (number_of_video_tracks > 0) {
1140 sdp_ms1 += std::string(kSdpStringVideo);
1141 sdp_ms1 += std::string(kSdpStringMs1Video0);
1142 AddVideoTrack(kVideoTracks[0], stream);
1143 }
1144 if (number_of_video_tracks > 1) {
1145 sdp_ms1 += kSdpStringMs1Video1;
1146 AddVideoTrack(kVideoTracks[1], stream);
1147 }
1148
kwibergd1fe2812016-04-27 06:47:29 -07001149 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001150 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001151 }
1152
1153 void AddAudioTrack(const std::string& track_id,
1154 MediaStreamInterface* stream) {
1155 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1156 webrtc::AudioTrack::Create(track_id, nullptr));
1157 ASSERT_TRUE(stream->AddTrack(audio_track));
1158 }
1159
1160 void AddVideoTrack(const std::string& track_id,
1161 MediaStreamInterface* stream) {
1162 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001163 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001164 webrtc::FakeVideoTrackSource::Create(),
1165 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001166 ASSERT_TRUE(stream->AddTrack(video_track));
1167 }
1168
Steve Anton36da6ff2018-02-16 16:04:20 -08001169 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001170 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001171 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001172 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001173 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1174 return offer;
1175 }
1176
Steve Anton36da6ff2018-02-16 16:04:20 -08001177 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1178 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001179 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001180 std::unique_ptr<SessionDescriptionInterface> offer;
1181 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1182 return offer;
1183 }
1184
1185 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1186 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1187 std::unique_ptr<SessionDescriptionInterface> answer;
1188 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1189 return answer;
1190 }
1191
kwibergfd8be342016-05-14 19:44:11 -07001192 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001193 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001194 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001195 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001196 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1197 return answer;
1198 }
1199
1200 const std::string& GetFirstAudioStreamCname(
1201 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001202 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001203 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001204 return audio_desc->streams()[0].cname;
1205 }
1206
zhihuang1c378ed2017-08-17 14:10:50 -07001207 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1208 const RTCOfferAnswerOptions& offer_answer_options) {
1209 RTC_DCHECK(pc_);
1210 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1211 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1212 pc_->CreateOffer(observer, offer_answer_options);
1213 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1214 return observer->MoveDescription();
1215 }
1216
1217 void CreateOfferWithOptionsAsRemoteDescription(
1218 std::unique_ptr<SessionDescriptionInterface>* desc,
1219 const RTCOfferAnswerOptions& offer_answer_options) {
1220 *desc = CreateOfferWithOptions(offer_answer_options);
1221 ASSERT_TRUE(desc != nullptr);
1222 std::string sdp;
1223 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001224 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001225 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001226 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001227 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1228 }
1229
1230 void CreateOfferWithOptionsAsLocalDescription(
1231 std::unique_ptr<SessionDescriptionInterface>* desc,
1232 const RTCOfferAnswerOptions& offer_answer_options) {
1233 *desc = CreateOfferWithOptions(offer_answer_options);
1234 ASSERT_TRUE(desc != nullptr);
1235 std::string sdp;
1236 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001237 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001238 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001239
Steve Antondb45ca82017-09-11 18:27:34 -07001240 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001241 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1242 }
1243
1244 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001245 RTC_DCHECK(content);
1246 RTC_DCHECK(content->media_description());
1247 for (const cricket::AudioCodec& codec :
1248 content->media_description()->as_audio()->codecs()) {
1249 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001250 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001251 }
zhihuang1c378ed2017-08-17 14:10:50 -07001252 }
1253 return false;
1254 }
1255
Steve Anton36da6ff2018-02-16 16:04:20 -08001256 const char* GetSdpStringWithStream1() const {
1257 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1258 return kSdpStringWithStream1PlanB;
1259 } else {
1260 return kSdpStringWithStream1UnifiedPlan;
1261 }
1262 }
1263
1264 const char* GetSdpStringWithStream1And2() const {
1265 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1266 return kSdpStringWithStream1And2PlanB;
1267 } else {
1268 return kSdpStringWithStream1And2UnifiedPlan;
1269 }
1270 }
1271
deadbeef9a6f4d42017-05-15 19:43:33 -07001272 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1273 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001274 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001275 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001276 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001277 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1278 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1279 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001281 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001282 const SdpSemantics sdp_semantics_;
1283};
1284
1285class PeerConnectionInterfaceTest
1286 : public PeerConnectionInterfaceBaseTest,
1287 public ::testing::WithParamInterface<SdpSemantics> {
1288 protected:
1289 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1290};
1291
1292class PeerConnectionInterfaceTestPlanB
1293 : public PeerConnectionInterfaceBaseTest {
1294 protected:
1295 PeerConnectionInterfaceTestPlanB()
1296 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297};
1298
zhihuang8f65cdf2016-05-06 18:40:30 -07001299// Generate different CNAMEs when PeerConnections are created.
1300// The CNAMEs are expected to be generated randomly. It is possible
1301// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001302TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001303 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001304 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001305 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001306 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001307 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1308 GetFirstAudioStreamCname(offer2.get()));
1309}
1310
Steve Anton36da6ff2018-02-16 16:04:20 -08001311TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001312 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001313 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001314 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001315 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001316 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1317 GetFirstAudioStreamCname(answer2.get()));
1318}
1319
Steve Anton36da6ff2018-02-16 16:04:20 -08001320TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 CreatePeerConnectionWithDifferentConfigurations) {
1322 CreatePeerConnectionWithDifferentConfigurations();
1323}
1324
Steve Anton36da6ff2018-02-16 16:04:20 -08001325TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001326 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1327 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1328 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1329 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1330 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1331 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1332 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1333 port_allocator_->candidate_filter());
1334 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1335 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1336}
1337
1338// Test that when a PeerConnection is created with a nonzero candidate pool
1339// size, the pooled PortAllocatorSession is created with all the attributes
1340// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001341TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001342 PeerConnectionInterface::RTCConfiguration config;
1343 PeerConnectionInterface::IceServer server;
1344 server.uri = kStunAddressOnly;
1345 config.servers.push_back(server);
1346 config.type = PeerConnectionInterface::kRelay;
1347 config.disable_ipv6 = true;
1348 config.tcp_candidate_policy =
1349 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001350 config.candidate_network_policy =
1351 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001352 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001353 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001354
1355 const cricket::FakePortAllocatorSession* session =
1356 static_cast<const cricket::FakePortAllocatorSession*>(
1357 port_allocator_->GetPooledSession());
1358 ASSERT_NE(nullptr, session);
1359 EXPECT_EQ(1UL, session->stun_servers().size());
1360 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1361 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001362 EXPECT_LT(0U,
1363 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001364}
1365
deadbeefd21eab32017-07-26 16:50:11 -07001366// Test that network-related RTCConfiguration members are applied to the
1367// PortAllocator when CreatePeerConnection is called. Specifically:
1368// - disable_ipv6_on_wifi
1369// - max_ipv6_networks
1370// - tcp_candidate_policy
1371// - candidate_network_policy
1372// - prune_turn_ports
1373//
1374// Note that the candidate filter (RTCConfiguration::type) is already tested
1375// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001376TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001377 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1378 // Create fake port allocator.
1379 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1380 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1381 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1382
1383 // Create RTCConfiguration with some network-related fields relevant to
1384 // PortAllocator populated.
1385 PeerConnectionInterface::RTCConfiguration config;
1386 config.disable_ipv6_on_wifi = true;
1387 config.max_ipv6_networks = 10;
1388 config.tcp_candidate_policy =
1389 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1390 config.candidate_network_policy =
1391 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1392 config.prune_turn_ports = true;
1393
1394 // Create the PC factory and PC with the above config.
1395 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1396 webrtc::CreatePeerConnectionFactory(
1397 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001398 rtc::Thread::Current(), fake_audio_capture_module_,
1399 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001400 webrtc::CreateBuiltinAudioDecoderFactory(),
1401 webrtc::CreateBuiltinVideoEncoderFactory(),
1402 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1403 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001404 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001405 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1406 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001407 EXPECT_TRUE(pc.get());
1408 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001409
1410 // Now validate that the config fields set above were applied to the
1411 // PortAllocator, as flags or otherwise.
1412 EXPECT_FALSE(raw_port_allocator->flags() &
1413 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1414 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1415 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1416 EXPECT_TRUE(raw_port_allocator->flags() &
1417 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1418 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1419}
1420
deadbeef46c73892016-11-16 19:42:04 -08001421// Check that GetConfiguration returns the configuration the PeerConnection was
1422// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001423TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001424 PeerConnectionInterface::RTCConfiguration config;
1425 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001426 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001427
1428 PeerConnectionInterface::RTCConfiguration returned_config =
1429 pc_->GetConfiguration();
1430 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1431}
1432
1433// Check that GetConfiguration returns the last configuration passed into
1434// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001435TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001436 PeerConnectionInterface::RTCConfiguration starting_config;
1437 starting_config.bundle_policy =
1438 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1439 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001440
Steve Anton36da6ff2018-02-16 16:04:20 -08001441 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001442 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001443 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001444 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001445 EXPECT_TRUE(pc_->SetConfiguration(config));
1446
1447 PeerConnectionInterface::RTCConfiguration returned_config =
1448 pc_->GetConfiguration();
1449 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001450 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001451 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001452}
1453
Steve Antonc79268f2018-04-24 09:54:10 -07001454TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1455 CreatePeerConnection();
1456
1457 pc_->Close();
1458
1459 EXPECT_FALSE(
1460 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1461}
1462
Steve Anton36da6ff2018-02-16 16:04:20 -08001463TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001464 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001465 AddVideoStream(kStreamId1);
1466 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 ASSERT_EQ(2u, pc_->local_streams()->count());
1468
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001469 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001470 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001471 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001472 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001473 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001474 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001476 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001477 EXPECT_EQ(3u, pc_->local_streams()->count());
1478
1479 // Remove the third stream.
1480 pc_->RemoveStream(pc_->local_streams()->at(2));
1481 EXPECT_EQ(2u, pc_->local_streams()->count());
1482
1483 // Remove the second stream.
1484 pc_->RemoveStream(pc_->local_streams()->at(1));
1485 EXPECT_EQ(1u, pc_->local_streams()->count());
1486
1487 // Remove the first stream.
1488 pc_->RemoveStream(pc_->local_streams()->at(0));
1489 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490}
1491
deadbeefab9b2d12015-10-14 11:33:11 -07001492// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001493// Don't run under Unified Plan since the stream API is not available.
1494TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001495 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001496 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001497 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001498 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001499
deadbeefab9b2d12015-10-14 11:33:11 -07001500 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001501 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001502 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001503
deadbeefab9b2d12015-10-14 11:33:11 -07001504 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001505 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001506 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001507
1508 // Add another stream and ensure the offer includes both the old and new
1509 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001510 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001511 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001512
Steve Antonb1c1de12017-12-21 15:14:30 -08001513 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001514 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1515 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001516
Steve Antonb1c1de12017-12-21 15:14:30 -08001517 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001518 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1519 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001520}
1521
Steve Anton36da6ff2018-02-16 16:04:20 -08001522// Don't run under Unified Plan since the stream API is not available.
1523TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001524 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001525 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 ASSERT_EQ(1u, pc_->local_streams()->count());
1527 pc_->RemoveStream(pc_->local_streams()->at(0));
1528 EXPECT_EQ(0u, pc_->local_streams()->count());
1529}
1530
deadbeefe1f9d832016-01-14 15:35:42 -08001531// Test for AddTrack and RemoveTrack methods.
1532// Tests that the created offer includes tracks we added,
1533// and that the RtpSenders are created correctly.
1534// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001535// Only tested with Plan B since Unified Plan is covered in more detail by tests
1536// in peerconnection_jsep_unittests.cc
1537TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001538 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001539 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001540 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001541 rtc::scoped_refptr<VideoTrackInterface> video_track(
1542 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001543 "video_track", pc_factory_->CreateVideoSource(
1544 std::unique_ptr<cricket::VideoCapturer>(
1545 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001546 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1547 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001548 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001549 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001550 EXPECT_EQ("audio_track", audio_sender->id());
1551 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001552 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001553 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001554 EXPECT_EQ("video_track", video_sender->id());
1555 EXPECT_EQ(video_track, video_sender->track());
1556
1557 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001558 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001559 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 const cricket::ContentInfo* audio_content =
1562 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001563 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001564 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
1566 const cricket::ContentInfo* video_content =
1567 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001568 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001569 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001570
Steve Antondb45ca82017-09-11 18:27:34 -07001571 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001572
1573 // Now try removing the tracks.
1574 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1575 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1576
1577 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001578 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001579
1580 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001581 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001582 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001583
1584 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001585 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001586 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001587
Steve Antondb45ca82017-09-11 18:27:34 -07001588 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001589
1590 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1591 // should return false.
1592 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1593 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1594}
1595
1596// Test creating senders without a stream specified,
1597// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001598TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001599 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001600 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001601 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001602 rtc::scoped_refptr<VideoTrackInterface> video_track(
1603 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001604 "video_track", pc_factory_->CreateVideoSource(
1605 std::unique_ptr<cricket::VideoCapturer>(
1606 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001607 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001608 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001609 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001610 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001611 EXPECT_EQ("audio_track", audio_sender->id());
1612 EXPECT_EQ(audio_track, audio_sender->track());
1613 EXPECT_EQ("video_track", video_sender->id());
1614 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001615 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1616 // If the ID is truly a random GUID, it should be infinitely unlikely they
1617 // will be the same.
1618 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1619 } else {
1620 // We allows creating tracks without stream ids under Unified Plan
1621 // semantics.
1622 EXPECT_EQ(0u, video_sender->stream_ids().size());
1623 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1624 }
deadbeefe1f9d832016-01-14 15:35:42 -08001625}
1626
Harald Alvestrand89061872018-01-02 14:08:34 +01001627// Test that we can call GetStats() after AddTrack but before connecting
1628// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001629TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001630 CreatePeerConnectionWithoutDtls();
1631 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1632 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1633 rtc::scoped_refptr<VideoTrackInterface> video_track(
1634 pc_factory_->CreateVideoTrack(
1635 "video_track", pc_factory_->CreateVideoSource(
1636 std::unique_ptr<cricket::VideoCapturer>(
1637 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001638 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1639 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001640 EXPECT_TRUE(DoGetStats(nullptr));
1641}
1642
Steve Anton36da6ff2018-02-16 16:04:20 -08001643TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001644 CreatePeerConnectionWithoutDtls();
1645 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1646 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1647 rtc::scoped_refptr<VideoTrackInterface> video_track(
1648 pc_factory_->CreateVideoTrack(
1649 "video_track", pc_factory_->CreateVideoSource(
1650 std::unique_ptr<cricket::VideoCapturer>(
1651 new cricket::FakeVideoCapturer()))));
1652 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001653 ASSERT_TRUE(audio_sender.ok());
1654 auto* audio_sender_proxy =
1655 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1656 audio_sender.value().get());
1657 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1658
Harald Alvestrandc72af932018-01-11 17:18:19 +01001659 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001660 ASSERT_TRUE(video_sender.ok());
1661 auto* video_sender_proxy =
1662 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1663 video_sender.value().get());
1664 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001665}
1666
Steve Anton36da6ff2018-02-16 16:04:20 -08001667// Don't run under Unified Plan since the stream API is not available.
1668TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001669 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001670 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001671 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001672 ASSERT_EQ(1u, senders.size());
1673 auto* sender_proxy =
1674 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1675 senders[0].get());
1676 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001677}
1678
Steve Anton36da6ff2018-02-16 16:04:20 -08001679TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001681 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 VerifyRemoteRtpHeaderExtensions();
1683}
1684
Steve Anton36da6ff2018-02-16 16:04:20 -08001685TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001686 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001687 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 CreateOfferAsLocalDescription();
1689 std::string offer;
1690 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1691 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001692 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693}
1694
Steve Anton36da6ff2018-02-16 16:04:20 -08001695TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001696 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001697 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698
1699 CreateOfferAsRemoteDescription();
1700 CreateAnswerAsLocalDescription();
1701
Seth Hampson845e8782018-03-02 11:34:10 -08001702 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703}
1704
Steve Anton36da6ff2018-02-16 16:04:20 -08001705TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001706 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001707 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708
1709 CreateOfferAsRemoteDescription();
1710 CreatePrAnswerAsLocalDescription();
1711 CreateAnswerAsLocalDescription();
1712
Seth Hampson845e8782018-03-02 11:34:10 -08001713 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714}
1715
Steve Anton36da6ff2018-02-16 16:04:20 -08001716// Don't run under Unified Plan since the stream API is not available.
1717TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 InitiateCall();
1719 ASSERT_EQ(1u, pc_->remote_streams()->count());
1720 pc_->RemoveStream(pc_->local_streams()->at(0));
1721 CreateOfferReceiveAnswer();
1722 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001723 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 CreateOfferReceiveAnswer();
1725}
1726
1727// Tests that after negotiating an audio only call, the respondent can perform a
1728// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001729TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001730 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001731 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 CreateOfferAsRemoteDescription();
1733 CreateAnswerAsLocalDescription();
1734
1735 ASSERT_EQ(1u, pc_->remote_streams()->count());
1736 pc_->RemoveStream(pc_->local_streams()->at(0));
1737 CreateOfferReceiveAnswer();
1738 EXPECT_EQ(0u, pc_->remote_streams()->count());
1739}
1740
1741// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001742TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001743 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
Steve Antonf1c6db12017-10-13 11:13:35 -07001745 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001747 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001748 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001749 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001750 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001753 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001754 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001755 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756
Steve Antonf1c6db12017-10-13 11:13:35 -07001757 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001758 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759
Steve Antonf1c6db12017-10-13 11:13:35 -07001760 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761}
1762
deadbeefab9b2d12015-10-14 11:33:11 -07001763// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001765TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001766 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001768 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001769 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001770 EXPECT_TRUE(offer);
1771 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772
1773 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001774 AddAudioTrack("track_label", {kStreamId1});
1775 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776
1777 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001778 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779
1780 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001781 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001782 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783}
1784
1785// Test that we will get different SSRCs for each tracks in the offer and answer
1786// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001787TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001788 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001790 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1791 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792
1793 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001794 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001795 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 int audio_ssrc = 0;
1797 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001798 EXPECT_TRUE(
1799 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1800 EXPECT_TRUE(
1801 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 EXPECT_NE(audio_ssrc, video_ssrc);
1803
1804 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001805 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001806 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001807 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 audio_ssrc = 0;
1809 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001810 EXPECT_TRUE(
1811 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1812 EXPECT_TRUE(
1813 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 EXPECT_NE(audio_ssrc, video_ssrc);
1815}
1816
deadbeefeb459812015-12-15 19:24:43 -08001817// Test that it's possible to call AddTrack on a MediaStream after adding
1818// the stream to a PeerConnection.
1819// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001820// Don't run under Unified Plan since the stream API is not available.
1821TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001822 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001823 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001824 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001825 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1826
1827 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001828 rtc::scoped_refptr<VideoTrackInterface> video_track(
1829 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001830 "video_label", pc_factory_->CreateVideoSource(
1831 std::unique_ptr<cricket::VideoCapturer>(
1832 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001833 stream->AddTrack(video_track.get());
1834
kwibergd1fe2812016-04-27 06:47:29 -07001835 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001836 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001837
1838 const cricket::MediaContentDescription* video_desc =
1839 cricket::GetFirstVideoContentDescription(offer->description());
1840 EXPECT_TRUE(video_desc != nullptr);
1841}
1842
1843// Test that it's possible to call RemoveTrack on a MediaStream after adding
1844// the stream to a PeerConnection.
1845// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001846// Don't run under Unified Plan since the stream API is not available.
1847TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001848 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001849 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001850 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001851 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1852
1853 // Remove the video track.
1854 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1855
kwibergd1fe2812016-04-27 06:47:29 -07001856 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001857 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001858
1859 const cricket::MediaContentDescription* video_desc =
1860 cricket::GetFirstVideoContentDescription(offer->description());
1861 EXPECT_TRUE(video_desc == nullptr);
1862}
1863
deadbeefbd7d8f72015-12-18 16:58:44 -08001864// Test creating a sender with a stream ID, and ensure the ID is populated
1865// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001866// Don't run under Unified Plan since the stream API is not available.
1867TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001868 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001869 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001870
kwibergd1fe2812016-04-27 06:47:29 -07001871 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001872 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001873
1874 const cricket::MediaContentDescription* video_desc =
1875 cricket::GetFirstVideoContentDescription(offer->description());
1876 ASSERT_TRUE(video_desc != nullptr);
1877 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001878 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001879}
1880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001882TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001884 ASSERT_LT(0u, pc_->GetSenders().size());
1885 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001886 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001887 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 EXPECT_TRUE(DoGetStats(remote_audio));
1889
1890 // Remove the stream. Since we are sending to our selves the local
1891 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001892 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 // Do a re-negotiation.
1894 CreateOfferReceiveAnswer();
1895
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 // Test that we still can get statistics for the old track. Even if it is not
1897 // sent any longer.
1898 EXPECT_TRUE(DoGetStats(remote_audio));
1899}
1900
1901// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001902TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001904 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1905 ASSERT_TRUE(video_receiver);
1906 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907}
1908
1909// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001910TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001912 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 pc_factory_->CreateAudioTrack("unknown track", NULL));
1914 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1915}
1916
Steve Anton36da6ff2018-02-16 16:04:20 -08001917TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001918 CreatePeerConnectionWithoutDtls();
1919 EXPECT_TRUE(DoGetRTCStats());
1920 // Clearing stats cache is needed now, but should be temporary.
1921 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1922 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001923 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1924 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001925 EXPECT_TRUE(DoGetRTCStats());
1926 pc_->ClearStatsCache();
1927 CreateOfferReceiveAnswer();
1928 EXPECT_TRUE(DoGetRTCStats());
1929}
1930
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001932TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001933 RTCConfiguration config;
1934 config.enable_rtp_data_channel = true;
1935 config.enable_dtls_srtp = false;
1936 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001937 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001939 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 pc_->CreateDataChannel("test2", NULL);
1941 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001942 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001944 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 new MockDataChannelObserver(data2));
1946
1947 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1948 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1949 std::string data_to_send1 = "testing testing";
1950 std::string data_to_send2 = "testing something else";
1951 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1952
1953 CreateOfferReceiveAnswer();
1954 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1955 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1956
1957 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1958 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1959 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1960 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1961
1962 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1963 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1964
1965 data1->Close();
1966 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1967 CreateOfferReceiveAnswer();
1968 EXPECT_FALSE(observer1->IsOpen());
1969 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1970 EXPECT_TRUE(observer2->IsOpen());
1971
1972 data_to_send2 = "testing something else again";
1973 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1974
1975 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1976}
1977
1978// This test verifies that sendnig binary data over RTP data channels should
1979// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001980TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001981 RTCConfiguration config;
1982 config.enable_rtp_data_channel = true;
1983 config.enable_dtls_srtp = false;
1984 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001985 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001987 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 pc_->CreateDataChannel("test2", NULL);
1989 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001990 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001992 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 new MockDataChannelObserver(data2));
1994
1995 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1996 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1997
1998 CreateOfferReceiveAnswer();
1999 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2000 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2001
2002 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2003 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2004
jbaucheec21bd2016-03-20 06:15:43 -07002005 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2007}
2008
2009// This test setup a RTP data channels in loop back and test that a channel is
2010// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002011TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002012 RTCConfiguration config;
2013 config.enable_rtp_data_channel = true;
2014 config.enable_dtls_srtp = false;
2015 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002016 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002018 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 new MockDataChannelObserver(data1));
2020
2021 CreateOfferReceiveAnswerWithoutSsrc();
2022
2023 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2024
2025 data1->Close();
2026 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2027 CreateOfferReceiveAnswerWithoutSsrc();
2028 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2029 EXPECT_FALSE(observer1->IsOpen());
2030}
2031
2032// This test that if a data channel is added in an answer a receive only channel
2033// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002034TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002035 RTCConfiguration config;
2036 config.enable_rtp_data_channel = true;
2037 config.enable_dtls_srtp = false;
2038
2039 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040
2041 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002042 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 pc_->CreateDataChannel(offer_label, NULL);
2044
2045 CreateOfferAsLocalDescription();
2046
2047 // Replace the data channel label in the offer and apply it as an answer.
2048 std::string receive_label = "answer_channel";
2049 std::string sdp;
2050 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002051 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002052 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 CreateAnswerAsRemoteDescription(sdp);
2054
2055 // Verify that a new incoming data channel has been created and that
2056 // it is open but can't we written to.
2057 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2058 DataChannelInterface* received_channel = observer_.last_datachannel_;
2059 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2060 EXPECT_EQ(receive_label, received_channel->label());
2061 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2062
2063 // Verify that the channel we initially offered has been rejected.
2064 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2065
2066 // Do another offer / answer exchange and verify that the data channel is
2067 // opened.
2068 CreateOfferReceiveAnswer();
2069 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2070 kTimeout);
2071}
2072
2073// This test that no data channel is returned if a reliable channel is
2074// requested.
2075// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002076TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002077 RTCConfiguration rtc_config;
2078 rtc_config.enable_rtp_data_channel = true;
2079 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080
2081 std::string label = "test";
2082 webrtc::DataChannelInit config;
2083 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002084 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 pc_->CreateDataChannel(label, &config);
2086 EXPECT_TRUE(channel == NULL);
2087}
2088
deadbeefab9b2d12015-10-14 11:33:11 -07002089// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002090TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002091 RTCConfiguration config;
2092 config.enable_rtp_data_channel = true;
2093 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002094
2095 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002096 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002097 pc_->CreateDataChannel(label, nullptr);
2098 EXPECT_NE(channel, nullptr);
2099
zhihuang9763d562016-08-05 11:14:50 -07002100 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002101 pc_->CreateDataChannel(label, nullptr);
2102 EXPECT_EQ(dup_channel, nullptr);
2103}
2104
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105// This tests that a SCTP data channel is returned using different
2106// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002107TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002108 RTCConfiguration rtc_config;
2109 rtc_config.enable_dtls_srtp = true;
2110 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111
2112 webrtc::DataChannelInit config;
2113
zhihuang9763d562016-08-05 11:14:50 -07002114 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 pc_->CreateDataChannel("1", &config);
2116 EXPECT_TRUE(channel != NULL);
2117 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002118 EXPECT_TRUE(observer_.renegotiation_needed_);
2119 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 config.ordered = false;
2122 channel = pc_->CreateDataChannel("2", &config);
2123 EXPECT_TRUE(channel != NULL);
2124 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002125 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126
2127 config.ordered = true;
2128 config.maxRetransmits = 0;
2129 channel = pc_->CreateDataChannel("3", &config);
2130 EXPECT_TRUE(channel != NULL);
2131 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002132 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
2134 config.maxRetransmits = -1;
2135 config.maxRetransmitTime = 0;
2136 channel = pc_->CreateDataChannel("4", &config);
2137 EXPECT_TRUE(channel != NULL);
2138 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002139 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140}
2141
2142// This tests that no data channel is returned if both maxRetransmits and
2143// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002144TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002146 RTCConfiguration rtc_config;
2147 rtc_config.enable_dtls_srtp = true;
2148 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149
2150 std::string label = "test";
2151 webrtc::DataChannelInit config;
2152 config.maxRetransmits = 0;
2153 config.maxRetransmitTime = 0;
2154
zhihuang9763d562016-08-05 11:14:50 -07002155 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 pc_->CreateDataChannel(label, &config);
2157 EXPECT_TRUE(channel == NULL);
2158}
2159
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160// The test verifies that creating a SCTP data channel with an id already in use
2161// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002162TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002164 RTCConfiguration rtc_config;
2165 rtc_config.enable_dtls_srtp = true;
2166 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167
2168 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002169 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002171 config.id = 1;
2172 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 EXPECT_TRUE(channel != NULL);
2174 EXPECT_EQ(1, channel->id());
2175
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 channel = pc_->CreateDataChannel("x", &config);
2177 EXPECT_TRUE(channel == NULL);
2178
2179 config.id = cricket::kMaxSctpSid;
2180 channel = pc_->CreateDataChannel("max", &config);
2181 EXPECT_TRUE(channel != NULL);
2182 EXPECT_EQ(config.id, channel->id());
2183
2184 config.id = cricket::kMaxSctpSid + 1;
2185 channel = pc_->CreateDataChannel("x", &config);
2186 EXPECT_TRUE(channel == NULL);
2187}
2188
deadbeefab9b2d12015-10-14 11:33:11 -07002189// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002190TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002191 RTCConfiguration rtc_config;
2192 rtc_config.enable_dtls_srtp = true;
2193 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002194
2195 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002196 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002197 pc_->CreateDataChannel(label, nullptr);
2198 EXPECT_NE(channel, nullptr);
2199
zhihuang9763d562016-08-05 11:14:50 -07002200 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002201 pc_->CreateDataChannel(label, nullptr);
2202 EXPECT_NE(dup_channel, nullptr);
2203}
2204
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002205// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2206// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002207TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002208 RTCConfiguration rtc_config;
2209 rtc_config.enable_rtp_data_channel = true;
2210 rtc_config.enable_dtls_srtp = false;
2211 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002212
zhihuang9763d562016-08-05 11:14:50 -07002213 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002214 pc_->CreateDataChannel("test1", NULL);
2215 EXPECT_TRUE(observer_.renegotiation_needed_);
2216 observer_.renegotiation_needed_ = false;
2217
zhihuang9763d562016-08-05 11:14:50 -07002218 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002219 pc_->CreateDataChannel("test2", NULL);
2220 EXPECT_TRUE(observer_.renegotiation_needed_);
2221}
2222
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002224TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002225 RTCConfiguration rtc_config;
2226 rtc_config.enable_rtp_data_channel = true;
2227 rtc_config.enable_dtls_srtp = false;
2228 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229
zhihuang9763d562016-08-05 11:14:50 -07002230 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002232 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 pc_->CreateDataChannel("test2", NULL);
2234 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002235 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002237 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 new MockDataChannelObserver(data2));
2239
2240 CreateOfferReceiveAnswer();
2241 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2242 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2243
2244 ReleasePeerConnection();
2245 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2246 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2247}
2248
Zhi Huang644fde42018-04-02 19:16:26 -07002249// This tests that RTP data channels can be rejected in an answer.
2250TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002251 RTCConfiguration rtc_config;
2252 rtc_config.enable_rtp_data_channel = true;
2253 rtc_config.enable_dtls_srtp = false;
2254 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255
zhihuang9763d562016-08-05 11:14:50 -07002256 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 pc_->CreateDataChannel("offer_channel", NULL));
2258
2259 CreateOfferAsLocalDescription();
2260
2261 // Create an answer where the m-line for data channels are rejected.
2262 std::string sdp;
2263 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002264 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002265 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002266 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002268 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 data_info->rejected = true;
2270
Steve Antondb45ca82017-09-11 18:27:34 -07002271 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2273}
2274
Zhi Huang644fde42018-04-02 19:16:26 -07002275#ifdef HAVE_SCTP
2276// This tests that SCTP data channels can be rejected in an answer.
2277TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2278#else
2279TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2280#endif
2281{
Niels Möllerf06f9232018-08-07 12:32:18 +02002282 RTCConfiguration rtc_config;
2283 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002284
2285 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2286 pc_->CreateDataChannel("offer_channel", NULL));
2287
2288 CreateOfferAsLocalDescription();
2289
2290 // Create an answer where the m-line for data channels are rejected.
2291 std::string sdp;
2292 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2293 std::unique_ptr<SessionDescriptionInterface> answer(
2294 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2295 ASSERT_TRUE(answer);
2296 cricket::ContentInfo* data_info =
2297 cricket::GetFirstDataContent(answer->description());
2298 data_info->rejected = true;
2299
2300 DoSetRemoteDescription(std::move(answer));
2301 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2302}
2303
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304// Test that we can create a session description from an SDP string from
2305// FireFox, use it as a remote session description, generate an answer and use
2306// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002307TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002308 RTCConfiguration rtc_config;
2309 rtc_config.enable_dtls_srtp = true;
2310 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002311 AddAudioTrack("audio_label");
2312 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002313 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002314 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002315 webrtc::kFireFoxSdpOffer, nullptr));
2316 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317 CreateAnswerAsLocalDescription();
2318 ASSERT_TRUE(pc_->local_description() != NULL);
2319 ASSERT_TRUE(pc_->remote_description() != NULL);
2320
2321 const cricket::ContentInfo* content =
2322 cricket::GetFirstAudioContent(pc_->local_description()->description());
2323 ASSERT_TRUE(content != NULL);
2324 EXPECT_FALSE(content->rejected);
2325
2326 content =
2327 cricket::GetFirstVideoContent(pc_->local_description()->description());
2328 ASSERT_TRUE(content != NULL);
2329 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002330#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 content =
2332 cricket::GetFirstDataContent(pc_->local_description()->description());
2333 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002334 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002335#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336}
2337
zhihuangb19012e2017-09-19 13:47:59 -07002338// Test that fallback from DTLS to SDES is not supported.
2339// The fallback was previously supported but was removed to simplify the code
2340// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002341TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002342 RTCConfiguration rtc_config;
2343 rtc_config.enable_dtls_srtp = true;
2344 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002345 // Wait for fake certificate to be generated. Previously, this is what caused
2346 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002347 AddAudioTrack("audio_label");
2348 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002349 ASSERT_NE(nullptr, fake_certificate_generator_);
2350 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2351 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002352 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002353 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2354 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002355 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002356}
2357
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358// Test that we can create an audio only offer and receive an answer with a
2359// limited set of audio codecs and receive an updated offer with more audio
2360// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002361TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002362 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002363 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 CreateOfferAsLocalDescription();
2365
Steve Anton36da6ff2018-02-16 16:04:20 -08002366 const char* answer_sdp =
2367 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2368 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002369 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002370 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002371 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372
Steve Anton36da6ff2018-02-16 16:04:20 -08002373 const char* reoffer_sdp =
2374 (sdp_semantics_ == SdpSemantics::kPlanB
2375 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2376 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002377 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002378 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002379 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 CreateAnswerAsLocalDescription();
2381}
2382
deadbeefc80741f2015-10-22 13:14:45 -07002383// Test that if we're receiving (but not sending) a track, subsequent offers
2384// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002385TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002386 RTCConfiguration rtc_config;
2387 rtc_config.enable_dtls_srtp = true;
2388 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002389 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002390 CreateAnswerAsLocalDescription();
2391
2392 // At this point we should be receiving stream 1, but not sending anything.
2393 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002394 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002395 DoCreateOffer(&offer, nullptr);
2396
2397 const cricket::ContentInfo* video_content =
2398 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002399 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2400 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002401
2402 const cricket::ContentInfo* audio_content =
2403 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002404 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2405 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002406}
2407
2408// Test that if we're receiving (but not sending) a track, and the
2409// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2410// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002411TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002412 RTCConfiguration rtc_config;
2413 rtc_config.enable_dtls_srtp = true;
2414 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002415 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002416 CreateAnswerAsLocalDescription();
2417
2418 // At this point we should be receiving stream 1, but not sending anything.
2419 // A new offer would be recvonly, but we'll set the "no receive" constraints
2420 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002421 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002422 RTCOfferAnswerOptions options;
2423 options.offer_to_receive_audio = 0;
2424 options.offer_to_receive_video = 0;
2425 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002426
2427 const cricket::ContentInfo* video_content =
2428 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002429 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2430 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002431
2432 const cricket::ContentInfo* audio_content =
2433 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002434 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2435 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002436}
2437
deadbeef653b8e02015-11-11 12:55:10 -08002438// Test that we can use SetConfiguration to change the ICE servers of the
2439// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002440TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002441 CreatePeerConnection();
2442
Steve Anton36da6ff2018-02-16 16:04:20 -08002443 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002444 PeerConnectionInterface::IceServer server;
2445 server.uri = "stun:test_hostname";
2446 config.servers.push_back(server);
2447 EXPECT_TRUE(pc_->SetConfiguration(config));
2448
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002449 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2450 EXPECT_EQ("test_hostname",
2451 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002452}
2453
Steve Anton36da6ff2018-02-16 16:04:20 -08002454TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002455 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002456 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002457 config.type = PeerConnectionInterface::kRelay;
2458 EXPECT_TRUE(pc_->SetConfiguration(config));
2459 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2460}
2461
Steve Anton36da6ff2018-02-16 16:04:20 -08002462TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002463 PeerConnectionInterface::RTCConfiguration config;
2464 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002465 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002466 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002467 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2468
2469 config.prune_turn_ports = true;
2470 EXPECT_TRUE(pc_->SetConfiguration(config));
2471 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2472}
2473
skvladd1f5fda2017-02-03 16:54:05 -08002474// Test that the ice check interval can be changed. This does not verify that
2475// the setting makes it all the way to P2PTransportChannel, as that would
2476// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002477TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002478 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002479 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002480 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002481 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002482 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002483 EXPECT_TRUE(pc_->SetConfiguration(config));
2484 PeerConnectionInterface::RTCConfiguration new_config =
2485 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002486 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002487}
2488
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002489// Test that when SetConfiguration changes both the pool size and other
2490// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002491TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002492 SetConfigurationCreatesPooledSessionCorrectly) {
2493 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002494 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002495 config.ice_candidate_pool_size = 1;
2496 PeerConnectionInterface::IceServer server;
2497 server.uri = kStunAddressOnly;
2498 config.servers.push_back(server);
2499 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002500 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002501
2502 const cricket::FakePortAllocatorSession* session =
2503 static_cast<const cricket::FakePortAllocatorSession*>(
2504 port_allocator_->GetPooledSession());
2505 ASSERT_NE(nullptr, session);
2506 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002507}
2508
deadbeef293e9262017-01-11 12:28:30 -08002509// Test that after SetLocalDescription, changing the pool size is not allowed,
2510// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002511TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002512 CantChangePoolSizeAfterSetLocalDescription) {
2513 CreatePeerConnection();
2514 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002515 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002516 config.ice_candidate_pool_size = 1;
2517 EXPECT_TRUE(pc_->SetConfiguration(config));
2518
2519 // Set remote offer; can still change pool size at this point.
2520 CreateOfferAsRemoteDescription();
2521 config.ice_candidate_pool_size = 2;
2522 EXPECT_TRUE(pc_->SetConfiguration(config));
2523
2524 // Set local answer; now it's too late.
2525 CreateAnswerAsLocalDescription();
2526 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002527 RTCError error;
2528 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2529 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2530}
2531
deadbeef42a42632017-03-10 15:18:00 -08002532// Test that after setting an answer, extra pooled sessions are discarded. The
2533// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002534TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002535 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2536 CreatePeerConnection();
2537
2538 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002539 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002540 config.ice_candidate_pool_size = 4;
2541 EXPECT_TRUE(pc_->SetConfiguration(config));
2542
2543 // Do offer/answer.
2544 CreateOfferAsRemoteDescription();
2545 CreateAnswerAsLocalDescription();
2546
2547 // Expect no pooled sessions to be left.
2548 const cricket::PortAllocatorSession* session =
2549 port_allocator_->GetPooledSession();
2550 EXPECT_EQ(nullptr, session);
2551}
2552
2553// After Close is called, pooled candidates should be discarded so as to not
2554// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002555TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002556 CreatePeerConnection();
2557
Steve Anton36da6ff2018-02-16 16:04:20 -08002558 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002559 config.ice_candidate_pool_size = 3;
2560 EXPECT_TRUE(pc_->SetConfiguration(config));
2561 pc_->Close();
2562
2563 // Expect no pooled sessions to be left.
2564 const cricket::PortAllocatorSession* session =
2565 port_allocator_->GetPooledSession();
2566 EXPECT_EQ(nullptr, session);
2567}
2568
deadbeef293e9262017-01-11 12:28:30 -08002569// Test that SetConfiguration returns an invalid modification error if
2570// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002571TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002572 SetConfigurationReturnsInvalidModificationError) {
2573 PeerConnectionInterface::RTCConfiguration config;
2574 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2575 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2576 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002577 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002578
Steve Anton36da6ff2018-02-16 16:04:20 -08002579 PeerConnectionInterface::RTCConfiguration modified_config =
2580 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002581 modified_config.bundle_policy =
2582 PeerConnectionInterface::kBundlePolicyMaxBundle;
2583 RTCError error;
2584 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2585 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2586
Steve Anton36da6ff2018-02-16 16:04:20 -08002587 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002588 modified_config.rtcp_mux_policy =
2589 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2590 error.set_type(RTCErrorType::NONE);
2591 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2592 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2593
Steve Anton36da6ff2018-02-16 16:04:20 -08002594 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002595 modified_config.continual_gathering_policy =
2596 PeerConnectionInterface::GATHER_CONTINUALLY;
2597 error.set_type(RTCErrorType::NONE);
2598 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2599 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2600}
2601
2602// Test that SetConfiguration returns a range error if the candidate pool size
2603// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002604TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002605 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2606 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002607 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002608 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002609
2610 config.ice_candidate_pool_size = -1;
2611 RTCError error;
2612 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2613 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2614
2615 config.ice_candidate_pool_size = INT_MAX;
2616 error.set_type(RTCErrorType::NONE);
2617 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2618 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2619}
2620
2621// Test that SetConfiguration returns a syntax error if parsing an ICE server
2622// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002623TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002624 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2625 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002626 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002627 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002628
2629 PeerConnectionInterface::IceServer bad_server;
2630 bad_server.uri = "stunn:www.example.com";
2631 config.servers.push_back(bad_server);
2632 RTCError error;
2633 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2634 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2635}
2636
2637// Test that SetConfiguration returns an invalid parameter error if a TURN
2638// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002639TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002640 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2641 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002642 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002643 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002644
2645 PeerConnectionInterface::IceServer bad_server;
2646 bad_server.uri = "turn:www.example.com";
2647 // Missing password.
2648 bad_server.username = "foo";
2649 config.servers.push_back(bad_server);
2650 RTCError error;
2651 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2652 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002653}
2654
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655// Test that PeerConnection::Close changes the states to closed and all remote
2656// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002657TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658 // Initialize a PeerConnection and negotiate local and remote session
2659 // description.
2660 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002661
2662 // With Plan B, verify the stream count. The analog with Unified Plan is the
2663 // RtpTransceiver count.
2664 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2665 ASSERT_EQ(1u, pc_->local_streams()->count());
2666 ASSERT_EQ(1u, pc_->remote_streams()->count());
2667 } else {
2668 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2669 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670
2671 pc_->Close();
2672
2673 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2674 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2675 pc_->ice_connection_state());
2676 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2677 pc_->ice_gathering_state());
2678
Steve Anton36da6ff2018-02-16 16:04:20 -08002679 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2680 EXPECT_EQ(1u, pc_->local_streams()->count());
2681 EXPECT_EQ(1u, pc_->remote_streams()->count());
2682 } else {
2683 // Verify that the RtpTransceivers are still present but all stopped.
2684 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2685 for (auto transceiver : pc_->GetTransceivers()) {
2686 EXPECT_TRUE(transceiver->stopped());
2687 }
2688 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689
Steve Anton36da6ff2018-02-16 16:04:20 -08002690 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2691 ASSERT_TRUE(audio_receiver);
2692 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2693 ASSERT_TRUE(video_receiver);
2694
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002695 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002696 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002697 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002698 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002699 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700}
2701
2702// Test that PeerConnection methods fails gracefully after
2703// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002704// Don't run under Unified Plan since the stream API is not available.
2705TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002706 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002707 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 CreateOfferAsRemoteDescription();
2709 CreateAnswerAsLocalDescription();
2710
2711 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002712 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 pc_->local_streams()->at(0);
2714
2715 pc_->Close();
2716
2717 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002718 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2721
2722 EXPECT_TRUE(pc_->local_description() != NULL);
2723 EXPECT_TRUE(pc_->remote_description() != NULL);
2724
kwibergd1fe2812016-04-27 06:47:29 -07002725 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002726 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002727 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002728 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729
2730 std::string sdp;
2731 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002732 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002733 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002734 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735
2736 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002737 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002738 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002739 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740}
2741
2742// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002743TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002744 InitiateCall();
2745 pc_->Close();
2746 DoGetStats(NULL);
2747}
deadbeefab9b2d12015-10-14 11:33:11 -07002748
2749// NOTE: The series of tests below come from what used to be
2750// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2751// setting a remote or local description has the expected effects.
2752
2753// This test verifies that the remote MediaStreams corresponding to a received
2754// SDP string is created. In this test the two separate MediaStreams are
2755// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002756TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002757 RTCConfiguration config;
2758 config.enable_dtls_srtp = true;
2759 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002760 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002761
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002762 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002763 EXPECT_TRUE(
2764 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2765 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2766 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2767
2768 // Create a session description based on another SDP with another
2769 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002770 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002771
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002772 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002773 EXPECT_TRUE(
2774 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2775}
2776
2777// This test verifies that when remote tracks are added/removed from SDP, the
2778// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002779// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2780// specific behavior.
2781TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002782 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002783 RTCConfiguration config;
2784 config.enable_dtls_srtp = true;
2785 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002786 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002787 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002788 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002789 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2790 reference_collection_));
2791
2792 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002793 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002794 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002795 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002796 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2797 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002798 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002799 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2800 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002801 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002802 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2803 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002804
2805 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002806 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002807 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002808 MockTrackObserver audio_track_observer(audio_track2);
2809 MockTrackObserver video_track_observer(video_track2);
2810
2811 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2812 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002813 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002814 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2815 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002816 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002817 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002818 audio_track2->state(), kTimeout);
2819 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2820 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002821}
2822
2823// This tests that remote tracks are ended if a local session description is set
2824// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002825TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002826 RTCConfiguration config;
2827 config.enable_dtls_srtp = true;
2828 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002829 // First create and set a remote offer, then reject its video content in our
2830 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002831 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2832 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2833 ASSERT_TRUE(audio_receiver);
2834 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2835 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002836
Steve Anton36da6ff2018-02-16 16:04:20 -08002837 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2838 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002839 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002840 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2841 video_receiver->track();
2842 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002843
kwibergd1fe2812016-04-27 06:47:29 -07002844 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002845 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002846 cricket::ContentInfo* video_info =
2847 local_answer->description()->GetContentByName("video");
2848 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002849 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002850 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2851 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002852
2853 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002854 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002855 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002856 video_info = local_offer->description()->GetContentByName("video");
2857 ASSERT_TRUE(video_info != nullptr);
2858 video_info->rejected = true;
2859 cricket::ContentInfo* audio_info =
2860 local_offer->description()->GetContentByName("audio");
2861 ASSERT_TRUE(audio_info != nullptr);
2862 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002863 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002864 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002865 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2866 kTimeout);
2867 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2868 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002869}
2870
2871// This tests that we won't crash if the remote track has been removed outside
2872// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002873// Don't run under Unified Plan since the stream API is not available.
2874TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002875 RTCConfiguration config;
2876 config.enable_dtls_srtp = true;
2877 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002878 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002879 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2880 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2881 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2882
kwibergd1fe2812016-04-27 06:47:29 -07002883 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002884 webrtc::CreateSessionDescription(SdpType::kAnswer,
2885 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002886 cricket::ContentInfo* video_info =
2887 local_answer->description()->GetContentByName("video");
2888 video_info->rejected = true;
2889 cricket::ContentInfo* audio_info =
2890 local_answer->description()->GetContentByName("audio");
2891 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002892 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002893
2894 // No crash is a pass.
2895}
2896
deadbeef5e97fb52015-10-15 12:49:08 -07002897// This tests that if a recvonly remote description is set, no remote streams
2898// will be created, even if the description contains SSRCs/MSIDs.
2899// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002900TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002901 RTCConfiguration config;
2902 config.enable_dtls_srtp = true;
2903 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002904
Steve Anton36da6ff2018-02-16 16:04:20 -08002905 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002906 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2907 strlen(kRecvonly), &recvonly_offer);
2908 CreateAndSetRemoteOffer(recvonly_offer);
2909
2910 EXPECT_EQ(0u, observer_.remote_streams()->count());
2911}
2912
deadbeefab9b2d12015-10-14 11:33:11 -07002913// This tests that a default MediaStream is created if a remote session
2914// description doesn't contain any streams and no MSID support.
2915// It also tests that the default stream is updated if a video m-line is added
2916// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002917// Don't run under Unified Plan since this behavior is Plan B specific.
2918TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002919 RTCConfiguration config;
2920 config.enable_dtls_srtp = true;
2921 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002922 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2923
2924 ASSERT_EQ(1u, observer_.remote_streams()->count());
2925 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2926
2927 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2928 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002929 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002930
2931 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2932 ASSERT_EQ(1u, observer_.remote_streams()->count());
2933 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2934 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002935 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2936 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002937 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2938 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002939 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2940 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002941}
2942
2943// This tests that a default MediaStream is created if a remote session
2944// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002945// Don't run under Unified Plan since this behavior is Plan B specific.
2946TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002947 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002948 RTCConfiguration config;
2949 config.enable_dtls_srtp = true;
2950 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002951 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2952
2953 ASSERT_EQ(1u, observer_.remote_streams()->count());
2954 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2955
2956 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2957 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002958 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002959}
2960
2961// This tests that it won't crash when PeerConnection tries to remove
2962// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002963// Don't run under Unified Plan since this behavior is Plan B specific.
2964TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002965 RTCConfiguration config;
2966 config.enable_dtls_srtp = true;
2967 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002968 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002969 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2970 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2971 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2972
2973 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2974
2975 // No crash is a pass.
2976}
2977
2978// This tests that a default MediaStream is created if the remote session
2979// description doesn't contain any streams and don't contain an indication if
2980// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002981// Don't run under Unified Plan since this behavior is Plan B specific.
2982TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002983 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002984 RTCConfiguration config;
2985 config.enable_dtls_srtp = true;
2986 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002987 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2988
2989 ASSERT_EQ(1u, observer_.remote_streams()->count());
2990 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2991 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2992 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2993}
2994
2995// This tests that a default MediaStream is not created if the remote session
2996// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002997// Don't run under Unified Plan since this behavior is Plan B specific.
2998TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002999 RTCConfiguration config;
3000 config.enable_dtls_srtp = true;
3001 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003002 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3003 EXPECT_EQ(0u, observer_.remote_streams()->count());
3004}
3005
deadbeefbda7e0b2015-12-08 17:13:40 -08003006// This tests that when setting a new description, the old default tracks are
3007// not destroyed and recreated.
3008// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003009// Don't run under Unified Plan since this behavior is Plan B specific.
3010TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003011 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003012 RTCConfiguration config;
3013 config.enable_dtls_srtp = true;
3014 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003015 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3016
3017 ASSERT_EQ(1u, observer_.remote_streams()->count());
3018 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3019 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3020
3021 // Set the track to "disabled", then set a new description and ensure the
3022 // track is still disabled, which ensures it hasn't been recreated.
3023 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3024 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3025 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3026 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3027}
3028
deadbeefab9b2d12015-10-14 11:33:11 -07003029// This tests that a default MediaStream is not created if a remote session
3030// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003031// Don't run under Unified Plan since this behavior is Plan B specific.
3032TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003033 RTCConfiguration config;
3034 config.enable_dtls_srtp = true;
3035 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003036 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003037 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003038 EXPECT_TRUE(
3039 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3040
3041 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3042 EXPECT_EQ(0u, observer_.remote_streams()->count());
3043}
3044
Seth Hampson5897a6e2018-04-03 11:16:33 -07003045// This tests that a default MediaStream is created if a remote SDP comes from
3046// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3047TEST_F(PeerConnectionInterfaceTestPlanB,
3048 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003049 RTCConfiguration config;
3050 config.enable_dtls_srtp = true;
3051 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003052 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3053 // Add a=msid lines to simulate a Unified Plan endpoint that only
3054 // signals stream IDs with a=msid lines.
3055 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3056
3057 CreateAndSetRemoteOffer(sdp_string);
3058
3059 ASSERT_EQ(1u, observer_.remote_streams()->count());
3060 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3061 EXPECT_EQ("default", remote_stream->id());
3062 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3063}
3064
Seth Hampson5b4f0752018-04-02 16:31:36 -07003065// This tests that when a Plan B endpoint receives an SDP that signals no media
3066// stream IDs indicated by the special character "-" in the a=msid line, that
3067// a default stream ID will be used for the MediaStream ID. This can occur
3068// when a Unified Plan endpoint signals no media stream IDs, but signals both
3069// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3070TEST_F(PeerConnectionInterfaceTestPlanB,
3071 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003072 RTCConfiguration config;
3073 config.enable_dtls_srtp = true;
3074 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003075 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3076 // the sender's stream ID will be interpreted as no stream IDs.
3077 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3078 sdp_string.append("a=msid:- audiotrack0\n");
3079
3080 CreateAndSetRemoteOffer(sdp_string);
3081
3082 ASSERT_EQ(1u, observer_.remote_streams()->count());
3083 // Because SSRCs are signaled the track ID will be what was signaled in the
3084 // a=msid line.
3085 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3086 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3087 EXPECT_EQ("default", remote_stream->id());
3088 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003089
3090 // Previously a bug ocurred when setting the remote description a second time.
3091 // This is because we checked equality of the remote StreamParams stream ID
3092 // (empty), and the previously set stream ID for the remote sender
3093 // ("default"). This cause a track to be removed, then added, when really
3094 // nothing should occur because it is the same track.
3095 CreateAndSetRemoteOffer(sdp_string);
3096 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3097 EXPECT_EQ(1u, observer_.add_track_events_.size());
3098 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3099 remote_stream = observer_.remote_streams()->at(0);
3100 EXPECT_EQ("default", remote_stream->id());
3101 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003102}
3103
deadbeefab9b2d12015-10-14 11:33:11 -07003104// This tests that an RtpSender is created when the local description is set
3105// after adding a local stream.
3106// TODO(deadbeef): This test and the one below it need to be updated when
3107// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003108// Don't run under Unified Plan since this behavior is Plan B specific.
3109TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003110 RTCConfiguration config;
3111 config.enable_dtls_srtp = true;
3112 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003113
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003114 // Create an offer with 1 stream with 2 tracks of each type.
3115 rtc::scoped_refptr<StreamCollection> stream_collection =
3116 CreateStreamCollection(1, 2);
3117 pc_->AddStream(stream_collection->at(0));
3118 std::unique_ptr<SessionDescriptionInterface> offer;
3119 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003120 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003121
deadbeefab9b2d12015-10-14 11:33:11 -07003122 auto senders = pc_->GetSenders();
3123 EXPECT_EQ(4u, senders.size());
3124 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3125 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3126 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3127 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3128
3129 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003130 pc_->RemoveStream(stream_collection->at(0));
3131 stream_collection = CreateStreamCollection(1, 1);
3132 pc_->AddStream(stream_collection->at(0));
3133 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003134 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003135
deadbeefab9b2d12015-10-14 11:33:11 -07003136 senders = pc_->GetSenders();
3137 EXPECT_EQ(2u, senders.size());
3138 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3139 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3140 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3141 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3142}
3143
3144// This tests that an RtpSender is created when the local description is set
3145// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003146// Don't run under Unified Plan since this behavior is Plan B specific.
3147TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003148 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003149 RTCConfiguration config;
3150 config.enable_dtls_srtp = true;
3151 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003152
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003153 rtc::scoped_refptr<StreamCollection> stream_collection =
3154 CreateStreamCollection(1, 2);
3155 // Add a stream to create the offer, but remove it afterwards.
3156 pc_->AddStream(stream_collection->at(0));
3157 std::unique_ptr<SessionDescriptionInterface> offer;
3158 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3159 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003160
Steve Antondb45ca82017-09-11 18:27:34 -07003161 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003162 auto senders = pc_->GetSenders();
3163 EXPECT_EQ(0u, senders.size());
3164
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003165 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003166 senders = pc_->GetSenders();
3167 EXPECT_EQ(4u, senders.size());
3168 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3169 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3170 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3171 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3172}
3173
3174// This tests that the expected behavior occurs if the SSRC on a local track is
3175// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003176TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003177 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003178 RTCConfiguration config;
3179 config.enable_dtls_srtp = true;
3180 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003181
Steve Anton36da6ff2018-02-16 16:04:20 -08003182 AddAudioTrack(kAudioTracks[0]);
3183 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003184 std::unique_ptr<SessionDescriptionInterface> offer;
3185 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3186 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003187 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3188 webrtc::CreateSessionDescription(
3189 webrtc::SdpType::kOffer, offer->session_id(),
3190 offer->session_version(),
3191 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003192 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003193
deadbeefab9b2d12015-10-14 11:33:11 -07003194 auto senders = pc_->GetSenders();
3195 EXPECT_EQ(2u, senders.size());
3196 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3197 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3198
3199 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003200 cricket::MediaContentDescription* desc =
3201 cricket::GetFirstAudioContentDescription(modified_offer->description());
3202 ASSERT_TRUE(desc != NULL);
3203 for (StreamParams& stream : desc->mutable_streams()) {
3204 for (unsigned int& ssrc : stream.ssrcs) {
3205 ++ssrc;
3206 }
3207 }
deadbeefab9b2d12015-10-14 11:33:11 -07003208
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003209 desc =
3210 cricket::GetFirstVideoContentDescription(modified_offer->description());
3211 ASSERT_TRUE(desc != NULL);
3212 for (StreamParams& stream : desc->mutable_streams()) {
3213 for (unsigned int& ssrc : stream.ssrcs) {
3214 ++ssrc;
3215 }
3216 }
3217
Steve Antondb45ca82017-09-11 18:27:34 -07003218 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003219 senders = pc_->GetSenders();
3220 EXPECT_EQ(2u, senders.size());
3221 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3222 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3223 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3224 // changed.
3225}
3226
3227// This tests that the expected behavior occurs if a new session description is
3228// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003229// Don't run under Unified Plan since the stream API is not available.
3230TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003231 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003232 RTCConfiguration config;
3233 config.enable_dtls_srtp = true;
3234 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003235
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003236 rtc::scoped_refptr<StreamCollection> stream_collection =
3237 CreateStreamCollection(2, 1);
3238 pc_->AddStream(stream_collection->at(0));
3239 std::unique_ptr<SessionDescriptionInterface> offer;
3240 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003241 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003242
deadbeefab9b2d12015-10-14 11:33:11 -07003243 auto senders = pc_->GetSenders();
3244 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003245 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3246 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003247
3248 // Add a new MediaStream but with the same tracks as in the first stream.
3249 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3250 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003251 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3252 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003253 pc_->AddStream(stream_1);
3254
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003255 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003256 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003257
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003258 auto new_senders = pc_->GetSenders();
3259 // Should be the same senders as before, but with updated stream id.
3260 // Note that this behavior is subject to change in the future.
3261 // We may decide the PC should ignore existing tracks in AddStream.
3262 EXPECT_EQ(senders, new_senders);
3263 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3264 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003265}
3266
zhihuang81c3a032016-11-17 12:06:24 -08003267// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003268TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003269 RTCConfiguration config;
3270 config.enable_dtls_srtp = true;
3271 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003272 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3273 EXPECT_EQ(observer_.num_added_tracks_, 1);
3274 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3275
3276 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003277 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003278 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003279 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3280}
3281
deadbeefd1a38b52016-12-10 13:15:33 -08003282// Test that when SetConfiguration is called and the configuration is
3283// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003284TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003285 PeerConnectionInterface::RTCConfiguration config;
3286 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003287 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003288 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003289 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3290 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003291
3292 // Do initial offer/answer so there's something to restart.
3293 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003294 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003295
3296 // Grab the ufrags.
3297 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3298
3299 // Change ICE policy, which should trigger an ICE restart on the next offer.
3300 config.type = PeerConnectionInterface::kAll;
3301 EXPECT_TRUE(pc_->SetConfiguration(config));
3302 CreateOfferAsLocalDescription();
3303
3304 // Grab the new ufrags.
3305 std::vector<std::string> subsequent_ufrags =
3306 GetUfrags(pc_->local_description());
3307
3308 // Sanity check.
3309 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3310 // Check that each ufrag is different.
3311 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3312 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3313 }
3314}
3315
3316// Test that when SetConfiguration is called and the configuration *isn't*
3317// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003318TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003319 PeerConnectionInterface::RTCConfiguration config;
3320 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003321 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003322 config = pc_->GetConfiguration();
3323 AddAudioTrack(kAudioTracks[0]);
3324 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003325
3326 // Do initial offer/answer so there's something to restart.
3327 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003328 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003329
3330 // Grab the ufrags.
3331 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3332
3333 // Call SetConfiguration with a config identical to what the PC was
3334 // constructed with.
3335 EXPECT_TRUE(pc_->SetConfiguration(config));
3336 CreateOfferAsLocalDescription();
3337
3338 // Grab the new ufrags.
3339 std::vector<std::string> subsequent_ufrags =
3340 GetUfrags(pc_->local_description());
3341
3342 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3343}
3344
3345// Test for a weird corner case scenario:
3346// 1. Audio/video session established.
3347// 2. SetConfiguration changes ICE config; ICE restart needed.
3348// 3. ICE restart initiated by remote peer, but only for one m= section.
3349// 4. Next createOffer should initiate an ICE restart, but only for the other
3350// m= section; it would be pointless to do an ICE restart for the m= section
3351// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003352TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003353 PeerConnectionInterface::RTCConfiguration config;
3354 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003355 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003356 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003357 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3358 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003359
3360 // Do initial offer/answer so there's something to restart.
3361 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003362 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003363
3364 // Change ICE policy, which should set the "needs-ice-restart" flag.
3365 config.type = PeerConnectionInterface::kAll;
3366 EXPECT_TRUE(pc_->SetConfiguration(config));
3367
3368 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003369 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003370 webrtc::CreateSessionDescription(SdpType::kOffer,
3371 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003372 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003373 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3374 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003375 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003376 CreateAnswerAsLocalDescription();
3377
3378 // Grab the ufrags.
3379 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003380 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003381
3382 // Create offer and grab the new ufrags.
3383 CreateOfferAsLocalDescription();
3384 std::vector<std::string> subsequent_ufrags =
3385 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003386 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003387
3388 // Ensure that only the ufrag for the second m= section changed.
3389 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3390 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3391}
3392
deadbeeffe4a8a42016-12-20 17:56:17 -08003393// Tests that the methods to return current/pending descriptions work as
3394// expected at different points in the offer/answer exchange. This test does
3395// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003396TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003397 // This disables DTLS so we can apply an answer to ourselves.
3398 CreatePeerConnection();
3399
3400 // Create initial local offer and get SDP (which will also be used as
3401 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003402 std::unique_ptr<SessionDescriptionInterface> local_offer;
3403 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003404 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003405 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003406
3407 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003408 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3409 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3410 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003411 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3412 EXPECT_EQ(nullptr, pc_->current_local_description());
3413 EXPECT_EQ(nullptr, pc_->current_remote_description());
3414
3415 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003416 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003417 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003418 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3419 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3420 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3421 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003422 EXPECT_EQ(nullptr, pc_->current_local_description());
3423 EXPECT_EQ(nullptr, pc_->current_remote_description());
3424
3425 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003426 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003427 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003428 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3429 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003430 EXPECT_EQ(nullptr, pc_->pending_local_description());
3431 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003432 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3433 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003434
3435 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003436 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003437 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003438 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3439 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3440 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003441 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003442 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3443 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003444
3445 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003446 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003447 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003448 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3449 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3450 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3451 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3452 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3453 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003454
3455 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003456 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003457 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003458 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3459 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003460 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3461 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003462 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3463 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003464}
3465
zhihuang77985012017-02-07 15:45:16 -08003466// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3467// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003468// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003469TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003470 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003471 CreatePeerConnection();
3472 // The RtcEventLog will be reset when the PeerConnection is closed.
3473 pc_->Close();
3474
Elad Alon9e6565b2017-10-11 16:04:13 +02003475 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3476 std::string filename = webrtc::test::OutputPath() +
3477 test_info->test_case_name() + test_info->name();
3478 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3479
3480 constexpr int64_t max_size_bytes = 1024;
3481
zhihuang77985012017-02-07 15:45:16 -08003482 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3483 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003484
3485 // Cleanup.
3486 rtc::ClosePlatformFile(file);
3487 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003488}
3489
Elad Alon99c3fe52017-10-13 16:29:40 +02003490// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3491// after the PeerConnection is closed.
3492// This version tests the StartRtcEventLog version that receives an object
3493// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003494TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003495 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3496 CreatePeerConnection();
3497 // The RtcEventLog will be reset when the PeerConnection is closed.
3498 pc_->Close();
3499
3500 rtc::PlatformFile file = 0;
3501 int64_t max_size_bytes = 1024;
3502 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003503 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003504 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003505 pc_->StopRtcEventLog();
3506}
3507
deadbeef30952b42017-04-21 02:41:29 -07003508// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003509TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003510 CreatePeerConnection();
3511
3512 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003513 RTCOfferAnswerOptions options;
3514 options.offer_to_receive_audio = 1;
3515 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003516 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003517 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003518 cricket::SessionDescription* desc = offer->description();
3519 ASSERT_EQ(2u, desc->transport_infos().size());
3520 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3521 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3522
3523 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003524 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003525 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003526 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003527 desc = answer->description();
3528 ASSERT_EQ(2u, desc->transport_infos().size());
3529 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3530 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3531}
3532
deadbeef1dcb1642017-03-29 21:08:16 -07003533// Test that ICE renomination isn't offered if it's not enabled in the PC's
3534// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003535TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003536 PeerConnectionInterface::RTCConfiguration config;
3537 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003538 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003539 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003540
3541 std::unique_ptr<SessionDescriptionInterface> offer;
3542 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3543 cricket::SessionDescription* desc = offer->description();
3544 EXPECT_EQ(1u, desc->transport_infos().size());
3545 EXPECT_FALSE(
3546 desc->transport_infos()[0].description.GetIceParameters().renomination);
3547}
3548
3549// Test that the ICE renomination option is present in generated offers/answers
3550// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003551TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003552 PeerConnectionInterface::RTCConfiguration config;
3553 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003554 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003555 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003556
3557 std::unique_ptr<SessionDescriptionInterface> offer;
3558 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3559 cricket::SessionDescription* desc = offer->description();
3560 EXPECT_EQ(1u, desc->transport_infos().size());
3561 EXPECT_TRUE(
3562 desc->transport_infos()[0].description.GetIceParameters().renomination);
3563
3564 // Set the offer as a remote description, then create an answer and ensure it
3565 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003566 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003567 std::unique_ptr<SessionDescriptionInterface> answer;
3568 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3569 desc = answer->description();
3570 EXPECT_EQ(1u, desc->transport_infos().size());
3571 EXPECT_TRUE(
3572 desc->transport_infos()[0].description.GetIceParameters().renomination);
3573}
3574
3575// Test that if CreateOffer is called with the deprecated "offer to receive
3576// audio/video" constraints, they're processed and result in an offer with
3577// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003578TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003579 CreatePeerConnection();
3580
Niels Möllerf06f9232018-08-07 12:32:18 +02003581 RTCOfferAnswerOptions options;
3582 options.offer_to_receive_audio = 1;
3583 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003584 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003585 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003586
3587 cricket::SessionDescription* desc = offer->description();
3588 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3589 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3590 ASSERT_NE(nullptr, audio);
3591 ASSERT_NE(nullptr, video);
3592 EXPECT_FALSE(audio->rejected);
3593 EXPECT_FALSE(video->rejected);
3594}
3595
3596// Test that if CreateAnswer is called with the deprecated "offer to receive
3597// audio/video" constraints, they're processed and can be used to reject an
3598// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003599// Don't run under Unified Plan since this behavior is not supported.
3600TEST_F(PeerConnectionInterfaceTestPlanB,
3601 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003602 CreatePeerConnection();
3603
3604 // First, create an offer with audio/video and apply it as a remote
3605 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003606 RTCOfferAnswerOptions options;
3607 options.offer_to_receive_audio = 1;
3608 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003609 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003610 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003611 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003612
3613 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003614 options.offer_to_receive_audio = 0;
3615 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003616 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003617 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003618
3619 cricket::SessionDescription* desc = answer->description();
3620 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3621 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3622 ASSERT_NE(nullptr, audio);
3623 ASSERT_NE(nullptr, video);
3624 EXPECT_TRUE(audio->rejected);
3625 EXPECT_TRUE(video->rejected);
3626}
3627
deadbeef1dcb1642017-03-29 21:08:16 -07003628// Test that negotiation can succeed with a data channel only, and with the max
3629// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003630#ifdef HAVE_SCTP
3631TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3632#else
3633TEST_P(PeerConnectionInterfaceTest,
3634 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3635#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003636 PeerConnectionInterface::RTCConfiguration config;
3637 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003638 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003639
3640 // First, create an offer with only a data channel and apply it as a remote
3641 // description.
3642 pc_->CreateDataChannel("test", nullptr);
3643 std::unique_ptr<SessionDescriptionInterface> offer;
3644 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003645 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003646
3647 // Create and set answer as well.
3648 std::unique_ptr<SessionDescriptionInterface> answer;
3649 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003650 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003651}
3652
Steve Anton36da6ff2018-02-16 16:04:20 -08003653TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003654 CreatePeerConnection();
3655 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003656 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003657 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3658}
3659
Steve Anton36da6ff2018-02-16 16:04:20 -08003660TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003661 CreatePeerConnection();
3662 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003663 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003664 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3665}
3666
Steve Anton36da6ff2018-02-16 16:04:20 -08003667TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003668 CreatePeerConnection();
3669 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003670 bitrate.min_bitrate_bps = 5;
3671 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003672 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3673}
3674
Steve Anton36da6ff2018-02-16 16:04:20 -08003675TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003676 CreatePeerConnection();
3677 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003678 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003679 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3680}
3681
Steve Anton36da6ff2018-02-16 16:04:20 -08003682TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003683 CreatePeerConnection();
3684 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003685 bitrate.current_bitrate_bps = 10;
3686 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003687 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3688}
3689
Steve Anton36da6ff2018-02-16 16:04:20 -08003690TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003691 CreatePeerConnection();
3692 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003693 bitrate.min_bitrate_bps = 10;
3694 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003695 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3696}
3697
Steve Anton36da6ff2018-02-16 16:04:20 -08003698TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003699 CreatePeerConnection();
3700 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003701 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003702 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3703}
3704
Steve Anton038834f2017-07-14 15:59:59 -07003705// ice_regather_interval_range requires WebRTC to be configured for continual
3706// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003707TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003708 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3709 PeerConnectionInterface::RTCConfiguration config;
3710 config.ice_regather_interval_range.emplace(1000, 2000);
3711 config.continual_gathering_policy =
3712 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3713 CreatePeerConnectionExpectFail(config);
3714}
3715
3716// Ensures that there is no error when ice_regather_interval_range is set with
3717// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003718TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003719 SetIceRegatherIntervalRangeWithContinualGathering) {
3720 PeerConnectionInterface::RTCConfiguration config;
3721 config.ice_regather_interval_range.emplace(1000, 2000);
3722 config.continual_gathering_policy =
3723 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003724 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003725}
3726
Niels Möller0c4f7be2018-05-07 14:01:37 +02003727// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003728// by Call's BitrateConstraints, which comes from the SDP or a default value.
3729// This test checks that a call to SetBitrate with a current bitrate that will
3730// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003731TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003732 CreatePeerConnection();
3733 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003734 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003735 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3736}
3737
zhihuang1c378ed2017-08-17 14:10:50 -07003738// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003739TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003740 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3741 RTCOfferAnswerOptions rtc_options;
3742
3743 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3744 // than kMaxOfferToReceiveMedia should be treated as invalid.
3745 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3746 CreatePeerConnection();
3747 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3748
3749 rtc_options.offer_to_receive_audio =
3750 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3751 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3752}
3753
Steve Anton36da6ff2018-02-16 16:04:20 -08003754TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003755 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3756 RTCOfferAnswerOptions rtc_options;
3757
3758 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3759 // than kMaxOfferToReceiveMedia should be treated as invalid.
3760 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3761 CreatePeerConnection();
3762 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3763
3764 rtc_options.offer_to_receive_video =
3765 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3766 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3767}
3768
3769// Test that the audio and video content will be added to an offer if both
3770// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003771TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003772 RTCOfferAnswerOptions rtc_options;
3773 rtc_options.offer_to_receive_audio = 1;
3774 rtc_options.offer_to_receive_video = 1;
3775
3776 std::unique_ptr<SessionDescriptionInterface> offer;
3777 CreatePeerConnection();
3778 offer = CreateOfferWithOptions(rtc_options);
3779 ASSERT_TRUE(offer);
3780 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3781 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3782}
3783
3784// Test that only audio content will be added to the offer if only
3785// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003786TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003787 RTCOfferAnswerOptions rtc_options;
3788 rtc_options.offer_to_receive_audio = 1;
3789 rtc_options.offer_to_receive_video = 0;
3790
3791 std::unique_ptr<SessionDescriptionInterface> offer;
3792 CreatePeerConnection();
3793 offer = CreateOfferWithOptions(rtc_options);
3794 ASSERT_TRUE(offer);
3795 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3796 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3797}
3798
3799// Test that only video content will be added if only |offer_to_receive_video|
3800// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003801TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003802 RTCOfferAnswerOptions rtc_options;
3803 rtc_options.offer_to_receive_audio = 0;
3804 rtc_options.offer_to_receive_video = 1;
3805
3806 std::unique_ptr<SessionDescriptionInterface> offer;
3807 CreatePeerConnection();
3808 offer = CreateOfferWithOptions(rtc_options);
3809 ASSERT_TRUE(offer);
3810 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3811 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3812}
3813
zhihuang1c378ed2017-08-17 14:10:50 -07003814// Test that no media content will be added to the offer if using default
3815// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003816TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003817 RTCOfferAnswerOptions rtc_options;
3818
3819 std::unique_ptr<SessionDescriptionInterface> offer;
3820 CreatePeerConnection();
3821 offer = CreateOfferWithOptions(rtc_options);
3822 ASSERT_TRUE(offer);
3823 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3824 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3825}
3826
3827// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3828// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003829TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3830 CreatePeerConnection();
3831
zhihuang1c378ed2017-08-17 14:10:50 -07003832 RTCOfferAnswerOptions rtc_options;
3833 rtc_options.ice_restart = false;
3834 rtc_options.offer_to_receive_audio = 1;
3835
3836 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003837 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003838 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3839 auto ufrag1 =
3840 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3841 auto pwd1 =
3842 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003843
3844 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3845 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003846 auto ufrag2 =
3847 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3848 auto pwd2 =
3849 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003850
3851 // |ice_restart| is true, the ufrag/pwd should change.
3852 rtc_options.ice_restart = true;
3853 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003854 auto ufrag3 =
3855 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3856 auto pwd3 =
3857 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003858
3859 EXPECT_EQ(ufrag1, ufrag2);
3860 EXPECT_EQ(pwd1, pwd2);
3861 EXPECT_NE(ufrag2, ufrag3);
3862 EXPECT_NE(pwd2, pwd3);
3863}
3864
3865// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3866// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003867TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003868 RTCOfferAnswerOptions rtc_options;
3869 rtc_options.offer_to_receive_audio = 1;
3870 rtc_options.offer_to_receive_video = 1;
3871
3872 std::unique_ptr<SessionDescriptionInterface> offer;
3873 CreatePeerConnection();
3874
3875 rtc_options.use_rtp_mux = true;
3876 offer = CreateOfferWithOptions(rtc_options);
3877 ASSERT_TRUE(offer);
3878 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3879 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3880 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3881
3882 rtc_options.use_rtp_mux = false;
3883 offer = CreateOfferWithOptions(rtc_options);
3884 ASSERT_TRUE(offer);
3885 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3886 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3887 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3888}
3889
zhihuang141aacb2017-08-29 13:23:53 -07003890// This test ensures OnRenegotiationNeeded is called when we add track with
3891// MediaStream -> AddTrack in the same way it is called when we add track with
3892// PeerConnection -> AddTrack.
3893// The test can be removed once addStream is rewritten in terms of addTrack
3894// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003895// Don't run under Unified Plan since the stream API is not available.
3896TEST_F(PeerConnectionInterfaceTestPlanB,
3897 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003898 CreatePeerConnectionWithoutDtls();
3899 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003900 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003901 pc_->AddStream(stream);
3902 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3903 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3904 rtc::scoped_refptr<VideoTrackInterface> video_track(
3905 pc_factory_->CreateVideoTrack(
3906 "video_track", pc_factory_->CreateVideoSource(
3907 std::unique_ptr<cricket::VideoCapturer>(
3908 new cricket::FakeVideoCapturer()))));
3909 stream->AddTrack(audio_track);
3910 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3911 observer_.renegotiation_needed_ = false;
3912
3913 stream->AddTrack(video_track);
3914 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3915 observer_.renegotiation_needed_ = false;
3916
3917 stream->RemoveTrack(audio_track);
3918 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3919 observer_.renegotiation_needed_ = false;
3920
3921 stream->RemoveTrack(video_track);
3922 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3923 observer_.renegotiation_needed_ = false;
3924}
3925
Zhi Huangb2d355e2017-10-26 17:26:37 -07003926// Tests that an error is returned if a description is applied that has fewer
3927// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003928TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003929 MediaSectionCountEnforcedForSubsequentOffer) {
3930 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003931 AddAudioTrack("audio_label");
3932 AddVideoTrack("video_label");
3933
Zhi Huangb2d355e2017-10-26 17:26:37 -07003934 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003935 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003936 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3937
3938 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003939 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003940 offer->description()->contents().pop_back();
3941 offer->description()->contents().pop_back();
3942 ASSERT_TRUE(offer->description()->contents().empty());
3943 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3944
3945 std::unique_ptr<SessionDescriptionInterface> answer;
3946 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3947 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3948
3949 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003950 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003951 offer->description()->contents().pop_back();
3952 offer->description()->contents().pop_back();
3953 ASSERT_TRUE(offer->description()->contents().empty());
3954 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3955}
3956
Johannes Kron89f874e2018-11-12 10:25:48 +01003957TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3958 RTCConfiguration config;
3959 // Default behavior is false.
3960 CreatePeerConnection(config);
3961 std::unique_ptr<SessionDescriptionInterface> offer;
3962 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3963 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3964 // Possible to set to true.
3965 config.offer_extmap_allow_mixed = true;
3966 CreatePeerConnection(config);
3967 offer.release();
3968 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3969 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3970}
3971
Steve Anton36da6ff2018-02-16 16:04:20 -08003972INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3973 PeerConnectionInterfaceTest,
3974 Values(SdpSemantics::kPlanB,
3975 SdpSemantics::kUnifiedPlan));
3976
nisse51542be2016-02-12 02:27:06 -08003977class PeerConnectionMediaConfigTest : public testing::Test {
3978 protected:
3979 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003980 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003981 pcf_->Initialize();
3982 }
nisseeaabdf62017-05-05 02:23:02 -07003983 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003984 const RTCConfiguration& config) {
3985 rtc::scoped_refptr<PeerConnectionInterface> pc(
3986 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003987 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003988 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003989 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003990 }
3991
zhihuang9763d562016-08-05 11:14:50 -07003992 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003993 MockPeerConnectionObserver observer_;
3994};
3995
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003996// This sanity check validates the test infrastructure itself.
3997TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3998 PeerConnectionInterface::RTCConfiguration config;
3999 rtc::scoped_refptr<PeerConnectionInterface> pc(
4000 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
4001 EXPECT_TRUE(pc.get());
4002 observer_.SetPeerConnectionInterface(pc.get()); // Required.
4003 pc->Close(); // No abort -> ok.
4004 SUCCEED();
4005}
4006
nisse51542be2016-02-12 02:27:06 -08004007// This test verifies the default behaviour with no constraints and a
4008// default RTCConfiguration.
4009TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4010 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004011
Niels Möllerf06f9232018-08-07 12:32:18 +02004012 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004013
4014 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004015 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4016 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004017 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004018 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004019}
4020
Niels Möller1d7ecd22018-01-18 15:25:12 +01004021// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004022// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004023TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4024 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004025
Niels Möller71bdda02016-03-31 12:59:59 +02004026 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004027 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004028
Niels Möller1d7ecd22018-01-18 15:25:12 +01004029 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004030}
4031
Niels Möller6539f692018-01-18 08:58:50 +01004032// This test verifies that the experiment_cpu_load_estimator flag is
4033// propagated from RTCConfiguration to the PeerConnection.
4034TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4035 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004036
4037 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004038 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004039
4040 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4041}
4042
deadbeef293e9262017-01-11 12:28:30 -08004043// Tests a few random fields being different.
4044TEST(RTCConfigurationTest, ComparisonOperators) {
4045 PeerConnectionInterface::RTCConfiguration a;
4046 PeerConnectionInterface::RTCConfiguration b;
4047 EXPECT_EQ(a, b);
4048
4049 PeerConnectionInterface::RTCConfiguration c;
4050 c.servers.push_back(PeerConnectionInterface::IceServer());
4051 EXPECT_NE(a, c);
4052
4053 PeerConnectionInterface::RTCConfiguration d;
4054 d.type = PeerConnectionInterface::kRelay;
4055 EXPECT_NE(a, d);
4056
4057 PeerConnectionInterface::RTCConfiguration e;
4058 e.audio_jitter_buffer_max_packets = 5;
4059 EXPECT_NE(a, e);
4060
4061 PeerConnectionInterface::RTCConfiguration f;
4062 f.ice_connection_receiving_timeout = 1337;
4063 EXPECT_NE(a, f);
4064
4065 PeerConnectionInterface::RTCConfiguration g;
4066 g.disable_ipv6 = true;
4067 EXPECT_NE(a, g);
4068
4069 PeerConnectionInterface::RTCConfiguration h(
4070 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4071 EXPECT_NE(a, h);
4072}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004073
4074} // namespace
4075} // namespace webrtc