blob: f702112ca2a9c3bc122070b63f4a538dd32a0946 [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
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001417// Test that the PeerConnection initializes the port allocator passed into it,
1418// and on the correct thread.
Steve Anton36da6ff2018-02-16 16:04:20 -08001419TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001420 CreatePeerConnectionInitializesPortAllocatorOnNetworkThread) {
tommie7251592017-07-14 14:44:46 -07001421 std::unique_ptr<rtc::Thread> network_thread(
1422 rtc::Thread::CreateWithSocketServer());
1423 network_thread->Start();
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001424 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1425 webrtc::CreatePeerConnectionFactory(
tommie7251592017-07-14 14:44:46 -07001426 network_thread.get(), rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001427 fake_audio_capture_module_,
1428 webrtc::CreateBuiltinAudioEncoderFactory(),
1429 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr));
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001430 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
tommie7251592017-07-14 14:44:46 -07001431 new cricket::FakePortAllocator(network_thread.get(), nullptr));
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001432 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1433 PeerConnectionInterface::RTCConfiguration config;
1434 rtc::scoped_refptr<PeerConnectionInterface> pc(
1435 pc_factory->CreatePeerConnection(
1436 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1437 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1438 // so all we have to do here is check that it's initialized.
1439 EXPECT_TRUE(raw_port_allocator->initialized());
1440}
1441
deadbeef46c73892016-11-16 19:42:04 -08001442// Check that GetConfiguration returns the configuration the PeerConnection was
1443// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001444TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001445 PeerConnectionInterface::RTCConfiguration config;
1446 config.type = PeerConnectionInterface::kRelay;
1447 CreatePeerConnection(config, nullptr);
1448
1449 PeerConnectionInterface::RTCConfiguration returned_config =
1450 pc_->GetConfiguration();
1451 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1452}
1453
1454// Check that GetConfiguration returns the last configuration passed into
1455// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001456TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001457 CreatePeerConnection();
1458
Steve Anton36da6ff2018-02-16 16:04:20 -08001459 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001460 config.type = PeerConnectionInterface::kRelay;
1461 EXPECT_TRUE(pc_->SetConfiguration(config));
1462
1463 PeerConnectionInterface::RTCConfiguration returned_config =
1464 pc_->GetConfiguration();
1465 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1466}
1467
Steve Anton36da6ff2018-02-16 16:04:20 -08001468TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001469 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001470 AddVideoStream(kStreamId1);
1471 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 ASSERT_EQ(2u, pc_->local_streams()->count());
1473
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001474 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001475 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001476 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001477 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001478 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001479 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001481 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001482 EXPECT_EQ(3u, pc_->local_streams()->count());
1483
1484 // Remove the third stream.
1485 pc_->RemoveStream(pc_->local_streams()->at(2));
1486 EXPECT_EQ(2u, pc_->local_streams()->count());
1487
1488 // Remove the second stream.
1489 pc_->RemoveStream(pc_->local_streams()->at(1));
1490 EXPECT_EQ(1u, pc_->local_streams()->count());
1491
1492 // Remove the first stream.
1493 pc_->RemoveStream(pc_->local_streams()->at(0));
1494 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495}
1496
deadbeefab9b2d12015-10-14 11:33:11 -07001497// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001498// Don't run under Unified Plan since the stream API is not available.
1499TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001500 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001501 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001502 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001503 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001504
deadbeefab9b2d12015-10-14 11:33:11 -07001505 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001506 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001507 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001508
deadbeefab9b2d12015-10-14 11:33:11 -07001509 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001510 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001511 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001512
1513 // Add another stream and ensure the offer includes both the old and new
1514 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001515 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001516 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001517
Steve Antonb1c1de12017-12-21 15:14:30 -08001518 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001519 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1520 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001521
Steve Antonb1c1de12017-12-21 15:14:30 -08001522 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001523 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1524 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001525}
1526
Steve Anton36da6ff2018-02-16 16:04:20 -08001527// Don't run under Unified Plan since the stream API is not available.
1528TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001529 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001530 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 ASSERT_EQ(1u, pc_->local_streams()->count());
1532 pc_->RemoveStream(pc_->local_streams()->at(0));
1533 EXPECT_EQ(0u, pc_->local_streams()->count());
1534}
1535
deadbeefe1f9d832016-01-14 15:35:42 -08001536// Test for AddTrack and RemoveTrack methods.
1537// Tests that the created offer includes tracks we added,
1538// and that the RtpSenders are created correctly.
1539// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001540// Only tested with Plan B since Unified Plan is covered in more detail by tests
1541// in peerconnection_jsep_unittests.cc
1542TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001543 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001544 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001545 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001546 rtc::scoped_refptr<VideoTrackInterface> video_track(
1547 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001548 "video_track", pc_factory_->CreateVideoSource(
1549 std::unique_ptr<cricket::VideoCapturer>(
1550 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001551 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1552 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001553 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001554 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001555 EXPECT_EQ("audio_track", audio_sender->id());
1556 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001557 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001558 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001559 EXPECT_EQ("video_track", video_sender->id());
1560 EXPECT_EQ(video_track, video_sender->track());
1561
1562 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001563 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001564 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
1566 const cricket::ContentInfo* audio_content =
1567 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001568 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001569 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001570
1571 const cricket::ContentInfo* video_content =
1572 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001573 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001574 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001575
Steve Antondb45ca82017-09-11 18:27:34 -07001576 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001577
1578 // Now try removing the tracks.
1579 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1580 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1581
1582 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001583 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001584
1585 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001586 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001587 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001588
1589 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001590 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001591 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001592
Steve Antondb45ca82017-09-11 18:27:34 -07001593 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001594
1595 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1596 // should return false.
1597 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1598 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1599}
1600
1601// Test creating senders without a stream specified,
1602// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001603TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001604 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001605 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001606 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001607 rtc::scoped_refptr<VideoTrackInterface> video_track(
1608 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001609 "video_track", pc_factory_->CreateVideoSource(
1610 std::unique_ptr<cricket::VideoCapturer>(
1611 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001612 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001613 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001614 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001615 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001616 EXPECT_EQ("audio_track", audio_sender->id());
1617 EXPECT_EQ(audio_track, audio_sender->track());
1618 EXPECT_EQ("video_track", video_sender->id());
1619 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001620 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1621 // If the ID is truly a random GUID, it should be infinitely unlikely they
1622 // will be the same.
1623 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1624 } else {
1625 // We allows creating tracks without stream ids under Unified Plan
1626 // semantics.
1627 EXPECT_EQ(0u, video_sender->stream_ids().size());
1628 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1629 }
deadbeefe1f9d832016-01-14 15:35:42 -08001630}
1631
Harald Alvestrand89061872018-01-02 14:08:34 +01001632// Test that we can call GetStats() after AddTrack but before connecting
1633// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001634TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001635 CreatePeerConnectionWithoutDtls();
1636 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1637 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1638 rtc::scoped_refptr<VideoTrackInterface> video_track(
1639 pc_factory_->CreateVideoTrack(
1640 "video_track", pc_factory_->CreateVideoSource(
1641 std::unique_ptr<cricket::VideoCapturer>(
1642 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001643 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1644 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001645 EXPECT_TRUE(DoGetStats(nullptr));
1646}
1647
Steve Anton36da6ff2018-02-16 16:04:20 -08001648TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001649 CreatePeerConnectionWithoutDtls();
1650 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1651 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1652 rtc::scoped_refptr<VideoTrackInterface> video_track(
1653 pc_factory_->CreateVideoTrack(
1654 "video_track", pc_factory_->CreateVideoSource(
1655 std::unique_ptr<cricket::VideoCapturer>(
1656 new cricket::FakeVideoCapturer()))));
1657 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001658 ASSERT_TRUE(audio_sender.ok());
1659 auto* audio_sender_proxy =
1660 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1661 audio_sender.value().get());
1662 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1663
Harald Alvestrandc72af932018-01-11 17:18:19 +01001664 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001665 ASSERT_TRUE(video_sender.ok());
1666 auto* video_sender_proxy =
1667 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1668 video_sender.value().get());
1669 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001670}
1671
Steve Anton36da6ff2018-02-16 16:04:20 -08001672// Don't run under Unified Plan since the stream API is not available.
1673TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001674 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001675 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001676 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001677 ASSERT_EQ(1u, senders.size());
1678 auto* sender_proxy =
1679 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1680 senders[0].get());
1681 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001686 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 VerifyRemoteRtpHeaderExtensions();
1688}
1689
Steve Anton36da6ff2018-02-16 16:04:20 -08001690TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001691 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001692 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 CreateOfferAsLocalDescription();
1694 std::string offer;
1695 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1696 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001697 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698}
1699
Steve Anton36da6ff2018-02-16 16:04:20 -08001700TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001701 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001702 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703
1704 CreateOfferAsRemoteDescription();
1705 CreateAnswerAsLocalDescription();
1706
Seth Hampson845e8782018-03-02 11:34:10 -08001707 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708}
1709
Steve Anton36da6ff2018-02-16 16:04:20 -08001710TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001711 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001712 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713
1714 CreateOfferAsRemoteDescription();
1715 CreatePrAnswerAsLocalDescription();
1716 CreateAnswerAsLocalDescription();
1717
Seth Hampson845e8782018-03-02 11:34:10 -08001718 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719}
1720
Steve Anton36da6ff2018-02-16 16:04:20 -08001721// Don't run under Unified Plan since the stream API is not available.
1722TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 InitiateCall();
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());
Seth Hampson845e8782018-03-02 11:34:10 -08001728 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 CreateOfferReceiveAnswer();
1730}
1731
1732// Tests that after negotiating an audio only call, the respondent can perform a
1733// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001734TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001735 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001736 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 CreateOfferAsRemoteDescription();
1738 CreateAnswerAsLocalDescription();
1739
1740 ASSERT_EQ(1u, pc_->remote_streams()->count());
1741 pc_->RemoveStream(pc_->local_streams()->at(0));
1742 CreateOfferReceiveAnswer();
1743 EXPECT_EQ(0u, pc_->remote_streams()->count());
1744}
1745
1746// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001747TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001748 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749
Steve Antonf1c6db12017-10-13 11:13:35 -07001750 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001752 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001753 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001754 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001755 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756
1757 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001758 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001759 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001760 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761
Steve Antonf1c6db12017-10-13 11:13:35 -07001762 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001763 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764
Steve Antonf1c6db12017-10-13 11:13:35 -07001765 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766}
1767
deadbeefab9b2d12015-10-14 11:33:11 -07001768// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769// not unique.
Steve Anton36da6ff2018-02-16 16:04:20 -08001770TEST_P(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001771 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001773 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001774 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001775 EXPECT_TRUE(offer);
1776 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777
1778 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001779 AddAudioTrack("track_label", {kStreamId1});
1780 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781
1782 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001783 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784
1785 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001786 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001787 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788}
1789
1790// Test that we will get different SSRCs for each tracks in the offer and answer
1791// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001792TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001793 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001795 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1796 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797
1798 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001799 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001800 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 int audio_ssrc = 0;
1802 int video_ssrc = 0;
1803 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1804 &audio_ssrc));
1805 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1806 &video_ssrc));
1807 EXPECT_NE(audio_ssrc, video_ssrc);
1808
1809 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001810 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001811 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001812 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 audio_ssrc = 0;
1814 video_ssrc = 0;
1815 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1816 &audio_ssrc));
1817 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1818 &video_ssrc));
1819 EXPECT_NE(audio_ssrc, video_ssrc);
1820}
1821
deadbeefeb459812015-12-15 19:24:43 -08001822// Test that it's possible to call AddTrack on a MediaStream after adding
1823// the stream to a PeerConnection.
1824// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001825// Don't run under Unified Plan since the stream API is not available.
1826TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001827 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001828 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001829 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001830 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1831
1832 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001833 rtc::scoped_refptr<VideoTrackInterface> video_track(
1834 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001835 "video_label", pc_factory_->CreateVideoSource(
1836 std::unique_ptr<cricket::VideoCapturer>(
1837 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001838 stream->AddTrack(video_track.get());
1839
kwibergd1fe2812016-04-27 06:47:29 -07001840 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001841 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001842
1843 const cricket::MediaContentDescription* video_desc =
1844 cricket::GetFirstVideoContentDescription(offer->description());
1845 EXPECT_TRUE(video_desc != nullptr);
1846}
1847
1848// Test that it's possible to call RemoveTrack on a MediaStream after adding
1849// the stream to a PeerConnection.
1850// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001851// Don't run under Unified Plan since the stream API is not available.
1852TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001853 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001854 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001855 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001856 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1857
1858 // Remove the video track.
1859 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1860
kwibergd1fe2812016-04-27 06:47:29 -07001861 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001862 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001863
1864 const cricket::MediaContentDescription* video_desc =
1865 cricket::GetFirstVideoContentDescription(offer->description());
1866 EXPECT_TRUE(video_desc == nullptr);
1867}
1868
deadbeef1dcb1642017-03-29 21:08:16 -07001869// Verify that CreateDtmfSender only succeeds if called with a valid local
1870// track. Other aspects of DtmfSenders are tested in
1871// peerconnection_integrationtest.cc.
Steve Anton36da6ff2018-02-16 16:04:20 -08001872TEST_P(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
deadbeef1dcb1642017-03-29 21:08:16 -07001873 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08001874 AddAudioTrack(kAudioTracks[0]);
deadbeef1dcb1642017-03-29 21:08:16 -07001875 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1876 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1877 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1878 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1879}
1880
deadbeefbd7d8f72015-12-18 16:58:44 -08001881// Test creating a sender with a stream ID, and ensure the ID is populated
1882// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001883// Don't run under Unified Plan since the stream API is not available.
1884TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001885 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001886 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001887
kwibergd1fe2812016-04-27 06:47:29 -07001888 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001889 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001890
1891 const cricket::MediaContentDescription* video_desc =
1892 cricket::GetFirstVideoContentDescription(offer->description());
1893 ASSERT_TRUE(video_desc != nullptr);
1894 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001895 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001896}
1897
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001899TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001901 ASSERT_LT(0u, pc_->GetSenders().size());
1902 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001903 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001904 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 EXPECT_TRUE(DoGetStats(remote_audio));
1906
1907 // Remove the stream. Since we are sending to our selves the local
1908 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001909 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 // Do a re-negotiation.
1911 CreateOfferReceiveAnswer();
1912
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 // Test that we still can get statistics for the old track. Even if it is not
1914 // sent any longer.
1915 EXPECT_TRUE(DoGetStats(remote_audio));
1916}
1917
1918// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001919TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001921 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1922 ASSERT_TRUE(video_receiver);
1923 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924}
1925
1926// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001927TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001929 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 pc_factory_->CreateAudioTrack("unknown track", NULL));
1931 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1932}
1933
Steve Anton36da6ff2018-02-16 16:04:20 -08001934TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001935 CreatePeerConnectionWithoutDtls();
1936 EXPECT_TRUE(DoGetRTCStats());
1937 // Clearing stats cache is needed now, but should be temporary.
1938 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1939 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001940 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1941 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001942 EXPECT_TRUE(DoGetRTCStats());
1943 pc_->ClearStatsCache();
1944 CreateOfferReceiveAnswer();
1945 EXPECT_TRUE(DoGetRTCStats());
1946}
1947
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001949TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 FakeConstraints constraints;
1951 constraints.SetAllowRtpDataChannels();
1952 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001953 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001955 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 pc_->CreateDataChannel("test2", NULL);
1957 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001958 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001960 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 new MockDataChannelObserver(data2));
1962
1963 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1964 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1965 std::string data_to_send1 = "testing testing";
1966 std::string data_to_send2 = "testing something else";
1967 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1968
1969 CreateOfferReceiveAnswer();
1970 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1971 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1972
1973 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1974 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1975 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1976 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1977
1978 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1979 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1980
1981 data1->Close();
1982 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1983 CreateOfferReceiveAnswer();
1984 EXPECT_FALSE(observer1->IsOpen());
1985 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1986 EXPECT_TRUE(observer2->IsOpen());
1987
1988 data_to_send2 = "testing something else again";
1989 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1990
1991 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1992}
1993
1994// This test verifies that sendnig binary data over RTP data channels should
1995// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001996TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 FakeConstraints constraints;
1998 constraints.SetAllowRtpDataChannels();
1999 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002000 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002002 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 pc_->CreateDataChannel("test2", NULL);
2004 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002005 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002007 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 new MockDataChannelObserver(data2));
2009
2010 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
2011 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
2012
2013 CreateOfferReceiveAnswer();
2014 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2015 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2016
2017 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2018 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2019
jbaucheec21bd2016-03-20 06:15:43 -07002020 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2022}
2023
2024// This test setup a RTP data channels in loop back and test that a channel is
2025// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002026TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 FakeConstraints constraints;
2028 constraints.SetAllowRtpDataChannels();
2029 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002030 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002032 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 new MockDataChannelObserver(data1));
2034
2035 CreateOfferReceiveAnswerWithoutSsrc();
2036
2037 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2038
2039 data1->Close();
2040 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2041 CreateOfferReceiveAnswerWithoutSsrc();
2042 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2043 EXPECT_FALSE(observer1->IsOpen());
2044}
2045
2046// This test that if a data channel is added in an answer a receive only channel
2047// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002048TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 FakeConstraints constraints;
2050 constraints.SetAllowRtpDataChannels();
2051 CreatePeerConnection(&constraints);
2052
2053 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002054 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 pc_->CreateDataChannel(offer_label, NULL);
2056
2057 CreateOfferAsLocalDescription();
2058
2059 // Replace the data channel label in the offer and apply it as an answer.
2060 std::string receive_label = "answer_channel";
2061 std::string sdp;
2062 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002063 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 receive_label.c_str(), receive_label.length(),
2065 &sdp);
2066 CreateAnswerAsRemoteDescription(sdp);
2067
2068 // Verify that a new incoming data channel has been created and that
2069 // it is open but can't we written to.
2070 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2071 DataChannelInterface* received_channel = observer_.last_datachannel_;
2072 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2073 EXPECT_EQ(receive_label, received_channel->label());
2074 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2075
2076 // Verify that the channel we initially offered has been rejected.
2077 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2078
2079 // Do another offer / answer exchange and verify that the data channel is
2080 // opened.
2081 CreateOfferReceiveAnswer();
2082 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2083 kTimeout);
2084}
2085
2086// This test that no data channel is returned if a reliable channel is
2087// requested.
2088// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002089TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 FakeConstraints constraints;
2091 constraints.SetAllowRtpDataChannels();
2092 CreatePeerConnection(&constraints);
2093
2094 std::string label = "test";
2095 webrtc::DataChannelInit config;
2096 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002097 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 pc_->CreateDataChannel(label, &config);
2099 EXPECT_TRUE(channel == NULL);
2100}
2101
deadbeefab9b2d12015-10-14 11:33:11 -07002102// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002103TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002104 FakeConstraints constraints;
2105 constraints.SetAllowRtpDataChannels();
2106 CreatePeerConnection(&constraints);
2107
2108 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002109 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002110 pc_->CreateDataChannel(label, nullptr);
2111 EXPECT_NE(channel, nullptr);
2112
zhihuang9763d562016-08-05 11:14:50 -07002113 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002114 pc_->CreateDataChannel(label, nullptr);
2115 EXPECT_EQ(dup_channel, nullptr);
2116}
2117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118// This tests that a SCTP data channel is returned using different
2119// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002120TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 FakeConstraints constraints;
2122 constraints.SetAllowDtlsSctpDataChannels();
2123 CreatePeerConnection(&constraints);
2124
2125 webrtc::DataChannelInit config;
2126
zhihuang9763d562016-08-05 11:14:50 -07002127 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 pc_->CreateDataChannel("1", &config);
2129 EXPECT_TRUE(channel != NULL);
2130 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002131 EXPECT_TRUE(observer_.renegotiation_needed_);
2132 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
2134 config.ordered = false;
2135 channel = pc_->CreateDataChannel("2", &config);
2136 EXPECT_TRUE(channel != NULL);
2137 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002138 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139
2140 config.ordered = true;
2141 config.maxRetransmits = 0;
2142 channel = pc_->CreateDataChannel("3", &config);
2143 EXPECT_TRUE(channel != NULL);
2144 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002145 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146
2147 config.maxRetransmits = -1;
2148 config.maxRetransmitTime = 0;
2149 channel = pc_->CreateDataChannel("4", &config);
2150 EXPECT_TRUE(channel != NULL);
2151 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002152 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153}
2154
2155// This tests that no data channel is returned if both maxRetransmits and
2156// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002157TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 CreateSctpDataChannelShouldFailForInvalidConfig) {
2159 FakeConstraints constraints;
2160 constraints.SetAllowDtlsSctpDataChannels();
2161 CreatePeerConnection(&constraints);
2162
2163 std::string label = "test";
2164 webrtc::DataChannelInit config;
2165 config.maxRetransmits = 0;
2166 config.maxRetransmitTime = 0;
2167
zhihuang9763d562016-08-05 11:14:50 -07002168 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 pc_->CreateDataChannel(label, &config);
2170 EXPECT_TRUE(channel == NULL);
2171}
2172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173// The test verifies that creating a SCTP data channel with an id already in use
2174// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002175TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 CreateSctpDataChannelWithInvalidIdShouldFail) {
2177 FakeConstraints constraints;
2178 constraints.SetAllowDtlsSctpDataChannels();
2179 CreatePeerConnection(&constraints);
2180
2181 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002182 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002184 config.id = 1;
2185 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 EXPECT_TRUE(channel != NULL);
2187 EXPECT_EQ(1, channel->id());
2188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 channel = pc_->CreateDataChannel("x", &config);
2190 EXPECT_TRUE(channel == NULL);
2191
2192 config.id = cricket::kMaxSctpSid;
2193 channel = pc_->CreateDataChannel("max", &config);
2194 EXPECT_TRUE(channel != NULL);
2195 EXPECT_EQ(config.id, channel->id());
2196
2197 config.id = cricket::kMaxSctpSid + 1;
2198 channel = pc_->CreateDataChannel("x", &config);
2199 EXPECT_TRUE(channel == NULL);
2200}
2201
deadbeefab9b2d12015-10-14 11:33:11 -07002202// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002203TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002204 FakeConstraints constraints;
2205 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2206 true);
2207 CreatePeerConnection(&constraints);
2208
2209 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002210 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002211 pc_->CreateDataChannel(label, nullptr);
2212 EXPECT_NE(channel, nullptr);
2213
zhihuang9763d562016-08-05 11:14:50 -07002214 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002215 pc_->CreateDataChannel(label, nullptr);
2216 EXPECT_NE(dup_channel, nullptr);
2217}
2218
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002219// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2220// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002221TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002222 FakeConstraints constraints;
2223 constraints.SetAllowRtpDataChannels();
2224 CreatePeerConnection(&constraints);
2225
zhihuang9763d562016-08-05 11:14:50 -07002226 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002227 pc_->CreateDataChannel("test1", NULL);
2228 EXPECT_TRUE(observer_.renegotiation_needed_);
2229 observer_.renegotiation_needed_ = false;
2230
zhihuang9763d562016-08-05 11:14:50 -07002231 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002232 pc_->CreateDataChannel("test2", NULL);
2233 EXPECT_TRUE(observer_.renegotiation_needed_);
2234}
2235
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002237TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 FakeConstraints constraints;
2239 constraints.SetAllowRtpDataChannels();
2240 CreatePeerConnection(&constraints);
2241
zhihuang9763d562016-08-05 11:14:50 -07002242 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002244 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 pc_->CreateDataChannel("test2", NULL);
2246 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002247 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002249 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 new MockDataChannelObserver(data2));
2251
2252 CreateOfferReceiveAnswer();
2253 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2254 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2255
2256 ReleasePeerConnection();
2257 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2258 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2259}
2260
Zhi Huang644fde42018-04-02 19:16:26 -07002261// This tests that RTP data channels can be rejected in an answer.
2262TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 FakeConstraints constraints;
2264 constraints.SetAllowRtpDataChannels();
2265 CreatePeerConnection(&constraints);
2266
zhihuang9763d562016-08-05 11:14:50 -07002267 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 pc_->CreateDataChannel("offer_channel", NULL));
2269
2270 CreateOfferAsLocalDescription();
2271
2272 // Create an answer where the m-line for data channels are rejected.
2273 std::string sdp;
2274 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002275 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002276 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002277 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002279 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 data_info->rejected = true;
2281
Steve Antondb45ca82017-09-11 18:27:34 -07002282 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2284}
2285
Zhi Huang644fde42018-04-02 19:16:26 -07002286#ifdef HAVE_SCTP
2287// This tests that SCTP data channels can be rejected in an answer.
2288TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2289#else
2290TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2291#endif
2292{
2293 FakeConstraints constraints;
2294 CreatePeerConnection(&constraints);
2295
2296 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2297 pc_->CreateDataChannel("offer_channel", NULL));
2298
2299 CreateOfferAsLocalDescription();
2300
2301 // Create an answer where the m-line for data channels are rejected.
2302 std::string sdp;
2303 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2304 std::unique_ptr<SessionDescriptionInterface> answer(
2305 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2306 ASSERT_TRUE(answer);
2307 cricket::ContentInfo* data_info =
2308 cricket::GetFirstDataContent(answer->description());
2309 data_info->rejected = true;
2310
2311 DoSetRemoteDescription(std::move(answer));
2312 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2313}
2314
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315// Test that we can create a session description from an SDP string from
2316// FireFox, use it as a remote session description, generate an answer and use
2317// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002318TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 FakeConstraints constraints;
2320 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2321 true);
2322 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002323 AddAudioTrack("audio_label");
2324 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002325 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002326 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002327 webrtc::kFireFoxSdpOffer, nullptr));
2328 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 CreateAnswerAsLocalDescription();
2330 ASSERT_TRUE(pc_->local_description() != NULL);
2331 ASSERT_TRUE(pc_->remote_description() != NULL);
2332
2333 const cricket::ContentInfo* content =
2334 cricket::GetFirstAudioContent(pc_->local_description()->description());
2335 ASSERT_TRUE(content != NULL);
2336 EXPECT_FALSE(content->rejected);
2337
2338 content =
2339 cricket::GetFirstVideoContent(pc_->local_description()->description());
2340 ASSERT_TRUE(content != NULL);
2341 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002342#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 content =
2344 cricket::GetFirstDataContent(pc_->local_description()->description());
2345 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002346 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002347#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348}
2349
zhihuangb19012e2017-09-19 13:47:59 -07002350// Test that fallback from DTLS to SDES is not supported.
2351// The fallback was previously supported but was removed to simplify the code
2352// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002353TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
deadbeef8662f942017-01-20 21:20:51 -08002354 FakeConstraints constraints;
2355 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2356 true);
2357 CreatePeerConnection(&constraints);
2358 // Wait for fake certificate to be generated. Previously, this is what caused
2359 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002360 AddAudioTrack("audio_label");
2361 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002362 ASSERT_NE(nullptr, fake_certificate_generator_);
2363 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2364 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002365 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002366 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2367 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002368 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002369}
2370
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371// Test that we can create an audio only offer and receive an answer with a
2372// limited set of audio codecs and receive an updated offer with more audio
2373// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002374TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002375 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002376 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 CreateOfferAsLocalDescription();
2378
Steve Anton36da6ff2018-02-16 16:04:20 -08002379 const char* answer_sdp =
2380 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2381 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002382 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002383 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002384 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385
Steve Anton36da6ff2018-02-16 16:04:20 -08002386 const char* reoffer_sdp =
2387 (sdp_semantics_ == SdpSemantics::kPlanB
2388 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2389 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002390 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002391 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002392 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 CreateAnswerAsLocalDescription();
2394}
2395
deadbeefc80741f2015-10-22 13:14:45 -07002396// Test that if we're receiving (but not sending) a track, subsequent offers
2397// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002398TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002399 FakeConstraints constraints;
2400 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2401 true);
2402 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002403 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002404 CreateAnswerAsLocalDescription();
2405
2406 // At this point we should be receiving stream 1, but not sending anything.
2407 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002408 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002409 DoCreateOffer(&offer, nullptr);
2410
2411 const cricket::ContentInfo* video_content =
2412 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002413 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2414 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002415
2416 const cricket::ContentInfo* audio_content =
2417 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002418 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2419 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002420}
2421
2422// Test that if we're receiving (but not sending) a track, and the
2423// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2424// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002425TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002426 FakeConstraints constraints;
2427 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2428 true);
2429 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002430 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002431 CreateAnswerAsLocalDescription();
2432
2433 // At this point we should be receiving stream 1, but not sending anything.
2434 // A new offer would be recvonly, but we'll set the "no receive" constraints
2435 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002436 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002437 FakeConstraints offer_constraints;
2438 offer_constraints.AddMandatory(
2439 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2440 offer_constraints.AddMandatory(
2441 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2442 DoCreateOffer(&offer, &offer_constraints);
2443
2444 const cricket::ContentInfo* video_content =
2445 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002446 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2447 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002448
2449 const cricket::ContentInfo* audio_content =
2450 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002451 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2452 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002453}
2454
deadbeef653b8e02015-11-11 12:55:10 -08002455// Test that we can use SetConfiguration to change the ICE servers of the
2456// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002457TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002458 CreatePeerConnection();
2459
Steve Anton36da6ff2018-02-16 16:04:20 -08002460 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002461 PeerConnectionInterface::IceServer server;
2462 server.uri = "stun:test_hostname";
2463 config.servers.push_back(server);
2464 EXPECT_TRUE(pc_->SetConfiguration(config));
2465
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002466 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2467 EXPECT_EQ("test_hostname",
2468 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002469}
2470
Steve Anton36da6ff2018-02-16 16:04:20 -08002471TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002472 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002473 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002474 config.type = PeerConnectionInterface::kRelay;
2475 EXPECT_TRUE(pc_->SetConfiguration(config));
2476 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2477}
2478
Steve Anton36da6ff2018-02-16 16:04:20 -08002479TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002480 PeerConnectionInterface::RTCConfiguration config;
2481 config.prune_turn_ports = false;
2482 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002483 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002484 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2485
2486 config.prune_turn_ports = true;
2487 EXPECT_TRUE(pc_->SetConfiguration(config));
2488 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2489}
2490
skvladd1f5fda2017-02-03 16:54:05 -08002491// Test that the ice check interval can be changed. This does not verify that
2492// the setting makes it all the way to P2PTransportChannel, as that would
2493// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002494TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002495 PeerConnectionInterface::RTCConfiguration config;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002496 config.ice_check_min_interval = rtc::nullopt;
skvladd1f5fda2017-02-03 16:54:05 -08002497 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002498 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002499 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002500 EXPECT_TRUE(pc_->SetConfiguration(config));
2501 PeerConnectionInterface::RTCConfiguration new_config =
2502 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002503 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002504}
2505
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002506// Test that when SetConfiguration changes both the pool size and other
2507// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002508TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002509 SetConfigurationCreatesPooledSessionCorrectly) {
2510 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002511 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002512 config.ice_candidate_pool_size = 1;
2513 PeerConnectionInterface::IceServer server;
2514 server.uri = kStunAddressOnly;
2515 config.servers.push_back(server);
2516 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002517 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002518
2519 const cricket::FakePortAllocatorSession* session =
2520 static_cast<const cricket::FakePortAllocatorSession*>(
2521 port_allocator_->GetPooledSession());
2522 ASSERT_NE(nullptr, session);
2523 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002524}
2525
deadbeef293e9262017-01-11 12:28:30 -08002526// Test that after SetLocalDescription, changing the pool size is not allowed,
2527// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002528TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002529 CantChangePoolSizeAfterSetLocalDescription) {
2530 CreatePeerConnection();
2531 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002532 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002533 config.ice_candidate_pool_size = 1;
2534 EXPECT_TRUE(pc_->SetConfiguration(config));
2535
2536 // Set remote offer; can still change pool size at this point.
2537 CreateOfferAsRemoteDescription();
2538 config.ice_candidate_pool_size = 2;
2539 EXPECT_TRUE(pc_->SetConfiguration(config));
2540
2541 // Set local answer; now it's too late.
2542 CreateAnswerAsLocalDescription();
2543 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002544 RTCError error;
2545 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2546 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2547}
2548
deadbeef42a42632017-03-10 15:18:00 -08002549// Test that after setting an answer, extra pooled sessions are discarded. The
2550// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002551TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002552 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2553 CreatePeerConnection();
2554
2555 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002556 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002557 config.ice_candidate_pool_size = 4;
2558 EXPECT_TRUE(pc_->SetConfiguration(config));
2559
2560 // Do offer/answer.
2561 CreateOfferAsRemoteDescription();
2562 CreateAnswerAsLocalDescription();
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
2570// After Close is called, pooled candidates should be discarded so as to not
2571// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002572TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002573 CreatePeerConnection();
2574
Steve Anton36da6ff2018-02-16 16:04:20 -08002575 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002576 config.ice_candidate_pool_size = 3;
2577 EXPECT_TRUE(pc_->SetConfiguration(config));
2578 pc_->Close();
2579
2580 // Expect no pooled sessions to be left.
2581 const cricket::PortAllocatorSession* session =
2582 port_allocator_->GetPooledSession();
2583 EXPECT_EQ(nullptr, session);
2584}
2585
deadbeef293e9262017-01-11 12:28:30 -08002586// Test that SetConfiguration returns an invalid modification error if
2587// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002588TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002589 SetConfigurationReturnsInvalidModificationError) {
2590 PeerConnectionInterface::RTCConfiguration config;
2591 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2592 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2593 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2594 CreatePeerConnection(config, nullptr);
2595
Steve Anton36da6ff2018-02-16 16:04:20 -08002596 PeerConnectionInterface::RTCConfiguration modified_config =
2597 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002598 modified_config.bundle_policy =
2599 PeerConnectionInterface::kBundlePolicyMaxBundle;
2600 RTCError error;
2601 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2602 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2603
Steve Anton36da6ff2018-02-16 16:04:20 -08002604 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002605 modified_config.rtcp_mux_policy =
2606 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2607 error.set_type(RTCErrorType::NONE);
2608 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2609 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2610
Steve Anton36da6ff2018-02-16 16:04:20 -08002611 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002612 modified_config.continual_gathering_policy =
2613 PeerConnectionInterface::GATHER_CONTINUALLY;
2614 error.set_type(RTCErrorType::NONE);
2615 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2616 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2617}
2618
2619// Test that SetConfiguration returns a range error if the candidate pool size
2620// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002621TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002622 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2623 PeerConnectionInterface::RTCConfiguration config;
2624 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002625 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002626
2627 config.ice_candidate_pool_size = -1;
2628 RTCError error;
2629 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2630 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2631
2632 config.ice_candidate_pool_size = INT_MAX;
2633 error.set_type(RTCErrorType::NONE);
2634 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2635 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2636}
2637
2638// Test that SetConfiguration returns a syntax error if parsing an ICE server
2639// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002640TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002641 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
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 = "stunn:www.example.com";
2648 config.servers.push_back(bad_server);
2649 RTCError error;
2650 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2651 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2652}
2653
2654// Test that SetConfiguration returns an invalid parameter error if a TURN
2655// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002656TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002657 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2658 PeerConnectionInterface::RTCConfiguration config;
2659 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002660 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002661
2662 PeerConnectionInterface::IceServer bad_server;
2663 bad_server.uri = "turn:www.example.com";
2664 // Missing password.
2665 bad_server.username = "foo";
2666 config.servers.push_back(bad_server);
2667 RTCError error;
2668 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2669 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002670}
2671
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672// Test that PeerConnection::Close changes the states to closed and all remote
2673// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002674TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675 // Initialize a PeerConnection and negotiate local and remote session
2676 // description.
2677 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002678
2679 // With Plan B, verify the stream count. The analog with Unified Plan is the
2680 // RtpTransceiver count.
2681 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2682 ASSERT_EQ(1u, pc_->local_streams()->count());
2683 ASSERT_EQ(1u, pc_->remote_streams()->count());
2684 } else {
2685 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2686 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687
2688 pc_->Close();
2689
2690 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2691 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2692 pc_->ice_connection_state());
2693 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2694 pc_->ice_gathering_state());
2695
Steve Anton36da6ff2018-02-16 16:04:20 -08002696 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2697 EXPECT_EQ(1u, pc_->local_streams()->count());
2698 EXPECT_EQ(1u, pc_->remote_streams()->count());
2699 } else {
2700 // Verify that the RtpTransceivers are still present but all stopped.
2701 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2702 for (auto transceiver : pc_->GetTransceivers()) {
2703 EXPECT_TRUE(transceiver->stopped());
2704 }
2705 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706
Steve Anton36da6ff2018-02-16 16:04:20 -08002707 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2708 ASSERT_TRUE(audio_receiver);
2709 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2710 ASSERT_TRUE(video_receiver);
2711
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002712 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002713 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002714 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002715 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002716 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717}
2718
2719// Test that PeerConnection methods fails gracefully after
2720// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002721// Don't run under Unified Plan since the stream API is not available.
2722TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002723 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002724 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 CreateOfferAsRemoteDescription();
2726 CreateAnswerAsLocalDescription();
2727
2728 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002729 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730 pc_->local_streams()->at(0);
2731
2732 pc_->Close();
2733
2734 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002735 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736
2737 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002738 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002740 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002741
2742 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2743
2744 EXPECT_TRUE(pc_->local_description() != NULL);
2745 EXPECT_TRUE(pc_->remote_description() != NULL);
2746
kwibergd1fe2812016-04-27 06:47:29 -07002747 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002748 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002749 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002750 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751
2752 std::string sdp;
2753 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002754 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002755 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002756 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757
2758 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002759 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002760 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002761 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002762}
2763
2764// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002765TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 InitiateCall();
2767 pc_->Close();
2768 DoGetStats(NULL);
2769}
deadbeefab9b2d12015-10-14 11:33:11 -07002770
2771// NOTE: The series of tests below come from what used to be
2772// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2773// setting a remote or local description has the expected effects.
2774
2775// This test verifies that the remote MediaStreams corresponding to a received
2776// SDP string is created. In this test the two separate MediaStreams are
2777// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002778TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
deadbeefab9b2d12015-10-14 11:33:11 -07002779 FakeConstraints constraints;
2780 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2781 true);
2782 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002783 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002784
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002785 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002786 EXPECT_TRUE(
2787 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2788 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2789 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2790
2791 // Create a session description based on another SDP with another
2792 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002793 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002794
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002795 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002796 EXPECT_TRUE(
2797 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2798}
2799
2800// This test verifies that when remote tracks are added/removed from SDP, the
2801// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002802// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2803// specific behavior.
2804TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002805 AddRemoveTrackFromExistingRemoteMediaStream) {
2806 FakeConstraints constraints;
2807 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2808 true);
2809 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002810 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002811 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002812 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002813 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2814 reference_collection_));
2815
2816 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002817 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002818 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002819 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002820 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2821 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002822 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002823 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2824 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002825 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002826 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2827 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002828
2829 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002830 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002831 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002832 MockTrackObserver audio_track_observer(audio_track2);
2833 MockTrackObserver video_track_observer(video_track2);
2834
2835 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2836 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002837 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002838 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2839 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002840 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002841 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002842 audio_track2->state(), kTimeout);
2843 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2844 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002845}
2846
2847// This tests that remote tracks are ended if a local session description is set
2848// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002849TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002850 FakeConstraints constraints;
2851 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2852 true);
2853 CreatePeerConnection(&constraints);
2854 // First create and set a remote offer, then reject its video content in our
2855 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002856 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2857 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2858 ASSERT_TRUE(audio_receiver);
2859 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2860 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002861
Steve Anton36da6ff2018-02-16 16:04:20 -08002862 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2863 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002864 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002865 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2866 video_receiver->track();
2867 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002868
kwibergd1fe2812016-04-27 06:47:29 -07002869 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002870 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002871 cricket::ContentInfo* video_info =
2872 local_answer->description()->GetContentByName("video");
2873 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002874 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002875 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2876 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002877
2878 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002880 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002881 video_info = local_offer->description()->GetContentByName("video");
2882 ASSERT_TRUE(video_info != nullptr);
2883 video_info->rejected = true;
2884 cricket::ContentInfo* audio_info =
2885 local_offer->description()->GetContentByName("audio");
2886 ASSERT_TRUE(audio_info != nullptr);
2887 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002888 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002889 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002890 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2891 kTimeout);
2892 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2893 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002894}
2895
2896// This tests that we won't crash if the remote track has been removed outside
2897// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002898// Don't run under Unified Plan since the stream API is not available.
2899TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002900 FakeConstraints constraints;
2901 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2902 true);
2903 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002904 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002905 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2906 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2907 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2908
kwibergd1fe2812016-04-27 06:47:29 -07002909 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002910 webrtc::CreateSessionDescription(SdpType::kAnswer,
2911 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002912 cricket::ContentInfo* video_info =
2913 local_answer->description()->GetContentByName("video");
2914 video_info->rejected = true;
2915 cricket::ContentInfo* audio_info =
2916 local_answer->description()->GetContentByName("audio");
2917 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002918 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002919
2920 // No crash is a pass.
2921}
2922
deadbeef5e97fb52015-10-15 12:49:08 -07002923// This tests that if a recvonly remote description is set, no remote streams
2924// will be created, even if the description contains SSRCs/MSIDs.
2925// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002926TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
deadbeef5e97fb52015-10-15 12:49:08 -07002927 FakeConstraints constraints;
2928 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2929 true);
2930 CreatePeerConnection(&constraints);
2931
Steve Anton36da6ff2018-02-16 16:04:20 -08002932 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002933 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2934 strlen(kRecvonly), &recvonly_offer);
2935 CreateAndSetRemoteOffer(recvonly_offer);
2936
2937 EXPECT_EQ(0u, observer_.remote_streams()->count());
2938}
2939
deadbeefab9b2d12015-10-14 11:33:11 -07002940// This tests that a default MediaStream is created if a remote session
2941// description doesn't contain any streams and no MSID support.
2942// It also tests that the default stream is updated if a video m-line is added
2943// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002944// Don't run under Unified Plan since this behavior is Plan B specific.
2945TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002946 FakeConstraints constraints;
2947 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2948 true);
2949 CreatePeerConnection(&constraints);
2950 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2951
2952 ASSERT_EQ(1u, observer_.remote_streams()->count());
2953 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2954
2955 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2956 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002957 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002958
2959 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2960 ASSERT_EQ(1u, observer_.remote_streams()->count());
2961 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2962 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002963 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2964 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002965 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2966 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002967 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2968 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002969}
2970
2971// This tests that a default MediaStream is created if a remote session
2972// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002973// Don't run under Unified Plan since this behavior is Plan B specific.
2974TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002975 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002976 FakeConstraints constraints;
2977 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2978 true);
2979 CreatePeerConnection(&constraints);
2980 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2981
2982 ASSERT_EQ(1u, observer_.remote_streams()->count());
2983 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2984
2985 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2986 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002987 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002988}
2989
2990// This tests that it won't crash when PeerConnection tries to remove
2991// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002992// Don't run under Unified Plan since this behavior is Plan B specific.
2993TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002994 FakeConstraints constraints;
2995 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2996 true);
2997 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002998 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002999 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3000 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
3001 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
3002
3003 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3004
3005 // No crash is a pass.
3006}
3007
3008// This tests that a default MediaStream is created if the remote session
3009// description doesn't contain any streams and don't contain an indication if
3010// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08003011// Don't run under Unified Plan since this behavior is Plan B specific.
3012TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003013 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003014 FakeConstraints constraints;
3015 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3016 true);
3017 CreatePeerConnection(&constraints);
3018 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3019
3020 ASSERT_EQ(1u, observer_.remote_streams()->count());
3021 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3022 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
3023 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3024}
3025
3026// This tests that a default MediaStream is not created if the remote session
3027// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003028// Don't run under Unified Plan since this behavior is Plan B specific.
3029TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003030 FakeConstraints constraints;
3031 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3032 true);
3033 CreatePeerConnection(&constraints);
3034 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3035 EXPECT_EQ(0u, observer_.remote_streams()->count());
3036}
3037
deadbeefbda7e0b2015-12-08 17:13:40 -08003038// This tests that when setting a new description, the old default tracks are
3039// not destroyed and recreated.
3040// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003041// Don't run under Unified Plan since this behavior is Plan B specific.
3042TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003043 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08003044 FakeConstraints constraints;
3045 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3046 true);
3047 CreatePeerConnection(&constraints);
3048 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3049
3050 ASSERT_EQ(1u, observer_.remote_streams()->count());
3051 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3052 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3053
3054 // Set the track to "disabled", then set a new description and ensure the
3055 // track is still disabled, which ensures it hasn't been recreated.
3056 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3057 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3058 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3059 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3060}
3061
deadbeefab9b2d12015-10-14 11:33:11 -07003062// This tests that a default MediaStream is not created if a remote session
3063// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003064// Don't run under Unified Plan since this behavior is Plan B specific.
3065TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
deadbeefab9b2d12015-10-14 11:33:11 -07003066 FakeConstraints constraints;
3067 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3068 true);
3069 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003070 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003071 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003072 EXPECT_TRUE(
3073 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3074
3075 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3076 EXPECT_EQ(0u, observer_.remote_streams()->count());
3077}
3078
Seth Hampson5897a6e2018-04-03 11:16:33 -07003079// This tests that a default MediaStream is created if a remote SDP comes from
3080// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3081TEST_F(PeerConnectionInterfaceTestPlanB,
3082 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
3083 FakeConstraints constraints;
3084 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3085 true);
3086 CreatePeerConnection(&constraints);
3087 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3088 // Add a=msid lines to simulate a Unified Plan endpoint that only
3089 // signals stream IDs with a=msid lines.
3090 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3091
3092 CreateAndSetRemoteOffer(sdp_string);
3093
3094 ASSERT_EQ(1u, observer_.remote_streams()->count());
3095 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3096 EXPECT_EQ("default", remote_stream->id());
3097 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3098}
3099
Seth Hampson5b4f0752018-04-02 16:31:36 -07003100// This tests that when a Plan B endpoint receives an SDP that signals no media
3101// stream IDs indicated by the special character "-" in the a=msid line, that
3102// a default stream ID will be used for the MediaStream ID. This can occur
3103// when a Unified Plan endpoint signals no media stream IDs, but signals both
3104// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3105TEST_F(PeerConnectionInterfaceTestPlanB,
3106 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
3107 FakeConstraints constraints;
3108 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3109 true);
3110 CreatePeerConnection(&constraints);
3111 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3112 // the sender's stream ID will be interpreted as no stream IDs.
3113 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3114 sdp_string.append("a=msid:- audiotrack0\n");
3115
3116 CreateAndSetRemoteOffer(sdp_string);
3117
3118 ASSERT_EQ(1u, observer_.remote_streams()->count());
3119 // Because SSRCs are signaled the track ID will be what was signaled in the
3120 // a=msid line.
3121 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3122 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3123 EXPECT_EQ("default", remote_stream->id());
3124 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3125}
3126
deadbeefab9b2d12015-10-14 11:33:11 -07003127// This tests that an RtpSender is created when the local description is set
3128// after adding a local stream.
3129// TODO(deadbeef): This test and the one below it need to be updated when
3130// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003131// Don't run under Unified Plan since this behavior is Plan B specific.
3132TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003133 FakeConstraints constraints;
3134 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3135 true);
3136 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003137
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003138 // Create an offer with 1 stream with 2 tracks of each type.
3139 rtc::scoped_refptr<StreamCollection> stream_collection =
3140 CreateStreamCollection(1, 2);
3141 pc_->AddStream(stream_collection->at(0));
3142 std::unique_ptr<SessionDescriptionInterface> offer;
3143 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003144 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003145
deadbeefab9b2d12015-10-14 11:33:11 -07003146 auto senders = pc_->GetSenders();
3147 EXPECT_EQ(4u, senders.size());
3148 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3149 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3150 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3151 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3152
3153 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003154 pc_->RemoveStream(stream_collection->at(0));
3155 stream_collection = CreateStreamCollection(1, 1);
3156 pc_->AddStream(stream_collection->at(0));
3157 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003158 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003159
deadbeefab9b2d12015-10-14 11:33:11 -07003160 senders = pc_->GetSenders();
3161 EXPECT_EQ(2u, senders.size());
3162 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3163 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3164 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3165 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3166}
3167
3168// This tests that an RtpSender is created when the local description is set
3169// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003170// Don't run under Unified Plan since this behavior is Plan B specific.
3171TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003172 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003173 FakeConstraints constraints;
3174 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3175 true);
3176 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003177
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003178 rtc::scoped_refptr<StreamCollection> stream_collection =
3179 CreateStreamCollection(1, 2);
3180 // Add a stream to create the offer, but remove it afterwards.
3181 pc_->AddStream(stream_collection->at(0));
3182 std::unique_ptr<SessionDescriptionInterface> offer;
3183 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3184 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003185
Steve Antondb45ca82017-09-11 18:27:34 -07003186 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003187 auto senders = pc_->GetSenders();
3188 EXPECT_EQ(0u, senders.size());
3189
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003190 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003191 senders = pc_->GetSenders();
3192 EXPECT_EQ(4u, senders.size());
3193 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3194 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3195 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3196 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3197}
3198
3199// This tests that the expected behavior occurs if the SSRC on a local track is
3200// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003201TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003202 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07003203 FakeConstraints constraints;
3204 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3205 true);
3206 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003207
Steve Anton36da6ff2018-02-16 16:04:20 -08003208 AddAudioTrack(kAudioTracks[0]);
3209 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003210 std::unique_ptr<SessionDescriptionInterface> offer;
3211 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3212 // Grab a copy of the offer before it gets passed into the PC.
Steve Antona3a92c22017-12-07 10:27:41 -08003213 auto modified_offer =
3214 rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003215 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
3216 offer->session_version());
Steve Antondb45ca82017-09-11 18:27:34 -07003217 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003218
deadbeefab9b2d12015-10-14 11:33:11 -07003219 auto senders = pc_->GetSenders();
3220 EXPECT_EQ(2u, senders.size());
3221 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3222 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3223
3224 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003225 cricket::MediaContentDescription* desc =
3226 cricket::GetFirstAudioContentDescription(modified_offer->description());
3227 ASSERT_TRUE(desc != NULL);
3228 for (StreamParams& stream : desc->mutable_streams()) {
3229 for (unsigned int& ssrc : stream.ssrcs) {
3230 ++ssrc;
3231 }
3232 }
deadbeefab9b2d12015-10-14 11:33:11 -07003233
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003234 desc =
3235 cricket::GetFirstVideoContentDescription(modified_offer->description());
3236 ASSERT_TRUE(desc != NULL);
3237 for (StreamParams& stream : desc->mutable_streams()) {
3238 for (unsigned int& ssrc : stream.ssrcs) {
3239 ++ssrc;
3240 }
3241 }
3242
Steve Antondb45ca82017-09-11 18:27:34 -07003243 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003244 senders = pc_->GetSenders();
3245 EXPECT_EQ(2u, senders.size());
3246 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3247 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3248 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3249 // changed.
3250}
3251
3252// This tests that the expected behavior occurs if a new session description is
3253// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003254// Don't run under Unified Plan since the stream API is not available.
3255TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003256 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003257 FakeConstraints constraints;
3258 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3259 true);
3260 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003261
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003262 rtc::scoped_refptr<StreamCollection> stream_collection =
3263 CreateStreamCollection(2, 1);
3264 pc_->AddStream(stream_collection->at(0));
3265 std::unique_ptr<SessionDescriptionInterface> offer;
3266 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003267 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003268
deadbeefab9b2d12015-10-14 11:33:11 -07003269 auto senders = pc_->GetSenders();
3270 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003271 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3272 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003273
3274 // Add a new MediaStream but with the same tracks as in the first stream.
3275 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3276 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003277 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3278 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003279 pc_->AddStream(stream_1);
3280
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003281 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003282 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003283
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003284 auto new_senders = pc_->GetSenders();
3285 // Should be the same senders as before, but with updated stream id.
3286 // Note that this behavior is subject to change in the future.
3287 // We may decide the PC should ignore existing tracks in AddStream.
3288 EXPECT_EQ(senders, new_senders);
3289 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3290 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003291}
3292
zhihuang81c3a032016-11-17 12:06:24 -08003293// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003294TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
zhihuang81c3a032016-11-17 12:06:24 -08003295 FakeConstraints constraints;
3296 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3297 true);
3298 CreatePeerConnection(&constraints);
3299 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3300 EXPECT_EQ(observer_.num_added_tracks_, 1);
3301 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3302
3303 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003304 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3305 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3306 EXPECT_EQ(observer_.num_added_tracks_, 2);
3307 } else {
3308 // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription
3309 // is called until the offer/answer exchange is complete. So in this case
3310 // OnAddTrack is fired twice for the first audio track plus the one time
3311 // for the video track.
3312 EXPECT_EQ(observer_.num_added_tracks_, 3);
3313 }
zhihuang81c3a032016-11-17 12:06:24 -08003314 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3315}
3316
deadbeefd1a38b52016-12-10 13:15:33 -08003317// Test that when SetConfiguration is called and the configuration is
3318// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003319TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003320 PeerConnectionInterface::RTCConfiguration config;
3321 config.type = PeerConnectionInterface::kRelay;
3322 // Need to pass default constraints to prevent disabling of DTLS...
3323 FakeConstraints default_constraints;
3324 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003325 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003326 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3327 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003328
3329 // Do initial offer/answer so there's something to restart.
3330 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003331 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003332
3333 // Grab the ufrags.
3334 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3335
3336 // Change ICE policy, which should trigger an ICE restart on the next offer.
3337 config.type = PeerConnectionInterface::kAll;
3338 EXPECT_TRUE(pc_->SetConfiguration(config));
3339 CreateOfferAsLocalDescription();
3340
3341 // Grab the new ufrags.
3342 std::vector<std::string> subsequent_ufrags =
3343 GetUfrags(pc_->local_description());
3344
3345 // Sanity check.
3346 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3347 // Check that each ufrag is different.
3348 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3349 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3350 }
3351}
3352
3353// Test that when SetConfiguration is called and the configuration *isn't*
3354// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003355TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003356 PeerConnectionInterface::RTCConfiguration config;
3357 config.type = PeerConnectionInterface::kRelay;
3358 // Need to pass default constraints to prevent disabling of DTLS...
3359 FakeConstraints default_constraints;
3360 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003361 config = pc_->GetConfiguration();
3362 AddAudioTrack(kAudioTracks[0]);
3363 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003364
3365 // Do initial offer/answer so there's something to restart.
3366 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003367 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003368
3369 // Grab the ufrags.
3370 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3371
3372 // Call SetConfiguration with a config identical to what the PC was
3373 // constructed with.
3374 EXPECT_TRUE(pc_->SetConfiguration(config));
3375 CreateOfferAsLocalDescription();
3376
3377 // Grab the new ufrags.
3378 std::vector<std::string> subsequent_ufrags =
3379 GetUfrags(pc_->local_description());
3380
3381 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3382}
3383
3384// Test for a weird corner case scenario:
3385// 1. Audio/video session established.
3386// 2. SetConfiguration changes ICE config; ICE restart needed.
3387// 3. ICE restart initiated by remote peer, but only for one m= section.
3388// 4. Next createOffer should initiate an ICE restart, but only for the other
3389// m= section; it would be pointless to do an ICE restart for the m= section
3390// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003391TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003392 PeerConnectionInterface::RTCConfiguration config;
3393 config.type = PeerConnectionInterface::kRelay;
3394 // Need to pass default constraints to prevent disabling of DTLS...
3395 FakeConstraints default_constraints;
3396 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003397 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003398 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3399 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003400
3401 // Do initial offer/answer so there's something to restart.
3402 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003403 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003404
3405 // Change ICE policy, which should set the "needs-ice-restart" flag.
3406 config.type = PeerConnectionInterface::kAll;
3407 EXPECT_TRUE(pc_->SetConfiguration(config));
3408
3409 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003410 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003411 webrtc::CreateSessionDescription(SdpType::kOffer,
3412 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003413 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003414 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3415 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003416 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003417 CreateAnswerAsLocalDescription();
3418
3419 // Grab the ufrags.
3420 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3421 ASSERT_EQ(2, initial_ufrags.size());
3422
3423 // Create offer and grab the new ufrags.
3424 CreateOfferAsLocalDescription();
3425 std::vector<std::string> subsequent_ufrags =
3426 GetUfrags(pc_->local_description());
3427 ASSERT_EQ(2, subsequent_ufrags.size());
3428
3429 // Ensure that only the ufrag for the second m= section changed.
3430 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3431 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3432}
3433
deadbeeffe4a8a42016-12-20 17:56:17 -08003434// Tests that the methods to return current/pending descriptions work as
3435// expected at different points in the offer/answer exchange. This test does
3436// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003437TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003438 // This disables DTLS so we can apply an answer to ourselves.
3439 CreatePeerConnection();
3440
3441 // Create initial local offer and get SDP (which will also be used as
3442 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003443 std::unique_ptr<SessionDescriptionInterface> local_offer;
3444 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003445 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003446 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003447
3448 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003449 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3450 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3451 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003452 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3453 EXPECT_EQ(nullptr, pc_->current_local_description());
3454 EXPECT_EQ(nullptr, pc_->current_remote_description());
3455
3456 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003457 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003458 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003459 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3460 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3461 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3462 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003463 EXPECT_EQ(nullptr, pc_->current_local_description());
3464 EXPECT_EQ(nullptr, pc_->current_remote_description());
3465
3466 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003467 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003468 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003469 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3470 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003471 EXPECT_EQ(nullptr, pc_->pending_local_description());
3472 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003473 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3474 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003475
3476 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003477 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003478 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003479 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3480 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3481 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003482 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003483 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3484 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003485
3486 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003487 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003488 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003489 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3490 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3491 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3492 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3493 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3494 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003495
3496 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003497 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003498 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003499 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3500 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003501 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3502 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003503 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3504 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003505}
3506
zhihuang77985012017-02-07 15:45:16 -08003507// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3508// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003509// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003510TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003511 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003512 CreatePeerConnection();
3513 // The RtcEventLog will be reset when the PeerConnection is closed.
3514 pc_->Close();
3515
Elad Alon9e6565b2017-10-11 16:04:13 +02003516 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3517 std::string filename = webrtc::test::OutputPath() +
3518 test_info->test_case_name() + test_info->name();
3519 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3520
3521 constexpr int64_t max_size_bytes = 1024;
3522
zhihuang77985012017-02-07 15:45:16 -08003523 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3524 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003525
3526 // Cleanup.
3527 rtc::ClosePlatformFile(file);
3528 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003529}
3530
Elad Alon99c3fe52017-10-13 16:29:40 +02003531// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3532// after the PeerConnection is closed.
3533// This version tests the StartRtcEventLog version that receives an object
3534// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003535TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003536 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3537 CreatePeerConnection();
3538 // The RtcEventLog will be reset when the PeerConnection is closed.
3539 pc_->Close();
3540
3541 rtc::PlatformFile file = 0;
3542 int64_t max_size_bytes = 1024;
3543 EXPECT_FALSE(pc_->StartRtcEventLog(
Bjorn Tereliusde939432017-11-20 17:38:14 +01003544 rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
3545 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003546 pc_->StopRtcEventLog();
3547}
3548
deadbeef30952b42017-04-21 02:41:29 -07003549// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003550TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003551 CreatePeerConnection();
3552
3553 // First, create an offer with audio/video.
3554 FakeConstraints constraints;
3555 constraints.SetMandatoryReceiveAudio(true);
3556 constraints.SetMandatoryReceiveVideo(true);
3557 std::unique_ptr<SessionDescriptionInterface> offer;
3558 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3559 cricket::SessionDescription* desc = offer->description();
3560 ASSERT_EQ(2u, desc->transport_infos().size());
3561 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3562 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3563
3564 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003565 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003566 std::unique_ptr<SessionDescriptionInterface> answer;
3567 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3568 desc = answer->description();
3569 ASSERT_EQ(2u, desc->transport_infos().size());
3570 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3571 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3572}
3573
deadbeef1dcb1642017-03-29 21:08:16 -07003574// Test that ICE renomination isn't offered if it's not enabled in the PC's
3575// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003576TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003577 PeerConnectionInterface::RTCConfiguration config;
3578 config.enable_ice_renomination = false;
3579 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003580 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003581
3582 std::unique_ptr<SessionDescriptionInterface> offer;
3583 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3584 cricket::SessionDescription* desc = offer->description();
3585 EXPECT_EQ(1u, desc->transport_infos().size());
3586 EXPECT_FALSE(
3587 desc->transport_infos()[0].description.GetIceParameters().renomination);
3588}
3589
3590// Test that the ICE renomination option is present in generated offers/answers
3591// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003592TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003593 PeerConnectionInterface::RTCConfiguration config;
3594 config.enable_ice_renomination = true;
3595 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003596 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003597
3598 std::unique_ptr<SessionDescriptionInterface> offer;
3599 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3600 cricket::SessionDescription* desc = offer->description();
3601 EXPECT_EQ(1u, desc->transport_infos().size());
3602 EXPECT_TRUE(
3603 desc->transport_infos()[0].description.GetIceParameters().renomination);
3604
3605 // Set the offer as a remote description, then create an answer and ensure it
3606 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003607 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003608 std::unique_ptr<SessionDescriptionInterface> answer;
3609 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3610 desc = answer->description();
3611 EXPECT_EQ(1u, desc->transport_infos().size());
3612 EXPECT_TRUE(
3613 desc->transport_infos()[0].description.GetIceParameters().renomination);
3614}
3615
3616// Test that if CreateOffer is called with the deprecated "offer to receive
3617// audio/video" constraints, they're processed and result in an offer with
3618// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003619TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003620 CreatePeerConnection();
3621
3622 FakeConstraints constraints;
3623 constraints.SetMandatoryReceiveAudio(true);
3624 constraints.SetMandatoryReceiveVideo(true);
3625 std::unique_ptr<SessionDescriptionInterface> offer;
3626 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3627
3628 cricket::SessionDescription* desc = offer->description();
3629 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3630 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3631 ASSERT_NE(nullptr, audio);
3632 ASSERT_NE(nullptr, video);
3633 EXPECT_FALSE(audio->rejected);
3634 EXPECT_FALSE(video->rejected);
3635}
3636
3637// Test that if CreateAnswer is called with the deprecated "offer to receive
3638// audio/video" constraints, they're processed and can be used to reject an
3639// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003640// Don't run under Unified Plan since this behavior is not supported.
3641TEST_F(PeerConnectionInterfaceTestPlanB,
3642 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003643 CreatePeerConnection();
3644
3645 // First, create an offer with audio/video and apply it as a remote
3646 // description.
3647 FakeConstraints constraints;
3648 constraints.SetMandatoryReceiveAudio(true);
3649 constraints.SetMandatoryReceiveVideo(true);
3650 std::unique_ptr<SessionDescriptionInterface> offer;
3651 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
Steve Antondb45ca82017-09-11 18:27:34 -07003652 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003653
3654 // Now create answer that rejects audio/video.
3655 constraints.SetMandatoryReceiveAudio(false);
3656 constraints.SetMandatoryReceiveVideo(false);
3657 std::unique_ptr<SessionDescriptionInterface> answer;
3658 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3659
3660 cricket::SessionDescription* desc = answer->description();
3661 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3662 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3663 ASSERT_NE(nullptr, audio);
3664 ASSERT_NE(nullptr, video);
3665 EXPECT_TRUE(audio->rejected);
3666 EXPECT_TRUE(video->rejected);
3667}
3668
deadbeef1dcb1642017-03-29 21:08:16 -07003669// Test that negotiation can succeed with a data channel only, and with the max
3670// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003671#ifdef HAVE_SCTP
3672TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3673#else
3674TEST_P(PeerConnectionInterfaceTest,
3675 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3676#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003677 PeerConnectionInterface::RTCConfiguration config;
3678 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3679 CreatePeerConnection(config, nullptr);
3680
3681 // First, create an offer with only a data channel and apply it as a remote
3682 // description.
3683 pc_->CreateDataChannel("test", nullptr);
3684 std::unique_ptr<SessionDescriptionInterface> offer;
3685 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003686 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003687
3688 // Create and set answer as well.
3689 std::unique_ptr<SessionDescriptionInterface> answer;
3690 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003691 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003692}
3693
Steve Anton36da6ff2018-02-16 16:04:20 -08003694TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003695 CreatePeerConnection();
3696 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003697 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003698 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3699}
3700
Steve Anton36da6ff2018-02-16 16:04:20 -08003701TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003702 CreatePeerConnection();
3703 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003704 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003705 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3706}
3707
Steve Anton36da6ff2018-02-16 16:04:20 -08003708TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003709 CreatePeerConnection();
3710 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003711 bitrate.min_bitrate_bps = 5;
3712 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003713 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3714}
3715
Steve Anton36da6ff2018-02-16 16:04:20 -08003716TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003717 CreatePeerConnection();
3718 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003719 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003720 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3721}
3722
Steve Anton36da6ff2018-02-16 16:04:20 -08003723TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003724 CreatePeerConnection();
3725 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003726 bitrate.current_bitrate_bps = 10;
3727 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003728 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3729}
3730
Steve Anton36da6ff2018-02-16 16:04:20 -08003731TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003732 CreatePeerConnection();
3733 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003734 bitrate.min_bitrate_bps = 10;
3735 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003736 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3737}
3738
Steve Anton36da6ff2018-02-16 16:04:20 -08003739TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003740 CreatePeerConnection();
3741 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003742 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003743 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3744}
3745
Steve Anton038834f2017-07-14 15:59:59 -07003746// ice_regather_interval_range requires WebRTC to be configured for continual
3747// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003748TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003749 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3750 PeerConnectionInterface::RTCConfiguration config;
3751 config.ice_regather_interval_range.emplace(1000, 2000);
3752 config.continual_gathering_policy =
3753 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3754 CreatePeerConnectionExpectFail(config);
3755}
3756
3757// Ensures that there is no error when ice_regather_interval_range is set with
3758// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003759TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003760 SetIceRegatherIntervalRangeWithContinualGathering) {
3761 PeerConnectionInterface::RTCConfiguration config;
3762 config.ice_regather_interval_range.emplace(1000, 2000);
3763 config.continual_gathering_policy =
3764 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3765 CreatePeerConnection(config, nullptr);
3766}
3767
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003768// The current bitrate from Call's BitrateConstraintsMask is currently clamped
3769// by Call's BitrateConstraints, which comes from the SDP or a default value.
3770// This test checks that a call to SetBitrate with a current bitrate that will
3771// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003772TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003773 CreatePeerConnection();
3774 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003775 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003776 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3777}
3778
zhihuang1c378ed2017-08-17 14:10:50 -07003779// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003780TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003781 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3782 RTCOfferAnswerOptions rtc_options;
3783
3784 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3785 // than kMaxOfferToReceiveMedia should be treated as invalid.
3786 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3787 CreatePeerConnection();
3788 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3789
3790 rtc_options.offer_to_receive_audio =
3791 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3792 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3793}
3794
Steve Anton36da6ff2018-02-16 16:04:20 -08003795TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003796 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3797 RTCOfferAnswerOptions rtc_options;
3798
3799 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3800 // than kMaxOfferToReceiveMedia should be treated as invalid.
3801 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3802 CreatePeerConnection();
3803 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3804
3805 rtc_options.offer_to_receive_video =
3806 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3807 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3808}
3809
3810// Test that the audio and video content will be added to an offer if both
3811// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003812TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003813 RTCOfferAnswerOptions rtc_options;
3814 rtc_options.offer_to_receive_audio = 1;
3815 rtc_options.offer_to_receive_video = 1;
3816
3817 std::unique_ptr<SessionDescriptionInterface> offer;
3818 CreatePeerConnection();
3819 offer = CreateOfferWithOptions(rtc_options);
3820 ASSERT_TRUE(offer);
3821 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3822 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3823}
3824
3825// Test that only audio content will be added to the offer if only
3826// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003827TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003828 RTCOfferAnswerOptions rtc_options;
3829 rtc_options.offer_to_receive_audio = 1;
3830 rtc_options.offer_to_receive_video = 0;
3831
3832 std::unique_ptr<SessionDescriptionInterface> offer;
3833 CreatePeerConnection();
3834 offer = CreateOfferWithOptions(rtc_options);
3835 ASSERT_TRUE(offer);
3836 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3837 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3838}
3839
3840// Test that only video content will be added if only |offer_to_receive_video|
3841// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003842TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003843 RTCOfferAnswerOptions rtc_options;
3844 rtc_options.offer_to_receive_audio = 0;
3845 rtc_options.offer_to_receive_video = 1;
3846
3847 std::unique_ptr<SessionDescriptionInterface> offer;
3848 CreatePeerConnection();
3849 offer = CreateOfferWithOptions(rtc_options);
3850 ASSERT_TRUE(offer);
3851 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3852 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3853}
3854
zhihuang1c378ed2017-08-17 14:10:50 -07003855// Test that no media content will be added to the offer if using default
3856// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003857TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003858 RTCOfferAnswerOptions rtc_options;
3859
3860 std::unique_ptr<SessionDescriptionInterface> offer;
3861 CreatePeerConnection();
3862 offer = CreateOfferWithOptions(rtc_options);
3863 ASSERT_TRUE(offer);
3864 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3865 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3866}
3867
3868// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3869// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003870TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3871 CreatePeerConnection();
3872
zhihuang1c378ed2017-08-17 14:10:50 -07003873 RTCOfferAnswerOptions rtc_options;
3874 rtc_options.ice_restart = false;
3875 rtc_options.offer_to_receive_audio = 1;
3876
3877 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003878 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003879 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3880 auto ufrag1 =
3881 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3882 auto pwd1 =
3883 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003884
3885 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3886 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003887 auto ufrag2 =
3888 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3889 auto pwd2 =
3890 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003891
3892 // |ice_restart| is true, the ufrag/pwd should change.
3893 rtc_options.ice_restart = true;
3894 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003895 auto ufrag3 =
3896 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3897 auto pwd3 =
3898 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003899
3900 EXPECT_EQ(ufrag1, ufrag2);
3901 EXPECT_EQ(pwd1, pwd2);
3902 EXPECT_NE(ufrag2, ufrag3);
3903 EXPECT_NE(pwd2, pwd3);
3904}
3905
3906// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3907// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003908TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003909 RTCOfferAnswerOptions rtc_options;
3910 rtc_options.offer_to_receive_audio = 1;
3911 rtc_options.offer_to_receive_video = 1;
3912
3913 std::unique_ptr<SessionDescriptionInterface> offer;
3914 CreatePeerConnection();
3915
3916 rtc_options.use_rtp_mux = true;
3917 offer = CreateOfferWithOptions(rtc_options);
3918 ASSERT_TRUE(offer);
3919 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3920 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3921 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3922
3923 rtc_options.use_rtp_mux = false;
3924 offer = CreateOfferWithOptions(rtc_options);
3925 ASSERT_TRUE(offer);
3926 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3927 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3928 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3929}
3930
zhihuang141aacb2017-08-29 13:23:53 -07003931// This test ensures OnRenegotiationNeeded is called when we add track with
3932// MediaStream -> AddTrack in the same way it is called when we add track with
3933// PeerConnection -> AddTrack.
3934// The test can be removed once addStream is rewritten in terms of addTrack
3935// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003936// Don't run under Unified Plan since the stream API is not available.
3937TEST_F(PeerConnectionInterfaceTestPlanB,
3938 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003939 CreatePeerConnectionWithoutDtls();
3940 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003941 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003942 pc_->AddStream(stream);
3943 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3944 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3945 rtc::scoped_refptr<VideoTrackInterface> video_track(
3946 pc_factory_->CreateVideoTrack(
3947 "video_track", pc_factory_->CreateVideoSource(
3948 std::unique_ptr<cricket::VideoCapturer>(
3949 new cricket::FakeVideoCapturer()))));
3950 stream->AddTrack(audio_track);
3951 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3952 observer_.renegotiation_needed_ = false;
3953
3954 stream->AddTrack(video_track);
3955 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3956 observer_.renegotiation_needed_ = false;
3957
3958 stream->RemoveTrack(audio_track);
3959 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3960 observer_.renegotiation_needed_ = false;
3961
3962 stream->RemoveTrack(video_track);
3963 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3964 observer_.renegotiation_needed_ = false;
3965}
3966
Zhi Huangb2d355e2017-10-26 17:26:37 -07003967// Tests that an error is returned if a description is applied that has fewer
3968// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003969TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003970 MediaSectionCountEnforcedForSubsequentOffer) {
3971 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003972 AddAudioTrack("audio_label");
3973 AddVideoTrack("video_label");
3974
Zhi Huangb2d355e2017-10-26 17:26:37 -07003975 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003976 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003977 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3978
3979 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003980 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003981 offer->description()->contents().pop_back();
3982 offer->description()->contents().pop_back();
3983 ASSERT_TRUE(offer->description()->contents().empty());
3984 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3985
3986 std::unique_ptr<SessionDescriptionInterface> answer;
3987 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3988 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3989
3990 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003991 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003992 offer->description()->contents().pop_back();
3993 offer->description()->contents().pop_back();
3994 ASSERT_TRUE(offer->description()->contents().empty());
3995 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3996}
3997
Steve Anton36da6ff2018-02-16 16:04:20 -08003998INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3999 PeerConnectionInterfaceTest,
4000 Values(SdpSemantics::kPlanB,
4001 SdpSemantics::kUnifiedPlan));
4002
nisse51542be2016-02-12 02:27:06 -08004003class PeerConnectionMediaConfigTest : public testing::Test {
4004 protected:
4005 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07004006 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08004007 pcf_->Initialize();
4008 }
nisseeaabdf62017-05-05 02:23:02 -07004009 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08004010 const PeerConnectionInterface::RTCConfiguration& config,
zhihuang1c378ed2017-08-17 14:10:50 -07004011 const MediaConstraintsInterface* constraints) {
zhihuang9763d562016-08-05 11:14:50 -07004012 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
4013 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08004014 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07004015 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08004016 }
4017
zhihuang9763d562016-08-05 11:14:50 -07004018 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08004019 MockPeerConnectionObserver observer_;
4020};
4021
4022// This test verifies the default behaviour with no constraints and a
4023// default RTCConfiguration.
4024TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4025 PeerConnectionInterface::RTCConfiguration config;
4026 FakeConstraints constraints;
4027
4028 const cricket::MediaConfig& media_config =
4029 TestCreatePeerConnection(config, &constraints);
4030
4031 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004032 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4033 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004034 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004035 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004036}
4037
4038// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07004039// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004040TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
4041 PeerConnectionInterface::RTCConfiguration config;
4042 FakeConstraints constraints;
4043
4044 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
4045 const cricket::MediaConfig& media_config =
4046 TestCreatePeerConnection(config, &constraints);
4047
4048 EXPECT_TRUE(media_config.enable_dscp);
4049}
4050
4051// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07004052// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004053TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
4054 PeerConnectionInterface::RTCConfiguration config;
4055 FakeConstraints constraints;
4056
4057 constraints.AddOptional(
4058 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
4059 const cricket::MediaConfig media_config =
4060 TestCreatePeerConnection(config, &constraints);
4061
Niels Möller1d7ecd22018-01-18 15:25:12 +01004062 EXPECT_FALSE(media_config.video.enable_cpu_adaptation);
nisse51542be2016-02-12 02:27:06 -08004063}
4064
Niels Möller1d7ecd22018-01-18 15:25:12 +01004065// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004066// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004067TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4068 PeerConnectionInterface::RTCConfiguration config;
4069 FakeConstraints constraints;
4070
Niels Möller71bdda02016-03-31 12:59:59 +02004071 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08004072 const cricket::MediaConfig& media_config =
4073 TestCreatePeerConnection(config, &constraints);
4074
Niels Möller1d7ecd22018-01-18 15:25:12 +01004075 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004076}
4077
Niels Möller6539f692018-01-18 08:58:50 +01004078// This test verifies that the experiment_cpu_load_estimator flag is
4079// propagated from RTCConfiguration to the PeerConnection.
4080TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4081 PeerConnectionInterface::RTCConfiguration config;
4082 FakeConstraints constraints;
4083
4084 config.set_experiment_cpu_load_estimator(true);
4085 const cricket::MediaConfig& media_config =
4086 TestCreatePeerConnection(config, &constraints);
4087
4088 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4089}
4090
nisse0db023a2016-03-01 04:29:59 -08004091// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07004092// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08004093TEST_F(PeerConnectionMediaConfigTest,
4094 TestSuspendBelowMinBitrateConstraintTrue) {
4095 PeerConnectionInterface::RTCConfiguration config;
4096 FakeConstraints constraints;
4097
4098 constraints.AddOptional(
4099 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4100 true);
4101 const cricket::MediaConfig media_config =
4102 TestCreatePeerConnection(config, &constraints);
4103
4104 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08004105}
4106
deadbeef293e9262017-01-11 12:28:30 -08004107// Tests a few random fields being different.
4108TEST(RTCConfigurationTest, ComparisonOperators) {
4109 PeerConnectionInterface::RTCConfiguration a;
4110 PeerConnectionInterface::RTCConfiguration b;
4111 EXPECT_EQ(a, b);
4112
4113 PeerConnectionInterface::RTCConfiguration c;
4114 c.servers.push_back(PeerConnectionInterface::IceServer());
4115 EXPECT_NE(a, c);
4116
4117 PeerConnectionInterface::RTCConfiguration d;
4118 d.type = PeerConnectionInterface::kRelay;
4119 EXPECT_NE(a, d);
4120
4121 PeerConnectionInterface::RTCConfiguration e;
4122 e.audio_jitter_buffer_max_packets = 5;
4123 EXPECT_NE(a, e);
4124
4125 PeerConnectionInterface::RTCConfiguration f;
4126 f.ice_connection_receiving_timeout = 1337;
4127 EXPECT_NE(a, f);
4128
4129 PeerConnectionInterface::RTCConfiguration g;
4130 g.disable_ipv6 = true;
4131 EXPECT_NE(a, g);
4132
4133 PeerConnectionInterface::RTCConfiguration h(
4134 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4135 EXPECT_NE(a, h);
4136}