blob: 0d5f177aaf9d7d309f96f400e537e97ab9730c62 [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"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700406 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
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) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700572 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700573 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
deadbeefd7850b22017-08-23 10:59:19 -0700670 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700671};
672
Steve Anton36da6ff2018-02-16 16:04:20 -0800673// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
674class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800676 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
677 : vss_(new rtc::VirtualSocketServer()),
678 main_(vss_.get()),
679 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800680#ifdef WEBRTC_ANDROID
681 webrtc::InitializeAndroidObjects();
682#endif
683 }
684
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700686 // Use fake audio capture module since we're only testing the interface
687 // level, and using a real one could make tests flaky when run in parallel.
688 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700690 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +0200691 fake_audio_capture_module_, webrtc::CreateBuiltinAudioEncoderFactory(),
692 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr);
danilchape9021a32016-05-17 01:52:02 -0700693 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700694 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700695 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700696 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 }
698
699 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700700 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 }
702
deadbeef293e9262017-01-11 12:28:30 -0800703 // DTLS does not work in a loopback call, so is disabled for most of the
704 // tests in this file.
705 void CreatePeerConnectionWithoutDtls() {
706 FakeConstraints no_dtls_constraints;
707 no_dtls_constraints.AddMandatory(
708 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
709
710 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
711 &no_dtls_constraints);
712 }
713
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700715 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
716 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 }
718
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 void CreatePeerConnectionWithIceTransportsType(
720 PeerConnectionInterface::IceTransportsType type) {
721 PeerConnectionInterface::RTCConfiguration config;
722 config.type = type;
723 return CreatePeerConnection(config, nullptr);
724 }
725
726 void CreatePeerConnectionWithIceServer(const std::string& uri,
727 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800728 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 server.uri = uri;
731 server.password = password;
732 config.servers.push_back(server);
733 CreatePeerConnection(config, nullptr);
734 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100736 void CreatePeerConnection(
737 const PeerConnectionInterface::RTCConfiguration& config,
738 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700739 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800740 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
741 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000742
deadbeef1dcb1642017-03-29 21:08:16 -0700743 // Create certificate generator unless DTLS constraint is explicitly set to
744 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200745 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000746 bool dtls;
747 if (FindConstraint(constraints,
748 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
749 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200750 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800751 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
752 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000753 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800754 RTCConfiguration modified_config = config;
755 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200756 pc_ = pc_factory_->CreatePeerConnection(
Steve Anton36da6ff2018-02-16 16:04:20 -0800757 modified_config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200758 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 ASSERT_TRUE(pc_.get() != NULL);
760 observer_.SetPeerConnectionInterface(pc_.get());
761 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
762 }
763
deadbeef0a6c4ca2015-10-06 11:38:28 -0700764 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800765 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700767 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800768 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800769 config.sdp_semantics = sdp_semantics_;
770 rtc::scoped_refptr<PeerConnectionInterface> pc =
771 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
772 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800773 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700774 }
775
Steve Anton038834f2017-07-14 15:59:59 -0700776 void CreatePeerConnectionExpectFail(
777 PeerConnectionInterface::RTCConfiguration config) {
778 PeerConnectionInterface::IceServer server;
779 server.uri = kTurnIceServerUri;
780 server.password = kTurnPassword;
781 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800782 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700783 rtc::scoped_refptr<PeerConnectionInterface> pc =
784 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
785 EXPECT_EQ(nullptr, pc);
786 }
787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700789 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800790 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
791 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
792 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795
deadbeef0a6c4ca2015-10-06 11:38:28 -0700796 CreatePeerConnectionExpectFail(kStunInvalidPort);
797 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
798 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700800 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
802 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800806 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800808 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 }
810
811 void ReleasePeerConnection() {
812 pc_ = NULL;
813 observer_.SetPeerConnectionInterface(NULL);
814 }
815
Steve Anton36da6ff2018-02-16 16:04:20 -0800816 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
817 const std::string& label) {
818 auto video_source = pc_factory_->CreateVideoSource(
819 rtc::MakeUnique<cricket::FakeVideoCapturer>(), nullptr);
820 return pc_factory_->CreateVideoTrack(label, video_source);
821 }
822
823 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800824 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800826 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
829 observer_.renegotiation_needed_ = false;
830 }
831
Steve Anton36da6ff2018-02-16 16:04:20 -0800832 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700833 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800835 stream->AddTrack(CreateVideoTrack(label + "v0"));
836 ASSERT_TRUE(pc_->AddStream(stream));
837 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
838 observer_.renegotiation_needed_ = false;
839 }
840
841 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
842 const std::string& label) {
843 return pc_factory_->CreateAudioTrack(label, nullptr);
844 }
845
846 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800847 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800848 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800849 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800850 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
851 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
852 observer_.renegotiation_needed_ = false;
853 }
854
855 void AddAudioStream(const std::string& label) {
856 rtc::scoped_refptr<MediaStreamInterface> stream(
857 pc_factory_->CreateLocalMediaStream(label));
858 stream->AddTrack(CreateAudioTrack(label + "a0"));
859 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
861 observer_.renegotiation_needed_ = false;
862 }
863
Seth Hampson845e8782018-03-02 11:34:10 -0800864 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 const std::string& audio_track_label,
866 const std::string& video_track_label) {
867 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700868 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800869 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800870 stream->AddTrack(CreateAudioTrack(audio_track_label));
871 stream->AddTrack(CreateVideoTrack(video_track_label));
872 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
874 observer_.renegotiation_needed_ = false;
875 }
876
Steve Anton36da6ff2018-02-16 16:04:20 -0800877 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
878 cricket::MediaType media_type) {
879 for (auto receiver : pc_->GetReceivers()) {
880 if (receiver->media_type() == media_type) {
881 return receiver;
882 }
883 }
884 return nullptr;
885 }
886
kwibergd1fe2812016-04-27 06:47:29 -0700887 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700888 bool offer,
889 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000890 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
891 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 MockCreateSessionDescriptionObserver>());
893 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700894 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700896 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700899 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 return observer->result();
901 }
902
kwibergd1fe2812016-04-27 06:47:29 -0700903 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700904 MediaConstraintsInterface* constraints) {
905 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 }
907
kwibergd1fe2812016-04-27 06:47:29 -0700908 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700909 MediaConstraintsInterface* constraints) {
910 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 }
912
Steve Antondb45ca82017-09-11 18:27:34 -0700913 bool DoSetSessionDescription(
914 std::unique_ptr<SessionDescriptionInterface> desc,
915 bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000916 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
917 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 MockSetSessionDescriptionObserver>());
919 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700920 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700922 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 }
zhihuang29ff8442016-07-27 11:07:25 -0700924 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
925 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
926 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 return observer->result();
928 }
929
Steve Antondb45ca82017-09-11 18:27:34 -0700930 bool DoSetLocalDescription(
931 std::unique_ptr<SessionDescriptionInterface> desc) {
932 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 }
934
Steve Antondb45ca82017-09-11 18:27:34 -0700935 bool DoSetRemoteDescription(
936 std::unique_ptr<SessionDescriptionInterface> desc) {
937 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 }
939
940 // Calls PeerConnection::GetStats and check the return value.
941 // It does not verify the values in the StatReports since a RTCP packet might
942 // be required.
943 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000944 rtc::scoped_refptr<MockStatsObserver> observer(
945 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000946 if (!pc_->GetStats(
947 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 return false;
949 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
950 return observer->called();
951 }
952
Harald Alvestrand89061872018-01-02 14:08:34 +0100953 // Call the standards-compliant GetStats function.
954 bool DoGetRTCStats() {
955 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
956 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
957 pc_->GetStats(callback);
958 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
959 return callback->called();
960 }
961
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800963 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800965 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800966 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800967 } else {
968 // Unified Plan does not support AddStream, so just add an audio and video
969 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800970 AddAudioTrack(kAudioTracks[0], {kStreamId1});
971 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800972 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 CreateOfferReceiveAnswer();
974 }
975
976 // Verify that RTP Header extensions has been negotiated for audio and video.
977 void VerifyRemoteRtpHeaderExtensions() {
978 const cricket::MediaContentDescription* desc =
979 cricket::GetFirstAudioContentDescription(
980 pc_->remote_description()->description());
981 ASSERT_TRUE(desc != NULL);
982 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
983
984 desc = cricket::GetFirstVideoContentDescription(
985 pc_->remote_description()->description());
986 ASSERT_TRUE(desc != NULL);
987 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
988 }
989
990 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700991 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700992 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 std::string sdp;
994 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700995 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800996 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700997 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
999 }
1000
deadbeefab9b2d12015-10-14 11:33:11 -07001001 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001002 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001003 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001004 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001005 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1006 }
1007
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001009 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001010 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011
1012 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1013 // audio codec change, even if the parameter has nothing to do with
1014 // receiving. Not all parameters are serialized to SDP.
1015 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1016 // the SessionDescription, it is necessary to do that here to in order to
1017 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1018 // https://code.google.com/p/webrtc/issues/detail?id=1356
1019 std::string sdp;
1020 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001021 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001022 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001023 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1025 }
1026
1027 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001028 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001029 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030
1031 std::string sdp;
1032 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001033 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001034 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001035 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1037 }
1038
1039 void CreateOfferReceiveAnswer() {
1040 CreateOfferAsLocalDescription();
1041 std::string sdp;
1042 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1043 CreateAnswerAsRemoteDescription(sdp);
1044 }
1045
1046 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001047 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001048 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1050 // audio codec change, even if the parameter has nothing to do with
1051 // receiving. Not all parameters are serialized to SDP.
1052 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1053 // the SessionDescription, it is necessary to do that here to in order to
1054 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1055 // https://code.google.com/p/webrtc/issues/detail?id=1356
1056 std::string sdp;
1057 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001058 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001059 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060
Steve Antondb45ca82017-09-11 18:27:34 -07001061 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001063 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001064 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 }
1066
deadbeefab9b2d12015-10-14 11:33:11 -07001067 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001068 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001069 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001070 ASSERT_TRUE(answer);
1071 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1073 }
1074
deadbeefab9b2d12015-10-14 11:33:11 -07001075 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001076 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001077 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001078 ASSERT_TRUE(pr_answer);
1079 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001081 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001082 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001083 ASSERT_TRUE(answer);
1084 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1086 }
1087
Seth Hampson845e8782018-03-02 11:34:10 -08001088 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001089 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001090 // called with the given stream id and expected number of tracks.
1091 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001092 int expected_num_tracks) {
1093 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001094 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001095 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001096 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 }
1098
1099 // Creates an offer and applies it as a local session description.
1100 // Creates an answer with the same SDP an the offer but removes all lines
1101 // that start with a:ssrc"
1102 void CreateOfferReceiveAnswerWithoutSsrc() {
1103 CreateOfferAsLocalDescription();
1104 std::string sdp;
1105 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1106 SetSsrcToZero(&sdp);
1107 CreateAnswerAsRemoteDescription(sdp);
1108 }
1109
deadbeefab9b2d12015-10-14 11:33:11 -07001110 // This function creates a MediaStream with label kStreams[0] and
1111 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1112 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001113 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001114 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001115 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001116 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1117 size_t number_of_video_tracks) {
1118 EXPECT_LE(number_of_audio_tracks, 2u);
1119 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001120
1121 reference_collection_ = StreamCollection::Create();
1122 std::string sdp_ms1 = std::string(kSdpStringInit);
1123
Seth Hampson845e8782018-03-02 11:34:10 -08001124 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001125
1126 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001127 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001128 reference_collection_->AddStream(stream);
1129
1130 if (number_of_audio_tracks > 0) {
1131 sdp_ms1 += std::string(kSdpStringAudio);
1132 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1133 AddAudioTrack(kAudioTracks[0], stream);
1134 }
1135 if (number_of_audio_tracks > 1) {
1136 sdp_ms1 += kSdpStringMs1Audio1;
1137 AddAudioTrack(kAudioTracks[1], stream);
1138 }
1139
1140 if (number_of_video_tracks > 0) {
1141 sdp_ms1 += std::string(kSdpStringVideo);
1142 sdp_ms1 += std::string(kSdpStringMs1Video0);
1143 AddVideoTrack(kVideoTracks[0], stream);
1144 }
1145 if (number_of_video_tracks > 1) {
1146 sdp_ms1 += kSdpStringMs1Video1;
1147 AddVideoTrack(kVideoTracks[1], stream);
1148 }
1149
kwibergd1fe2812016-04-27 06:47:29 -07001150 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001151 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001152 }
1153
1154 void AddAudioTrack(const std::string& track_id,
1155 MediaStreamInterface* stream) {
1156 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1157 webrtc::AudioTrack::Create(track_id, nullptr));
1158 ASSERT_TRUE(stream->AddTrack(audio_track));
1159 }
1160
1161 void AddVideoTrack(const std::string& track_id,
1162 MediaStreamInterface* stream) {
1163 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001164 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001165 webrtc::FakeVideoTrackSource::Create(),
1166 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001167 ASSERT_TRUE(stream->AddTrack(video_track));
1168 }
1169
Steve Anton36da6ff2018-02-16 16:04:20 -08001170 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001171 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001172 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001173 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001174 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1175 return offer;
1176 }
1177
Steve Anton36da6ff2018-02-16 16:04:20 -08001178 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1179 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001180 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001181 std::unique_ptr<SessionDescriptionInterface> offer;
1182 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1183 return offer;
1184 }
1185
1186 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1187 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1188 std::unique_ptr<SessionDescriptionInterface> answer;
1189 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1190 return answer;
1191 }
1192
kwibergfd8be342016-05-14 19:44:11 -07001193 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001194 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001195 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001196 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001197 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1198 return answer;
1199 }
1200
1201 const std::string& GetFirstAudioStreamCname(
1202 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001203 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001204 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001205 return audio_desc->streams()[0].cname;
1206 }
1207
zhihuang1c378ed2017-08-17 14:10:50 -07001208 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1209 const RTCOfferAnswerOptions& offer_answer_options) {
1210 RTC_DCHECK(pc_);
1211 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1212 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1213 pc_->CreateOffer(observer, offer_answer_options);
1214 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1215 return observer->MoveDescription();
1216 }
1217
1218 void CreateOfferWithOptionsAsRemoteDescription(
1219 std::unique_ptr<SessionDescriptionInterface>* desc,
1220 const RTCOfferAnswerOptions& offer_answer_options) {
1221 *desc = CreateOfferWithOptions(offer_answer_options);
1222 ASSERT_TRUE(desc != nullptr);
1223 std::string sdp;
1224 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001225 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001226 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001227 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001228 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1229 }
1230
1231 void CreateOfferWithOptionsAsLocalDescription(
1232 std::unique_ptr<SessionDescriptionInterface>* desc,
1233 const RTCOfferAnswerOptions& offer_answer_options) {
1234 *desc = CreateOfferWithOptions(offer_answer_options);
1235 ASSERT_TRUE(desc != nullptr);
1236 std::string sdp;
1237 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001238 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001239 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001240
Steve Antondb45ca82017-09-11 18:27:34 -07001241 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001242 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1243 }
1244
1245 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001246 RTC_DCHECK(content);
1247 RTC_DCHECK(content->media_description());
1248 for (const cricket::AudioCodec& codec :
1249 content->media_description()->as_audio()->codecs()) {
1250 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001251 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001252 }
zhihuang1c378ed2017-08-17 14:10:50 -07001253 }
1254 return false;
1255 }
1256
Steve Anton36da6ff2018-02-16 16:04:20 -08001257 const char* GetSdpStringWithStream1() const {
1258 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1259 return kSdpStringWithStream1PlanB;
1260 } else {
1261 return kSdpStringWithStream1UnifiedPlan;
1262 }
1263 }
1264
1265 const char* GetSdpStringWithStream1And2() const {
1266 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1267 return kSdpStringWithStream1And2PlanB;
1268 } else {
1269 return kSdpStringWithStream1And2UnifiedPlan;
1270 }
1271 }
1272
deadbeef9a6f4d42017-05-15 19:43:33 -07001273 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1274 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001275 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001276 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001277 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001278 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1279 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1280 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001282 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001283 const SdpSemantics sdp_semantics_;
1284};
1285
1286class PeerConnectionInterfaceTest
1287 : public PeerConnectionInterfaceBaseTest,
1288 public ::testing::WithParamInterface<SdpSemantics> {
1289 protected:
1290 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1291};
1292
1293class PeerConnectionInterfaceTestPlanB
1294 : public PeerConnectionInterfaceBaseTest {
1295 protected:
1296 PeerConnectionInterfaceTestPlanB()
1297 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298};
1299
zhihuang8f65cdf2016-05-06 18:40:30 -07001300// Generate different CNAMEs when PeerConnections are created.
1301// The CNAMEs are expected to be generated randomly. It is possible
1302// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001303TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001304 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001305 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001306 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001307 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001308 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1309 GetFirstAudioStreamCname(offer2.get()));
1310}
1311
Steve Anton36da6ff2018-02-16 16:04:20 -08001312TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001313 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001314 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001315 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001316 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001317 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1318 GetFirstAudioStreamCname(answer2.get()));
1319}
1320
Steve Anton36da6ff2018-02-16 16:04:20 -08001321TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 CreatePeerConnectionWithDifferentConfigurations) {
1323 CreatePeerConnectionWithDifferentConfigurations();
1324}
1325
Steve Anton36da6ff2018-02-16 16:04:20 -08001326TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001327 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1328 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1329 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1330 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1331 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1332 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1333 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1334 port_allocator_->candidate_filter());
1335 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1336 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1337}
1338
1339// Test that when a PeerConnection is created with a nonzero candidate pool
1340// size, the pooled PortAllocatorSession is created with all the attributes
1341// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001342TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001343 PeerConnectionInterface::RTCConfiguration config;
1344 PeerConnectionInterface::IceServer server;
1345 server.uri = kStunAddressOnly;
1346 config.servers.push_back(server);
1347 config.type = PeerConnectionInterface::kRelay;
1348 config.disable_ipv6 = true;
1349 config.tcp_candidate_policy =
1350 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001351 config.candidate_network_policy =
1352 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001353 config.ice_candidate_pool_size = 1;
1354 CreatePeerConnection(config, nullptr);
1355
1356 const cricket::FakePortAllocatorSession* session =
1357 static_cast<const cricket::FakePortAllocatorSession*>(
1358 port_allocator_->GetPooledSession());
1359 ASSERT_NE(nullptr, session);
1360 EXPECT_EQ(1UL, session->stun_servers().size());
1361 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1362 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001363 EXPECT_LT(0U,
1364 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001365}
1366
deadbeefd21eab32017-07-26 16:50:11 -07001367// Test that network-related RTCConfiguration members are applied to the
1368// PortAllocator when CreatePeerConnection is called. Specifically:
1369// - disable_ipv6_on_wifi
1370// - max_ipv6_networks
1371// - tcp_candidate_policy
1372// - candidate_network_policy
1373// - prune_turn_ports
1374//
1375// Note that the candidate filter (RTCConfiguration::type) is already tested
1376// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001377TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001378 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1379 // Create fake port allocator.
1380 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1381 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1382 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1383
1384 // Create RTCConfiguration with some network-related fields relevant to
1385 // PortAllocator populated.
1386 PeerConnectionInterface::RTCConfiguration config;
1387 config.disable_ipv6_on_wifi = true;
1388 config.max_ipv6_networks = 10;
1389 config.tcp_candidate_policy =
1390 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1391 config.candidate_network_policy =
1392 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1393 config.prune_turn_ports = true;
1394
1395 // Create the PC factory and PC with the above config.
1396 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1397 webrtc::CreatePeerConnectionFactory(
1398 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001399 rtc::Thread::Current(), fake_audio_capture_module_,
1400 webrtc::CreateBuiltinAudioEncoderFactory(),
1401 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr));
deadbeefd21eab32017-07-26 16:50:11 -07001402 rtc::scoped_refptr<PeerConnectionInterface> pc(
1403 pc_factory->CreatePeerConnection(
1404 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1405
1406 // Now validate that the config fields set above were applied to the
1407 // PortAllocator, as flags or otherwise.
1408 EXPECT_FALSE(raw_port_allocator->flags() &
1409 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1410 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1411 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1412 EXPECT_TRUE(raw_port_allocator->flags() &
1413 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1414 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1415}
1416
deadbeef46c73892016-11-16 19:42:04 -08001417// Check that GetConfiguration returns the configuration the PeerConnection was
1418// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001419TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001420 PeerConnectionInterface::RTCConfiguration config;
1421 config.type = PeerConnectionInterface::kRelay;
1422 CreatePeerConnection(config, nullptr);
1423
1424 PeerConnectionInterface::RTCConfiguration returned_config =
1425 pc_->GetConfiguration();
1426 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1427}
1428
1429// Check that GetConfiguration returns the last configuration passed into
1430// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001431TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001432 CreatePeerConnection();
1433
Steve Anton36da6ff2018-02-16 16:04:20 -08001434 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001435 config.type = PeerConnectionInterface::kRelay;
1436 EXPECT_TRUE(pc_->SetConfiguration(config));
1437
1438 PeerConnectionInterface::RTCConfiguration returned_config =
1439 pc_->GetConfiguration();
1440 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1441}
1442
Steve Antonc79268f2018-04-24 09:54:10 -07001443TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1444 CreatePeerConnection();
1445
1446 pc_->Close();
1447
1448 EXPECT_FALSE(
1449 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1450}
1451
Steve Anton36da6ff2018-02-16 16:04:20 -08001452TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001453 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001454 AddVideoStream(kStreamId1);
1455 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 ASSERT_EQ(2u, pc_->local_streams()->count());
1457
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001458 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001459 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001460 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001461 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001462 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001463 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001465 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001466 EXPECT_EQ(3u, pc_->local_streams()->count());
1467
1468 // Remove the third stream.
1469 pc_->RemoveStream(pc_->local_streams()->at(2));
1470 EXPECT_EQ(2u, pc_->local_streams()->count());
1471
1472 // Remove the second stream.
1473 pc_->RemoveStream(pc_->local_streams()->at(1));
1474 EXPECT_EQ(1u, pc_->local_streams()->count());
1475
1476 // Remove the first stream.
1477 pc_->RemoveStream(pc_->local_streams()->at(0));
1478 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479}
1480
deadbeefab9b2d12015-10-14 11:33:11 -07001481// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001482// Don't run under Unified Plan since the stream API is not available.
1483TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001484 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001485 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001486 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001487 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001488
deadbeefab9b2d12015-10-14 11:33:11 -07001489 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001490 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001491 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001492
deadbeefab9b2d12015-10-14 11:33:11 -07001493 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001494 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001495 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001496
1497 // Add another stream and ensure the offer includes both the old and new
1498 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001499 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001500 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001501
Steve Antonb1c1de12017-12-21 15:14:30 -08001502 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001503 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1504 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001505
Steve Antonb1c1de12017-12-21 15:14:30 -08001506 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001507 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1508 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001509}
1510
Steve Anton36da6ff2018-02-16 16:04:20 -08001511// Don't run under Unified Plan since the stream API is not available.
1512TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001513 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001514 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 ASSERT_EQ(1u, pc_->local_streams()->count());
1516 pc_->RemoveStream(pc_->local_streams()->at(0));
1517 EXPECT_EQ(0u, pc_->local_streams()->count());
1518}
1519
deadbeefe1f9d832016-01-14 15:35:42 -08001520// Test for AddTrack and RemoveTrack methods.
1521// Tests that the created offer includes tracks we added,
1522// and that the RtpSenders are created correctly.
1523// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001524// Only tested with Plan B since Unified Plan is covered in more detail by tests
1525// in peerconnection_jsep_unittests.cc
1526TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001527 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001528 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001529 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001530 rtc::scoped_refptr<VideoTrackInterface> video_track(
1531 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001532 "video_track", pc_factory_->CreateVideoSource(
1533 std::unique_ptr<cricket::VideoCapturer>(
1534 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001535 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1536 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001537 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001538 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001539 EXPECT_EQ("audio_track", audio_sender->id());
1540 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001541 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001542 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001543 EXPECT_EQ("video_track", video_sender->id());
1544 EXPECT_EQ(video_track, video_sender->track());
1545
1546 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001547 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001548 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001549
1550 const cricket::ContentInfo* audio_content =
1551 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001552 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001553 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001554
1555 const cricket::ContentInfo* video_content =
1556 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001557 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001558 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
Steve Antondb45ca82017-09-11 18:27:34 -07001560 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001561
1562 // Now try removing the tracks.
1563 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1564 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1565
1566 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001567 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001568
1569 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001570 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001571 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001572
1573 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001574 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001575 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001576
Steve Antondb45ca82017-09-11 18:27:34 -07001577 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001578
1579 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1580 // should return false.
1581 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1582 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1583}
1584
1585// Test creating senders without a stream specified,
1586// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001587TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001588 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001589 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001590 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001591 rtc::scoped_refptr<VideoTrackInterface> video_track(
1592 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001593 "video_track", pc_factory_->CreateVideoSource(
1594 std::unique_ptr<cricket::VideoCapturer>(
1595 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001596 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001597 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001598 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001599 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001600 EXPECT_EQ("audio_track", audio_sender->id());
1601 EXPECT_EQ(audio_track, audio_sender->track());
1602 EXPECT_EQ("video_track", video_sender->id());
1603 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001604 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1605 // If the ID is truly a random GUID, it should be infinitely unlikely they
1606 // will be the same.
1607 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1608 } else {
1609 // We allows creating tracks without stream ids under Unified Plan
1610 // semantics.
1611 EXPECT_EQ(0u, video_sender->stream_ids().size());
1612 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1613 }
deadbeefe1f9d832016-01-14 15:35:42 -08001614}
1615
Harald Alvestrand89061872018-01-02 14:08:34 +01001616// Test that we can call GetStats() after AddTrack but before connecting
1617// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001618TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001619 CreatePeerConnectionWithoutDtls();
1620 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1621 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1622 rtc::scoped_refptr<VideoTrackInterface> video_track(
1623 pc_factory_->CreateVideoTrack(
1624 "video_track", pc_factory_->CreateVideoSource(
1625 std::unique_ptr<cricket::VideoCapturer>(
1626 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001627 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1628 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001629 EXPECT_TRUE(DoGetStats(nullptr));
1630}
1631
Steve Anton36da6ff2018-02-16 16:04:20 -08001632TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001633 CreatePeerConnectionWithoutDtls();
1634 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1635 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1636 rtc::scoped_refptr<VideoTrackInterface> video_track(
1637 pc_factory_->CreateVideoTrack(
1638 "video_track", pc_factory_->CreateVideoSource(
1639 std::unique_ptr<cricket::VideoCapturer>(
1640 new cricket::FakeVideoCapturer()))));
1641 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001642 ASSERT_TRUE(audio_sender.ok());
1643 auto* audio_sender_proxy =
1644 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1645 audio_sender.value().get());
1646 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1647
Harald Alvestrandc72af932018-01-11 17:18:19 +01001648 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001649 ASSERT_TRUE(video_sender.ok());
1650 auto* video_sender_proxy =
1651 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1652 video_sender.value().get());
1653 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001654}
1655
Steve Anton36da6ff2018-02-16 16:04:20 -08001656// Don't run under Unified Plan since the stream API is not available.
1657TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001658 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001659 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001660 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001661 ASSERT_EQ(1u, senders.size());
1662 auto* sender_proxy =
1663 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1664 senders[0].get());
1665 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001666}
1667
Steve Anton36da6ff2018-02-16 16:04:20 -08001668TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001670 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 VerifyRemoteRtpHeaderExtensions();
1672}
1673
Steve Anton36da6ff2018-02-16 16:04:20 -08001674TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001675 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001676 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 CreateOfferAsLocalDescription();
1678 std::string offer;
1679 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1680 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001681 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001685 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001686 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 CreateOfferAsRemoteDescription();
1689 CreateAnswerAsLocalDescription();
1690
Seth Hampson845e8782018-03-02 11:34:10 -08001691 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692}
1693
Steve Anton36da6ff2018-02-16 16:04:20 -08001694TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001695 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001696 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697
1698 CreateOfferAsRemoteDescription();
1699 CreatePrAnswerAsLocalDescription();
1700 CreateAnswerAsLocalDescription();
1701
Seth Hampson845e8782018-03-02 11:34:10 -08001702 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703}
1704
Steve Anton36da6ff2018-02-16 16:04:20 -08001705// Don't run under Unified Plan since the stream API is not available.
1706TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 InitiateCall();
1708 ASSERT_EQ(1u, pc_->remote_streams()->count());
1709 pc_->RemoveStream(pc_->local_streams()->at(0));
1710 CreateOfferReceiveAnswer();
1711 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001712 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 CreateOfferReceiveAnswer();
1714}
1715
1716// Tests that after negotiating an audio only call, the respondent can perform a
1717// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001718TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001719 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001720 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 CreateOfferAsRemoteDescription();
1722 CreateAnswerAsLocalDescription();
1723
1724 ASSERT_EQ(1u, pc_->remote_streams()->count());
1725 pc_->RemoveStream(pc_->local_streams()->at(0));
1726 CreateOfferReceiveAnswer();
1727 EXPECT_EQ(0u, pc_->remote_streams()->count());
1728}
1729
1730// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001731TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001732 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733
Steve Antonf1c6db12017-10-13 11:13:35 -07001734 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001736 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001737 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001738 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001739 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740
1741 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001742 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001743 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001744 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745
Steve Antonf1c6db12017-10-13 11:13:35 -07001746 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001747 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748
Steve Antonf1c6db12017-10-13 11:13:35 -07001749 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750}
1751
deadbeefab9b2d12015-10-14 11:33:11 -07001752// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753// not unique.
Steve Anton36da6ff2018-02-16 16:04:20 -08001754TEST_P(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001755 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001757 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001758 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001759 EXPECT_TRUE(offer);
1760 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761
1762 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001763 AddAudioTrack("track_label", {kStreamId1});
1764 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765
1766 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001767 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768
1769 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001770 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001771 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772}
1773
1774// Test that we will get different SSRCs for each tracks in the offer and answer
1775// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001776TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001777 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001779 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1780 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781
1782 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001783 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001784 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 int audio_ssrc = 0;
1786 int video_ssrc = 0;
1787 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1788 &audio_ssrc));
1789 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1790 &video_ssrc));
1791 EXPECT_NE(audio_ssrc, video_ssrc);
1792
1793 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001794 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001795 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001796 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 audio_ssrc = 0;
1798 video_ssrc = 0;
1799 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1800 &audio_ssrc));
1801 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1802 &video_ssrc));
1803 EXPECT_NE(audio_ssrc, video_ssrc);
1804}
1805
deadbeefeb459812015-12-15 19:24:43 -08001806// Test that it's possible to call AddTrack on a MediaStream after adding
1807// the stream to a PeerConnection.
1808// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001809// Don't run under Unified Plan since the stream API is not available.
1810TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001811 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001812 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001813 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001814 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1815
1816 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001817 rtc::scoped_refptr<VideoTrackInterface> video_track(
1818 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001819 "video_label", pc_factory_->CreateVideoSource(
1820 std::unique_ptr<cricket::VideoCapturer>(
1821 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001822 stream->AddTrack(video_track.get());
1823
kwibergd1fe2812016-04-27 06:47:29 -07001824 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001825 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001826
1827 const cricket::MediaContentDescription* video_desc =
1828 cricket::GetFirstVideoContentDescription(offer->description());
1829 EXPECT_TRUE(video_desc != nullptr);
1830}
1831
1832// Test that it's possible to call RemoveTrack on a MediaStream after adding
1833// the stream to a PeerConnection.
1834// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001835// Don't run under Unified Plan since the stream API is not available.
1836TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001837 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001838 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001839 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001840 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1841
1842 // Remove the video track.
1843 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1844
kwibergd1fe2812016-04-27 06:47:29 -07001845 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001846 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001847
1848 const cricket::MediaContentDescription* video_desc =
1849 cricket::GetFirstVideoContentDescription(offer->description());
1850 EXPECT_TRUE(video_desc == nullptr);
1851}
1852
deadbeef1dcb1642017-03-29 21:08:16 -07001853// Verify that CreateDtmfSender only succeeds if called with a valid local
1854// track. Other aspects of DtmfSenders are tested in
1855// peerconnection_integrationtest.cc.
Steve Anton36da6ff2018-02-16 16:04:20 -08001856TEST_P(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
deadbeef1dcb1642017-03-29 21:08:16 -07001857 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08001858 AddAudioTrack(kAudioTracks[0]);
deadbeef1dcb1642017-03-29 21:08:16 -07001859 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1860 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1861 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1862 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1863}
1864
deadbeefbd7d8f72015-12-18 16:58:44 -08001865// Test creating a sender with a stream ID, and ensure the ID is populated
1866// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001867// Don't run under Unified Plan since the stream API is not available.
1868TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001869 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001870 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001871
kwibergd1fe2812016-04-27 06:47:29 -07001872 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001873 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001874
1875 const cricket::MediaContentDescription* video_desc =
1876 cricket::GetFirstVideoContentDescription(offer->description());
1877 ASSERT_TRUE(video_desc != nullptr);
1878 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001879 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001880}
1881
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001883TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001885 ASSERT_LT(0u, pc_->GetSenders().size());
1886 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001887 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001888 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 EXPECT_TRUE(DoGetStats(remote_audio));
1890
1891 // Remove the stream. Since we are sending to our selves the local
1892 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001893 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 // Do a re-negotiation.
1895 CreateOfferReceiveAnswer();
1896
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 // Test that we still can get statistics for the old track. Even if it is not
1898 // sent any longer.
1899 EXPECT_TRUE(DoGetStats(remote_audio));
1900}
1901
1902// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001903TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001905 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1906 ASSERT_TRUE(video_receiver);
1907 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908}
1909
1910// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001911TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001913 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 pc_factory_->CreateAudioTrack("unknown track", NULL));
1915 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1916}
1917
Steve Anton36da6ff2018-02-16 16:04:20 -08001918TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001919 CreatePeerConnectionWithoutDtls();
1920 EXPECT_TRUE(DoGetRTCStats());
1921 // Clearing stats cache is needed now, but should be temporary.
1922 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1923 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001924 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1925 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001926 EXPECT_TRUE(DoGetRTCStats());
1927 pc_->ClearStatsCache();
1928 CreateOfferReceiveAnswer();
1929 EXPECT_TRUE(DoGetRTCStats());
1930}
1931
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001933TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 FakeConstraints constraints;
1935 constraints.SetAllowRtpDataChannels();
1936 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001937 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001939 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 pc_->CreateDataChannel("test2", NULL);
1941 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001942 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001944 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 new MockDataChannelObserver(data2));
1946
1947 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1948 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1949 std::string data_to_send1 = "testing testing";
1950 std::string data_to_send2 = "testing something else";
1951 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1952
1953 CreateOfferReceiveAnswer();
1954 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1955 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1956
1957 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1958 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1959 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1960 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1961
1962 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1963 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1964
1965 data1->Close();
1966 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1967 CreateOfferReceiveAnswer();
1968 EXPECT_FALSE(observer1->IsOpen());
1969 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1970 EXPECT_TRUE(observer2->IsOpen());
1971
1972 data_to_send2 = "testing something else again";
1973 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1974
1975 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1976}
1977
1978// This test verifies that sendnig binary data over RTP data channels should
1979// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001980TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 FakeConstraints constraints;
1982 constraints.SetAllowRtpDataChannels();
1983 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001984 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001986 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 pc_->CreateDataChannel("test2", NULL);
1988 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001989 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001991 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 new MockDataChannelObserver(data2));
1993
1994 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1995 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1996
1997 CreateOfferReceiveAnswer();
1998 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1999 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2000
2001 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2002 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2003
jbaucheec21bd2016-03-20 06:15:43 -07002004 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2006}
2007
2008// This test setup a RTP data channels in loop back and test that a channel is
2009// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002010TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 FakeConstraints constraints;
2012 constraints.SetAllowRtpDataChannels();
2013 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002014 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002016 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 new MockDataChannelObserver(data1));
2018
2019 CreateOfferReceiveAnswerWithoutSsrc();
2020
2021 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2022
2023 data1->Close();
2024 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2025 CreateOfferReceiveAnswerWithoutSsrc();
2026 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2027 EXPECT_FALSE(observer1->IsOpen());
2028}
2029
2030// This test that if a data channel is added in an answer a receive only channel
2031// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002032TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 FakeConstraints constraints;
2034 constraints.SetAllowRtpDataChannels();
2035 CreatePeerConnection(&constraints);
2036
2037 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002038 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 pc_->CreateDataChannel(offer_label, NULL);
2040
2041 CreateOfferAsLocalDescription();
2042
2043 // Replace the data channel label in the offer and apply it as an answer.
2044 std::string receive_label = "answer_channel";
2045 std::string sdp;
2046 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002047 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 receive_label.c_str(), receive_label.length(),
2049 &sdp);
2050 CreateAnswerAsRemoteDescription(sdp);
2051
2052 // Verify that a new incoming data channel has been created and that
2053 // it is open but can't we written to.
2054 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2055 DataChannelInterface* received_channel = observer_.last_datachannel_;
2056 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2057 EXPECT_EQ(receive_label, received_channel->label());
2058 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2059
2060 // Verify that the channel we initially offered has been rejected.
2061 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2062
2063 // Do another offer / answer exchange and verify that the data channel is
2064 // opened.
2065 CreateOfferReceiveAnswer();
2066 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2067 kTimeout);
2068}
2069
2070// This test that no data channel is returned if a reliable channel is
2071// requested.
2072// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002073TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 FakeConstraints constraints;
2075 constraints.SetAllowRtpDataChannels();
2076 CreatePeerConnection(&constraints);
2077
2078 std::string label = "test";
2079 webrtc::DataChannelInit config;
2080 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002081 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 pc_->CreateDataChannel(label, &config);
2083 EXPECT_TRUE(channel == NULL);
2084}
2085
deadbeefab9b2d12015-10-14 11:33:11 -07002086// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002087TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002088 FakeConstraints constraints;
2089 constraints.SetAllowRtpDataChannels();
2090 CreatePeerConnection(&constraints);
2091
2092 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002093 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002094 pc_->CreateDataChannel(label, nullptr);
2095 EXPECT_NE(channel, nullptr);
2096
zhihuang9763d562016-08-05 11:14:50 -07002097 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002098 pc_->CreateDataChannel(label, nullptr);
2099 EXPECT_EQ(dup_channel, nullptr);
2100}
2101
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102// This tests that a SCTP data channel is returned using different
2103// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002104TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 FakeConstraints constraints;
2106 constraints.SetAllowDtlsSctpDataChannels();
2107 CreatePeerConnection(&constraints);
2108
2109 webrtc::DataChannelInit config;
2110
zhihuang9763d562016-08-05 11:14:50 -07002111 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 pc_->CreateDataChannel("1", &config);
2113 EXPECT_TRUE(channel != NULL);
2114 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002115 EXPECT_TRUE(observer_.renegotiation_needed_);
2116 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117
2118 config.ordered = false;
2119 channel = pc_->CreateDataChannel("2", &config);
2120 EXPECT_TRUE(channel != NULL);
2121 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002122 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123
2124 config.ordered = true;
2125 config.maxRetransmits = 0;
2126 channel = pc_->CreateDataChannel("3", &config);
2127 EXPECT_TRUE(channel != NULL);
2128 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002129 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
2131 config.maxRetransmits = -1;
2132 config.maxRetransmitTime = 0;
2133 channel = pc_->CreateDataChannel("4", &config);
2134 EXPECT_TRUE(channel != NULL);
2135 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002136 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137}
2138
2139// This tests that no data channel is returned if both maxRetransmits and
2140// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002141TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 CreateSctpDataChannelShouldFailForInvalidConfig) {
2143 FakeConstraints constraints;
2144 constraints.SetAllowDtlsSctpDataChannels();
2145 CreatePeerConnection(&constraints);
2146
2147 std::string label = "test";
2148 webrtc::DataChannelInit config;
2149 config.maxRetransmits = 0;
2150 config.maxRetransmitTime = 0;
2151
zhihuang9763d562016-08-05 11:14:50 -07002152 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 pc_->CreateDataChannel(label, &config);
2154 EXPECT_TRUE(channel == NULL);
2155}
2156
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157// The test verifies that creating a SCTP data channel with an id already in use
2158// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002159TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 CreateSctpDataChannelWithInvalidIdShouldFail) {
2161 FakeConstraints constraints;
2162 constraints.SetAllowDtlsSctpDataChannels();
2163 CreatePeerConnection(&constraints);
2164
2165 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002166 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002168 config.id = 1;
2169 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 EXPECT_TRUE(channel != NULL);
2171 EXPECT_EQ(1, channel->id());
2172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 channel = pc_->CreateDataChannel("x", &config);
2174 EXPECT_TRUE(channel == NULL);
2175
2176 config.id = cricket::kMaxSctpSid;
2177 channel = pc_->CreateDataChannel("max", &config);
2178 EXPECT_TRUE(channel != NULL);
2179 EXPECT_EQ(config.id, channel->id());
2180
2181 config.id = cricket::kMaxSctpSid + 1;
2182 channel = pc_->CreateDataChannel("x", &config);
2183 EXPECT_TRUE(channel == NULL);
2184}
2185
deadbeefab9b2d12015-10-14 11:33:11 -07002186// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002187TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002188 FakeConstraints constraints;
2189 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2190 true);
2191 CreatePeerConnection(&constraints);
2192
2193 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002194 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002195 pc_->CreateDataChannel(label, nullptr);
2196 EXPECT_NE(channel, nullptr);
2197
zhihuang9763d562016-08-05 11:14:50 -07002198 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002199 pc_->CreateDataChannel(label, nullptr);
2200 EXPECT_NE(dup_channel, nullptr);
2201}
2202
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002203// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2204// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002205TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002206 FakeConstraints constraints;
2207 constraints.SetAllowRtpDataChannels();
2208 CreatePeerConnection(&constraints);
2209
zhihuang9763d562016-08-05 11:14:50 -07002210 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002211 pc_->CreateDataChannel("test1", NULL);
2212 EXPECT_TRUE(observer_.renegotiation_needed_);
2213 observer_.renegotiation_needed_ = false;
2214
zhihuang9763d562016-08-05 11:14:50 -07002215 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002216 pc_->CreateDataChannel("test2", NULL);
2217 EXPECT_TRUE(observer_.renegotiation_needed_);
2218}
2219
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002221TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 FakeConstraints constraints;
2223 constraints.SetAllowRtpDataChannels();
2224 CreatePeerConnection(&constraints);
2225
zhihuang9763d562016-08-05 11:14:50 -07002226 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002228 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 pc_->CreateDataChannel("test2", NULL);
2230 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002231 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002233 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 new MockDataChannelObserver(data2));
2235
2236 CreateOfferReceiveAnswer();
2237 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2238 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2239
2240 ReleasePeerConnection();
2241 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2242 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2243}
2244
Zhi Huang644fde42018-04-02 19:16:26 -07002245// This tests that RTP data channels can be rejected in an answer.
2246TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 FakeConstraints constraints;
2248 constraints.SetAllowRtpDataChannels();
2249 CreatePeerConnection(&constraints);
2250
zhihuang9763d562016-08-05 11:14:50 -07002251 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 pc_->CreateDataChannel("offer_channel", NULL));
2253
2254 CreateOfferAsLocalDescription();
2255
2256 // Create an answer where the m-line for data channels are rejected.
2257 std::string sdp;
2258 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002259 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002260 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002261 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002263 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 data_info->rejected = true;
2265
Steve Antondb45ca82017-09-11 18:27:34 -07002266 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2268}
2269
Zhi Huang644fde42018-04-02 19:16:26 -07002270#ifdef HAVE_SCTP
2271// This tests that SCTP data channels can be rejected in an answer.
2272TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2273#else
2274TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2275#endif
2276{
2277 FakeConstraints constraints;
2278 CreatePeerConnection(&constraints);
2279
2280 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2281 pc_->CreateDataChannel("offer_channel", NULL));
2282
2283 CreateOfferAsLocalDescription();
2284
2285 // Create an answer where the m-line for data channels are rejected.
2286 std::string sdp;
2287 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2288 std::unique_ptr<SessionDescriptionInterface> answer(
2289 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2290 ASSERT_TRUE(answer);
2291 cricket::ContentInfo* data_info =
2292 cricket::GetFirstDataContent(answer->description());
2293 data_info->rejected = true;
2294
2295 DoSetRemoteDescription(std::move(answer));
2296 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2297}
2298
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299// Test that we can create a session description from an SDP string from
2300// FireFox, use it as a remote session description, generate an answer and use
2301// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002302TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 FakeConstraints constraints;
2304 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2305 true);
2306 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002307 AddAudioTrack("audio_label");
2308 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002309 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002310 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002311 webrtc::kFireFoxSdpOffer, nullptr));
2312 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 CreateAnswerAsLocalDescription();
2314 ASSERT_TRUE(pc_->local_description() != NULL);
2315 ASSERT_TRUE(pc_->remote_description() != NULL);
2316
2317 const cricket::ContentInfo* content =
2318 cricket::GetFirstAudioContent(pc_->local_description()->description());
2319 ASSERT_TRUE(content != NULL);
2320 EXPECT_FALSE(content->rejected);
2321
2322 content =
2323 cricket::GetFirstVideoContent(pc_->local_description()->description());
2324 ASSERT_TRUE(content != NULL);
2325 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002326#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 content =
2328 cricket::GetFirstDataContent(pc_->local_description()->description());
2329 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002330 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002331#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332}
2333
zhihuangb19012e2017-09-19 13:47:59 -07002334// Test that fallback from DTLS to SDES is not supported.
2335// The fallback was previously supported but was removed to simplify the code
2336// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002337TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
deadbeef8662f942017-01-20 21:20:51 -08002338 FakeConstraints constraints;
2339 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2340 true);
2341 CreatePeerConnection(&constraints);
2342 // Wait for fake certificate to be generated. Previously, this is what caused
2343 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002344 AddAudioTrack("audio_label");
2345 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002346 ASSERT_NE(nullptr, fake_certificate_generator_);
2347 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2348 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002349 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002350 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2351 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002352 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002353}
2354
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355// Test that we can create an audio only offer and receive an answer with a
2356// limited set of audio codecs and receive an updated offer with more audio
2357// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002358TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002359 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002360 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 CreateOfferAsLocalDescription();
2362
Steve Anton36da6ff2018-02-16 16:04:20 -08002363 const char* answer_sdp =
2364 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2365 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002366 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002367 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002368 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369
Steve Anton36da6ff2018-02-16 16:04:20 -08002370 const char* reoffer_sdp =
2371 (sdp_semantics_ == SdpSemantics::kPlanB
2372 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2373 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002374 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002375 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002376 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 CreateAnswerAsLocalDescription();
2378}
2379
deadbeefc80741f2015-10-22 13:14:45 -07002380// Test that if we're receiving (but not sending) a track, subsequent offers
2381// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002382TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002383 FakeConstraints constraints;
2384 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2385 true);
2386 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002387 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002388 CreateAnswerAsLocalDescription();
2389
2390 // At this point we should be receiving stream 1, but not sending anything.
2391 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002392 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002393 DoCreateOffer(&offer, nullptr);
2394
2395 const cricket::ContentInfo* video_content =
2396 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002397 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2398 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002399
2400 const cricket::ContentInfo* audio_content =
2401 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002402 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2403 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002404}
2405
2406// Test that if we're receiving (but not sending) a track, and the
2407// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2408// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002409TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002410 FakeConstraints constraints;
2411 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2412 true);
2413 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002414 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002415 CreateAnswerAsLocalDescription();
2416
2417 // At this point we should be receiving stream 1, but not sending anything.
2418 // A new offer would be recvonly, but we'll set the "no receive" constraints
2419 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002420 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002421 FakeConstraints offer_constraints;
2422 offer_constraints.AddMandatory(
2423 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2424 offer_constraints.AddMandatory(
2425 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2426 DoCreateOffer(&offer, &offer_constraints);
2427
2428 const cricket::ContentInfo* video_content =
2429 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002430 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2431 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002432
2433 const cricket::ContentInfo* audio_content =
2434 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002435 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2436 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002437}
2438
deadbeef653b8e02015-11-11 12:55:10 -08002439// Test that we can use SetConfiguration to change the ICE servers of the
2440// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002441TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002442 CreatePeerConnection();
2443
Steve Anton36da6ff2018-02-16 16:04:20 -08002444 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002445 PeerConnectionInterface::IceServer server;
2446 server.uri = "stun:test_hostname";
2447 config.servers.push_back(server);
2448 EXPECT_TRUE(pc_->SetConfiguration(config));
2449
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002450 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2451 EXPECT_EQ("test_hostname",
2452 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002453}
2454
Steve Anton36da6ff2018-02-16 16:04:20 -08002455TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002456 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002457 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002458 config.type = PeerConnectionInterface::kRelay;
2459 EXPECT_TRUE(pc_->SetConfiguration(config));
2460 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2461}
2462
Steve Anton36da6ff2018-02-16 16:04:20 -08002463TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002464 PeerConnectionInterface::RTCConfiguration config;
2465 config.prune_turn_ports = false;
2466 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002467 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002468 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2469
2470 config.prune_turn_ports = true;
2471 EXPECT_TRUE(pc_->SetConfiguration(config));
2472 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2473}
2474
skvladd1f5fda2017-02-03 16:54:05 -08002475// Test that the ice check interval can be changed. This does not verify that
2476// the setting makes it all the way to P2PTransportChannel, as that would
2477// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002478TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002479 PeerConnectionInterface::RTCConfiguration config;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002480 config.ice_check_min_interval = rtc::nullopt;
skvladd1f5fda2017-02-03 16:54:05 -08002481 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002482 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002483 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002484 EXPECT_TRUE(pc_->SetConfiguration(config));
2485 PeerConnectionInterface::RTCConfiguration new_config =
2486 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002487 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002488}
2489
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002490// Test that when SetConfiguration changes both the pool size and other
2491// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002492TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002493 SetConfigurationCreatesPooledSessionCorrectly) {
2494 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002495 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002496 config.ice_candidate_pool_size = 1;
2497 PeerConnectionInterface::IceServer server;
2498 server.uri = kStunAddressOnly;
2499 config.servers.push_back(server);
2500 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002501 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002502
2503 const cricket::FakePortAllocatorSession* session =
2504 static_cast<const cricket::FakePortAllocatorSession*>(
2505 port_allocator_->GetPooledSession());
2506 ASSERT_NE(nullptr, session);
2507 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002508}
2509
deadbeef293e9262017-01-11 12:28:30 -08002510// Test that after SetLocalDescription, changing the pool size is not allowed,
2511// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002512TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002513 CantChangePoolSizeAfterSetLocalDescription) {
2514 CreatePeerConnection();
2515 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002516 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002517 config.ice_candidate_pool_size = 1;
2518 EXPECT_TRUE(pc_->SetConfiguration(config));
2519
2520 // Set remote offer; can still change pool size at this point.
2521 CreateOfferAsRemoteDescription();
2522 config.ice_candidate_pool_size = 2;
2523 EXPECT_TRUE(pc_->SetConfiguration(config));
2524
2525 // Set local answer; now it's too late.
2526 CreateAnswerAsLocalDescription();
2527 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002528 RTCError error;
2529 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2530 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2531}
2532
deadbeef42a42632017-03-10 15:18:00 -08002533// Test that after setting an answer, extra pooled sessions are discarded. The
2534// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002535TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002536 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2537 CreatePeerConnection();
2538
2539 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002540 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002541 config.ice_candidate_pool_size = 4;
2542 EXPECT_TRUE(pc_->SetConfiguration(config));
2543
2544 // Do offer/answer.
2545 CreateOfferAsRemoteDescription();
2546 CreateAnswerAsLocalDescription();
2547
2548 // Expect no pooled sessions to be left.
2549 const cricket::PortAllocatorSession* session =
2550 port_allocator_->GetPooledSession();
2551 EXPECT_EQ(nullptr, session);
2552}
2553
2554// After Close is called, pooled candidates should be discarded so as to not
2555// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002556TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002557 CreatePeerConnection();
2558
Steve Anton36da6ff2018-02-16 16:04:20 -08002559 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002560 config.ice_candidate_pool_size = 3;
2561 EXPECT_TRUE(pc_->SetConfiguration(config));
2562 pc_->Close();
2563
2564 // Expect no pooled sessions to be left.
2565 const cricket::PortAllocatorSession* session =
2566 port_allocator_->GetPooledSession();
2567 EXPECT_EQ(nullptr, session);
2568}
2569
deadbeef293e9262017-01-11 12:28:30 -08002570// Test that SetConfiguration returns an invalid modification error if
2571// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002572TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002573 SetConfigurationReturnsInvalidModificationError) {
2574 PeerConnectionInterface::RTCConfiguration config;
2575 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2576 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2577 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2578 CreatePeerConnection(config, nullptr);
2579
Steve Anton36da6ff2018-02-16 16:04:20 -08002580 PeerConnectionInterface::RTCConfiguration modified_config =
2581 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002582 modified_config.bundle_policy =
2583 PeerConnectionInterface::kBundlePolicyMaxBundle;
2584 RTCError error;
2585 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2586 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2587
Steve Anton36da6ff2018-02-16 16:04:20 -08002588 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002589 modified_config.rtcp_mux_policy =
2590 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2591 error.set_type(RTCErrorType::NONE);
2592 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2593 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2594
Steve Anton36da6ff2018-02-16 16:04:20 -08002595 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002596 modified_config.continual_gathering_policy =
2597 PeerConnectionInterface::GATHER_CONTINUALLY;
2598 error.set_type(RTCErrorType::NONE);
2599 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2600 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2601}
2602
2603// Test that SetConfiguration returns a range error if the candidate pool size
2604// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002605TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002606 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2607 PeerConnectionInterface::RTCConfiguration config;
2608 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002609 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002610
2611 config.ice_candidate_pool_size = -1;
2612 RTCError error;
2613 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2614 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2615
2616 config.ice_candidate_pool_size = INT_MAX;
2617 error.set_type(RTCErrorType::NONE);
2618 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2619 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2620}
2621
2622// Test that SetConfiguration returns a syntax error if parsing an ICE server
2623// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002624TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002625 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2626 PeerConnectionInterface::RTCConfiguration config;
2627 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002628 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002629
2630 PeerConnectionInterface::IceServer bad_server;
2631 bad_server.uri = "stunn:www.example.com";
2632 config.servers.push_back(bad_server);
2633 RTCError error;
2634 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2635 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2636}
2637
2638// Test that SetConfiguration returns an invalid parameter error if a TURN
2639// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002640TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002641 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2642 PeerConnectionInterface::RTCConfiguration config;
2643 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002644 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002645
2646 PeerConnectionInterface::IceServer bad_server;
2647 bad_server.uri = "turn:www.example.com";
2648 // Missing password.
2649 bad_server.username = "foo";
2650 config.servers.push_back(bad_server);
2651 RTCError error;
2652 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2653 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002654}
2655
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656// Test that PeerConnection::Close changes the states to closed and all remote
2657// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002658TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 // Initialize a PeerConnection and negotiate local and remote session
2660 // description.
2661 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002662
2663 // With Plan B, verify the stream count. The analog with Unified Plan is the
2664 // RtpTransceiver count.
2665 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2666 ASSERT_EQ(1u, pc_->local_streams()->count());
2667 ASSERT_EQ(1u, pc_->remote_streams()->count());
2668 } else {
2669 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2670 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671
2672 pc_->Close();
2673
2674 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2675 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2676 pc_->ice_connection_state());
2677 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2678 pc_->ice_gathering_state());
2679
Steve Anton36da6ff2018-02-16 16:04:20 -08002680 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2681 EXPECT_EQ(1u, pc_->local_streams()->count());
2682 EXPECT_EQ(1u, pc_->remote_streams()->count());
2683 } else {
2684 // Verify that the RtpTransceivers are still present but all stopped.
2685 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2686 for (auto transceiver : pc_->GetTransceivers()) {
2687 EXPECT_TRUE(transceiver->stopped());
2688 }
2689 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690
Steve Anton36da6ff2018-02-16 16:04:20 -08002691 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2692 ASSERT_TRUE(audio_receiver);
2693 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2694 ASSERT_TRUE(video_receiver);
2695
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002696 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002697 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002698 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002699 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002700 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701}
2702
2703// Test that PeerConnection methods fails gracefully after
2704// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002705// Don't run under Unified Plan since the stream API is not available.
2706TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002707 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002708 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709 CreateOfferAsRemoteDescription();
2710 CreateAnswerAsLocalDescription();
2711
2712 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002713 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 pc_->local_streams()->at(0);
2715
2716 pc_->Close();
2717
2718 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002719 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720
2721 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002722 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002724 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725
2726 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2727
2728 EXPECT_TRUE(pc_->local_description() != NULL);
2729 EXPECT_TRUE(pc_->remote_description() != NULL);
2730
kwibergd1fe2812016-04-27 06:47:29 -07002731 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002732 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002733 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002734 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735
2736 std::string sdp;
2737 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002738 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002739 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002740 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002741
2742 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002743 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002744 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002745 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746}
2747
2748// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002749TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 InitiateCall();
2751 pc_->Close();
2752 DoGetStats(NULL);
2753}
deadbeefab9b2d12015-10-14 11:33:11 -07002754
2755// NOTE: The series of tests below come from what used to be
2756// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2757// setting a remote or local description has the expected effects.
2758
2759// This test verifies that the remote MediaStreams corresponding to a received
2760// SDP string is created. In this test the two separate MediaStreams are
2761// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002762TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
deadbeefab9b2d12015-10-14 11:33:11 -07002763 FakeConstraints constraints;
2764 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2765 true);
2766 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002767 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002768
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002769 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002770 EXPECT_TRUE(
2771 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2772 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2773 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2774
2775 // Create a session description based on another SDP with another
2776 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002777 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002778
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002779 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002780 EXPECT_TRUE(
2781 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2782}
2783
2784// This test verifies that when remote tracks are added/removed from SDP, the
2785// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002786// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2787// specific behavior.
2788TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002789 AddRemoveTrackFromExistingRemoteMediaStream) {
2790 FakeConstraints constraints;
2791 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2792 true);
2793 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002794 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002795 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002796 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002797 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2798 reference_collection_));
2799
2800 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002801 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002802 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002803 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002804 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2805 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002806 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002807 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2808 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002809 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002810 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2811 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002812
2813 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002814 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002815 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002816 MockTrackObserver audio_track_observer(audio_track2);
2817 MockTrackObserver video_track_observer(video_track2);
2818
2819 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2820 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002821 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002822 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2823 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002824 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002825 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002826 audio_track2->state(), kTimeout);
2827 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2828 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002829}
2830
2831// This tests that remote tracks are ended if a local session description is set
2832// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002833TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002834 FakeConstraints constraints;
2835 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2836 true);
2837 CreatePeerConnection(&constraints);
2838 // First create and set a remote offer, then reject its video content in our
2839 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002840 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2841 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2842 ASSERT_TRUE(audio_receiver);
2843 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2844 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002845
Steve Anton36da6ff2018-02-16 16:04:20 -08002846 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2847 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002848 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002849 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2850 video_receiver->track();
2851 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002852
kwibergd1fe2812016-04-27 06:47:29 -07002853 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002854 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002855 cricket::ContentInfo* video_info =
2856 local_answer->description()->GetContentByName("video");
2857 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002858 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002859 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2860 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002861
2862 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002863 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002864 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002865 video_info = local_offer->description()->GetContentByName("video");
2866 ASSERT_TRUE(video_info != nullptr);
2867 video_info->rejected = true;
2868 cricket::ContentInfo* audio_info =
2869 local_offer->description()->GetContentByName("audio");
2870 ASSERT_TRUE(audio_info != nullptr);
2871 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002872 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002873 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002874 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2875 kTimeout);
2876 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2877 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002878}
2879
2880// This tests that we won't crash if the remote track has been removed outside
2881// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002882// Don't run under Unified Plan since the stream API is not available.
2883TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002884 FakeConstraints constraints;
2885 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2886 true);
2887 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002888 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002889 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2890 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2891 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2892
kwibergd1fe2812016-04-27 06:47:29 -07002893 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002894 webrtc::CreateSessionDescription(SdpType::kAnswer,
2895 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002896 cricket::ContentInfo* video_info =
2897 local_answer->description()->GetContentByName("video");
2898 video_info->rejected = true;
2899 cricket::ContentInfo* audio_info =
2900 local_answer->description()->GetContentByName("audio");
2901 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002902 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002903
2904 // No crash is a pass.
2905}
2906
deadbeef5e97fb52015-10-15 12:49:08 -07002907// This tests that if a recvonly remote description is set, no remote streams
2908// will be created, even if the description contains SSRCs/MSIDs.
2909// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002910TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
deadbeef5e97fb52015-10-15 12:49:08 -07002911 FakeConstraints constraints;
2912 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2913 true);
2914 CreatePeerConnection(&constraints);
2915
Steve Anton36da6ff2018-02-16 16:04:20 -08002916 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002917 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2918 strlen(kRecvonly), &recvonly_offer);
2919 CreateAndSetRemoteOffer(recvonly_offer);
2920
2921 EXPECT_EQ(0u, observer_.remote_streams()->count());
2922}
2923
deadbeefab9b2d12015-10-14 11:33:11 -07002924// This tests that a default MediaStream is created if a remote session
2925// description doesn't contain any streams and no MSID support.
2926// It also tests that the default stream is updated if a video m-line is added
2927// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002928// Don't run under Unified Plan since this behavior is Plan B specific.
2929TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002930 FakeConstraints constraints;
2931 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2932 true);
2933 CreatePeerConnection(&constraints);
2934 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2935
2936 ASSERT_EQ(1u, observer_.remote_streams()->count());
2937 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2938
2939 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2940 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002941 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002942
2943 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2944 ASSERT_EQ(1u, observer_.remote_streams()->count());
2945 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2946 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002947 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2948 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002949 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2950 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002951 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2952 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002953}
2954
2955// This tests that a default MediaStream is created if a remote session
2956// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002957// Don't run under Unified Plan since this behavior is Plan B specific.
2958TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002959 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002960 FakeConstraints constraints;
2961 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2962 true);
2963 CreatePeerConnection(&constraints);
2964 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2965
2966 ASSERT_EQ(1u, observer_.remote_streams()->count());
2967 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2968
2969 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2970 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002971 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002972}
2973
2974// This tests that it won't crash when PeerConnection tries to remove
2975// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002976// Don't run under Unified Plan since this behavior is Plan B specific.
2977TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002978 FakeConstraints constraints;
2979 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2980 true);
2981 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002982 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002983 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2984 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2985 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2986
2987 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2988
2989 // No crash is a pass.
2990}
2991
2992// This tests that a default MediaStream is created if the remote session
2993// description doesn't contain any streams and don't contain an indication if
2994// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002995// Don't run under Unified Plan since this behavior is Plan B specific.
2996TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002997 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002998 FakeConstraints constraints;
2999 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3000 true);
3001 CreatePeerConnection(&constraints);
3002 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3003
3004 ASSERT_EQ(1u, observer_.remote_streams()->count());
3005 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3006 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
3007 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3008}
3009
3010// This tests that a default MediaStream is not created if the remote session
3011// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003012// Don't run under Unified Plan since this behavior is Plan B specific.
3013TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003014 FakeConstraints constraints;
3015 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3016 true);
3017 CreatePeerConnection(&constraints);
3018 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3019 EXPECT_EQ(0u, observer_.remote_streams()->count());
3020}
3021
deadbeefbda7e0b2015-12-08 17:13:40 -08003022// This tests that when setting a new description, the old default tracks are
3023// not destroyed and recreated.
3024// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003025// Don't run under Unified Plan since this behavior is Plan B specific.
3026TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003027 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08003028 FakeConstraints constraints;
3029 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3030 true);
3031 CreatePeerConnection(&constraints);
3032 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3033
3034 ASSERT_EQ(1u, observer_.remote_streams()->count());
3035 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3036 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3037
3038 // Set the track to "disabled", then set a new description and ensure the
3039 // track is still disabled, which ensures it hasn't been recreated.
3040 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3041 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3042 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3043 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3044}
3045
deadbeefab9b2d12015-10-14 11:33:11 -07003046// This tests that a default MediaStream is not created if a remote session
3047// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003048// Don't run under Unified Plan since this behavior is Plan B specific.
3049TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
deadbeefab9b2d12015-10-14 11:33:11 -07003050 FakeConstraints constraints;
3051 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3052 true);
3053 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003054 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003055 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003056 EXPECT_TRUE(
3057 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3058
3059 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3060 EXPECT_EQ(0u, observer_.remote_streams()->count());
3061}
3062
Seth Hampson5897a6e2018-04-03 11:16:33 -07003063// This tests that a default MediaStream is created if a remote SDP comes from
3064// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3065TEST_F(PeerConnectionInterfaceTestPlanB,
3066 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
3067 FakeConstraints constraints;
3068 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3069 true);
3070 CreatePeerConnection(&constraints);
3071 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3072 // Add a=msid lines to simulate a Unified Plan endpoint that only
3073 // signals stream IDs with a=msid lines.
3074 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3075
3076 CreateAndSetRemoteOffer(sdp_string);
3077
3078 ASSERT_EQ(1u, observer_.remote_streams()->count());
3079 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3080 EXPECT_EQ("default", remote_stream->id());
3081 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3082}
3083
Seth Hampson5b4f0752018-04-02 16:31:36 -07003084// This tests that when a Plan B endpoint receives an SDP that signals no media
3085// stream IDs indicated by the special character "-" in the a=msid line, that
3086// a default stream ID will be used for the MediaStream ID. This can occur
3087// when a Unified Plan endpoint signals no media stream IDs, but signals both
3088// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3089TEST_F(PeerConnectionInterfaceTestPlanB,
3090 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
3091 FakeConstraints constraints;
3092 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3093 true);
3094 CreatePeerConnection(&constraints);
3095 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3096 // the sender's stream ID will be interpreted as no stream IDs.
3097 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3098 sdp_string.append("a=msid:- audiotrack0\n");
3099
3100 CreateAndSetRemoteOffer(sdp_string);
3101
3102 ASSERT_EQ(1u, observer_.remote_streams()->count());
3103 // Because SSRCs are signaled the track ID will be what was signaled in the
3104 // a=msid line.
3105 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3106 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3107 EXPECT_EQ("default", remote_stream->id());
3108 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003109
3110 // Previously a bug ocurred when setting the remote description a second time.
3111 // This is because we checked equality of the remote StreamParams stream ID
3112 // (empty), and the previously set stream ID for the remote sender
3113 // ("default"). This cause a track to be removed, then added, when really
3114 // nothing should occur because it is the same track.
3115 CreateAndSetRemoteOffer(sdp_string);
3116 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3117 EXPECT_EQ(1u, observer_.add_track_events_.size());
3118 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3119 remote_stream = observer_.remote_streams()->at(0);
3120 EXPECT_EQ("default", remote_stream->id());
3121 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003122}
3123
deadbeefab9b2d12015-10-14 11:33:11 -07003124// This tests that an RtpSender is created when the local description is set
3125// after adding a local stream.
3126// TODO(deadbeef): This test and the one below it need to be updated when
3127// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003128// Don't run under Unified Plan since this behavior is Plan B specific.
3129TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003130 FakeConstraints constraints;
3131 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3132 true);
3133 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003134
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003135 // Create an offer with 1 stream with 2 tracks of each type.
3136 rtc::scoped_refptr<StreamCollection> stream_collection =
3137 CreateStreamCollection(1, 2);
3138 pc_->AddStream(stream_collection->at(0));
3139 std::unique_ptr<SessionDescriptionInterface> offer;
3140 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003141 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003142
deadbeefab9b2d12015-10-14 11:33:11 -07003143 auto senders = pc_->GetSenders();
3144 EXPECT_EQ(4u, senders.size());
3145 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3146 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3147 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3148 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3149
3150 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003151 pc_->RemoveStream(stream_collection->at(0));
3152 stream_collection = CreateStreamCollection(1, 1);
3153 pc_->AddStream(stream_collection->at(0));
3154 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003155 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003156
deadbeefab9b2d12015-10-14 11:33:11 -07003157 senders = pc_->GetSenders();
3158 EXPECT_EQ(2u, senders.size());
3159 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3160 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3161 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3162 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3163}
3164
3165// This tests that an RtpSender is created when the local description is set
3166// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003167// Don't run under Unified Plan since this behavior is Plan B specific.
3168TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003169 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003170 FakeConstraints constraints;
3171 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3172 true);
3173 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003174
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003175 rtc::scoped_refptr<StreamCollection> stream_collection =
3176 CreateStreamCollection(1, 2);
3177 // Add a stream to create the offer, but remove it afterwards.
3178 pc_->AddStream(stream_collection->at(0));
3179 std::unique_ptr<SessionDescriptionInterface> offer;
3180 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3181 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003182
Steve Antondb45ca82017-09-11 18:27:34 -07003183 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003184 auto senders = pc_->GetSenders();
3185 EXPECT_EQ(0u, senders.size());
3186
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003187 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003188 senders = pc_->GetSenders();
3189 EXPECT_EQ(4u, senders.size());
3190 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3191 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3192 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3193 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3194}
3195
3196// This tests that the expected behavior occurs if the SSRC on a local track is
3197// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003198TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003199 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07003200 FakeConstraints constraints;
3201 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3202 true);
3203 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003204
Steve Anton36da6ff2018-02-16 16:04:20 -08003205 AddAudioTrack(kAudioTracks[0]);
3206 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003207 std::unique_ptr<SessionDescriptionInterface> offer;
3208 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3209 // Grab a copy of the offer before it gets passed into the PC.
Steve Antona3a92c22017-12-07 10:27:41 -08003210 auto modified_offer =
3211 rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003212 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
3213 offer->session_version());
Steve Antondb45ca82017-09-11 18:27:34 -07003214 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003215
deadbeefab9b2d12015-10-14 11:33:11 -07003216 auto senders = pc_->GetSenders();
3217 EXPECT_EQ(2u, senders.size());
3218 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3219 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3220
3221 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003222 cricket::MediaContentDescription* desc =
3223 cricket::GetFirstAudioContentDescription(modified_offer->description());
3224 ASSERT_TRUE(desc != NULL);
3225 for (StreamParams& stream : desc->mutable_streams()) {
3226 for (unsigned int& ssrc : stream.ssrcs) {
3227 ++ssrc;
3228 }
3229 }
deadbeefab9b2d12015-10-14 11:33:11 -07003230
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003231 desc =
3232 cricket::GetFirstVideoContentDescription(modified_offer->description());
3233 ASSERT_TRUE(desc != NULL);
3234 for (StreamParams& stream : desc->mutable_streams()) {
3235 for (unsigned int& ssrc : stream.ssrcs) {
3236 ++ssrc;
3237 }
3238 }
3239
Steve Antondb45ca82017-09-11 18:27:34 -07003240 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003241 senders = pc_->GetSenders();
3242 EXPECT_EQ(2u, senders.size());
3243 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3244 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3245 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3246 // changed.
3247}
3248
3249// This tests that the expected behavior occurs if a new session description is
3250// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003251// Don't run under Unified Plan since the stream API is not available.
3252TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003253 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003254 FakeConstraints constraints;
3255 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3256 true);
3257 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003258
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003259 rtc::scoped_refptr<StreamCollection> stream_collection =
3260 CreateStreamCollection(2, 1);
3261 pc_->AddStream(stream_collection->at(0));
3262 std::unique_ptr<SessionDescriptionInterface> offer;
3263 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003264 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003265
deadbeefab9b2d12015-10-14 11:33:11 -07003266 auto senders = pc_->GetSenders();
3267 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003268 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3269 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003270
3271 // Add a new MediaStream but with the same tracks as in the first stream.
3272 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3273 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003274 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3275 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003276 pc_->AddStream(stream_1);
3277
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003278 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003279 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003280
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003281 auto new_senders = pc_->GetSenders();
3282 // Should be the same senders as before, but with updated stream id.
3283 // Note that this behavior is subject to change in the future.
3284 // We may decide the PC should ignore existing tracks in AddStream.
3285 EXPECT_EQ(senders, new_senders);
3286 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3287 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003288}
3289
zhihuang81c3a032016-11-17 12:06:24 -08003290// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003291TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
zhihuang81c3a032016-11-17 12:06:24 -08003292 FakeConstraints constraints;
3293 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3294 true);
3295 CreatePeerConnection(&constraints);
3296 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3297 EXPECT_EQ(observer_.num_added_tracks_, 1);
3298 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3299
3300 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003301 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3302 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3303 EXPECT_EQ(observer_.num_added_tracks_, 2);
3304 } else {
3305 // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription
3306 // is called until the offer/answer exchange is complete. So in this case
3307 // OnAddTrack is fired twice for the first audio track plus the one time
3308 // for the video track.
3309 EXPECT_EQ(observer_.num_added_tracks_, 3);
3310 }
zhihuang81c3a032016-11-17 12:06:24 -08003311 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3312}
3313
deadbeefd1a38b52016-12-10 13:15:33 -08003314// Test that when SetConfiguration is called and the configuration is
3315// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003316TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003317 PeerConnectionInterface::RTCConfiguration config;
3318 config.type = PeerConnectionInterface::kRelay;
3319 // Need to pass default constraints to prevent disabling of DTLS...
3320 FakeConstraints default_constraints;
3321 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003322 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003323 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3324 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003325
3326 // Do initial offer/answer so there's something to restart.
3327 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003328 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003329
3330 // Grab the ufrags.
3331 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3332
3333 // Change ICE policy, which should trigger an ICE restart on the next offer.
3334 config.type = PeerConnectionInterface::kAll;
3335 EXPECT_TRUE(pc_->SetConfiguration(config));
3336 CreateOfferAsLocalDescription();
3337
3338 // Grab the new ufrags.
3339 std::vector<std::string> subsequent_ufrags =
3340 GetUfrags(pc_->local_description());
3341
3342 // Sanity check.
3343 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3344 // Check that each ufrag is different.
3345 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3346 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3347 }
3348}
3349
3350// Test that when SetConfiguration is called and the configuration *isn't*
3351// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003352TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003353 PeerConnectionInterface::RTCConfiguration config;
3354 config.type = PeerConnectionInterface::kRelay;
3355 // Need to pass default constraints to prevent disabling of DTLS...
3356 FakeConstraints default_constraints;
3357 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003358 config = pc_->GetConfiguration();
3359 AddAudioTrack(kAudioTracks[0]);
3360 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003361
3362 // Do initial offer/answer so there's something to restart.
3363 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003364 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003365
3366 // Grab the ufrags.
3367 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3368
3369 // Call SetConfiguration with a config identical to what the PC was
3370 // constructed with.
3371 EXPECT_TRUE(pc_->SetConfiguration(config));
3372 CreateOfferAsLocalDescription();
3373
3374 // Grab the new ufrags.
3375 std::vector<std::string> subsequent_ufrags =
3376 GetUfrags(pc_->local_description());
3377
3378 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3379}
3380
3381// Test for a weird corner case scenario:
3382// 1. Audio/video session established.
3383// 2. SetConfiguration changes ICE config; ICE restart needed.
3384// 3. ICE restart initiated by remote peer, but only for one m= section.
3385// 4. Next createOffer should initiate an ICE restart, but only for the other
3386// m= section; it would be pointless to do an ICE restart for the m= section
3387// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003388TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003389 PeerConnectionInterface::RTCConfiguration config;
3390 config.type = PeerConnectionInterface::kRelay;
3391 // Need to pass default constraints to prevent disabling of DTLS...
3392 FakeConstraints default_constraints;
3393 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003394 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003395 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3396 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003397
3398 // Do initial offer/answer so there's something to restart.
3399 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003400 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003401
3402 // Change ICE policy, which should set the "needs-ice-restart" flag.
3403 config.type = PeerConnectionInterface::kAll;
3404 EXPECT_TRUE(pc_->SetConfiguration(config));
3405
3406 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003407 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003408 webrtc::CreateSessionDescription(SdpType::kOffer,
3409 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003410 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003411 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3412 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003413 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003414 CreateAnswerAsLocalDescription();
3415
3416 // Grab the ufrags.
3417 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3418 ASSERT_EQ(2, initial_ufrags.size());
3419
3420 // Create offer and grab the new ufrags.
3421 CreateOfferAsLocalDescription();
3422 std::vector<std::string> subsequent_ufrags =
3423 GetUfrags(pc_->local_description());
3424 ASSERT_EQ(2, subsequent_ufrags.size());
3425
3426 // Ensure that only the ufrag for the second m= section changed.
3427 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3428 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3429}
3430
deadbeeffe4a8a42016-12-20 17:56:17 -08003431// Tests that the methods to return current/pending descriptions work as
3432// expected at different points in the offer/answer exchange. This test does
3433// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003434TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003435 // This disables DTLS so we can apply an answer to ourselves.
3436 CreatePeerConnection();
3437
3438 // Create initial local offer and get SDP (which will also be used as
3439 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003440 std::unique_ptr<SessionDescriptionInterface> local_offer;
3441 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003442 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003443 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003444
3445 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003446 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3447 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3448 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003449 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3450 EXPECT_EQ(nullptr, pc_->current_local_description());
3451 EXPECT_EQ(nullptr, pc_->current_remote_description());
3452
3453 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003454 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003455 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003456 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3457 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3458 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3459 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003460 EXPECT_EQ(nullptr, pc_->current_local_description());
3461 EXPECT_EQ(nullptr, pc_->current_remote_description());
3462
3463 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003464 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003465 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003466 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3467 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003468 EXPECT_EQ(nullptr, pc_->pending_local_description());
3469 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003470 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3471 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003472
3473 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003474 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003475 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003476 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3477 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3478 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003479 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003480 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3481 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003482
3483 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003484 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003485 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003486 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3487 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3488 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3489 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3490 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3491 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003492
3493 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003494 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003495 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003496 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3497 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003498 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3499 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003500 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3501 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003502}
3503
zhihuang77985012017-02-07 15:45:16 -08003504// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3505// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003506// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003507TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003508 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003509 CreatePeerConnection();
3510 // The RtcEventLog will be reset when the PeerConnection is closed.
3511 pc_->Close();
3512
Elad Alon9e6565b2017-10-11 16:04:13 +02003513 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3514 std::string filename = webrtc::test::OutputPath() +
3515 test_info->test_case_name() + test_info->name();
3516 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3517
3518 constexpr int64_t max_size_bytes = 1024;
3519
zhihuang77985012017-02-07 15:45:16 -08003520 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3521 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003522
3523 // Cleanup.
3524 rtc::ClosePlatformFile(file);
3525 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003526}
3527
Elad Alon99c3fe52017-10-13 16:29:40 +02003528// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3529// after the PeerConnection is closed.
3530// This version tests the StartRtcEventLog version that receives an object
3531// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003532TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003533 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3534 CreatePeerConnection();
3535 // The RtcEventLog will be reset when the PeerConnection is closed.
3536 pc_->Close();
3537
3538 rtc::PlatformFile file = 0;
3539 int64_t max_size_bytes = 1024;
3540 EXPECT_FALSE(pc_->StartRtcEventLog(
Bjorn Tereliusde939432017-11-20 17:38:14 +01003541 rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
3542 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003543 pc_->StopRtcEventLog();
3544}
3545
deadbeef30952b42017-04-21 02:41:29 -07003546// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003547TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003548 CreatePeerConnection();
3549
3550 // First, create an offer with audio/video.
3551 FakeConstraints constraints;
3552 constraints.SetMandatoryReceiveAudio(true);
3553 constraints.SetMandatoryReceiveVideo(true);
3554 std::unique_ptr<SessionDescriptionInterface> offer;
3555 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3556 cricket::SessionDescription* desc = offer->description();
3557 ASSERT_EQ(2u, desc->transport_infos().size());
3558 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3559 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3560
3561 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003562 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003563 std::unique_ptr<SessionDescriptionInterface> answer;
3564 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3565 desc = answer->description();
3566 ASSERT_EQ(2u, desc->transport_infos().size());
3567 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3568 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3569}
3570
deadbeef1dcb1642017-03-29 21:08:16 -07003571// Test that ICE renomination isn't offered if it's not enabled in the PC's
3572// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003573TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003574 PeerConnectionInterface::RTCConfiguration config;
3575 config.enable_ice_renomination = false;
3576 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003577 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003578
3579 std::unique_ptr<SessionDescriptionInterface> offer;
3580 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3581 cricket::SessionDescription* desc = offer->description();
3582 EXPECT_EQ(1u, desc->transport_infos().size());
3583 EXPECT_FALSE(
3584 desc->transport_infos()[0].description.GetIceParameters().renomination);
3585}
3586
3587// Test that the ICE renomination option is present in generated offers/answers
3588// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003589TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003590 PeerConnectionInterface::RTCConfiguration config;
3591 config.enable_ice_renomination = true;
3592 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003593 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003594
3595 std::unique_ptr<SessionDescriptionInterface> offer;
3596 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3597 cricket::SessionDescription* desc = offer->description();
3598 EXPECT_EQ(1u, desc->transport_infos().size());
3599 EXPECT_TRUE(
3600 desc->transport_infos()[0].description.GetIceParameters().renomination);
3601
3602 // Set the offer as a remote description, then create an answer and ensure it
3603 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003604 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003605 std::unique_ptr<SessionDescriptionInterface> answer;
3606 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3607 desc = answer->description();
3608 EXPECT_EQ(1u, desc->transport_infos().size());
3609 EXPECT_TRUE(
3610 desc->transport_infos()[0].description.GetIceParameters().renomination);
3611}
3612
3613// Test that if CreateOffer is called with the deprecated "offer to receive
3614// audio/video" constraints, they're processed and result in an offer with
3615// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003616TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003617 CreatePeerConnection();
3618
3619 FakeConstraints constraints;
3620 constraints.SetMandatoryReceiveAudio(true);
3621 constraints.SetMandatoryReceiveVideo(true);
3622 std::unique_ptr<SessionDescriptionInterface> offer;
3623 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3624
3625 cricket::SessionDescription* desc = offer->description();
3626 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3627 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3628 ASSERT_NE(nullptr, audio);
3629 ASSERT_NE(nullptr, video);
3630 EXPECT_FALSE(audio->rejected);
3631 EXPECT_FALSE(video->rejected);
3632}
3633
3634// Test that if CreateAnswer is called with the deprecated "offer to receive
3635// audio/video" constraints, they're processed and can be used to reject an
3636// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003637// Don't run under Unified Plan since this behavior is not supported.
3638TEST_F(PeerConnectionInterfaceTestPlanB,
3639 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003640 CreatePeerConnection();
3641
3642 // First, create an offer with audio/video and apply it as a remote
3643 // description.
3644 FakeConstraints constraints;
3645 constraints.SetMandatoryReceiveAudio(true);
3646 constraints.SetMandatoryReceiveVideo(true);
3647 std::unique_ptr<SessionDescriptionInterface> offer;
3648 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
Steve Antondb45ca82017-09-11 18:27:34 -07003649 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003650
3651 // Now create answer that rejects audio/video.
3652 constraints.SetMandatoryReceiveAudio(false);
3653 constraints.SetMandatoryReceiveVideo(false);
3654 std::unique_ptr<SessionDescriptionInterface> answer;
3655 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3656
3657 cricket::SessionDescription* desc = answer->description();
3658 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3659 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3660 ASSERT_NE(nullptr, audio);
3661 ASSERT_NE(nullptr, video);
3662 EXPECT_TRUE(audio->rejected);
3663 EXPECT_TRUE(video->rejected);
3664}
3665
deadbeef1dcb1642017-03-29 21:08:16 -07003666// Test that negotiation can succeed with a data channel only, and with the max
3667// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003668#ifdef HAVE_SCTP
3669TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3670#else
3671TEST_P(PeerConnectionInterfaceTest,
3672 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3673#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003674 PeerConnectionInterface::RTCConfiguration config;
3675 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3676 CreatePeerConnection(config, nullptr);
3677
3678 // First, create an offer with only a data channel and apply it as a remote
3679 // description.
3680 pc_->CreateDataChannel("test", nullptr);
3681 std::unique_ptr<SessionDescriptionInterface> offer;
3682 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003683 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003684
3685 // Create and set answer as well.
3686 std::unique_ptr<SessionDescriptionInterface> answer;
3687 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003688 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003689}
3690
Steve Anton36da6ff2018-02-16 16:04:20 -08003691TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003692 CreatePeerConnection();
3693 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003694 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003695 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3696}
3697
Steve Anton36da6ff2018-02-16 16:04:20 -08003698TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003699 CreatePeerConnection();
3700 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003701 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003702 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3703}
3704
Steve Anton36da6ff2018-02-16 16:04:20 -08003705TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003706 CreatePeerConnection();
3707 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003708 bitrate.min_bitrate_bps = 5;
3709 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003710 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3711}
3712
Steve Anton36da6ff2018-02-16 16:04:20 -08003713TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003714 CreatePeerConnection();
3715 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003716 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003717 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3718}
3719
Steve Anton36da6ff2018-02-16 16:04:20 -08003720TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003721 CreatePeerConnection();
3722 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003723 bitrate.current_bitrate_bps = 10;
3724 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003725 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3726}
3727
Steve Anton36da6ff2018-02-16 16:04:20 -08003728TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003729 CreatePeerConnection();
3730 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003731 bitrate.min_bitrate_bps = 10;
3732 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003733 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3734}
3735
Steve Anton36da6ff2018-02-16 16:04:20 -08003736TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003737 CreatePeerConnection();
3738 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003739 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003740 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3741}
3742
Steve Anton038834f2017-07-14 15:59:59 -07003743// ice_regather_interval_range requires WebRTC to be configured for continual
3744// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003745TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003746 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3747 PeerConnectionInterface::RTCConfiguration config;
3748 config.ice_regather_interval_range.emplace(1000, 2000);
3749 config.continual_gathering_policy =
3750 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3751 CreatePeerConnectionExpectFail(config);
3752}
3753
3754// Ensures that there is no error when ice_regather_interval_range is set with
3755// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003756TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003757 SetIceRegatherIntervalRangeWithContinualGathering) {
3758 PeerConnectionInterface::RTCConfiguration config;
3759 config.ice_regather_interval_range.emplace(1000, 2000);
3760 config.continual_gathering_policy =
3761 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3762 CreatePeerConnection(config, nullptr);
3763}
3764
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003765// The current bitrate from Call's BitrateConstraintsMask is currently clamped
3766// by Call's BitrateConstraints, which comes from the SDP or a default value.
3767// This test checks that a call to SetBitrate with a current bitrate that will
3768// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003769TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003770 CreatePeerConnection();
3771 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003772 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003773 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3774}
3775
zhihuang1c378ed2017-08-17 14:10:50 -07003776// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003777TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003778 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3779 RTCOfferAnswerOptions rtc_options;
3780
3781 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3782 // than kMaxOfferToReceiveMedia should be treated as invalid.
3783 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3784 CreatePeerConnection();
3785 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3786
3787 rtc_options.offer_to_receive_audio =
3788 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3789 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3790}
3791
Steve Anton36da6ff2018-02-16 16:04:20 -08003792TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003793 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3794 RTCOfferAnswerOptions rtc_options;
3795
3796 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3797 // than kMaxOfferToReceiveMedia should be treated as invalid.
3798 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3799 CreatePeerConnection();
3800 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3801
3802 rtc_options.offer_to_receive_video =
3803 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3804 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3805}
3806
3807// Test that the audio and video content will be added to an offer if both
3808// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003809TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003810 RTCOfferAnswerOptions rtc_options;
3811 rtc_options.offer_to_receive_audio = 1;
3812 rtc_options.offer_to_receive_video = 1;
3813
3814 std::unique_ptr<SessionDescriptionInterface> offer;
3815 CreatePeerConnection();
3816 offer = CreateOfferWithOptions(rtc_options);
3817 ASSERT_TRUE(offer);
3818 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3819 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3820}
3821
3822// Test that only audio content will be added to the offer if only
3823// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003824TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003825 RTCOfferAnswerOptions rtc_options;
3826 rtc_options.offer_to_receive_audio = 1;
3827 rtc_options.offer_to_receive_video = 0;
3828
3829 std::unique_ptr<SessionDescriptionInterface> offer;
3830 CreatePeerConnection();
3831 offer = CreateOfferWithOptions(rtc_options);
3832 ASSERT_TRUE(offer);
3833 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3834 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3835}
3836
3837// Test that only video content will be added if only |offer_to_receive_video|
3838// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003839TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003840 RTCOfferAnswerOptions rtc_options;
3841 rtc_options.offer_to_receive_audio = 0;
3842 rtc_options.offer_to_receive_video = 1;
3843
3844 std::unique_ptr<SessionDescriptionInterface> offer;
3845 CreatePeerConnection();
3846 offer = CreateOfferWithOptions(rtc_options);
3847 ASSERT_TRUE(offer);
3848 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3849 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3850}
3851
zhihuang1c378ed2017-08-17 14:10:50 -07003852// Test that no media content will be added to the offer if using default
3853// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003854TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003855 RTCOfferAnswerOptions rtc_options;
3856
3857 std::unique_ptr<SessionDescriptionInterface> offer;
3858 CreatePeerConnection();
3859 offer = CreateOfferWithOptions(rtc_options);
3860 ASSERT_TRUE(offer);
3861 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3862 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3863}
3864
3865// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3866// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003867TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3868 CreatePeerConnection();
3869
zhihuang1c378ed2017-08-17 14:10:50 -07003870 RTCOfferAnswerOptions rtc_options;
3871 rtc_options.ice_restart = false;
3872 rtc_options.offer_to_receive_audio = 1;
3873
3874 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003875 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003876 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3877 auto ufrag1 =
3878 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3879 auto pwd1 =
3880 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003881
3882 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3883 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003884 auto ufrag2 =
3885 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3886 auto pwd2 =
3887 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003888
3889 // |ice_restart| is true, the ufrag/pwd should change.
3890 rtc_options.ice_restart = true;
3891 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003892 auto ufrag3 =
3893 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3894 auto pwd3 =
3895 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003896
3897 EXPECT_EQ(ufrag1, ufrag2);
3898 EXPECT_EQ(pwd1, pwd2);
3899 EXPECT_NE(ufrag2, ufrag3);
3900 EXPECT_NE(pwd2, pwd3);
3901}
3902
3903// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3904// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003905TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003906 RTCOfferAnswerOptions rtc_options;
3907 rtc_options.offer_to_receive_audio = 1;
3908 rtc_options.offer_to_receive_video = 1;
3909
3910 std::unique_ptr<SessionDescriptionInterface> offer;
3911 CreatePeerConnection();
3912
3913 rtc_options.use_rtp_mux = true;
3914 offer = CreateOfferWithOptions(rtc_options);
3915 ASSERT_TRUE(offer);
3916 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3917 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3918 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3919
3920 rtc_options.use_rtp_mux = false;
3921 offer = CreateOfferWithOptions(rtc_options);
3922 ASSERT_TRUE(offer);
3923 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3924 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3925 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3926}
3927
zhihuang141aacb2017-08-29 13:23:53 -07003928// This test ensures OnRenegotiationNeeded is called when we add track with
3929// MediaStream -> AddTrack in the same way it is called when we add track with
3930// PeerConnection -> AddTrack.
3931// The test can be removed once addStream is rewritten in terms of addTrack
3932// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003933// Don't run under Unified Plan since the stream API is not available.
3934TEST_F(PeerConnectionInterfaceTestPlanB,
3935 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003936 CreatePeerConnectionWithoutDtls();
3937 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003938 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003939 pc_->AddStream(stream);
3940 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3941 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3942 rtc::scoped_refptr<VideoTrackInterface> video_track(
3943 pc_factory_->CreateVideoTrack(
3944 "video_track", pc_factory_->CreateVideoSource(
3945 std::unique_ptr<cricket::VideoCapturer>(
3946 new cricket::FakeVideoCapturer()))));
3947 stream->AddTrack(audio_track);
3948 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3949 observer_.renegotiation_needed_ = false;
3950
3951 stream->AddTrack(video_track);
3952 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3953 observer_.renegotiation_needed_ = false;
3954
3955 stream->RemoveTrack(audio_track);
3956 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3957 observer_.renegotiation_needed_ = false;
3958
3959 stream->RemoveTrack(video_track);
3960 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3961 observer_.renegotiation_needed_ = false;
3962}
3963
Zhi Huangb2d355e2017-10-26 17:26:37 -07003964// Tests that an error is returned if a description is applied that has fewer
3965// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003966TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003967 MediaSectionCountEnforcedForSubsequentOffer) {
3968 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003969 AddAudioTrack("audio_label");
3970 AddVideoTrack("video_label");
3971
Zhi Huangb2d355e2017-10-26 17:26:37 -07003972 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003973 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003974 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3975
3976 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003977 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003978 offer->description()->contents().pop_back();
3979 offer->description()->contents().pop_back();
3980 ASSERT_TRUE(offer->description()->contents().empty());
3981 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3982
3983 std::unique_ptr<SessionDescriptionInterface> answer;
3984 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3985 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3986
3987 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003988 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003989 offer->description()->contents().pop_back();
3990 offer->description()->contents().pop_back();
3991 ASSERT_TRUE(offer->description()->contents().empty());
3992 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3993}
3994
Steve Anton36da6ff2018-02-16 16:04:20 -08003995INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3996 PeerConnectionInterfaceTest,
3997 Values(SdpSemantics::kPlanB,
3998 SdpSemantics::kUnifiedPlan));
3999
nisse51542be2016-02-12 02:27:06 -08004000class PeerConnectionMediaConfigTest : public testing::Test {
4001 protected:
4002 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07004003 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08004004 pcf_->Initialize();
4005 }
nisseeaabdf62017-05-05 02:23:02 -07004006 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08004007 const PeerConnectionInterface::RTCConfiguration& config,
zhihuang1c378ed2017-08-17 14:10:50 -07004008 const MediaConstraintsInterface* constraints) {
zhihuang9763d562016-08-05 11:14:50 -07004009 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
4010 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08004011 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07004012 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08004013 }
4014
zhihuang9763d562016-08-05 11:14:50 -07004015 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08004016 MockPeerConnectionObserver observer_;
4017};
4018
4019// This test verifies the default behaviour with no constraints and a
4020// default RTCConfiguration.
4021TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4022 PeerConnectionInterface::RTCConfiguration config;
4023 FakeConstraints constraints;
4024
4025 const cricket::MediaConfig& media_config =
4026 TestCreatePeerConnection(config, &constraints);
4027
4028 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004029 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4030 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004031 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004032 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004033}
4034
4035// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07004036// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004037TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
4038 PeerConnectionInterface::RTCConfiguration config;
4039 FakeConstraints constraints;
4040
4041 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
4042 const cricket::MediaConfig& media_config =
4043 TestCreatePeerConnection(config, &constraints);
4044
4045 EXPECT_TRUE(media_config.enable_dscp);
4046}
4047
4048// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07004049// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004050TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
4051 PeerConnectionInterface::RTCConfiguration config;
4052 FakeConstraints constraints;
4053
4054 constraints.AddOptional(
4055 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
4056 const cricket::MediaConfig media_config =
4057 TestCreatePeerConnection(config, &constraints);
4058
Niels Möller1d7ecd22018-01-18 15:25:12 +01004059 EXPECT_FALSE(media_config.video.enable_cpu_adaptation);
nisse51542be2016-02-12 02:27:06 -08004060}
4061
Niels Möller1d7ecd22018-01-18 15:25:12 +01004062// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004063// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004064TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4065 PeerConnectionInterface::RTCConfiguration config;
4066 FakeConstraints constraints;
4067
Niels Möller71bdda02016-03-31 12:59:59 +02004068 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08004069 const cricket::MediaConfig& media_config =
4070 TestCreatePeerConnection(config, &constraints);
4071
Niels Möller1d7ecd22018-01-18 15:25:12 +01004072 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004073}
4074
Niels Möller6539f692018-01-18 08:58:50 +01004075// This test verifies that the experiment_cpu_load_estimator flag is
4076// propagated from RTCConfiguration to the PeerConnection.
4077TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4078 PeerConnectionInterface::RTCConfiguration config;
4079 FakeConstraints constraints;
4080
4081 config.set_experiment_cpu_load_estimator(true);
4082 const cricket::MediaConfig& media_config =
4083 TestCreatePeerConnection(config, &constraints);
4084
4085 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4086}
4087
nisse0db023a2016-03-01 04:29:59 -08004088// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07004089// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08004090TEST_F(PeerConnectionMediaConfigTest,
4091 TestSuspendBelowMinBitrateConstraintTrue) {
4092 PeerConnectionInterface::RTCConfiguration config;
4093 FakeConstraints constraints;
4094
4095 constraints.AddOptional(
4096 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4097 true);
4098 const cricket::MediaConfig media_config =
4099 TestCreatePeerConnection(config, &constraints);
4100
4101 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08004102}
4103
deadbeef293e9262017-01-11 12:28:30 -08004104// Tests a few random fields being different.
4105TEST(RTCConfigurationTest, ComparisonOperators) {
4106 PeerConnectionInterface::RTCConfiguration a;
4107 PeerConnectionInterface::RTCConfiguration b;
4108 EXPECT_EQ(a, b);
4109
4110 PeerConnectionInterface::RTCConfiguration c;
4111 c.servers.push_back(PeerConnectionInterface::IceServer());
4112 EXPECT_NE(a, c);
4113
4114 PeerConnectionInterface::RTCConfiguration d;
4115 d.type = PeerConnectionInterface::kRelay;
4116 EXPECT_NE(a, d);
4117
4118 PeerConnectionInterface::RTCConfiguration e;
4119 e.audio_jitter_buffer_max_packets = 5;
4120 EXPECT_NE(a, e);
4121
4122 PeerConnectionInterface::RTCConfiguration f;
4123 f.ice_connection_receiving_timeout = 1337;
4124 EXPECT_NE(a, f);
4125
4126 PeerConnectionInterface::RTCConfiguration g;
4127 g.disable_ipv6 = true;
4128 EXPECT_NE(a, g);
4129
4130 PeerConnectionInterface::RTCConfiguration h(
4131 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4132 EXPECT_NE(a, h);
4133}