blob: 198e1e55b109168d2d6c9c2411e7acfa703bcf2c [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
Zhi Huang2a5e4262017-09-14 01:15:03 -070011#include <algorithm>
kwibergd1fe2812016-04-27 06:47:29 -070012#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080013#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080015#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/audio_codecs/builtin_audio_decoder_factory.h"
18#include "api/audio_codecs/builtin_audio_encoder_factory.h"
19#include "api/jsepsessiondescription.h"
20#include "api/mediastreaminterface.h"
21#include "api/peerconnectioninterface.h"
22#include "api/rtpreceiverinterface.h"
23#include "api/rtpsenderinterface.h"
24#include "api/test/fakeconstraints.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020025#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "media/base/fakevideocapturer.h"
27#include "media/engine/webrtcmediaengine.h"
28#include "media/sctp/sctptransportinternal.h"
29#include "modules/audio_processing/include/audio_processing.h"
30#include "p2p/base/fakeportallocator.h"
31#include "pc/audiotrack.h"
32#include "pc/mediasession.h"
33#include "pc/mediastream.h"
34#include "pc/peerconnection.h"
Steve Anton57858b32018-02-15 15:19:50 -080035#include "pc/rtpsender.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "pc/streamcollection.h"
37#include "pc/test/fakeaudiocapturemodule.h"
38#include "pc/test/fakertccertificategenerator.h"
39#include "pc/test/fakevideotracksource.h"
40#include "pc/test/mockpeerconnectionobservers.h"
41#include "pc/test/testsdpstrings.h"
42#include "pc/videocapturertracksource.h"
43#include "pc/videotrack.h"
44#include "rtc_base/gunit.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020045#include "rtc_base/ptr_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "rtc_base/stringutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020047#include "rtc_base/virtualsocketserver.h"
48#include "test/gmock.h"
Elad Alon9e6565b2017-10-11 16:04:13 +020049#include "test/testsupport/fileutils.h"
kwibergac9f8762016-09-30 22:29:43 -070050
51#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#include "pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070053#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054
Seth Hampson845e8782018-03-02 11:34:10 -080055static const char kStreamId1[] = "local_stream_1";
56static const char kStreamId2[] = "local_stream_2";
57static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058static const int kDefaultStunPort = 3478;
59static const char kStunAddressOnly[] = "stun:address";
60static const char kStunInvalidPort[] = "stun:address:-1";
61static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
62static const char kStunAddressPortAndMore2[] = "stun:address:port more";
63static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
64static const char kTurnUsername[] = "user";
65static const char kTurnPassword[] = "password";
66static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020067static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068
deadbeefab9b2d12015-10-14 11:33:11 -070069static const char kStreams[][8] = {"stream1", "stream2"};
70static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
71static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
72
deadbeef5e97fb52015-10-15 12:49:08 -070073static const char kRecvonly[] = "recvonly";
74static const char kSendrecv[] = "sendrecv";
75
deadbeefab9b2d12015-10-14 11:33:11 -070076// Reference SDP with a MediaStream with label "stream1" and audio track with
77// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -080078static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -070079 "v=0\r\n"
80 "o=- 0 0 IN IP4 127.0.0.1\r\n"
81 "s=-\r\n"
82 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080083 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070084 "a=ice-ufrag:e5785931\r\n"
85 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
86 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
87 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070088 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070089 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080090 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070091 "a=rtpmap:103 ISAC/16000\r\n"
92 "a=ssrc:1 cname:stream1\r\n"
93 "a=ssrc:1 mslabel:stream1\r\n"
94 "a=ssrc:1 label:audiotrack0\r\n"
95 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080096 "a=ice-ufrag:e5785931\r\n"
97 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
98 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
99 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700100 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700101 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800102 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700103 "a=rtpmap:120 VP8/90000\r\n"
104 "a=ssrc:2 cname:stream1\r\n"
105 "a=ssrc:2 mslabel:stream1\r\n"
106 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800107// Same string as above but with the MID changed to the Unified Plan default.
108// This is needed so that this SDP can be used as an answer for a Unified Plan
109// offer.
110static const char kSdpStringWithStream1UnifiedPlan[] =
111 "v=0\r\n"
112 "o=- 0 0 IN IP4 127.0.0.1\r\n"
113 "s=-\r\n"
114 "t=0 0\r\n"
115 "m=audio 1 RTP/AVPF 103\r\n"
116 "a=ice-ufrag:e5785931\r\n"
117 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
118 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
119 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
120 "a=mid:0\r\n"
121 "a=sendrecv\r\n"
122 "a=rtcp-mux\r\n"
123 "a=rtpmap:103 ISAC/16000\r\n"
124 "a=ssrc:1 cname:stream1\r\n"
125 "a=ssrc:1 mslabel:stream1\r\n"
126 "a=ssrc:1 label:audiotrack0\r\n"
127 "m=video 1 RTP/AVPF 120\r\n"
128 "a=ice-ufrag:e5785931\r\n"
129 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
130 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
131 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
132 "a=mid:1\r\n"
133 "a=sendrecv\r\n"
134 "a=rtcp-mux\r\n"
135 "a=rtpmap:120 VP8/90000\r\n"
136 "a=ssrc:2 cname:stream1\r\n"
137 "a=ssrc:2 mslabel:stream1\r\n"
138 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700139
zhihuang81c3a032016-11-17 12:06:24 -0800140// Reference SDP with a MediaStream with label "stream1" and audio track with
141// id "audio_1";
142static const char kSdpStringWithStream1AudioTrackOnly[] =
143 "v=0\r\n"
144 "o=- 0 0 IN IP4 127.0.0.1\r\n"
145 "s=-\r\n"
146 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800147 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800148 "a=ice-ufrag:e5785931\r\n"
149 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
150 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
151 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800152 "a=mid:audio\r\n"
153 "a=sendrecv\r\n"
154 "a=rtpmap:103 ISAC/16000\r\n"
155 "a=ssrc:1 cname:stream1\r\n"
156 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800157 "a=ssrc:1 label:audiotrack0\r\n"
158 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800159
deadbeefab9b2d12015-10-14 11:33:11 -0700160// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
161// MediaStreams have one audio track and one video track.
162// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800163static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700164 "v=0\r\n"
165 "o=- 0 0 IN IP4 127.0.0.1\r\n"
166 "s=-\r\n"
167 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800168 "a=msid-semantic: WMS stream1 stream2\r\n"
169 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700170 "a=ice-ufrag:e5785931\r\n"
171 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
172 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
173 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700174 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700175 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800176 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700177 "a=rtpmap:103 ISAC/16000\r\n"
178 "a=ssrc:1 cname:stream1\r\n"
179 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
180 "a=ssrc:3 cname:stream2\r\n"
181 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
182 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800183 "a=ice-ufrag:e5785931\r\n"
184 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
185 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
186 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700187 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700188 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800189 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700190 "a=rtpmap:120 VP8/0\r\n"
191 "a=ssrc:2 cname:stream1\r\n"
192 "a=ssrc:2 msid:stream1 videotrack0\r\n"
193 "a=ssrc:4 cname:stream2\r\n"
194 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800195static const char kSdpStringWithStream1And2UnifiedPlan[] =
196 "v=0\r\n"
197 "o=- 0 0 IN IP4 127.0.0.1\r\n"
198 "s=-\r\n"
199 "t=0 0\r\n"
200 "a=msid-semantic: WMS stream1 stream2\r\n"
201 "m=audio 1 RTP/AVPF 103\r\n"
202 "a=ice-ufrag:e5785931\r\n"
203 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
204 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
205 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
206 "a=mid:0\r\n"
207 "a=sendrecv\r\n"
208 "a=rtcp-mux\r\n"
209 "a=rtpmap:103 ISAC/16000\r\n"
210 "a=ssrc:1 cname:stream1\r\n"
211 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
212 "m=video 1 RTP/AVPF 120\r\n"
213 "a=ice-ufrag:e5785931\r\n"
214 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
215 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
216 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
217 "a=mid:1\r\n"
218 "a=sendrecv\r\n"
219 "a=rtcp-mux\r\n"
220 "a=rtpmap:120 VP8/0\r\n"
221 "a=ssrc:2 cname:stream1\r\n"
222 "a=ssrc:2 msid:stream1 videotrack0\r\n"
223 "m=audio 1 RTP/AVPF 103\r\n"
224 "a=ice-ufrag:e5785931\r\n"
225 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
226 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
227 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
228 "a=mid:2\r\n"
229 "a=sendrecv\r\n"
230 "a=rtcp-mux\r\n"
231 "a=rtpmap:103 ISAC/16000\r\n"
232 "a=ssrc:3 cname:stream2\r\n"
233 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
234 "m=video 1 RTP/AVPF 120\r\n"
235 "a=ice-ufrag:e5785931\r\n"
236 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
237 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
238 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
239 "a=mid:3\r\n"
240 "a=sendrecv\r\n"
241 "a=rtcp-mux\r\n"
242 "a=rtpmap:120 VP8/0\r\n"
243 "a=ssrc:4 cname:stream2\r\n"
244 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700245
246// Reference SDP without MediaStreams. Msid is not supported.
247static const char kSdpStringWithoutStreams[] =
248 "v=0\r\n"
249 "o=- 0 0 IN IP4 127.0.0.1\r\n"
250 "s=-\r\n"
251 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800252 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700253 "a=ice-ufrag:e5785931\r\n"
254 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
255 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
256 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700257 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700258 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800259 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700260 "a=rtpmap:103 ISAC/16000\r\n"
261 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800262 "a=ice-ufrag:e5785931\r\n"
263 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
264 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
265 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700266 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700267 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800268 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700269 "a=rtpmap:120 VP8/90000\r\n";
270
271// Reference SDP without MediaStreams. Msid is supported.
272static const char kSdpStringWithMsidWithoutStreams[] =
273 "v=0\r\n"
274 "o=- 0 0 IN IP4 127.0.0.1\r\n"
275 "s=-\r\n"
276 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800277 "a=msid-semantic: WMS\r\n"
278 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700279 "a=ice-ufrag:e5785931\r\n"
280 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
281 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
282 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700283 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700284 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800285 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700286 "a=rtpmap:103 ISAC/16000\r\n"
287 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800288 "a=ice-ufrag:e5785931\r\n"
289 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
290 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
291 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700292 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700293 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800294 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700295 "a=rtpmap:120 VP8/90000\r\n";
296
297// Reference SDP without MediaStreams and audio only.
298static const char kSdpStringWithoutStreamsAudioOnly[] =
299 "v=0\r\n"
300 "o=- 0 0 IN IP4 127.0.0.1\r\n"
301 "s=-\r\n"
302 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800303 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700304 "a=ice-ufrag:e5785931\r\n"
305 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
306 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
307 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700308 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700309 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800310 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700311 "a=rtpmap:103 ISAC/16000\r\n";
312
313// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
314static const char kSdpStringSendOnlyWithoutStreams[] =
315 "v=0\r\n"
316 "o=- 0 0 IN IP4 127.0.0.1\r\n"
317 "s=-\r\n"
318 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800319 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700320 "a=ice-ufrag:e5785931\r\n"
321 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
322 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
323 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700324 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700325 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700326 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800327 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=rtpmap:103 ISAC/16000\r\n"
329 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800330 "a=ice-ufrag:e5785931\r\n"
331 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
332 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
333 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700334 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700335 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700336 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800337 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700338 "a=rtpmap:120 VP8/90000\r\n";
339
340static const char kSdpStringInit[] =
341 "v=0\r\n"
342 "o=- 0 0 IN IP4 127.0.0.1\r\n"
343 "s=-\r\n"
344 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700345 "a=msid-semantic: WMS\r\n";
346
347static const char kSdpStringAudio[] =
348 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800349 "a=ice-ufrag:e5785931\r\n"
350 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
351 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
352 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700353 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700354 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800355 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700356 "a=rtpmap:103 ISAC/16000\r\n";
357
358static const char kSdpStringVideo[] =
359 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800360 "a=ice-ufrag:e5785931\r\n"
361 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
362 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
363 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700364 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700365 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800366 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700367 "a=rtpmap:120 VP8/90000\r\n";
368
369static const char kSdpStringMs1Audio0[] =
370 "a=ssrc:1 cname:stream1\r\n"
371 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
372
373static const char kSdpStringMs1Video0[] =
374 "a=ssrc:2 cname:stream1\r\n"
375 "a=ssrc:2 msid:stream1 videotrack0\r\n";
376
377static const char kSdpStringMs1Audio1[] =
378 "a=ssrc:3 cname:stream1\r\n"
379 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
380
381static const char kSdpStringMs1Video1[] =
382 "a=ssrc:4 cname:stream1\r\n"
383 "a=ssrc:4 msid:stream1 videotrack1\r\n";
384
deadbeef8662f942017-01-20 21:20:51 -0800385static const char kDtlsSdesFallbackSdp[] =
386 "v=0\r\n"
387 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
388 "s=-\r\n"
389 "c=IN IP4 0.0.0.0\r\n"
390 "t=0 0\r\n"
391 "a=group:BUNDLE audio\r\n"
392 "a=msid-semantic: WMS\r\n"
393 "m=audio 1 RTP/SAVPF 0\r\n"
394 "a=sendrecv\r\n"
395 "a=rtcp-mux\r\n"
396 "a=mid:audio\r\n"
397 "a=ssrc:1 cname:stream1\r\n"
398 "a=ssrc:1 mslabel:stream1\r\n"
399 "a=ssrc:1 label:audiotrack0\r\n"
400 "a=ice-ufrag:e5785931\r\n"
401 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
402 "a=rtpmap:0 pcmu/8000\r\n"
403 "a=fingerprint:sha-1 "
404 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
405 "a=setup:actpass\r\n"
Tommi8e545ee2018-02-08 16:25:20 +0000406 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
deadbeef8662f942017-01-20 21:20:51 -0800407 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
408 "dummy_session_params\r\n";
409
perkjd61bf802016-03-24 03:16:19 -0700410using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800411using ::testing::Values;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700412using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700414using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415using webrtc::AudioTrackInterface;
416using webrtc::DataBuffer;
417using webrtc::DataChannelInterface;
418using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419using webrtc::IceCandidateInterface;
deadbeefc80741f2015-10-22 13:14:45 -0700420using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700421using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422using webrtc::MediaStreamInterface;
423using webrtc::MediaStreamTrackInterface;
424using webrtc::MockCreateSessionDescriptionObserver;
425using webrtc::MockDataChannelObserver;
Steve Anton94286cb2017-09-26 16:20:19 -0700426using webrtc::MockPeerConnectionObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427using webrtc::MockSetSessionDescriptionObserver;
428using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700429using webrtc::NotifierInterface;
430using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431using webrtc::PeerConnectionInterface;
432using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800433using webrtc::RTCError;
434using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700435using webrtc::RtpReceiverInterface;
436using webrtc::RtpSenderInterface;
Steve Anton57858b32018-02-15 15:19:50 -0800437using webrtc::RtpSenderProxyWithInternal;
438using webrtc::RtpSenderInternal;
Steve Anton4e70a722017-11-28 14:57:10 -0800439using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440using webrtc::SdpParseError;
Steve Anton36da6ff2018-02-16 16:04:20 -0800441using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800442using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700444using webrtc::StreamCollection;
445using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100446using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700447using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448using webrtc::VideoTrackInterface;
449
Steve Anton36da6ff2018-02-16 16:04:20 -0800450using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
451using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700452
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453namespace {
454
455// Gets the first ssrc of given content type from the ContentInfo.
456bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
457 if (!content_info || !ssrc) {
458 return false;
459 }
460 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800461 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 if (!media_desc || media_desc->streams().empty()) {
463 return false;
464 }
465 *ssrc = media_desc->streams().begin()->first_ssrc();
466 return true;
467}
468
deadbeefd1a38b52016-12-10 13:15:33 -0800469// Get the ufrags out of an SDP blob. Useful for testing ICE restart
470// behavior.
471std::vector<std::string> GetUfrags(
472 const webrtc::SessionDescriptionInterface* desc) {
473 std::vector<std::string> ufrags;
474 for (const cricket::TransportInfo& info :
475 desc->description()->transport_infos()) {
476 ufrags.push_back(info.description.ice_ufrag);
477 }
478 return ufrags;
479}
480
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481void SetSsrcToZero(std::string* sdp) {
482 const char kSdpSsrcAtribute[] = "a=ssrc:";
483 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
484 size_t ssrc_pos = 0;
485 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
486 std::string::npos) {
487 size_t end_ssrc = sdp->find(" ", ssrc_pos);
488 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
489 ssrc_pos = end_ssrc;
490 }
491}
492
deadbeefab9b2d12015-10-14 11:33:11 -0700493// Check if |streams| contains the specified track.
494bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800495 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700496 const std::string& track_id) {
497 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800498 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700499 return true;
500 }
501 }
502 return false;
503}
504
505// Check if |senders| contains the specified sender, by id.
506bool ContainsSender(
507 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
508 const std::string& id) {
509 for (const auto& sender : senders) {
510 if (sender->id() == id) {
511 return true;
512 }
513 }
514 return false;
515}
516
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700517// Check if |senders| contains the specified sender, by id and stream id.
518bool ContainsSender(
519 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
520 const std::string& id,
521 const std::string& stream_id) {
522 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700523 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700524 return true;
525 }
526 }
527 return false;
528}
529
deadbeefab9b2d12015-10-14 11:33:11 -0700530// Create a collection of streams.
531// CreateStreamCollection(1) creates a collection that
532// correspond to kSdpStringWithStream1.
533// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
534rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700535 int number_of_streams,
536 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700537 rtc::scoped_refptr<StreamCollection> local_collection(
538 StreamCollection::Create());
539
540 for (int i = 0; i < number_of_streams; ++i) {
541 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
542 webrtc::MediaStream::Create(kStreams[i]));
543
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700544 for (int j = 0; j < tracks_per_stream; ++j) {
545 // Add a local audio track.
546 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
547 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
548 nullptr));
549 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700550
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700551 // Add a local video track.
552 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
553 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700554 webrtc::FakeVideoTrackSource::Create(),
555 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700556 stream->AddTrack(video_track);
557 }
deadbeefab9b2d12015-10-14 11:33:11 -0700558
559 local_collection->AddStream(stream);
560 }
561 return local_collection;
562}
563
564// Check equality of StreamCollections.
565bool CompareStreamCollections(StreamCollectionInterface* s1,
566 StreamCollectionInterface* s2) {
567 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
568 return false;
569 }
570
571 for (size_t i = 0; i != s1->count(); ++i) {
572 if (s1->at(i)->label() != s2->at(i)->label()) {
573 return false;
574 }
575 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
576 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
577 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
578 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
579
580 if (audio_tracks1.size() != audio_tracks2.size()) {
581 return false;
582 }
583 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
584 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
585 return false;
586 }
587 }
588 if (video_tracks1.size() != video_tracks2.size()) {
589 return false;
590 }
591 for (size_t j = 0; j != video_tracks1.size(); ++j) {
592 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
593 return false;
594 }
595 }
596 }
597 return true;
598}
599
perkjd61bf802016-03-24 03:16:19 -0700600// Helper class to test Observer.
601class MockTrackObserver : public ObserverInterface {
602 public:
603 explicit MockTrackObserver(NotifierInterface* notifier)
604 : notifier_(notifier) {
605 notifier_->RegisterObserver(this);
606 }
607
608 ~MockTrackObserver() { Unregister(); }
609
610 void Unregister() {
611 if (notifier_) {
612 notifier_->UnregisterObserver(this);
613 notifier_ = nullptr;
614 }
615 }
616
617 MOCK_METHOD0(OnChanged, void());
618
619 private:
620 NotifierInterface* notifier_;
621};
622
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700624
nisse528b7932017-05-08 03:21:43 -0700625// The PeerConnectionMediaConfig tests below verify that configuration and
626// constraints are propagated into the PeerConnection's MediaConfig. These
627// settings are intended for MediaChannel constructors, but that is not
628// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700629class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
630 public:
zhihuang38ede132017-06-15 12:52:32 -0700631 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
632 CreatePeerConnectionFactoryForTest() {
633 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
634 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
635
henrika919dc2e2017-10-12 14:24:55 +0200636 // Use fake audio device module since we're only testing the interface
637 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700638 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
639 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200640 FakeAudioCaptureModule::Create(), audio_encoder_factory,
641 audio_decoder_factory, nullptr, nullptr, nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100642 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700643
644 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
645 webrtc::CreateCallFactory();
646
647 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
648 webrtc::CreateRtcEventLogFactory();
649
650 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
651 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200652 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700653 std::move(event_log_factory));
654 }
655
656 PeerConnectionFactoryForTest(
657 rtc::Thread* network_thread,
658 rtc::Thread* worker_thread,
659 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700660 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
661 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
662 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
663 : webrtc::PeerConnectionFactory(network_thread,
664 worker_thread,
665 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700666 std::move(media_engine),
667 std::move(call_factory),
668 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800669
zhihuang29ff8442016-07-27 11:07:25 -0700670 cricket::TransportController* CreateTransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700671 cricket::PortAllocator* port_allocator,
Qingsi Wang93a84392018-01-30 17:13:09 -0800672 bool redetermine_role_on_ice_restart,
673 webrtc::RtcEventLog* event_log = nullptr) override {
zhihuang29ff8442016-07-27 11:07:25 -0700674 transport_controller = new cricket::TransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700675 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
Qingsi Wang93a84392018-01-30 17:13:09 -0800676 redetermine_role_on_ice_restart, rtc::CryptoOptions(), event_log);
zhihuang29ff8442016-07-27 11:07:25 -0700677 return transport_controller;
678 }
679
deadbeefd7850b22017-08-23 10:59:19 -0700680 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700681 cricket::TransportController* transport_controller;
zhihuang29ff8442016-07-27 11:07:25 -0700682};
683
Steve Anton36da6ff2018-02-16 16:04:20 -0800684// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
685class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800687 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
688 : vss_(new rtc::VirtualSocketServer()),
689 main_(vss_.get()),
690 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800691#ifdef WEBRTC_ANDROID
692 webrtc::InitializeAndroidObjects();
693#endif
694 }
695
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700697 // Use fake audio capture module since we're only testing the interface
698 // level, and using a real one could make tests flaky when run in parallel.
699 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700701 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +0200702 fake_audio_capture_module_, webrtc::CreateBuiltinAudioEncoderFactory(),
703 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr);
danilchape9021a32016-05-17 01:52:02 -0700704 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700705 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700706 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700707 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
710 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700711 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 }
713
deadbeef293e9262017-01-11 12:28:30 -0800714 // DTLS does not work in a loopback call, so is disabled for most of the
715 // tests in this file.
716 void CreatePeerConnectionWithoutDtls() {
717 FakeConstraints no_dtls_constraints;
718 no_dtls_constraints.AddMandatory(
719 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
720
721 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
722 &no_dtls_constraints);
723 }
724
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700726 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
727 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 }
729
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 void CreatePeerConnectionWithIceTransportsType(
731 PeerConnectionInterface::IceTransportsType type) {
732 PeerConnectionInterface::RTCConfiguration config;
733 config.type = type;
734 return CreatePeerConnection(config, nullptr);
735 }
736
737 void CreatePeerConnectionWithIceServer(const std::string& uri,
738 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800739 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700741 server.uri = uri;
742 server.password = password;
743 config.servers.push_back(server);
744 CreatePeerConnection(config, nullptr);
745 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100747 void CreatePeerConnection(
748 const PeerConnectionInterface::RTCConfiguration& config,
749 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700750 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800751 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
752 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000753
deadbeef1dcb1642017-03-29 21:08:16 -0700754 // Create certificate generator unless DTLS constraint is explicitly set to
755 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200756 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000757 bool dtls;
758 if (FindConstraint(constraints,
759 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
760 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200761 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800762 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
763 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000764 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800765 RTCConfiguration modified_config = config;
766 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200767 pc_ = pc_factory_->CreatePeerConnection(
Steve Anton36da6ff2018-02-16 16:04:20 -0800768 modified_config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200769 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 ASSERT_TRUE(pc_.get() != NULL);
771 observer_.SetPeerConnectionInterface(pc_.get());
772 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
773 }
774
deadbeef0a6c4ca2015-10-06 11:38:28 -0700775 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800776 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700777 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700778 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800779 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800780 config.sdp_semantics = sdp_semantics_;
781 rtc::scoped_refptr<PeerConnectionInterface> pc =
782 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
783 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800784 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700785 }
786
Steve Anton038834f2017-07-14 15:59:59 -0700787 void CreatePeerConnectionExpectFail(
788 PeerConnectionInterface::RTCConfiguration config) {
789 PeerConnectionInterface::IceServer server;
790 server.uri = kTurnIceServerUri;
791 server.password = kTurnPassword;
792 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800793 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700794 rtc::scoped_refptr<PeerConnectionInterface> pc =
795 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
796 EXPECT_EQ(nullptr, pc);
797 }
798
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700800 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
802 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
803 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800805 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806
deadbeef0a6c4ca2015-10-06 11:38:28 -0700807 CreatePeerConnectionExpectFail(kStunInvalidPort);
808 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
809 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700811 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800812 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
813 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800815 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800817 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800819 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 }
821
822 void ReleasePeerConnection() {
823 pc_ = NULL;
824 observer_.SetPeerConnectionInterface(NULL);
825 }
826
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
828 const std::string& label) {
829 auto video_source = pc_factory_->CreateVideoSource(
830 rtc::MakeUnique<cricket::FakeVideoCapturer>(), nullptr);
831 return pc_factory_->CreateVideoTrack(label, video_source);
832 }
833
834 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800835 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800836 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800837 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800838 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
840 observer_.renegotiation_needed_ = false;
841 }
842
Steve Anton36da6ff2018-02-16 16:04:20 -0800843 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700844 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800846 stream->AddTrack(CreateVideoTrack(label + "v0"));
847 ASSERT_TRUE(pc_->AddStream(stream));
848 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
849 observer_.renegotiation_needed_ = false;
850 }
851
852 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
853 const std::string& label) {
854 return pc_factory_->CreateAudioTrack(label, nullptr);
855 }
856
857 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800858 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800859 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800860 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800861 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
862 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
863 observer_.renegotiation_needed_ = false;
864 }
865
866 void AddAudioStream(const std::string& label) {
867 rtc::scoped_refptr<MediaStreamInterface> stream(
868 pc_factory_->CreateLocalMediaStream(label));
869 stream->AddTrack(CreateAudioTrack(label + "a0"));
870 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
872 observer_.renegotiation_needed_ = false;
873 }
874
Seth Hampson845e8782018-03-02 11:34:10 -0800875 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 const std::string& audio_track_label,
877 const std::string& video_track_label) {
878 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700879 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800880 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800881 stream->AddTrack(CreateAudioTrack(audio_track_label));
882 stream->AddTrack(CreateVideoTrack(video_track_label));
883 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
885 observer_.renegotiation_needed_ = false;
886 }
887
Steve Anton36da6ff2018-02-16 16:04:20 -0800888 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
889 cricket::MediaType media_type) {
890 for (auto receiver : pc_->GetReceivers()) {
891 if (receiver->media_type() == media_type) {
892 return receiver;
893 }
894 }
895 return nullptr;
896 }
897
kwibergd1fe2812016-04-27 06:47:29 -0700898 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700899 bool offer,
900 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000901 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
902 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 MockCreateSessionDescriptionObserver>());
904 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700905 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700907 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 }
909 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700910 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 return observer->result();
912 }
913
kwibergd1fe2812016-04-27 06:47:29 -0700914 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700915 MediaConstraintsInterface* constraints) {
916 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 }
918
kwibergd1fe2812016-04-27 06:47:29 -0700919 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700920 MediaConstraintsInterface* constraints) {
921 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 }
923
Steve Antondb45ca82017-09-11 18:27:34 -0700924 bool DoSetSessionDescription(
925 std::unique_ptr<SessionDescriptionInterface> desc,
926 bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000927 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
928 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 MockSetSessionDescriptionObserver>());
930 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700931 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700933 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 }
zhihuang29ff8442016-07-27 11:07:25 -0700935 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
936 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
937 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 return observer->result();
939 }
940
Steve Antondb45ca82017-09-11 18:27:34 -0700941 bool DoSetLocalDescription(
942 std::unique_ptr<SessionDescriptionInterface> desc) {
943 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 }
945
Steve Antondb45ca82017-09-11 18:27:34 -0700946 bool DoSetRemoteDescription(
947 std::unique_ptr<SessionDescriptionInterface> desc) {
948 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 }
950
951 // Calls PeerConnection::GetStats and check the return value.
952 // It does not verify the values in the StatReports since a RTCP packet might
953 // be required.
954 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000955 rtc::scoped_refptr<MockStatsObserver> observer(
956 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000957 if (!pc_->GetStats(
958 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 return false;
960 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
961 return observer->called();
962 }
963
Harald Alvestrand89061872018-01-02 14:08:34 +0100964 // Call the standards-compliant GetStats function.
965 bool DoGetRTCStats() {
966 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
967 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
968 pc_->GetStats(callback);
969 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
970 return callback->called();
971 }
972
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800974 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800976 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800977 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800978 } else {
979 // Unified Plan does not support AddStream, so just add an audio and video
980 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800981 AddAudioTrack(kAudioTracks[0], {kStreamId1});
982 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800983 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 CreateOfferReceiveAnswer();
985 }
986
987 // Verify that RTP Header extensions has been negotiated for audio and video.
988 void VerifyRemoteRtpHeaderExtensions() {
989 const cricket::MediaContentDescription* desc =
990 cricket::GetFirstAudioContentDescription(
991 pc_->remote_description()->description());
992 ASSERT_TRUE(desc != NULL);
993 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
994
995 desc = cricket::GetFirstVideoContentDescription(
996 pc_->remote_description()->description());
997 ASSERT_TRUE(desc != NULL);
998 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
999 }
1000
1001 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001002 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001003 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 std::string sdp;
1005 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001006 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001007 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001008 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1010 }
1011
deadbeefab9b2d12015-10-14 11:33:11 -07001012 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001013 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001014 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001015 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001016 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1017 }
1018
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001020 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001021 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022
1023 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1024 // audio codec change, even if the parameter has nothing to do with
1025 // receiving. Not all parameters are serialized to SDP.
1026 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1027 // the SessionDescription, it is necessary to do that here to in order to
1028 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1029 // https://code.google.com/p/webrtc/issues/detail?id=1356
1030 std::string sdp;
1031 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001032 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001033 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001034 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1036 }
1037
1038 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001039 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001040 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041
1042 std::string sdp;
1043 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001044 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001045 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001046 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1048 }
1049
1050 void CreateOfferReceiveAnswer() {
1051 CreateOfferAsLocalDescription();
1052 std::string sdp;
1053 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1054 CreateAnswerAsRemoteDescription(sdp);
1055 }
1056
1057 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001058 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001059 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1061 // audio codec change, even if the parameter has nothing to do with
1062 // receiving. Not all parameters are serialized to SDP.
1063 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1064 // the SessionDescription, it is necessary to do that here to in order to
1065 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1066 // https://code.google.com/p/webrtc/issues/detail?id=1356
1067 std::string sdp;
1068 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001069 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001070 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071
Steve Antondb45ca82017-09-11 18:27:34 -07001072 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001074 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001075 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 }
1077
deadbeefab9b2d12015-10-14 11:33:11 -07001078 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001079 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001080 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001081 ASSERT_TRUE(answer);
1082 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1084 }
1085
deadbeefab9b2d12015-10-14 11:33:11 -07001086 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001087 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001088 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001089 ASSERT_TRUE(pr_answer);
1090 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001092 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001093 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001094 ASSERT_TRUE(answer);
1095 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1097 }
1098
Seth Hampson845e8782018-03-02 11:34:10 -08001099 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001100 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001101 // called with the given stream id and expected number of tracks.
1102 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001103 int expected_num_tracks) {
1104 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001105 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001106 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001107 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 }
1109
1110 // Creates an offer and applies it as a local session description.
1111 // Creates an answer with the same SDP an the offer but removes all lines
1112 // that start with a:ssrc"
1113 void CreateOfferReceiveAnswerWithoutSsrc() {
1114 CreateOfferAsLocalDescription();
1115 std::string sdp;
1116 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1117 SetSsrcToZero(&sdp);
1118 CreateAnswerAsRemoteDescription(sdp);
1119 }
1120
deadbeefab9b2d12015-10-14 11:33:11 -07001121 // This function creates a MediaStream with label kStreams[0] and
1122 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1123 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001124 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001125 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001126 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001127 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1128 size_t number_of_video_tracks) {
1129 EXPECT_LE(number_of_audio_tracks, 2u);
1130 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001131
1132 reference_collection_ = StreamCollection::Create();
1133 std::string sdp_ms1 = std::string(kSdpStringInit);
1134
Seth Hampson845e8782018-03-02 11:34:10 -08001135 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001136
1137 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001138 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001139 reference_collection_->AddStream(stream);
1140
1141 if (number_of_audio_tracks > 0) {
1142 sdp_ms1 += std::string(kSdpStringAudio);
1143 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1144 AddAudioTrack(kAudioTracks[0], stream);
1145 }
1146 if (number_of_audio_tracks > 1) {
1147 sdp_ms1 += kSdpStringMs1Audio1;
1148 AddAudioTrack(kAudioTracks[1], stream);
1149 }
1150
1151 if (number_of_video_tracks > 0) {
1152 sdp_ms1 += std::string(kSdpStringVideo);
1153 sdp_ms1 += std::string(kSdpStringMs1Video0);
1154 AddVideoTrack(kVideoTracks[0], stream);
1155 }
1156 if (number_of_video_tracks > 1) {
1157 sdp_ms1 += kSdpStringMs1Video1;
1158 AddVideoTrack(kVideoTracks[1], stream);
1159 }
1160
kwibergd1fe2812016-04-27 06:47:29 -07001161 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001162 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001163 }
1164
1165 void AddAudioTrack(const std::string& track_id,
1166 MediaStreamInterface* stream) {
1167 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1168 webrtc::AudioTrack::Create(track_id, nullptr));
1169 ASSERT_TRUE(stream->AddTrack(audio_track));
1170 }
1171
1172 void AddVideoTrack(const std::string& track_id,
1173 MediaStreamInterface* stream) {
1174 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001175 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001176 webrtc::FakeVideoTrackSource::Create(),
1177 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001178 ASSERT_TRUE(stream->AddTrack(video_track));
1179 }
1180
Steve Anton36da6ff2018-02-16 16:04:20 -08001181 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001182 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001183 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001184 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001185 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1186 return offer;
1187 }
1188
Steve Anton36da6ff2018-02-16 16:04:20 -08001189 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1190 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001191 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001192 std::unique_ptr<SessionDescriptionInterface> offer;
1193 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1194 return offer;
1195 }
1196
1197 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1198 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1199 std::unique_ptr<SessionDescriptionInterface> answer;
1200 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1201 return answer;
1202 }
1203
kwibergfd8be342016-05-14 19:44:11 -07001204 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001205 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001206 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001207 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001208 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1209 return answer;
1210 }
1211
1212 const std::string& GetFirstAudioStreamCname(
1213 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001214 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001215 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001216 return audio_desc->streams()[0].cname;
1217 }
1218
zhihuang1c378ed2017-08-17 14:10:50 -07001219 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1220 const RTCOfferAnswerOptions& offer_answer_options) {
1221 RTC_DCHECK(pc_);
1222 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1223 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1224 pc_->CreateOffer(observer, offer_answer_options);
1225 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1226 return observer->MoveDescription();
1227 }
1228
1229 void CreateOfferWithOptionsAsRemoteDescription(
1230 std::unique_ptr<SessionDescriptionInterface>* desc,
1231 const RTCOfferAnswerOptions& offer_answer_options) {
1232 *desc = CreateOfferWithOptions(offer_answer_options);
1233 ASSERT_TRUE(desc != nullptr);
1234 std::string sdp;
1235 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001236 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001237 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001238 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001239 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1240 }
1241
1242 void CreateOfferWithOptionsAsLocalDescription(
1243 std::unique_ptr<SessionDescriptionInterface>* desc,
1244 const RTCOfferAnswerOptions& offer_answer_options) {
1245 *desc = CreateOfferWithOptions(offer_answer_options);
1246 ASSERT_TRUE(desc != nullptr);
1247 std::string sdp;
1248 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001249 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001250 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001251
Steve Antondb45ca82017-09-11 18:27:34 -07001252 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001253 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1254 }
1255
1256 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001257 RTC_DCHECK(content);
1258 RTC_DCHECK(content->media_description());
1259 for (const cricket::AudioCodec& codec :
1260 content->media_description()->as_audio()->codecs()) {
1261 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001262 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001263 }
zhihuang1c378ed2017-08-17 14:10:50 -07001264 }
1265 return false;
1266 }
1267
Steve Anton36da6ff2018-02-16 16:04:20 -08001268 const char* GetSdpStringWithStream1() const {
1269 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1270 return kSdpStringWithStream1PlanB;
1271 } else {
1272 return kSdpStringWithStream1UnifiedPlan;
1273 }
1274 }
1275
1276 const char* GetSdpStringWithStream1And2() const {
1277 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1278 return kSdpStringWithStream1And2PlanB;
1279 } else {
1280 return kSdpStringWithStream1And2UnifiedPlan;
1281 }
1282 }
1283
deadbeef9a6f4d42017-05-15 19:43:33 -07001284 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1285 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001286 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001287 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001288 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001289 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1290 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1291 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001293 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001294 const SdpSemantics sdp_semantics_;
1295};
1296
1297class PeerConnectionInterfaceTest
1298 : public PeerConnectionInterfaceBaseTest,
1299 public ::testing::WithParamInterface<SdpSemantics> {
1300 protected:
1301 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1302};
1303
1304class PeerConnectionInterfaceTestPlanB
1305 : public PeerConnectionInterfaceBaseTest {
1306 protected:
1307 PeerConnectionInterfaceTestPlanB()
1308 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309};
1310
zhihuang8f65cdf2016-05-06 18:40:30 -07001311// Generate different CNAMEs when PeerConnections are created.
1312// The CNAMEs are expected to be generated randomly. It is possible
1313// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001314TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001315 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001316 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001317 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001318 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001319 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1320 GetFirstAudioStreamCname(offer2.get()));
1321}
1322
Steve Anton36da6ff2018-02-16 16:04:20 -08001323TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001324 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001325 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001326 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001327 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001328 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1329 GetFirstAudioStreamCname(answer2.get()));
1330}
1331
Steve Anton36da6ff2018-02-16 16:04:20 -08001332TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 CreatePeerConnectionWithDifferentConfigurations) {
1334 CreatePeerConnectionWithDifferentConfigurations();
1335}
1336
Steve Anton36da6ff2018-02-16 16:04:20 -08001337TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001338 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1339 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1340 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1341 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1342 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1343 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1344 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1345 port_allocator_->candidate_filter());
1346 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1347 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1348}
1349
1350// Test that when a PeerConnection is created with a nonzero candidate pool
1351// size, the pooled PortAllocatorSession is created with all the attributes
1352// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001353TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001354 PeerConnectionInterface::RTCConfiguration config;
1355 PeerConnectionInterface::IceServer server;
1356 server.uri = kStunAddressOnly;
1357 config.servers.push_back(server);
1358 config.type = PeerConnectionInterface::kRelay;
1359 config.disable_ipv6 = true;
1360 config.tcp_candidate_policy =
1361 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001362 config.candidate_network_policy =
1363 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001364 config.ice_candidate_pool_size = 1;
1365 CreatePeerConnection(config, nullptr);
1366
1367 const cricket::FakePortAllocatorSession* session =
1368 static_cast<const cricket::FakePortAllocatorSession*>(
1369 port_allocator_->GetPooledSession());
1370 ASSERT_NE(nullptr, session);
1371 EXPECT_EQ(1UL, session->stun_servers().size());
1372 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1373 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001374 EXPECT_LT(0U,
1375 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001376}
1377
deadbeefd21eab32017-07-26 16:50:11 -07001378// Test that network-related RTCConfiguration members are applied to the
1379// PortAllocator when CreatePeerConnection is called. Specifically:
1380// - disable_ipv6_on_wifi
1381// - max_ipv6_networks
1382// - tcp_candidate_policy
1383// - candidate_network_policy
1384// - prune_turn_ports
1385//
1386// Note that the candidate filter (RTCConfiguration::type) is already tested
1387// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001388TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001389 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1390 // Create fake port allocator.
1391 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1392 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1393 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1394
1395 // Create RTCConfiguration with some network-related fields relevant to
1396 // PortAllocator populated.
1397 PeerConnectionInterface::RTCConfiguration config;
1398 config.disable_ipv6_on_wifi = true;
1399 config.max_ipv6_networks = 10;
1400 config.tcp_candidate_policy =
1401 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1402 config.candidate_network_policy =
1403 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1404 config.prune_turn_ports = true;
1405
1406 // Create the PC factory and PC with the above config.
1407 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1408 webrtc::CreatePeerConnectionFactory(
1409 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001410 rtc::Thread::Current(), fake_audio_capture_module_,
1411 webrtc::CreateBuiltinAudioEncoderFactory(),
1412 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr));
deadbeefd21eab32017-07-26 16:50:11 -07001413 rtc::scoped_refptr<PeerConnectionInterface> pc(
1414 pc_factory->CreatePeerConnection(
1415 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1416
1417 // Now validate that the config fields set above were applied to the
1418 // PortAllocator, as flags or otherwise.
1419 EXPECT_FALSE(raw_port_allocator->flags() &
1420 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1421 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1422 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1423 EXPECT_TRUE(raw_port_allocator->flags() &
1424 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1425 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1426}
1427
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001428// Test that the PeerConnection initializes the port allocator passed into it,
1429// and on the correct thread.
Steve Anton36da6ff2018-02-16 16:04:20 -08001430TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001431 CreatePeerConnectionInitializesPortAllocatorOnNetworkThread) {
tommie7251592017-07-14 14:44:46 -07001432 std::unique_ptr<rtc::Thread> network_thread(
1433 rtc::Thread::CreateWithSocketServer());
1434 network_thread->Start();
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001435 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1436 webrtc::CreatePeerConnectionFactory(
tommie7251592017-07-14 14:44:46 -07001437 network_thread.get(), rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001438 fake_audio_capture_module_,
1439 webrtc::CreateBuiltinAudioEncoderFactory(),
1440 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr));
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001441 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
tommie7251592017-07-14 14:44:46 -07001442 new cricket::FakePortAllocator(network_thread.get(), nullptr));
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001443 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1444 PeerConnectionInterface::RTCConfiguration config;
1445 rtc::scoped_refptr<PeerConnectionInterface> pc(
1446 pc_factory->CreatePeerConnection(
1447 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1448 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1449 // so all we have to do here is check that it's initialized.
1450 EXPECT_TRUE(raw_port_allocator->initialized());
1451}
1452
deadbeef46c73892016-11-16 19:42:04 -08001453// Check that GetConfiguration returns the configuration the PeerConnection was
1454// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001455TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001456 PeerConnectionInterface::RTCConfiguration config;
1457 config.type = PeerConnectionInterface::kRelay;
1458 CreatePeerConnection(config, nullptr);
1459
1460 PeerConnectionInterface::RTCConfiguration returned_config =
1461 pc_->GetConfiguration();
1462 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1463}
1464
1465// Check that GetConfiguration returns the last configuration passed into
1466// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001467TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001468 CreatePeerConnection();
1469
Steve Anton36da6ff2018-02-16 16:04:20 -08001470 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001471 config.type = PeerConnectionInterface::kRelay;
1472 EXPECT_TRUE(pc_->SetConfiguration(config));
1473
1474 PeerConnectionInterface::RTCConfiguration returned_config =
1475 pc_->GetConfiguration();
1476 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1477}
1478
Steve Anton36da6ff2018-02-16 16:04:20 -08001479TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001480 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001481 AddVideoStream(kStreamId1);
1482 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 ASSERT_EQ(2u, pc_->local_streams()->count());
1484
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001485 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001486 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001487 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001488 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001489 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001490 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001492 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001493 EXPECT_EQ(3u, pc_->local_streams()->count());
1494
1495 // Remove the third stream.
1496 pc_->RemoveStream(pc_->local_streams()->at(2));
1497 EXPECT_EQ(2u, pc_->local_streams()->count());
1498
1499 // Remove the second stream.
1500 pc_->RemoveStream(pc_->local_streams()->at(1));
1501 EXPECT_EQ(1u, pc_->local_streams()->count());
1502
1503 // Remove the first stream.
1504 pc_->RemoveStream(pc_->local_streams()->at(0));
1505 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506}
1507
deadbeefab9b2d12015-10-14 11:33:11 -07001508// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001509// Don't run under Unified Plan since the stream API is not available.
1510TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001511 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001512 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001513 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001514 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001515
deadbeefab9b2d12015-10-14 11:33:11 -07001516 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001517 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001518 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001519
deadbeefab9b2d12015-10-14 11:33:11 -07001520 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001521 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001522 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001523
1524 // Add another stream and ensure the offer includes both the old and new
1525 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001526 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001527 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001528
Steve Antonb1c1de12017-12-21 15:14:30 -08001529 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001530 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1531 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001532
Steve Antonb1c1de12017-12-21 15:14:30 -08001533 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001534 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1535 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001536}
1537
Steve Anton36da6ff2018-02-16 16:04:20 -08001538// Don't run under Unified Plan since the stream API is not available.
1539TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001540 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001541 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 ASSERT_EQ(1u, pc_->local_streams()->count());
1543 pc_->RemoveStream(pc_->local_streams()->at(0));
1544 EXPECT_EQ(0u, pc_->local_streams()->count());
1545}
1546
deadbeefe1f9d832016-01-14 15:35:42 -08001547// Test for AddTrack and RemoveTrack methods.
1548// Tests that the created offer includes tracks we added,
1549// and that the RtpSenders are created correctly.
1550// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001551// Only tested with Plan B since Unified Plan is covered in more detail by tests
1552// in peerconnection_jsep_unittests.cc
1553TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001554 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001555 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001556 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001557 rtc::scoped_refptr<VideoTrackInterface> video_track(
1558 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001559 "video_track", pc_factory_->CreateVideoSource(
1560 std::unique_ptr<cricket::VideoCapturer>(
1561 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001562 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1563 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001564 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001565 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001566 EXPECT_EQ("audio_track", audio_sender->id());
1567 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001568 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001569 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001570 EXPECT_EQ("video_track", video_sender->id());
1571 EXPECT_EQ(video_track, video_sender->track());
1572
1573 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001574 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001575 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001576
1577 const cricket::ContentInfo* audio_content =
1578 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001579 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001580 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001581
1582 const cricket::ContentInfo* video_content =
1583 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001584 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001585 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001586
Steve Antondb45ca82017-09-11 18:27:34 -07001587 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001588
1589 // Now try removing the tracks.
1590 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1591 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1592
1593 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001594 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001595
1596 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001597 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001598 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001599
1600 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001601 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001602 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001603
Steve Antondb45ca82017-09-11 18:27:34 -07001604 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001605
1606 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1607 // should return false.
1608 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1609 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1610}
1611
1612// Test creating senders without a stream specified,
1613// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001614TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001615 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001616 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001617 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001618 rtc::scoped_refptr<VideoTrackInterface> video_track(
1619 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001620 "video_track", pc_factory_->CreateVideoSource(
1621 std::unique_ptr<cricket::VideoCapturer>(
1622 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001623 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001624 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001625 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001626 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001627 EXPECT_EQ("audio_track", audio_sender->id());
1628 EXPECT_EQ(audio_track, audio_sender->track());
1629 EXPECT_EQ("video_track", video_sender->id());
1630 EXPECT_EQ(video_track, video_sender->track());
1631 // If the ID is truly a random GUID, it should be infinitely unlikely they
1632 // will be the same.
deadbeefa601f5c2016-06-06 14:27:39 -07001633 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
deadbeefe1f9d832016-01-14 15:35:42 -08001634}
1635
Harald Alvestrand89061872018-01-02 14:08:34 +01001636// Test that we can call GetStats() after AddTrack but before connecting
1637// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001638TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001639 CreatePeerConnectionWithoutDtls();
1640 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1641 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1642 rtc::scoped_refptr<VideoTrackInterface> video_track(
1643 pc_factory_->CreateVideoTrack(
1644 "video_track", pc_factory_->CreateVideoSource(
1645 std::unique_ptr<cricket::VideoCapturer>(
1646 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001647 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1648 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001649 EXPECT_TRUE(DoGetStats(nullptr));
1650}
1651
Steve Anton36da6ff2018-02-16 16:04:20 -08001652TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001653 CreatePeerConnectionWithoutDtls();
1654 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1655 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1656 rtc::scoped_refptr<VideoTrackInterface> video_track(
1657 pc_factory_->CreateVideoTrack(
1658 "video_track", pc_factory_->CreateVideoSource(
1659 std::unique_ptr<cricket::VideoCapturer>(
1660 new cricket::FakeVideoCapturer()))));
1661 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001662 ASSERT_TRUE(audio_sender.ok());
1663 auto* audio_sender_proxy =
1664 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1665 audio_sender.value().get());
1666 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1667
Harald Alvestrandc72af932018-01-11 17:18:19 +01001668 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001669 ASSERT_TRUE(video_sender.ok());
1670 auto* video_sender_proxy =
1671 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1672 video_sender.value().get());
1673 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001674}
1675
Steve Anton36da6ff2018-02-16 16:04:20 -08001676// Don't run under Unified Plan since the stream API is not available.
1677TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001678 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001679 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001680 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001681 ASSERT_EQ(1u, senders.size());
1682 auto* sender_proxy =
1683 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1684 senders[0].get());
1685 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001686}
1687
Steve Anton36da6ff2018-02-16 16:04:20 -08001688TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001690 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 VerifyRemoteRtpHeaderExtensions();
1692}
1693
Steve Anton36da6ff2018-02-16 16:04:20 -08001694TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001695 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001696 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 CreateOfferAsLocalDescription();
1698 std::string offer;
1699 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1700 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001701 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702}
1703
Steve Anton36da6ff2018-02-16 16:04:20 -08001704TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001705 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001706 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707
1708 CreateOfferAsRemoteDescription();
1709 CreateAnswerAsLocalDescription();
1710
Seth Hampson845e8782018-03-02 11:34:10 -08001711 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712}
1713
Steve Anton36da6ff2018-02-16 16:04:20 -08001714TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001715 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001716 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717
1718 CreateOfferAsRemoteDescription();
1719 CreatePrAnswerAsLocalDescription();
1720 CreateAnswerAsLocalDescription();
1721
Seth Hampson845e8782018-03-02 11:34:10 -08001722 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723}
1724
Steve Anton36da6ff2018-02-16 16:04:20 -08001725// Don't run under Unified Plan since the stream API is not available.
1726TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 InitiateCall();
1728 ASSERT_EQ(1u, pc_->remote_streams()->count());
1729 pc_->RemoveStream(pc_->local_streams()->at(0));
1730 CreateOfferReceiveAnswer();
1731 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001732 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 CreateOfferReceiveAnswer();
1734}
1735
1736// Tests that after negotiating an audio only call, the respondent can perform a
1737// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001738TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001739 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001740 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 CreateOfferAsRemoteDescription();
1742 CreateAnswerAsLocalDescription();
1743
1744 ASSERT_EQ(1u, pc_->remote_streams()->count());
1745 pc_->RemoveStream(pc_->local_streams()->at(0));
1746 CreateOfferReceiveAnswer();
1747 EXPECT_EQ(0u, pc_->remote_streams()->count());
1748}
1749
1750// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001751TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001752 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753
Steve Antonf1c6db12017-10-13 11:13:35 -07001754 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001756 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001757 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001758 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001759 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760
1761 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001762 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001763 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001764 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765
Steve Antonf1c6db12017-10-13 11:13:35 -07001766 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001767 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768
Steve Antonf1c6db12017-10-13 11:13:35 -07001769 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770}
1771
deadbeefab9b2d12015-10-14 11:33:11 -07001772// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773// not unique.
Steve Anton36da6ff2018-02-16 16:04:20 -08001774TEST_P(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001775 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001777 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001778 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001779 EXPECT_TRUE(offer);
1780 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781
1782 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001783 AddAudioTrack("track_label", {kStreamId1});
1784 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785
1786 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001787 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788
1789 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001790 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001791 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792}
1793
1794// Test that we will get different SSRCs for each tracks in the offer and answer
1795// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001796TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001797 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001799 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1800 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801
1802 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001803 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001804 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 int audio_ssrc = 0;
1806 int video_ssrc = 0;
1807 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1808 &audio_ssrc));
1809 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1810 &video_ssrc));
1811 EXPECT_NE(audio_ssrc, video_ssrc);
1812
1813 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001814 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001815 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001816 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 audio_ssrc = 0;
1818 video_ssrc = 0;
1819 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1820 &audio_ssrc));
1821 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1822 &video_ssrc));
1823 EXPECT_NE(audio_ssrc, video_ssrc);
1824}
1825
deadbeefeb459812015-12-15 19:24:43 -08001826// Test that it's possible to call AddTrack on a MediaStream after adding
1827// the stream to a PeerConnection.
1828// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001829// Don't run under Unified Plan since the stream API is not available.
1830TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001831 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001832 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001833 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001834 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1835
1836 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001837 rtc::scoped_refptr<VideoTrackInterface> video_track(
1838 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001839 "video_label", pc_factory_->CreateVideoSource(
1840 std::unique_ptr<cricket::VideoCapturer>(
1841 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001842 stream->AddTrack(video_track.get());
1843
kwibergd1fe2812016-04-27 06:47:29 -07001844 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001845 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001846
1847 const cricket::MediaContentDescription* video_desc =
1848 cricket::GetFirstVideoContentDescription(offer->description());
1849 EXPECT_TRUE(video_desc != nullptr);
1850}
1851
1852// Test that it's possible to call RemoveTrack on a MediaStream after adding
1853// the stream to a PeerConnection.
1854// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001855// Don't run under Unified Plan since the stream API is not available.
1856TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001857 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001858 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001859 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001860 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1861
1862 // Remove the video track.
1863 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1864
kwibergd1fe2812016-04-27 06:47:29 -07001865 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001866 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001867
1868 const cricket::MediaContentDescription* video_desc =
1869 cricket::GetFirstVideoContentDescription(offer->description());
1870 EXPECT_TRUE(video_desc == nullptr);
1871}
1872
deadbeef1dcb1642017-03-29 21:08:16 -07001873// Verify that CreateDtmfSender only succeeds if called with a valid local
1874// track. Other aspects of DtmfSenders are tested in
1875// peerconnection_integrationtest.cc.
Steve Anton36da6ff2018-02-16 16:04:20 -08001876TEST_P(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
deadbeef1dcb1642017-03-29 21:08:16 -07001877 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08001878 AddAudioTrack(kAudioTracks[0]);
deadbeef1dcb1642017-03-29 21:08:16 -07001879 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1880 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1881 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1882 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1883}
1884
deadbeefbd7d8f72015-12-18 16:58:44 -08001885// Test creating a sender with a stream ID, and ensure the ID is populated
1886// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001887// Don't run under Unified Plan since the stream API is not available.
1888TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001889 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001890 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001891
kwibergd1fe2812016-04-27 06:47:29 -07001892 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001893 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001894
1895 const cricket::MediaContentDescription* video_desc =
1896 cricket::GetFirstVideoContentDescription(offer->description());
1897 ASSERT_TRUE(video_desc != nullptr);
1898 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001899 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001900}
1901
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001903TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001905 ASSERT_LT(0u, pc_->GetSenders().size());
1906 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001907 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001908 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 EXPECT_TRUE(DoGetStats(remote_audio));
1910
1911 // Remove the stream. Since we are sending to our selves the local
1912 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001913 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 // Do a re-negotiation.
1915 CreateOfferReceiveAnswer();
1916
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 // Test that we still can get statistics for the old track. Even if it is not
1918 // sent any longer.
1919 EXPECT_TRUE(DoGetStats(remote_audio));
1920}
1921
1922// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001923TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001925 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1926 ASSERT_TRUE(video_receiver);
1927 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928}
1929
1930// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001931TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001933 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 pc_factory_->CreateAudioTrack("unknown track", NULL));
1935 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1936}
1937
Steve Anton36da6ff2018-02-16 16:04:20 -08001938TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001939 CreatePeerConnectionWithoutDtls();
1940 EXPECT_TRUE(DoGetRTCStats());
1941 // Clearing stats cache is needed now, but should be temporary.
1942 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1943 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001944 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1945 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001946 EXPECT_TRUE(DoGetRTCStats());
1947 pc_->ClearStatsCache();
1948 CreateOfferReceiveAnswer();
1949 EXPECT_TRUE(DoGetRTCStats());
1950}
1951
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001953TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 FakeConstraints constraints;
1955 constraints.SetAllowRtpDataChannels();
1956 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001957 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001959 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 pc_->CreateDataChannel("test2", NULL);
1961 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001962 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001964 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 new MockDataChannelObserver(data2));
1966
1967 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1968 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1969 std::string data_to_send1 = "testing testing";
1970 std::string data_to_send2 = "testing something else";
1971 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1972
1973 CreateOfferReceiveAnswer();
1974 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1975 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1976
1977 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1978 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1979 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1980 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1981
1982 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1983 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1984
1985 data1->Close();
1986 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1987 CreateOfferReceiveAnswer();
1988 EXPECT_FALSE(observer1->IsOpen());
1989 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1990 EXPECT_TRUE(observer2->IsOpen());
1991
1992 data_to_send2 = "testing something else again";
1993 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1994
1995 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1996}
1997
1998// This test verifies that sendnig binary data over RTP data channels should
1999// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002000TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 FakeConstraints constraints;
2002 constraints.SetAllowRtpDataChannels();
2003 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002004 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002006 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 pc_->CreateDataChannel("test2", NULL);
2008 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002009 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002011 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 new MockDataChannelObserver(data2));
2013
2014 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
2015 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
2016
2017 CreateOfferReceiveAnswer();
2018 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2019 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2020
2021 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2022 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2023
jbaucheec21bd2016-03-20 06:15:43 -07002024 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2026}
2027
2028// This test setup a RTP data channels in loop back and test that a channel is
2029// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002030TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 FakeConstraints constraints;
2032 constraints.SetAllowRtpDataChannels();
2033 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002034 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002036 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 new MockDataChannelObserver(data1));
2038
2039 CreateOfferReceiveAnswerWithoutSsrc();
2040
2041 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2042
2043 data1->Close();
2044 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2045 CreateOfferReceiveAnswerWithoutSsrc();
2046 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2047 EXPECT_FALSE(observer1->IsOpen());
2048}
2049
2050// This test that if a data channel is added in an answer a receive only channel
2051// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002052TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 FakeConstraints constraints;
2054 constraints.SetAllowRtpDataChannels();
2055 CreatePeerConnection(&constraints);
2056
2057 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002058 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 pc_->CreateDataChannel(offer_label, NULL);
2060
2061 CreateOfferAsLocalDescription();
2062
2063 // Replace the data channel label in the offer and apply it as an answer.
2064 std::string receive_label = "answer_channel";
2065 std::string sdp;
2066 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002067 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 receive_label.c_str(), receive_label.length(),
2069 &sdp);
2070 CreateAnswerAsRemoteDescription(sdp);
2071
2072 // Verify that a new incoming data channel has been created and that
2073 // it is open but can't we written to.
2074 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2075 DataChannelInterface* received_channel = observer_.last_datachannel_;
2076 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2077 EXPECT_EQ(receive_label, received_channel->label());
2078 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2079
2080 // Verify that the channel we initially offered has been rejected.
2081 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2082
2083 // Do another offer / answer exchange and verify that the data channel is
2084 // opened.
2085 CreateOfferReceiveAnswer();
2086 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2087 kTimeout);
2088}
2089
2090// This test that no data channel is returned if a reliable channel is
2091// requested.
2092// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002093TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 FakeConstraints constraints;
2095 constraints.SetAllowRtpDataChannels();
2096 CreatePeerConnection(&constraints);
2097
2098 std::string label = "test";
2099 webrtc::DataChannelInit config;
2100 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002101 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 pc_->CreateDataChannel(label, &config);
2103 EXPECT_TRUE(channel == NULL);
2104}
2105
deadbeefab9b2d12015-10-14 11:33:11 -07002106// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002107TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002108 FakeConstraints constraints;
2109 constraints.SetAllowRtpDataChannels();
2110 CreatePeerConnection(&constraints);
2111
2112 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002113 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002114 pc_->CreateDataChannel(label, nullptr);
2115 EXPECT_NE(channel, nullptr);
2116
zhihuang9763d562016-08-05 11:14:50 -07002117 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002118 pc_->CreateDataChannel(label, nullptr);
2119 EXPECT_EQ(dup_channel, nullptr);
2120}
2121
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122// This tests that a SCTP data channel is returned using different
2123// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002124TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 FakeConstraints constraints;
2126 constraints.SetAllowDtlsSctpDataChannels();
2127 CreatePeerConnection(&constraints);
2128
2129 webrtc::DataChannelInit config;
2130
zhihuang9763d562016-08-05 11:14:50 -07002131 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 pc_->CreateDataChannel("1", &config);
2133 EXPECT_TRUE(channel != NULL);
2134 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002135 EXPECT_TRUE(observer_.renegotiation_needed_);
2136 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 config.ordered = false;
2139 channel = pc_->CreateDataChannel("2", &config);
2140 EXPECT_TRUE(channel != NULL);
2141 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002142 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143
2144 config.ordered = true;
2145 config.maxRetransmits = 0;
2146 channel = pc_->CreateDataChannel("3", &config);
2147 EXPECT_TRUE(channel != NULL);
2148 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002149 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150
2151 config.maxRetransmits = -1;
2152 config.maxRetransmitTime = 0;
2153 channel = pc_->CreateDataChannel("4", &config);
2154 EXPECT_TRUE(channel != NULL);
2155 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002156 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157}
2158
2159// This tests that no data channel is returned if both maxRetransmits and
2160// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002161TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 CreateSctpDataChannelShouldFailForInvalidConfig) {
2163 FakeConstraints constraints;
2164 constraints.SetAllowDtlsSctpDataChannels();
2165 CreatePeerConnection(&constraints);
2166
2167 std::string label = "test";
2168 webrtc::DataChannelInit config;
2169 config.maxRetransmits = 0;
2170 config.maxRetransmitTime = 0;
2171
zhihuang9763d562016-08-05 11:14:50 -07002172 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 pc_->CreateDataChannel(label, &config);
2174 EXPECT_TRUE(channel == NULL);
2175}
2176
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177// The test verifies that creating a SCTP data channel with an id already in use
2178// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002179TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 CreateSctpDataChannelWithInvalidIdShouldFail) {
2181 FakeConstraints constraints;
2182 constraints.SetAllowDtlsSctpDataChannels();
2183 CreatePeerConnection(&constraints);
2184
2185 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002186 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002188 config.id = 1;
2189 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 EXPECT_TRUE(channel != NULL);
2191 EXPECT_EQ(1, channel->id());
2192
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 channel = pc_->CreateDataChannel("x", &config);
2194 EXPECT_TRUE(channel == NULL);
2195
2196 config.id = cricket::kMaxSctpSid;
2197 channel = pc_->CreateDataChannel("max", &config);
2198 EXPECT_TRUE(channel != NULL);
2199 EXPECT_EQ(config.id, channel->id());
2200
2201 config.id = cricket::kMaxSctpSid + 1;
2202 channel = pc_->CreateDataChannel("x", &config);
2203 EXPECT_TRUE(channel == NULL);
2204}
2205
deadbeefab9b2d12015-10-14 11:33:11 -07002206// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002207TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002208 FakeConstraints constraints;
2209 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2210 true);
2211 CreatePeerConnection(&constraints);
2212
2213 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002214 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002215 pc_->CreateDataChannel(label, nullptr);
2216 EXPECT_NE(channel, nullptr);
2217
zhihuang9763d562016-08-05 11:14:50 -07002218 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002219 pc_->CreateDataChannel(label, nullptr);
2220 EXPECT_NE(dup_channel, nullptr);
2221}
2222
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002223// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2224// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002225TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002226 FakeConstraints constraints;
2227 constraints.SetAllowRtpDataChannels();
2228 CreatePeerConnection(&constraints);
2229
zhihuang9763d562016-08-05 11:14:50 -07002230 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002231 pc_->CreateDataChannel("test1", NULL);
2232 EXPECT_TRUE(observer_.renegotiation_needed_);
2233 observer_.renegotiation_needed_ = false;
2234
zhihuang9763d562016-08-05 11:14:50 -07002235 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002236 pc_->CreateDataChannel("test2", NULL);
2237 EXPECT_TRUE(observer_.renegotiation_needed_);
2238}
2239
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002241TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 FakeConstraints constraints;
2243 constraints.SetAllowRtpDataChannels();
2244 CreatePeerConnection(&constraints);
2245
zhihuang9763d562016-08-05 11:14:50 -07002246 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002248 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 pc_->CreateDataChannel("test2", NULL);
2250 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002251 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002253 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 new MockDataChannelObserver(data2));
2255
2256 CreateOfferReceiveAnswer();
2257 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2258 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2259
2260 ReleasePeerConnection();
2261 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2262 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2263}
2264
2265// This test that data channels can be rejected in an answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002266TEST_P(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 FakeConstraints constraints;
2268 constraints.SetAllowRtpDataChannels();
2269 CreatePeerConnection(&constraints);
2270
zhihuang9763d562016-08-05 11:14:50 -07002271 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 pc_->CreateDataChannel("offer_channel", NULL));
2273
2274 CreateOfferAsLocalDescription();
2275
2276 // Create an answer where the m-line for data channels are rejected.
2277 std::string sdp;
2278 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002279 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002280 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002281 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002283 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 data_info->rejected = true;
2285
Steve Antondb45ca82017-09-11 18:27:34 -07002286 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2288}
2289
2290// Test that we can create a session description from an SDP string from
2291// FireFox, use it as a remote session description, generate an answer and use
2292// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002293TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 FakeConstraints constraints;
2295 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2296 true);
2297 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002298 AddAudioTrack("audio_label");
2299 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002300 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002301 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002302 webrtc::kFireFoxSdpOffer, nullptr));
2303 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 CreateAnswerAsLocalDescription();
2305 ASSERT_TRUE(pc_->local_description() != NULL);
2306 ASSERT_TRUE(pc_->remote_description() != NULL);
2307
2308 const cricket::ContentInfo* content =
2309 cricket::GetFirstAudioContent(pc_->local_description()->description());
2310 ASSERT_TRUE(content != NULL);
2311 EXPECT_FALSE(content->rejected);
2312
2313 content =
2314 cricket::GetFirstVideoContent(pc_->local_description()->description());
2315 ASSERT_TRUE(content != NULL);
2316 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002317#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 content =
2319 cricket::GetFirstDataContent(pc_->local_description()->description());
2320 ASSERT_TRUE(content != NULL);
Taylor Brandstetter74cefe12017-12-14 15:38:57 -08002321 // Expected to fail since it's using an incompatible format.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002323#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324}
2325
zhihuangb19012e2017-09-19 13:47:59 -07002326// Test that fallback from DTLS to SDES is not supported.
2327// The fallback was previously supported but was removed to simplify the code
2328// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002329TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
deadbeef8662f942017-01-20 21:20:51 -08002330 FakeConstraints constraints;
2331 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2332 true);
2333 CreatePeerConnection(&constraints);
2334 // Wait for fake certificate to be generated. Previously, this is what caused
2335 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002336 AddAudioTrack("audio_label");
2337 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002338 ASSERT_NE(nullptr, fake_certificate_generator_);
2339 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2340 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002341 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002342 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2343 nullptr));
zhihuangb19012e2017-09-19 13:47:59 -07002344 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), false));
deadbeef8662f942017-01-20 21:20:51 -08002345}
2346
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347// Test that we can create an audio only offer and receive an answer with a
2348// limited set of audio codecs and receive an updated offer with more audio
2349// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002350TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002351 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002352 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 CreateOfferAsLocalDescription();
2354
Steve Anton36da6ff2018-02-16 16:04:20 -08002355 const char* answer_sdp =
2356 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2357 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002358 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002359 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002360 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361
Steve Anton36da6ff2018-02-16 16:04:20 -08002362 const char* reoffer_sdp =
2363 (sdp_semantics_ == SdpSemantics::kPlanB
2364 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2365 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002366 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002367 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002368 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 CreateAnswerAsLocalDescription();
2370}
2371
deadbeefc80741f2015-10-22 13:14:45 -07002372// Test that if we're receiving (but not sending) a track, subsequent offers
2373// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002374TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002375 FakeConstraints constraints;
2376 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2377 true);
2378 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002379 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002380 CreateAnswerAsLocalDescription();
2381
2382 // At this point we should be receiving stream 1, but not sending anything.
2383 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002384 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002385 DoCreateOffer(&offer, nullptr);
2386
2387 const cricket::ContentInfo* video_content =
2388 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002389 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2390 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002391
2392 const cricket::ContentInfo* audio_content =
2393 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002394 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2395 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002396}
2397
2398// Test that if we're receiving (but not sending) a track, and the
2399// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2400// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002401TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002402 FakeConstraints constraints;
2403 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2404 true);
2405 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002406 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002407 CreateAnswerAsLocalDescription();
2408
2409 // At this point we should be receiving stream 1, but not sending anything.
2410 // A new offer would be recvonly, but we'll set the "no receive" constraints
2411 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002412 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002413 FakeConstraints offer_constraints;
2414 offer_constraints.AddMandatory(
2415 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2416 offer_constraints.AddMandatory(
2417 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2418 DoCreateOffer(&offer, &offer_constraints);
2419
2420 const cricket::ContentInfo* video_content =
2421 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002422 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2423 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002424
2425 const cricket::ContentInfo* audio_content =
2426 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002427 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2428 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002429}
2430
deadbeef653b8e02015-11-11 12:55:10 -08002431// Test that we can use SetConfiguration to change the ICE servers of the
2432// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002433TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002434 CreatePeerConnection();
2435
Steve Anton36da6ff2018-02-16 16:04:20 -08002436 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002437 PeerConnectionInterface::IceServer server;
2438 server.uri = "stun:test_hostname";
2439 config.servers.push_back(server);
2440 EXPECT_TRUE(pc_->SetConfiguration(config));
2441
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002442 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2443 EXPECT_EQ("test_hostname",
2444 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002445}
2446
Steve Anton36da6ff2018-02-16 16:04:20 -08002447TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002448 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002449 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002450 config.type = PeerConnectionInterface::kRelay;
2451 EXPECT_TRUE(pc_->SetConfiguration(config));
2452 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2453}
2454
Steve Anton36da6ff2018-02-16 16:04:20 -08002455TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002456 PeerConnectionInterface::RTCConfiguration config;
2457 config.prune_turn_ports = false;
2458 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002459 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002460 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2461
2462 config.prune_turn_ports = true;
2463 EXPECT_TRUE(pc_->SetConfiguration(config));
2464 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2465}
2466
skvladd1f5fda2017-02-03 16:54:05 -08002467// Test that the ice check interval can be changed. This does not verify that
2468// the setting makes it all the way to P2PTransportChannel, as that would
2469// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002470TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002471 PeerConnectionInterface::RTCConfiguration config;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002472 config.ice_check_min_interval = rtc::nullopt;
skvladd1f5fda2017-02-03 16:54:05 -08002473 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002474 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002475 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002476 EXPECT_TRUE(pc_->SetConfiguration(config));
2477 PeerConnectionInterface::RTCConfiguration new_config =
2478 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002479 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002480}
2481
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002482// Test that when SetConfiguration changes both the pool size and other
2483// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002484TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002485 SetConfigurationCreatesPooledSessionCorrectly) {
2486 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002487 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002488 config.ice_candidate_pool_size = 1;
2489 PeerConnectionInterface::IceServer server;
2490 server.uri = kStunAddressOnly;
2491 config.servers.push_back(server);
2492 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002493 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002494
2495 const cricket::FakePortAllocatorSession* session =
2496 static_cast<const cricket::FakePortAllocatorSession*>(
2497 port_allocator_->GetPooledSession());
2498 ASSERT_NE(nullptr, session);
2499 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002500}
2501
deadbeef293e9262017-01-11 12:28:30 -08002502// Test that after SetLocalDescription, changing the pool size is not allowed,
2503// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002504TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002505 CantChangePoolSizeAfterSetLocalDescription) {
2506 CreatePeerConnection();
2507 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002508 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002509 config.ice_candidate_pool_size = 1;
2510 EXPECT_TRUE(pc_->SetConfiguration(config));
2511
2512 // Set remote offer; can still change pool size at this point.
2513 CreateOfferAsRemoteDescription();
2514 config.ice_candidate_pool_size = 2;
2515 EXPECT_TRUE(pc_->SetConfiguration(config));
2516
2517 // Set local answer; now it's too late.
2518 CreateAnswerAsLocalDescription();
2519 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002520 RTCError error;
2521 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2522 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2523}
2524
deadbeef42a42632017-03-10 15:18:00 -08002525// Test that after setting an answer, extra pooled sessions are discarded. The
2526// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002527TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002528 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2529 CreatePeerConnection();
2530
2531 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002532 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002533 config.ice_candidate_pool_size = 4;
2534 EXPECT_TRUE(pc_->SetConfiguration(config));
2535
2536 // Do offer/answer.
2537 CreateOfferAsRemoteDescription();
2538 CreateAnswerAsLocalDescription();
2539
2540 // Expect no pooled sessions to be left.
2541 const cricket::PortAllocatorSession* session =
2542 port_allocator_->GetPooledSession();
2543 EXPECT_EQ(nullptr, session);
2544}
2545
2546// After Close is called, pooled candidates should be discarded so as to not
2547// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002548TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002549 CreatePeerConnection();
2550
Steve Anton36da6ff2018-02-16 16:04:20 -08002551 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002552 config.ice_candidate_pool_size = 3;
2553 EXPECT_TRUE(pc_->SetConfiguration(config));
2554 pc_->Close();
2555
2556 // Expect no pooled sessions to be left.
2557 const cricket::PortAllocatorSession* session =
2558 port_allocator_->GetPooledSession();
2559 EXPECT_EQ(nullptr, session);
2560}
2561
deadbeef293e9262017-01-11 12:28:30 -08002562// Test that SetConfiguration returns an invalid modification error if
2563// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002564TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002565 SetConfigurationReturnsInvalidModificationError) {
2566 PeerConnectionInterface::RTCConfiguration config;
2567 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2568 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2569 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2570 CreatePeerConnection(config, nullptr);
2571
Steve Anton36da6ff2018-02-16 16:04:20 -08002572 PeerConnectionInterface::RTCConfiguration modified_config =
2573 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002574 modified_config.bundle_policy =
2575 PeerConnectionInterface::kBundlePolicyMaxBundle;
2576 RTCError error;
2577 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2578 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2579
Steve Anton36da6ff2018-02-16 16:04:20 -08002580 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002581 modified_config.rtcp_mux_policy =
2582 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2583 error.set_type(RTCErrorType::NONE);
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.continual_gathering_policy =
2589 PeerConnectionInterface::GATHER_CONTINUALLY;
2590 error.set_type(RTCErrorType::NONE);
2591 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2592 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2593}
2594
2595// Test that SetConfiguration returns a range error if the candidate pool size
2596// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002597TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002598 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2599 PeerConnectionInterface::RTCConfiguration config;
2600 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002601 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002602
2603 config.ice_candidate_pool_size = -1;
2604 RTCError error;
2605 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2606 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2607
2608 config.ice_candidate_pool_size = INT_MAX;
2609 error.set_type(RTCErrorType::NONE);
2610 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2611 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2612}
2613
2614// Test that SetConfiguration returns a syntax error if parsing an ICE server
2615// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002616TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002617 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2618 PeerConnectionInterface::RTCConfiguration config;
2619 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002620 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002621
2622 PeerConnectionInterface::IceServer bad_server;
2623 bad_server.uri = "stunn:www.example.com";
2624 config.servers.push_back(bad_server);
2625 RTCError error;
2626 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2627 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2628}
2629
2630// Test that SetConfiguration returns an invalid parameter error if a TURN
2631// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002632TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002633 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2634 PeerConnectionInterface::RTCConfiguration config;
2635 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002636 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002637
2638 PeerConnectionInterface::IceServer bad_server;
2639 bad_server.uri = "turn:www.example.com";
2640 // Missing password.
2641 bad_server.username = "foo";
2642 config.servers.push_back(bad_server);
2643 RTCError error;
2644 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2645 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002646}
2647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648// Test that PeerConnection::Close changes the states to closed and all remote
2649// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002650TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 // Initialize a PeerConnection and negotiate local and remote session
2652 // description.
2653 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002654
2655 // With Plan B, verify the stream count. The analog with Unified Plan is the
2656 // RtpTransceiver count.
2657 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2658 ASSERT_EQ(1u, pc_->local_streams()->count());
2659 ASSERT_EQ(1u, pc_->remote_streams()->count());
2660 } else {
2661 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2662 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663
2664 pc_->Close();
2665
2666 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2667 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2668 pc_->ice_connection_state());
2669 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2670 pc_->ice_gathering_state());
2671
Steve Anton36da6ff2018-02-16 16:04:20 -08002672 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2673 EXPECT_EQ(1u, pc_->local_streams()->count());
2674 EXPECT_EQ(1u, pc_->remote_streams()->count());
2675 } else {
2676 // Verify that the RtpTransceivers are still present but all stopped.
2677 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2678 for (auto transceiver : pc_->GetTransceivers()) {
2679 EXPECT_TRUE(transceiver->stopped());
2680 }
2681 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682
Steve Anton36da6ff2018-02-16 16:04:20 -08002683 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2684 ASSERT_TRUE(audio_receiver);
2685 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2686 ASSERT_TRUE(video_receiver);
2687
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002688 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002689 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002690 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002691 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002692 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693}
2694
2695// Test that PeerConnection methods fails gracefully after
2696// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002697// Don't run under Unified Plan since the stream API is not available.
2698TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002699 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002700 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701 CreateOfferAsRemoteDescription();
2702 CreateAnswerAsLocalDescription();
2703
2704 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002705 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 pc_->local_streams()->at(0);
2707
2708 pc_->Close();
2709
2710 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002711 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712
2713 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002714 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002716 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717
2718 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2719
2720 EXPECT_TRUE(pc_->local_description() != NULL);
2721 EXPECT_TRUE(pc_->remote_description() != NULL);
2722
kwibergd1fe2812016-04-27 06:47:29 -07002723 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002724 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002725 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002726 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727
2728 std::string sdp;
2729 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002730 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002731 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002732 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733
2734 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002735 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002736 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002737 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738}
2739
2740// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002741TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 InitiateCall();
2743 pc_->Close();
2744 DoGetStats(NULL);
2745}
deadbeefab9b2d12015-10-14 11:33:11 -07002746
2747// NOTE: The series of tests below come from what used to be
2748// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2749// setting a remote or local description has the expected effects.
2750
2751// This test verifies that the remote MediaStreams corresponding to a received
2752// SDP string is created. In this test the two separate MediaStreams are
2753// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002754TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
deadbeefab9b2d12015-10-14 11:33:11 -07002755 FakeConstraints constraints;
2756 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2757 true);
2758 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002759 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002760
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002761 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002762 EXPECT_TRUE(
2763 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2764 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2765 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2766
2767 // Create a session description based on another SDP with another
2768 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002769 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002770
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002771 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002772 EXPECT_TRUE(
2773 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2774}
2775
2776// This test verifies that when remote tracks are added/removed from SDP, the
2777// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002778// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2779// specific behavior.
2780TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002781 AddRemoveTrackFromExistingRemoteMediaStream) {
2782 FakeConstraints constraints;
2783 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2784 true);
2785 CreatePeerConnection(&constraints);
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) {
deadbeefab9b2d12015-10-14 11:33:11 -07002826 FakeConstraints constraints;
2827 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2828 true);
2829 CreatePeerConnection(&constraints);
2830 // First create and set a remote offer, then reject its video content in our
2831 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002832 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2833 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2834 ASSERT_TRUE(audio_receiver);
2835 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2836 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002837
Steve Anton36da6ff2018-02-16 16:04:20 -08002838 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2839 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002840 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002841 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2842 video_receiver->track();
2843 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002844
kwibergd1fe2812016-04-27 06:47:29 -07002845 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002846 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002847 cricket::ContentInfo* video_info =
2848 local_answer->description()->GetContentByName("video");
2849 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002850 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002851 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2852 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002853
2854 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002855 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002856 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002857 video_info = local_offer->description()->GetContentByName("video");
2858 ASSERT_TRUE(video_info != nullptr);
2859 video_info->rejected = true;
2860 cricket::ContentInfo* audio_info =
2861 local_offer->description()->GetContentByName("audio");
2862 ASSERT_TRUE(audio_info != nullptr);
2863 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002864 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002865 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002866 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2867 kTimeout);
2868 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2869 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002870}
2871
2872// This tests that we won't crash if the remote track has been removed outside
2873// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002874// Don't run under Unified Plan since the stream API is not available.
2875TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002876 FakeConstraints constraints;
2877 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2878 true);
2879 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002880 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002881 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2882 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2883 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2884
kwibergd1fe2812016-04-27 06:47:29 -07002885 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002886 webrtc::CreateSessionDescription(SdpType::kAnswer,
2887 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002888 cricket::ContentInfo* video_info =
2889 local_answer->description()->GetContentByName("video");
2890 video_info->rejected = true;
2891 cricket::ContentInfo* audio_info =
2892 local_answer->description()->GetContentByName("audio");
2893 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002894 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002895
2896 // No crash is a pass.
2897}
2898
deadbeef5e97fb52015-10-15 12:49:08 -07002899// This tests that if a recvonly remote description is set, no remote streams
2900// will be created, even if the description contains SSRCs/MSIDs.
2901// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002902TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
deadbeef5e97fb52015-10-15 12:49:08 -07002903 FakeConstraints constraints;
2904 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2905 true);
2906 CreatePeerConnection(&constraints);
2907
Steve Anton36da6ff2018-02-16 16:04:20 -08002908 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002909 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2910 strlen(kRecvonly), &recvonly_offer);
2911 CreateAndSetRemoteOffer(recvonly_offer);
2912
2913 EXPECT_EQ(0u, observer_.remote_streams()->count());
2914}
2915
deadbeefab9b2d12015-10-14 11:33:11 -07002916// This tests that a default MediaStream is created if a remote session
2917// description doesn't contain any streams and no MSID support.
2918// It also tests that the default stream is updated if a video m-line is added
2919// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002920// Don't run under Unified Plan since this behavior is Plan B specific.
2921TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002922 FakeConstraints constraints;
2923 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2924 true);
2925 CreatePeerConnection(&constraints);
2926 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2927
2928 ASSERT_EQ(1u, observer_.remote_streams()->count());
2929 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2930
2931 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2932 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2933 EXPECT_EQ("default", remote_stream->label());
2934
2935 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2936 ASSERT_EQ(1u, observer_.remote_streams()->count());
2937 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2938 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002939 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2940 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002941 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2942 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002943 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2944 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002945}
2946
2947// This tests that a default MediaStream is created if a remote session
2948// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002949// Don't run under Unified Plan since this behavior is Plan B specific.
2950TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002951 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002952 FakeConstraints constraints;
2953 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2954 true);
2955 CreatePeerConnection(&constraints);
2956 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2957
2958 ASSERT_EQ(1u, observer_.remote_streams()->count());
2959 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2960
2961 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2962 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2963 EXPECT_EQ("default", remote_stream->label());
2964}
2965
2966// This tests that it won't crash when PeerConnection tries to remove
2967// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002968// Don't run under Unified Plan since this behavior is Plan B specific.
2969TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002970 FakeConstraints constraints;
2971 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2972 true);
2973 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002974 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002975 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2976 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2977 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2978
2979 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2980
2981 // No crash is a pass.
2982}
2983
2984// This tests that a default MediaStream is created if the remote session
2985// description doesn't contain any streams and don't contain an indication if
2986// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002987// Don't run under Unified Plan since this behavior is Plan B specific.
2988TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002989 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002990 FakeConstraints constraints;
2991 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2992 true);
2993 CreatePeerConnection(&constraints);
2994 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2995
2996 ASSERT_EQ(1u, observer_.remote_streams()->count());
2997 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2998 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2999 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3000}
3001
3002// This tests that a default MediaStream is not created if the remote session
3003// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003004// Don't run under Unified Plan since this behavior is Plan B specific.
3005TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003006 FakeConstraints constraints;
3007 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3008 true);
3009 CreatePeerConnection(&constraints);
3010 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3011 EXPECT_EQ(0u, observer_.remote_streams()->count());
3012}
3013
deadbeefbda7e0b2015-12-08 17:13:40 -08003014// This tests that when setting a new description, the old default tracks are
3015// not destroyed and recreated.
3016// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003017// Don't run under Unified Plan since this behavior is Plan B specific.
3018TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003019 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08003020 FakeConstraints constraints;
3021 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3022 true);
3023 CreatePeerConnection(&constraints);
3024 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3025
3026 ASSERT_EQ(1u, observer_.remote_streams()->count());
3027 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3028 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3029
3030 // Set the track to "disabled", then set a new description and ensure the
3031 // track is still disabled, which ensures it hasn't been recreated.
3032 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3033 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3034 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3035 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3036}
3037
deadbeefab9b2d12015-10-14 11:33:11 -07003038// This tests that a default MediaStream is not created if a remote session
3039// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003040// Don't run under Unified Plan since this behavior is Plan B specific.
3041TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
deadbeefab9b2d12015-10-14 11:33:11 -07003042 FakeConstraints constraints;
3043 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3044 true);
3045 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003046 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003047 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003048 EXPECT_TRUE(
3049 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3050
3051 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3052 EXPECT_EQ(0u, observer_.remote_streams()->count());
3053}
3054
3055// This tests that an RtpSender is created when the local description is set
3056// after adding a local stream.
3057// TODO(deadbeef): This test and the one below it need to be updated when
3058// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003059// Don't run under Unified Plan since this behavior is Plan B specific.
3060TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003061 FakeConstraints constraints;
3062 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3063 true);
3064 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003065
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003066 // Create an offer with 1 stream with 2 tracks of each type.
3067 rtc::scoped_refptr<StreamCollection> stream_collection =
3068 CreateStreamCollection(1, 2);
3069 pc_->AddStream(stream_collection->at(0));
3070 std::unique_ptr<SessionDescriptionInterface> offer;
3071 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003072 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003073
deadbeefab9b2d12015-10-14 11:33:11 -07003074 auto senders = pc_->GetSenders();
3075 EXPECT_EQ(4u, senders.size());
3076 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3077 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3078 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3079 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3080
3081 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003082 pc_->RemoveStream(stream_collection->at(0));
3083 stream_collection = CreateStreamCollection(1, 1);
3084 pc_->AddStream(stream_collection->at(0));
3085 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003086 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003087
deadbeefab9b2d12015-10-14 11:33:11 -07003088 senders = pc_->GetSenders();
3089 EXPECT_EQ(2u, senders.size());
3090 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3091 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3092 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3093 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3094}
3095
3096// This tests that an RtpSender is created when the local description is set
3097// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003098// Don't run under Unified Plan since this behavior is Plan B specific.
3099TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003100 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003101 FakeConstraints constraints;
3102 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3103 true);
3104 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003105
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003106 rtc::scoped_refptr<StreamCollection> stream_collection =
3107 CreateStreamCollection(1, 2);
3108 // Add a stream to create the offer, but remove it afterwards.
3109 pc_->AddStream(stream_collection->at(0));
3110 std::unique_ptr<SessionDescriptionInterface> offer;
3111 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3112 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003113
Steve Antondb45ca82017-09-11 18:27:34 -07003114 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003115 auto senders = pc_->GetSenders();
3116 EXPECT_EQ(0u, senders.size());
3117
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003118 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003119 senders = pc_->GetSenders();
3120 EXPECT_EQ(4u, senders.size());
3121 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3122 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3123 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3124 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3125}
3126
3127// This tests that the expected behavior occurs if the SSRC on a local track is
3128// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003129TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003130 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07003131 FakeConstraints constraints;
3132 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3133 true);
3134 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003135
Steve Anton36da6ff2018-02-16 16:04:20 -08003136 AddAudioTrack(kAudioTracks[0]);
3137 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003138 std::unique_ptr<SessionDescriptionInterface> offer;
3139 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3140 // Grab a copy of the offer before it gets passed into the PC.
Steve Antona3a92c22017-12-07 10:27:41 -08003141 auto modified_offer =
3142 rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003143 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
3144 offer->session_version());
Steve Antondb45ca82017-09-11 18:27:34 -07003145 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003146
deadbeefab9b2d12015-10-14 11:33:11 -07003147 auto senders = pc_->GetSenders();
3148 EXPECT_EQ(2u, senders.size());
3149 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3150 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3151
3152 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003153 cricket::MediaContentDescription* desc =
3154 cricket::GetFirstAudioContentDescription(modified_offer->description());
3155 ASSERT_TRUE(desc != NULL);
3156 for (StreamParams& stream : desc->mutable_streams()) {
3157 for (unsigned int& ssrc : stream.ssrcs) {
3158 ++ssrc;
3159 }
3160 }
deadbeefab9b2d12015-10-14 11:33:11 -07003161
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003162 desc =
3163 cricket::GetFirstVideoContentDescription(modified_offer->description());
3164 ASSERT_TRUE(desc != NULL);
3165 for (StreamParams& stream : desc->mutable_streams()) {
3166 for (unsigned int& ssrc : stream.ssrcs) {
3167 ++ssrc;
3168 }
3169 }
3170
Steve Antondb45ca82017-09-11 18:27:34 -07003171 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003172 senders = pc_->GetSenders();
3173 EXPECT_EQ(2u, senders.size());
3174 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3175 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3176 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3177 // changed.
3178}
3179
3180// This tests that the expected behavior occurs if a new session description is
3181// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003182// Don't run under Unified Plan since the stream API is not available.
3183TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003184 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003185 FakeConstraints constraints;
3186 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3187 true);
3188 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003189
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003190 rtc::scoped_refptr<StreamCollection> stream_collection =
3191 CreateStreamCollection(2, 1);
3192 pc_->AddStream(stream_collection->at(0));
3193 std::unique_ptr<SessionDescriptionInterface> offer;
3194 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003195 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003196
deadbeefab9b2d12015-10-14 11:33:11 -07003197 auto senders = pc_->GetSenders();
3198 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003199 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3200 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003201
3202 // Add a new MediaStream but with the same tracks as in the first stream.
3203 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3204 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003205 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3206 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003207 pc_->AddStream(stream_1);
3208
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003209 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003210 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003211
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003212 auto new_senders = pc_->GetSenders();
3213 // Should be the same senders as before, but with updated stream id.
3214 // Note that this behavior is subject to change in the future.
3215 // We may decide the PC should ignore existing tracks in AddStream.
3216 EXPECT_EQ(senders, new_senders);
3217 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3218 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003219}
3220
zhihuang81c3a032016-11-17 12:06:24 -08003221// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003222TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
zhihuang81c3a032016-11-17 12:06:24 -08003223 FakeConstraints constraints;
3224 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3225 true);
3226 CreatePeerConnection(&constraints);
3227 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3228 EXPECT_EQ(observer_.num_added_tracks_, 1);
3229 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3230
3231 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003232 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3233 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3234 EXPECT_EQ(observer_.num_added_tracks_, 2);
3235 } else {
3236 // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription
3237 // is called until the offer/answer exchange is complete. So in this case
3238 // OnAddTrack is fired twice for the first audio track plus the one time
3239 // for the video track.
3240 EXPECT_EQ(observer_.num_added_tracks_, 3);
3241 }
zhihuang81c3a032016-11-17 12:06:24 -08003242 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3243}
3244
deadbeefd1a38b52016-12-10 13:15:33 -08003245// Test that when SetConfiguration is called and the configuration is
3246// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003247TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003248 PeerConnectionInterface::RTCConfiguration config;
3249 config.type = PeerConnectionInterface::kRelay;
3250 // Need to pass default constraints to prevent disabling of DTLS...
3251 FakeConstraints default_constraints;
3252 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003253 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003254 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3255 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003256
3257 // Do initial offer/answer so there's something to restart.
3258 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003259 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003260
3261 // Grab the ufrags.
3262 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3263
3264 // Change ICE policy, which should trigger an ICE restart on the next offer.
3265 config.type = PeerConnectionInterface::kAll;
3266 EXPECT_TRUE(pc_->SetConfiguration(config));
3267 CreateOfferAsLocalDescription();
3268
3269 // Grab the new ufrags.
3270 std::vector<std::string> subsequent_ufrags =
3271 GetUfrags(pc_->local_description());
3272
3273 // Sanity check.
3274 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3275 // Check that each ufrag is different.
3276 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3277 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3278 }
3279}
3280
3281// Test that when SetConfiguration is called and the configuration *isn't*
3282// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003283TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003284 PeerConnectionInterface::RTCConfiguration config;
3285 config.type = PeerConnectionInterface::kRelay;
3286 // Need to pass default constraints to prevent disabling of DTLS...
3287 FakeConstraints default_constraints;
3288 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003289 config = pc_->GetConfiguration();
3290 AddAudioTrack(kAudioTracks[0]);
3291 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003292
3293 // Do initial offer/answer so there's something to restart.
3294 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003295 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003296
3297 // Grab the ufrags.
3298 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3299
3300 // Call SetConfiguration with a config identical to what the PC was
3301 // constructed with.
3302 EXPECT_TRUE(pc_->SetConfiguration(config));
3303 CreateOfferAsLocalDescription();
3304
3305 // Grab the new ufrags.
3306 std::vector<std::string> subsequent_ufrags =
3307 GetUfrags(pc_->local_description());
3308
3309 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3310}
3311
3312// Test for a weird corner case scenario:
3313// 1. Audio/video session established.
3314// 2. SetConfiguration changes ICE config; ICE restart needed.
3315// 3. ICE restart initiated by remote peer, but only for one m= section.
3316// 4. Next createOffer should initiate an ICE restart, but only for the other
3317// m= section; it would be pointless to do an ICE restart for the m= section
3318// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003319TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003320 PeerConnectionInterface::RTCConfiguration config;
3321 config.type = PeerConnectionInterface::kRelay;
3322 // Need to pass default constraints to prevent disabling of DTLS...
3323 FakeConstraints default_constraints;
3324 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003325 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003326 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3327 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003328
3329 // Do initial offer/answer so there's something to restart.
3330 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003331 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003332
3333 // Change ICE policy, which should set the "needs-ice-restart" flag.
3334 config.type = PeerConnectionInterface::kAll;
3335 EXPECT_TRUE(pc_->SetConfiguration(config));
3336
3337 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003338 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003339 webrtc::CreateSessionDescription(SdpType::kOffer,
3340 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003341 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003342 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3343 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003344 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003345 CreateAnswerAsLocalDescription();
3346
3347 // Grab the ufrags.
3348 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3349 ASSERT_EQ(2, initial_ufrags.size());
3350
3351 // Create offer and grab the new ufrags.
3352 CreateOfferAsLocalDescription();
3353 std::vector<std::string> subsequent_ufrags =
3354 GetUfrags(pc_->local_description());
3355 ASSERT_EQ(2, subsequent_ufrags.size());
3356
3357 // Ensure that only the ufrag for the second m= section changed.
3358 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3359 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3360}
3361
deadbeeffe4a8a42016-12-20 17:56:17 -08003362// Tests that the methods to return current/pending descriptions work as
3363// expected at different points in the offer/answer exchange. This test does
3364// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003365TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003366 // This disables DTLS so we can apply an answer to ourselves.
3367 CreatePeerConnection();
3368
3369 // Create initial local offer and get SDP (which will also be used as
3370 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003371 std::unique_ptr<SessionDescriptionInterface> local_offer;
3372 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003373 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003374 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003375
3376 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003377 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3378 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3379 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003380 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3381 EXPECT_EQ(nullptr, pc_->current_local_description());
3382 EXPECT_EQ(nullptr, pc_->current_remote_description());
3383
3384 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003385 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003386 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003387 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3388 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3389 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3390 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003391 EXPECT_EQ(nullptr, pc_->current_local_description());
3392 EXPECT_EQ(nullptr, pc_->current_remote_description());
3393
3394 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003395 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003396 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003397 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3398 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003399 EXPECT_EQ(nullptr, pc_->pending_local_description());
3400 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003401 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3402 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003403
3404 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003405 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003406 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003407 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3408 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3409 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003410 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003411 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3412 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003413
3414 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003415 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003416 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003417 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3418 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3419 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3420 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3421 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3422 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003423
3424 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003425 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003426 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003427 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3428 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003429 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3430 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003431 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3432 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003433}
3434
zhihuang77985012017-02-07 15:45:16 -08003435// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3436// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003437// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003438TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003439 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003440 CreatePeerConnection();
3441 // The RtcEventLog will be reset when the PeerConnection is closed.
3442 pc_->Close();
3443
Elad Alon9e6565b2017-10-11 16:04:13 +02003444 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3445 std::string filename = webrtc::test::OutputPath() +
3446 test_info->test_case_name() + test_info->name();
3447 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3448
3449 constexpr int64_t max_size_bytes = 1024;
3450
zhihuang77985012017-02-07 15:45:16 -08003451 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3452 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003453
3454 // Cleanup.
3455 rtc::ClosePlatformFile(file);
3456 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003457}
3458
Elad Alon99c3fe52017-10-13 16:29:40 +02003459// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3460// after the PeerConnection is closed.
3461// This version tests the StartRtcEventLog version that receives an object
3462// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003463TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003464 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3465 CreatePeerConnection();
3466 // The RtcEventLog will be reset when the PeerConnection is closed.
3467 pc_->Close();
3468
3469 rtc::PlatformFile file = 0;
3470 int64_t max_size_bytes = 1024;
3471 EXPECT_FALSE(pc_->StartRtcEventLog(
Bjorn Tereliusde939432017-11-20 17:38:14 +01003472 rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
3473 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003474 pc_->StopRtcEventLog();
3475}
3476
deadbeef30952b42017-04-21 02:41:29 -07003477// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003478TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003479 CreatePeerConnection();
3480
3481 // First, create an offer with audio/video.
3482 FakeConstraints constraints;
3483 constraints.SetMandatoryReceiveAudio(true);
3484 constraints.SetMandatoryReceiveVideo(true);
3485 std::unique_ptr<SessionDescriptionInterface> offer;
3486 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3487 cricket::SessionDescription* desc = offer->description();
3488 ASSERT_EQ(2u, desc->transport_infos().size());
3489 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3490 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3491
3492 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003493 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003494 std::unique_ptr<SessionDescriptionInterface> answer;
3495 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3496 desc = answer->description();
3497 ASSERT_EQ(2u, desc->transport_infos().size());
3498 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3499 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3500}
3501
deadbeef1dcb1642017-03-29 21:08:16 -07003502// Test that ICE renomination isn't offered if it's not enabled in the PC's
3503// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003504TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003505 PeerConnectionInterface::RTCConfiguration config;
3506 config.enable_ice_renomination = false;
3507 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003508 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003509
3510 std::unique_ptr<SessionDescriptionInterface> offer;
3511 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3512 cricket::SessionDescription* desc = offer->description();
3513 EXPECT_EQ(1u, desc->transport_infos().size());
3514 EXPECT_FALSE(
3515 desc->transport_infos()[0].description.GetIceParameters().renomination);
3516}
3517
3518// Test that the ICE renomination option is present in generated offers/answers
3519// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003520TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003521 PeerConnectionInterface::RTCConfiguration config;
3522 config.enable_ice_renomination = true;
3523 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003524 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003525
3526 std::unique_ptr<SessionDescriptionInterface> offer;
3527 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3528 cricket::SessionDescription* desc = offer->description();
3529 EXPECT_EQ(1u, desc->transport_infos().size());
3530 EXPECT_TRUE(
3531 desc->transport_infos()[0].description.GetIceParameters().renomination);
3532
3533 // Set the offer as a remote description, then create an answer and ensure it
3534 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003535 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003536 std::unique_ptr<SessionDescriptionInterface> answer;
3537 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3538 desc = answer->description();
3539 EXPECT_EQ(1u, desc->transport_infos().size());
3540 EXPECT_TRUE(
3541 desc->transport_infos()[0].description.GetIceParameters().renomination);
3542}
3543
3544// Test that if CreateOffer is called with the deprecated "offer to receive
3545// audio/video" constraints, they're processed and result in an offer with
3546// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003547TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003548 CreatePeerConnection();
3549
3550 FakeConstraints constraints;
3551 constraints.SetMandatoryReceiveAudio(true);
3552 constraints.SetMandatoryReceiveVideo(true);
3553 std::unique_ptr<SessionDescriptionInterface> offer;
3554 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3555
3556 cricket::SessionDescription* desc = offer->description();
3557 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3558 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3559 ASSERT_NE(nullptr, audio);
3560 ASSERT_NE(nullptr, video);
3561 EXPECT_FALSE(audio->rejected);
3562 EXPECT_FALSE(video->rejected);
3563}
3564
3565// Test that if CreateAnswer is called with the deprecated "offer to receive
3566// audio/video" constraints, they're processed and can be used to reject an
3567// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003568// Don't run under Unified Plan since this behavior is not supported.
3569TEST_F(PeerConnectionInterfaceTestPlanB,
3570 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003571 CreatePeerConnection();
3572
3573 // First, create an offer with audio/video and apply it as a remote
3574 // description.
3575 FakeConstraints constraints;
3576 constraints.SetMandatoryReceiveAudio(true);
3577 constraints.SetMandatoryReceiveVideo(true);
3578 std::unique_ptr<SessionDescriptionInterface> offer;
3579 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
Steve Antondb45ca82017-09-11 18:27:34 -07003580 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003581
3582 // Now create answer that rejects audio/video.
3583 constraints.SetMandatoryReceiveAudio(false);
3584 constraints.SetMandatoryReceiveVideo(false);
3585 std::unique_ptr<SessionDescriptionInterface> answer;
3586 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3587
3588 cricket::SessionDescription* desc = answer->description();
3589 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3590 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3591 ASSERT_NE(nullptr, audio);
3592 ASSERT_NE(nullptr, video);
3593 EXPECT_TRUE(audio->rejected);
3594 EXPECT_TRUE(video->rejected);
3595}
3596
deadbeef1dcb1642017-03-29 21:08:16 -07003597// Test that negotiation can succeed with a data channel only, and with the max
3598// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003599#ifdef HAVE_SCTP
3600TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3601#else
3602TEST_P(PeerConnectionInterfaceTest,
3603 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3604#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003605 PeerConnectionInterface::RTCConfiguration config;
3606 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3607 CreatePeerConnection(config, nullptr);
3608
3609 // First, create an offer with only a data channel and apply it as a remote
3610 // description.
3611 pc_->CreateDataChannel("test", nullptr);
3612 std::unique_ptr<SessionDescriptionInterface> offer;
3613 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003614 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003615
3616 // Create and set answer as well.
3617 std::unique_ptr<SessionDescriptionInterface> answer;
3618 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003619 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003620}
3621
Steve Anton36da6ff2018-02-16 16:04:20 -08003622TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003623 CreatePeerConnection();
3624 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003625 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003626 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3627}
3628
Steve Anton36da6ff2018-02-16 16:04:20 -08003629TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003630 CreatePeerConnection();
3631 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003632 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003633 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3634}
3635
Steve Anton36da6ff2018-02-16 16:04:20 -08003636TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003637 CreatePeerConnection();
3638 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003639 bitrate.min_bitrate_bps = 5;
3640 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003641 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3642}
3643
Steve Anton36da6ff2018-02-16 16:04:20 -08003644TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003645 CreatePeerConnection();
3646 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003647 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003648 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3649}
3650
Steve Anton36da6ff2018-02-16 16:04:20 -08003651TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003652 CreatePeerConnection();
3653 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003654 bitrate.current_bitrate_bps = 10;
3655 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003656 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3657}
3658
Steve Anton36da6ff2018-02-16 16:04:20 -08003659TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003660 CreatePeerConnection();
3661 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003662 bitrate.min_bitrate_bps = 10;
3663 bitrate.max_bitrate_bps = 8;
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, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003668 CreatePeerConnection();
3669 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003670 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003671 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3672}
3673
Steve Anton038834f2017-07-14 15:59:59 -07003674// ice_regather_interval_range requires WebRTC to be configured for continual
3675// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003676TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003677 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3678 PeerConnectionInterface::RTCConfiguration config;
3679 config.ice_regather_interval_range.emplace(1000, 2000);
3680 config.continual_gathering_policy =
3681 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3682 CreatePeerConnectionExpectFail(config);
3683}
3684
3685// Ensures that there is no error when ice_regather_interval_range is set with
3686// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003687TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003688 SetIceRegatherIntervalRangeWithContinualGathering) {
3689 PeerConnectionInterface::RTCConfiguration config;
3690 config.ice_regather_interval_range.emplace(1000, 2000);
3691 config.continual_gathering_policy =
3692 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3693 CreatePeerConnection(config, nullptr);
3694}
3695
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003696// The current bitrate from Call's BitrateConstraintsMask is currently clamped
3697// by Call's BitrateConstraints, which comes from the SDP or a default value.
3698// This test checks that a call to SetBitrate with a current bitrate that will
3699// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003700TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003701 CreatePeerConnection();
3702 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003703 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003704 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3705}
3706
zhihuang1c378ed2017-08-17 14:10:50 -07003707// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003708TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003709 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3710 RTCOfferAnswerOptions rtc_options;
3711
3712 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3713 // than kMaxOfferToReceiveMedia should be treated as invalid.
3714 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3715 CreatePeerConnection();
3716 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3717
3718 rtc_options.offer_to_receive_audio =
3719 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3720 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3721}
3722
Steve Anton36da6ff2018-02-16 16:04:20 -08003723TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003724 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3725 RTCOfferAnswerOptions rtc_options;
3726
3727 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3728 // than kMaxOfferToReceiveMedia should be treated as invalid.
3729 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3730 CreatePeerConnection();
3731 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3732
3733 rtc_options.offer_to_receive_video =
3734 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3735 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3736}
3737
3738// Test that the audio and video content will be added to an offer if both
3739// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003740TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003741 RTCOfferAnswerOptions rtc_options;
3742 rtc_options.offer_to_receive_audio = 1;
3743 rtc_options.offer_to_receive_video = 1;
3744
3745 std::unique_ptr<SessionDescriptionInterface> offer;
3746 CreatePeerConnection();
3747 offer = CreateOfferWithOptions(rtc_options);
3748 ASSERT_TRUE(offer);
3749 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3750 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3751}
3752
3753// Test that only audio content will be added to the offer if only
3754// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003755TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003756 RTCOfferAnswerOptions rtc_options;
3757 rtc_options.offer_to_receive_audio = 1;
3758 rtc_options.offer_to_receive_video = 0;
3759
3760 std::unique_ptr<SessionDescriptionInterface> offer;
3761 CreatePeerConnection();
3762 offer = CreateOfferWithOptions(rtc_options);
3763 ASSERT_TRUE(offer);
3764 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3765 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3766}
3767
3768// Test that only video content will be added if only |offer_to_receive_video|
3769// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003770TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003771 RTCOfferAnswerOptions rtc_options;
3772 rtc_options.offer_to_receive_audio = 0;
3773 rtc_options.offer_to_receive_video = 1;
3774
3775 std::unique_ptr<SessionDescriptionInterface> offer;
3776 CreatePeerConnection();
3777 offer = CreateOfferWithOptions(rtc_options);
3778 ASSERT_TRUE(offer);
3779 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3780 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3781}
3782
zhihuang1c378ed2017-08-17 14:10:50 -07003783// Test that no media content will be added to the offer if using default
3784// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003785TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003786 RTCOfferAnswerOptions rtc_options;
3787
3788 std::unique_ptr<SessionDescriptionInterface> offer;
3789 CreatePeerConnection();
3790 offer = CreateOfferWithOptions(rtc_options);
3791 ASSERT_TRUE(offer);
3792 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3793 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3794}
3795
3796// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3797// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003798TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3799 CreatePeerConnection();
3800
zhihuang1c378ed2017-08-17 14:10:50 -07003801 RTCOfferAnswerOptions rtc_options;
3802 rtc_options.ice_restart = false;
3803 rtc_options.offer_to_receive_audio = 1;
3804
3805 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003806 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003807 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3808 auto ufrag1 =
3809 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3810 auto pwd1 =
3811 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003812
3813 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3814 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003815 auto ufrag2 =
3816 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3817 auto pwd2 =
3818 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003819
3820 // |ice_restart| is true, the ufrag/pwd should change.
3821 rtc_options.ice_restart = true;
3822 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003823 auto ufrag3 =
3824 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3825 auto pwd3 =
3826 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003827
3828 EXPECT_EQ(ufrag1, ufrag2);
3829 EXPECT_EQ(pwd1, pwd2);
3830 EXPECT_NE(ufrag2, ufrag3);
3831 EXPECT_NE(pwd2, pwd3);
3832}
3833
3834// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3835// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003836TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003837 RTCOfferAnswerOptions rtc_options;
3838 rtc_options.offer_to_receive_audio = 1;
3839 rtc_options.offer_to_receive_video = 1;
3840
3841 std::unique_ptr<SessionDescriptionInterface> offer;
3842 CreatePeerConnection();
3843
3844 rtc_options.use_rtp_mux = true;
3845 offer = CreateOfferWithOptions(rtc_options);
3846 ASSERT_TRUE(offer);
3847 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3848 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3849 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3850
3851 rtc_options.use_rtp_mux = false;
3852 offer = CreateOfferWithOptions(rtc_options);
3853 ASSERT_TRUE(offer);
3854 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3855 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3856 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3857}
3858
zhihuang141aacb2017-08-29 13:23:53 -07003859// This test ensures OnRenegotiationNeeded is called when we add track with
3860// MediaStream -> AddTrack in the same way it is called when we add track with
3861// PeerConnection -> AddTrack.
3862// The test can be removed once addStream is rewritten in terms of addTrack
3863// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003864// Don't run under Unified Plan since the stream API is not available.
3865TEST_F(PeerConnectionInterfaceTestPlanB,
3866 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003867 CreatePeerConnectionWithoutDtls();
3868 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003869 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003870 pc_->AddStream(stream);
3871 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3872 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3873 rtc::scoped_refptr<VideoTrackInterface> video_track(
3874 pc_factory_->CreateVideoTrack(
3875 "video_track", pc_factory_->CreateVideoSource(
3876 std::unique_ptr<cricket::VideoCapturer>(
3877 new cricket::FakeVideoCapturer()))));
3878 stream->AddTrack(audio_track);
3879 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3880 observer_.renegotiation_needed_ = false;
3881
3882 stream->AddTrack(video_track);
3883 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3884 observer_.renegotiation_needed_ = false;
3885
3886 stream->RemoveTrack(audio_track);
3887 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3888 observer_.renegotiation_needed_ = false;
3889
3890 stream->RemoveTrack(video_track);
3891 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3892 observer_.renegotiation_needed_ = false;
3893}
3894
Zhi Huangb2d355e2017-10-26 17:26:37 -07003895// Tests that an error is returned if a description is applied that has fewer
3896// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003897TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003898 MediaSectionCountEnforcedForSubsequentOffer) {
3899 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003900 AddAudioTrack("audio_label");
3901 AddVideoTrack("video_label");
3902
Zhi Huangb2d355e2017-10-26 17:26:37 -07003903 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003904 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003905 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3906
3907 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003908 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003909 offer->description()->contents().pop_back();
3910 offer->description()->contents().pop_back();
3911 ASSERT_TRUE(offer->description()->contents().empty());
3912 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3913
3914 std::unique_ptr<SessionDescriptionInterface> answer;
3915 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3916 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3917
3918 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003919 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003920 offer->description()->contents().pop_back();
3921 offer->description()->contents().pop_back();
3922 ASSERT_TRUE(offer->description()->contents().empty());
3923 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3924}
3925
Steve Anton36da6ff2018-02-16 16:04:20 -08003926INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3927 PeerConnectionInterfaceTest,
3928 Values(SdpSemantics::kPlanB,
3929 SdpSemantics::kUnifiedPlan));
3930
nisse51542be2016-02-12 02:27:06 -08003931class PeerConnectionMediaConfigTest : public testing::Test {
3932 protected:
3933 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003934 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003935 pcf_->Initialize();
3936 }
nisseeaabdf62017-05-05 02:23:02 -07003937 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08003938 const PeerConnectionInterface::RTCConfiguration& config,
zhihuang1c378ed2017-08-17 14:10:50 -07003939 const MediaConstraintsInterface* constraints) {
zhihuang9763d562016-08-05 11:14:50 -07003940 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3941 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003942 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003943 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003944 }
3945
zhihuang9763d562016-08-05 11:14:50 -07003946 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003947 MockPeerConnectionObserver observer_;
3948};
3949
3950// This test verifies the default behaviour with no constraints and a
3951// default RTCConfiguration.
3952TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3953 PeerConnectionInterface::RTCConfiguration config;
3954 FakeConstraints constraints;
3955
3956 const cricket::MediaConfig& media_config =
3957 TestCreatePeerConnection(config, &constraints);
3958
3959 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003960 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3961 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003962 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003963 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003964}
3965
3966// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07003967// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003968TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
3969 PeerConnectionInterface::RTCConfiguration config;
3970 FakeConstraints constraints;
3971
3972 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
3973 const cricket::MediaConfig& media_config =
3974 TestCreatePeerConnection(config, &constraints);
3975
3976 EXPECT_TRUE(media_config.enable_dscp);
3977}
3978
3979// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07003980// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003981TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
3982 PeerConnectionInterface::RTCConfiguration config;
3983 FakeConstraints constraints;
3984
3985 constraints.AddOptional(
3986 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
3987 const cricket::MediaConfig media_config =
3988 TestCreatePeerConnection(config, &constraints);
3989
Niels Möller1d7ecd22018-01-18 15:25:12 +01003990 EXPECT_FALSE(media_config.video.enable_cpu_adaptation);
nisse51542be2016-02-12 02:27:06 -08003991}
3992
Niels Möller1d7ecd22018-01-18 15:25:12 +01003993// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003994// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003995TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3996 PeerConnectionInterface::RTCConfiguration config;
3997 FakeConstraints constraints;
3998
Niels Möller71bdda02016-03-31 12:59:59 +02003999 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08004000 const cricket::MediaConfig& media_config =
4001 TestCreatePeerConnection(config, &constraints);
4002
Niels Möller1d7ecd22018-01-18 15:25:12 +01004003 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004004}
4005
Niels Möller6539f692018-01-18 08:58:50 +01004006// This test verifies that the experiment_cpu_load_estimator flag is
4007// propagated from RTCConfiguration to the PeerConnection.
4008TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4009 PeerConnectionInterface::RTCConfiguration config;
4010 FakeConstraints constraints;
4011
4012 config.set_experiment_cpu_load_estimator(true);
4013 const cricket::MediaConfig& media_config =
4014 TestCreatePeerConnection(config, &constraints);
4015
4016 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4017}
4018
nisse0db023a2016-03-01 04:29:59 -08004019// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07004020// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08004021TEST_F(PeerConnectionMediaConfigTest,
4022 TestSuspendBelowMinBitrateConstraintTrue) {
4023 PeerConnectionInterface::RTCConfiguration config;
4024 FakeConstraints constraints;
4025
4026 constraints.AddOptional(
4027 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4028 true);
4029 const cricket::MediaConfig media_config =
4030 TestCreatePeerConnection(config, &constraints);
4031
4032 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08004033}
4034
deadbeef293e9262017-01-11 12:28:30 -08004035// Tests a few random fields being different.
4036TEST(RTCConfigurationTest, ComparisonOperators) {
4037 PeerConnectionInterface::RTCConfiguration a;
4038 PeerConnectionInterface::RTCConfiguration b;
4039 EXPECT_EQ(a, b);
4040
4041 PeerConnectionInterface::RTCConfiguration c;
4042 c.servers.push_back(PeerConnectionInterface::IceServer());
4043 EXPECT_NE(a, c);
4044
4045 PeerConnectionInterface::RTCConfiguration d;
4046 d.type = PeerConnectionInterface::kRelay;
4047 EXPECT_NE(a, d);
4048
4049 PeerConnectionInterface::RTCConfiguration e;
4050 e.audio_jitter_buffer_max_packets = 5;
4051 EXPECT_NE(a, e);
4052
4053 PeerConnectionInterface::RTCConfiguration f;
4054 f.ice_connection_receiving_timeout = 1337;
4055 EXPECT_NE(a, f);
4056
4057 PeerConnectionInterface::RTCConfiguration g;
4058 g.disable_ipv6 = true;
4059 EXPECT_NE(a, g);
4060
4061 PeerConnectionInterface::RTCConfiguration h(
4062 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4063 EXPECT_NE(a, h);
4064}