blob: dd5d0d16a91986b0ec45f24b7df030e11ea40b30 [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"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010020#include "api/create_peerconnection_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/jsepsessiondescription.h"
22#include "api/mediastreaminterface.h"
23#include "api/peerconnectioninterface.h"
24#include "api/rtpreceiverinterface.h"
25#include "api/rtpsenderinterface.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();
zhihuang38ede132017-06-15 12:52:32 -0700637
henrika919dc2e2017-10-12 14:24:55 +0200638 // Use fake audio device module since we're only testing the interface
639 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700640 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
641 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200642 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200643 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000644 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100645 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700646
647 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
648 webrtc::CreateCallFactory();
649
650 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
651 webrtc::CreateRtcEventLogFactory();
652
653 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
654 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200655 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700656 std::move(event_log_factory));
657 }
658
659 PeerConnectionFactoryForTest(
660 rtc::Thread* network_thread,
661 rtc::Thread* worker_thread,
662 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700663 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
664 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
665 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
666 : webrtc::PeerConnectionFactory(network_thread,
667 worker_thread,
668 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700669 std::move(media_engine),
670 std::move(call_factory),
671 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800672
deadbeefd7850b22017-08-23 10:59:19 -0700673 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700674};
675
Steve Anton36da6ff2018-02-16 16:04:20 -0800676// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
677class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800679 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
680 : vss_(new rtc::VirtualSocketServer()),
681 main_(vss_.get()),
682 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800683#ifdef WEBRTC_ANDROID
684 webrtc::InitializeAndroidObjects();
685#endif
686 }
687
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700689 // Use fake audio capture module since we're only testing the interface
690 // level, and using a real one could make tests flaky when run in parallel.
691 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700693 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200694 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
695 fake_audio_capture_module_),
696 webrtc::CreateBuiltinAudioEncoderFactory(),
697 webrtc::CreateBuiltinAudioDecoderFactory(),
698 webrtc::CreateBuiltinVideoEncoderFactory(),
699 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
700 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700701 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700702 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700703 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700704 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 }
706
707 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200708 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 }
710
deadbeef293e9262017-01-11 12:28:30 -0800711 // DTLS does not work in a loopback call, so is disabled for most of the
712 // tests in this file.
713 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200714 RTCConfiguration config;
715 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800716
Niels Möllerf06f9232018-08-07 12:32:18 +0200717 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 }
719
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700720 void CreatePeerConnectionWithIceTransportsType(
721 PeerConnectionInterface::IceTransportsType type) {
722 PeerConnectionInterface::RTCConfiguration config;
723 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200724 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700725 }
726
727 void CreatePeerConnectionWithIceServer(const std::string& uri,
728 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800729 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700731 server.uri = uri;
732 server.password = password;
733 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200734 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700735 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736
Niels Möllerf06f9232018-08-07 12:32:18 +0200737 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700738 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800739 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
740 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000741
deadbeef1dcb1642017-03-29 21:08:16 -0700742 // Create certificate generator unless DTLS constraint is explicitly set to
743 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200744 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200745
746 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800747 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
748 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000749 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800750 RTCConfiguration modified_config = config;
751 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200752 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200753 modified_config, std::move(port_allocator), std::move(cert_generator),
754 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 ASSERT_TRUE(pc_.get() != NULL);
756 observer_.SetPeerConnectionInterface(pc_.get());
757 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
758 }
759
deadbeef0a6c4ca2015-10-06 11:38:28 -0700760 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800761 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700762 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700763 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800764 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800765 config.sdp_semantics = sdp_semantics_;
766 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200767 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800768 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700769 }
770
Steve Anton038834f2017-07-14 15:59:59 -0700771 void CreatePeerConnectionExpectFail(
772 PeerConnectionInterface::RTCConfiguration config) {
773 PeerConnectionInterface::IceServer server;
774 server.uri = kTurnIceServerUri;
775 server.password = kTurnPassword;
776 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800777 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700778 rtc::scoped_refptr<PeerConnectionInterface> pc =
779 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
780 EXPECT_EQ(nullptr, pc);
781 }
782
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700784 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800785 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
786 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
787 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800789 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
deadbeef0a6c4ca2015-10-06 11:38:28 -0700791 CreatePeerConnectionExpectFail(kStunInvalidPort);
792 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
793 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700795 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800796 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
797 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800799 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800803 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 }
805
806 void ReleasePeerConnection() {
807 pc_ = NULL;
808 observer_.SetPeerConnectionInterface(NULL);
809 }
810
Steve Anton36da6ff2018-02-16 16:04:20 -0800811 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
812 const std::string& label) {
813 auto video_source = pc_factory_->CreateVideoSource(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200814 absl::make_unique<cricket::FakeVideoCapturer>(), nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -0800815 return pc_factory_->CreateVideoTrack(label, video_source);
816 }
817
818 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800819 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800820 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800821 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800822 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
824 observer_.renegotiation_needed_ = false;
825 }
826
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700828 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800830 stream->AddTrack(CreateVideoTrack(label + "v0"));
831 ASSERT_TRUE(pc_->AddStream(stream));
832 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
833 observer_.renegotiation_needed_ = false;
834 }
835
836 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
837 const std::string& label) {
838 return pc_factory_->CreateAudioTrack(label, nullptr);
839 }
840
841 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800842 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800843 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800844 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800845 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
846 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
847 observer_.renegotiation_needed_ = false;
848 }
849
850 void AddAudioStream(const std::string& label) {
851 rtc::scoped_refptr<MediaStreamInterface> stream(
852 pc_factory_->CreateLocalMediaStream(label));
853 stream->AddTrack(CreateAudioTrack(label + "a0"));
854 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
856 observer_.renegotiation_needed_ = false;
857 }
858
Seth Hampson845e8782018-03-02 11:34:10 -0800859 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 const std::string& audio_track_label,
861 const std::string& video_track_label) {
862 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700863 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800864 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800865 stream->AddTrack(CreateAudioTrack(audio_track_label));
866 stream->AddTrack(CreateVideoTrack(video_track_label));
867 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
869 observer_.renegotiation_needed_ = false;
870 }
871
Steve Anton36da6ff2018-02-16 16:04:20 -0800872 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
873 cricket::MediaType media_type) {
874 for (auto receiver : pc_->GetReceivers()) {
875 if (receiver->media_type() == media_type) {
876 return receiver;
877 }
878 }
879 return nullptr;
880 }
881
kwibergd1fe2812016-04-27 06:47:29 -0700882 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200883 const RTCOfferAnswerOptions* options,
884 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200885 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
886 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200888 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200890 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 }
892 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700893 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 return observer->result();
895 }
896
kwibergd1fe2812016-04-27 06:47:29 -0700897 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200898 const RTCOfferAnswerOptions* options) {
899 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 }
901
kwibergd1fe2812016-04-27 06:47:29 -0700902 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200903 const RTCOfferAnswerOptions* options) {
904 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 }
906
Steve Antondb45ca82017-09-11 18:27:34 -0700907 bool DoSetSessionDescription(
908 std::unique_ptr<SessionDescriptionInterface> desc,
909 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200910 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
911 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700913 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700915 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 }
zhihuang29ff8442016-07-27 11:07:25 -0700917 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
918 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
919 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 return observer->result();
921 }
922
Steve Antondb45ca82017-09-11 18:27:34 -0700923 bool DoSetLocalDescription(
924 std::unique_ptr<SessionDescriptionInterface> desc) {
925 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 }
927
Steve Antondb45ca82017-09-11 18:27:34 -0700928 bool DoSetRemoteDescription(
929 std::unique_ptr<SessionDescriptionInterface> desc) {
930 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 }
932
933 // Calls PeerConnection::GetStats and check the return value.
934 // It does not verify the values in the StatReports since a RTCP packet might
935 // be required.
936 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000937 rtc::scoped_refptr<MockStatsObserver> observer(
938 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200939 if (!pc_->GetStats(observer, track,
940 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 return false;
942 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
943 return observer->called();
944 }
945
Harald Alvestrand89061872018-01-02 14:08:34 +0100946 // Call the standards-compliant GetStats function.
947 bool DoGetRTCStats() {
948 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
949 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
950 pc_->GetStats(callback);
951 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
952 return callback->called();
953 }
954
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800956 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800958 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800959 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800960 } else {
961 // Unified Plan does not support AddStream, so just add an audio and video
962 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800963 AddAudioTrack(kAudioTracks[0], {kStreamId1});
964 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800965 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 CreateOfferReceiveAnswer();
967 }
968
969 // Verify that RTP Header extensions has been negotiated for audio and video.
970 void VerifyRemoteRtpHeaderExtensions() {
971 const cricket::MediaContentDescription* desc =
972 cricket::GetFirstAudioContentDescription(
973 pc_->remote_description()->description());
974 ASSERT_TRUE(desc != NULL);
975 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
976
977 desc = cricket::GetFirstVideoContentDescription(
978 pc_->remote_description()->description());
979 ASSERT_TRUE(desc != NULL);
980 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
981 }
982
983 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700984 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700985 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 std::string sdp;
987 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700988 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800989 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700990 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
992 }
993
deadbeefab9b2d12015-10-14 11:33:11 -0700994 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700995 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800996 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700997 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700998 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
999 }
1000
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001002 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001003 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004
1005 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1006 // audio codec change, even if the parameter has nothing to do with
1007 // receiving. Not all parameters are serialized to SDP.
1008 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1009 // the SessionDescription, it is necessary to do that here to in order to
1010 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1011 // https://code.google.com/p/webrtc/issues/detail?id=1356
1012 std::string sdp;
1013 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001014 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001015 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001016 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1018 }
1019
1020 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001021 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001022 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023
1024 std::string sdp;
1025 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001026 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001027 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001028 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1030 }
1031
1032 void CreateOfferReceiveAnswer() {
1033 CreateOfferAsLocalDescription();
1034 std::string sdp;
1035 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1036 CreateAnswerAsRemoteDescription(sdp);
1037 }
1038
1039 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001040 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001041 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1043 // audio codec change, even if the parameter has nothing to do with
1044 // receiving. Not all parameters are serialized to SDP.
1045 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1046 // the SessionDescription, it is necessary to do that here to in order to
1047 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1048 // https://code.google.com/p/webrtc/issues/detail?id=1356
1049 std::string sdp;
1050 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001051 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001052 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053
Steve Antondb45ca82017-09-11 18:27:34 -07001054 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001056 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001057 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 }
1059
deadbeefab9b2d12015-10-14 11:33:11 -07001060 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001061 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001062 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001063 ASSERT_TRUE(answer);
1064 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1066 }
1067
deadbeefab9b2d12015-10-14 11:33:11 -07001068 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001069 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001070 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001071 ASSERT_TRUE(pr_answer);
1072 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001074 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001075 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001076 ASSERT_TRUE(answer);
1077 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1079 }
1080
Seth Hampson845e8782018-03-02 11:34:10 -08001081 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001082 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001083 // called with the given stream id and expected number of tracks.
1084 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001085 int expected_num_tracks) {
1086 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001087 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001088 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001089 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 }
1091
1092 // Creates an offer and applies it as a local session description.
1093 // Creates an answer with the same SDP an the offer but removes all lines
1094 // that start with a:ssrc"
1095 void CreateOfferReceiveAnswerWithoutSsrc() {
1096 CreateOfferAsLocalDescription();
1097 std::string sdp;
1098 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1099 SetSsrcToZero(&sdp);
1100 CreateAnswerAsRemoteDescription(sdp);
1101 }
1102
deadbeefab9b2d12015-10-14 11:33:11 -07001103 // This function creates a MediaStream with label kStreams[0] and
1104 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1105 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001106 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001107 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001108 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001109 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1110 size_t number_of_video_tracks) {
1111 EXPECT_LE(number_of_audio_tracks, 2u);
1112 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001113
1114 reference_collection_ = StreamCollection::Create();
1115 std::string sdp_ms1 = std::string(kSdpStringInit);
1116
Seth Hampson845e8782018-03-02 11:34:10 -08001117 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001118
1119 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001120 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001121 reference_collection_->AddStream(stream);
1122
1123 if (number_of_audio_tracks > 0) {
1124 sdp_ms1 += std::string(kSdpStringAudio);
1125 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1126 AddAudioTrack(kAudioTracks[0], stream);
1127 }
1128 if (number_of_audio_tracks > 1) {
1129 sdp_ms1 += kSdpStringMs1Audio1;
1130 AddAudioTrack(kAudioTracks[1], stream);
1131 }
1132
1133 if (number_of_video_tracks > 0) {
1134 sdp_ms1 += std::string(kSdpStringVideo);
1135 sdp_ms1 += std::string(kSdpStringMs1Video0);
1136 AddVideoTrack(kVideoTracks[0], stream);
1137 }
1138 if (number_of_video_tracks > 1) {
1139 sdp_ms1 += kSdpStringMs1Video1;
1140 AddVideoTrack(kVideoTracks[1], stream);
1141 }
1142
kwibergd1fe2812016-04-27 06:47:29 -07001143 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001144 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001145 }
1146
1147 void AddAudioTrack(const std::string& track_id,
1148 MediaStreamInterface* stream) {
1149 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1150 webrtc::AudioTrack::Create(track_id, nullptr));
1151 ASSERT_TRUE(stream->AddTrack(audio_track));
1152 }
1153
1154 void AddVideoTrack(const std::string& track_id,
1155 MediaStreamInterface* stream) {
1156 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001157 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001158 webrtc::FakeVideoTrackSource::Create(),
1159 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001160 ASSERT_TRUE(stream->AddTrack(video_track));
1161 }
1162
Steve Anton36da6ff2018-02-16 16:04:20 -08001163 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001164 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001165 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001166 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001167 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1168 return offer;
1169 }
1170
Steve Anton36da6ff2018-02-16 16:04:20 -08001171 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1172 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001173 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001174 std::unique_ptr<SessionDescriptionInterface> offer;
1175 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1176 return offer;
1177 }
1178
1179 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1180 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1181 std::unique_ptr<SessionDescriptionInterface> answer;
1182 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1183 return answer;
1184 }
1185
kwibergfd8be342016-05-14 19:44:11 -07001186 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001187 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001188 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001189 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001190 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1191 return answer;
1192 }
1193
1194 const std::string& GetFirstAudioStreamCname(
1195 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001196 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001197 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001198 return audio_desc->streams()[0].cname;
1199 }
1200
zhihuang1c378ed2017-08-17 14:10:50 -07001201 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1202 const RTCOfferAnswerOptions& offer_answer_options) {
1203 RTC_DCHECK(pc_);
1204 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1205 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1206 pc_->CreateOffer(observer, offer_answer_options);
1207 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1208 return observer->MoveDescription();
1209 }
1210
1211 void CreateOfferWithOptionsAsRemoteDescription(
1212 std::unique_ptr<SessionDescriptionInterface>* desc,
1213 const RTCOfferAnswerOptions& offer_answer_options) {
1214 *desc = CreateOfferWithOptions(offer_answer_options);
1215 ASSERT_TRUE(desc != nullptr);
1216 std::string sdp;
1217 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001218 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001219 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001220 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001221 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1222 }
1223
1224 void CreateOfferWithOptionsAsLocalDescription(
1225 std::unique_ptr<SessionDescriptionInterface>* desc,
1226 const RTCOfferAnswerOptions& offer_answer_options) {
1227 *desc = CreateOfferWithOptions(offer_answer_options);
1228 ASSERT_TRUE(desc != nullptr);
1229 std::string sdp;
1230 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001231 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001232 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001233
Steve Antondb45ca82017-09-11 18:27:34 -07001234 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001235 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1236 }
1237
1238 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001239 RTC_DCHECK(content);
1240 RTC_DCHECK(content->media_description());
1241 for (const cricket::AudioCodec& codec :
1242 content->media_description()->as_audio()->codecs()) {
1243 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001244 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001245 }
zhihuang1c378ed2017-08-17 14:10:50 -07001246 }
1247 return false;
1248 }
1249
Steve Anton36da6ff2018-02-16 16:04:20 -08001250 const char* GetSdpStringWithStream1() const {
1251 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1252 return kSdpStringWithStream1PlanB;
1253 } else {
1254 return kSdpStringWithStream1UnifiedPlan;
1255 }
1256 }
1257
1258 const char* GetSdpStringWithStream1And2() const {
1259 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1260 return kSdpStringWithStream1And2PlanB;
1261 } else {
1262 return kSdpStringWithStream1And2UnifiedPlan;
1263 }
1264 }
1265
deadbeef9a6f4d42017-05-15 19:43:33 -07001266 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1267 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001268 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001269 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001270 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001271 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1272 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1273 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001275 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001276 const SdpSemantics sdp_semantics_;
1277};
1278
1279class PeerConnectionInterfaceTest
1280 : public PeerConnectionInterfaceBaseTest,
1281 public ::testing::WithParamInterface<SdpSemantics> {
1282 protected:
1283 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1284};
1285
1286class PeerConnectionInterfaceTestPlanB
1287 : public PeerConnectionInterfaceBaseTest {
1288 protected:
1289 PeerConnectionInterfaceTestPlanB()
1290 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291};
1292
zhihuang8f65cdf2016-05-06 18:40:30 -07001293// Generate different CNAMEs when PeerConnections are created.
1294// The CNAMEs are expected to be generated randomly. It is possible
1295// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001296TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001297 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001298 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001299 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001300 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001301 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1302 GetFirstAudioStreamCname(offer2.get()));
1303}
1304
Steve Anton36da6ff2018-02-16 16:04:20 -08001305TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001306 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001307 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001308 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001309 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001310 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1311 GetFirstAudioStreamCname(answer2.get()));
1312}
1313
Steve Anton36da6ff2018-02-16 16:04:20 -08001314TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 CreatePeerConnectionWithDifferentConfigurations) {
1316 CreatePeerConnectionWithDifferentConfigurations();
1317}
1318
Steve Anton36da6ff2018-02-16 16:04:20 -08001319TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001320 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1321 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1322 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1323 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1324 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1325 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1326 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1327 port_allocator_->candidate_filter());
1328 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1329 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1330}
1331
1332// Test that when a PeerConnection is created with a nonzero candidate pool
1333// size, the pooled PortAllocatorSession is created with all the attributes
1334// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001335TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001336 PeerConnectionInterface::RTCConfiguration config;
1337 PeerConnectionInterface::IceServer server;
1338 server.uri = kStunAddressOnly;
1339 config.servers.push_back(server);
1340 config.type = PeerConnectionInterface::kRelay;
1341 config.disable_ipv6 = true;
1342 config.tcp_candidate_policy =
1343 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001344 config.candidate_network_policy =
1345 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001346 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001347 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001348
1349 const cricket::FakePortAllocatorSession* session =
1350 static_cast<const cricket::FakePortAllocatorSession*>(
1351 port_allocator_->GetPooledSession());
1352 ASSERT_NE(nullptr, session);
1353 EXPECT_EQ(1UL, session->stun_servers().size());
1354 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1355 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001356 EXPECT_LT(0U,
1357 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001358}
1359
deadbeefd21eab32017-07-26 16:50:11 -07001360// Test that network-related RTCConfiguration members are applied to the
1361// PortAllocator when CreatePeerConnection is called. Specifically:
1362// - disable_ipv6_on_wifi
1363// - max_ipv6_networks
1364// - tcp_candidate_policy
1365// - candidate_network_policy
1366// - prune_turn_ports
1367//
1368// Note that the candidate filter (RTCConfiguration::type) is already tested
1369// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001370TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001371 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1372 // Create fake port allocator.
1373 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1374 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1375 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1376
1377 // Create RTCConfiguration with some network-related fields relevant to
1378 // PortAllocator populated.
1379 PeerConnectionInterface::RTCConfiguration config;
1380 config.disable_ipv6_on_wifi = true;
1381 config.max_ipv6_networks = 10;
1382 config.tcp_candidate_policy =
1383 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1384 config.candidate_network_policy =
1385 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1386 config.prune_turn_ports = true;
1387
1388 // Create the PC factory and PC with the above config.
1389 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1390 webrtc::CreatePeerConnectionFactory(
1391 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001392 rtc::Thread::Current(), fake_audio_capture_module_,
1393 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001394 webrtc::CreateBuiltinAudioDecoderFactory(),
1395 webrtc::CreateBuiltinVideoEncoderFactory(),
1396 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1397 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001398 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001399 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1400 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001401 EXPECT_TRUE(pc.get());
1402 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001403
1404 // Now validate that the config fields set above were applied to the
1405 // PortAllocator, as flags or otherwise.
1406 EXPECT_FALSE(raw_port_allocator->flags() &
1407 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1408 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1409 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1410 EXPECT_TRUE(raw_port_allocator->flags() &
1411 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1412 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1413}
1414
deadbeef46c73892016-11-16 19:42:04 -08001415// Check that GetConfiguration returns the configuration the PeerConnection was
1416// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001417TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001418 PeerConnectionInterface::RTCConfiguration config;
1419 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001420 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001421
1422 PeerConnectionInterface::RTCConfiguration returned_config =
1423 pc_->GetConfiguration();
1424 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1425}
1426
1427// Check that GetConfiguration returns the last configuration passed into
1428// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001429TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001430 PeerConnectionInterface::RTCConfiguration starting_config;
1431 starting_config.bundle_policy =
1432 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1433 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001434
Steve Anton36da6ff2018-02-16 16:04:20 -08001435 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001436 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001437 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001438 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001439 EXPECT_TRUE(pc_->SetConfiguration(config));
1440
1441 PeerConnectionInterface::RTCConfiguration returned_config =
1442 pc_->GetConfiguration();
1443 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001444 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001445 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001446}
1447
Steve Antonc79268f2018-04-24 09:54:10 -07001448TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1449 CreatePeerConnection();
1450
1451 pc_->Close();
1452
1453 EXPECT_FALSE(
1454 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1455}
1456
Steve Anton36da6ff2018-02-16 16:04:20 -08001457TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001458 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001459 AddVideoStream(kStreamId1);
1460 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 ASSERT_EQ(2u, pc_->local_streams()->count());
1462
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001463 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001464 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001465 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001466 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001467 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001468 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001470 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001471 EXPECT_EQ(3u, pc_->local_streams()->count());
1472
1473 // Remove the third stream.
1474 pc_->RemoveStream(pc_->local_streams()->at(2));
1475 EXPECT_EQ(2u, pc_->local_streams()->count());
1476
1477 // Remove the second stream.
1478 pc_->RemoveStream(pc_->local_streams()->at(1));
1479 EXPECT_EQ(1u, pc_->local_streams()->count());
1480
1481 // Remove the first stream.
1482 pc_->RemoveStream(pc_->local_streams()->at(0));
1483 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484}
1485
deadbeefab9b2d12015-10-14 11:33:11 -07001486// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001487// Don't run under Unified Plan since the stream API is not available.
1488TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001489 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001490 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001491 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001492 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001493
deadbeefab9b2d12015-10-14 11:33:11 -07001494 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001495 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001496 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001497
deadbeefab9b2d12015-10-14 11:33:11 -07001498 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001499 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001500 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001501
1502 // Add another stream and ensure the offer includes both the old and new
1503 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001504 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001505 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001506
Steve Antonb1c1de12017-12-21 15:14:30 -08001507 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001508 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1509 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001510
Steve Antonb1c1de12017-12-21 15:14:30 -08001511 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001512 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1513 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001514}
1515
Steve Anton36da6ff2018-02-16 16:04:20 -08001516// Don't run under Unified Plan since the stream API is not available.
1517TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001518 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001519 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 ASSERT_EQ(1u, pc_->local_streams()->count());
1521 pc_->RemoveStream(pc_->local_streams()->at(0));
1522 EXPECT_EQ(0u, pc_->local_streams()->count());
1523}
1524
deadbeefe1f9d832016-01-14 15:35:42 -08001525// Test for AddTrack and RemoveTrack methods.
1526// Tests that the created offer includes tracks we added,
1527// and that the RtpSenders are created correctly.
1528// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001529// Only tested with Plan B since Unified Plan is covered in more detail by tests
1530// in peerconnection_jsep_unittests.cc
1531TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001532 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001533 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001534 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001535 rtc::scoped_refptr<VideoTrackInterface> video_track(
1536 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001537 "video_track", pc_factory_->CreateVideoSource(
1538 std::unique_ptr<cricket::VideoCapturer>(
1539 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001540 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1541 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001542 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001543 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001544 EXPECT_EQ("audio_track", audio_sender->id());
1545 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001546 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001547 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001548 EXPECT_EQ("video_track", video_sender->id());
1549 EXPECT_EQ(video_track, video_sender->track());
1550
1551 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001552 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001553 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001554
1555 const cricket::ContentInfo* audio_content =
1556 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001557 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001558 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 const cricket::ContentInfo* video_content =
1561 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
Steve Antondb45ca82017-09-11 18:27:34 -07001565 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001566
1567 // Now try removing the tracks.
1568 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1569 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1570
1571 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001572 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001573
1574 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001575 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001576 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001577
1578 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001579 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001580 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001581
Steve Antondb45ca82017-09-11 18:27:34 -07001582 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001583
1584 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1585 // should return false.
1586 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1587 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1588}
1589
1590// Test creating senders without a stream specified,
1591// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001592TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001593 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001594 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001595 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001596 rtc::scoped_refptr<VideoTrackInterface> video_track(
1597 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001598 "video_track", pc_factory_->CreateVideoSource(
1599 std::unique_ptr<cricket::VideoCapturer>(
1600 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001601 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001602 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001603 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001604 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001605 EXPECT_EQ("audio_track", audio_sender->id());
1606 EXPECT_EQ(audio_track, audio_sender->track());
1607 EXPECT_EQ("video_track", video_sender->id());
1608 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001609 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1610 // If the ID is truly a random GUID, it should be infinitely unlikely they
1611 // will be the same.
1612 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1613 } else {
1614 // We allows creating tracks without stream ids under Unified Plan
1615 // semantics.
1616 EXPECT_EQ(0u, video_sender->stream_ids().size());
1617 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1618 }
deadbeefe1f9d832016-01-14 15:35:42 -08001619}
1620
Harald Alvestrand89061872018-01-02 14:08:34 +01001621// Test that we can call GetStats() after AddTrack but before connecting
1622// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001623TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001624 CreatePeerConnectionWithoutDtls();
1625 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1626 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1627 rtc::scoped_refptr<VideoTrackInterface> video_track(
1628 pc_factory_->CreateVideoTrack(
1629 "video_track", pc_factory_->CreateVideoSource(
1630 std::unique_ptr<cricket::VideoCapturer>(
1631 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001632 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1633 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001634 EXPECT_TRUE(DoGetStats(nullptr));
1635}
1636
Steve Anton36da6ff2018-02-16 16:04:20 -08001637TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001638 CreatePeerConnectionWithoutDtls();
1639 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1640 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1641 rtc::scoped_refptr<VideoTrackInterface> video_track(
1642 pc_factory_->CreateVideoTrack(
1643 "video_track", pc_factory_->CreateVideoSource(
1644 std::unique_ptr<cricket::VideoCapturer>(
1645 new cricket::FakeVideoCapturer()))));
1646 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001647 ASSERT_TRUE(audio_sender.ok());
1648 auto* audio_sender_proxy =
1649 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1650 audio_sender.value().get());
1651 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1652
Harald Alvestrandc72af932018-01-11 17:18:19 +01001653 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001654 ASSERT_TRUE(video_sender.ok());
1655 auto* video_sender_proxy =
1656 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1657 video_sender.value().get());
1658 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001659}
1660
Steve Anton36da6ff2018-02-16 16:04:20 -08001661// Don't run under Unified Plan since the stream API is not available.
1662TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001663 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001664 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001665 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001666 ASSERT_EQ(1u, senders.size());
1667 auto* sender_proxy =
1668 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1669 senders[0].get());
1670 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001671}
1672
Steve Anton36da6ff2018-02-16 16:04:20 -08001673TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001675 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 VerifyRemoteRtpHeaderExtensions();
1677}
1678
Steve Anton36da6ff2018-02-16 16:04:20 -08001679TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001680 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001681 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 CreateOfferAsLocalDescription();
1683 std::string offer;
1684 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1685 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001686 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687}
1688
Steve Anton36da6ff2018-02-16 16:04:20 -08001689TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001690 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001691 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692
1693 CreateOfferAsRemoteDescription();
1694 CreateAnswerAsLocalDescription();
1695
Seth Hampson845e8782018-03-02 11:34:10 -08001696 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697}
1698
Steve Anton36da6ff2018-02-16 16:04:20 -08001699TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001700 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001701 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702
1703 CreateOfferAsRemoteDescription();
1704 CreatePrAnswerAsLocalDescription();
1705 CreateAnswerAsLocalDescription();
1706
Seth Hampson845e8782018-03-02 11:34:10 -08001707 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708}
1709
Steve Anton36da6ff2018-02-16 16:04:20 -08001710// Don't run under Unified Plan since the stream API is not available.
1711TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 InitiateCall();
1713 ASSERT_EQ(1u, pc_->remote_streams()->count());
1714 pc_->RemoveStream(pc_->local_streams()->at(0));
1715 CreateOfferReceiveAnswer();
1716 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001717 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 CreateOfferReceiveAnswer();
1719}
1720
1721// Tests that after negotiating an audio only call, the respondent can perform a
1722// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001723TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001724 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001725 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 CreateOfferAsRemoteDescription();
1727 CreateAnswerAsLocalDescription();
1728
1729 ASSERT_EQ(1u, pc_->remote_streams()->count());
1730 pc_->RemoveStream(pc_->local_streams()->at(0));
1731 CreateOfferReceiveAnswer();
1732 EXPECT_EQ(0u, pc_->remote_streams()->count());
1733}
1734
1735// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001736TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001737 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738
Steve Antonf1c6db12017-10-13 11:13:35 -07001739 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001741 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001742 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001743 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001744 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745
1746 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001747 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001748 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001749 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
Steve Antonf1c6db12017-10-13 11:13:35 -07001751 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001752 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753
Steve Antonf1c6db12017-10-13 11:13:35 -07001754 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755}
1756
deadbeefab9b2d12015-10-14 11:33:11 -07001757// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001759TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001760 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001762 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001763 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001764 EXPECT_TRUE(offer);
1765 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766
1767 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001768 AddAudioTrack("track_label", {kStreamId1});
1769 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770
1771 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001772 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773
1774 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001775 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001776 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777}
1778
1779// Test that we will get different SSRCs for each tracks in the offer and answer
1780// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001781TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001782 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001784 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1785 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786
1787 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001788 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001789 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 int audio_ssrc = 0;
1791 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001792 EXPECT_TRUE(
1793 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1794 EXPECT_TRUE(
1795 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 EXPECT_NE(audio_ssrc, video_ssrc);
1797
1798 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001799 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001800 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001801 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 audio_ssrc = 0;
1803 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001804 EXPECT_TRUE(
1805 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1806 EXPECT_TRUE(
1807 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 EXPECT_NE(audio_ssrc, video_ssrc);
1809}
1810
deadbeefeb459812015-12-15 19:24:43 -08001811// Test that it's possible to call AddTrack on a MediaStream after adding
1812// the stream to a PeerConnection.
1813// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001814// Don't run under Unified Plan since the stream API is not available.
1815TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001816 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001817 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001818 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001819 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1820
1821 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001822 rtc::scoped_refptr<VideoTrackInterface> video_track(
1823 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001824 "video_label", pc_factory_->CreateVideoSource(
1825 std::unique_ptr<cricket::VideoCapturer>(
1826 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001827 stream->AddTrack(video_track.get());
1828
kwibergd1fe2812016-04-27 06:47:29 -07001829 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001830 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001831
1832 const cricket::MediaContentDescription* video_desc =
1833 cricket::GetFirstVideoContentDescription(offer->description());
1834 EXPECT_TRUE(video_desc != nullptr);
1835}
1836
1837// Test that it's possible to call RemoveTrack on a MediaStream after adding
1838// the stream to a PeerConnection.
1839// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001840// Don't run under Unified Plan since the stream API is not available.
1841TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001842 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001843 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001844 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001845 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1846
1847 // Remove the video track.
1848 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1849
kwibergd1fe2812016-04-27 06:47:29 -07001850 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001851 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001852
1853 const cricket::MediaContentDescription* video_desc =
1854 cricket::GetFirstVideoContentDescription(offer->description());
1855 EXPECT_TRUE(video_desc == nullptr);
1856}
1857
deadbeefbd7d8f72015-12-18 16:58:44 -08001858// Test creating a sender with a stream ID, and ensure the ID is populated
1859// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001860// Don't run under Unified Plan since the stream API is not available.
1861TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001862 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001863 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001864
kwibergd1fe2812016-04-27 06:47:29 -07001865 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001866 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001867
1868 const cricket::MediaContentDescription* video_desc =
1869 cricket::GetFirstVideoContentDescription(offer->description());
1870 ASSERT_TRUE(video_desc != nullptr);
1871 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001872 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001873}
1874
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001876TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001878 ASSERT_LT(0u, pc_->GetSenders().size());
1879 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001880 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001881 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 EXPECT_TRUE(DoGetStats(remote_audio));
1883
1884 // Remove the stream. Since we are sending to our selves the local
1885 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001886 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 // Do a re-negotiation.
1888 CreateOfferReceiveAnswer();
1889
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 // Test that we still can get statistics for the old track. Even if it is not
1891 // sent any longer.
1892 EXPECT_TRUE(DoGetStats(remote_audio));
1893}
1894
1895// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001896TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001898 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1899 ASSERT_TRUE(video_receiver);
1900 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901}
1902
1903// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001904TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001906 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 pc_factory_->CreateAudioTrack("unknown track", NULL));
1908 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1909}
1910
Steve Anton36da6ff2018-02-16 16:04:20 -08001911TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001912 CreatePeerConnectionWithoutDtls();
1913 EXPECT_TRUE(DoGetRTCStats());
1914 // Clearing stats cache is needed now, but should be temporary.
1915 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1916 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001917 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1918 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001919 EXPECT_TRUE(DoGetRTCStats());
1920 pc_->ClearStatsCache();
1921 CreateOfferReceiveAnswer();
1922 EXPECT_TRUE(DoGetRTCStats());
1923}
1924
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001926TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001927 RTCConfiguration config;
1928 config.enable_rtp_data_channel = true;
1929 config.enable_dtls_srtp = false;
1930 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001931 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001933 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 pc_->CreateDataChannel("test2", NULL);
1935 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001936 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001938 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939 new MockDataChannelObserver(data2));
1940
1941 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1942 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1943 std::string data_to_send1 = "testing testing";
1944 std::string data_to_send2 = "testing something else";
1945 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1946
1947 CreateOfferReceiveAnswer();
1948 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1949 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1950
1951 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1952 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1953 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1954 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1955
1956 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1957 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1958
1959 data1->Close();
1960 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1961 CreateOfferReceiveAnswer();
1962 EXPECT_FALSE(observer1->IsOpen());
1963 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1964 EXPECT_TRUE(observer2->IsOpen());
1965
1966 data_to_send2 = "testing something else again";
1967 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1968
1969 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1970}
1971
1972// This test verifies that sendnig binary data over RTP data channels should
1973// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001974TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001975 RTCConfiguration config;
1976 config.enable_rtp_data_channel = true;
1977 config.enable_dtls_srtp = false;
1978 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001979 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001981 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 pc_->CreateDataChannel("test2", NULL);
1983 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001984 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001986 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 new MockDataChannelObserver(data2));
1988
1989 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1990 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1991
1992 CreateOfferReceiveAnswer();
1993 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1994 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1995
1996 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1997 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1998
jbaucheec21bd2016-03-20 06:15:43 -07001999 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2001}
2002
2003// This test setup a RTP data channels in loop back and test that a channel is
2004// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002005TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002006 RTCConfiguration config;
2007 config.enable_rtp_data_channel = true;
2008 config.enable_dtls_srtp = false;
2009 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002010 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002012 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 new MockDataChannelObserver(data1));
2014
2015 CreateOfferReceiveAnswerWithoutSsrc();
2016
2017 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2018
2019 data1->Close();
2020 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2021 CreateOfferReceiveAnswerWithoutSsrc();
2022 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2023 EXPECT_FALSE(observer1->IsOpen());
2024}
2025
2026// This test that if a data channel is added in an answer a receive only channel
2027// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002028TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002029 RTCConfiguration config;
2030 config.enable_rtp_data_channel = true;
2031 config.enable_dtls_srtp = false;
2032
2033 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034
2035 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002036 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 pc_->CreateDataChannel(offer_label, NULL);
2038
2039 CreateOfferAsLocalDescription();
2040
2041 // Replace the data channel label in the offer and apply it as an answer.
2042 std::string receive_label = "answer_channel";
2043 std::string sdp;
2044 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002045 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002046 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 CreateAnswerAsRemoteDescription(sdp);
2048
2049 // Verify that a new incoming data channel has been created and that
2050 // it is open but can't we written to.
2051 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2052 DataChannelInterface* received_channel = observer_.last_datachannel_;
2053 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2054 EXPECT_EQ(receive_label, received_channel->label());
2055 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2056
2057 // Verify that the channel we initially offered has been rejected.
2058 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2059
2060 // Do another offer / answer exchange and verify that the data channel is
2061 // opened.
2062 CreateOfferReceiveAnswer();
2063 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2064 kTimeout);
2065}
2066
2067// This test that no data channel is returned if a reliable channel is
2068// requested.
2069// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002070TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002071 RTCConfiguration rtc_config;
2072 rtc_config.enable_rtp_data_channel = true;
2073 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
2075 std::string label = "test";
2076 webrtc::DataChannelInit config;
2077 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002078 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 pc_->CreateDataChannel(label, &config);
2080 EXPECT_TRUE(channel == NULL);
2081}
2082
deadbeefab9b2d12015-10-14 11:33:11 -07002083// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002084TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002085 RTCConfiguration config;
2086 config.enable_rtp_data_channel = true;
2087 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002088
2089 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002090 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002091 pc_->CreateDataChannel(label, nullptr);
2092 EXPECT_NE(channel, nullptr);
2093
zhihuang9763d562016-08-05 11:14:50 -07002094 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002095 pc_->CreateDataChannel(label, nullptr);
2096 EXPECT_EQ(dup_channel, nullptr);
2097}
2098
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099// This tests that a SCTP data channel is returned using different
2100// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002101TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002102 RTCConfiguration rtc_config;
2103 rtc_config.enable_dtls_srtp = true;
2104 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105
2106 webrtc::DataChannelInit config;
2107
zhihuang9763d562016-08-05 11:14:50 -07002108 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 pc_->CreateDataChannel("1", &config);
2110 EXPECT_TRUE(channel != NULL);
2111 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002112 EXPECT_TRUE(observer_.renegotiation_needed_);
2113 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 config.ordered = false;
2116 channel = pc_->CreateDataChannel("2", &config);
2117 EXPECT_TRUE(channel != NULL);
2118 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002119 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 config.ordered = true;
2122 config.maxRetransmits = 0;
2123 channel = pc_->CreateDataChannel("3", &config);
2124 EXPECT_TRUE(channel != NULL);
2125 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002126 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127
2128 config.maxRetransmits = -1;
2129 config.maxRetransmitTime = 0;
2130 channel = pc_->CreateDataChannel("4", &config);
2131 EXPECT_TRUE(channel != NULL);
2132 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002133 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134}
2135
2136// This tests that no data channel is returned if both maxRetransmits and
2137// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002138TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002140 RTCConfiguration rtc_config;
2141 rtc_config.enable_dtls_srtp = true;
2142 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143
2144 std::string label = "test";
2145 webrtc::DataChannelInit config;
2146 config.maxRetransmits = 0;
2147 config.maxRetransmitTime = 0;
2148
zhihuang9763d562016-08-05 11:14:50 -07002149 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 pc_->CreateDataChannel(label, &config);
2151 EXPECT_TRUE(channel == NULL);
2152}
2153
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154// The test verifies that creating a SCTP data channel with an id already in use
2155// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002156TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002158 RTCConfiguration rtc_config;
2159 rtc_config.enable_dtls_srtp = true;
2160 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161
2162 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002163 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002165 config.id = 1;
2166 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 EXPECT_TRUE(channel != NULL);
2168 EXPECT_EQ(1, channel->id());
2169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 channel = pc_->CreateDataChannel("x", &config);
2171 EXPECT_TRUE(channel == NULL);
2172
2173 config.id = cricket::kMaxSctpSid;
2174 channel = pc_->CreateDataChannel("max", &config);
2175 EXPECT_TRUE(channel != NULL);
2176 EXPECT_EQ(config.id, channel->id());
2177
2178 config.id = cricket::kMaxSctpSid + 1;
2179 channel = pc_->CreateDataChannel("x", &config);
2180 EXPECT_TRUE(channel == NULL);
2181}
2182
deadbeefab9b2d12015-10-14 11:33:11 -07002183// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002184TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002185 RTCConfiguration rtc_config;
2186 rtc_config.enable_dtls_srtp = true;
2187 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002188
2189 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002190 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002191 pc_->CreateDataChannel(label, nullptr);
2192 EXPECT_NE(channel, nullptr);
2193
zhihuang9763d562016-08-05 11:14:50 -07002194 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002195 pc_->CreateDataChannel(label, nullptr);
2196 EXPECT_NE(dup_channel, nullptr);
2197}
2198
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002199// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2200// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002201TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002202 RTCConfiguration rtc_config;
2203 rtc_config.enable_rtp_data_channel = true;
2204 rtc_config.enable_dtls_srtp = false;
2205 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002206
zhihuang9763d562016-08-05 11:14:50 -07002207 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002208 pc_->CreateDataChannel("test1", NULL);
2209 EXPECT_TRUE(observer_.renegotiation_needed_);
2210 observer_.renegotiation_needed_ = false;
2211
zhihuang9763d562016-08-05 11:14:50 -07002212 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002213 pc_->CreateDataChannel("test2", NULL);
2214 EXPECT_TRUE(observer_.renegotiation_needed_);
2215}
2216
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002218TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002219 RTCConfiguration rtc_config;
2220 rtc_config.enable_rtp_data_channel = true;
2221 rtc_config.enable_dtls_srtp = false;
2222 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223
zhihuang9763d562016-08-05 11:14:50 -07002224 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002226 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 pc_->CreateDataChannel("test2", NULL);
2228 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002229 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002231 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 new MockDataChannelObserver(data2));
2233
2234 CreateOfferReceiveAnswer();
2235 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2236 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2237
2238 ReleasePeerConnection();
2239 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2240 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2241}
2242
Zhi Huang644fde42018-04-02 19:16:26 -07002243// This tests that RTP data channels can be rejected in an answer.
2244TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002245 RTCConfiguration rtc_config;
2246 rtc_config.enable_rtp_data_channel = true;
2247 rtc_config.enable_dtls_srtp = false;
2248 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249
zhihuang9763d562016-08-05 11:14:50 -07002250 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 pc_->CreateDataChannel("offer_channel", NULL));
2252
2253 CreateOfferAsLocalDescription();
2254
2255 // Create an answer where the m-line for data channels are rejected.
2256 std::string sdp;
2257 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002258 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002259 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002260 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002262 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 data_info->rejected = true;
2264
Steve Antondb45ca82017-09-11 18:27:34 -07002265 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2267}
2268
Zhi Huang644fde42018-04-02 19:16:26 -07002269#ifdef HAVE_SCTP
2270// This tests that SCTP data channels can be rejected in an answer.
2271TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2272#else
2273TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2274#endif
2275{
Niels Möllerf06f9232018-08-07 12:32:18 +02002276 RTCConfiguration rtc_config;
2277 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002278
2279 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2280 pc_->CreateDataChannel("offer_channel", NULL));
2281
2282 CreateOfferAsLocalDescription();
2283
2284 // Create an answer where the m-line for data channels are rejected.
2285 std::string sdp;
2286 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2287 std::unique_ptr<SessionDescriptionInterface> answer(
2288 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2289 ASSERT_TRUE(answer);
2290 cricket::ContentInfo* data_info =
2291 cricket::GetFirstDataContent(answer->description());
2292 data_info->rejected = true;
2293
2294 DoSetRemoteDescription(std::move(answer));
2295 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2296}
2297
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298// Test that we can create a session description from an SDP string from
2299// FireFox, use it as a remote session description, generate an answer and use
2300// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002301TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002302 RTCConfiguration rtc_config;
2303 rtc_config.enable_dtls_srtp = true;
2304 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002305 AddAudioTrack("audio_label");
2306 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002307 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002308 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002309 webrtc::kFireFoxSdpOffer, nullptr));
2310 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 CreateAnswerAsLocalDescription();
2312 ASSERT_TRUE(pc_->local_description() != NULL);
2313 ASSERT_TRUE(pc_->remote_description() != NULL);
2314
2315 const cricket::ContentInfo* content =
2316 cricket::GetFirstAudioContent(pc_->local_description()->description());
2317 ASSERT_TRUE(content != NULL);
2318 EXPECT_FALSE(content->rejected);
2319
2320 content =
2321 cricket::GetFirstVideoContent(pc_->local_description()->description());
2322 ASSERT_TRUE(content != NULL);
2323 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002324#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 content =
2326 cricket::GetFirstDataContent(pc_->local_description()->description());
2327 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002328 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002329#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330}
2331
zhihuangb19012e2017-09-19 13:47:59 -07002332// Test that fallback from DTLS to SDES is not supported.
2333// The fallback was previously supported but was removed to simplify the code
2334// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002335TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002336 RTCConfiguration rtc_config;
2337 rtc_config.enable_dtls_srtp = true;
2338 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002339 // Wait for fake certificate to be generated. Previously, this is what caused
2340 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002341 AddAudioTrack("audio_label");
2342 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002343 ASSERT_NE(nullptr, fake_certificate_generator_);
2344 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2345 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002346 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002347 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2348 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002349 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002350}
2351
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352// Test that we can create an audio only offer and receive an answer with a
2353// limited set of audio codecs and receive an updated offer with more audio
2354// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002355TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002356 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002357 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 CreateOfferAsLocalDescription();
2359
Steve Anton36da6ff2018-02-16 16:04:20 -08002360 const char* answer_sdp =
2361 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2362 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002363 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002364 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002365 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366
Steve Anton36da6ff2018-02-16 16:04:20 -08002367 const char* reoffer_sdp =
2368 (sdp_semantics_ == SdpSemantics::kPlanB
2369 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2370 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002371 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002372 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002373 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 CreateAnswerAsLocalDescription();
2375}
2376
deadbeefc80741f2015-10-22 13:14:45 -07002377// Test that if we're receiving (but not sending) a track, subsequent offers
2378// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002379TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002380 RTCConfiguration rtc_config;
2381 rtc_config.enable_dtls_srtp = true;
2382 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002383 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002384 CreateAnswerAsLocalDescription();
2385
2386 // At this point we should be receiving stream 1, but not sending anything.
2387 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002388 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002389 DoCreateOffer(&offer, nullptr);
2390
2391 const cricket::ContentInfo* video_content =
2392 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002393 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2394 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002395
2396 const cricket::ContentInfo* audio_content =
2397 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002398 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2399 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002400}
2401
2402// Test that if we're receiving (but not sending) a track, and the
2403// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2404// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002405TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002406 RTCConfiguration rtc_config;
2407 rtc_config.enable_dtls_srtp = true;
2408 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002409 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002410 CreateAnswerAsLocalDescription();
2411
2412 // At this point we should be receiving stream 1, but not sending anything.
2413 // A new offer would be recvonly, but we'll set the "no receive" constraints
2414 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002415 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002416 RTCOfferAnswerOptions options;
2417 options.offer_to_receive_audio = 0;
2418 options.offer_to_receive_video = 0;
2419 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002420
2421 const cricket::ContentInfo* video_content =
2422 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002423 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2424 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002425
2426 const cricket::ContentInfo* audio_content =
2427 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002428 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2429 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002430}
2431
deadbeef653b8e02015-11-11 12:55:10 -08002432// Test that we can use SetConfiguration to change the ICE servers of the
2433// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002434TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002435 CreatePeerConnection();
2436
Steve Anton36da6ff2018-02-16 16:04:20 -08002437 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002438 PeerConnectionInterface::IceServer server;
2439 server.uri = "stun:test_hostname";
2440 config.servers.push_back(server);
2441 EXPECT_TRUE(pc_->SetConfiguration(config));
2442
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002443 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2444 EXPECT_EQ("test_hostname",
2445 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002446}
2447
Steve Anton36da6ff2018-02-16 16:04:20 -08002448TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002449 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002450 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002451 config.type = PeerConnectionInterface::kRelay;
2452 EXPECT_TRUE(pc_->SetConfiguration(config));
2453 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2454}
2455
Steve Anton36da6ff2018-02-16 16:04:20 -08002456TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002457 PeerConnectionInterface::RTCConfiguration config;
2458 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002459 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002460 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002461 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2462
2463 config.prune_turn_ports = true;
2464 EXPECT_TRUE(pc_->SetConfiguration(config));
2465 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2466}
2467
skvladd1f5fda2017-02-03 16:54:05 -08002468// Test that the ice check interval can be changed. This does not verify that
2469// the setting makes it all the way to P2PTransportChannel, as that would
2470// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002471TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002472 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002473 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002474 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002475 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002476 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002477 EXPECT_TRUE(pc_->SetConfiguration(config));
2478 PeerConnectionInterface::RTCConfiguration new_config =
2479 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002480 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002481}
2482
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002483// Test that when SetConfiguration changes both the pool size and other
2484// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002485TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002486 SetConfigurationCreatesPooledSessionCorrectly) {
2487 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002488 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002489 config.ice_candidate_pool_size = 1;
2490 PeerConnectionInterface::IceServer server;
2491 server.uri = kStunAddressOnly;
2492 config.servers.push_back(server);
2493 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002494 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002495
2496 const cricket::FakePortAllocatorSession* session =
2497 static_cast<const cricket::FakePortAllocatorSession*>(
2498 port_allocator_->GetPooledSession());
2499 ASSERT_NE(nullptr, session);
2500 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002501}
2502
deadbeef293e9262017-01-11 12:28:30 -08002503// Test that after SetLocalDescription, changing the pool size is not allowed,
2504// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002505TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002506 CantChangePoolSizeAfterSetLocalDescription) {
2507 CreatePeerConnection();
2508 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002509 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002510 config.ice_candidate_pool_size = 1;
2511 EXPECT_TRUE(pc_->SetConfiguration(config));
2512
2513 // Set remote offer; can still change pool size at this point.
2514 CreateOfferAsRemoteDescription();
2515 config.ice_candidate_pool_size = 2;
2516 EXPECT_TRUE(pc_->SetConfiguration(config));
2517
2518 // Set local answer; now it's too late.
2519 CreateAnswerAsLocalDescription();
2520 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002521 RTCError error;
2522 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2523 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2524}
2525
deadbeef42a42632017-03-10 15:18:00 -08002526// Test that after setting an answer, extra pooled sessions are discarded. The
2527// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002528TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002529 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2530 CreatePeerConnection();
2531
2532 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002533 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002534 config.ice_candidate_pool_size = 4;
2535 EXPECT_TRUE(pc_->SetConfiguration(config));
2536
2537 // Do offer/answer.
2538 CreateOfferAsRemoteDescription();
2539 CreateAnswerAsLocalDescription();
2540
2541 // Expect no pooled sessions to be left.
2542 const cricket::PortAllocatorSession* session =
2543 port_allocator_->GetPooledSession();
2544 EXPECT_EQ(nullptr, session);
2545}
2546
2547// After Close is called, pooled candidates should be discarded so as to not
2548// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002549TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002550 CreatePeerConnection();
2551
Steve Anton36da6ff2018-02-16 16:04:20 -08002552 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002553 config.ice_candidate_pool_size = 3;
2554 EXPECT_TRUE(pc_->SetConfiguration(config));
2555 pc_->Close();
2556
2557 // Expect no pooled sessions to be left.
2558 const cricket::PortAllocatorSession* session =
2559 port_allocator_->GetPooledSession();
2560 EXPECT_EQ(nullptr, session);
2561}
2562
deadbeef293e9262017-01-11 12:28:30 -08002563// Test that SetConfiguration returns an invalid modification error if
2564// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002565TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002566 SetConfigurationReturnsInvalidModificationError) {
2567 PeerConnectionInterface::RTCConfiguration config;
2568 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2569 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2570 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002571 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002572
Steve Anton36da6ff2018-02-16 16:04:20 -08002573 PeerConnectionInterface::RTCConfiguration modified_config =
2574 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002575 modified_config.bundle_policy =
2576 PeerConnectionInterface::kBundlePolicyMaxBundle;
2577 RTCError error;
2578 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2579 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2580
Steve Anton36da6ff2018-02-16 16:04:20 -08002581 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002582 modified_config.rtcp_mux_policy =
2583 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2584 error.set_type(RTCErrorType::NONE);
2585 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2586 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2587
Steve Anton36da6ff2018-02-16 16:04:20 -08002588 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002589 modified_config.continual_gathering_policy =
2590 PeerConnectionInterface::GATHER_CONTINUALLY;
2591 error.set_type(RTCErrorType::NONE);
2592 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2593 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2594}
2595
2596// Test that SetConfiguration returns a range error if the candidate pool size
2597// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002598TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002599 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2600 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002601 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002602 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002603
2604 config.ice_candidate_pool_size = -1;
2605 RTCError error;
2606 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2607 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2608
2609 config.ice_candidate_pool_size = INT_MAX;
2610 error.set_type(RTCErrorType::NONE);
2611 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2612 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2613}
2614
2615// Test that SetConfiguration returns a syntax error if parsing an ICE server
2616// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002617TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002618 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2619 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002620 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002621 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002622
2623 PeerConnectionInterface::IceServer bad_server;
2624 bad_server.uri = "stunn:www.example.com";
2625 config.servers.push_back(bad_server);
2626 RTCError error;
2627 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2628 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2629}
2630
2631// Test that SetConfiguration returns an invalid parameter error if a TURN
2632// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002633TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002634 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2635 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002636 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002637 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002638
2639 PeerConnectionInterface::IceServer bad_server;
2640 bad_server.uri = "turn:www.example.com";
2641 // Missing password.
2642 bad_server.username = "foo";
2643 config.servers.push_back(bad_server);
2644 RTCError error;
2645 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2646 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002647}
2648
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649// Test that PeerConnection::Close changes the states to closed and all remote
2650// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002651TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 // Initialize a PeerConnection and negotiate local and remote session
2653 // description.
2654 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002655
2656 // With Plan B, verify the stream count. The analog with Unified Plan is the
2657 // RtpTransceiver count.
2658 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2659 ASSERT_EQ(1u, pc_->local_streams()->count());
2660 ASSERT_EQ(1u, pc_->remote_streams()->count());
2661 } else {
2662 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2663 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664
2665 pc_->Close();
2666
2667 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2668 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2669 pc_->ice_connection_state());
2670 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2671 pc_->ice_gathering_state());
2672
Steve Anton36da6ff2018-02-16 16:04:20 -08002673 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2674 EXPECT_EQ(1u, pc_->local_streams()->count());
2675 EXPECT_EQ(1u, pc_->remote_streams()->count());
2676 } else {
2677 // Verify that the RtpTransceivers are still present but all stopped.
2678 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2679 for (auto transceiver : pc_->GetTransceivers()) {
2680 EXPECT_TRUE(transceiver->stopped());
2681 }
2682 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683
Steve Anton36da6ff2018-02-16 16:04:20 -08002684 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2685 ASSERT_TRUE(audio_receiver);
2686 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2687 ASSERT_TRUE(video_receiver);
2688
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002689 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002690 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002691 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002692 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002693 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694}
2695
2696// Test that PeerConnection methods fails gracefully after
2697// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002698// Don't run under Unified Plan since the stream API is not available.
2699TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002700 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002701 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 CreateOfferAsRemoteDescription();
2703 CreateAnswerAsLocalDescription();
2704
2705 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002706 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 pc_->local_streams()->at(0);
2708
2709 pc_->Close();
2710
2711 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002712 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2715
2716 EXPECT_TRUE(pc_->local_description() != NULL);
2717 EXPECT_TRUE(pc_->remote_description() != NULL);
2718
kwibergd1fe2812016-04-27 06:47:29 -07002719 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002720 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002721 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002722 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723
2724 std::string sdp;
2725 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002726 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002727 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002728 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729
2730 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002731 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002732 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002733 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734}
2735
2736// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002737TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 InitiateCall();
2739 pc_->Close();
2740 DoGetStats(NULL);
2741}
deadbeefab9b2d12015-10-14 11:33:11 -07002742
2743// NOTE: The series of tests below come from what used to be
2744// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2745// setting a remote or local description has the expected effects.
2746
2747// This test verifies that the remote MediaStreams corresponding to a received
2748// SDP string is created. In this test the two separate MediaStreams are
2749// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002750TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002751 RTCConfiguration config;
2752 config.enable_dtls_srtp = true;
2753 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002754 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002755
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002756 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002757 EXPECT_TRUE(
2758 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2759 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2760 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2761
2762 // Create a session description based on another SDP with another
2763 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002764 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002765
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002766 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002767 EXPECT_TRUE(
2768 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2769}
2770
2771// This test verifies that when remote tracks are added/removed from SDP, the
2772// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002773// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2774// specific behavior.
2775TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002776 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002777 RTCConfiguration config;
2778 config.enable_dtls_srtp = true;
2779 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002780 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002781 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002782 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002783 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2784 reference_collection_));
2785
2786 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002787 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002788 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002789 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002790 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2791 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002792 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002793 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2794 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002795 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002796 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2797 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002798
2799 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002800 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002801 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002802 MockTrackObserver audio_track_observer(audio_track2);
2803 MockTrackObserver video_track_observer(video_track2);
2804
2805 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2806 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002807 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002808 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2809 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002810 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002811 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002812 audio_track2->state(), kTimeout);
2813 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2814 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002815}
2816
2817// This tests that remote tracks are ended if a local session description is set
2818// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002819TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002820 RTCConfiguration config;
2821 config.enable_dtls_srtp = true;
2822 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002823 // First create and set a remote offer, then reject its video content in our
2824 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002825 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2826 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2827 ASSERT_TRUE(audio_receiver);
2828 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2829 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002830
Steve Anton36da6ff2018-02-16 16:04:20 -08002831 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2832 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002833 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002834 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2835 video_receiver->track();
2836 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002837
kwibergd1fe2812016-04-27 06:47:29 -07002838 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002839 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002840 cricket::ContentInfo* video_info =
2841 local_answer->description()->GetContentByName("video");
2842 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002843 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002844 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2845 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002846
2847 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002848 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002849 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002850 video_info = local_offer->description()->GetContentByName("video");
2851 ASSERT_TRUE(video_info != nullptr);
2852 video_info->rejected = true;
2853 cricket::ContentInfo* audio_info =
2854 local_offer->description()->GetContentByName("audio");
2855 ASSERT_TRUE(audio_info != nullptr);
2856 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002857 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002858 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002859 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2860 kTimeout);
2861 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2862 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002863}
2864
2865// This tests that we won't crash if the remote track has been removed outside
2866// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002867// Don't run under Unified Plan since the stream API is not available.
2868TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002869 RTCConfiguration config;
2870 config.enable_dtls_srtp = true;
2871 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002872 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002873 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2874 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2875 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2876
kwibergd1fe2812016-04-27 06:47:29 -07002877 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002878 webrtc::CreateSessionDescription(SdpType::kAnswer,
2879 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002880 cricket::ContentInfo* video_info =
2881 local_answer->description()->GetContentByName("video");
2882 video_info->rejected = true;
2883 cricket::ContentInfo* audio_info =
2884 local_answer->description()->GetContentByName("audio");
2885 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002886 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002887
2888 // No crash is a pass.
2889}
2890
deadbeef5e97fb52015-10-15 12:49:08 -07002891// This tests that if a recvonly remote description is set, no remote streams
2892// will be created, even if the description contains SSRCs/MSIDs.
2893// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002894TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002895 RTCConfiguration config;
2896 config.enable_dtls_srtp = true;
2897 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002898
Steve Anton36da6ff2018-02-16 16:04:20 -08002899 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002900 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2901 strlen(kRecvonly), &recvonly_offer);
2902 CreateAndSetRemoteOffer(recvonly_offer);
2903
2904 EXPECT_EQ(0u, observer_.remote_streams()->count());
2905}
2906
deadbeefab9b2d12015-10-14 11:33:11 -07002907// This tests that a default MediaStream is created if a remote session
2908// description doesn't contain any streams and no MSID support.
2909// It also tests that the default stream is updated if a video m-line is added
2910// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002911// Don't run under Unified Plan since this behavior is Plan B specific.
2912TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002913 RTCConfiguration config;
2914 config.enable_dtls_srtp = true;
2915 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002916 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2917
2918 ASSERT_EQ(1u, observer_.remote_streams()->count());
2919 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2920
2921 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2922 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002923 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002924
2925 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2926 ASSERT_EQ(1u, observer_.remote_streams()->count());
2927 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2928 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002929 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2930 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002931 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2932 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002933 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2934 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002935}
2936
2937// This tests that a default MediaStream is created if a remote session
2938// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002939// Don't run under Unified Plan since this behavior is Plan B specific.
2940TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002941 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002942 RTCConfiguration config;
2943 config.enable_dtls_srtp = true;
2944 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002945 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2946
2947 ASSERT_EQ(1u, observer_.remote_streams()->count());
2948 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2949
2950 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2951 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002952 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002953}
2954
2955// This tests that it won't crash when PeerConnection tries to remove
2956// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002957// Don't run under Unified Plan since this behavior is Plan B specific.
2958TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002959 RTCConfiguration config;
2960 config.enable_dtls_srtp = true;
2961 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002962 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002963 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2964 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2965 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2966
2967 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2968
2969 // No crash is a pass.
2970}
2971
2972// This tests that a default MediaStream is created if the remote session
2973// description doesn't contain any streams and don't contain an indication if
2974// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002975// Don't run under Unified Plan since this behavior is Plan B specific.
2976TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002977 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002978 RTCConfiguration config;
2979 config.enable_dtls_srtp = true;
2980 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002981 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2982
2983 ASSERT_EQ(1u, observer_.remote_streams()->count());
2984 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2985 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2986 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2987}
2988
2989// This tests that a default MediaStream is not created if the remote session
2990// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002991// Don't run under Unified Plan since this behavior is Plan B specific.
2992TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002993 RTCConfiguration config;
2994 config.enable_dtls_srtp = true;
2995 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002996 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2997 EXPECT_EQ(0u, observer_.remote_streams()->count());
2998}
2999
deadbeefbda7e0b2015-12-08 17:13:40 -08003000// This tests that when setting a new description, the old default tracks are
3001// not destroyed and recreated.
3002// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003003// Don't run under Unified Plan since this behavior is Plan B specific.
3004TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003005 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003006 RTCConfiguration config;
3007 config.enable_dtls_srtp = true;
3008 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003009 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3010
3011 ASSERT_EQ(1u, observer_.remote_streams()->count());
3012 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3013 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3014
3015 // Set the track to "disabled", then set a new description and ensure the
3016 // track is still disabled, which ensures it hasn't been recreated.
3017 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3018 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3019 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3020 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3021}
3022
deadbeefab9b2d12015-10-14 11:33:11 -07003023// This tests that a default MediaStream is not created if a remote session
3024// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003025// Don't run under Unified Plan since this behavior is Plan B specific.
3026TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003027 RTCConfiguration config;
3028 config.enable_dtls_srtp = true;
3029 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003030 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003031 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003032 EXPECT_TRUE(
3033 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3034
3035 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3036 EXPECT_EQ(0u, observer_.remote_streams()->count());
3037}
3038
Seth Hampson5897a6e2018-04-03 11:16:33 -07003039// This tests that a default MediaStream is created if a remote SDP comes from
3040// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3041TEST_F(PeerConnectionInterfaceTestPlanB,
3042 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003043 RTCConfiguration config;
3044 config.enable_dtls_srtp = true;
3045 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003046 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3047 // Add a=msid lines to simulate a Unified Plan endpoint that only
3048 // signals stream IDs with a=msid lines.
3049 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3050
3051 CreateAndSetRemoteOffer(sdp_string);
3052
3053 ASSERT_EQ(1u, observer_.remote_streams()->count());
3054 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3055 EXPECT_EQ("default", remote_stream->id());
3056 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3057}
3058
Seth Hampson5b4f0752018-04-02 16:31:36 -07003059// This tests that when a Plan B endpoint receives an SDP that signals no media
3060// stream IDs indicated by the special character "-" in the a=msid line, that
3061// a default stream ID will be used for the MediaStream ID. This can occur
3062// when a Unified Plan endpoint signals no media stream IDs, but signals both
3063// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3064TEST_F(PeerConnectionInterfaceTestPlanB,
3065 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003066 RTCConfiguration config;
3067 config.enable_dtls_srtp = true;
3068 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003069 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3070 // the sender's stream ID will be interpreted as no stream IDs.
3071 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3072 sdp_string.append("a=msid:- audiotrack0\n");
3073
3074 CreateAndSetRemoteOffer(sdp_string);
3075
3076 ASSERT_EQ(1u, observer_.remote_streams()->count());
3077 // Because SSRCs are signaled the track ID will be what was signaled in the
3078 // a=msid line.
3079 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3080 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3081 EXPECT_EQ("default", remote_stream->id());
3082 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003083
3084 // Previously a bug ocurred when setting the remote description a second time.
3085 // This is because we checked equality of the remote StreamParams stream ID
3086 // (empty), and the previously set stream ID for the remote sender
3087 // ("default"). This cause a track to be removed, then added, when really
3088 // nothing should occur because it is the same track.
3089 CreateAndSetRemoteOffer(sdp_string);
3090 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3091 EXPECT_EQ(1u, observer_.add_track_events_.size());
3092 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3093 remote_stream = observer_.remote_streams()->at(0);
3094 EXPECT_EQ("default", remote_stream->id());
3095 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003096}
3097
deadbeefab9b2d12015-10-14 11:33:11 -07003098// This tests that an RtpSender is created when the local description is set
3099// after adding a local stream.
3100// TODO(deadbeef): This test and the one below it need to be updated when
3101// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003102// Don't run under Unified Plan since this behavior is Plan B specific.
3103TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003104 RTCConfiguration config;
3105 config.enable_dtls_srtp = true;
3106 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003107
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003108 // Create an offer with 1 stream with 2 tracks of each type.
3109 rtc::scoped_refptr<StreamCollection> stream_collection =
3110 CreateStreamCollection(1, 2);
3111 pc_->AddStream(stream_collection->at(0));
3112 std::unique_ptr<SessionDescriptionInterface> offer;
3113 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003114 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003115
deadbeefab9b2d12015-10-14 11:33:11 -07003116 auto senders = pc_->GetSenders();
3117 EXPECT_EQ(4u, senders.size());
3118 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3119 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3120 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3121 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3122
3123 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003124 pc_->RemoveStream(stream_collection->at(0));
3125 stream_collection = CreateStreamCollection(1, 1);
3126 pc_->AddStream(stream_collection->at(0));
3127 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003128 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003129
deadbeefab9b2d12015-10-14 11:33:11 -07003130 senders = pc_->GetSenders();
3131 EXPECT_EQ(2u, senders.size());
3132 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3133 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3134 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3135 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3136}
3137
3138// This tests that an RtpSender is created when the local description is set
3139// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003140// Don't run under Unified Plan since this behavior is Plan B specific.
3141TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003142 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003143 RTCConfiguration config;
3144 config.enable_dtls_srtp = true;
3145 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003146
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003147 rtc::scoped_refptr<StreamCollection> stream_collection =
3148 CreateStreamCollection(1, 2);
3149 // Add a stream to create the offer, but remove it afterwards.
3150 pc_->AddStream(stream_collection->at(0));
3151 std::unique_ptr<SessionDescriptionInterface> offer;
3152 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3153 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003154
Steve Antondb45ca82017-09-11 18:27:34 -07003155 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003156 auto senders = pc_->GetSenders();
3157 EXPECT_EQ(0u, senders.size());
3158
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003159 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003160 senders = pc_->GetSenders();
3161 EXPECT_EQ(4u, senders.size());
3162 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3163 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3164 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3165 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3166}
3167
3168// This tests that the expected behavior occurs if the SSRC on a local track is
3169// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003170TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003171 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003172 RTCConfiguration config;
3173 config.enable_dtls_srtp = true;
3174 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003175
Steve Anton36da6ff2018-02-16 16:04:20 -08003176 AddAudioTrack(kAudioTracks[0]);
3177 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003178 std::unique_ptr<SessionDescriptionInterface> offer;
3179 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3180 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003181 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3182 webrtc::CreateSessionDescription(
3183 webrtc::SdpType::kOffer, offer->session_id(),
3184 offer->session_version(),
3185 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003186 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003187
deadbeefab9b2d12015-10-14 11:33:11 -07003188 auto senders = pc_->GetSenders();
3189 EXPECT_EQ(2u, senders.size());
3190 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3191 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3192
3193 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003194 cricket::MediaContentDescription* desc =
3195 cricket::GetFirstAudioContentDescription(modified_offer->description());
3196 ASSERT_TRUE(desc != NULL);
3197 for (StreamParams& stream : desc->mutable_streams()) {
3198 for (unsigned int& ssrc : stream.ssrcs) {
3199 ++ssrc;
3200 }
3201 }
deadbeefab9b2d12015-10-14 11:33:11 -07003202
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003203 desc =
3204 cricket::GetFirstVideoContentDescription(modified_offer->description());
3205 ASSERT_TRUE(desc != NULL);
3206 for (StreamParams& stream : desc->mutable_streams()) {
3207 for (unsigned int& ssrc : stream.ssrcs) {
3208 ++ssrc;
3209 }
3210 }
3211
Steve Antondb45ca82017-09-11 18:27:34 -07003212 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003213 senders = pc_->GetSenders();
3214 EXPECT_EQ(2u, senders.size());
3215 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3216 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3217 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3218 // changed.
3219}
3220
3221// This tests that the expected behavior occurs if a new session description is
3222// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003223// Don't run under Unified Plan since the stream API is not available.
3224TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003225 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003226 RTCConfiguration config;
3227 config.enable_dtls_srtp = true;
3228 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003229
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003230 rtc::scoped_refptr<StreamCollection> stream_collection =
3231 CreateStreamCollection(2, 1);
3232 pc_->AddStream(stream_collection->at(0));
3233 std::unique_ptr<SessionDescriptionInterface> offer;
3234 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003235 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003236
deadbeefab9b2d12015-10-14 11:33:11 -07003237 auto senders = pc_->GetSenders();
3238 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003239 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3240 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003241
3242 // Add a new MediaStream but with the same tracks as in the first stream.
3243 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3244 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003245 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3246 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003247 pc_->AddStream(stream_1);
3248
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003249 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003250 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003251
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003252 auto new_senders = pc_->GetSenders();
3253 // Should be the same senders as before, but with updated stream id.
3254 // Note that this behavior is subject to change in the future.
3255 // We may decide the PC should ignore existing tracks in AddStream.
3256 EXPECT_EQ(senders, new_senders);
3257 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3258 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003259}
3260
zhihuang81c3a032016-11-17 12:06:24 -08003261// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003262TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003263 RTCConfiguration config;
3264 config.enable_dtls_srtp = true;
3265 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003266 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3267 EXPECT_EQ(observer_.num_added_tracks_, 1);
3268 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3269
3270 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003271 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003272 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003273 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3274}
3275
deadbeefd1a38b52016-12-10 13:15:33 -08003276// Test that when SetConfiguration is called and the configuration is
3277// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003278TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003279 PeerConnectionInterface::RTCConfiguration config;
3280 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003281 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003282 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003283 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3284 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003285
3286 // Do initial offer/answer so there's something to restart.
3287 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003288 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003289
3290 // Grab the ufrags.
3291 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3292
3293 // Change ICE policy, which should trigger an ICE restart on the next offer.
3294 config.type = PeerConnectionInterface::kAll;
3295 EXPECT_TRUE(pc_->SetConfiguration(config));
3296 CreateOfferAsLocalDescription();
3297
3298 // Grab the new ufrags.
3299 std::vector<std::string> subsequent_ufrags =
3300 GetUfrags(pc_->local_description());
3301
3302 // Sanity check.
3303 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3304 // Check that each ufrag is different.
3305 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3306 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3307 }
3308}
3309
3310// Test that when SetConfiguration is called and the configuration *isn't*
3311// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003312TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003313 PeerConnectionInterface::RTCConfiguration config;
3314 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003315 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003316 config = pc_->GetConfiguration();
3317 AddAudioTrack(kAudioTracks[0]);
3318 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003319
3320 // Do initial offer/answer so there's something to restart.
3321 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003322 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003323
3324 // Grab the ufrags.
3325 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3326
3327 // Call SetConfiguration with a config identical to what the PC was
3328 // constructed with.
3329 EXPECT_TRUE(pc_->SetConfiguration(config));
3330 CreateOfferAsLocalDescription();
3331
3332 // Grab the new ufrags.
3333 std::vector<std::string> subsequent_ufrags =
3334 GetUfrags(pc_->local_description());
3335
3336 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3337}
3338
3339// Test for a weird corner case scenario:
3340// 1. Audio/video session established.
3341// 2. SetConfiguration changes ICE config; ICE restart needed.
3342// 3. ICE restart initiated by remote peer, but only for one m= section.
3343// 4. Next createOffer should initiate an ICE restart, but only for the other
3344// m= section; it would be pointless to do an ICE restart for the m= section
3345// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003346TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003347 PeerConnectionInterface::RTCConfiguration config;
3348 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003349 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003350 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003351 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3352 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003353
3354 // Do initial offer/answer so there's something to restart.
3355 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003356 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003357
3358 // Change ICE policy, which should set the "needs-ice-restart" flag.
3359 config.type = PeerConnectionInterface::kAll;
3360 EXPECT_TRUE(pc_->SetConfiguration(config));
3361
3362 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003363 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003364 webrtc::CreateSessionDescription(SdpType::kOffer,
3365 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003366 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003367 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3368 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003369 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003370 CreateAnswerAsLocalDescription();
3371
3372 // Grab the ufrags.
3373 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003374 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003375
3376 // Create offer and grab the new ufrags.
3377 CreateOfferAsLocalDescription();
3378 std::vector<std::string> subsequent_ufrags =
3379 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003380 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003381
3382 // Ensure that only the ufrag for the second m= section changed.
3383 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3384 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3385}
3386
deadbeeffe4a8a42016-12-20 17:56:17 -08003387// Tests that the methods to return current/pending descriptions work as
3388// expected at different points in the offer/answer exchange. This test does
3389// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003390TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003391 // This disables DTLS so we can apply an answer to ourselves.
3392 CreatePeerConnection();
3393
3394 // Create initial local offer and get SDP (which will also be used as
3395 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003396 std::unique_ptr<SessionDescriptionInterface> local_offer;
3397 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003398 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003399 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003400
3401 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003402 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3403 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3404 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003405 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3406 EXPECT_EQ(nullptr, pc_->current_local_description());
3407 EXPECT_EQ(nullptr, pc_->current_remote_description());
3408
3409 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003410 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003411 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003412 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3413 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3414 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3415 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003416 EXPECT_EQ(nullptr, pc_->current_local_description());
3417 EXPECT_EQ(nullptr, pc_->current_remote_description());
3418
3419 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003420 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003421 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003422 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3423 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003424 EXPECT_EQ(nullptr, pc_->pending_local_description());
3425 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003426 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3427 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003428
3429 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003430 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003431 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003432 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3433 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3434 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003435 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003436 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3437 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003438
3439 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003440 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003441 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003442 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3443 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3444 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3445 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3446 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3447 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003448
3449 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003450 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003451 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003452 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3453 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003454 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3455 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003456 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3457 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003458}
3459
zhihuang77985012017-02-07 15:45:16 -08003460// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3461// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003462// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003463TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003464 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003465 CreatePeerConnection();
3466 // The RtcEventLog will be reset when the PeerConnection is closed.
3467 pc_->Close();
3468
Elad Alon9e6565b2017-10-11 16:04:13 +02003469 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3470 std::string filename = webrtc::test::OutputPath() +
3471 test_info->test_case_name() + test_info->name();
3472 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3473
3474 constexpr int64_t max_size_bytes = 1024;
3475
zhihuang77985012017-02-07 15:45:16 -08003476 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3477 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003478
3479 // Cleanup.
3480 rtc::ClosePlatformFile(file);
3481 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003482}
3483
Elad Alon99c3fe52017-10-13 16:29:40 +02003484// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3485// after the PeerConnection is closed.
3486// This version tests the StartRtcEventLog version that receives an object
3487// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003488TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003489 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3490 CreatePeerConnection();
3491 // The RtcEventLog will be reset when the PeerConnection is closed.
3492 pc_->Close();
3493
3494 rtc::PlatformFile file = 0;
3495 int64_t max_size_bytes = 1024;
3496 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003497 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003498 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003499 pc_->StopRtcEventLog();
3500}
3501
deadbeef30952b42017-04-21 02:41:29 -07003502// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003503TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003504 CreatePeerConnection();
3505
3506 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003507 RTCOfferAnswerOptions options;
3508 options.offer_to_receive_audio = 1;
3509 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003510 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003511 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003512 cricket::SessionDescription* desc = offer->description();
3513 ASSERT_EQ(2u, desc->transport_infos().size());
3514 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3515 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3516
3517 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003518 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003519 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003520 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003521 desc = answer->description();
3522 ASSERT_EQ(2u, desc->transport_infos().size());
3523 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3524 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3525}
3526
deadbeef1dcb1642017-03-29 21:08:16 -07003527// Test that ICE renomination isn't offered if it's not enabled in the PC's
3528// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003529TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003530 PeerConnectionInterface::RTCConfiguration config;
3531 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003532 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003533 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003534
3535 std::unique_ptr<SessionDescriptionInterface> offer;
3536 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3537 cricket::SessionDescription* desc = offer->description();
3538 EXPECT_EQ(1u, desc->transport_infos().size());
3539 EXPECT_FALSE(
3540 desc->transport_infos()[0].description.GetIceParameters().renomination);
3541}
3542
3543// Test that the ICE renomination option is present in generated offers/answers
3544// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003545TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003546 PeerConnectionInterface::RTCConfiguration config;
3547 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003548 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003549 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003550
3551 std::unique_ptr<SessionDescriptionInterface> offer;
3552 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3553 cricket::SessionDescription* desc = offer->description();
3554 EXPECT_EQ(1u, desc->transport_infos().size());
3555 EXPECT_TRUE(
3556 desc->transport_infos()[0].description.GetIceParameters().renomination);
3557
3558 // Set the offer as a remote description, then create an answer and ensure it
3559 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003560 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003561 std::unique_ptr<SessionDescriptionInterface> answer;
3562 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3563 desc = answer->description();
3564 EXPECT_EQ(1u, desc->transport_infos().size());
3565 EXPECT_TRUE(
3566 desc->transport_infos()[0].description.GetIceParameters().renomination);
3567}
3568
3569// Test that if CreateOffer is called with the deprecated "offer to receive
3570// audio/video" constraints, they're processed and result in an offer with
3571// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003572TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003573 CreatePeerConnection();
3574
Niels Möllerf06f9232018-08-07 12:32:18 +02003575 RTCOfferAnswerOptions options;
3576 options.offer_to_receive_audio = 1;
3577 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003578 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003579 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003580
3581 cricket::SessionDescription* desc = offer->description();
3582 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3583 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3584 ASSERT_NE(nullptr, audio);
3585 ASSERT_NE(nullptr, video);
3586 EXPECT_FALSE(audio->rejected);
3587 EXPECT_FALSE(video->rejected);
3588}
3589
3590// Test that if CreateAnswer is called with the deprecated "offer to receive
3591// audio/video" constraints, they're processed and can be used to reject an
3592// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003593// Don't run under Unified Plan since this behavior is not supported.
3594TEST_F(PeerConnectionInterfaceTestPlanB,
3595 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003596 CreatePeerConnection();
3597
3598 // First, create an offer with audio/video and apply it as a remote
3599 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003600 RTCOfferAnswerOptions options;
3601 options.offer_to_receive_audio = 1;
3602 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003603 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003604 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003605 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003606
3607 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003608 options.offer_to_receive_audio = 0;
3609 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003610 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003611 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003612
3613 cricket::SessionDescription* desc = answer->description();
3614 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3615 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3616 ASSERT_NE(nullptr, audio);
3617 ASSERT_NE(nullptr, video);
3618 EXPECT_TRUE(audio->rejected);
3619 EXPECT_TRUE(video->rejected);
3620}
3621
deadbeef1dcb1642017-03-29 21:08:16 -07003622// Test that negotiation can succeed with a data channel only, and with the max
3623// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003624#ifdef HAVE_SCTP
3625TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3626#else
3627TEST_P(PeerConnectionInterfaceTest,
3628 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3629#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003630 PeerConnectionInterface::RTCConfiguration config;
3631 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003632 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003633
3634 // First, create an offer with only a data channel and apply it as a remote
3635 // description.
3636 pc_->CreateDataChannel("test", nullptr);
3637 std::unique_ptr<SessionDescriptionInterface> offer;
3638 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003639 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003640
3641 // Create and set answer as well.
3642 std::unique_ptr<SessionDescriptionInterface> answer;
3643 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003644 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003645}
3646
Steve Anton36da6ff2018-02-16 16:04:20 -08003647TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003648 CreatePeerConnection();
3649 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003650 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003651 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3652}
3653
Steve Anton36da6ff2018-02-16 16:04:20 -08003654TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003655 CreatePeerConnection();
3656 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003657 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003658 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3659}
3660
Steve Anton36da6ff2018-02-16 16:04:20 -08003661TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003662 CreatePeerConnection();
3663 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003664 bitrate.min_bitrate_bps = 5;
3665 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003666 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3667}
3668
Steve Anton36da6ff2018-02-16 16:04:20 -08003669TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003670 CreatePeerConnection();
3671 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003672 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003673 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3674}
3675
Steve Anton36da6ff2018-02-16 16:04:20 -08003676TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003677 CreatePeerConnection();
3678 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003679 bitrate.current_bitrate_bps = 10;
3680 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003681 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3682}
3683
Steve Anton36da6ff2018-02-16 16:04:20 -08003684TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003685 CreatePeerConnection();
3686 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003687 bitrate.min_bitrate_bps = 10;
3688 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003689 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3690}
3691
Steve Anton36da6ff2018-02-16 16:04:20 -08003692TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003693 CreatePeerConnection();
3694 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003695 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003696 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3697}
3698
Steve Anton038834f2017-07-14 15:59:59 -07003699// ice_regather_interval_range requires WebRTC to be configured for continual
3700// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003701TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003702 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3703 PeerConnectionInterface::RTCConfiguration config;
3704 config.ice_regather_interval_range.emplace(1000, 2000);
3705 config.continual_gathering_policy =
3706 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3707 CreatePeerConnectionExpectFail(config);
3708}
3709
3710// Ensures that there is no error when ice_regather_interval_range is set with
3711// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003712TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003713 SetIceRegatherIntervalRangeWithContinualGathering) {
3714 PeerConnectionInterface::RTCConfiguration config;
3715 config.ice_regather_interval_range.emplace(1000, 2000);
3716 config.continual_gathering_policy =
3717 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003718 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003719}
3720
Niels Möller0c4f7be2018-05-07 14:01:37 +02003721// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003722// by Call's BitrateConstraints, which comes from the SDP or a default value.
3723// This test checks that a call to SetBitrate with a current bitrate that will
3724// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003725TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003726 CreatePeerConnection();
3727 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003728 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003729 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3730}
3731
zhihuang1c378ed2017-08-17 14:10:50 -07003732// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003733TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003734 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3735 RTCOfferAnswerOptions rtc_options;
3736
3737 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3738 // than kMaxOfferToReceiveMedia should be treated as invalid.
3739 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3740 CreatePeerConnection();
3741 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3742
3743 rtc_options.offer_to_receive_audio =
3744 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3745 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3746}
3747
Steve Anton36da6ff2018-02-16 16:04:20 -08003748TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003749 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3750 RTCOfferAnswerOptions rtc_options;
3751
3752 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3753 // than kMaxOfferToReceiveMedia should be treated as invalid.
3754 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3755 CreatePeerConnection();
3756 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3757
3758 rtc_options.offer_to_receive_video =
3759 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3760 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3761}
3762
3763// Test that the audio and video content will be added to an offer if both
3764// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003765TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003766 RTCOfferAnswerOptions rtc_options;
3767 rtc_options.offer_to_receive_audio = 1;
3768 rtc_options.offer_to_receive_video = 1;
3769
3770 std::unique_ptr<SessionDescriptionInterface> offer;
3771 CreatePeerConnection();
3772 offer = CreateOfferWithOptions(rtc_options);
3773 ASSERT_TRUE(offer);
3774 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3775 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3776}
3777
3778// Test that only audio content will be added to the offer if only
3779// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003780TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003781 RTCOfferAnswerOptions rtc_options;
3782 rtc_options.offer_to_receive_audio = 1;
3783 rtc_options.offer_to_receive_video = 0;
3784
3785 std::unique_ptr<SessionDescriptionInterface> offer;
3786 CreatePeerConnection();
3787 offer = CreateOfferWithOptions(rtc_options);
3788 ASSERT_TRUE(offer);
3789 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3790 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3791}
3792
3793// Test that only video content will be added if only |offer_to_receive_video|
3794// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003795TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003796 RTCOfferAnswerOptions rtc_options;
3797 rtc_options.offer_to_receive_audio = 0;
3798 rtc_options.offer_to_receive_video = 1;
3799
3800 std::unique_ptr<SessionDescriptionInterface> offer;
3801 CreatePeerConnection();
3802 offer = CreateOfferWithOptions(rtc_options);
3803 ASSERT_TRUE(offer);
3804 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3805 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3806}
3807
zhihuang1c378ed2017-08-17 14:10:50 -07003808// Test that no media content will be added to the offer if using default
3809// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003810TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003811 RTCOfferAnswerOptions rtc_options;
3812
3813 std::unique_ptr<SessionDescriptionInterface> offer;
3814 CreatePeerConnection();
3815 offer = CreateOfferWithOptions(rtc_options);
3816 ASSERT_TRUE(offer);
3817 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3818 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3819}
3820
3821// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3822// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003823TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3824 CreatePeerConnection();
3825
zhihuang1c378ed2017-08-17 14:10:50 -07003826 RTCOfferAnswerOptions rtc_options;
3827 rtc_options.ice_restart = false;
3828 rtc_options.offer_to_receive_audio = 1;
3829
3830 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003831 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003832 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3833 auto ufrag1 =
3834 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3835 auto pwd1 =
3836 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003837
3838 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3839 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003840 auto ufrag2 =
3841 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3842 auto pwd2 =
3843 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003844
3845 // |ice_restart| is true, the ufrag/pwd should change.
3846 rtc_options.ice_restart = true;
3847 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003848 auto ufrag3 =
3849 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3850 auto pwd3 =
3851 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003852
3853 EXPECT_EQ(ufrag1, ufrag2);
3854 EXPECT_EQ(pwd1, pwd2);
3855 EXPECT_NE(ufrag2, ufrag3);
3856 EXPECT_NE(pwd2, pwd3);
3857}
3858
3859// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3860// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003861TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003862 RTCOfferAnswerOptions rtc_options;
3863 rtc_options.offer_to_receive_audio = 1;
3864 rtc_options.offer_to_receive_video = 1;
3865
3866 std::unique_ptr<SessionDescriptionInterface> offer;
3867 CreatePeerConnection();
3868
3869 rtc_options.use_rtp_mux = true;
3870 offer = CreateOfferWithOptions(rtc_options);
3871 ASSERT_TRUE(offer);
3872 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3873 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3874 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3875
3876 rtc_options.use_rtp_mux = false;
3877 offer = CreateOfferWithOptions(rtc_options);
3878 ASSERT_TRUE(offer);
3879 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3880 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3881 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3882}
3883
zhihuang141aacb2017-08-29 13:23:53 -07003884// This test ensures OnRenegotiationNeeded is called when we add track with
3885// MediaStream -> AddTrack in the same way it is called when we add track with
3886// PeerConnection -> AddTrack.
3887// The test can be removed once addStream is rewritten in terms of addTrack
3888// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003889// Don't run under Unified Plan since the stream API is not available.
3890TEST_F(PeerConnectionInterfaceTestPlanB,
3891 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003892 CreatePeerConnectionWithoutDtls();
3893 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003894 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003895 pc_->AddStream(stream);
3896 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3897 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3898 rtc::scoped_refptr<VideoTrackInterface> video_track(
3899 pc_factory_->CreateVideoTrack(
3900 "video_track", pc_factory_->CreateVideoSource(
3901 std::unique_ptr<cricket::VideoCapturer>(
3902 new cricket::FakeVideoCapturer()))));
3903 stream->AddTrack(audio_track);
3904 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3905 observer_.renegotiation_needed_ = false;
3906
3907 stream->AddTrack(video_track);
3908 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3909 observer_.renegotiation_needed_ = false;
3910
3911 stream->RemoveTrack(audio_track);
3912 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3913 observer_.renegotiation_needed_ = false;
3914
3915 stream->RemoveTrack(video_track);
3916 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3917 observer_.renegotiation_needed_ = false;
3918}
3919
Zhi Huangb2d355e2017-10-26 17:26:37 -07003920// Tests that an error is returned if a description is applied that has fewer
3921// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003922TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003923 MediaSectionCountEnforcedForSubsequentOffer) {
3924 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003925 AddAudioTrack("audio_label");
3926 AddVideoTrack("video_label");
3927
Zhi Huangb2d355e2017-10-26 17:26:37 -07003928 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003929 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003930 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3931
3932 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003933 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003934 offer->description()->contents().pop_back();
3935 offer->description()->contents().pop_back();
3936 ASSERT_TRUE(offer->description()->contents().empty());
3937 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3938
3939 std::unique_ptr<SessionDescriptionInterface> answer;
3940 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3941 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3942
3943 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003944 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003945 offer->description()->contents().pop_back();
3946 offer->description()->contents().pop_back();
3947 ASSERT_TRUE(offer->description()->contents().empty());
3948 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3949}
3950
Johannes Kron89f874e2018-11-12 10:25:48 +01003951TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3952 RTCConfiguration config;
3953 // Default behavior is false.
3954 CreatePeerConnection(config);
3955 std::unique_ptr<SessionDescriptionInterface> offer;
3956 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3957 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3958 // Possible to set to true.
3959 config.offer_extmap_allow_mixed = true;
3960 CreatePeerConnection(config);
3961 offer.release();
3962 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3963 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3964}
3965
Steve Anton36da6ff2018-02-16 16:04:20 -08003966INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3967 PeerConnectionInterfaceTest,
3968 Values(SdpSemantics::kPlanB,
3969 SdpSemantics::kUnifiedPlan));
3970
nisse51542be2016-02-12 02:27:06 -08003971class PeerConnectionMediaConfigTest : public testing::Test {
3972 protected:
3973 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003974 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003975 pcf_->Initialize();
3976 }
nisseeaabdf62017-05-05 02:23:02 -07003977 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003978 const RTCConfiguration& config) {
3979 rtc::scoped_refptr<PeerConnectionInterface> pc(
3980 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003981 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003982 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003983 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003984 }
3985
zhihuang9763d562016-08-05 11:14:50 -07003986 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003987 MockPeerConnectionObserver observer_;
3988};
3989
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003990// This sanity check validates the test infrastructure itself.
3991TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3992 PeerConnectionInterface::RTCConfiguration config;
3993 rtc::scoped_refptr<PeerConnectionInterface> pc(
3994 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3995 EXPECT_TRUE(pc.get());
3996 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3997 pc->Close(); // No abort -> ok.
3998 SUCCEED();
3999}
4000
nisse51542be2016-02-12 02:27:06 -08004001// This test verifies the default behaviour with no constraints and a
4002// default RTCConfiguration.
4003TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4004 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004005
Niels Möllerf06f9232018-08-07 12:32:18 +02004006 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004007
4008 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004009 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4010 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004011 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004012 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004013}
4014
Niels Möller1d7ecd22018-01-18 15:25:12 +01004015// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004016// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004017TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4018 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004019
Niels Möller71bdda02016-03-31 12:59:59 +02004020 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004021 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004022
Niels Möller1d7ecd22018-01-18 15:25:12 +01004023 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004024}
4025
Niels Möller6539f692018-01-18 08:58:50 +01004026// This test verifies that the experiment_cpu_load_estimator flag is
4027// propagated from RTCConfiguration to the PeerConnection.
4028TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4029 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004030
4031 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004032 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004033
4034 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4035}
4036
deadbeef293e9262017-01-11 12:28:30 -08004037// Tests a few random fields being different.
4038TEST(RTCConfigurationTest, ComparisonOperators) {
4039 PeerConnectionInterface::RTCConfiguration a;
4040 PeerConnectionInterface::RTCConfiguration b;
4041 EXPECT_EQ(a, b);
4042
4043 PeerConnectionInterface::RTCConfiguration c;
4044 c.servers.push_back(PeerConnectionInterface::IceServer());
4045 EXPECT_NE(a, c);
4046
4047 PeerConnectionInterface::RTCConfiguration d;
4048 d.type = PeerConnectionInterface::kRelay;
4049 EXPECT_NE(a, d);
4050
4051 PeerConnectionInterface::RTCConfiguration e;
4052 e.audio_jitter_buffer_max_packets = 5;
4053 EXPECT_NE(a, e);
4054
4055 PeerConnectionInterface::RTCConfiguration f;
4056 f.ice_connection_receiving_timeout = 1337;
4057 EXPECT_NE(a, f);
4058
4059 PeerConnectionInterface::RTCConfiguration g;
4060 g.disable_ipv6 = true;
4061 EXPECT_NE(a, g);
4062
4063 PeerConnectionInterface::RTCConfiguration h(
4064 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4065 EXPECT_NE(a, h);
4066}