blob: 0f855494006a1c1c6aa8b6c03c589afcfa33f91c [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
Karl Wiberg918f50c2018-07-05 11:40:33 +020017#include "absl/memory/memory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio_codecs/builtin_audio_decoder_factory.h"
19#include "api/audio_codecs/builtin_audio_encoder_factory.h"
20#include "api/jsepsessiondescription.h"
21#include "api/mediastreaminterface.h"
22#include "api/peerconnectioninterface.h"
23#include "api/rtpreceiverinterface.h"
24#include "api/rtpsenderinterface.h"
Jiawei Oube142172018-10-10 01:16:20 -070025#include "api/video/builtin_video_bitrate_allocator_factory.h"
Anders Carlsson67537952018-05-03 11:28:29 +020026#include "api/video_codecs/builtin_video_decoder_factory.h"
27#include "api/video_codecs/builtin_video_encoder_factory.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020028#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "media/base/fakevideocapturer.h"
30#include "media/engine/webrtcmediaengine.h"
31#include "media/sctp/sctptransportinternal.h"
32#include "modules/audio_processing/include/audio_processing.h"
33#include "p2p/base/fakeportallocator.h"
34#include "pc/audiotrack.h"
35#include "pc/mediasession.h"
36#include "pc/mediastream.h"
37#include "pc/peerconnection.h"
Steve Anton57858b32018-02-15 15:19:50 -080038#include "pc/rtpsender.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "pc/streamcollection.h"
40#include "pc/test/fakeaudiocapturemodule.h"
41#include "pc/test/fakertccertificategenerator.h"
42#include "pc/test/fakevideotracksource.h"
43#include "pc/test/mockpeerconnectionobservers.h"
44#include "pc/test/testsdpstrings.h"
45#include "pc/videocapturertracksource.h"
46#include "pc/videotrack.h"
47#include "rtc_base/gunit.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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420using webrtc::IceCandidateInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700421using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422using webrtc::MediaStreamInterface;
423using webrtc::MediaStreamTrackInterface;
424using webrtc::MockCreateSessionDescriptionObserver;
425using webrtc::MockDataChannelObserver;
Steve Anton94286cb2017-09-26 16:20:19 -0700426using webrtc::MockPeerConnectionObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427using webrtc::MockSetSessionDescriptionObserver;
428using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700429using webrtc::NotifierInterface;
430using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431using webrtc::PeerConnectionInterface;
432using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800433using webrtc::RTCError;
434using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700435using webrtc::RtpReceiverInterface;
436using webrtc::RtpSenderInterface;
Steve Anton57858b32018-02-15 15:19:50 -0800437using webrtc::RtpSenderProxyWithInternal;
438using webrtc::RtpSenderInternal;
Steve Anton4e70a722017-11-28 14:57:10 -0800439using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440using webrtc::SdpParseError;
Steve Anton36da6ff2018-02-16 16:04:20 -0800441using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800442using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700444using webrtc::StreamCollection;
445using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100446using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700447using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448using webrtc::VideoTrackInterface;
449
Steve Anton36da6ff2018-02-16 16:04:20 -0800450using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
451using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700452
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453namespace {
454
455// Gets the first ssrc of given content type from the ContentInfo.
456bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
457 if (!content_info || !ssrc) {
458 return false;
459 }
460 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800461 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 if (!media_desc || media_desc->streams().empty()) {
463 return false;
464 }
465 *ssrc = media_desc->streams().begin()->first_ssrc();
466 return true;
467}
468
deadbeefd1a38b52016-12-10 13:15:33 -0800469// Get the ufrags out of an SDP blob. Useful for testing ICE restart
470// behavior.
471std::vector<std::string> GetUfrags(
472 const webrtc::SessionDescriptionInterface* desc) {
473 std::vector<std::string> ufrags;
474 for (const cricket::TransportInfo& info :
475 desc->description()->transport_infos()) {
476 ufrags.push_back(info.description.ice_ufrag);
477 }
478 return ufrags;
479}
480
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481void SetSsrcToZero(std::string* sdp) {
482 const char kSdpSsrcAtribute[] = "a=ssrc:";
483 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
484 size_t ssrc_pos = 0;
485 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200486 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 size_t end_ssrc = sdp->find(" ", ssrc_pos);
488 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
489 ssrc_pos = end_ssrc;
490 }
491}
492
deadbeefab9b2d12015-10-14 11:33:11 -0700493// Check if |streams| contains the specified track.
494bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800495 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700496 const std::string& track_id) {
497 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800498 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700499 return true;
500 }
501 }
502 return false;
503}
504
505// Check if |senders| contains the specified sender, by id.
506bool ContainsSender(
507 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
508 const std::string& id) {
509 for (const auto& sender : senders) {
510 if (sender->id() == id) {
511 return true;
512 }
513 }
514 return false;
515}
516
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700517// Check if |senders| contains the specified sender, by id and stream id.
518bool ContainsSender(
519 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
520 const std::string& id,
521 const std::string& stream_id) {
522 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700523 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700524 return true;
525 }
526 }
527 return false;
528}
529
deadbeefab9b2d12015-10-14 11:33:11 -0700530// Create a collection of streams.
531// CreateStreamCollection(1) creates a collection that
532// correspond to kSdpStringWithStream1.
533// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
534rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700535 int number_of_streams,
536 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700537 rtc::scoped_refptr<StreamCollection> local_collection(
538 StreamCollection::Create());
539
540 for (int i = 0; i < number_of_streams; ++i) {
541 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
542 webrtc::MediaStream::Create(kStreams[i]));
543
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700544 for (int j = 0; j < tracks_per_stream; ++j) {
545 // Add a local audio track.
546 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
547 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
548 nullptr));
549 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700550
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700551 // Add a local video track.
552 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
553 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700554 webrtc::FakeVideoTrackSource::Create(),
555 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700556 stream->AddTrack(video_track);
557 }
deadbeefab9b2d12015-10-14 11:33:11 -0700558
559 local_collection->AddStream(stream);
560 }
561 return local_collection;
562}
563
564// Check equality of StreamCollections.
565bool CompareStreamCollections(StreamCollectionInterface* s1,
566 StreamCollectionInterface* s2) {
567 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
568 return false;
569 }
570
571 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700572 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700573 return false;
574 }
575 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
576 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
577 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
578 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
579
580 if (audio_tracks1.size() != audio_tracks2.size()) {
581 return false;
582 }
583 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
584 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
585 return false;
586 }
587 }
588 if (video_tracks1.size() != video_tracks2.size()) {
589 return false;
590 }
591 for (size_t j = 0; j != video_tracks1.size(); ++j) {
592 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
593 return false;
594 }
595 }
596 }
597 return true;
598}
599
perkjd61bf802016-03-24 03:16:19 -0700600// Helper class to test Observer.
601class MockTrackObserver : public ObserverInterface {
602 public:
603 explicit MockTrackObserver(NotifierInterface* notifier)
604 : notifier_(notifier) {
605 notifier_->RegisterObserver(this);
606 }
607
608 ~MockTrackObserver() { Unregister(); }
609
610 void Unregister() {
611 if (notifier_) {
612 notifier_->UnregisterObserver(this);
613 notifier_ = nullptr;
614 }
615 }
616
617 MOCK_METHOD0(OnChanged, void());
618
619 private:
620 NotifierInterface* notifier_;
621};
622
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700624
nisse528b7932017-05-08 03:21:43 -0700625// The PeerConnectionMediaConfig tests below verify that configuration and
626// constraints are propagated into the PeerConnection's MediaConfig. These
627// settings are intended for MediaChannel constructors, but that is not
628// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700629class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
630 public:
zhihuang38ede132017-06-15 12:52:32 -0700631 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
632 CreatePeerConnectionFactoryForTest() {
633 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
634 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200635 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
636 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
Jiawei Oube142172018-10-10 01:16:20 -0700637 auto video_bitrate_allocator_factory =
638 webrtc::CreateBuiltinVideoBitrateAllocatorFactory();
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),
Jiawei Oube142172018-10-10 01:16:20 -0700646 std::move(video_decoder_factory),
647 std::move(video_bitrate_allocator_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100648 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700649
650 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
651 webrtc::CreateCallFactory();
652
653 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
654 webrtc::CreateRtcEventLogFactory();
655
656 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
657 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200658 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700659 std::move(event_log_factory));
660 }
661
662 PeerConnectionFactoryForTest(
663 rtc::Thread* network_thread,
664 rtc::Thread* worker_thread,
665 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700666 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
667 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
668 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
669 : webrtc::PeerConnectionFactory(network_thread,
670 worker_thread,
671 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700672 std::move(media_engine),
673 std::move(call_factory),
674 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800675
deadbeefd7850b22017-08-23 10:59:19 -0700676 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700677};
678
Steve Anton36da6ff2018-02-16 16:04:20 -0800679// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
680class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800682 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
683 : vss_(new rtc::VirtualSocketServer()),
684 main_(vss_.get()),
685 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800686#ifdef WEBRTC_ANDROID
687 webrtc::InitializeAndroidObjects();
688#endif
689 }
690
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700692 // Use fake audio capture module since we're only testing the interface
693 // level, and using a real one could make tests flaky when run in parallel.
694 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700696 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200697 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
698 fake_audio_capture_module_),
699 webrtc::CreateBuiltinAudioEncoderFactory(),
700 webrtc::CreateBuiltinAudioDecoderFactory(),
701 webrtc::CreateBuiltinVideoEncoderFactory(),
702 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
703 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700704 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700705 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700706 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700707 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
710 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200711 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 }
713
deadbeef293e9262017-01-11 12:28:30 -0800714 // DTLS does not work in a loopback call, so is disabled for most of the
715 // tests in this file.
716 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200717 RTCConfiguration config;
718 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800719
Niels Möllerf06f9232018-08-07 12:32:18 +0200720 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 }
722
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700723 void CreatePeerConnectionWithIceTransportsType(
724 PeerConnectionInterface::IceTransportsType type) {
725 PeerConnectionInterface::RTCConfiguration config;
726 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200727 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700728 }
729
730 void CreatePeerConnectionWithIceServer(const std::string& uri,
731 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800732 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700734 server.uri = uri;
735 server.password = password;
736 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200737 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700738 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739
Niels Möllerf06f9232018-08-07 12:32:18 +0200740 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700741 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800742 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
743 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000744
deadbeef1dcb1642017-03-29 21:08:16 -0700745 // Create certificate generator unless DTLS constraint is explicitly set to
746 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200747 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200748
749 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800750 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
751 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000752 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800753 RTCConfiguration modified_config = config;
754 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200755 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200756 modified_config, std::move(port_allocator), std::move(cert_generator),
757 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 ASSERT_TRUE(pc_.get() != NULL);
759 observer_.SetPeerConnectionInterface(pc_.get());
760 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
761 }
762
deadbeef0a6c4ca2015-10-06 11:38:28 -0700763 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800764 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700765 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800767 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800768 config.sdp_semantics = sdp_semantics_;
769 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200770 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800771 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700772 }
773
Steve Anton038834f2017-07-14 15:59:59 -0700774 void CreatePeerConnectionExpectFail(
775 PeerConnectionInterface::RTCConfiguration config) {
776 PeerConnectionInterface::IceServer server;
777 server.uri = kTurnIceServerUri;
778 server.password = kTurnPassword;
779 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800780 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700781 rtc::scoped_refptr<PeerConnectionInterface> pc =
782 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
783 EXPECT_EQ(nullptr, pc);
784 }
785
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700787 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800788 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
789 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
790 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800792 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793
deadbeef0a6c4ca2015-10-06 11:38:28 -0700794 CreatePeerConnectionExpectFail(kStunInvalidPort);
795 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
796 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700798 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800799 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
800 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800806 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 }
808
809 void ReleasePeerConnection() {
810 pc_ = NULL;
811 observer_.SetPeerConnectionInterface(NULL);
812 }
813
Steve Anton36da6ff2018-02-16 16:04:20 -0800814 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
815 const std::string& label) {
816 auto video_source = pc_factory_->CreateVideoSource(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200817 absl::make_unique<cricket::FakeVideoCapturer>(), nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -0800818 return pc_factory_->CreateVideoTrack(label, video_source);
819 }
820
821 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800822 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800823 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800824 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
827 observer_.renegotiation_needed_ = false;
828 }
829
Steve Anton36da6ff2018-02-16 16:04:20 -0800830 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700831 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800833 stream->AddTrack(CreateVideoTrack(label + "v0"));
834 ASSERT_TRUE(pc_->AddStream(stream));
835 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
836 observer_.renegotiation_needed_ = false;
837 }
838
839 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
840 const std::string& label) {
841 return pc_factory_->CreateAudioTrack(label, nullptr);
842 }
843
844 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800845 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800846 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800847 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800848 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
849 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
850 observer_.renegotiation_needed_ = false;
851 }
852
853 void AddAudioStream(const std::string& label) {
854 rtc::scoped_refptr<MediaStreamInterface> stream(
855 pc_factory_->CreateLocalMediaStream(label));
856 stream->AddTrack(CreateAudioTrack(label + "a0"));
857 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
859 observer_.renegotiation_needed_ = false;
860 }
861
Seth Hampson845e8782018-03-02 11:34:10 -0800862 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 const std::string& audio_track_label,
864 const std::string& video_track_label) {
865 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700866 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800867 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800868 stream->AddTrack(CreateAudioTrack(audio_track_label));
869 stream->AddTrack(CreateVideoTrack(video_track_label));
870 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
872 observer_.renegotiation_needed_ = false;
873 }
874
Steve Anton36da6ff2018-02-16 16:04:20 -0800875 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
876 cricket::MediaType media_type) {
877 for (auto receiver : pc_->GetReceivers()) {
878 if (receiver->media_type() == media_type) {
879 return receiver;
880 }
881 }
882 return nullptr;
883 }
884
kwibergd1fe2812016-04-27 06:47:29 -0700885 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200886 const RTCOfferAnswerOptions* options,
887 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200888 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
889 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200891 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200893 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 }
895 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700896 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 return observer->result();
898 }
899
kwibergd1fe2812016-04-27 06:47:29 -0700900 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200901 const RTCOfferAnswerOptions* options) {
902 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 }
904
kwibergd1fe2812016-04-27 06:47:29 -0700905 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200906 const RTCOfferAnswerOptions* options) {
907 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 }
909
Steve Antondb45ca82017-09-11 18:27:34 -0700910 bool DoSetSessionDescription(
911 std::unique_ptr<SessionDescriptionInterface> desc,
912 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200913 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
914 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700916 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700918 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 }
zhihuang29ff8442016-07-27 11:07:25 -0700920 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
921 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
922 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 return observer->result();
924 }
925
Steve Antondb45ca82017-09-11 18:27:34 -0700926 bool DoSetLocalDescription(
927 std::unique_ptr<SessionDescriptionInterface> desc) {
928 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 }
930
Steve Antondb45ca82017-09-11 18:27:34 -0700931 bool DoSetRemoteDescription(
932 std::unique_ptr<SessionDescriptionInterface> desc) {
933 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 }
935
936 // Calls PeerConnection::GetStats and check the return value.
937 // It does not verify the values in the StatReports since a RTCP packet might
938 // be required.
939 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::scoped_refptr<MockStatsObserver> observer(
941 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200942 if (!pc_->GetStats(observer, track,
943 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 return false;
945 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
946 return observer->called();
947 }
948
Harald Alvestrand89061872018-01-02 14:08:34 +0100949 // Call the standards-compliant GetStats function.
950 bool DoGetRTCStats() {
951 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
952 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
953 pc_->GetStats(callback);
954 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
955 return callback->called();
956 }
957
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800959 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800961 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800962 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800963 } else {
964 // Unified Plan does not support AddStream, so just add an audio and video
965 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800966 AddAudioTrack(kAudioTracks[0], {kStreamId1});
967 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800968 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 CreateOfferReceiveAnswer();
970 }
971
972 // Verify that RTP Header extensions has been negotiated for audio and video.
973 void VerifyRemoteRtpHeaderExtensions() {
974 const cricket::MediaContentDescription* desc =
975 cricket::GetFirstAudioContentDescription(
976 pc_->remote_description()->description());
977 ASSERT_TRUE(desc != NULL);
978 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
979
980 desc = cricket::GetFirstVideoContentDescription(
981 pc_->remote_description()->description());
982 ASSERT_TRUE(desc != NULL);
983 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
984 }
985
986 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700987 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700988 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 std::string sdp;
990 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700991 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800992 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700993 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
995 }
996
deadbeefab9b2d12015-10-14 11:33:11 -0700997 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700998 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800999 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001000 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001001 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1002 }
1003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001005 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001006 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007
1008 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1009 // audio codec change, even if the parameter has nothing to do with
1010 // receiving. Not all parameters are serialized to SDP.
1011 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1012 // the SessionDescription, it is necessary to do that here to in order to
1013 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1014 // https://code.google.com/p/webrtc/issues/detail?id=1356
1015 std::string sdp;
1016 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001017 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001018 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001019 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1021 }
1022
1023 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001024 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001025 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026
1027 std::string sdp;
1028 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001029 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001030 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001031 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1033 }
1034
1035 void CreateOfferReceiveAnswer() {
1036 CreateOfferAsLocalDescription();
1037 std::string sdp;
1038 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1039 CreateAnswerAsRemoteDescription(sdp);
1040 }
1041
1042 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001043 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001044 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1046 // audio codec change, even if the parameter has nothing to do with
1047 // receiving. Not all parameters are serialized to SDP.
1048 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1049 // the SessionDescription, it is necessary to do that here to in order to
1050 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1051 // https://code.google.com/p/webrtc/issues/detail?id=1356
1052 std::string sdp;
1053 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001054 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001055 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056
Steve Antondb45ca82017-09-11 18:27:34 -07001057 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001059 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001060 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 }
1062
deadbeefab9b2d12015-10-14 11:33:11 -07001063 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001064 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001065 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 ASSERT_TRUE(answer);
1067 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1069 }
1070
deadbeefab9b2d12015-10-14 11:33:11 -07001071 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001072 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001073 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001074 ASSERT_TRUE(pr_answer);
1075 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001077 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001078 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001079 ASSERT_TRUE(answer);
1080 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1082 }
1083
Seth Hampson845e8782018-03-02 11:34:10 -08001084 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001085 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001086 // called with the given stream id and expected number of tracks.
1087 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001088 int expected_num_tracks) {
1089 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001090 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001091 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001092 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 }
1094
1095 // Creates an offer and applies it as a local session description.
1096 // Creates an answer with the same SDP an the offer but removes all lines
1097 // that start with a:ssrc"
1098 void CreateOfferReceiveAnswerWithoutSsrc() {
1099 CreateOfferAsLocalDescription();
1100 std::string sdp;
1101 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1102 SetSsrcToZero(&sdp);
1103 CreateAnswerAsRemoteDescription(sdp);
1104 }
1105
deadbeefab9b2d12015-10-14 11:33:11 -07001106 // This function creates a MediaStream with label kStreams[0] and
1107 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1108 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001109 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001110 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001111 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001112 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1113 size_t number_of_video_tracks) {
1114 EXPECT_LE(number_of_audio_tracks, 2u);
1115 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001116
1117 reference_collection_ = StreamCollection::Create();
1118 std::string sdp_ms1 = std::string(kSdpStringInit);
1119
Seth Hampson845e8782018-03-02 11:34:10 -08001120 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001121
1122 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001123 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001124 reference_collection_->AddStream(stream);
1125
1126 if (number_of_audio_tracks > 0) {
1127 sdp_ms1 += std::string(kSdpStringAudio);
1128 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1129 AddAudioTrack(kAudioTracks[0], stream);
1130 }
1131 if (number_of_audio_tracks > 1) {
1132 sdp_ms1 += kSdpStringMs1Audio1;
1133 AddAudioTrack(kAudioTracks[1], stream);
1134 }
1135
1136 if (number_of_video_tracks > 0) {
1137 sdp_ms1 += std::string(kSdpStringVideo);
1138 sdp_ms1 += std::string(kSdpStringMs1Video0);
1139 AddVideoTrack(kVideoTracks[0], stream);
1140 }
1141 if (number_of_video_tracks > 1) {
1142 sdp_ms1 += kSdpStringMs1Video1;
1143 AddVideoTrack(kVideoTracks[1], stream);
1144 }
1145
kwibergd1fe2812016-04-27 06:47:29 -07001146 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001147 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001148 }
1149
1150 void AddAudioTrack(const std::string& track_id,
1151 MediaStreamInterface* stream) {
1152 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1153 webrtc::AudioTrack::Create(track_id, nullptr));
1154 ASSERT_TRUE(stream->AddTrack(audio_track));
1155 }
1156
1157 void AddVideoTrack(const std::string& track_id,
1158 MediaStreamInterface* stream) {
1159 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001160 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001161 webrtc::FakeVideoTrackSource::Create(),
1162 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001163 ASSERT_TRUE(stream->AddTrack(video_track));
1164 }
1165
Steve Anton36da6ff2018-02-16 16:04:20 -08001166 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001167 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001168 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001169 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001170 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1171 return offer;
1172 }
1173
Steve Anton36da6ff2018-02-16 16:04:20 -08001174 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1175 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001176 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001177 std::unique_ptr<SessionDescriptionInterface> offer;
1178 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1179 return offer;
1180 }
1181
1182 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1183 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1184 std::unique_ptr<SessionDescriptionInterface> answer;
1185 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1186 return answer;
1187 }
1188
kwibergfd8be342016-05-14 19:44:11 -07001189 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001190 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001191 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001192 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001193 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1194 return answer;
1195 }
1196
1197 const std::string& GetFirstAudioStreamCname(
1198 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001199 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001200 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001201 return audio_desc->streams()[0].cname;
1202 }
1203
zhihuang1c378ed2017-08-17 14:10:50 -07001204 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1205 const RTCOfferAnswerOptions& offer_answer_options) {
1206 RTC_DCHECK(pc_);
1207 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1208 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1209 pc_->CreateOffer(observer, offer_answer_options);
1210 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1211 return observer->MoveDescription();
1212 }
1213
1214 void CreateOfferWithOptionsAsRemoteDescription(
1215 std::unique_ptr<SessionDescriptionInterface>* desc,
1216 const RTCOfferAnswerOptions& offer_answer_options) {
1217 *desc = CreateOfferWithOptions(offer_answer_options);
1218 ASSERT_TRUE(desc != nullptr);
1219 std::string sdp;
1220 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001221 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001222 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001223 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001224 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1225 }
1226
1227 void CreateOfferWithOptionsAsLocalDescription(
1228 std::unique_ptr<SessionDescriptionInterface>* desc,
1229 const RTCOfferAnswerOptions& offer_answer_options) {
1230 *desc = CreateOfferWithOptions(offer_answer_options);
1231 ASSERT_TRUE(desc != nullptr);
1232 std::string sdp;
1233 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001234 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001235 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001236
Steve Antondb45ca82017-09-11 18:27:34 -07001237 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001238 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1239 }
1240
1241 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001242 RTC_DCHECK(content);
1243 RTC_DCHECK(content->media_description());
1244 for (const cricket::AudioCodec& codec :
1245 content->media_description()->as_audio()->codecs()) {
1246 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001247 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001248 }
zhihuang1c378ed2017-08-17 14:10:50 -07001249 }
1250 return false;
1251 }
1252
Steve Anton36da6ff2018-02-16 16:04:20 -08001253 const char* GetSdpStringWithStream1() const {
1254 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1255 return kSdpStringWithStream1PlanB;
1256 } else {
1257 return kSdpStringWithStream1UnifiedPlan;
1258 }
1259 }
1260
1261 const char* GetSdpStringWithStream1And2() const {
1262 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1263 return kSdpStringWithStream1And2PlanB;
1264 } else {
1265 return kSdpStringWithStream1And2UnifiedPlan;
1266 }
1267 }
1268
deadbeef9a6f4d42017-05-15 19:43:33 -07001269 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1270 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001271 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001272 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001273 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001274 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1275 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1276 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001278 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001279 const SdpSemantics sdp_semantics_;
1280};
1281
1282class PeerConnectionInterfaceTest
1283 : public PeerConnectionInterfaceBaseTest,
1284 public ::testing::WithParamInterface<SdpSemantics> {
1285 protected:
1286 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1287};
1288
1289class PeerConnectionInterfaceTestPlanB
1290 : public PeerConnectionInterfaceBaseTest {
1291 protected:
1292 PeerConnectionInterfaceTestPlanB()
1293 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294};
1295
zhihuang8f65cdf2016-05-06 18:40:30 -07001296// Generate different CNAMEs when PeerConnections are created.
1297// The CNAMEs are expected to be generated randomly. It is possible
1298// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001299TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001300 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001301 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001302 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001303 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001304 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1305 GetFirstAudioStreamCname(offer2.get()));
1306}
1307
Steve Anton36da6ff2018-02-16 16:04:20 -08001308TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001309 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001310 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001311 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001312 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001313 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1314 GetFirstAudioStreamCname(answer2.get()));
1315}
1316
Steve Anton36da6ff2018-02-16 16:04:20 -08001317TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318 CreatePeerConnectionWithDifferentConfigurations) {
1319 CreatePeerConnectionWithDifferentConfigurations();
1320}
1321
Steve Anton36da6ff2018-02-16 16:04:20 -08001322TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001323 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1324 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1325 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1326 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1327 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1328 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1329 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1330 port_allocator_->candidate_filter());
1331 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1332 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1333}
1334
1335// Test that when a PeerConnection is created with a nonzero candidate pool
1336// size, the pooled PortAllocatorSession is created with all the attributes
1337// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001338TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001339 PeerConnectionInterface::RTCConfiguration config;
1340 PeerConnectionInterface::IceServer server;
1341 server.uri = kStunAddressOnly;
1342 config.servers.push_back(server);
1343 config.type = PeerConnectionInterface::kRelay;
1344 config.disable_ipv6 = true;
1345 config.tcp_candidate_policy =
1346 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001347 config.candidate_network_policy =
1348 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001349 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001350 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001351
1352 const cricket::FakePortAllocatorSession* session =
1353 static_cast<const cricket::FakePortAllocatorSession*>(
1354 port_allocator_->GetPooledSession());
1355 ASSERT_NE(nullptr, session);
1356 EXPECT_EQ(1UL, session->stun_servers().size());
1357 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1358 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001359 EXPECT_LT(0U,
1360 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001361}
1362
deadbeefd21eab32017-07-26 16:50:11 -07001363// Test that network-related RTCConfiguration members are applied to the
1364// PortAllocator when CreatePeerConnection is called. Specifically:
1365// - disable_ipv6_on_wifi
1366// - max_ipv6_networks
1367// - tcp_candidate_policy
1368// - candidate_network_policy
1369// - prune_turn_ports
1370//
1371// Note that the candidate filter (RTCConfiguration::type) is already tested
1372// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001373TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001374 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1375 // Create fake port allocator.
1376 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1377 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1378 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1379
1380 // Create RTCConfiguration with some network-related fields relevant to
1381 // PortAllocator populated.
1382 PeerConnectionInterface::RTCConfiguration config;
1383 config.disable_ipv6_on_wifi = true;
1384 config.max_ipv6_networks = 10;
1385 config.tcp_candidate_policy =
1386 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1387 config.candidate_network_policy =
1388 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1389 config.prune_turn_ports = true;
1390
1391 // Create the PC factory and PC with the above config.
1392 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1393 webrtc::CreatePeerConnectionFactory(
1394 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001395 rtc::Thread::Current(), fake_audio_capture_module_,
1396 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001397 webrtc::CreateBuiltinAudioDecoderFactory(),
1398 webrtc::CreateBuiltinVideoEncoderFactory(),
1399 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1400 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001401 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001402 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1403 nullptr, &observer_));
deadbeefd21eab32017-07-26 16:50:11 -07001404
1405 // Now validate that the config fields set above were applied to the
1406 // PortAllocator, as flags or otherwise.
1407 EXPECT_FALSE(raw_port_allocator->flags() &
1408 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1409 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1410 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1411 EXPECT_TRUE(raw_port_allocator->flags() &
1412 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1413 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1414}
1415
deadbeef46c73892016-11-16 19:42:04 -08001416// Check that GetConfiguration returns the configuration the PeerConnection was
1417// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001418TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001419 PeerConnectionInterface::RTCConfiguration config;
1420 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001421 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001422
1423 PeerConnectionInterface::RTCConfiguration returned_config =
1424 pc_->GetConfiguration();
1425 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1426}
1427
1428// Check that GetConfiguration returns the last configuration passed into
1429// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001430TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001431 CreatePeerConnection();
1432
Steve Anton36da6ff2018-02-16 16:04:20 -08001433 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001434 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001435 config.use_media_transport = true;
deadbeef46c73892016-11-16 19:42:04 -08001436 EXPECT_TRUE(pc_->SetConfiguration(config));
1437
1438 PeerConnectionInterface::RTCConfiguration returned_config =
1439 pc_->GetConfiguration();
1440 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001441 EXPECT_TRUE(returned_config.use_media_transport);
deadbeef46c73892016-11-16 19:42:04 -08001442}
1443
Steve Antonc79268f2018-04-24 09:54:10 -07001444TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1445 CreatePeerConnection();
1446
1447 pc_->Close();
1448
1449 EXPECT_FALSE(
1450 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1451}
1452
Steve Anton36da6ff2018-02-16 16:04:20 -08001453TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001454 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001455 AddVideoStream(kStreamId1);
1456 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 ASSERT_EQ(2u, pc_->local_streams()->count());
1458
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001459 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001460 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001461 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001462 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001463 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001464 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001466 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001467 EXPECT_EQ(3u, pc_->local_streams()->count());
1468
1469 // Remove the third stream.
1470 pc_->RemoveStream(pc_->local_streams()->at(2));
1471 EXPECT_EQ(2u, pc_->local_streams()->count());
1472
1473 // Remove the second stream.
1474 pc_->RemoveStream(pc_->local_streams()->at(1));
1475 EXPECT_EQ(1u, pc_->local_streams()->count());
1476
1477 // Remove the first stream.
1478 pc_->RemoveStream(pc_->local_streams()->at(0));
1479 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480}
1481
deadbeefab9b2d12015-10-14 11:33:11 -07001482// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001483// Don't run under Unified Plan since the stream API is not available.
1484TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001485 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001486 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001487 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001488 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001489
deadbeefab9b2d12015-10-14 11:33:11 -07001490 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001491 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001492 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001493
deadbeefab9b2d12015-10-14 11:33:11 -07001494 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001495 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001496 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001497
1498 // Add another stream and ensure the offer includes both the old and new
1499 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001500 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001501 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001502
Steve Antonb1c1de12017-12-21 15:14:30 -08001503 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001504 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1505 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001506
Steve Antonb1c1de12017-12-21 15:14:30 -08001507 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001508 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1509 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001510}
1511
Steve Anton36da6ff2018-02-16 16:04:20 -08001512// Don't run under Unified Plan since the stream API is not available.
1513TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001514 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001515 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 ASSERT_EQ(1u, pc_->local_streams()->count());
1517 pc_->RemoveStream(pc_->local_streams()->at(0));
1518 EXPECT_EQ(0u, pc_->local_streams()->count());
1519}
1520
deadbeefe1f9d832016-01-14 15:35:42 -08001521// Test for AddTrack and RemoveTrack methods.
1522// Tests that the created offer includes tracks we added,
1523// and that the RtpSenders are created correctly.
1524// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001525// Only tested with Plan B since Unified Plan is covered in more detail by tests
1526// in peerconnection_jsep_unittests.cc
1527TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001528 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001529 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001530 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001531 rtc::scoped_refptr<VideoTrackInterface> video_track(
1532 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001533 "video_track", pc_factory_->CreateVideoSource(
1534 std::unique_ptr<cricket::VideoCapturer>(
1535 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001536 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1537 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001538 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001539 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001540 EXPECT_EQ("audio_track", audio_sender->id());
1541 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001542 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001543 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001544 EXPECT_EQ("video_track", video_sender->id());
1545 EXPECT_EQ(video_track, video_sender->track());
1546
1547 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001548 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001549 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001550
1551 const cricket::ContentInfo* audio_content =
1552 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001553 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001554 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001555
1556 const cricket::ContentInfo* video_content =
1557 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001558 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001559 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
Steve Antondb45ca82017-09-11 18:27:34 -07001561 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001562
1563 // Now try removing the tracks.
1564 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1565 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1566
1567 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001568 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001569
1570 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001571 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001572 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001573
1574 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001575 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001576 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001577
Steve Antondb45ca82017-09-11 18:27:34 -07001578 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001579
1580 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1581 // should return false.
1582 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1583 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1584}
1585
1586// Test creating senders without a stream specified,
1587// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001588TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001589 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001590 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001591 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001592 rtc::scoped_refptr<VideoTrackInterface> video_track(
1593 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001594 "video_track", pc_factory_->CreateVideoSource(
1595 std::unique_ptr<cricket::VideoCapturer>(
1596 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001597 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001598 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001599 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001600 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001601 EXPECT_EQ("audio_track", audio_sender->id());
1602 EXPECT_EQ(audio_track, audio_sender->track());
1603 EXPECT_EQ("video_track", video_sender->id());
1604 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001605 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1606 // If the ID is truly a random GUID, it should be infinitely unlikely they
1607 // will be the same.
1608 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1609 } else {
1610 // We allows creating tracks without stream ids under Unified Plan
1611 // semantics.
1612 EXPECT_EQ(0u, video_sender->stream_ids().size());
1613 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1614 }
deadbeefe1f9d832016-01-14 15:35:42 -08001615}
1616
Harald Alvestrand89061872018-01-02 14:08:34 +01001617// Test that we can call GetStats() after AddTrack but before connecting
1618// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001619TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001620 CreatePeerConnectionWithoutDtls();
1621 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1622 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1623 rtc::scoped_refptr<VideoTrackInterface> video_track(
1624 pc_factory_->CreateVideoTrack(
1625 "video_track", pc_factory_->CreateVideoSource(
1626 std::unique_ptr<cricket::VideoCapturer>(
1627 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001628 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1629 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001630 EXPECT_TRUE(DoGetStats(nullptr));
1631}
1632
Steve Anton36da6ff2018-02-16 16:04:20 -08001633TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001634 CreatePeerConnectionWithoutDtls();
1635 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1636 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1637 rtc::scoped_refptr<VideoTrackInterface> video_track(
1638 pc_factory_->CreateVideoTrack(
1639 "video_track", pc_factory_->CreateVideoSource(
1640 std::unique_ptr<cricket::VideoCapturer>(
1641 new cricket::FakeVideoCapturer()))));
1642 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001643 ASSERT_TRUE(audio_sender.ok());
1644 auto* audio_sender_proxy =
1645 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1646 audio_sender.value().get());
1647 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1648
Harald Alvestrandc72af932018-01-11 17:18:19 +01001649 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001650 ASSERT_TRUE(video_sender.ok());
1651 auto* video_sender_proxy =
1652 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1653 video_sender.value().get());
1654 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001655}
1656
Steve Anton36da6ff2018-02-16 16:04:20 -08001657// Don't run under Unified Plan since the stream API is not available.
1658TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001659 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001660 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001661 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001662 ASSERT_EQ(1u, senders.size());
1663 auto* sender_proxy =
1664 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1665 senders[0].get());
1666 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001667}
1668
Steve Anton36da6ff2018-02-16 16:04:20 -08001669TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001671 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 VerifyRemoteRtpHeaderExtensions();
1673}
1674
Steve Anton36da6ff2018-02-16 16:04:20 -08001675TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001676 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001677 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 CreateOfferAsLocalDescription();
1679 std::string offer;
1680 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1681 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001682 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683}
1684
Steve Anton36da6ff2018-02-16 16:04:20 -08001685TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
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
1689 CreateOfferAsRemoteDescription();
1690 CreateAnswerAsLocalDescription();
1691
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, ReceiveOfferCreatePrAnswerAndAnswer) {
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 CreatePrAnswerAsLocalDescription();
1701 CreateAnswerAsLocalDescription();
1702
Seth Hampson845e8782018-03-02 11:34:10 -08001703 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704}
1705
Steve Anton36da6ff2018-02-16 16:04:20 -08001706// Don't run under Unified Plan since the stream API is not available.
1707TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 InitiateCall();
1709 ASSERT_EQ(1u, pc_->remote_streams()->count());
1710 pc_->RemoveStream(pc_->local_streams()->at(0));
1711 CreateOfferReceiveAnswer();
1712 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001713 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 CreateOfferReceiveAnswer();
1715}
1716
1717// Tests that after negotiating an audio only call, the respondent can perform a
1718// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001719TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001720 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001721 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 CreateOfferAsRemoteDescription();
1723 CreateAnswerAsLocalDescription();
1724
1725 ASSERT_EQ(1u, pc_->remote_streams()->count());
1726 pc_->RemoveStream(pc_->local_streams()->at(0));
1727 CreateOfferReceiveAnswer();
1728 EXPECT_EQ(0u, pc_->remote_streams()->count());
1729}
1730
1731// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001732TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001733 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734
Steve Antonf1c6db12017-10-13 11:13:35 -07001735 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001737 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001738 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001739 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001740 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741
1742 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001743 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001744 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001745 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746
Steve Antonf1c6db12017-10-13 11:13:35 -07001747 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001748 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749
Steve Antonf1c6db12017-10-13 11:13:35 -07001750 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751}
1752
deadbeefab9b2d12015-10-14 11:33:11 -07001753// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001755TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001756 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001758 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001759 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001760 EXPECT_TRUE(offer);
1761 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762
1763 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001764 AddAudioTrack("track_label", {kStreamId1});
1765 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766
1767 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001768 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769
1770 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001771 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001772 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773}
1774
1775// Test that we will get different SSRCs for each tracks in the offer and answer
1776// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001777TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001778 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001780 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1781 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782
1783 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001784 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001785 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 int audio_ssrc = 0;
1787 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001788 EXPECT_TRUE(
1789 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1790 EXPECT_TRUE(
1791 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 EXPECT_NE(audio_ssrc, video_ssrc);
1793
1794 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001795 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001796 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001797 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 audio_ssrc = 0;
1799 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001800 EXPECT_TRUE(
1801 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1802 EXPECT_TRUE(
1803 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 EXPECT_NE(audio_ssrc, video_ssrc);
1805}
1806
deadbeefeb459812015-12-15 19:24:43 -08001807// Test that it's possible to call AddTrack on a MediaStream after adding
1808// the stream to a PeerConnection.
1809// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001810// Don't run under Unified Plan since the stream API is not available.
1811TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001812 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001813 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001814 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001815 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1816
1817 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001818 rtc::scoped_refptr<VideoTrackInterface> video_track(
1819 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001820 "video_label", pc_factory_->CreateVideoSource(
1821 std::unique_ptr<cricket::VideoCapturer>(
1822 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001823 stream->AddTrack(video_track.get());
1824
kwibergd1fe2812016-04-27 06:47:29 -07001825 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001826 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001827
1828 const cricket::MediaContentDescription* video_desc =
1829 cricket::GetFirstVideoContentDescription(offer->description());
1830 EXPECT_TRUE(video_desc != nullptr);
1831}
1832
1833// Test that it's possible to call RemoveTrack on a MediaStream after adding
1834// the stream to a PeerConnection.
1835// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001836// Don't run under Unified Plan since the stream API is not available.
1837TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001838 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001839 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001840 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001841 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1842
1843 // Remove the video track.
1844 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1845
kwibergd1fe2812016-04-27 06:47:29 -07001846 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001847 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001848
1849 const cricket::MediaContentDescription* video_desc =
1850 cricket::GetFirstVideoContentDescription(offer->description());
1851 EXPECT_TRUE(video_desc == nullptr);
1852}
1853
deadbeefbd7d8f72015-12-18 16:58:44 -08001854// Test creating a sender with a stream ID, and ensure the ID is populated
1855// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001856// Don't run under Unified Plan since the stream API is not available.
1857TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001858 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001859 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001860
kwibergd1fe2812016-04-27 06:47:29 -07001861 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001862 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001863
1864 const cricket::MediaContentDescription* video_desc =
1865 cricket::GetFirstVideoContentDescription(offer->description());
1866 ASSERT_TRUE(video_desc != nullptr);
1867 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001868 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001869}
1870
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001872TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001874 ASSERT_LT(0u, pc_->GetSenders().size());
1875 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001876 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001877 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 EXPECT_TRUE(DoGetStats(remote_audio));
1879
1880 // Remove the stream. Since we are sending to our selves the local
1881 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001882 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 // Do a re-negotiation.
1884 CreateOfferReceiveAnswer();
1885
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 // Test that we still can get statistics for the old track. Even if it is not
1887 // sent any longer.
1888 EXPECT_TRUE(DoGetStats(remote_audio));
1889}
1890
1891// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001892TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001894 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1895 ASSERT_TRUE(video_receiver);
1896 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897}
1898
1899// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001900TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001902 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 pc_factory_->CreateAudioTrack("unknown track", NULL));
1904 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1905}
1906
Steve Anton36da6ff2018-02-16 16:04:20 -08001907TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001908 CreatePeerConnectionWithoutDtls();
1909 EXPECT_TRUE(DoGetRTCStats());
1910 // Clearing stats cache is needed now, but should be temporary.
1911 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1912 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001913 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1914 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001915 EXPECT_TRUE(DoGetRTCStats());
1916 pc_->ClearStatsCache();
1917 CreateOfferReceiveAnswer();
1918 EXPECT_TRUE(DoGetRTCStats());
1919}
1920
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001922TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001923 RTCConfiguration config;
1924 config.enable_rtp_data_channel = true;
1925 config.enable_dtls_srtp = false;
1926 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001927 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001929 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 pc_->CreateDataChannel("test2", NULL);
1931 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001932 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001934 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 new MockDataChannelObserver(data2));
1936
1937 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1938 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1939 std::string data_to_send1 = "testing testing";
1940 std::string data_to_send2 = "testing something else";
1941 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1942
1943 CreateOfferReceiveAnswer();
1944 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1945 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1946
1947 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1948 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1949 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1950 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1951
1952 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1953 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1954
1955 data1->Close();
1956 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1957 CreateOfferReceiveAnswer();
1958 EXPECT_FALSE(observer1->IsOpen());
1959 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1960 EXPECT_TRUE(observer2->IsOpen());
1961
1962 data_to_send2 = "testing something else again";
1963 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1964
1965 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1966}
1967
1968// This test verifies that sendnig binary data over RTP data channels should
1969// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001970TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001971 RTCConfiguration config;
1972 config.enable_rtp_data_channel = true;
1973 config.enable_dtls_srtp = false;
1974 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001975 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001977 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 pc_->CreateDataChannel("test2", NULL);
1979 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001980 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001982 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 new MockDataChannelObserver(data2));
1984
1985 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1986 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1987
1988 CreateOfferReceiveAnswer();
1989 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1990 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1991
1992 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1993 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1994
jbaucheec21bd2016-03-20 06:15:43 -07001995 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1997}
1998
1999// This test setup a RTP data channels in loop back and test that a channel is
2000// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002001TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002002 RTCConfiguration config;
2003 config.enable_rtp_data_channel = true;
2004 config.enable_dtls_srtp = false;
2005 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002006 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002008 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 new MockDataChannelObserver(data1));
2010
2011 CreateOfferReceiveAnswerWithoutSsrc();
2012
2013 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2014
2015 data1->Close();
2016 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2017 CreateOfferReceiveAnswerWithoutSsrc();
2018 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2019 EXPECT_FALSE(observer1->IsOpen());
2020}
2021
2022// This test that if a data channel is added in an answer a receive only channel
2023// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002024TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002025 RTCConfiguration config;
2026 config.enable_rtp_data_channel = true;
2027 config.enable_dtls_srtp = false;
2028
2029 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030
2031 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002032 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 pc_->CreateDataChannel(offer_label, NULL);
2034
2035 CreateOfferAsLocalDescription();
2036
2037 // Replace the data channel label in the offer and apply it as an answer.
2038 std::string receive_label = "answer_channel";
2039 std::string sdp;
2040 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002041 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002042 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 CreateAnswerAsRemoteDescription(sdp);
2044
2045 // Verify that a new incoming data channel has been created and that
2046 // it is open but can't we written to.
2047 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2048 DataChannelInterface* received_channel = observer_.last_datachannel_;
2049 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2050 EXPECT_EQ(receive_label, received_channel->label());
2051 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2052
2053 // Verify that the channel we initially offered has been rejected.
2054 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2055
2056 // Do another offer / answer exchange and verify that the data channel is
2057 // opened.
2058 CreateOfferReceiveAnswer();
2059 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2060 kTimeout);
2061}
2062
2063// This test that no data channel is returned if a reliable channel is
2064// requested.
2065// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002066TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002067 RTCConfiguration rtc_config;
2068 rtc_config.enable_rtp_data_channel = true;
2069 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070
2071 std::string label = "test";
2072 webrtc::DataChannelInit config;
2073 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002074 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 pc_->CreateDataChannel(label, &config);
2076 EXPECT_TRUE(channel == NULL);
2077}
2078
deadbeefab9b2d12015-10-14 11:33:11 -07002079// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002080TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002081 RTCConfiguration config;
2082 config.enable_rtp_data_channel = true;
2083 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002084
2085 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002086 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002087 pc_->CreateDataChannel(label, nullptr);
2088 EXPECT_NE(channel, nullptr);
2089
zhihuang9763d562016-08-05 11:14:50 -07002090 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002091 pc_->CreateDataChannel(label, nullptr);
2092 EXPECT_EQ(dup_channel, nullptr);
2093}
2094
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095// This tests that a SCTP data channel is returned using different
2096// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002097TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002098 RTCConfiguration rtc_config;
2099 rtc_config.enable_dtls_srtp = true;
2100 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101
2102 webrtc::DataChannelInit config;
2103
zhihuang9763d562016-08-05 11:14:50 -07002104 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 pc_->CreateDataChannel("1", &config);
2106 EXPECT_TRUE(channel != NULL);
2107 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002108 EXPECT_TRUE(observer_.renegotiation_needed_);
2109 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
2111 config.ordered = false;
2112 channel = pc_->CreateDataChannel("2", &config);
2113 EXPECT_TRUE(channel != NULL);
2114 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002115 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116
2117 config.ordered = true;
2118 config.maxRetransmits = 0;
2119 channel = pc_->CreateDataChannel("3", &config);
2120 EXPECT_TRUE(channel != NULL);
2121 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002122 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123
2124 config.maxRetransmits = -1;
2125 config.maxRetransmitTime = 0;
2126 channel = pc_->CreateDataChannel("4", &config);
2127 EXPECT_TRUE(channel != NULL);
2128 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002129 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130}
2131
2132// This tests that no data channel is returned if both maxRetransmits and
2133// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002134TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002136 RTCConfiguration rtc_config;
2137 rtc_config.enable_dtls_srtp = true;
2138 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139
2140 std::string label = "test";
2141 webrtc::DataChannelInit config;
2142 config.maxRetransmits = 0;
2143 config.maxRetransmitTime = 0;
2144
zhihuang9763d562016-08-05 11:14:50 -07002145 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 pc_->CreateDataChannel(label, &config);
2147 EXPECT_TRUE(channel == NULL);
2148}
2149
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150// The test verifies that creating a SCTP data channel with an id already in use
2151// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002152TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002154 RTCConfiguration rtc_config;
2155 rtc_config.enable_dtls_srtp = true;
2156 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157
2158 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002159 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002161 config.id = 1;
2162 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 EXPECT_TRUE(channel != NULL);
2164 EXPECT_EQ(1, channel->id());
2165
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 channel = pc_->CreateDataChannel("x", &config);
2167 EXPECT_TRUE(channel == NULL);
2168
2169 config.id = cricket::kMaxSctpSid;
2170 channel = pc_->CreateDataChannel("max", &config);
2171 EXPECT_TRUE(channel != NULL);
2172 EXPECT_EQ(config.id, channel->id());
2173
2174 config.id = cricket::kMaxSctpSid + 1;
2175 channel = pc_->CreateDataChannel("x", &config);
2176 EXPECT_TRUE(channel == NULL);
2177}
2178
deadbeefab9b2d12015-10-14 11:33:11 -07002179// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002180TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002181 RTCConfiguration rtc_config;
2182 rtc_config.enable_dtls_srtp = true;
2183 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002184
2185 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002186 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002187 pc_->CreateDataChannel(label, nullptr);
2188 EXPECT_NE(channel, nullptr);
2189
zhihuang9763d562016-08-05 11:14:50 -07002190 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002191 pc_->CreateDataChannel(label, nullptr);
2192 EXPECT_NE(dup_channel, nullptr);
2193}
2194
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002195// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2196// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002197TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002198 RTCConfiguration rtc_config;
2199 rtc_config.enable_rtp_data_channel = true;
2200 rtc_config.enable_dtls_srtp = false;
2201 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002202
zhihuang9763d562016-08-05 11:14:50 -07002203 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002204 pc_->CreateDataChannel("test1", NULL);
2205 EXPECT_TRUE(observer_.renegotiation_needed_);
2206 observer_.renegotiation_needed_ = false;
2207
zhihuang9763d562016-08-05 11:14:50 -07002208 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002209 pc_->CreateDataChannel("test2", NULL);
2210 EXPECT_TRUE(observer_.renegotiation_needed_);
2211}
2212
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002214TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002215 RTCConfiguration rtc_config;
2216 rtc_config.enable_rtp_data_channel = true;
2217 rtc_config.enable_dtls_srtp = false;
2218 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219
zhihuang9763d562016-08-05 11:14:50 -07002220 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002222 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 pc_->CreateDataChannel("test2", NULL);
2224 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002225 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002227 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 new MockDataChannelObserver(data2));
2229
2230 CreateOfferReceiveAnswer();
2231 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2232 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2233
2234 ReleasePeerConnection();
2235 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2236 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2237}
2238
Zhi Huang644fde42018-04-02 19:16:26 -07002239// This tests that RTP data channels can be rejected in an answer.
2240TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002241 RTCConfiguration rtc_config;
2242 rtc_config.enable_rtp_data_channel = true;
2243 rtc_config.enable_dtls_srtp = false;
2244 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245
zhihuang9763d562016-08-05 11:14:50 -07002246 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 pc_->CreateDataChannel("offer_channel", NULL));
2248
2249 CreateOfferAsLocalDescription();
2250
2251 // Create an answer where the m-line for data channels are rejected.
2252 std::string sdp;
2253 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002254 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002255 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002256 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002258 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259 data_info->rejected = true;
2260
Steve Antondb45ca82017-09-11 18:27:34 -07002261 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2263}
2264
Zhi Huang644fde42018-04-02 19:16:26 -07002265#ifdef HAVE_SCTP
2266// This tests that SCTP data channels can be rejected in an answer.
2267TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2268#else
2269TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2270#endif
2271{
Niels Möllerf06f9232018-08-07 12:32:18 +02002272 RTCConfiguration rtc_config;
2273 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002274
2275 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2276 pc_->CreateDataChannel("offer_channel", NULL));
2277
2278 CreateOfferAsLocalDescription();
2279
2280 // Create an answer where the m-line for data channels are rejected.
2281 std::string sdp;
2282 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2283 std::unique_ptr<SessionDescriptionInterface> answer(
2284 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2285 ASSERT_TRUE(answer);
2286 cricket::ContentInfo* data_info =
2287 cricket::GetFirstDataContent(answer->description());
2288 data_info->rejected = true;
2289
2290 DoSetRemoteDescription(std::move(answer));
2291 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2292}
2293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294// Test that we can create a session description from an SDP string from
2295// FireFox, use it as a remote session description, generate an answer and use
2296// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002297TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002298 RTCConfiguration rtc_config;
2299 rtc_config.enable_dtls_srtp = true;
2300 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002301 AddAudioTrack("audio_label");
2302 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002303 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002304 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002305 webrtc::kFireFoxSdpOffer, nullptr));
2306 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 CreateAnswerAsLocalDescription();
2308 ASSERT_TRUE(pc_->local_description() != NULL);
2309 ASSERT_TRUE(pc_->remote_description() != NULL);
2310
2311 const cricket::ContentInfo* content =
2312 cricket::GetFirstAudioContent(pc_->local_description()->description());
2313 ASSERT_TRUE(content != NULL);
2314 EXPECT_FALSE(content->rejected);
2315
2316 content =
2317 cricket::GetFirstVideoContent(pc_->local_description()->description());
2318 ASSERT_TRUE(content != NULL);
2319 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002320#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 content =
2322 cricket::GetFirstDataContent(pc_->local_description()->description());
2323 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002324 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002325#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326}
2327
zhihuangb19012e2017-09-19 13:47:59 -07002328// Test that fallback from DTLS to SDES is not supported.
2329// The fallback was previously supported but was removed to simplify the code
2330// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002331TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002332 RTCConfiguration rtc_config;
2333 rtc_config.enable_dtls_srtp = true;
2334 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002335 // Wait for fake certificate to be generated. Previously, this is what caused
2336 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002337 AddAudioTrack("audio_label");
2338 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002339 ASSERT_NE(nullptr, fake_certificate_generator_);
2340 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2341 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002342 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002343 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2344 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002345 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002346}
2347
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348// Test that we can create an audio only offer and receive an answer with a
2349// limited set of audio codecs and receive an updated offer with more audio
2350// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002351TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002352 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002353 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 CreateOfferAsLocalDescription();
2355
Steve Anton36da6ff2018-02-16 16:04:20 -08002356 const char* answer_sdp =
2357 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2358 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002359 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002360 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002361 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362
Steve Anton36da6ff2018-02-16 16:04:20 -08002363 const char* reoffer_sdp =
2364 (sdp_semantics_ == SdpSemantics::kPlanB
2365 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2366 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002367 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002368 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002369 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 CreateAnswerAsLocalDescription();
2371}
2372
deadbeefc80741f2015-10-22 13:14:45 -07002373// Test that if we're receiving (but not sending) a track, subsequent offers
2374// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002375TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002376 RTCConfiguration rtc_config;
2377 rtc_config.enable_dtls_srtp = true;
2378 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002379 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002380 CreateAnswerAsLocalDescription();
2381
2382 // At this point we should be receiving stream 1, but not sending anything.
2383 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002384 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002385 DoCreateOffer(&offer, nullptr);
2386
2387 const cricket::ContentInfo* video_content =
2388 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002389 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2390 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002391
2392 const cricket::ContentInfo* audio_content =
2393 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002394 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2395 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002396}
2397
2398// Test that if we're receiving (but not sending) a track, and the
2399// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2400// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002401TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002402 RTCConfiguration rtc_config;
2403 rtc_config.enable_dtls_srtp = true;
2404 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002405 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002406 CreateAnswerAsLocalDescription();
2407
2408 // At this point we should be receiving stream 1, but not sending anything.
2409 // A new offer would be recvonly, but we'll set the "no receive" constraints
2410 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002411 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002412 RTCOfferAnswerOptions options;
2413 options.offer_to_receive_audio = 0;
2414 options.offer_to_receive_video = 0;
2415 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002416
2417 const cricket::ContentInfo* video_content =
2418 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002419 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2420 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002421
2422 const cricket::ContentInfo* audio_content =
2423 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002424 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2425 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002426}
2427
deadbeef653b8e02015-11-11 12:55:10 -08002428// Test that we can use SetConfiguration to change the ICE servers of the
2429// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002430TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002431 CreatePeerConnection();
2432
Steve Anton36da6ff2018-02-16 16:04:20 -08002433 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002434 PeerConnectionInterface::IceServer server;
2435 server.uri = "stun:test_hostname";
2436 config.servers.push_back(server);
2437 EXPECT_TRUE(pc_->SetConfiguration(config));
2438
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002439 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2440 EXPECT_EQ("test_hostname",
2441 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002442}
2443
Steve Anton36da6ff2018-02-16 16:04:20 -08002444TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002445 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002446 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002447 config.type = PeerConnectionInterface::kRelay;
2448 EXPECT_TRUE(pc_->SetConfiguration(config));
2449 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2450}
2451
Steve Anton36da6ff2018-02-16 16:04:20 -08002452TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002453 PeerConnectionInterface::RTCConfiguration config;
2454 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002455 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002456 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002457 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2458
2459 config.prune_turn_ports = true;
2460 EXPECT_TRUE(pc_->SetConfiguration(config));
2461 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2462}
2463
skvladd1f5fda2017-02-03 16:54:05 -08002464// Test that the ice check interval can be changed. This does not verify that
2465// the setting makes it all the way to P2PTransportChannel, as that would
2466// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002467TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002468 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002469 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002470 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002471 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002472 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002473 EXPECT_TRUE(pc_->SetConfiguration(config));
2474 PeerConnectionInterface::RTCConfiguration new_config =
2475 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002476 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002477}
2478
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002479// Test that when SetConfiguration changes both the pool size and other
2480// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002481TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002482 SetConfigurationCreatesPooledSessionCorrectly) {
2483 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002484 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002485 config.ice_candidate_pool_size = 1;
2486 PeerConnectionInterface::IceServer server;
2487 server.uri = kStunAddressOnly;
2488 config.servers.push_back(server);
2489 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002490 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002491
2492 const cricket::FakePortAllocatorSession* session =
2493 static_cast<const cricket::FakePortAllocatorSession*>(
2494 port_allocator_->GetPooledSession());
2495 ASSERT_NE(nullptr, session);
2496 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002497}
2498
deadbeef293e9262017-01-11 12:28:30 -08002499// Test that after SetLocalDescription, changing the pool size is not allowed,
2500// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002501TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002502 CantChangePoolSizeAfterSetLocalDescription) {
2503 CreatePeerConnection();
2504 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002505 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002506 config.ice_candidate_pool_size = 1;
2507 EXPECT_TRUE(pc_->SetConfiguration(config));
2508
2509 // Set remote offer; can still change pool size at this point.
2510 CreateOfferAsRemoteDescription();
2511 config.ice_candidate_pool_size = 2;
2512 EXPECT_TRUE(pc_->SetConfiguration(config));
2513
2514 // Set local answer; now it's too late.
2515 CreateAnswerAsLocalDescription();
2516 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002517 RTCError error;
2518 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2519 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2520}
2521
deadbeef42a42632017-03-10 15:18:00 -08002522// Test that after setting an answer, extra pooled sessions are discarded. The
2523// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002524TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002525 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2526 CreatePeerConnection();
2527
2528 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002529 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002530 config.ice_candidate_pool_size = 4;
2531 EXPECT_TRUE(pc_->SetConfiguration(config));
2532
2533 // Do offer/answer.
2534 CreateOfferAsRemoteDescription();
2535 CreateAnswerAsLocalDescription();
2536
2537 // Expect no pooled sessions to be left.
2538 const cricket::PortAllocatorSession* session =
2539 port_allocator_->GetPooledSession();
2540 EXPECT_EQ(nullptr, session);
2541}
2542
2543// After Close is called, pooled candidates should be discarded so as to not
2544// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002545TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002546 CreatePeerConnection();
2547
Steve Anton36da6ff2018-02-16 16:04:20 -08002548 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002549 config.ice_candidate_pool_size = 3;
2550 EXPECT_TRUE(pc_->SetConfiguration(config));
2551 pc_->Close();
2552
2553 // Expect no pooled sessions to be left.
2554 const cricket::PortAllocatorSession* session =
2555 port_allocator_->GetPooledSession();
2556 EXPECT_EQ(nullptr, session);
2557}
2558
deadbeef293e9262017-01-11 12:28:30 -08002559// Test that SetConfiguration returns an invalid modification error if
2560// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002561TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002562 SetConfigurationReturnsInvalidModificationError) {
2563 PeerConnectionInterface::RTCConfiguration config;
2564 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2565 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2566 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002567 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002568
Steve Anton36da6ff2018-02-16 16:04:20 -08002569 PeerConnectionInterface::RTCConfiguration modified_config =
2570 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002571 modified_config.bundle_policy =
2572 PeerConnectionInterface::kBundlePolicyMaxBundle;
2573 RTCError error;
2574 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2575 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2576
Steve Anton36da6ff2018-02-16 16:04:20 -08002577 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002578 modified_config.rtcp_mux_policy =
2579 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2580 error.set_type(RTCErrorType::NONE);
2581 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2582 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2583
Steve Anton36da6ff2018-02-16 16:04:20 -08002584 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002585 modified_config.continual_gathering_policy =
2586 PeerConnectionInterface::GATHER_CONTINUALLY;
2587 error.set_type(RTCErrorType::NONE);
2588 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2589 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2590}
2591
2592// Test that SetConfiguration returns a range error if the candidate pool size
2593// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002594TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002595 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2596 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002597 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002598 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002599
2600 config.ice_candidate_pool_size = -1;
2601 RTCError error;
2602 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2603 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2604
2605 config.ice_candidate_pool_size = INT_MAX;
2606 error.set_type(RTCErrorType::NONE);
2607 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2608 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2609}
2610
2611// Test that SetConfiguration returns a syntax error if parsing an ICE server
2612// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002613TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002614 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2615 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002616 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002617 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002618
2619 PeerConnectionInterface::IceServer bad_server;
2620 bad_server.uri = "stunn:www.example.com";
2621 config.servers.push_back(bad_server);
2622 RTCError error;
2623 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2624 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2625}
2626
2627// Test that SetConfiguration returns an invalid parameter error if a TURN
2628// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002629TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002630 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2631 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002632 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002633 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002634
2635 PeerConnectionInterface::IceServer bad_server;
2636 bad_server.uri = "turn:www.example.com";
2637 // Missing password.
2638 bad_server.username = "foo";
2639 config.servers.push_back(bad_server);
2640 RTCError error;
2641 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2642 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002643}
2644
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002645// Test that PeerConnection::Close changes the states to closed and all remote
2646// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002647TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 // Initialize a PeerConnection and negotiate local and remote session
2649 // description.
2650 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002651
2652 // With Plan B, verify the stream count. The analog with Unified Plan is the
2653 // RtpTransceiver count.
2654 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2655 ASSERT_EQ(1u, pc_->local_streams()->count());
2656 ASSERT_EQ(1u, pc_->remote_streams()->count());
2657 } else {
2658 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2659 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660
2661 pc_->Close();
2662
2663 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2664 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2665 pc_->ice_connection_state());
2666 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2667 pc_->ice_gathering_state());
2668
Steve Anton36da6ff2018-02-16 16:04:20 -08002669 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2670 EXPECT_EQ(1u, pc_->local_streams()->count());
2671 EXPECT_EQ(1u, pc_->remote_streams()->count());
2672 } else {
2673 // Verify that the RtpTransceivers are still present but all stopped.
2674 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2675 for (auto transceiver : pc_->GetTransceivers()) {
2676 EXPECT_TRUE(transceiver->stopped());
2677 }
2678 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002679
Steve Anton36da6ff2018-02-16 16:04:20 -08002680 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2681 ASSERT_TRUE(audio_receiver);
2682 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2683 ASSERT_TRUE(video_receiver);
2684
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002685 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002686 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002687 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002688 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002689 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690}
2691
2692// Test that PeerConnection methods fails gracefully after
2693// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002694// Don't run under Unified Plan since the stream API is not available.
2695TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002696 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002697 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 CreateOfferAsRemoteDescription();
2699 CreateAnswerAsLocalDescription();
2700
2701 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002702 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703 pc_->local_streams()->at(0);
2704
2705 pc_->Close();
2706
2707 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002708 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2711
2712 EXPECT_TRUE(pc_->local_description() != NULL);
2713 EXPECT_TRUE(pc_->remote_description() != NULL);
2714
kwibergd1fe2812016-04-27 06:47:29 -07002715 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002716 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002717 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002718 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719
2720 std::string sdp;
2721 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002722 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002723 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002724 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725
2726 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002727 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002728 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002729 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730}
2731
2732// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002733TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 InitiateCall();
2735 pc_->Close();
2736 DoGetStats(NULL);
2737}
deadbeefab9b2d12015-10-14 11:33:11 -07002738
2739// NOTE: The series of tests below come from what used to be
2740// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2741// setting a remote or local description has the expected effects.
2742
2743// This test verifies that the remote MediaStreams corresponding to a received
2744// SDP string is created. In this test the two separate MediaStreams are
2745// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002746TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002747 RTCConfiguration config;
2748 config.enable_dtls_srtp = true;
2749 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002750 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002751
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002752 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002753 EXPECT_TRUE(
2754 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2755 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2756 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2757
2758 // Create a session description based on another SDP with another
2759 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002760 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002761
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002762 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002763 EXPECT_TRUE(
2764 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2765}
2766
2767// This test verifies that when remote tracks are added/removed from SDP, the
2768// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002769// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2770// specific behavior.
2771TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002772 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002773 RTCConfiguration config;
2774 config.enable_dtls_srtp = true;
2775 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002776 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002777 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002778 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002779 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2780 reference_collection_));
2781
2782 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002783 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002784 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002785 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002786 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2787 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002788 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002789 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2790 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002791 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002792 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2793 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002794
2795 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002796 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002797 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002798 MockTrackObserver audio_track_observer(audio_track2);
2799 MockTrackObserver video_track_observer(video_track2);
2800
2801 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2802 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002803 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002804 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2805 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002806 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002807 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002808 audio_track2->state(), kTimeout);
2809 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2810 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002811}
2812
2813// This tests that remote tracks are ended if a local session description is set
2814// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002815TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002816 RTCConfiguration config;
2817 config.enable_dtls_srtp = true;
2818 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002819 // First create and set a remote offer, then reject its video content in our
2820 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002821 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2822 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2823 ASSERT_TRUE(audio_receiver);
2824 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2825 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002826
Steve Anton36da6ff2018-02-16 16:04:20 -08002827 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2828 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002829 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002830 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2831 video_receiver->track();
2832 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002833
kwibergd1fe2812016-04-27 06:47:29 -07002834 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002835 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002836 cricket::ContentInfo* video_info =
2837 local_answer->description()->GetContentByName("video");
2838 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002839 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002840 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2841 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002842
2843 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002844 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002845 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002846 video_info = local_offer->description()->GetContentByName("video");
2847 ASSERT_TRUE(video_info != nullptr);
2848 video_info->rejected = true;
2849 cricket::ContentInfo* audio_info =
2850 local_offer->description()->GetContentByName("audio");
2851 ASSERT_TRUE(audio_info != nullptr);
2852 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002853 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002854 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002855 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2856 kTimeout);
2857 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2858 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002859}
2860
2861// This tests that we won't crash if the remote track has been removed outside
2862// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002863// Don't run under Unified Plan since the stream API is not available.
2864TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002865 RTCConfiguration config;
2866 config.enable_dtls_srtp = true;
2867 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002868 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002869 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2870 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2871 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2872
kwibergd1fe2812016-04-27 06:47:29 -07002873 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002874 webrtc::CreateSessionDescription(SdpType::kAnswer,
2875 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002876 cricket::ContentInfo* video_info =
2877 local_answer->description()->GetContentByName("video");
2878 video_info->rejected = true;
2879 cricket::ContentInfo* audio_info =
2880 local_answer->description()->GetContentByName("audio");
2881 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002882 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002883
2884 // No crash is a pass.
2885}
2886
deadbeef5e97fb52015-10-15 12:49:08 -07002887// This tests that if a recvonly remote description is set, no remote streams
2888// will be created, even if the description contains SSRCs/MSIDs.
2889// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002890TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002891 RTCConfiguration config;
2892 config.enable_dtls_srtp = true;
2893 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002894
Steve Anton36da6ff2018-02-16 16:04:20 -08002895 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002896 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2897 strlen(kRecvonly), &recvonly_offer);
2898 CreateAndSetRemoteOffer(recvonly_offer);
2899
2900 EXPECT_EQ(0u, observer_.remote_streams()->count());
2901}
2902
deadbeefab9b2d12015-10-14 11:33:11 -07002903// This tests that a default MediaStream is created if a remote session
2904// description doesn't contain any streams and no MSID support.
2905// It also tests that the default stream is updated if a video m-line is added
2906// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002907// Don't run under Unified Plan since this behavior is Plan B specific.
2908TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002909 RTCConfiguration config;
2910 config.enable_dtls_srtp = true;
2911 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002912 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2913
2914 ASSERT_EQ(1u, observer_.remote_streams()->count());
2915 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2916
2917 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2918 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002919 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002920
2921 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2922 ASSERT_EQ(1u, observer_.remote_streams()->count());
2923 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2924 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002925 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2926 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002927 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2928 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002929 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2930 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002931}
2932
2933// This tests that a default MediaStream is created if a remote session
2934// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002935// Don't run under Unified Plan since this behavior is Plan B specific.
2936TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002937 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002938 RTCConfiguration config;
2939 config.enable_dtls_srtp = true;
2940 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002941 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2942
2943 ASSERT_EQ(1u, observer_.remote_streams()->count());
2944 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2945
2946 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2947 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002948 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002949}
2950
2951// This tests that it won't crash when PeerConnection tries to remove
2952// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002953// Don't run under Unified Plan since this behavior is Plan B specific.
2954TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002955 RTCConfiguration config;
2956 config.enable_dtls_srtp = true;
2957 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002958 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002959 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2960 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2961 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2962
2963 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2964
2965 // No crash is a pass.
2966}
2967
2968// This tests that a default MediaStream is created if the remote session
2969// description doesn't contain any streams and don't contain an indication if
2970// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002971// Don't run under Unified Plan since this behavior is Plan B specific.
2972TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002973 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002974 RTCConfiguration config;
2975 config.enable_dtls_srtp = true;
2976 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002977 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2978
2979 ASSERT_EQ(1u, observer_.remote_streams()->count());
2980 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2981 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2982 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2983}
2984
2985// This tests that a default MediaStream is not created if the remote session
2986// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002987// Don't run under Unified Plan since this behavior is Plan B specific.
2988TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002989 RTCConfiguration config;
2990 config.enable_dtls_srtp = true;
2991 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002992 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2993 EXPECT_EQ(0u, observer_.remote_streams()->count());
2994}
2995
deadbeefbda7e0b2015-12-08 17:13:40 -08002996// This tests that when setting a new description, the old default tracks are
2997// not destroyed and recreated.
2998// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002999// Don't run under Unified Plan since this behavior is Plan B specific.
3000TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003001 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003002 RTCConfiguration config;
3003 config.enable_dtls_srtp = true;
3004 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003005 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3006
3007 ASSERT_EQ(1u, observer_.remote_streams()->count());
3008 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3009 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3010
3011 // Set the track to "disabled", then set a new description and ensure the
3012 // track is still disabled, which ensures it hasn't been recreated.
3013 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3014 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3015 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3016 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3017}
3018
deadbeefab9b2d12015-10-14 11:33:11 -07003019// This tests that a default MediaStream is not created if a remote session
3020// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003021// Don't run under Unified Plan since this behavior is Plan B specific.
3022TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003023 RTCConfiguration config;
3024 config.enable_dtls_srtp = true;
3025 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003026 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003027 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003028 EXPECT_TRUE(
3029 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3030
3031 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3032 EXPECT_EQ(0u, observer_.remote_streams()->count());
3033}
3034
Seth Hampson5897a6e2018-04-03 11:16:33 -07003035// This tests that a default MediaStream is created if a remote SDP comes from
3036// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3037TEST_F(PeerConnectionInterfaceTestPlanB,
3038 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003039 RTCConfiguration config;
3040 config.enable_dtls_srtp = true;
3041 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003042 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3043 // Add a=msid lines to simulate a Unified Plan endpoint that only
3044 // signals stream IDs with a=msid lines.
3045 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3046
3047 CreateAndSetRemoteOffer(sdp_string);
3048
3049 ASSERT_EQ(1u, observer_.remote_streams()->count());
3050 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3051 EXPECT_EQ("default", remote_stream->id());
3052 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3053}
3054
Seth Hampson5b4f0752018-04-02 16:31:36 -07003055// This tests that when a Plan B endpoint receives an SDP that signals no media
3056// stream IDs indicated by the special character "-" in the a=msid line, that
3057// a default stream ID will be used for the MediaStream ID. This can occur
3058// when a Unified Plan endpoint signals no media stream IDs, but signals both
3059// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3060TEST_F(PeerConnectionInterfaceTestPlanB,
3061 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003062 RTCConfiguration config;
3063 config.enable_dtls_srtp = true;
3064 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003065 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3066 // the sender's stream ID will be interpreted as no stream IDs.
3067 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3068 sdp_string.append("a=msid:- audiotrack0\n");
3069
3070 CreateAndSetRemoteOffer(sdp_string);
3071
3072 ASSERT_EQ(1u, observer_.remote_streams()->count());
3073 // Because SSRCs are signaled the track ID will be what was signaled in the
3074 // a=msid line.
3075 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3076 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3077 EXPECT_EQ("default", remote_stream->id());
3078 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003079
3080 // Previously a bug ocurred when setting the remote description a second time.
3081 // This is because we checked equality of the remote StreamParams stream ID
3082 // (empty), and the previously set stream ID for the remote sender
3083 // ("default"). This cause a track to be removed, then added, when really
3084 // nothing should occur because it is the same track.
3085 CreateAndSetRemoteOffer(sdp_string);
3086 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3087 EXPECT_EQ(1u, observer_.add_track_events_.size());
3088 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3089 remote_stream = observer_.remote_streams()->at(0);
3090 EXPECT_EQ("default", remote_stream->id());
3091 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003092}
3093
deadbeefab9b2d12015-10-14 11:33:11 -07003094// This tests that an RtpSender is created when the local description is set
3095// after adding a local stream.
3096// TODO(deadbeef): This test and the one below it need to be updated when
3097// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003098// Don't run under Unified Plan since this behavior is Plan B specific.
3099TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003100 RTCConfiguration config;
3101 config.enable_dtls_srtp = true;
3102 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003103
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003104 // Create an offer with 1 stream with 2 tracks of each type.
3105 rtc::scoped_refptr<StreamCollection> stream_collection =
3106 CreateStreamCollection(1, 2);
3107 pc_->AddStream(stream_collection->at(0));
3108 std::unique_ptr<SessionDescriptionInterface> offer;
3109 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003110 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003111
deadbeefab9b2d12015-10-14 11:33:11 -07003112 auto senders = pc_->GetSenders();
3113 EXPECT_EQ(4u, senders.size());
3114 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3115 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3116 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3117 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3118
3119 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003120 pc_->RemoveStream(stream_collection->at(0));
3121 stream_collection = CreateStreamCollection(1, 1);
3122 pc_->AddStream(stream_collection->at(0));
3123 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003124 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003125
deadbeefab9b2d12015-10-14 11:33:11 -07003126 senders = pc_->GetSenders();
3127 EXPECT_EQ(2u, senders.size());
3128 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3129 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3130 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3131 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3132}
3133
3134// This tests that an RtpSender is created when the local description is set
3135// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003136// Don't run under Unified Plan since this behavior is Plan B specific.
3137TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003138 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003139 RTCConfiguration config;
3140 config.enable_dtls_srtp = true;
3141 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003142
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003143 rtc::scoped_refptr<StreamCollection> stream_collection =
3144 CreateStreamCollection(1, 2);
3145 // Add a stream to create the offer, but remove it afterwards.
3146 pc_->AddStream(stream_collection->at(0));
3147 std::unique_ptr<SessionDescriptionInterface> offer;
3148 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3149 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003150
Steve Antondb45ca82017-09-11 18:27:34 -07003151 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003152 auto senders = pc_->GetSenders();
3153 EXPECT_EQ(0u, senders.size());
3154
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003155 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003156 senders = pc_->GetSenders();
3157 EXPECT_EQ(4u, senders.size());
3158 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3159 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3160 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3161 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3162}
3163
3164// This tests that the expected behavior occurs if the SSRC on a local track is
3165// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003166TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003167 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003168 RTCConfiguration config;
3169 config.enable_dtls_srtp = true;
3170 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003171
Steve Anton36da6ff2018-02-16 16:04:20 -08003172 AddAudioTrack(kAudioTracks[0]);
3173 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003174 std::unique_ptr<SessionDescriptionInterface> offer;
3175 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3176 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003177 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3178 webrtc::CreateSessionDescription(
3179 webrtc::SdpType::kOffer, offer->session_id(),
3180 offer->session_version(),
3181 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003182 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003183
deadbeefab9b2d12015-10-14 11:33:11 -07003184 auto senders = pc_->GetSenders();
3185 EXPECT_EQ(2u, senders.size());
3186 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3187 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3188
3189 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003190 cricket::MediaContentDescription* desc =
3191 cricket::GetFirstAudioContentDescription(modified_offer->description());
3192 ASSERT_TRUE(desc != NULL);
3193 for (StreamParams& stream : desc->mutable_streams()) {
3194 for (unsigned int& ssrc : stream.ssrcs) {
3195 ++ssrc;
3196 }
3197 }
deadbeefab9b2d12015-10-14 11:33:11 -07003198
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003199 desc =
3200 cricket::GetFirstVideoContentDescription(modified_offer->description());
3201 ASSERT_TRUE(desc != NULL);
3202 for (StreamParams& stream : desc->mutable_streams()) {
3203 for (unsigned int& ssrc : stream.ssrcs) {
3204 ++ssrc;
3205 }
3206 }
3207
Steve Antondb45ca82017-09-11 18:27:34 -07003208 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003209 senders = pc_->GetSenders();
3210 EXPECT_EQ(2u, senders.size());
3211 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3212 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3213 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3214 // changed.
3215}
3216
3217// This tests that the expected behavior occurs if a new session description is
3218// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003219// Don't run under Unified Plan since the stream API is not available.
3220TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003221 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003222 RTCConfiguration config;
3223 config.enable_dtls_srtp = true;
3224 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003225
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003226 rtc::scoped_refptr<StreamCollection> stream_collection =
3227 CreateStreamCollection(2, 1);
3228 pc_->AddStream(stream_collection->at(0));
3229 std::unique_ptr<SessionDescriptionInterface> offer;
3230 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003231 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003232
deadbeefab9b2d12015-10-14 11:33:11 -07003233 auto senders = pc_->GetSenders();
3234 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003235 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3236 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003237
3238 // Add a new MediaStream but with the same tracks as in the first stream.
3239 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3240 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003241 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3242 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003243 pc_->AddStream(stream_1);
3244
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003245 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003246 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003247
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003248 auto new_senders = pc_->GetSenders();
3249 // Should be the same senders as before, but with updated stream id.
3250 // Note that this behavior is subject to change in the future.
3251 // We may decide the PC should ignore existing tracks in AddStream.
3252 EXPECT_EQ(senders, new_senders);
3253 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3254 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003255}
3256
zhihuang81c3a032016-11-17 12:06:24 -08003257// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003258TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003259 RTCConfiguration config;
3260 config.enable_dtls_srtp = true;
3261 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003262 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3263 EXPECT_EQ(observer_.num_added_tracks_, 1);
3264 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3265
3266 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003267 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003268 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003269 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3270}
3271
deadbeefd1a38b52016-12-10 13:15:33 -08003272// Test that when SetConfiguration is called and the configuration is
3273// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003274TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003275 PeerConnectionInterface::RTCConfiguration config;
3276 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003277 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003278 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003279 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3280 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003281
3282 // Do initial offer/answer so there's something to restart.
3283 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003284 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003285
3286 // Grab the ufrags.
3287 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3288
3289 // Change ICE policy, which should trigger an ICE restart on the next offer.
3290 config.type = PeerConnectionInterface::kAll;
3291 EXPECT_TRUE(pc_->SetConfiguration(config));
3292 CreateOfferAsLocalDescription();
3293
3294 // Grab the new ufrags.
3295 std::vector<std::string> subsequent_ufrags =
3296 GetUfrags(pc_->local_description());
3297
3298 // Sanity check.
3299 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3300 // Check that each ufrag is different.
3301 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3302 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3303 }
3304}
3305
3306// Test that when SetConfiguration is called and the configuration *isn't*
3307// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003308TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003309 PeerConnectionInterface::RTCConfiguration config;
3310 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003311 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003312 config = pc_->GetConfiguration();
3313 AddAudioTrack(kAudioTracks[0]);
3314 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003315
3316 // Do initial offer/answer so there's something to restart.
3317 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003318 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003319
3320 // Grab the ufrags.
3321 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3322
3323 // Call SetConfiguration with a config identical to what the PC was
3324 // constructed with.
3325 EXPECT_TRUE(pc_->SetConfiguration(config));
3326 CreateOfferAsLocalDescription();
3327
3328 // Grab the new ufrags.
3329 std::vector<std::string> subsequent_ufrags =
3330 GetUfrags(pc_->local_description());
3331
3332 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3333}
3334
3335// Test for a weird corner case scenario:
3336// 1. Audio/video session established.
3337// 2. SetConfiguration changes ICE config; ICE restart needed.
3338// 3. ICE restart initiated by remote peer, but only for one m= section.
3339// 4. Next createOffer should initiate an ICE restart, but only for the other
3340// m= section; it would be pointless to do an ICE restart for the m= section
3341// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003342TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003343 PeerConnectionInterface::RTCConfiguration config;
3344 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003345 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003346 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003347 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3348 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003349
3350 // Do initial offer/answer so there's something to restart.
3351 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003352 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003353
3354 // Change ICE policy, which should set the "needs-ice-restart" flag.
3355 config.type = PeerConnectionInterface::kAll;
3356 EXPECT_TRUE(pc_->SetConfiguration(config));
3357
3358 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003359 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003360 webrtc::CreateSessionDescription(SdpType::kOffer,
3361 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003362 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003363 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3364 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003365 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003366 CreateAnswerAsLocalDescription();
3367
3368 // Grab the ufrags.
3369 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003370 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003371
3372 // Create offer and grab the new ufrags.
3373 CreateOfferAsLocalDescription();
3374 std::vector<std::string> subsequent_ufrags =
3375 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003376 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003377
3378 // Ensure that only the ufrag for the second m= section changed.
3379 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3380 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3381}
3382
deadbeeffe4a8a42016-12-20 17:56:17 -08003383// Tests that the methods to return current/pending descriptions work as
3384// expected at different points in the offer/answer exchange. This test does
3385// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003386TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003387 // This disables DTLS so we can apply an answer to ourselves.
3388 CreatePeerConnection();
3389
3390 // Create initial local offer and get SDP (which will also be used as
3391 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003392 std::unique_ptr<SessionDescriptionInterface> local_offer;
3393 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003394 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003395 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003396
3397 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003398 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3399 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3400 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003401 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3402 EXPECT_EQ(nullptr, pc_->current_local_description());
3403 EXPECT_EQ(nullptr, pc_->current_remote_description());
3404
3405 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003406 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003407 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003408 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3409 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3410 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3411 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003412 EXPECT_EQ(nullptr, pc_->current_local_description());
3413 EXPECT_EQ(nullptr, pc_->current_remote_description());
3414
3415 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003416 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003417 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003418 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3419 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003420 EXPECT_EQ(nullptr, pc_->pending_local_description());
3421 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003422 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3423 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003424
3425 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003426 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003427 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003428 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3429 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3430 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003431 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003432 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3433 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003434
3435 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003436 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003437 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003438 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3439 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3440 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3441 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3442 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3443 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003444
3445 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003446 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003447 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003448 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3449 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003450 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3451 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003452 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3453 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003454}
3455
zhihuang77985012017-02-07 15:45:16 -08003456// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3457// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003458// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003459TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003460 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003461 CreatePeerConnection();
3462 // The RtcEventLog will be reset when the PeerConnection is closed.
3463 pc_->Close();
3464
Elad Alon9e6565b2017-10-11 16:04:13 +02003465 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3466 std::string filename = webrtc::test::OutputPath() +
3467 test_info->test_case_name() + test_info->name();
3468 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3469
3470 constexpr int64_t max_size_bytes = 1024;
3471
zhihuang77985012017-02-07 15:45:16 -08003472 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3473 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003474
3475 // Cleanup.
3476 rtc::ClosePlatformFile(file);
3477 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003478}
3479
Elad Alon99c3fe52017-10-13 16:29:40 +02003480// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3481// after the PeerConnection is closed.
3482// This version tests the StartRtcEventLog version that receives an object
3483// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003484TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003485 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3486 CreatePeerConnection();
3487 // The RtcEventLog will be reset when the PeerConnection is closed.
3488 pc_->Close();
3489
3490 rtc::PlatformFile file = 0;
3491 int64_t max_size_bytes = 1024;
3492 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003493 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003494 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003495 pc_->StopRtcEventLog();
3496}
3497
deadbeef30952b42017-04-21 02:41:29 -07003498// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003499TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003500 CreatePeerConnection();
3501
3502 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003503 RTCOfferAnswerOptions options;
3504 options.offer_to_receive_audio = 1;
3505 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003506 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003507 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003508 cricket::SessionDescription* desc = offer->description();
3509 ASSERT_EQ(2u, desc->transport_infos().size());
3510 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3511 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3512
3513 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003514 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003515 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003516 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003517 desc = answer->description();
3518 ASSERT_EQ(2u, desc->transport_infos().size());
3519 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3520 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3521}
3522
deadbeef1dcb1642017-03-29 21:08:16 -07003523// Test that ICE renomination isn't offered if it's not enabled in the PC's
3524// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003525TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003526 PeerConnectionInterface::RTCConfiguration config;
3527 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003528 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003529 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003530
3531 std::unique_ptr<SessionDescriptionInterface> offer;
3532 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3533 cricket::SessionDescription* desc = offer->description();
3534 EXPECT_EQ(1u, desc->transport_infos().size());
3535 EXPECT_FALSE(
3536 desc->transport_infos()[0].description.GetIceParameters().renomination);
3537}
3538
3539// Test that the ICE renomination option is present in generated offers/answers
3540// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003541TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003542 PeerConnectionInterface::RTCConfiguration config;
3543 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003544 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003545 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003546
3547 std::unique_ptr<SessionDescriptionInterface> offer;
3548 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3549 cricket::SessionDescription* desc = offer->description();
3550 EXPECT_EQ(1u, desc->transport_infos().size());
3551 EXPECT_TRUE(
3552 desc->transport_infos()[0].description.GetIceParameters().renomination);
3553
3554 // Set the offer as a remote description, then create an answer and ensure it
3555 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003556 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003557 std::unique_ptr<SessionDescriptionInterface> answer;
3558 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3559 desc = answer->description();
3560 EXPECT_EQ(1u, desc->transport_infos().size());
3561 EXPECT_TRUE(
3562 desc->transport_infos()[0].description.GetIceParameters().renomination);
3563}
3564
3565// Test that if CreateOffer is called with the deprecated "offer to receive
3566// audio/video" constraints, they're processed and result in an offer with
3567// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003568TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003569 CreatePeerConnection();
3570
Niels Möllerf06f9232018-08-07 12:32:18 +02003571 RTCOfferAnswerOptions options;
3572 options.offer_to_receive_audio = 1;
3573 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003574 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003575 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003576
3577 cricket::SessionDescription* desc = offer->description();
3578 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3579 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3580 ASSERT_NE(nullptr, audio);
3581 ASSERT_NE(nullptr, video);
3582 EXPECT_FALSE(audio->rejected);
3583 EXPECT_FALSE(video->rejected);
3584}
3585
3586// Test that if CreateAnswer is called with the deprecated "offer to receive
3587// audio/video" constraints, they're processed and can be used to reject an
3588// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003589// Don't run under Unified Plan since this behavior is not supported.
3590TEST_F(PeerConnectionInterfaceTestPlanB,
3591 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003592 CreatePeerConnection();
3593
3594 // First, create an offer with audio/video and apply it as a remote
3595 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003596 RTCOfferAnswerOptions options;
3597 options.offer_to_receive_audio = 1;
3598 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003599 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003600 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003601 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003602
3603 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003604 options.offer_to_receive_audio = 0;
3605 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003606 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003607 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003608
3609 cricket::SessionDescription* desc = answer->description();
3610 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3611 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3612 ASSERT_NE(nullptr, audio);
3613 ASSERT_NE(nullptr, video);
3614 EXPECT_TRUE(audio->rejected);
3615 EXPECT_TRUE(video->rejected);
3616}
3617
deadbeef1dcb1642017-03-29 21:08:16 -07003618// Test that negotiation can succeed with a data channel only, and with the max
3619// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003620#ifdef HAVE_SCTP
3621TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3622#else
3623TEST_P(PeerConnectionInterfaceTest,
3624 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3625#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003626 PeerConnectionInterface::RTCConfiguration config;
3627 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003628 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003629
3630 // First, create an offer with only a data channel and apply it as a remote
3631 // description.
3632 pc_->CreateDataChannel("test", nullptr);
3633 std::unique_ptr<SessionDescriptionInterface> offer;
3634 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003635 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003636
3637 // Create and set answer as well.
3638 std::unique_ptr<SessionDescriptionInterface> answer;
3639 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003640 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003641}
3642
Steve Anton36da6ff2018-02-16 16:04:20 -08003643TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003644 CreatePeerConnection();
3645 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003646 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003647 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3648}
3649
Steve Anton36da6ff2018-02-16 16:04:20 -08003650TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003651 CreatePeerConnection();
3652 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003653 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003654 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3655}
3656
Steve Anton36da6ff2018-02-16 16:04:20 -08003657TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003658 CreatePeerConnection();
3659 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003660 bitrate.min_bitrate_bps = 5;
3661 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003662 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3663}
3664
Steve Anton36da6ff2018-02-16 16:04:20 -08003665TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003666 CreatePeerConnection();
3667 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003668 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003669 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3670}
3671
Steve Anton36da6ff2018-02-16 16:04:20 -08003672TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003673 CreatePeerConnection();
3674 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003675 bitrate.current_bitrate_bps = 10;
3676 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003677 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3678}
3679
Steve Anton36da6ff2018-02-16 16:04:20 -08003680TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003681 CreatePeerConnection();
3682 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003683 bitrate.min_bitrate_bps = 10;
3684 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003685 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3686}
3687
Steve Anton36da6ff2018-02-16 16:04:20 -08003688TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003689 CreatePeerConnection();
3690 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003691 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003692 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3693}
3694
Steve Anton038834f2017-07-14 15:59:59 -07003695// ice_regather_interval_range requires WebRTC to be configured for continual
3696// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003697TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003698 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3699 PeerConnectionInterface::RTCConfiguration config;
3700 config.ice_regather_interval_range.emplace(1000, 2000);
3701 config.continual_gathering_policy =
3702 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3703 CreatePeerConnectionExpectFail(config);
3704}
3705
3706// Ensures that there is no error when ice_regather_interval_range is set with
3707// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003708TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003709 SetIceRegatherIntervalRangeWithContinualGathering) {
3710 PeerConnectionInterface::RTCConfiguration config;
3711 config.ice_regather_interval_range.emplace(1000, 2000);
3712 config.continual_gathering_policy =
3713 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003714 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003715}
3716
Niels Möller0c4f7be2018-05-07 14:01:37 +02003717// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003718// by Call's BitrateConstraints, which comes from the SDP or a default value.
3719// This test checks that a call to SetBitrate with a current bitrate that will
3720// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003721TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003722 CreatePeerConnection();
3723 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003724 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003725 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3726}
3727
zhihuang1c378ed2017-08-17 14:10:50 -07003728// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003729TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003730 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3731 RTCOfferAnswerOptions rtc_options;
3732
3733 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3734 // than kMaxOfferToReceiveMedia should be treated as invalid.
3735 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3736 CreatePeerConnection();
3737 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3738
3739 rtc_options.offer_to_receive_audio =
3740 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3741 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3742}
3743
Steve Anton36da6ff2018-02-16 16:04:20 -08003744TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003745 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3746 RTCOfferAnswerOptions rtc_options;
3747
3748 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3749 // than kMaxOfferToReceiveMedia should be treated as invalid.
3750 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3751 CreatePeerConnection();
3752 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3753
3754 rtc_options.offer_to_receive_video =
3755 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3756 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3757}
3758
3759// Test that the audio and video content will be added to an offer if both
3760// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003761TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003762 RTCOfferAnswerOptions rtc_options;
3763 rtc_options.offer_to_receive_audio = 1;
3764 rtc_options.offer_to_receive_video = 1;
3765
3766 std::unique_ptr<SessionDescriptionInterface> offer;
3767 CreatePeerConnection();
3768 offer = CreateOfferWithOptions(rtc_options);
3769 ASSERT_TRUE(offer);
3770 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3771 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3772}
3773
3774// Test that only audio content will be added to the offer if only
3775// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003776TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003777 RTCOfferAnswerOptions rtc_options;
3778 rtc_options.offer_to_receive_audio = 1;
3779 rtc_options.offer_to_receive_video = 0;
3780
3781 std::unique_ptr<SessionDescriptionInterface> offer;
3782 CreatePeerConnection();
3783 offer = CreateOfferWithOptions(rtc_options);
3784 ASSERT_TRUE(offer);
3785 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3786 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3787}
3788
3789// Test that only video content will be added if only |offer_to_receive_video|
3790// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003791TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003792 RTCOfferAnswerOptions rtc_options;
3793 rtc_options.offer_to_receive_audio = 0;
3794 rtc_options.offer_to_receive_video = 1;
3795
3796 std::unique_ptr<SessionDescriptionInterface> offer;
3797 CreatePeerConnection();
3798 offer = CreateOfferWithOptions(rtc_options);
3799 ASSERT_TRUE(offer);
3800 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3801 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3802}
3803
zhihuang1c378ed2017-08-17 14:10:50 -07003804// Test that no media content will be added to the offer if using default
3805// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003806TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003807 RTCOfferAnswerOptions rtc_options;
3808
3809 std::unique_ptr<SessionDescriptionInterface> offer;
3810 CreatePeerConnection();
3811 offer = CreateOfferWithOptions(rtc_options);
3812 ASSERT_TRUE(offer);
3813 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3814 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3815}
3816
3817// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3818// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003819TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3820 CreatePeerConnection();
3821
zhihuang1c378ed2017-08-17 14:10:50 -07003822 RTCOfferAnswerOptions rtc_options;
3823 rtc_options.ice_restart = false;
3824 rtc_options.offer_to_receive_audio = 1;
3825
3826 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003827 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003828 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3829 auto ufrag1 =
3830 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3831 auto pwd1 =
3832 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003833
3834 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3835 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003836 auto ufrag2 =
3837 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3838 auto pwd2 =
3839 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003840
3841 // |ice_restart| is true, the ufrag/pwd should change.
3842 rtc_options.ice_restart = true;
3843 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003844 auto ufrag3 =
3845 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3846 auto pwd3 =
3847 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003848
3849 EXPECT_EQ(ufrag1, ufrag2);
3850 EXPECT_EQ(pwd1, pwd2);
3851 EXPECT_NE(ufrag2, ufrag3);
3852 EXPECT_NE(pwd2, pwd3);
3853}
3854
3855// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3856// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003857TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003858 RTCOfferAnswerOptions rtc_options;
3859 rtc_options.offer_to_receive_audio = 1;
3860 rtc_options.offer_to_receive_video = 1;
3861
3862 std::unique_ptr<SessionDescriptionInterface> offer;
3863 CreatePeerConnection();
3864
3865 rtc_options.use_rtp_mux = true;
3866 offer = CreateOfferWithOptions(rtc_options);
3867 ASSERT_TRUE(offer);
3868 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3869 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3870 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3871
3872 rtc_options.use_rtp_mux = false;
3873 offer = CreateOfferWithOptions(rtc_options);
3874 ASSERT_TRUE(offer);
3875 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3876 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3877 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3878}
3879
zhihuang141aacb2017-08-29 13:23:53 -07003880// This test ensures OnRenegotiationNeeded is called when we add track with
3881// MediaStream -> AddTrack in the same way it is called when we add track with
3882// PeerConnection -> AddTrack.
3883// The test can be removed once addStream is rewritten in terms of addTrack
3884// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003885// Don't run under Unified Plan since the stream API is not available.
3886TEST_F(PeerConnectionInterfaceTestPlanB,
3887 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003888 CreatePeerConnectionWithoutDtls();
3889 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003890 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003891 pc_->AddStream(stream);
3892 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3893 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3894 rtc::scoped_refptr<VideoTrackInterface> video_track(
3895 pc_factory_->CreateVideoTrack(
3896 "video_track", pc_factory_->CreateVideoSource(
3897 std::unique_ptr<cricket::VideoCapturer>(
3898 new cricket::FakeVideoCapturer()))));
3899 stream->AddTrack(audio_track);
3900 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3901 observer_.renegotiation_needed_ = false;
3902
3903 stream->AddTrack(video_track);
3904 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3905 observer_.renegotiation_needed_ = false;
3906
3907 stream->RemoveTrack(audio_track);
3908 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3909 observer_.renegotiation_needed_ = false;
3910
3911 stream->RemoveTrack(video_track);
3912 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3913 observer_.renegotiation_needed_ = false;
3914}
3915
Zhi Huangb2d355e2017-10-26 17:26:37 -07003916// Tests that an error is returned if a description is applied that has fewer
3917// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003918TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003919 MediaSectionCountEnforcedForSubsequentOffer) {
3920 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003921 AddAudioTrack("audio_label");
3922 AddVideoTrack("video_label");
3923
Zhi Huangb2d355e2017-10-26 17:26:37 -07003924 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003925 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003926 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3927
3928 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003929 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003930 offer->description()->contents().pop_back();
3931 offer->description()->contents().pop_back();
3932 ASSERT_TRUE(offer->description()->contents().empty());
3933 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3934
3935 std::unique_ptr<SessionDescriptionInterface> answer;
3936 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3937 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3938
3939 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003940 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003941 offer->description()->contents().pop_back();
3942 offer->description()->contents().pop_back();
3943 ASSERT_TRUE(offer->description()->contents().empty());
3944 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3945}
3946
Steve Anton36da6ff2018-02-16 16:04:20 -08003947INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3948 PeerConnectionInterfaceTest,
3949 Values(SdpSemantics::kPlanB,
3950 SdpSemantics::kUnifiedPlan));
3951
nisse51542be2016-02-12 02:27:06 -08003952class PeerConnectionMediaConfigTest : public testing::Test {
3953 protected:
3954 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003955 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003956 pcf_->Initialize();
3957 }
nisseeaabdf62017-05-05 02:23:02 -07003958 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003959 const RTCConfiguration& config) {
3960 rtc::scoped_refptr<PeerConnectionInterface> pc(
3961 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003962 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003963 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003964 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003965 }
3966
zhihuang9763d562016-08-05 11:14:50 -07003967 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003968 MockPeerConnectionObserver observer_;
3969};
3970
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003971// This sanity check validates the test infrastructure itself.
3972TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3973 PeerConnectionInterface::RTCConfiguration config;
3974 rtc::scoped_refptr<PeerConnectionInterface> pc(
3975 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3976 EXPECT_TRUE(pc.get());
3977 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3978 pc->Close(); // No abort -> ok.
3979 SUCCEED();
3980}
3981
nisse51542be2016-02-12 02:27:06 -08003982// This test verifies the default behaviour with no constraints and a
3983// default RTCConfiguration.
3984TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3985 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003986
Niels Möllerf06f9232018-08-07 12:32:18 +02003987 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003988
3989 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003990 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3991 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003992 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003993 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003994}
3995
Niels Möller1d7ecd22018-01-18 15:25:12 +01003996// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003997// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003998TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3999 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004000
Niels Möller71bdda02016-03-31 12:59:59 +02004001 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004002 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004003
Niels Möller1d7ecd22018-01-18 15:25:12 +01004004 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004005}
4006
Niels Möller6539f692018-01-18 08:58:50 +01004007// This test verifies that the experiment_cpu_load_estimator flag is
4008// propagated from RTCConfiguration to the PeerConnection.
4009TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4010 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004011
4012 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004013 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004014
4015 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4016}
4017
deadbeef293e9262017-01-11 12:28:30 -08004018// Tests a few random fields being different.
4019TEST(RTCConfigurationTest, ComparisonOperators) {
4020 PeerConnectionInterface::RTCConfiguration a;
4021 PeerConnectionInterface::RTCConfiguration b;
4022 EXPECT_EQ(a, b);
4023
4024 PeerConnectionInterface::RTCConfiguration c;
4025 c.servers.push_back(PeerConnectionInterface::IceServer());
4026 EXPECT_NE(a, c);
4027
4028 PeerConnectionInterface::RTCConfiguration d;
4029 d.type = PeerConnectionInterface::kRelay;
4030 EXPECT_NE(a, d);
4031
4032 PeerConnectionInterface::RTCConfiguration e;
4033 e.audio_jitter_buffer_max_packets = 5;
4034 EXPECT_NE(a, e);
4035
4036 PeerConnectionInterface::RTCConfiguration f;
4037 f.ice_connection_receiving_timeout = 1337;
4038 EXPECT_NE(a, f);
4039
4040 PeerConnectionInterface::RTCConfiguration g;
4041 g.disable_ipv6 = true;
4042 EXPECT_NE(a, g);
4043
4044 PeerConnectionInterface::RTCConfiguration h(
4045 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4046 EXPECT_NE(a, h);
4047}