blob: a974316cfa490a8c24a849586333b15f616f59f8 [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"
Anders Carlsson67537952018-05-03 11:28:29 +020025#include "api/video_codecs/builtin_video_decoder_factory.h"
26#include "api/video_codecs/builtin_video_encoder_factory.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020027#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "media/base/fakevideocapturer.h"
29#include "media/engine/webrtcmediaengine.h"
30#include "media/sctp/sctptransportinternal.h"
31#include "modules/audio_processing/include/audio_processing.h"
32#include "p2p/base/fakeportallocator.h"
33#include "pc/audiotrack.h"
34#include "pc/mediasession.h"
35#include "pc/mediastream.h"
36#include "pc/peerconnection.h"
Steve Anton57858b32018-02-15 15:19:50 -080037#include "pc/rtpsender.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "pc/streamcollection.h"
39#include "pc/test/fakeaudiocapturemodule.h"
40#include "pc/test/fakertccertificategenerator.h"
41#include "pc/test/fakevideotracksource.h"
42#include "pc/test/mockpeerconnectionobservers.h"
43#include "pc/test/testsdpstrings.h"
44#include "pc/videocapturertracksource.h"
45#include "pc/videotrack.h"
46#include "rtc_base/gunit.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020047#include "rtc_base/ptr_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "rtc_base/stringutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#include "rtc_base/virtualsocketserver.h"
50#include "test/gmock.h"
Elad Alon9e6565b2017-10-11 16:04:13 +020051#include "test/testsupport/fileutils.h"
kwibergac9f8762016-09-30 22:29:43 -070052
53#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#include "pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070055#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
Seth Hampson845e8782018-03-02 11:34:10 -080057static const char kStreamId1[] = "local_stream_1";
58static const char kStreamId2[] = "local_stream_2";
59static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060static const int kDefaultStunPort = 3478;
61static const char kStunAddressOnly[] = "stun:address";
62static const char kStunInvalidPort[] = "stun:address:-1";
63static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
64static const char kStunAddressPortAndMore2[] = "stun:address:port more";
65static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
66static const char kTurnUsername[] = "user";
67static const char kTurnPassword[] = "password";
68static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020069static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070
deadbeefab9b2d12015-10-14 11:33:11 -070071static const char kStreams[][8] = {"stream1", "stream2"};
72static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
73static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
74
deadbeef5e97fb52015-10-15 12:49:08 -070075static const char kRecvonly[] = "recvonly";
76static const char kSendrecv[] = "sendrecv";
77
deadbeefab9b2d12015-10-14 11:33:11 -070078// Reference SDP with a MediaStream with label "stream1" and audio track with
79// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -080080static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -070081 "v=0\r\n"
82 "o=- 0 0 IN IP4 127.0.0.1\r\n"
83 "s=-\r\n"
84 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080085 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070086 "a=ice-ufrag:e5785931\r\n"
87 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
88 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
89 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070090 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070091 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080092 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070093 "a=rtpmap:103 ISAC/16000\r\n"
94 "a=ssrc:1 cname:stream1\r\n"
95 "a=ssrc:1 mslabel:stream1\r\n"
96 "a=ssrc:1 label:audiotrack0\r\n"
97 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080098 "a=ice-ufrag:e5785931\r\n"
99 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
100 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
101 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700102 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700103 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800104 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700105 "a=rtpmap:120 VP8/90000\r\n"
106 "a=ssrc:2 cname:stream1\r\n"
107 "a=ssrc:2 mslabel:stream1\r\n"
108 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800109// Same string as above but with the MID changed to the Unified Plan default.
110// This is needed so that this SDP can be used as an answer for a Unified Plan
111// offer.
112static const char kSdpStringWithStream1UnifiedPlan[] =
113 "v=0\r\n"
114 "o=- 0 0 IN IP4 127.0.0.1\r\n"
115 "s=-\r\n"
116 "t=0 0\r\n"
117 "m=audio 1 RTP/AVPF 103\r\n"
118 "a=ice-ufrag:e5785931\r\n"
119 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
120 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
121 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
122 "a=mid:0\r\n"
123 "a=sendrecv\r\n"
124 "a=rtcp-mux\r\n"
125 "a=rtpmap:103 ISAC/16000\r\n"
126 "a=ssrc:1 cname:stream1\r\n"
127 "a=ssrc:1 mslabel:stream1\r\n"
128 "a=ssrc:1 label:audiotrack0\r\n"
129 "m=video 1 RTP/AVPF 120\r\n"
130 "a=ice-ufrag:e5785931\r\n"
131 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
132 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
133 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
134 "a=mid:1\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=rtpmap:120 VP8/90000\r\n"
138 "a=ssrc:2 cname:stream1\r\n"
139 "a=ssrc:2 mslabel:stream1\r\n"
140 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700141
zhihuang81c3a032016-11-17 12:06:24 -0800142// Reference SDP with a MediaStream with label "stream1" and audio track with
143// id "audio_1";
144static const char kSdpStringWithStream1AudioTrackOnly[] =
145 "v=0\r\n"
146 "o=- 0 0 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800149 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800150 "a=ice-ufrag:e5785931\r\n"
151 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
152 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
153 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800154 "a=mid:audio\r\n"
155 "a=sendrecv\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
157 "a=ssrc:1 cname:stream1\r\n"
158 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800159 "a=ssrc:1 label:audiotrack0\r\n"
160 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800161
deadbeefab9b2d12015-10-14 11:33:11 -0700162// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
163// MediaStreams have one audio track and one video track.
164// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800165static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700166 "v=0\r\n"
167 "o=- 0 0 IN IP4 127.0.0.1\r\n"
168 "s=-\r\n"
169 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800170 "a=msid-semantic: WMS stream1 stream2\r\n"
171 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700172 "a=ice-ufrag:e5785931\r\n"
173 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
174 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
175 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700176 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700177 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800178 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700179 "a=rtpmap:103 ISAC/16000\r\n"
180 "a=ssrc:1 cname:stream1\r\n"
181 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
182 "a=ssrc:3 cname:stream2\r\n"
183 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
184 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800185 "a=ice-ufrag:e5785931\r\n"
186 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
187 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
188 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700189 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700190 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800191 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700192 "a=rtpmap:120 VP8/0\r\n"
193 "a=ssrc:2 cname:stream1\r\n"
194 "a=ssrc:2 msid:stream1 videotrack0\r\n"
195 "a=ssrc:4 cname:stream2\r\n"
196 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800197static const char kSdpStringWithStream1And2UnifiedPlan[] =
198 "v=0\r\n"
199 "o=- 0 0 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
202 "a=msid-semantic: WMS stream1 stream2\r\n"
203 "m=audio 1 RTP/AVPF 103\r\n"
204 "a=ice-ufrag:e5785931\r\n"
205 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
206 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
207 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
208 "a=mid:0\r\n"
209 "a=sendrecv\r\n"
210 "a=rtcp-mux\r\n"
211 "a=rtpmap:103 ISAC/16000\r\n"
212 "a=ssrc:1 cname:stream1\r\n"
213 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
214 "m=video 1 RTP/AVPF 120\r\n"
215 "a=ice-ufrag:e5785931\r\n"
216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
219 "a=mid:1\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=rtpmap:120 VP8/0\r\n"
223 "a=ssrc:2 cname:stream1\r\n"
224 "a=ssrc:2 msid:stream1 videotrack0\r\n"
225 "m=audio 1 RTP/AVPF 103\r\n"
226 "a=ice-ufrag:e5785931\r\n"
227 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
228 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
229 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
230 "a=mid:2\r\n"
231 "a=sendrecv\r\n"
232 "a=rtcp-mux\r\n"
233 "a=rtpmap:103 ISAC/16000\r\n"
234 "a=ssrc:3 cname:stream2\r\n"
235 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
236 "m=video 1 RTP/AVPF 120\r\n"
237 "a=ice-ufrag:e5785931\r\n"
238 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
239 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
240 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
241 "a=mid:3\r\n"
242 "a=sendrecv\r\n"
243 "a=rtcp-mux\r\n"
244 "a=rtpmap:120 VP8/0\r\n"
245 "a=ssrc:4 cname:stream2\r\n"
246 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700247
248// Reference SDP without MediaStreams. Msid is not supported.
249static const char kSdpStringWithoutStreams[] =
250 "v=0\r\n"
251 "o=- 0 0 IN IP4 127.0.0.1\r\n"
252 "s=-\r\n"
253 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800254 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700255 "a=ice-ufrag:e5785931\r\n"
256 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
257 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
258 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700259 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700260 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800261 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700262 "a=rtpmap:103 ISAC/16000\r\n"
263 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800264 "a=ice-ufrag:e5785931\r\n"
265 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
266 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
267 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700268 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700269 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800270 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700271 "a=rtpmap:120 VP8/90000\r\n";
272
273// Reference SDP without MediaStreams. Msid is supported.
274static const char kSdpStringWithMsidWithoutStreams[] =
275 "v=0\r\n"
276 "o=- 0 0 IN IP4 127.0.0.1\r\n"
277 "s=-\r\n"
278 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800279 "a=msid-semantic: WMS\r\n"
280 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700281 "a=ice-ufrag:e5785931\r\n"
282 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
283 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
284 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700285 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700286 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800287 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700288 "a=rtpmap:103 ISAC/16000\r\n"
289 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800290 "a=ice-ufrag:e5785931\r\n"
291 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
292 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
293 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700294 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700295 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800296 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700297 "a=rtpmap:120 VP8/90000\r\n";
298
299// Reference SDP without MediaStreams and audio only.
300static const char kSdpStringWithoutStreamsAudioOnly[] =
301 "v=0\r\n"
302 "o=- 0 0 IN IP4 127.0.0.1\r\n"
303 "s=-\r\n"
304 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800305 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700306 "a=ice-ufrag:e5785931\r\n"
307 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
308 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
309 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700310 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700311 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800312 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700313 "a=rtpmap:103 ISAC/16000\r\n";
314
315// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
316static const char kSdpStringSendOnlyWithoutStreams[] =
317 "v=0\r\n"
318 "o=- 0 0 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800321 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700322 "a=ice-ufrag:e5785931\r\n"
323 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
324 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
325 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700326 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700327 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700330 "a=rtpmap:103 ISAC/16000\r\n"
331 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800332 "a=ice-ufrag:e5785931\r\n"
333 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
334 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
335 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700336 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700337 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700338 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800339 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700340 "a=rtpmap:120 VP8/90000\r\n";
341
342static const char kSdpStringInit[] =
343 "v=0\r\n"
344 "o=- 0 0 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700347 "a=msid-semantic: WMS\r\n";
348
349static const char kSdpStringAudio[] =
350 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800351 "a=ice-ufrag:e5785931\r\n"
352 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
353 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
354 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700356 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800357 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700358 "a=rtpmap:103 ISAC/16000\r\n";
359
360static const char kSdpStringVideo[] =
361 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800362 "a=ice-ufrag:e5785931\r\n"
363 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
364 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
365 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700366 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700367 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800368 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700369 "a=rtpmap:120 VP8/90000\r\n";
370
371static const char kSdpStringMs1Audio0[] =
372 "a=ssrc:1 cname:stream1\r\n"
373 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
374
375static const char kSdpStringMs1Video0[] =
376 "a=ssrc:2 cname:stream1\r\n"
377 "a=ssrc:2 msid:stream1 videotrack0\r\n";
378
379static const char kSdpStringMs1Audio1[] =
380 "a=ssrc:3 cname:stream1\r\n"
381 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
382
383static const char kSdpStringMs1Video1[] =
384 "a=ssrc:4 cname:stream1\r\n"
385 "a=ssrc:4 msid:stream1 videotrack1\r\n";
386
deadbeef8662f942017-01-20 21:20:51 -0800387static const char kDtlsSdesFallbackSdp[] =
388 "v=0\r\n"
389 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
390 "s=-\r\n"
391 "c=IN IP4 0.0.0.0\r\n"
392 "t=0 0\r\n"
393 "a=group:BUNDLE audio\r\n"
394 "a=msid-semantic: WMS\r\n"
395 "m=audio 1 RTP/SAVPF 0\r\n"
396 "a=sendrecv\r\n"
397 "a=rtcp-mux\r\n"
398 "a=mid:audio\r\n"
399 "a=ssrc:1 cname:stream1\r\n"
400 "a=ssrc:1 mslabel:stream1\r\n"
401 "a=ssrc:1 label:audiotrack0\r\n"
402 "a=ice-ufrag:e5785931\r\n"
403 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
404 "a=rtpmap:0 pcmu/8000\r\n"
405 "a=fingerprint:sha-1 "
406 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
407 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700408 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800409 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
410 "dummy_session_params\r\n";
411
perkjd61bf802016-03-24 03:16:19 -0700412using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800413using ::testing::Values;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700414using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700416using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417using webrtc::AudioTrackInterface;
418using webrtc::DataBuffer;
419using webrtc::DataChannelInterface;
420using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421using webrtc::IceCandidateInterface;
deadbeefc80741f2015-10-22 13:14:45 -0700422using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700423using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424using webrtc::MediaStreamInterface;
425using webrtc::MediaStreamTrackInterface;
426using webrtc::MockCreateSessionDescriptionObserver;
427using webrtc::MockDataChannelObserver;
Steve Anton94286cb2017-09-26 16:20:19 -0700428using webrtc::MockPeerConnectionObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429using webrtc::MockSetSessionDescriptionObserver;
430using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700431using webrtc::NotifierInterface;
432using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433using webrtc::PeerConnectionInterface;
434using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800435using webrtc::RTCError;
436using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700437using webrtc::RtpReceiverInterface;
438using webrtc::RtpSenderInterface;
Steve Anton57858b32018-02-15 15:19:50 -0800439using webrtc::RtpSenderProxyWithInternal;
440using webrtc::RtpSenderInternal;
Steve Anton4e70a722017-11-28 14:57:10 -0800441using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442using webrtc::SdpParseError;
Steve Anton36da6ff2018-02-16 16:04:20 -0800443using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800444using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700446using webrtc::StreamCollection;
447using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100448using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700449using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450using webrtc::VideoTrackInterface;
451
Steve Anton36da6ff2018-02-16 16:04:20 -0800452using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
453using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700454
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455namespace {
456
457// Gets the first ssrc of given content type from the ContentInfo.
458bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
459 if (!content_info || !ssrc) {
460 return false;
461 }
462 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800463 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 if (!media_desc || media_desc->streams().empty()) {
465 return false;
466 }
467 *ssrc = media_desc->streams().begin()->first_ssrc();
468 return true;
469}
470
deadbeefd1a38b52016-12-10 13:15:33 -0800471// Get the ufrags out of an SDP blob. Useful for testing ICE restart
472// behavior.
473std::vector<std::string> GetUfrags(
474 const webrtc::SessionDescriptionInterface* desc) {
475 std::vector<std::string> ufrags;
476 for (const cricket::TransportInfo& info :
477 desc->description()->transport_infos()) {
478 ufrags.push_back(info.description.ice_ufrag);
479 }
480 return ufrags;
481}
482
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483void SetSsrcToZero(std::string* sdp) {
484 const char kSdpSsrcAtribute[] = "a=ssrc:";
485 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
486 size_t ssrc_pos = 0;
487 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200488 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 size_t end_ssrc = sdp->find(" ", ssrc_pos);
490 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
491 ssrc_pos = end_ssrc;
492 }
493}
494
deadbeefab9b2d12015-10-14 11:33:11 -0700495// Check if |streams| contains the specified track.
496bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800497 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700498 const std::string& track_id) {
499 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800500 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700501 return true;
502 }
503 }
504 return false;
505}
506
507// Check if |senders| contains the specified sender, by id.
508bool ContainsSender(
509 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
510 const std::string& id) {
511 for (const auto& sender : senders) {
512 if (sender->id() == id) {
513 return true;
514 }
515 }
516 return false;
517}
518
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700519// Check if |senders| contains the specified sender, by id and stream id.
520bool ContainsSender(
521 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
522 const std::string& id,
523 const std::string& stream_id) {
524 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700525 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700526 return true;
527 }
528 }
529 return false;
530}
531
deadbeefab9b2d12015-10-14 11:33:11 -0700532// Create a collection of streams.
533// CreateStreamCollection(1) creates a collection that
534// correspond to kSdpStringWithStream1.
535// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
536rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700537 int number_of_streams,
538 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700539 rtc::scoped_refptr<StreamCollection> local_collection(
540 StreamCollection::Create());
541
542 for (int i = 0; i < number_of_streams; ++i) {
543 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
544 webrtc::MediaStream::Create(kStreams[i]));
545
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700546 for (int j = 0; j < tracks_per_stream; ++j) {
547 // Add a local audio track.
548 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
549 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
550 nullptr));
551 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700552
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700553 // Add a local video track.
554 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
555 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700556 webrtc::FakeVideoTrackSource::Create(),
557 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700558 stream->AddTrack(video_track);
559 }
deadbeefab9b2d12015-10-14 11:33:11 -0700560
561 local_collection->AddStream(stream);
562 }
563 return local_collection;
564}
565
566// Check equality of StreamCollections.
567bool CompareStreamCollections(StreamCollectionInterface* s1,
568 StreamCollectionInterface* s2) {
569 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
570 return false;
571 }
572
573 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700574 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700575 return false;
576 }
577 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
578 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
579 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
580 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
581
582 if (audio_tracks1.size() != audio_tracks2.size()) {
583 return false;
584 }
585 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
586 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
587 return false;
588 }
589 }
590 if (video_tracks1.size() != video_tracks2.size()) {
591 return false;
592 }
593 for (size_t j = 0; j != video_tracks1.size(); ++j) {
594 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
595 return false;
596 }
597 }
598 }
599 return true;
600}
601
perkjd61bf802016-03-24 03:16:19 -0700602// Helper class to test Observer.
603class MockTrackObserver : public ObserverInterface {
604 public:
605 explicit MockTrackObserver(NotifierInterface* notifier)
606 : notifier_(notifier) {
607 notifier_->RegisterObserver(this);
608 }
609
610 ~MockTrackObserver() { Unregister(); }
611
612 void Unregister() {
613 if (notifier_) {
614 notifier_->UnregisterObserver(this);
615 notifier_ = nullptr;
616 }
617 }
618
619 MOCK_METHOD0(OnChanged, void());
620
621 private:
622 NotifierInterface* notifier_;
623};
624
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700626
nisse528b7932017-05-08 03:21:43 -0700627// The PeerConnectionMediaConfig tests below verify that configuration and
628// constraints are propagated into the PeerConnection's MediaConfig. These
629// settings are intended for MediaChannel constructors, but that is not
630// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700631class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
632 public:
zhihuang38ede132017-06-15 12:52:32 -0700633 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
634 CreatePeerConnectionFactoryForTest() {
635 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
636 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200637 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
638 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700639
henrika919dc2e2017-10-12 14:24:55 +0200640 // Use fake audio device module since we're only testing the interface
641 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700642 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
643 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200644 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200645 audio_decoder_factory, std::move(video_encoder_factory),
646 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100647 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700648
649 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
650 webrtc::CreateCallFactory();
651
652 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
653 webrtc::CreateRtcEventLogFactory();
654
655 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
656 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200657 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700658 std::move(event_log_factory));
659 }
660
661 PeerConnectionFactoryForTest(
662 rtc::Thread* network_thread,
663 rtc::Thread* worker_thread,
664 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700665 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
666 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
667 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
668 : webrtc::PeerConnectionFactory(network_thread,
669 worker_thread,
670 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700671 std::move(media_engine),
672 std::move(call_factory),
673 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800674
deadbeefd7850b22017-08-23 10:59:19 -0700675 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700676};
677
Steve Anton36da6ff2018-02-16 16:04:20 -0800678// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
679class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800681 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
682 : vss_(new rtc::VirtualSocketServer()),
683 main_(vss_.get()),
684 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800685#ifdef WEBRTC_ANDROID
686 webrtc::InitializeAndroidObjects();
687#endif
688 }
689
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700691 // Use fake audio capture module since we're only testing the interface
692 // level, and using a real one could make tests flaky when run in parallel.
693 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700695 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200696 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
697 fake_audio_capture_module_),
698 webrtc::CreateBuiltinAudioEncoderFactory(),
699 webrtc::CreateBuiltinAudioDecoderFactory(),
700 webrtc::CreateBuiltinVideoEncoderFactory(),
701 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
702 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700703 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700704 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700705 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700706 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 }
708
709 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700710 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 }
712
deadbeef293e9262017-01-11 12:28:30 -0800713 // DTLS does not work in a loopback call, so is disabled for most of the
714 // tests in this file.
715 void CreatePeerConnectionWithoutDtls() {
716 FakeConstraints no_dtls_constraints;
717 no_dtls_constraints.AddMandatory(
718 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
719
720 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
721 &no_dtls_constraints);
722 }
723
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700725 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
726 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 }
728
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700729 void CreatePeerConnectionWithIceTransportsType(
730 PeerConnectionInterface::IceTransportsType type) {
731 PeerConnectionInterface::RTCConfiguration config;
732 config.type = type;
733 return CreatePeerConnection(config, nullptr);
734 }
735
736 void CreatePeerConnectionWithIceServer(const std::string& uri,
737 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800738 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700740 server.uri = uri;
741 server.password = password;
742 config.servers.push_back(server);
743 CreatePeerConnection(config, nullptr);
744 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100746 void CreatePeerConnection(
747 const PeerConnectionInterface::RTCConfiguration& config,
748 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700749 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800750 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
751 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000752
deadbeef1dcb1642017-03-29 21:08:16 -0700753 // Create certificate generator unless DTLS constraint is explicitly set to
754 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200755 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000756 bool dtls;
757 if (FindConstraint(constraints,
758 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
Yves Gerey665174f2018-06-19 15:03:05 +0200759 &dtls, nullptr) &&
760 dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800761 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
762 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000763 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800764 RTCConfiguration modified_config = config;
765 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200766 pc_ = pc_factory_->CreatePeerConnection(
Steve Anton36da6ff2018-02-16 16:04:20 -0800767 modified_config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200768 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 ASSERT_TRUE(pc_.get() != NULL);
770 observer_.SetPeerConnectionInterface(pc_.get());
771 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
772 }
773
deadbeef0a6c4ca2015-10-06 11:38:28 -0700774 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800775 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700776 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700777 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800778 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800779 config.sdp_semantics = sdp_semantics_;
780 rtc::scoped_refptr<PeerConnectionInterface> pc =
781 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
782 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800783 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700784 }
785
Steve Anton038834f2017-07-14 15:59:59 -0700786 void CreatePeerConnectionExpectFail(
787 PeerConnectionInterface::RTCConfiguration config) {
788 PeerConnectionInterface::IceServer server;
789 server.uri = kTurnIceServerUri;
790 server.password = kTurnPassword;
791 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800792 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700793 rtc::scoped_refptr<PeerConnectionInterface> pc =
794 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
795 EXPECT_EQ(nullptr, pc);
796 }
797
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700799 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
801 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
802 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805
deadbeef0a6c4ca2015-10-06 11:38:28 -0700806 CreatePeerConnectionExpectFail(kStunInvalidPort);
807 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
808 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700810 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800811 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
812 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800814 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800816 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800818 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 }
820
821 void ReleasePeerConnection() {
822 pc_ = NULL;
823 observer_.SetPeerConnectionInterface(NULL);
824 }
825
Steve Anton36da6ff2018-02-16 16:04:20 -0800826 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
827 const std::string& label) {
828 auto video_source = pc_factory_->CreateVideoSource(
829 rtc::MakeUnique<cricket::FakeVideoCapturer>(), nullptr);
830 return pc_factory_->CreateVideoTrack(label, video_source);
831 }
832
833 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800834 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800835 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800836 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800837 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
839 observer_.renegotiation_needed_ = false;
840 }
841
Steve Anton36da6ff2018-02-16 16:04:20 -0800842 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700843 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800845 stream->AddTrack(CreateVideoTrack(label + "v0"));
846 ASSERT_TRUE(pc_->AddStream(stream));
847 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
848 observer_.renegotiation_needed_ = false;
849 }
850
851 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
852 const std::string& label) {
853 return pc_factory_->CreateAudioTrack(label, nullptr);
854 }
855
856 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800857 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800858 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800859 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800860 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
861 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
862 observer_.renegotiation_needed_ = false;
863 }
864
865 void AddAudioStream(const std::string& label) {
866 rtc::scoped_refptr<MediaStreamInterface> stream(
867 pc_factory_->CreateLocalMediaStream(label));
868 stream->AddTrack(CreateAudioTrack(label + "a0"));
869 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
871 observer_.renegotiation_needed_ = false;
872 }
873
Seth Hampson845e8782018-03-02 11:34:10 -0800874 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 const std::string& audio_track_label,
876 const std::string& video_track_label) {
877 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700878 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800879 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800880 stream->AddTrack(CreateAudioTrack(audio_track_label));
881 stream->AddTrack(CreateVideoTrack(video_track_label));
882 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
884 observer_.renegotiation_needed_ = false;
885 }
886
Steve Anton36da6ff2018-02-16 16:04:20 -0800887 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
888 cricket::MediaType media_type) {
889 for (auto receiver : pc_->GetReceivers()) {
890 if (receiver->media_type() == media_type) {
891 return receiver;
892 }
893 }
894 return nullptr;
895 }
896
kwibergd1fe2812016-04-27 06:47:29 -0700897 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700898 bool offer,
899 MediaConstraintsInterface* constraints) {
Yves Gerey665174f2018-06-19 15:03:05 +0200900 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
901 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700903 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700905 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 }
907 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700908 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 return observer->result();
910 }
911
kwibergd1fe2812016-04-27 06:47:29 -0700912 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700913 MediaConstraintsInterface* constraints) {
914 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 }
916
kwibergd1fe2812016-04-27 06:47:29 -0700917 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700918 MediaConstraintsInterface* constraints) {
919 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 }
921
Steve Antondb45ca82017-09-11 18:27:34 -0700922 bool DoSetSessionDescription(
923 std::unique_ptr<SessionDescriptionInterface> desc,
924 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200925 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
926 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700928 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700930 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 }
zhihuang29ff8442016-07-27 11:07:25 -0700932 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
933 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
934 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 return observer->result();
936 }
937
Steve Antondb45ca82017-09-11 18:27:34 -0700938 bool DoSetLocalDescription(
939 std::unique_ptr<SessionDescriptionInterface> desc) {
940 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 }
942
Steve Antondb45ca82017-09-11 18:27:34 -0700943 bool DoSetRemoteDescription(
944 std::unique_ptr<SessionDescriptionInterface> desc) {
945 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 }
947
948 // Calls PeerConnection::GetStats and check the return value.
949 // It does not verify the values in the StatReports since a RTCP packet might
950 // be required.
951 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000952 rtc::scoped_refptr<MockStatsObserver> observer(
953 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200954 if (!pc_->GetStats(observer, track,
955 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 return false;
957 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
958 return observer->called();
959 }
960
Harald Alvestrand89061872018-01-02 14:08:34 +0100961 // Call the standards-compliant GetStats function.
962 bool DoGetRTCStats() {
963 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
964 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
965 pc_->GetStats(callback);
966 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
967 return callback->called();
968 }
969
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800971 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800973 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800974 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800975 } else {
976 // Unified Plan does not support AddStream, so just add an audio and video
977 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800978 AddAudioTrack(kAudioTracks[0], {kStreamId1});
979 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800980 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 CreateOfferReceiveAnswer();
982 }
983
984 // Verify that RTP Header extensions has been negotiated for audio and video.
985 void VerifyRemoteRtpHeaderExtensions() {
986 const cricket::MediaContentDescription* desc =
987 cricket::GetFirstAudioContentDescription(
988 pc_->remote_description()->description());
989 ASSERT_TRUE(desc != NULL);
990 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
991
992 desc = cricket::GetFirstVideoContentDescription(
993 pc_->remote_description()->description());
994 ASSERT_TRUE(desc != NULL);
995 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
996 }
997
998 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700999 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001000 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 std::string sdp;
1002 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001003 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001004 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001005 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1007 }
1008
deadbeefab9b2d12015-10-14 11:33:11 -07001009 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001010 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001011 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001012 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001013 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1014 }
1015
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001017 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001018 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019
1020 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1021 // audio codec change, even if the parameter has nothing to do with
1022 // receiving. Not all parameters are serialized to SDP.
1023 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1024 // the SessionDescription, it is necessary to do that here to in order to
1025 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1026 // https://code.google.com/p/webrtc/issues/detail?id=1356
1027 std::string sdp;
1028 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001029 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001030 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001031 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1033 }
1034
1035 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001036 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001037 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038
1039 std::string sdp;
1040 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001041 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001042 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001043 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1045 }
1046
1047 void CreateOfferReceiveAnswer() {
1048 CreateOfferAsLocalDescription();
1049 std::string sdp;
1050 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1051 CreateAnswerAsRemoteDescription(sdp);
1052 }
1053
1054 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001055 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001056 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1058 // audio codec change, even if the parameter has nothing to do with
1059 // receiving. Not all parameters are serialized to SDP.
1060 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1061 // the SessionDescription, it is necessary to do that here to in order to
1062 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1063 // https://code.google.com/p/webrtc/issues/detail?id=1356
1064 std::string sdp;
1065 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001067 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068
Steve Antondb45ca82017-09-11 18:27:34 -07001069 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001071 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001072 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 }
1074
deadbeefab9b2d12015-10-14 11:33:11 -07001075 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001076 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001077 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001078 ASSERT_TRUE(answer);
1079 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1081 }
1082
deadbeefab9b2d12015-10-14 11:33:11 -07001083 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001084 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001085 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001086 ASSERT_TRUE(pr_answer);
1087 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001089 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001090 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001091 ASSERT_TRUE(answer);
1092 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1094 }
1095
Seth Hampson845e8782018-03-02 11:34:10 -08001096 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001097 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001098 // called with the given stream id and expected number of tracks.
1099 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001100 int expected_num_tracks) {
1101 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001102 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001103 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001104 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 }
1106
1107 // Creates an offer and applies it as a local session description.
1108 // Creates an answer with the same SDP an the offer but removes all lines
1109 // that start with a:ssrc"
1110 void CreateOfferReceiveAnswerWithoutSsrc() {
1111 CreateOfferAsLocalDescription();
1112 std::string sdp;
1113 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1114 SetSsrcToZero(&sdp);
1115 CreateAnswerAsRemoteDescription(sdp);
1116 }
1117
deadbeefab9b2d12015-10-14 11:33:11 -07001118 // This function creates a MediaStream with label kStreams[0] and
1119 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1120 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001121 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001122 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001123 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001124 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1125 size_t number_of_video_tracks) {
1126 EXPECT_LE(number_of_audio_tracks, 2u);
1127 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001128
1129 reference_collection_ = StreamCollection::Create();
1130 std::string sdp_ms1 = std::string(kSdpStringInit);
1131
Seth Hampson845e8782018-03-02 11:34:10 -08001132 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001133
1134 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001135 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001136 reference_collection_->AddStream(stream);
1137
1138 if (number_of_audio_tracks > 0) {
1139 sdp_ms1 += std::string(kSdpStringAudio);
1140 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1141 AddAudioTrack(kAudioTracks[0], stream);
1142 }
1143 if (number_of_audio_tracks > 1) {
1144 sdp_ms1 += kSdpStringMs1Audio1;
1145 AddAudioTrack(kAudioTracks[1], stream);
1146 }
1147
1148 if (number_of_video_tracks > 0) {
1149 sdp_ms1 += std::string(kSdpStringVideo);
1150 sdp_ms1 += std::string(kSdpStringMs1Video0);
1151 AddVideoTrack(kVideoTracks[0], stream);
1152 }
1153 if (number_of_video_tracks > 1) {
1154 sdp_ms1 += kSdpStringMs1Video1;
1155 AddVideoTrack(kVideoTracks[1], stream);
1156 }
1157
kwibergd1fe2812016-04-27 06:47:29 -07001158 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001159 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001160 }
1161
1162 void AddAudioTrack(const std::string& track_id,
1163 MediaStreamInterface* stream) {
1164 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1165 webrtc::AudioTrack::Create(track_id, nullptr));
1166 ASSERT_TRUE(stream->AddTrack(audio_track));
1167 }
1168
1169 void AddVideoTrack(const std::string& track_id,
1170 MediaStreamInterface* stream) {
1171 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001172 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001173 webrtc::FakeVideoTrackSource::Create(),
1174 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001175 ASSERT_TRUE(stream->AddTrack(video_track));
1176 }
1177
Steve Anton36da6ff2018-02-16 16:04:20 -08001178 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001179 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001180 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001181 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001182 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1183 return offer;
1184 }
1185
Steve Anton36da6ff2018-02-16 16:04:20 -08001186 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1187 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001188 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001189 std::unique_ptr<SessionDescriptionInterface> offer;
1190 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1191 return offer;
1192 }
1193
1194 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1195 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1196 std::unique_ptr<SessionDescriptionInterface> answer;
1197 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1198 return answer;
1199 }
1200
kwibergfd8be342016-05-14 19:44:11 -07001201 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001202 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001203 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001204 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001205 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1206 return answer;
1207 }
1208
1209 const std::string& GetFirstAudioStreamCname(
1210 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001211 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001212 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001213 return audio_desc->streams()[0].cname;
1214 }
1215
zhihuang1c378ed2017-08-17 14:10:50 -07001216 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1217 const RTCOfferAnswerOptions& offer_answer_options) {
1218 RTC_DCHECK(pc_);
1219 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1220 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1221 pc_->CreateOffer(observer, offer_answer_options);
1222 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1223 return observer->MoveDescription();
1224 }
1225
1226 void CreateOfferWithOptionsAsRemoteDescription(
1227 std::unique_ptr<SessionDescriptionInterface>* desc,
1228 const RTCOfferAnswerOptions& offer_answer_options) {
1229 *desc = CreateOfferWithOptions(offer_answer_options);
1230 ASSERT_TRUE(desc != nullptr);
1231 std::string sdp;
1232 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001233 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001234 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001235 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001236 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1237 }
1238
1239 void CreateOfferWithOptionsAsLocalDescription(
1240 std::unique_ptr<SessionDescriptionInterface>* desc,
1241 const RTCOfferAnswerOptions& offer_answer_options) {
1242 *desc = CreateOfferWithOptions(offer_answer_options);
1243 ASSERT_TRUE(desc != nullptr);
1244 std::string sdp;
1245 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001246 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001247 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001248
Steve Antondb45ca82017-09-11 18:27:34 -07001249 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001250 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1251 }
1252
1253 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001254 RTC_DCHECK(content);
1255 RTC_DCHECK(content->media_description());
1256 for (const cricket::AudioCodec& codec :
1257 content->media_description()->as_audio()->codecs()) {
1258 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001259 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001260 }
zhihuang1c378ed2017-08-17 14:10:50 -07001261 }
1262 return false;
1263 }
1264
Steve Anton36da6ff2018-02-16 16:04:20 -08001265 const char* GetSdpStringWithStream1() const {
1266 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1267 return kSdpStringWithStream1PlanB;
1268 } else {
1269 return kSdpStringWithStream1UnifiedPlan;
1270 }
1271 }
1272
1273 const char* GetSdpStringWithStream1And2() const {
1274 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1275 return kSdpStringWithStream1And2PlanB;
1276 } else {
1277 return kSdpStringWithStream1And2UnifiedPlan;
1278 }
1279 }
1280
deadbeef9a6f4d42017-05-15 19:43:33 -07001281 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1282 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001283 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001284 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001285 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001286 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1287 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1288 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001290 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001291 const SdpSemantics sdp_semantics_;
1292};
1293
1294class PeerConnectionInterfaceTest
1295 : public PeerConnectionInterfaceBaseTest,
1296 public ::testing::WithParamInterface<SdpSemantics> {
1297 protected:
1298 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1299};
1300
1301class PeerConnectionInterfaceTestPlanB
1302 : public PeerConnectionInterfaceBaseTest {
1303 protected:
1304 PeerConnectionInterfaceTestPlanB()
1305 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306};
1307
zhihuang8f65cdf2016-05-06 18:40:30 -07001308// Generate different CNAMEs when PeerConnections are created.
1309// The CNAMEs are expected to be generated randomly. It is possible
1310// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001311TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001312 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001313 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001314 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001315 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001316 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1317 GetFirstAudioStreamCname(offer2.get()));
1318}
1319
Steve Anton36da6ff2018-02-16 16:04:20 -08001320TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001321 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001322 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001323 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001324 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001325 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1326 GetFirstAudioStreamCname(answer2.get()));
1327}
1328
Steve Anton36da6ff2018-02-16 16:04:20 -08001329TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 CreatePeerConnectionWithDifferentConfigurations) {
1331 CreatePeerConnectionWithDifferentConfigurations();
1332}
1333
Steve Anton36da6ff2018-02-16 16:04:20 -08001334TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001335 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1336 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1337 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1338 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1339 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1340 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1341 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1342 port_allocator_->candidate_filter());
1343 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1344 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1345}
1346
1347// Test that when a PeerConnection is created with a nonzero candidate pool
1348// size, the pooled PortAllocatorSession is created with all the attributes
1349// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001350TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001351 PeerConnectionInterface::RTCConfiguration config;
1352 PeerConnectionInterface::IceServer server;
1353 server.uri = kStunAddressOnly;
1354 config.servers.push_back(server);
1355 config.type = PeerConnectionInterface::kRelay;
1356 config.disable_ipv6 = true;
1357 config.tcp_candidate_policy =
1358 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001359 config.candidate_network_policy =
1360 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001361 config.ice_candidate_pool_size = 1;
1362 CreatePeerConnection(config, nullptr);
1363
1364 const cricket::FakePortAllocatorSession* session =
1365 static_cast<const cricket::FakePortAllocatorSession*>(
1366 port_allocator_->GetPooledSession());
1367 ASSERT_NE(nullptr, session);
1368 EXPECT_EQ(1UL, session->stun_servers().size());
1369 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1370 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001371 EXPECT_LT(0U,
1372 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001373}
1374
deadbeefd21eab32017-07-26 16:50:11 -07001375// Test that network-related RTCConfiguration members are applied to the
1376// PortAllocator when CreatePeerConnection is called. Specifically:
1377// - disable_ipv6_on_wifi
1378// - max_ipv6_networks
1379// - tcp_candidate_policy
1380// - candidate_network_policy
1381// - prune_turn_ports
1382//
1383// Note that the candidate filter (RTCConfiguration::type) is already tested
1384// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001385TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001386 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1387 // Create fake port allocator.
1388 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1389 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1390 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1391
1392 // Create RTCConfiguration with some network-related fields relevant to
1393 // PortAllocator populated.
1394 PeerConnectionInterface::RTCConfiguration config;
1395 config.disable_ipv6_on_wifi = true;
1396 config.max_ipv6_networks = 10;
1397 config.tcp_candidate_policy =
1398 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1399 config.candidate_network_policy =
1400 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1401 config.prune_turn_ports = true;
1402
1403 // Create the PC factory and PC with the above config.
1404 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1405 webrtc::CreatePeerConnectionFactory(
1406 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001407 rtc::Thread::Current(), fake_audio_capture_module_,
1408 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001409 webrtc::CreateBuiltinAudioDecoderFactory(),
1410 webrtc::CreateBuiltinVideoEncoderFactory(),
1411 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1412 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001413 rtc::scoped_refptr<PeerConnectionInterface> pc(
1414 pc_factory->CreatePeerConnection(
1415 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1416
1417 // Now validate that the config fields set above were applied to the
1418 // PortAllocator, as flags or otherwise.
1419 EXPECT_FALSE(raw_port_allocator->flags() &
1420 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1421 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1422 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1423 EXPECT_TRUE(raw_port_allocator->flags() &
1424 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1425 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1426}
1427
deadbeef46c73892016-11-16 19:42:04 -08001428// Check that GetConfiguration returns the configuration the PeerConnection was
1429// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001430TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001431 PeerConnectionInterface::RTCConfiguration config;
1432 config.type = PeerConnectionInterface::kRelay;
1433 CreatePeerConnection(config, nullptr);
1434
1435 PeerConnectionInterface::RTCConfiguration returned_config =
1436 pc_->GetConfiguration();
1437 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1438}
1439
1440// Check that GetConfiguration returns the last configuration passed into
1441// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001442TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001443 CreatePeerConnection();
1444
Steve Anton36da6ff2018-02-16 16:04:20 -08001445 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001446 config.type = PeerConnectionInterface::kRelay;
1447 EXPECT_TRUE(pc_->SetConfiguration(config));
1448
1449 PeerConnectionInterface::RTCConfiguration returned_config =
1450 pc_->GetConfiguration();
1451 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1452}
1453
Steve Antonc79268f2018-04-24 09:54:10 -07001454TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1455 CreatePeerConnection();
1456
1457 pc_->Close();
1458
1459 EXPECT_FALSE(
1460 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1461}
1462
Steve Anton36da6ff2018-02-16 16:04:20 -08001463TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001464 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001465 AddVideoStream(kStreamId1);
1466 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 ASSERT_EQ(2u, pc_->local_streams()->count());
1468
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001469 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001470 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001471 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001472 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001473 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001474 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001476 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001477 EXPECT_EQ(3u, pc_->local_streams()->count());
1478
1479 // Remove the third stream.
1480 pc_->RemoveStream(pc_->local_streams()->at(2));
1481 EXPECT_EQ(2u, pc_->local_streams()->count());
1482
1483 // Remove the second stream.
1484 pc_->RemoveStream(pc_->local_streams()->at(1));
1485 EXPECT_EQ(1u, pc_->local_streams()->count());
1486
1487 // Remove the first stream.
1488 pc_->RemoveStream(pc_->local_streams()->at(0));
1489 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490}
1491
deadbeefab9b2d12015-10-14 11:33:11 -07001492// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001493// Don't run under Unified Plan since the stream API is not available.
1494TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001495 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001496 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001497 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001498 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001499
deadbeefab9b2d12015-10-14 11:33:11 -07001500 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001501 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001502 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001503
deadbeefab9b2d12015-10-14 11:33:11 -07001504 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001505 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001506 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001507
1508 // Add another stream and ensure the offer includes both the old and new
1509 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001510 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001511 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001512
Steve Antonb1c1de12017-12-21 15:14:30 -08001513 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001514 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1515 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001516
Steve Antonb1c1de12017-12-21 15:14:30 -08001517 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001518 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1519 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001520}
1521
Steve Anton36da6ff2018-02-16 16:04:20 -08001522// Don't run under Unified Plan since the stream API is not available.
1523TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001524 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001525 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 ASSERT_EQ(1u, pc_->local_streams()->count());
1527 pc_->RemoveStream(pc_->local_streams()->at(0));
1528 EXPECT_EQ(0u, pc_->local_streams()->count());
1529}
1530
deadbeefe1f9d832016-01-14 15:35:42 -08001531// Test for AddTrack and RemoveTrack methods.
1532// Tests that the created offer includes tracks we added,
1533// and that the RtpSenders are created correctly.
1534// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001535// Only tested with Plan B since Unified Plan is covered in more detail by tests
1536// in peerconnection_jsep_unittests.cc
1537TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001538 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001539 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001540 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001541 rtc::scoped_refptr<VideoTrackInterface> video_track(
1542 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001543 "video_track", pc_factory_->CreateVideoSource(
1544 std::unique_ptr<cricket::VideoCapturer>(
1545 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001546 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1547 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001548 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001549 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001550 EXPECT_EQ("audio_track", audio_sender->id());
1551 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001552 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001553 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001554 EXPECT_EQ("video_track", video_sender->id());
1555 EXPECT_EQ(video_track, video_sender->track());
1556
1557 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001558 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001559 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 const cricket::ContentInfo* audio_content =
1562 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001563 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001564 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
1566 const cricket::ContentInfo* video_content =
1567 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001568 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001569 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001570
Steve Antondb45ca82017-09-11 18:27:34 -07001571 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001572
1573 // Now try removing the tracks.
1574 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1575 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1576
1577 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001578 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001579
1580 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001581 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001582 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001583
1584 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001585 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001586 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001587
Steve Antondb45ca82017-09-11 18:27:34 -07001588 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001589
1590 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1591 // should return false.
1592 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1593 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1594}
1595
1596// Test creating senders without a stream specified,
1597// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001598TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001599 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001600 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001601 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001602 rtc::scoped_refptr<VideoTrackInterface> video_track(
1603 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001604 "video_track", pc_factory_->CreateVideoSource(
1605 std::unique_ptr<cricket::VideoCapturer>(
1606 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001607 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001608 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001609 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001610 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001611 EXPECT_EQ("audio_track", audio_sender->id());
1612 EXPECT_EQ(audio_track, audio_sender->track());
1613 EXPECT_EQ("video_track", video_sender->id());
1614 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001615 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1616 // If the ID is truly a random GUID, it should be infinitely unlikely they
1617 // will be the same.
1618 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1619 } else {
1620 // We allows creating tracks without stream ids under Unified Plan
1621 // semantics.
1622 EXPECT_EQ(0u, video_sender->stream_ids().size());
1623 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1624 }
deadbeefe1f9d832016-01-14 15:35:42 -08001625}
1626
Harald Alvestrand89061872018-01-02 14:08:34 +01001627// Test that we can call GetStats() after AddTrack but before connecting
1628// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001629TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001630 CreatePeerConnectionWithoutDtls();
1631 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1632 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1633 rtc::scoped_refptr<VideoTrackInterface> video_track(
1634 pc_factory_->CreateVideoTrack(
1635 "video_track", pc_factory_->CreateVideoSource(
1636 std::unique_ptr<cricket::VideoCapturer>(
1637 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001638 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1639 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001640 EXPECT_TRUE(DoGetStats(nullptr));
1641}
1642
Steve Anton36da6ff2018-02-16 16:04:20 -08001643TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001644 CreatePeerConnectionWithoutDtls();
1645 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1646 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1647 rtc::scoped_refptr<VideoTrackInterface> video_track(
1648 pc_factory_->CreateVideoTrack(
1649 "video_track", pc_factory_->CreateVideoSource(
1650 std::unique_ptr<cricket::VideoCapturer>(
1651 new cricket::FakeVideoCapturer()))));
1652 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001653 ASSERT_TRUE(audio_sender.ok());
1654 auto* audio_sender_proxy =
1655 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1656 audio_sender.value().get());
1657 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1658
Harald Alvestrandc72af932018-01-11 17:18:19 +01001659 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001660 ASSERT_TRUE(video_sender.ok());
1661 auto* video_sender_proxy =
1662 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1663 video_sender.value().get());
1664 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001665}
1666
Steve Anton36da6ff2018-02-16 16:04:20 -08001667// Don't run under Unified Plan since the stream API is not available.
1668TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001669 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001670 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001671 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001672 ASSERT_EQ(1u, senders.size());
1673 auto* sender_proxy =
1674 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1675 senders[0].get());
1676 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001677}
1678
Steve Anton36da6ff2018-02-16 16:04:20 -08001679TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001681 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 VerifyRemoteRtpHeaderExtensions();
1683}
1684
Steve Anton36da6ff2018-02-16 16:04:20 -08001685TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001686 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001687 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 CreateOfferAsLocalDescription();
1689 std::string offer;
1690 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1691 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001692 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693}
1694
Steve Anton36da6ff2018-02-16 16:04:20 -08001695TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001696 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001697 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698
1699 CreateOfferAsRemoteDescription();
1700 CreateAnswerAsLocalDescription();
1701
Seth Hampson845e8782018-03-02 11:34:10 -08001702 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703}
1704
Steve Anton36da6ff2018-02-16 16:04:20 -08001705TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001706 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001707 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708
1709 CreateOfferAsRemoteDescription();
1710 CreatePrAnswerAsLocalDescription();
1711 CreateAnswerAsLocalDescription();
1712
Seth Hampson845e8782018-03-02 11:34:10 -08001713 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714}
1715
Steve Anton36da6ff2018-02-16 16:04:20 -08001716// Don't run under Unified Plan since the stream API is not available.
1717TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 InitiateCall();
1719 ASSERT_EQ(1u, pc_->remote_streams()->count());
1720 pc_->RemoveStream(pc_->local_streams()->at(0));
1721 CreateOfferReceiveAnswer();
1722 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001723 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 CreateOfferReceiveAnswer();
1725}
1726
1727// Tests that after negotiating an audio only call, the respondent can perform a
1728// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001729TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001730 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001731 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 CreateOfferAsRemoteDescription();
1733 CreateAnswerAsLocalDescription();
1734
1735 ASSERT_EQ(1u, pc_->remote_streams()->count());
1736 pc_->RemoveStream(pc_->local_streams()->at(0));
1737 CreateOfferReceiveAnswer();
1738 EXPECT_EQ(0u, pc_->remote_streams()->count());
1739}
1740
1741// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001742TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001743 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
Steve Antonf1c6db12017-10-13 11:13:35 -07001745 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001747 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001748 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001749 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001750 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001753 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001754 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001755 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756
Steve Antonf1c6db12017-10-13 11:13:35 -07001757 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001758 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759
Steve Antonf1c6db12017-10-13 11:13:35 -07001760 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761}
1762
deadbeefab9b2d12015-10-14 11:33:11 -07001763// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001765TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001766 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001768 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001769 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001770 EXPECT_TRUE(offer);
1771 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772
1773 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001774 AddAudioTrack("track_label", {kStreamId1});
1775 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776
1777 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001778 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779
1780 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001781 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001782 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783}
1784
1785// Test that we will get different SSRCs for each tracks in the offer and answer
1786// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001787TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001788 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001790 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1791 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792
1793 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001794 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001795 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 int audio_ssrc = 0;
1797 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001798 EXPECT_TRUE(
1799 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1800 EXPECT_TRUE(
1801 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 EXPECT_NE(audio_ssrc, video_ssrc);
1803
1804 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001805 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001806 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001807 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 audio_ssrc = 0;
1809 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001810 EXPECT_TRUE(
1811 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1812 EXPECT_TRUE(
1813 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 EXPECT_NE(audio_ssrc, video_ssrc);
1815}
1816
deadbeefeb459812015-12-15 19:24:43 -08001817// Test that it's possible to call AddTrack on a MediaStream after adding
1818// the stream to a PeerConnection.
1819// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001820// Don't run under Unified Plan since the stream API is not available.
1821TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001822 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001823 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001824 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001825 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1826
1827 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001828 rtc::scoped_refptr<VideoTrackInterface> video_track(
1829 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001830 "video_label", pc_factory_->CreateVideoSource(
1831 std::unique_ptr<cricket::VideoCapturer>(
1832 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001833 stream->AddTrack(video_track.get());
1834
kwibergd1fe2812016-04-27 06:47:29 -07001835 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001836 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001837
1838 const cricket::MediaContentDescription* video_desc =
1839 cricket::GetFirstVideoContentDescription(offer->description());
1840 EXPECT_TRUE(video_desc != nullptr);
1841}
1842
1843// Test that it's possible to call RemoveTrack on a MediaStream after adding
1844// the stream to a PeerConnection.
1845// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001846// Don't run under Unified Plan since the stream API is not available.
1847TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001848 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001849 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001850 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001851 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1852
1853 // Remove the video track.
1854 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1855
kwibergd1fe2812016-04-27 06:47:29 -07001856 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001857 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001858
1859 const cricket::MediaContentDescription* video_desc =
1860 cricket::GetFirstVideoContentDescription(offer->description());
1861 EXPECT_TRUE(video_desc == nullptr);
1862}
1863
deadbeefbd7d8f72015-12-18 16:58:44 -08001864// Test creating a sender with a stream ID, and ensure the ID is populated
1865// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001866// Don't run under Unified Plan since the stream API is not available.
1867TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001868 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001869 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001870
kwibergd1fe2812016-04-27 06:47:29 -07001871 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001872 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001873
1874 const cricket::MediaContentDescription* video_desc =
1875 cricket::GetFirstVideoContentDescription(offer->description());
1876 ASSERT_TRUE(video_desc != nullptr);
1877 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001878 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001879}
1880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001882TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001884 ASSERT_LT(0u, pc_->GetSenders().size());
1885 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001886 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001887 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 EXPECT_TRUE(DoGetStats(remote_audio));
1889
1890 // Remove the stream. Since we are sending to our selves the local
1891 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001892 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 // Do a re-negotiation.
1894 CreateOfferReceiveAnswer();
1895
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 // Test that we still can get statistics for the old track. Even if it is not
1897 // sent any longer.
1898 EXPECT_TRUE(DoGetStats(remote_audio));
1899}
1900
1901// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001902TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001904 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1905 ASSERT_TRUE(video_receiver);
1906 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907}
1908
1909// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001910TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001912 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 pc_factory_->CreateAudioTrack("unknown track", NULL));
1914 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1915}
1916
Steve Anton36da6ff2018-02-16 16:04:20 -08001917TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001918 CreatePeerConnectionWithoutDtls();
1919 EXPECT_TRUE(DoGetRTCStats());
1920 // Clearing stats cache is needed now, but should be temporary.
1921 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1922 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001923 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1924 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001925 EXPECT_TRUE(DoGetRTCStats());
1926 pc_->ClearStatsCache();
1927 CreateOfferReceiveAnswer();
1928 EXPECT_TRUE(DoGetRTCStats());
1929}
1930
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001932TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 FakeConstraints constraints;
1934 constraints.SetAllowRtpDataChannels();
1935 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001936 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001938 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939 pc_->CreateDataChannel("test2", NULL);
1940 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001941 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001943 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 new MockDataChannelObserver(data2));
1945
1946 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1947 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1948 std::string data_to_send1 = "testing testing";
1949 std::string data_to_send2 = "testing something else";
1950 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1951
1952 CreateOfferReceiveAnswer();
1953 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1954 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1955
1956 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1957 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1958 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1959 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1960
1961 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1962 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1963
1964 data1->Close();
1965 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1966 CreateOfferReceiveAnswer();
1967 EXPECT_FALSE(observer1->IsOpen());
1968 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1969 EXPECT_TRUE(observer2->IsOpen());
1970
1971 data_to_send2 = "testing something else again";
1972 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1973
1974 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1975}
1976
1977// This test verifies that sendnig binary data over RTP data channels should
1978// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001979TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 FakeConstraints constraints;
1981 constraints.SetAllowRtpDataChannels();
1982 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001983 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001985 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 pc_->CreateDataChannel("test2", NULL);
1987 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001988 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001990 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 new MockDataChannelObserver(data2));
1992
1993 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1994 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1995
1996 CreateOfferReceiveAnswer();
1997 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1998 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1999
2000 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2001 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2002
jbaucheec21bd2016-03-20 06:15:43 -07002003 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2005}
2006
2007// This test setup a RTP data channels in loop back and test that a channel is
2008// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002009TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 FakeConstraints constraints;
2011 constraints.SetAllowRtpDataChannels();
2012 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002013 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002015 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 new MockDataChannelObserver(data1));
2017
2018 CreateOfferReceiveAnswerWithoutSsrc();
2019
2020 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2021
2022 data1->Close();
2023 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2024 CreateOfferReceiveAnswerWithoutSsrc();
2025 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2026 EXPECT_FALSE(observer1->IsOpen());
2027}
2028
2029// This test that if a data channel is added in an answer a receive only channel
2030// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002031TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 FakeConstraints constraints;
2033 constraints.SetAllowRtpDataChannels();
2034 CreatePeerConnection(&constraints);
2035
2036 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002037 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 pc_->CreateDataChannel(offer_label, NULL);
2039
2040 CreateOfferAsLocalDescription();
2041
2042 // Replace the data channel label in the offer and apply it as an answer.
2043 std::string receive_label = "answer_channel";
2044 std::string sdp;
2045 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002046 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002047 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 CreateAnswerAsRemoteDescription(sdp);
2049
2050 // Verify that a new incoming data channel has been created and that
2051 // it is open but can't we written to.
2052 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2053 DataChannelInterface* received_channel = observer_.last_datachannel_;
2054 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2055 EXPECT_EQ(receive_label, received_channel->label());
2056 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2057
2058 // Verify that the channel we initially offered has been rejected.
2059 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2060
2061 // Do another offer / answer exchange and verify that the data channel is
2062 // opened.
2063 CreateOfferReceiveAnswer();
2064 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2065 kTimeout);
2066}
2067
2068// This test that no data channel is returned if a reliable channel is
2069// requested.
2070// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002071TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 FakeConstraints constraints;
2073 constraints.SetAllowRtpDataChannels();
2074 CreatePeerConnection(&constraints);
2075
2076 std::string label = "test";
2077 webrtc::DataChannelInit config;
2078 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002079 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 pc_->CreateDataChannel(label, &config);
2081 EXPECT_TRUE(channel == NULL);
2082}
2083
deadbeefab9b2d12015-10-14 11:33:11 -07002084// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002085TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002086 FakeConstraints constraints;
2087 constraints.SetAllowRtpDataChannels();
2088 CreatePeerConnection(&constraints);
2089
2090 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002091 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002092 pc_->CreateDataChannel(label, nullptr);
2093 EXPECT_NE(channel, nullptr);
2094
zhihuang9763d562016-08-05 11:14:50 -07002095 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002096 pc_->CreateDataChannel(label, nullptr);
2097 EXPECT_EQ(dup_channel, nullptr);
2098}
2099
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100// This tests that a SCTP data channel is returned using different
2101// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002102TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 FakeConstraints constraints;
2104 constraints.SetAllowDtlsSctpDataChannels();
2105 CreatePeerConnection(&constraints);
2106
2107 webrtc::DataChannelInit config;
2108
zhihuang9763d562016-08-05 11:14:50 -07002109 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 pc_->CreateDataChannel("1", &config);
2111 EXPECT_TRUE(channel != NULL);
2112 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002113 EXPECT_TRUE(observer_.renegotiation_needed_);
2114 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 config.ordered = false;
2117 channel = pc_->CreateDataChannel("2", &config);
2118 EXPECT_TRUE(channel != NULL);
2119 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002120 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121
2122 config.ordered = true;
2123 config.maxRetransmits = 0;
2124 channel = pc_->CreateDataChannel("3", &config);
2125 EXPECT_TRUE(channel != NULL);
2126 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002127 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128
2129 config.maxRetransmits = -1;
2130 config.maxRetransmitTime = 0;
2131 channel = pc_->CreateDataChannel("4", &config);
2132 EXPECT_TRUE(channel != NULL);
2133 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002134 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135}
2136
2137// This tests that no data channel is returned if both maxRetransmits and
2138// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002139TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 CreateSctpDataChannelShouldFailForInvalidConfig) {
2141 FakeConstraints constraints;
2142 constraints.SetAllowDtlsSctpDataChannels();
2143 CreatePeerConnection(&constraints);
2144
2145 std::string label = "test";
2146 webrtc::DataChannelInit config;
2147 config.maxRetransmits = 0;
2148 config.maxRetransmitTime = 0;
2149
zhihuang9763d562016-08-05 11:14:50 -07002150 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 pc_->CreateDataChannel(label, &config);
2152 EXPECT_TRUE(channel == NULL);
2153}
2154
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155// The test verifies that creating a SCTP data channel with an id already in use
2156// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002157TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 CreateSctpDataChannelWithInvalidIdShouldFail) {
2159 FakeConstraints constraints;
2160 constraints.SetAllowDtlsSctpDataChannels();
2161 CreatePeerConnection(&constraints);
2162
2163 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002164 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002166 config.id = 1;
2167 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 EXPECT_TRUE(channel != NULL);
2169 EXPECT_EQ(1, channel->id());
2170
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 channel = pc_->CreateDataChannel("x", &config);
2172 EXPECT_TRUE(channel == NULL);
2173
2174 config.id = cricket::kMaxSctpSid;
2175 channel = pc_->CreateDataChannel("max", &config);
2176 EXPECT_TRUE(channel != NULL);
2177 EXPECT_EQ(config.id, channel->id());
2178
2179 config.id = cricket::kMaxSctpSid + 1;
2180 channel = pc_->CreateDataChannel("x", &config);
2181 EXPECT_TRUE(channel == NULL);
2182}
2183
deadbeefab9b2d12015-10-14 11:33:11 -07002184// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002185TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002186 FakeConstraints constraints;
2187 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2188 true);
2189 CreatePeerConnection(&constraints);
2190
2191 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002192 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002193 pc_->CreateDataChannel(label, nullptr);
2194 EXPECT_NE(channel, nullptr);
2195
zhihuang9763d562016-08-05 11:14:50 -07002196 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002197 pc_->CreateDataChannel(label, nullptr);
2198 EXPECT_NE(dup_channel, nullptr);
2199}
2200
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002201// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2202// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002203TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002204 FakeConstraints constraints;
2205 constraints.SetAllowRtpDataChannels();
2206 CreatePeerConnection(&constraints);
2207
zhihuang9763d562016-08-05 11:14:50 -07002208 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002209 pc_->CreateDataChannel("test1", NULL);
2210 EXPECT_TRUE(observer_.renegotiation_needed_);
2211 observer_.renegotiation_needed_ = false;
2212
zhihuang9763d562016-08-05 11:14:50 -07002213 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002214 pc_->CreateDataChannel("test2", NULL);
2215 EXPECT_TRUE(observer_.renegotiation_needed_);
2216}
2217
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002219TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 FakeConstraints constraints;
2221 constraints.SetAllowRtpDataChannels();
2222 CreatePeerConnection(&constraints);
2223
zhihuang9763d562016-08-05 11:14:50 -07002224 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002226 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 pc_->CreateDataChannel("test2", NULL);
2228 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002229 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002231 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 new MockDataChannelObserver(data2));
2233
2234 CreateOfferReceiveAnswer();
2235 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2236 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2237
2238 ReleasePeerConnection();
2239 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2240 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2241}
2242
Zhi Huang644fde42018-04-02 19:16:26 -07002243// This tests that RTP data channels can be rejected in an answer.
2244TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 FakeConstraints constraints;
2246 constraints.SetAllowRtpDataChannels();
2247 CreatePeerConnection(&constraints);
2248
zhihuang9763d562016-08-05 11:14:50 -07002249 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 pc_->CreateDataChannel("offer_channel", NULL));
2251
2252 CreateOfferAsLocalDescription();
2253
2254 // Create an answer where the m-line for data channels are rejected.
2255 std::string sdp;
2256 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002257 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002258 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002259 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002261 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 data_info->rejected = true;
2263
Steve Antondb45ca82017-09-11 18:27:34 -07002264 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2266}
2267
Zhi Huang644fde42018-04-02 19:16:26 -07002268#ifdef HAVE_SCTP
2269// This tests that SCTP data channels can be rejected in an answer.
2270TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2271#else
2272TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2273#endif
2274{
2275 FakeConstraints constraints;
2276 CreatePeerConnection(&constraints);
2277
2278 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2279 pc_->CreateDataChannel("offer_channel", NULL));
2280
2281 CreateOfferAsLocalDescription();
2282
2283 // Create an answer where the m-line for data channels are rejected.
2284 std::string sdp;
2285 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2286 std::unique_ptr<SessionDescriptionInterface> answer(
2287 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2288 ASSERT_TRUE(answer);
2289 cricket::ContentInfo* data_info =
2290 cricket::GetFirstDataContent(answer->description());
2291 data_info->rejected = true;
2292
2293 DoSetRemoteDescription(std::move(answer));
2294 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2295}
2296
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297// Test that we can create a session description from an SDP string from
2298// FireFox, use it as a remote session description, generate an answer and use
2299// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002300TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 FakeConstraints constraints;
2302 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2303 true);
2304 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002305 AddAudioTrack("audio_label");
2306 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002307 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002308 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002309 webrtc::kFireFoxSdpOffer, nullptr));
2310 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 CreateAnswerAsLocalDescription();
2312 ASSERT_TRUE(pc_->local_description() != NULL);
2313 ASSERT_TRUE(pc_->remote_description() != NULL);
2314
2315 const cricket::ContentInfo* content =
2316 cricket::GetFirstAudioContent(pc_->local_description()->description());
2317 ASSERT_TRUE(content != NULL);
2318 EXPECT_FALSE(content->rejected);
2319
2320 content =
2321 cricket::GetFirstVideoContent(pc_->local_description()->description());
2322 ASSERT_TRUE(content != NULL);
2323 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002324#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 content =
2326 cricket::GetFirstDataContent(pc_->local_description()->description());
2327 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002328 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002329#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330}
2331
zhihuangb19012e2017-09-19 13:47:59 -07002332// Test that fallback from DTLS to SDES is not supported.
2333// The fallback was previously supported but was removed to simplify the code
2334// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002335TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
deadbeef8662f942017-01-20 21:20:51 -08002336 FakeConstraints constraints;
2337 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2338 true);
2339 CreatePeerConnection(&constraints);
2340 // Wait for fake certificate to be generated. Previously, this is what caused
2341 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002342 AddAudioTrack("audio_label");
2343 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002344 ASSERT_NE(nullptr, fake_certificate_generator_);
2345 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2346 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002347 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002348 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2349 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002350 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002351}
2352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353// Test that we can create an audio only offer and receive an answer with a
2354// limited set of audio codecs and receive an updated offer with more audio
2355// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002356TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002357 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002358 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 CreateOfferAsLocalDescription();
2360
Steve Anton36da6ff2018-02-16 16:04:20 -08002361 const char* answer_sdp =
2362 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2363 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002364 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002365 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002366 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367
Steve Anton36da6ff2018-02-16 16:04:20 -08002368 const char* reoffer_sdp =
2369 (sdp_semantics_ == SdpSemantics::kPlanB
2370 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2371 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002372 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002373 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002374 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 CreateAnswerAsLocalDescription();
2376}
2377
deadbeefc80741f2015-10-22 13:14:45 -07002378// Test that if we're receiving (but not sending) a track, subsequent offers
2379// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002380TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002381 FakeConstraints constraints;
2382 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2383 true);
2384 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002385 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002386 CreateAnswerAsLocalDescription();
2387
2388 // At this point we should be receiving stream 1, but not sending anything.
2389 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002390 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002391 DoCreateOffer(&offer, nullptr);
2392
2393 const cricket::ContentInfo* video_content =
2394 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002395 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2396 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002397
2398 const cricket::ContentInfo* audio_content =
2399 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002400 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2401 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002402}
2403
2404// Test that if we're receiving (but not sending) a track, and the
2405// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2406// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002407TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002408 FakeConstraints constraints;
2409 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2410 true);
2411 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002412 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002413 CreateAnswerAsLocalDescription();
2414
2415 // At this point we should be receiving stream 1, but not sending anything.
2416 // A new offer would be recvonly, but we'll set the "no receive" constraints
2417 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002418 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002419 FakeConstraints offer_constraints;
2420 offer_constraints.AddMandatory(
2421 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2422 offer_constraints.AddMandatory(
2423 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2424 DoCreateOffer(&offer, &offer_constraints);
2425
2426 const cricket::ContentInfo* video_content =
2427 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002428 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2429 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002430
2431 const cricket::ContentInfo* audio_content =
2432 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002433 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2434 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002435}
2436
deadbeef653b8e02015-11-11 12:55:10 -08002437// Test that we can use SetConfiguration to change the ICE servers of the
2438// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002439TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002440 CreatePeerConnection();
2441
Steve Anton36da6ff2018-02-16 16:04:20 -08002442 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002443 PeerConnectionInterface::IceServer server;
2444 server.uri = "stun:test_hostname";
2445 config.servers.push_back(server);
2446 EXPECT_TRUE(pc_->SetConfiguration(config));
2447
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002448 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2449 EXPECT_EQ("test_hostname",
2450 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002451}
2452
Steve Anton36da6ff2018-02-16 16:04:20 -08002453TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002454 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002455 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002456 config.type = PeerConnectionInterface::kRelay;
2457 EXPECT_TRUE(pc_->SetConfiguration(config));
2458 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2459}
2460
Steve Anton36da6ff2018-02-16 16:04:20 -08002461TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002462 PeerConnectionInterface::RTCConfiguration config;
2463 config.prune_turn_ports = false;
2464 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002465 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002466 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2467
2468 config.prune_turn_ports = true;
2469 EXPECT_TRUE(pc_->SetConfiguration(config));
2470 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2471}
2472
skvladd1f5fda2017-02-03 16:54:05 -08002473// Test that the ice check interval can be changed. This does not verify that
2474// the setting makes it all the way to P2PTransportChannel, as that would
2475// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002476TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002477 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002478 config.ice_check_min_interval = absl::nullopt;
skvladd1f5fda2017-02-03 16:54:05 -08002479 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002480 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002481 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002482 EXPECT_TRUE(pc_->SetConfiguration(config));
2483 PeerConnectionInterface::RTCConfiguration new_config =
2484 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002485 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002486}
2487
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002488// Test that when SetConfiguration changes both the pool size and other
2489// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002490TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002491 SetConfigurationCreatesPooledSessionCorrectly) {
2492 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002493 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002494 config.ice_candidate_pool_size = 1;
2495 PeerConnectionInterface::IceServer server;
2496 server.uri = kStunAddressOnly;
2497 config.servers.push_back(server);
2498 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002499 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002500
2501 const cricket::FakePortAllocatorSession* session =
2502 static_cast<const cricket::FakePortAllocatorSession*>(
2503 port_allocator_->GetPooledSession());
2504 ASSERT_NE(nullptr, session);
2505 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002506}
2507
deadbeef293e9262017-01-11 12:28:30 -08002508// Test that after SetLocalDescription, changing the pool size is not allowed,
2509// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002510TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002511 CantChangePoolSizeAfterSetLocalDescription) {
2512 CreatePeerConnection();
2513 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002514 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002515 config.ice_candidate_pool_size = 1;
2516 EXPECT_TRUE(pc_->SetConfiguration(config));
2517
2518 // Set remote offer; can still change pool size at this point.
2519 CreateOfferAsRemoteDescription();
2520 config.ice_candidate_pool_size = 2;
2521 EXPECT_TRUE(pc_->SetConfiguration(config));
2522
2523 // Set local answer; now it's too late.
2524 CreateAnswerAsLocalDescription();
2525 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002526 RTCError error;
2527 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2528 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2529}
2530
deadbeef42a42632017-03-10 15:18:00 -08002531// Test that after setting an answer, extra pooled sessions are discarded. The
2532// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002533TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002534 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2535 CreatePeerConnection();
2536
2537 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002538 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002539 config.ice_candidate_pool_size = 4;
2540 EXPECT_TRUE(pc_->SetConfiguration(config));
2541
2542 // Do offer/answer.
2543 CreateOfferAsRemoteDescription();
2544 CreateAnswerAsLocalDescription();
2545
2546 // Expect no pooled sessions to be left.
2547 const cricket::PortAllocatorSession* session =
2548 port_allocator_->GetPooledSession();
2549 EXPECT_EQ(nullptr, session);
2550}
2551
2552// After Close is called, pooled candidates should be discarded so as to not
2553// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002554TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002555 CreatePeerConnection();
2556
Steve Anton36da6ff2018-02-16 16:04:20 -08002557 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002558 config.ice_candidate_pool_size = 3;
2559 EXPECT_TRUE(pc_->SetConfiguration(config));
2560 pc_->Close();
2561
2562 // Expect no pooled sessions to be left.
2563 const cricket::PortAllocatorSession* session =
2564 port_allocator_->GetPooledSession();
2565 EXPECT_EQ(nullptr, session);
2566}
2567
deadbeef293e9262017-01-11 12:28:30 -08002568// Test that SetConfiguration returns an invalid modification error if
2569// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002570TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002571 SetConfigurationReturnsInvalidModificationError) {
2572 PeerConnectionInterface::RTCConfiguration config;
2573 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2574 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2575 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2576 CreatePeerConnection(config, nullptr);
2577
Steve Anton36da6ff2018-02-16 16:04:20 -08002578 PeerConnectionInterface::RTCConfiguration modified_config =
2579 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002580 modified_config.bundle_policy =
2581 PeerConnectionInterface::kBundlePolicyMaxBundle;
2582 RTCError error;
2583 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2584 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2585
Steve Anton36da6ff2018-02-16 16:04:20 -08002586 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002587 modified_config.rtcp_mux_policy =
2588 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2589 error.set_type(RTCErrorType::NONE);
2590 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2591 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2592
Steve Anton36da6ff2018-02-16 16:04:20 -08002593 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002594 modified_config.continual_gathering_policy =
2595 PeerConnectionInterface::GATHER_CONTINUALLY;
2596 error.set_type(RTCErrorType::NONE);
2597 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2598 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2599}
2600
2601// Test that SetConfiguration returns a range error if the candidate pool size
2602// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002603TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002604 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2605 PeerConnectionInterface::RTCConfiguration config;
2606 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002607 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002608
2609 config.ice_candidate_pool_size = -1;
2610 RTCError error;
2611 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2612 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2613
2614 config.ice_candidate_pool_size = INT_MAX;
2615 error.set_type(RTCErrorType::NONE);
2616 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2617 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2618}
2619
2620// Test that SetConfiguration returns a syntax error if parsing an ICE server
2621// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002622TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002623 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2624 PeerConnectionInterface::RTCConfiguration config;
2625 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002626 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002627
2628 PeerConnectionInterface::IceServer bad_server;
2629 bad_server.uri = "stunn:www.example.com";
2630 config.servers.push_back(bad_server);
2631 RTCError error;
2632 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2633 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2634}
2635
2636// Test that SetConfiguration returns an invalid parameter error if a TURN
2637// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002638TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002639 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2640 PeerConnectionInterface::RTCConfiguration config;
2641 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002642 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002643
2644 PeerConnectionInterface::IceServer bad_server;
2645 bad_server.uri = "turn:www.example.com";
2646 // Missing password.
2647 bad_server.username = "foo";
2648 config.servers.push_back(bad_server);
2649 RTCError error;
2650 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2651 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002652}
2653
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654// Test that PeerConnection::Close changes the states to closed and all remote
2655// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002656TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657 // Initialize a PeerConnection and negotiate local and remote session
2658 // description.
2659 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002660
2661 // With Plan B, verify the stream count. The analog with Unified Plan is the
2662 // RtpTransceiver count.
2663 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2664 ASSERT_EQ(1u, pc_->local_streams()->count());
2665 ASSERT_EQ(1u, pc_->remote_streams()->count());
2666 } else {
2667 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2668 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669
2670 pc_->Close();
2671
2672 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2673 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2674 pc_->ice_connection_state());
2675 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2676 pc_->ice_gathering_state());
2677
Steve Anton36da6ff2018-02-16 16:04:20 -08002678 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2679 EXPECT_EQ(1u, pc_->local_streams()->count());
2680 EXPECT_EQ(1u, pc_->remote_streams()->count());
2681 } else {
2682 // Verify that the RtpTransceivers are still present but all stopped.
2683 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2684 for (auto transceiver : pc_->GetTransceivers()) {
2685 EXPECT_TRUE(transceiver->stopped());
2686 }
2687 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688
Steve Anton36da6ff2018-02-16 16:04:20 -08002689 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2690 ASSERT_TRUE(audio_receiver);
2691 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2692 ASSERT_TRUE(video_receiver);
2693
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002694 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002695 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002696 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002697 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002698 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699}
2700
2701// Test that PeerConnection methods fails gracefully after
2702// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002703// Don't run under Unified Plan since the stream API is not available.
2704TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002705 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002706 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 CreateOfferAsRemoteDescription();
2708 CreateAnswerAsLocalDescription();
2709
2710 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002711 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 pc_->local_streams()->at(0);
2713
2714 pc_->Close();
2715
2716 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002717 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2720
2721 EXPECT_TRUE(pc_->local_description() != NULL);
2722 EXPECT_TRUE(pc_->remote_description() != NULL);
2723
kwibergd1fe2812016-04-27 06:47:29 -07002724 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002725 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002726 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002727 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728
2729 std::string sdp;
2730 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002731 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002732 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002733 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734
2735 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002736 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002737 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002738 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739}
2740
2741// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002742TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 InitiateCall();
2744 pc_->Close();
2745 DoGetStats(NULL);
2746}
deadbeefab9b2d12015-10-14 11:33:11 -07002747
2748// NOTE: The series of tests below come from what used to be
2749// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2750// setting a remote or local description has the expected effects.
2751
2752// This test verifies that the remote MediaStreams corresponding to a received
2753// SDP string is created. In this test the two separate MediaStreams are
2754// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002755TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
deadbeefab9b2d12015-10-14 11:33:11 -07002756 FakeConstraints constraints;
2757 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2758 true);
2759 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002760 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002761
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002762 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002763 EXPECT_TRUE(
2764 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2765 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2766 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2767
2768 // Create a session description based on another SDP with another
2769 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002770 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002771
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002772 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002773 EXPECT_TRUE(
2774 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2775}
2776
2777// This test verifies that when remote tracks are added/removed from SDP, the
2778// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002779// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2780// specific behavior.
2781TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002782 AddRemoveTrackFromExistingRemoteMediaStream) {
2783 FakeConstraints constraints;
2784 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2785 true);
2786 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002787 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002788 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002789 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002790 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2791 reference_collection_));
2792
2793 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002794 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002795 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002796 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002797 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2798 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002799 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002800 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2801 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002802 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002803 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2804 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002805
2806 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002807 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002808 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002809 MockTrackObserver audio_track_observer(audio_track2);
2810 MockTrackObserver video_track_observer(video_track2);
2811
2812 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2813 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002814 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002815 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2816 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002817 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002818 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002819 audio_track2->state(), kTimeout);
2820 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2821 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002822}
2823
2824// This tests that remote tracks are ended if a local session description is set
2825// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002826TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002827 FakeConstraints constraints;
2828 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2829 true);
2830 CreatePeerConnection(&constraints);
2831 // First create and set a remote offer, then reject its video content in our
2832 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002833 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2834 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2835 ASSERT_TRUE(audio_receiver);
2836 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2837 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002838
Steve Anton36da6ff2018-02-16 16:04:20 -08002839 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2840 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002841 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002842 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2843 video_receiver->track();
2844 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002845
kwibergd1fe2812016-04-27 06:47:29 -07002846 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002847 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002848 cricket::ContentInfo* video_info =
2849 local_answer->description()->GetContentByName("video");
2850 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002851 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002852 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2853 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002854
2855 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002856 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002857 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002858 video_info = local_offer->description()->GetContentByName("video");
2859 ASSERT_TRUE(video_info != nullptr);
2860 video_info->rejected = true;
2861 cricket::ContentInfo* audio_info =
2862 local_offer->description()->GetContentByName("audio");
2863 ASSERT_TRUE(audio_info != nullptr);
2864 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002865 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002866 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002867 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2868 kTimeout);
2869 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2870 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002871}
2872
2873// This tests that we won't crash if the remote track has been removed outside
2874// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002875// Don't run under Unified Plan since the stream API is not available.
2876TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002877 FakeConstraints constraints;
2878 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2879 true);
2880 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002881 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002882 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2883 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2884 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2885
kwibergd1fe2812016-04-27 06:47:29 -07002886 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002887 webrtc::CreateSessionDescription(SdpType::kAnswer,
2888 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002889 cricket::ContentInfo* video_info =
2890 local_answer->description()->GetContentByName("video");
2891 video_info->rejected = true;
2892 cricket::ContentInfo* audio_info =
2893 local_answer->description()->GetContentByName("audio");
2894 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002895 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002896
2897 // No crash is a pass.
2898}
2899
deadbeef5e97fb52015-10-15 12:49:08 -07002900// This tests that if a recvonly remote description is set, no remote streams
2901// will be created, even if the description contains SSRCs/MSIDs.
2902// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002903TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
deadbeef5e97fb52015-10-15 12:49:08 -07002904 FakeConstraints constraints;
2905 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2906 true);
2907 CreatePeerConnection(&constraints);
2908
Steve Anton36da6ff2018-02-16 16:04:20 -08002909 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002910 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2911 strlen(kRecvonly), &recvonly_offer);
2912 CreateAndSetRemoteOffer(recvonly_offer);
2913
2914 EXPECT_EQ(0u, observer_.remote_streams()->count());
2915}
2916
deadbeefab9b2d12015-10-14 11:33:11 -07002917// This tests that a default MediaStream is created if a remote session
2918// description doesn't contain any streams and no MSID support.
2919// It also tests that the default stream is updated if a video m-line is added
2920// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002921// Don't run under Unified Plan since this behavior is Plan B specific.
2922TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002923 FakeConstraints constraints;
2924 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2925 true);
2926 CreatePeerConnection(&constraints);
2927 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2928
2929 ASSERT_EQ(1u, observer_.remote_streams()->count());
2930 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2931
2932 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2933 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002934 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002935
2936 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2937 ASSERT_EQ(1u, observer_.remote_streams()->count());
2938 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2939 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002940 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2941 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002942 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2943 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002944 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2945 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002946}
2947
2948// This tests that a default MediaStream is created if a remote session
2949// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002950// Don't run under Unified Plan since this behavior is Plan B specific.
2951TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002952 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002953 FakeConstraints constraints;
2954 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2955 true);
2956 CreatePeerConnection(&constraints);
2957 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2958
2959 ASSERT_EQ(1u, observer_.remote_streams()->count());
2960 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2961
2962 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2963 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002964 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002965}
2966
2967// This tests that it won't crash when PeerConnection tries to remove
2968// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002969// Don't run under Unified Plan since this behavior is Plan B specific.
2970TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002971 FakeConstraints constraints;
2972 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2973 true);
2974 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002975 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002976 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2977 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2978 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2979
2980 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2981
2982 // No crash is a pass.
2983}
2984
2985// This tests that a default MediaStream is created if the remote session
2986// description doesn't contain any streams and don't contain an indication if
2987// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002988// Don't run under Unified Plan since this behavior is Plan B specific.
2989TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002990 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002991 FakeConstraints constraints;
2992 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2993 true);
2994 CreatePeerConnection(&constraints);
2995 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2996
2997 ASSERT_EQ(1u, observer_.remote_streams()->count());
2998 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2999 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
3000 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3001}
3002
3003// This tests that a default MediaStream is not created if the remote session
3004// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003005// Don't run under Unified Plan since this behavior is Plan B specific.
3006TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003007 FakeConstraints constraints;
3008 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3009 true);
3010 CreatePeerConnection(&constraints);
3011 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3012 EXPECT_EQ(0u, observer_.remote_streams()->count());
3013}
3014
deadbeefbda7e0b2015-12-08 17:13:40 -08003015// This tests that when setting a new description, the old default tracks are
3016// not destroyed and recreated.
3017// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003018// Don't run under Unified Plan since this behavior is Plan B specific.
3019TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003020 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08003021 FakeConstraints constraints;
3022 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3023 true);
3024 CreatePeerConnection(&constraints);
3025 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3026
3027 ASSERT_EQ(1u, observer_.remote_streams()->count());
3028 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3029 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3030
3031 // Set the track to "disabled", then set a new description and ensure the
3032 // track is still disabled, which ensures it hasn't been recreated.
3033 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3034 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3035 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3036 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3037}
3038
deadbeefab9b2d12015-10-14 11:33:11 -07003039// This tests that a default MediaStream is not created if a remote session
3040// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003041// Don't run under Unified Plan since this behavior is Plan B specific.
3042TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
deadbeefab9b2d12015-10-14 11:33:11 -07003043 FakeConstraints constraints;
3044 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3045 true);
3046 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003047 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003048 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003049 EXPECT_TRUE(
3050 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3051
3052 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3053 EXPECT_EQ(0u, observer_.remote_streams()->count());
3054}
3055
Seth Hampson5897a6e2018-04-03 11:16:33 -07003056// This tests that a default MediaStream is created if a remote SDP comes from
3057// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3058TEST_F(PeerConnectionInterfaceTestPlanB,
3059 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
3060 FakeConstraints constraints;
3061 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3062 true);
3063 CreatePeerConnection(&constraints);
3064 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3065 // Add a=msid lines to simulate a Unified Plan endpoint that only
3066 // signals stream IDs with a=msid lines.
3067 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3068
3069 CreateAndSetRemoteOffer(sdp_string);
3070
3071 ASSERT_EQ(1u, observer_.remote_streams()->count());
3072 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3073 EXPECT_EQ("default", remote_stream->id());
3074 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3075}
3076
Seth Hampson5b4f0752018-04-02 16:31:36 -07003077// This tests that when a Plan B endpoint receives an SDP that signals no media
3078// stream IDs indicated by the special character "-" in the a=msid line, that
3079// a default stream ID will be used for the MediaStream ID. This can occur
3080// when a Unified Plan endpoint signals no media stream IDs, but signals both
3081// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3082TEST_F(PeerConnectionInterfaceTestPlanB,
3083 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
3084 FakeConstraints constraints;
3085 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3086 true);
3087 CreatePeerConnection(&constraints);
3088 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3089 // the sender's stream ID will be interpreted as no stream IDs.
3090 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3091 sdp_string.append("a=msid:- audiotrack0\n");
3092
3093 CreateAndSetRemoteOffer(sdp_string);
3094
3095 ASSERT_EQ(1u, observer_.remote_streams()->count());
3096 // Because SSRCs are signaled the track ID will be what was signaled in the
3097 // a=msid line.
3098 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3099 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3100 EXPECT_EQ("default", remote_stream->id());
3101 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003102
3103 // Previously a bug ocurred when setting the remote description a second time.
3104 // This is because we checked equality of the remote StreamParams stream ID
3105 // (empty), and the previously set stream ID for the remote sender
3106 // ("default"). This cause a track to be removed, then added, when really
3107 // nothing should occur because it is the same track.
3108 CreateAndSetRemoteOffer(sdp_string);
3109 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3110 EXPECT_EQ(1u, observer_.add_track_events_.size());
3111 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3112 remote_stream = observer_.remote_streams()->at(0);
3113 EXPECT_EQ("default", remote_stream->id());
3114 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003115}
3116
deadbeefab9b2d12015-10-14 11:33:11 -07003117// This tests that an RtpSender is created when the local description is set
3118// after adding a local stream.
3119// TODO(deadbeef): This test and the one below it need to be updated when
3120// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003121// Don't run under Unified Plan since this behavior is Plan B specific.
3122TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003123 FakeConstraints constraints;
3124 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3125 true);
3126 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003127
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003128 // Create an offer with 1 stream with 2 tracks of each type.
3129 rtc::scoped_refptr<StreamCollection> stream_collection =
3130 CreateStreamCollection(1, 2);
3131 pc_->AddStream(stream_collection->at(0));
3132 std::unique_ptr<SessionDescriptionInterface> offer;
3133 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003134 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003135
deadbeefab9b2d12015-10-14 11:33:11 -07003136 auto senders = pc_->GetSenders();
3137 EXPECT_EQ(4u, senders.size());
3138 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3139 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3140 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3141 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3142
3143 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003144 pc_->RemoveStream(stream_collection->at(0));
3145 stream_collection = CreateStreamCollection(1, 1);
3146 pc_->AddStream(stream_collection->at(0));
3147 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003148 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003149
deadbeefab9b2d12015-10-14 11:33:11 -07003150 senders = pc_->GetSenders();
3151 EXPECT_EQ(2u, senders.size());
3152 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3153 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3154 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3155 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3156}
3157
3158// This tests that an RtpSender is created when the local description is set
3159// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003160// Don't run under Unified Plan since this behavior is Plan B specific.
3161TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003162 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003163 FakeConstraints constraints;
3164 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3165 true);
3166 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003167
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003168 rtc::scoped_refptr<StreamCollection> stream_collection =
3169 CreateStreamCollection(1, 2);
3170 // Add a stream to create the offer, but remove it afterwards.
3171 pc_->AddStream(stream_collection->at(0));
3172 std::unique_ptr<SessionDescriptionInterface> offer;
3173 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3174 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003175
Steve Antondb45ca82017-09-11 18:27:34 -07003176 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003177 auto senders = pc_->GetSenders();
3178 EXPECT_EQ(0u, senders.size());
3179
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003180 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003181 senders = pc_->GetSenders();
3182 EXPECT_EQ(4u, senders.size());
3183 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3184 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3185 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3186 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3187}
3188
3189// This tests that the expected behavior occurs if the SSRC on a local track is
3190// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003191TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003192 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07003193 FakeConstraints constraints;
3194 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3195 true);
3196 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003197
Steve Anton36da6ff2018-02-16 16:04:20 -08003198 AddAudioTrack(kAudioTracks[0]);
3199 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003200 std::unique_ptr<SessionDescriptionInterface> offer;
3201 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3202 // Grab a copy of the offer before it gets passed into the PC.
Steve Antona3a92c22017-12-07 10:27:41 -08003203 auto modified_offer =
3204 rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003205 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
3206 offer->session_version());
Steve Antondb45ca82017-09-11 18:27:34 -07003207 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003208
deadbeefab9b2d12015-10-14 11:33:11 -07003209 auto senders = pc_->GetSenders();
3210 EXPECT_EQ(2u, senders.size());
3211 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3212 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3213
3214 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003215 cricket::MediaContentDescription* desc =
3216 cricket::GetFirstAudioContentDescription(modified_offer->description());
3217 ASSERT_TRUE(desc != NULL);
3218 for (StreamParams& stream : desc->mutable_streams()) {
3219 for (unsigned int& ssrc : stream.ssrcs) {
3220 ++ssrc;
3221 }
3222 }
deadbeefab9b2d12015-10-14 11:33:11 -07003223
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003224 desc =
3225 cricket::GetFirstVideoContentDescription(modified_offer->description());
3226 ASSERT_TRUE(desc != NULL);
3227 for (StreamParams& stream : desc->mutable_streams()) {
3228 for (unsigned int& ssrc : stream.ssrcs) {
3229 ++ssrc;
3230 }
3231 }
3232
Steve Antondb45ca82017-09-11 18:27:34 -07003233 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003234 senders = pc_->GetSenders();
3235 EXPECT_EQ(2u, senders.size());
3236 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3237 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3238 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3239 // changed.
3240}
3241
3242// This tests that the expected behavior occurs if a new session description is
3243// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003244// Don't run under Unified Plan since the stream API is not available.
3245TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003246 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003247 FakeConstraints constraints;
3248 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3249 true);
3250 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003251
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003252 rtc::scoped_refptr<StreamCollection> stream_collection =
3253 CreateStreamCollection(2, 1);
3254 pc_->AddStream(stream_collection->at(0));
3255 std::unique_ptr<SessionDescriptionInterface> offer;
3256 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003257 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003258
deadbeefab9b2d12015-10-14 11:33:11 -07003259 auto senders = pc_->GetSenders();
3260 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003261 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3262 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003263
3264 // Add a new MediaStream but with the same tracks as in the first stream.
3265 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3266 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003267 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3268 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003269 pc_->AddStream(stream_1);
3270
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003271 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003272 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003273
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003274 auto new_senders = pc_->GetSenders();
3275 // Should be the same senders as before, but with updated stream id.
3276 // Note that this behavior is subject to change in the future.
3277 // We may decide the PC should ignore existing tracks in AddStream.
3278 EXPECT_EQ(senders, new_senders);
3279 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3280 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003281}
3282
zhihuang81c3a032016-11-17 12:06:24 -08003283// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003284TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
zhihuang81c3a032016-11-17 12:06:24 -08003285 FakeConstraints constraints;
3286 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3287 true);
3288 CreatePeerConnection(&constraints);
3289 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3290 EXPECT_EQ(observer_.num_added_tracks_, 1);
3291 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3292
3293 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003294 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3295 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3296 EXPECT_EQ(observer_.num_added_tracks_, 2);
3297 } else {
3298 // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription
3299 // is called until the offer/answer exchange is complete. So in this case
3300 // OnAddTrack is fired twice for the first audio track plus the one time
3301 // for the video track.
3302 EXPECT_EQ(observer_.num_added_tracks_, 3);
3303 }
zhihuang81c3a032016-11-17 12:06:24 -08003304 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3305}
3306
deadbeefd1a38b52016-12-10 13:15:33 -08003307// Test that when SetConfiguration is called and the configuration is
3308// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003309TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003310 PeerConnectionInterface::RTCConfiguration config;
3311 config.type = PeerConnectionInterface::kRelay;
3312 // Need to pass default constraints to prevent disabling of DTLS...
3313 FakeConstraints default_constraints;
3314 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003315 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003316 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3317 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003318
3319 // Do initial offer/answer so there's something to restart.
3320 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003321 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003322
3323 // Grab the ufrags.
3324 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3325
3326 // Change ICE policy, which should trigger an ICE restart on the next offer.
3327 config.type = PeerConnectionInterface::kAll;
3328 EXPECT_TRUE(pc_->SetConfiguration(config));
3329 CreateOfferAsLocalDescription();
3330
3331 // Grab the new ufrags.
3332 std::vector<std::string> subsequent_ufrags =
3333 GetUfrags(pc_->local_description());
3334
3335 // Sanity check.
3336 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3337 // Check that each ufrag is different.
3338 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3339 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3340 }
3341}
3342
3343// Test that when SetConfiguration is called and the configuration *isn't*
3344// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003345TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003346 PeerConnectionInterface::RTCConfiguration config;
3347 config.type = PeerConnectionInterface::kRelay;
3348 // Need to pass default constraints to prevent disabling of DTLS...
3349 FakeConstraints default_constraints;
3350 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003351 config = pc_->GetConfiguration();
3352 AddAudioTrack(kAudioTracks[0]);
3353 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003354
3355 // Do initial offer/answer so there's something to restart.
3356 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003357 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003358
3359 // Grab the ufrags.
3360 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3361
3362 // Call SetConfiguration with a config identical to what the PC was
3363 // constructed with.
3364 EXPECT_TRUE(pc_->SetConfiguration(config));
3365 CreateOfferAsLocalDescription();
3366
3367 // Grab the new ufrags.
3368 std::vector<std::string> subsequent_ufrags =
3369 GetUfrags(pc_->local_description());
3370
3371 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3372}
3373
3374// Test for a weird corner case scenario:
3375// 1. Audio/video session established.
3376// 2. SetConfiguration changes ICE config; ICE restart needed.
3377// 3. ICE restart initiated by remote peer, but only for one m= section.
3378// 4. Next createOffer should initiate an ICE restart, but only for the other
3379// m= section; it would be pointless to do an ICE restart for the m= section
3380// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003381TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003382 PeerConnectionInterface::RTCConfiguration config;
3383 config.type = PeerConnectionInterface::kRelay;
3384 // Need to pass default constraints to prevent disabling of DTLS...
3385 FakeConstraints default_constraints;
3386 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003387 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003388 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3389 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003390
3391 // Do initial offer/answer so there's something to restart.
3392 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003393 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003394
3395 // Change ICE policy, which should set the "needs-ice-restart" flag.
3396 config.type = PeerConnectionInterface::kAll;
3397 EXPECT_TRUE(pc_->SetConfiguration(config));
3398
3399 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003400 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003401 webrtc::CreateSessionDescription(SdpType::kOffer,
3402 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003403 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003404 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3405 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003406 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003407 CreateAnswerAsLocalDescription();
3408
3409 // Grab the ufrags.
3410 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3411 ASSERT_EQ(2, initial_ufrags.size());
3412
3413 // Create offer and grab the new ufrags.
3414 CreateOfferAsLocalDescription();
3415 std::vector<std::string> subsequent_ufrags =
3416 GetUfrags(pc_->local_description());
3417 ASSERT_EQ(2, subsequent_ufrags.size());
3418
3419 // Ensure that only the ufrag for the second m= section changed.
3420 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3421 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3422}
3423
deadbeeffe4a8a42016-12-20 17:56:17 -08003424// Tests that the methods to return current/pending descriptions work as
3425// expected at different points in the offer/answer exchange. This test does
3426// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003427TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003428 // This disables DTLS so we can apply an answer to ourselves.
3429 CreatePeerConnection();
3430
3431 // Create initial local offer and get SDP (which will also be used as
3432 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003433 std::unique_ptr<SessionDescriptionInterface> local_offer;
3434 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003435 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003436 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003437
3438 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003439 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3440 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3441 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003442 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3443 EXPECT_EQ(nullptr, pc_->current_local_description());
3444 EXPECT_EQ(nullptr, pc_->current_remote_description());
3445
3446 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003447 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003448 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003449 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3450 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3451 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3452 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003453 EXPECT_EQ(nullptr, pc_->current_local_description());
3454 EXPECT_EQ(nullptr, pc_->current_remote_description());
3455
3456 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003457 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003458 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003459 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3460 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003461 EXPECT_EQ(nullptr, pc_->pending_local_description());
3462 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003463 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3464 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003465
3466 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003467 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003468 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003469 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3470 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3471 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003472 EXPECT_EQ(nullptr, pc_->pending_local_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 local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003477 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003478 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003479 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3480 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3481 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3482 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3483 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 answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003487 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003488 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003489 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3490 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003491 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3492 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003493 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3494 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003495}
3496
zhihuang77985012017-02-07 15:45:16 -08003497// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3498// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003499// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003500TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003501 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003502 CreatePeerConnection();
3503 // The RtcEventLog will be reset when the PeerConnection is closed.
3504 pc_->Close();
3505
Elad Alon9e6565b2017-10-11 16:04:13 +02003506 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3507 std::string filename = webrtc::test::OutputPath() +
3508 test_info->test_case_name() + test_info->name();
3509 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3510
3511 constexpr int64_t max_size_bytes = 1024;
3512
zhihuang77985012017-02-07 15:45:16 -08003513 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3514 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003515
3516 // Cleanup.
3517 rtc::ClosePlatformFile(file);
3518 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003519}
3520
Elad Alon99c3fe52017-10-13 16:29:40 +02003521// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3522// after the PeerConnection is closed.
3523// This version tests the StartRtcEventLog version that receives an object
3524// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003525TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003526 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3527 CreatePeerConnection();
3528 // The RtcEventLog will be reset when the PeerConnection is closed.
3529 pc_->Close();
3530
3531 rtc::PlatformFile file = 0;
3532 int64_t max_size_bytes = 1024;
3533 EXPECT_FALSE(pc_->StartRtcEventLog(
Bjorn Tereliusde939432017-11-20 17:38:14 +01003534 rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
3535 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003536 pc_->StopRtcEventLog();
3537}
3538
deadbeef30952b42017-04-21 02:41:29 -07003539// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003540TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003541 CreatePeerConnection();
3542
3543 // First, create an offer with audio/video.
3544 FakeConstraints constraints;
3545 constraints.SetMandatoryReceiveAudio(true);
3546 constraints.SetMandatoryReceiveVideo(true);
3547 std::unique_ptr<SessionDescriptionInterface> offer;
3548 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3549 cricket::SessionDescription* desc = offer->description();
3550 ASSERT_EQ(2u, desc->transport_infos().size());
3551 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3552 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3553
3554 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003555 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003556 std::unique_ptr<SessionDescriptionInterface> answer;
3557 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3558 desc = answer->description();
3559 ASSERT_EQ(2u, desc->transport_infos().size());
3560 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3561 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3562}
3563
deadbeef1dcb1642017-03-29 21:08:16 -07003564// Test that ICE renomination isn't offered if it's not enabled in the PC's
3565// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003566TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003567 PeerConnectionInterface::RTCConfiguration config;
3568 config.enable_ice_renomination = false;
3569 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003570 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003571
3572 std::unique_ptr<SessionDescriptionInterface> offer;
3573 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3574 cricket::SessionDescription* desc = offer->description();
3575 EXPECT_EQ(1u, desc->transport_infos().size());
3576 EXPECT_FALSE(
3577 desc->transport_infos()[0].description.GetIceParameters().renomination);
3578}
3579
3580// Test that the ICE renomination option is present in generated offers/answers
3581// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003582TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003583 PeerConnectionInterface::RTCConfiguration config;
3584 config.enable_ice_renomination = true;
3585 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003586 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003587
3588 std::unique_ptr<SessionDescriptionInterface> offer;
3589 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3590 cricket::SessionDescription* desc = offer->description();
3591 EXPECT_EQ(1u, desc->transport_infos().size());
3592 EXPECT_TRUE(
3593 desc->transport_infos()[0].description.GetIceParameters().renomination);
3594
3595 // Set the offer as a remote description, then create an answer and ensure it
3596 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003597 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003598 std::unique_ptr<SessionDescriptionInterface> answer;
3599 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3600 desc = answer->description();
3601 EXPECT_EQ(1u, desc->transport_infos().size());
3602 EXPECT_TRUE(
3603 desc->transport_infos()[0].description.GetIceParameters().renomination);
3604}
3605
3606// Test that if CreateOffer is called with the deprecated "offer to receive
3607// audio/video" constraints, they're processed and result in an offer with
3608// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003609TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003610 CreatePeerConnection();
3611
3612 FakeConstraints constraints;
3613 constraints.SetMandatoryReceiveAudio(true);
3614 constraints.SetMandatoryReceiveVideo(true);
3615 std::unique_ptr<SessionDescriptionInterface> offer;
3616 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3617
3618 cricket::SessionDescription* desc = offer->description();
3619 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3620 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3621 ASSERT_NE(nullptr, audio);
3622 ASSERT_NE(nullptr, video);
3623 EXPECT_FALSE(audio->rejected);
3624 EXPECT_FALSE(video->rejected);
3625}
3626
3627// Test that if CreateAnswer is called with the deprecated "offer to receive
3628// audio/video" constraints, they're processed and can be used to reject an
3629// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003630// Don't run under Unified Plan since this behavior is not supported.
3631TEST_F(PeerConnectionInterfaceTestPlanB,
3632 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003633 CreatePeerConnection();
3634
3635 // First, create an offer with audio/video and apply it as a remote
3636 // description.
3637 FakeConstraints constraints;
3638 constraints.SetMandatoryReceiveAudio(true);
3639 constraints.SetMandatoryReceiveVideo(true);
3640 std::unique_ptr<SessionDescriptionInterface> offer;
3641 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
Steve Antondb45ca82017-09-11 18:27:34 -07003642 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003643
3644 // Now create answer that rejects audio/video.
3645 constraints.SetMandatoryReceiveAudio(false);
3646 constraints.SetMandatoryReceiveVideo(false);
3647 std::unique_ptr<SessionDescriptionInterface> answer;
3648 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3649
3650 cricket::SessionDescription* desc = answer->description();
3651 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3652 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3653 ASSERT_NE(nullptr, audio);
3654 ASSERT_NE(nullptr, video);
3655 EXPECT_TRUE(audio->rejected);
3656 EXPECT_TRUE(video->rejected);
3657}
3658
deadbeef1dcb1642017-03-29 21:08:16 -07003659// Test that negotiation can succeed with a data channel only, and with the max
3660// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003661#ifdef HAVE_SCTP
3662TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3663#else
3664TEST_P(PeerConnectionInterfaceTest,
3665 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3666#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003667 PeerConnectionInterface::RTCConfiguration config;
3668 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3669 CreatePeerConnection(config, nullptr);
3670
3671 // First, create an offer with only a data channel and apply it as a remote
3672 // description.
3673 pc_->CreateDataChannel("test", nullptr);
3674 std::unique_ptr<SessionDescriptionInterface> offer;
3675 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003676 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003677
3678 // Create and set answer as well.
3679 std::unique_ptr<SessionDescriptionInterface> answer;
3680 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003681 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003682}
3683
Steve Anton36da6ff2018-02-16 16:04:20 -08003684TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003685 CreatePeerConnection();
3686 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003687 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003688 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3689}
3690
Steve Anton36da6ff2018-02-16 16:04:20 -08003691TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003692 CreatePeerConnection();
3693 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003694 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003695 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3696}
3697
Steve Anton36da6ff2018-02-16 16:04:20 -08003698TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003699 CreatePeerConnection();
3700 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003701 bitrate.min_bitrate_bps = 5;
3702 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003703 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3704}
3705
Steve Anton36da6ff2018-02-16 16:04:20 -08003706TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003707 CreatePeerConnection();
3708 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003709 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003710 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3711}
3712
Steve Anton36da6ff2018-02-16 16:04:20 -08003713TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003714 CreatePeerConnection();
3715 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003716 bitrate.current_bitrate_bps = 10;
3717 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003718 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3719}
3720
Steve Anton36da6ff2018-02-16 16:04:20 -08003721TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003722 CreatePeerConnection();
3723 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003724 bitrate.min_bitrate_bps = 10;
3725 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003726 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3727}
3728
Steve Anton36da6ff2018-02-16 16:04:20 -08003729TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003730 CreatePeerConnection();
3731 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003732 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003733 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3734}
3735
Steve Anton038834f2017-07-14 15:59:59 -07003736// ice_regather_interval_range requires WebRTC to be configured for continual
3737// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003738TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003739 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3740 PeerConnectionInterface::RTCConfiguration config;
3741 config.ice_regather_interval_range.emplace(1000, 2000);
3742 config.continual_gathering_policy =
3743 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3744 CreatePeerConnectionExpectFail(config);
3745}
3746
3747// Ensures that there is no error when ice_regather_interval_range is set with
3748// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003749TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003750 SetIceRegatherIntervalRangeWithContinualGathering) {
3751 PeerConnectionInterface::RTCConfiguration config;
3752 config.ice_regather_interval_range.emplace(1000, 2000);
3753 config.continual_gathering_policy =
3754 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3755 CreatePeerConnection(config, nullptr);
3756}
3757
Niels Möller0c4f7be2018-05-07 14:01:37 +02003758// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003759// by Call's BitrateConstraints, which comes from the SDP or a default value.
3760// This test checks that a call to SetBitrate with a current bitrate that will
3761// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003762TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003763 CreatePeerConnection();
3764 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003765 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003766 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3767}
3768
zhihuang1c378ed2017-08-17 14:10:50 -07003769// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003770TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003771 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3772 RTCOfferAnswerOptions rtc_options;
3773
3774 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3775 // than kMaxOfferToReceiveMedia should be treated as invalid.
3776 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3777 CreatePeerConnection();
3778 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3779
3780 rtc_options.offer_to_receive_audio =
3781 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3782 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3783}
3784
Steve Anton36da6ff2018-02-16 16:04:20 -08003785TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003786 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3787 RTCOfferAnswerOptions rtc_options;
3788
3789 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3790 // than kMaxOfferToReceiveMedia should be treated as invalid.
3791 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3792 CreatePeerConnection();
3793 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3794
3795 rtc_options.offer_to_receive_video =
3796 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3797 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3798}
3799
3800// Test that the audio and video content will be added to an offer if both
3801// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003802TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003803 RTCOfferAnswerOptions rtc_options;
3804 rtc_options.offer_to_receive_audio = 1;
3805 rtc_options.offer_to_receive_video = 1;
3806
3807 std::unique_ptr<SessionDescriptionInterface> offer;
3808 CreatePeerConnection();
3809 offer = CreateOfferWithOptions(rtc_options);
3810 ASSERT_TRUE(offer);
3811 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3812 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3813}
3814
3815// Test that only audio content will be added to the offer if only
3816// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003817TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003818 RTCOfferAnswerOptions rtc_options;
3819 rtc_options.offer_to_receive_audio = 1;
3820 rtc_options.offer_to_receive_video = 0;
3821
3822 std::unique_ptr<SessionDescriptionInterface> offer;
3823 CreatePeerConnection();
3824 offer = CreateOfferWithOptions(rtc_options);
3825 ASSERT_TRUE(offer);
3826 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3827 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3828}
3829
3830// Test that only video content will be added if only |offer_to_receive_video|
3831// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003832TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003833 RTCOfferAnswerOptions rtc_options;
3834 rtc_options.offer_to_receive_audio = 0;
3835 rtc_options.offer_to_receive_video = 1;
3836
3837 std::unique_ptr<SessionDescriptionInterface> offer;
3838 CreatePeerConnection();
3839 offer = CreateOfferWithOptions(rtc_options);
3840 ASSERT_TRUE(offer);
3841 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3842 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3843}
3844
zhihuang1c378ed2017-08-17 14:10:50 -07003845// Test that no media content will be added to the offer if using default
3846// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003847TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003848 RTCOfferAnswerOptions rtc_options;
3849
3850 std::unique_ptr<SessionDescriptionInterface> offer;
3851 CreatePeerConnection();
3852 offer = CreateOfferWithOptions(rtc_options);
3853 ASSERT_TRUE(offer);
3854 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3855 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3856}
3857
3858// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3859// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003860TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3861 CreatePeerConnection();
3862
zhihuang1c378ed2017-08-17 14:10:50 -07003863 RTCOfferAnswerOptions rtc_options;
3864 rtc_options.ice_restart = false;
3865 rtc_options.offer_to_receive_audio = 1;
3866
3867 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003868 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003869 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3870 auto ufrag1 =
3871 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3872 auto pwd1 =
3873 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003874
3875 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3876 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003877 auto ufrag2 =
3878 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3879 auto pwd2 =
3880 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003881
3882 // |ice_restart| is true, the ufrag/pwd should change.
3883 rtc_options.ice_restart = true;
3884 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003885 auto ufrag3 =
3886 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3887 auto pwd3 =
3888 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003889
3890 EXPECT_EQ(ufrag1, ufrag2);
3891 EXPECT_EQ(pwd1, pwd2);
3892 EXPECT_NE(ufrag2, ufrag3);
3893 EXPECT_NE(pwd2, pwd3);
3894}
3895
3896// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3897// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003898TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003899 RTCOfferAnswerOptions rtc_options;
3900 rtc_options.offer_to_receive_audio = 1;
3901 rtc_options.offer_to_receive_video = 1;
3902
3903 std::unique_ptr<SessionDescriptionInterface> offer;
3904 CreatePeerConnection();
3905
3906 rtc_options.use_rtp_mux = true;
3907 offer = CreateOfferWithOptions(rtc_options);
3908 ASSERT_TRUE(offer);
3909 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3910 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3911 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3912
3913 rtc_options.use_rtp_mux = false;
3914 offer = CreateOfferWithOptions(rtc_options);
3915 ASSERT_TRUE(offer);
3916 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3917 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3918 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3919}
3920
zhihuang141aacb2017-08-29 13:23:53 -07003921// This test ensures OnRenegotiationNeeded is called when we add track with
3922// MediaStream -> AddTrack in the same way it is called when we add track with
3923// PeerConnection -> AddTrack.
3924// The test can be removed once addStream is rewritten in terms of addTrack
3925// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003926// Don't run under Unified Plan since the stream API is not available.
3927TEST_F(PeerConnectionInterfaceTestPlanB,
3928 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003929 CreatePeerConnectionWithoutDtls();
3930 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003931 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003932 pc_->AddStream(stream);
3933 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3934 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3935 rtc::scoped_refptr<VideoTrackInterface> video_track(
3936 pc_factory_->CreateVideoTrack(
3937 "video_track", pc_factory_->CreateVideoSource(
3938 std::unique_ptr<cricket::VideoCapturer>(
3939 new cricket::FakeVideoCapturer()))));
3940 stream->AddTrack(audio_track);
3941 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3942 observer_.renegotiation_needed_ = false;
3943
3944 stream->AddTrack(video_track);
3945 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3946 observer_.renegotiation_needed_ = false;
3947
3948 stream->RemoveTrack(audio_track);
3949 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3950 observer_.renegotiation_needed_ = false;
3951
3952 stream->RemoveTrack(video_track);
3953 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3954 observer_.renegotiation_needed_ = false;
3955}
3956
Zhi Huangb2d355e2017-10-26 17:26:37 -07003957// Tests that an error is returned if a description is applied that has fewer
3958// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003959TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003960 MediaSectionCountEnforcedForSubsequentOffer) {
3961 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003962 AddAudioTrack("audio_label");
3963 AddVideoTrack("video_label");
3964
Zhi Huangb2d355e2017-10-26 17:26:37 -07003965 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003966 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003967 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3968
3969 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003970 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003971 offer->description()->contents().pop_back();
3972 offer->description()->contents().pop_back();
3973 ASSERT_TRUE(offer->description()->contents().empty());
3974 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3975
3976 std::unique_ptr<SessionDescriptionInterface> answer;
3977 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3978 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3979
3980 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003981 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003982 offer->description()->contents().pop_back();
3983 offer->description()->contents().pop_back();
3984 ASSERT_TRUE(offer->description()->contents().empty());
3985 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3986}
3987
Steve Anton36da6ff2018-02-16 16:04:20 -08003988INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3989 PeerConnectionInterfaceTest,
3990 Values(SdpSemantics::kPlanB,
3991 SdpSemantics::kUnifiedPlan));
3992
nisse51542be2016-02-12 02:27:06 -08003993class PeerConnectionMediaConfigTest : public testing::Test {
3994 protected:
3995 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003996 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003997 pcf_->Initialize();
3998 }
nisseeaabdf62017-05-05 02:23:02 -07003999 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08004000 const PeerConnectionInterface::RTCConfiguration& config,
zhihuang1c378ed2017-08-17 14:10:50 -07004001 const MediaConstraintsInterface* constraints) {
zhihuang9763d562016-08-05 11:14:50 -07004002 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
4003 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08004004 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07004005 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08004006 }
4007
zhihuang9763d562016-08-05 11:14:50 -07004008 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08004009 MockPeerConnectionObserver observer_;
4010};
4011
4012// This test verifies the default behaviour with no constraints and a
4013// default RTCConfiguration.
4014TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4015 PeerConnectionInterface::RTCConfiguration config;
4016 FakeConstraints constraints;
4017
4018 const cricket::MediaConfig& media_config =
4019 TestCreatePeerConnection(config, &constraints);
4020
4021 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004022 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4023 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004024 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004025 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004026}
4027
4028// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07004029// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004030TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
4031 PeerConnectionInterface::RTCConfiguration config;
4032 FakeConstraints constraints;
4033
4034 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
4035 const cricket::MediaConfig& media_config =
4036 TestCreatePeerConnection(config, &constraints);
4037
4038 EXPECT_TRUE(media_config.enable_dscp);
4039}
4040
4041// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07004042// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004043TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
4044 PeerConnectionInterface::RTCConfiguration config;
4045 FakeConstraints constraints;
4046
4047 constraints.AddOptional(
4048 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
4049 const cricket::MediaConfig media_config =
4050 TestCreatePeerConnection(config, &constraints);
4051
Niels Möller1d7ecd22018-01-18 15:25:12 +01004052 EXPECT_FALSE(media_config.video.enable_cpu_adaptation);
nisse51542be2016-02-12 02:27:06 -08004053}
4054
Niels Möller1d7ecd22018-01-18 15:25:12 +01004055// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004056// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004057TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4058 PeerConnectionInterface::RTCConfiguration config;
4059 FakeConstraints constraints;
4060
Niels Möller71bdda02016-03-31 12:59:59 +02004061 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08004062 const cricket::MediaConfig& media_config =
4063 TestCreatePeerConnection(config, &constraints);
4064
Niels Möller1d7ecd22018-01-18 15:25:12 +01004065 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004066}
4067
Niels Möller6539f692018-01-18 08:58:50 +01004068// This test verifies that the experiment_cpu_load_estimator flag is
4069// propagated from RTCConfiguration to the PeerConnection.
4070TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4071 PeerConnectionInterface::RTCConfiguration config;
4072 FakeConstraints constraints;
4073
4074 config.set_experiment_cpu_load_estimator(true);
4075 const cricket::MediaConfig& media_config =
4076 TestCreatePeerConnection(config, &constraints);
4077
4078 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4079}
4080
nisse0db023a2016-03-01 04:29:59 -08004081// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07004082// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08004083TEST_F(PeerConnectionMediaConfigTest,
4084 TestSuspendBelowMinBitrateConstraintTrue) {
4085 PeerConnectionInterface::RTCConfiguration config;
4086 FakeConstraints constraints;
4087
4088 constraints.AddOptional(
4089 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4090 true);
4091 const cricket::MediaConfig media_config =
4092 TestCreatePeerConnection(config, &constraints);
4093
4094 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08004095}
4096
deadbeef293e9262017-01-11 12:28:30 -08004097// Tests a few random fields being different.
4098TEST(RTCConfigurationTest, ComparisonOperators) {
4099 PeerConnectionInterface::RTCConfiguration a;
4100 PeerConnectionInterface::RTCConfiguration b;
4101 EXPECT_EQ(a, b);
4102
4103 PeerConnectionInterface::RTCConfiguration c;
4104 c.servers.push_back(PeerConnectionInterface::IceServer());
4105 EXPECT_NE(a, c);
4106
4107 PeerConnectionInterface::RTCConfiguration d;
4108 d.type = PeerConnectionInterface::kRelay;
4109 EXPECT_NE(a, d);
4110
4111 PeerConnectionInterface::RTCConfiguration e;
4112 e.audio_jitter_buffer_max_packets = 5;
4113 EXPECT_NE(a, e);
4114
4115 PeerConnectionInterface::RTCConfiguration f;
4116 f.ice_connection_receiving_timeout = 1337;
4117 EXPECT_NE(a, f);
4118
4119 PeerConnectionInterface::RTCConfiguration g;
4120 g.disable_ipv6 = true;
4121 EXPECT_NE(a, g);
4122
4123 PeerConnectionInterface::RTCConfiguration h(
4124 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4125 EXPECT_NE(a, h);
4126}