blob: fe8fd8ddea2e0586d0c9e5899482855c586c5048 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Zhi Huang2a5e4262017-09-14 01:15:03 -070011#include <algorithm>
kwibergd1fe2812016-04-27 06:47:29 -070012#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080013#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080015#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
Karl Wiberg918f50c2018-07-05 11:40:33 +020017#include "absl/memory/memory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio_codecs/builtin_audio_decoder_factory.h"
19#include "api/audio_codecs/builtin_audio_encoder_factory.h"
20#include "api/jsepsessiondescription.h"
21#include "api/mediastreaminterface.h"
22#include "api/peerconnectioninterface.h"
23#include "api/rtpreceiverinterface.h"
24#include "api/rtpsenderinterface.h"
Anders Carlsson67537952018-05-03 11:28:29 +020025#include "api/video_codecs/builtin_video_decoder_factory.h"
26#include "api/video_codecs/builtin_video_encoder_factory.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020027#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "media/base/fakevideocapturer.h"
29#include "media/engine/webrtcmediaengine.h"
30#include "media/sctp/sctptransportinternal.h"
31#include "modules/audio_processing/include/audio_processing.h"
32#include "p2p/base/fakeportallocator.h"
33#include "pc/audiotrack.h"
34#include "pc/mediasession.h"
35#include "pc/mediastream.h"
36#include "pc/peerconnection.h"
Steve Anton57858b32018-02-15 15:19:50 -080037#include "pc/rtpsender.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "pc/streamcollection.h"
39#include "pc/test/fakeaudiocapturemodule.h"
40#include "pc/test/fakertccertificategenerator.h"
41#include "pc/test/fakevideotracksource.h"
42#include "pc/test/mockpeerconnectionobservers.h"
43#include "pc/test/testsdpstrings.h"
44#include "pc/videocapturertracksource.h"
45#include "pc/videotrack.h"
46#include "rtc_base/gunit.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020047#include "rtc_base/stringutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "rtc_base/virtualsocketserver.h"
49#include "test/gmock.h"
Elad Alon9e6565b2017-10-11 16:04:13 +020050#include "test/testsupport/fileutils.h"
kwibergac9f8762016-09-30 22:29:43 -070051
52#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#include "pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070054#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
Seth Hampson845e8782018-03-02 11:34:10 -080056static const char kStreamId1[] = "local_stream_1";
57static const char kStreamId2[] = "local_stream_2";
58static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059static const int kDefaultStunPort = 3478;
60static const char kStunAddressOnly[] = "stun:address";
61static const char kStunInvalidPort[] = "stun:address:-1";
62static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
63static const char kStunAddressPortAndMore2[] = "stun:address:port more";
64static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
65static const char kTurnUsername[] = "user";
66static const char kTurnPassword[] = "password";
67static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020068static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069
deadbeefab9b2d12015-10-14 11:33:11 -070070static const char kStreams[][8] = {"stream1", "stream2"};
71static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
72static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
73
deadbeef5e97fb52015-10-15 12:49:08 -070074static const char kRecvonly[] = "recvonly";
75static const char kSendrecv[] = "sendrecv";
76
deadbeefab9b2d12015-10-14 11:33:11 -070077// Reference SDP with a MediaStream with label "stream1" and audio track with
78// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -080079static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -070080 "v=0\r\n"
81 "o=- 0 0 IN IP4 127.0.0.1\r\n"
82 "s=-\r\n"
83 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080084 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070085 "a=ice-ufrag:e5785931\r\n"
86 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
87 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
88 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070089 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070090 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080091 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070092 "a=rtpmap:103 ISAC/16000\r\n"
93 "a=ssrc:1 cname:stream1\r\n"
94 "a=ssrc:1 mslabel:stream1\r\n"
95 "a=ssrc:1 label:audiotrack0\r\n"
96 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080097 "a=ice-ufrag:e5785931\r\n"
98 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
99 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
100 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700101 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700102 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800103 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700104 "a=rtpmap:120 VP8/90000\r\n"
105 "a=ssrc:2 cname:stream1\r\n"
106 "a=ssrc:2 mslabel:stream1\r\n"
107 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800108// Same string as above but with the MID changed to the Unified Plan default.
109// This is needed so that this SDP can be used as an answer for a Unified Plan
110// offer.
111static const char kSdpStringWithStream1UnifiedPlan[] =
112 "v=0\r\n"
113 "o=- 0 0 IN IP4 127.0.0.1\r\n"
114 "s=-\r\n"
115 "t=0 0\r\n"
116 "m=audio 1 RTP/AVPF 103\r\n"
117 "a=ice-ufrag:e5785931\r\n"
118 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
119 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
120 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
121 "a=mid:0\r\n"
122 "a=sendrecv\r\n"
123 "a=rtcp-mux\r\n"
124 "a=rtpmap:103 ISAC/16000\r\n"
125 "a=ssrc:1 cname:stream1\r\n"
126 "a=ssrc:1 mslabel:stream1\r\n"
127 "a=ssrc:1 label:audiotrack0\r\n"
128 "m=video 1 RTP/AVPF 120\r\n"
129 "a=ice-ufrag:e5785931\r\n"
130 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
131 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
132 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
133 "a=mid:1\r\n"
134 "a=sendrecv\r\n"
135 "a=rtcp-mux\r\n"
136 "a=rtpmap:120 VP8/90000\r\n"
137 "a=ssrc:2 cname:stream1\r\n"
138 "a=ssrc:2 mslabel:stream1\r\n"
139 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700140
zhihuang81c3a032016-11-17 12:06:24 -0800141// Reference SDP with a MediaStream with label "stream1" and audio track with
142// id "audio_1";
143static const char kSdpStringWithStream1AudioTrackOnly[] =
144 "v=0\r\n"
145 "o=- 0 0 IN IP4 127.0.0.1\r\n"
146 "s=-\r\n"
147 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800148 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800149 "a=ice-ufrag:e5785931\r\n"
150 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
151 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
152 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800153 "a=mid:audio\r\n"
154 "a=sendrecv\r\n"
155 "a=rtpmap:103 ISAC/16000\r\n"
156 "a=ssrc:1 cname:stream1\r\n"
157 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800158 "a=ssrc:1 label:audiotrack0\r\n"
159 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800160
deadbeefab9b2d12015-10-14 11:33:11 -0700161// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
162// MediaStreams have one audio track and one video track.
163// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800164static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700165 "v=0\r\n"
166 "o=- 0 0 IN IP4 127.0.0.1\r\n"
167 "s=-\r\n"
168 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800169 "a=msid-semantic: WMS stream1 stream2\r\n"
170 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700171 "a=ice-ufrag:e5785931\r\n"
172 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
173 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
174 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700175 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700176 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800177 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700178 "a=rtpmap:103 ISAC/16000\r\n"
179 "a=ssrc:1 cname:stream1\r\n"
180 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
181 "a=ssrc:3 cname:stream2\r\n"
182 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
183 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800184 "a=ice-ufrag:e5785931\r\n"
185 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
186 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
187 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700188 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700189 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800190 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700191 "a=rtpmap:120 VP8/0\r\n"
192 "a=ssrc:2 cname:stream1\r\n"
193 "a=ssrc:2 msid:stream1 videotrack0\r\n"
194 "a=ssrc:4 cname:stream2\r\n"
195 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800196static const char kSdpStringWithStream1And2UnifiedPlan[] =
197 "v=0\r\n"
198 "o=- 0 0 IN IP4 127.0.0.1\r\n"
199 "s=-\r\n"
200 "t=0 0\r\n"
201 "a=msid-semantic: WMS stream1 stream2\r\n"
202 "m=audio 1 RTP/AVPF 103\r\n"
203 "a=ice-ufrag:e5785931\r\n"
204 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
205 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
206 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
207 "a=mid:0\r\n"
208 "a=sendrecv\r\n"
209 "a=rtcp-mux\r\n"
210 "a=rtpmap:103 ISAC/16000\r\n"
211 "a=ssrc:1 cname:stream1\r\n"
212 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
213 "m=video 1 RTP/AVPF 120\r\n"
214 "a=ice-ufrag:e5785931\r\n"
215 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
216 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
217 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
218 "a=mid:1\r\n"
219 "a=sendrecv\r\n"
220 "a=rtcp-mux\r\n"
221 "a=rtpmap:120 VP8/0\r\n"
222 "a=ssrc:2 cname:stream1\r\n"
223 "a=ssrc:2 msid:stream1 videotrack0\r\n"
224 "m=audio 1 RTP/AVPF 103\r\n"
225 "a=ice-ufrag:e5785931\r\n"
226 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
227 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
228 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
229 "a=mid:2\r\n"
230 "a=sendrecv\r\n"
231 "a=rtcp-mux\r\n"
232 "a=rtpmap:103 ISAC/16000\r\n"
233 "a=ssrc:3 cname:stream2\r\n"
234 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
235 "m=video 1 RTP/AVPF 120\r\n"
236 "a=ice-ufrag:e5785931\r\n"
237 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
238 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
239 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
240 "a=mid:3\r\n"
241 "a=sendrecv\r\n"
242 "a=rtcp-mux\r\n"
243 "a=rtpmap:120 VP8/0\r\n"
244 "a=ssrc:4 cname:stream2\r\n"
245 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700246
247// Reference SDP without MediaStreams. Msid is not supported.
248static const char kSdpStringWithoutStreams[] =
249 "v=0\r\n"
250 "o=- 0 0 IN IP4 127.0.0.1\r\n"
251 "s=-\r\n"
252 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800253 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700254 "a=ice-ufrag:e5785931\r\n"
255 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
256 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
257 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700258 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700259 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800260 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700261 "a=rtpmap:103 ISAC/16000\r\n"
262 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800263 "a=ice-ufrag:e5785931\r\n"
264 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
265 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
266 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700267 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700268 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800269 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700270 "a=rtpmap:120 VP8/90000\r\n";
271
272// Reference SDP without MediaStreams. Msid is supported.
273static const char kSdpStringWithMsidWithoutStreams[] =
274 "v=0\r\n"
275 "o=- 0 0 IN IP4 127.0.0.1\r\n"
276 "s=-\r\n"
277 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800278 "a=msid-semantic: WMS\r\n"
279 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700280 "a=ice-ufrag:e5785931\r\n"
281 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
282 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
283 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700284 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700285 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800286 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700287 "a=rtpmap:103 ISAC/16000\r\n"
288 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800289 "a=ice-ufrag:e5785931\r\n"
290 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
291 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
292 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700293 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700294 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800295 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700296 "a=rtpmap:120 VP8/90000\r\n";
297
298// Reference SDP without MediaStreams and audio only.
299static const char kSdpStringWithoutStreamsAudioOnly[] =
300 "v=0\r\n"
301 "o=- 0 0 IN IP4 127.0.0.1\r\n"
302 "s=-\r\n"
303 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800304 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700305 "a=ice-ufrag:e5785931\r\n"
306 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
307 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
308 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700309 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700310 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800311 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700312 "a=rtpmap:103 ISAC/16000\r\n";
313
314// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
315static const char kSdpStringSendOnlyWithoutStreams[] =
316 "v=0\r\n"
317 "o=- 0 0 IN IP4 127.0.0.1\r\n"
318 "s=-\r\n"
319 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800320 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700321 "a=ice-ufrag:e5785931\r\n"
322 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
323 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
324 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700325 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700326 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700327 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800328 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700329 "a=rtpmap:103 ISAC/16000\r\n"
330 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800331 "a=ice-ufrag:e5785931\r\n"
332 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
333 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
334 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700335 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700336 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700337 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800338 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700339 "a=rtpmap:120 VP8/90000\r\n";
340
341static const char kSdpStringInit[] =
342 "v=0\r\n"
343 "o=- 0 0 IN IP4 127.0.0.1\r\n"
344 "s=-\r\n"
345 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700346 "a=msid-semantic: WMS\r\n";
347
348static const char kSdpStringAudio[] =
349 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800350 "a=ice-ufrag:e5785931\r\n"
351 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
352 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
353 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700354 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700355 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800356 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700357 "a=rtpmap:103 ISAC/16000\r\n";
358
359static const char kSdpStringVideo[] =
360 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800361 "a=ice-ufrag:e5785931\r\n"
362 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
363 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
364 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700365 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700366 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800367 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700368 "a=rtpmap:120 VP8/90000\r\n";
369
370static const char kSdpStringMs1Audio0[] =
371 "a=ssrc:1 cname:stream1\r\n"
372 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
373
374static const char kSdpStringMs1Video0[] =
375 "a=ssrc:2 cname:stream1\r\n"
376 "a=ssrc:2 msid:stream1 videotrack0\r\n";
377
378static const char kSdpStringMs1Audio1[] =
379 "a=ssrc:3 cname:stream1\r\n"
380 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
381
382static const char kSdpStringMs1Video1[] =
383 "a=ssrc:4 cname:stream1\r\n"
384 "a=ssrc:4 msid:stream1 videotrack1\r\n";
385
deadbeef8662f942017-01-20 21:20:51 -0800386static const char kDtlsSdesFallbackSdp[] =
387 "v=0\r\n"
388 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
389 "s=-\r\n"
390 "c=IN IP4 0.0.0.0\r\n"
391 "t=0 0\r\n"
392 "a=group:BUNDLE audio\r\n"
393 "a=msid-semantic: WMS\r\n"
394 "m=audio 1 RTP/SAVPF 0\r\n"
395 "a=sendrecv\r\n"
396 "a=rtcp-mux\r\n"
397 "a=mid:audio\r\n"
398 "a=ssrc:1 cname:stream1\r\n"
399 "a=ssrc:1 mslabel:stream1\r\n"
400 "a=ssrc:1 label:audiotrack0\r\n"
401 "a=ice-ufrag:e5785931\r\n"
402 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
403 "a=rtpmap:0 pcmu/8000\r\n"
404 "a=fingerprint:sha-1 "
405 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
406 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700407 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800408 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
409 "dummy_session_params\r\n";
410
perkjd61bf802016-03-24 03:16:19 -0700411using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800412using ::testing::Values;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700413using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700415using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416using webrtc::AudioTrackInterface;
417using webrtc::DataBuffer;
418using webrtc::DataChannelInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419using webrtc::IceCandidateInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700420using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421using webrtc::MediaStreamInterface;
422using webrtc::MediaStreamTrackInterface;
423using webrtc::MockCreateSessionDescriptionObserver;
424using webrtc::MockDataChannelObserver;
Steve Anton94286cb2017-09-26 16:20:19 -0700425using webrtc::MockPeerConnectionObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426using webrtc::MockSetSessionDescriptionObserver;
427using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700428using webrtc::NotifierInterface;
429using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430using webrtc::PeerConnectionInterface;
431using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800432using webrtc::RTCError;
433using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700434using webrtc::RtpReceiverInterface;
435using webrtc::RtpSenderInterface;
Steve Anton57858b32018-02-15 15:19:50 -0800436using webrtc::RtpSenderProxyWithInternal;
437using webrtc::RtpSenderInternal;
Steve Anton4e70a722017-11-28 14:57:10 -0800438using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439using webrtc::SdpParseError;
Steve Anton36da6ff2018-02-16 16:04:20 -0800440using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800441using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700443using webrtc::StreamCollection;
444using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100445using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700446using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447using webrtc::VideoTrackInterface;
448
Steve Anton36da6ff2018-02-16 16:04:20 -0800449using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
450using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700451
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452namespace {
453
454// Gets the first ssrc of given content type from the ContentInfo.
455bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
456 if (!content_info || !ssrc) {
457 return false;
458 }
459 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800460 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 if (!media_desc || media_desc->streams().empty()) {
462 return false;
463 }
464 *ssrc = media_desc->streams().begin()->first_ssrc();
465 return true;
466}
467
deadbeefd1a38b52016-12-10 13:15:33 -0800468// Get the ufrags out of an SDP blob. Useful for testing ICE restart
469// behavior.
470std::vector<std::string> GetUfrags(
471 const webrtc::SessionDescriptionInterface* desc) {
472 std::vector<std::string> ufrags;
473 for (const cricket::TransportInfo& info :
474 desc->description()->transport_infos()) {
475 ufrags.push_back(info.description.ice_ufrag);
476 }
477 return ufrags;
478}
479
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480void SetSsrcToZero(std::string* sdp) {
481 const char kSdpSsrcAtribute[] = "a=ssrc:";
482 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
483 size_t ssrc_pos = 0;
484 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200485 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 size_t end_ssrc = sdp->find(" ", ssrc_pos);
487 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
488 ssrc_pos = end_ssrc;
489 }
490}
491
deadbeefab9b2d12015-10-14 11:33:11 -0700492// Check if |streams| contains the specified track.
493bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800494 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700495 const std::string& track_id) {
496 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800497 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700498 return true;
499 }
500 }
501 return false;
502}
503
504// Check if |senders| contains the specified sender, by id.
505bool ContainsSender(
506 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
507 const std::string& id) {
508 for (const auto& sender : senders) {
509 if (sender->id() == id) {
510 return true;
511 }
512 }
513 return false;
514}
515
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700516// Check if |senders| contains the specified sender, by id and stream id.
517bool ContainsSender(
518 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
519 const std::string& id,
520 const std::string& stream_id) {
521 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700522 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700523 return true;
524 }
525 }
526 return false;
527}
528
deadbeefab9b2d12015-10-14 11:33:11 -0700529// Create a collection of streams.
530// CreateStreamCollection(1) creates a collection that
531// correspond to kSdpStringWithStream1.
532// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
533rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700534 int number_of_streams,
535 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700536 rtc::scoped_refptr<StreamCollection> local_collection(
537 StreamCollection::Create());
538
539 for (int i = 0; i < number_of_streams; ++i) {
540 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
541 webrtc::MediaStream::Create(kStreams[i]));
542
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700543 for (int j = 0; j < tracks_per_stream; ++j) {
544 // Add a local audio track.
545 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
546 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
547 nullptr));
548 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700549
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700550 // Add a local video track.
551 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
552 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700553 webrtc::FakeVideoTrackSource::Create(),
554 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700555 stream->AddTrack(video_track);
556 }
deadbeefab9b2d12015-10-14 11:33:11 -0700557
558 local_collection->AddStream(stream);
559 }
560 return local_collection;
561}
562
563// Check equality of StreamCollections.
564bool CompareStreamCollections(StreamCollectionInterface* s1,
565 StreamCollectionInterface* s2) {
566 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
567 return false;
568 }
569
570 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700571 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700572 return false;
573 }
574 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
575 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
576 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
577 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
578
579 if (audio_tracks1.size() != audio_tracks2.size()) {
580 return false;
581 }
582 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
583 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
584 return false;
585 }
586 }
587 if (video_tracks1.size() != video_tracks2.size()) {
588 return false;
589 }
590 for (size_t j = 0; j != video_tracks1.size(); ++j) {
591 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
592 return false;
593 }
594 }
595 }
596 return true;
597}
598
perkjd61bf802016-03-24 03:16:19 -0700599// Helper class to test Observer.
600class MockTrackObserver : public ObserverInterface {
601 public:
602 explicit MockTrackObserver(NotifierInterface* notifier)
603 : notifier_(notifier) {
604 notifier_->RegisterObserver(this);
605 }
606
607 ~MockTrackObserver() { Unregister(); }
608
609 void Unregister() {
610 if (notifier_) {
611 notifier_->UnregisterObserver(this);
612 notifier_ = nullptr;
613 }
614 }
615
616 MOCK_METHOD0(OnChanged, void());
617
618 private:
619 NotifierInterface* notifier_;
620};
621
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700623
nisse528b7932017-05-08 03:21:43 -0700624// The PeerConnectionMediaConfig tests below verify that configuration and
625// constraints are propagated into the PeerConnection's MediaConfig. These
626// settings are intended for MediaChannel constructors, but that is not
627// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700628class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
629 public:
zhihuang38ede132017-06-15 12:52:32 -0700630 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
631 CreatePeerConnectionFactoryForTest() {
632 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
633 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200634 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
635 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700636
henrika919dc2e2017-10-12 14:24:55 +0200637 // Use fake audio device module since we're only testing the interface
638 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700639 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
640 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200641 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200642 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000643 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100644 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700645
646 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
647 webrtc::CreateCallFactory();
648
649 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
650 webrtc::CreateRtcEventLogFactory();
651
652 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
653 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200654 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700655 std::move(event_log_factory));
656 }
657
658 PeerConnectionFactoryForTest(
659 rtc::Thread* network_thread,
660 rtc::Thread* worker_thread,
661 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700662 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
663 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
664 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
665 : webrtc::PeerConnectionFactory(network_thread,
666 worker_thread,
667 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700668 std::move(media_engine),
669 std::move(call_factory),
670 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800671
deadbeefd7850b22017-08-23 10:59:19 -0700672 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700673};
674
Steve Anton36da6ff2018-02-16 16:04:20 -0800675// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
676class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800678 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
679 : vss_(new rtc::VirtualSocketServer()),
680 main_(vss_.get()),
681 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800682#ifdef WEBRTC_ANDROID
683 webrtc::InitializeAndroidObjects();
684#endif
685 }
686
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700688 // Use fake audio capture module since we're only testing the interface
689 // level, and using a real one could make tests flaky when run in parallel.
690 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700692 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200693 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
694 fake_audio_capture_module_),
695 webrtc::CreateBuiltinAudioEncoderFactory(),
696 webrtc::CreateBuiltinAudioDecoderFactory(),
697 webrtc::CreateBuiltinVideoEncoderFactory(),
698 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
699 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700700 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700701 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700702 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700703 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 }
705
706 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200707 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
deadbeef293e9262017-01-11 12:28:30 -0800710 // DTLS does not work in a loopback call, so is disabled for most of the
711 // tests in this file.
712 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200713 RTCConfiguration config;
714 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800715
Niels Möllerf06f9232018-08-07 12:32:18 +0200716 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 }
718
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 void CreatePeerConnectionWithIceTransportsType(
720 PeerConnectionInterface::IceTransportsType type) {
721 PeerConnectionInterface::RTCConfiguration config;
722 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200723 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700724 }
725
726 void CreatePeerConnectionWithIceServer(const std::string& uri,
727 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800728 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 server.uri = uri;
731 server.password = password;
732 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200733 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700734 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735
Niels Möllerf06f9232018-08-07 12:32:18 +0200736 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700737 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800738 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
739 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000740
deadbeef1dcb1642017-03-29 21:08:16 -0700741 // Create certificate generator unless DTLS constraint is explicitly set to
742 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200743 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200744
745 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800746 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
747 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000748 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800749 RTCConfiguration modified_config = config;
750 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200751 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200752 modified_config, std::move(port_allocator), std::move(cert_generator),
753 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 ASSERT_TRUE(pc_.get() != NULL);
755 observer_.SetPeerConnectionInterface(pc_.get());
756 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
757 }
758
deadbeef0a6c4ca2015-10-06 11:38:28 -0700759 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800760 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700761 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700762 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800763 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800764 config.sdp_semantics = sdp_semantics_;
765 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200766 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800767 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700768 }
769
Steve Anton038834f2017-07-14 15:59:59 -0700770 void CreatePeerConnectionExpectFail(
771 PeerConnectionInterface::RTCConfiguration config) {
772 PeerConnectionInterface::IceServer server;
773 server.uri = kTurnIceServerUri;
774 server.password = kTurnPassword;
775 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800776 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700777 rtc::scoped_refptr<PeerConnectionInterface> pc =
778 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
779 EXPECT_EQ(nullptr, pc);
780 }
781
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700783 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800784 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
785 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
786 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800788 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789
deadbeef0a6c4ca2015-10-06 11:38:28 -0700790 CreatePeerConnectionExpectFail(kStunInvalidPort);
791 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
792 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700794 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800795 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
796 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 }
804
805 void ReleasePeerConnection() {
806 pc_ = NULL;
807 observer_.SetPeerConnectionInterface(NULL);
808 }
809
Steve Anton36da6ff2018-02-16 16:04:20 -0800810 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
811 const std::string& label) {
812 auto video_source = pc_factory_->CreateVideoSource(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200813 absl::make_unique<cricket::FakeVideoCapturer>(), nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -0800814 return pc_factory_->CreateVideoTrack(label, video_source);
815 }
816
817 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800818 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800819 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800820 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800821 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
823 observer_.renegotiation_needed_ = false;
824 }
825
Steve Anton36da6ff2018-02-16 16:04:20 -0800826 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700827 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800829 stream->AddTrack(CreateVideoTrack(label + "v0"));
830 ASSERT_TRUE(pc_->AddStream(stream));
831 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
832 observer_.renegotiation_needed_ = false;
833 }
834
835 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
836 const std::string& label) {
837 return pc_factory_->CreateAudioTrack(label, nullptr);
838 }
839
840 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800841 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800842 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800843 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800844 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
845 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
846 observer_.renegotiation_needed_ = false;
847 }
848
849 void AddAudioStream(const std::string& label) {
850 rtc::scoped_refptr<MediaStreamInterface> stream(
851 pc_factory_->CreateLocalMediaStream(label));
852 stream->AddTrack(CreateAudioTrack(label + "a0"));
853 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
855 observer_.renegotiation_needed_ = false;
856 }
857
Seth Hampson845e8782018-03-02 11:34:10 -0800858 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 const std::string& audio_track_label,
860 const std::string& video_track_label) {
861 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700862 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800863 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800864 stream->AddTrack(CreateAudioTrack(audio_track_label));
865 stream->AddTrack(CreateVideoTrack(video_track_label));
866 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
868 observer_.renegotiation_needed_ = false;
869 }
870
Steve Anton36da6ff2018-02-16 16:04:20 -0800871 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
872 cricket::MediaType media_type) {
873 for (auto receiver : pc_->GetReceivers()) {
874 if (receiver->media_type() == media_type) {
875 return receiver;
876 }
877 }
878 return nullptr;
879 }
880
kwibergd1fe2812016-04-27 06:47:29 -0700881 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200882 const RTCOfferAnswerOptions* options,
883 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200884 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
885 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200887 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200889 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700892 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 return observer->result();
894 }
895
kwibergd1fe2812016-04-27 06:47:29 -0700896 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200897 const RTCOfferAnswerOptions* options) {
898 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 }
900
kwibergd1fe2812016-04-27 06:47:29 -0700901 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200902 const RTCOfferAnswerOptions* options) {
903 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 }
905
Steve Antondb45ca82017-09-11 18:27:34 -0700906 bool DoSetSessionDescription(
907 std::unique_ptr<SessionDescriptionInterface> desc,
908 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200909 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
910 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700912 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700914 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 }
zhihuang29ff8442016-07-27 11:07:25 -0700916 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
917 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
918 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 return observer->result();
920 }
921
Steve Antondb45ca82017-09-11 18:27:34 -0700922 bool DoSetLocalDescription(
923 std::unique_ptr<SessionDescriptionInterface> desc) {
924 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 }
926
Steve Antondb45ca82017-09-11 18:27:34 -0700927 bool DoSetRemoteDescription(
928 std::unique_ptr<SessionDescriptionInterface> desc) {
929 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 }
931
932 // Calls PeerConnection::GetStats and check the return value.
933 // It does not verify the values in the StatReports since a RTCP packet might
934 // be required.
935 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000936 rtc::scoped_refptr<MockStatsObserver> observer(
937 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200938 if (!pc_->GetStats(observer, track,
939 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 return false;
941 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
942 return observer->called();
943 }
944
Harald Alvestrand89061872018-01-02 14:08:34 +0100945 // Call the standards-compliant GetStats function.
946 bool DoGetRTCStats() {
947 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
948 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
949 pc_->GetStats(callback);
950 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
951 return callback->called();
952 }
953
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800955 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800957 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800958 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800959 } else {
960 // Unified Plan does not support AddStream, so just add an audio and video
961 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800962 AddAudioTrack(kAudioTracks[0], {kStreamId1});
963 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800964 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 CreateOfferReceiveAnswer();
966 }
967
968 // Verify that RTP Header extensions has been negotiated for audio and video.
969 void VerifyRemoteRtpHeaderExtensions() {
970 const cricket::MediaContentDescription* desc =
971 cricket::GetFirstAudioContentDescription(
972 pc_->remote_description()->description());
973 ASSERT_TRUE(desc != NULL);
974 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
975
976 desc = cricket::GetFirstVideoContentDescription(
977 pc_->remote_description()->description());
978 ASSERT_TRUE(desc != NULL);
979 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
980 }
981
982 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700983 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700984 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 std::string sdp;
986 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700987 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800988 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700989 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
991 }
992
deadbeefab9b2d12015-10-14 11:33:11 -0700993 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700994 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800995 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700996 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700997 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
998 }
999
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001001 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001002 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003
1004 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1005 // audio codec change, even if the parameter has nothing to do with
1006 // receiving. Not all parameters are serialized to SDP.
1007 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1008 // the SessionDescription, it is necessary to do that here to in order to
1009 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1010 // https://code.google.com/p/webrtc/issues/detail?id=1356
1011 std::string sdp;
1012 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001013 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001014 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001015 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1017 }
1018
1019 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001020 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001021 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022
1023 std::string sdp;
1024 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001025 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001026 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001027 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1029 }
1030
1031 void CreateOfferReceiveAnswer() {
1032 CreateOfferAsLocalDescription();
1033 std::string sdp;
1034 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1035 CreateAnswerAsRemoteDescription(sdp);
1036 }
1037
1038 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001039 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001040 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1042 // audio codec change, even if the parameter has nothing to do with
1043 // receiving. Not all parameters are serialized to SDP.
1044 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1045 // the SessionDescription, it is necessary to do that here to in order to
1046 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1047 // https://code.google.com/p/webrtc/issues/detail?id=1356
1048 std::string sdp;
1049 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001050 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001051 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052
Steve Antondb45ca82017-09-11 18:27:34 -07001053 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001055 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001056 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 }
1058
deadbeefab9b2d12015-10-14 11:33:11 -07001059 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001060 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001061 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001062 ASSERT_TRUE(answer);
1063 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1065 }
1066
deadbeefab9b2d12015-10-14 11:33:11 -07001067 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001068 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001069 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001070 ASSERT_TRUE(pr_answer);
1071 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001073 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001074 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001075 ASSERT_TRUE(answer);
1076 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1078 }
1079
Seth Hampson845e8782018-03-02 11:34:10 -08001080 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001081 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001082 // called with the given stream id and expected number of tracks.
1083 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001084 int expected_num_tracks) {
1085 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001086 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001087 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001088 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 }
1090
1091 // Creates an offer and applies it as a local session description.
1092 // Creates an answer with the same SDP an the offer but removes all lines
1093 // that start with a:ssrc"
1094 void CreateOfferReceiveAnswerWithoutSsrc() {
1095 CreateOfferAsLocalDescription();
1096 std::string sdp;
1097 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1098 SetSsrcToZero(&sdp);
1099 CreateAnswerAsRemoteDescription(sdp);
1100 }
1101
deadbeefab9b2d12015-10-14 11:33:11 -07001102 // This function creates a MediaStream with label kStreams[0] and
1103 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1104 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001105 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001106 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001107 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001108 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1109 size_t number_of_video_tracks) {
1110 EXPECT_LE(number_of_audio_tracks, 2u);
1111 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001112
1113 reference_collection_ = StreamCollection::Create();
1114 std::string sdp_ms1 = std::string(kSdpStringInit);
1115
Seth Hampson845e8782018-03-02 11:34:10 -08001116 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001117
1118 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001119 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001120 reference_collection_->AddStream(stream);
1121
1122 if (number_of_audio_tracks > 0) {
1123 sdp_ms1 += std::string(kSdpStringAudio);
1124 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1125 AddAudioTrack(kAudioTracks[0], stream);
1126 }
1127 if (number_of_audio_tracks > 1) {
1128 sdp_ms1 += kSdpStringMs1Audio1;
1129 AddAudioTrack(kAudioTracks[1], stream);
1130 }
1131
1132 if (number_of_video_tracks > 0) {
1133 sdp_ms1 += std::string(kSdpStringVideo);
1134 sdp_ms1 += std::string(kSdpStringMs1Video0);
1135 AddVideoTrack(kVideoTracks[0], stream);
1136 }
1137 if (number_of_video_tracks > 1) {
1138 sdp_ms1 += kSdpStringMs1Video1;
1139 AddVideoTrack(kVideoTracks[1], stream);
1140 }
1141
kwibergd1fe2812016-04-27 06:47:29 -07001142 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001143 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001144 }
1145
1146 void AddAudioTrack(const std::string& track_id,
1147 MediaStreamInterface* stream) {
1148 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1149 webrtc::AudioTrack::Create(track_id, nullptr));
1150 ASSERT_TRUE(stream->AddTrack(audio_track));
1151 }
1152
1153 void AddVideoTrack(const std::string& track_id,
1154 MediaStreamInterface* stream) {
1155 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001156 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001157 webrtc::FakeVideoTrackSource::Create(),
1158 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001159 ASSERT_TRUE(stream->AddTrack(video_track));
1160 }
1161
Steve Anton36da6ff2018-02-16 16:04:20 -08001162 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001163 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001164 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001165 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001166 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1167 return offer;
1168 }
1169
Steve Anton36da6ff2018-02-16 16:04:20 -08001170 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1171 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001172 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001173 std::unique_ptr<SessionDescriptionInterface> offer;
1174 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1175 return offer;
1176 }
1177
1178 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1179 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1180 std::unique_ptr<SessionDescriptionInterface> answer;
1181 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1182 return answer;
1183 }
1184
kwibergfd8be342016-05-14 19:44:11 -07001185 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001186 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001187 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001188 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001189 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1190 return answer;
1191 }
1192
1193 const std::string& GetFirstAudioStreamCname(
1194 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001195 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001196 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001197 return audio_desc->streams()[0].cname;
1198 }
1199
zhihuang1c378ed2017-08-17 14:10:50 -07001200 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1201 const RTCOfferAnswerOptions& offer_answer_options) {
1202 RTC_DCHECK(pc_);
1203 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1204 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1205 pc_->CreateOffer(observer, offer_answer_options);
1206 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1207 return observer->MoveDescription();
1208 }
1209
1210 void CreateOfferWithOptionsAsRemoteDescription(
1211 std::unique_ptr<SessionDescriptionInterface>* desc,
1212 const RTCOfferAnswerOptions& offer_answer_options) {
1213 *desc = CreateOfferWithOptions(offer_answer_options);
1214 ASSERT_TRUE(desc != nullptr);
1215 std::string sdp;
1216 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001217 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001218 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001219 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001220 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1221 }
1222
1223 void CreateOfferWithOptionsAsLocalDescription(
1224 std::unique_ptr<SessionDescriptionInterface>* desc,
1225 const RTCOfferAnswerOptions& offer_answer_options) {
1226 *desc = CreateOfferWithOptions(offer_answer_options);
1227 ASSERT_TRUE(desc != nullptr);
1228 std::string sdp;
1229 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001230 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001231 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001232
Steve Antondb45ca82017-09-11 18:27:34 -07001233 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001234 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1235 }
1236
1237 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001238 RTC_DCHECK(content);
1239 RTC_DCHECK(content->media_description());
1240 for (const cricket::AudioCodec& codec :
1241 content->media_description()->as_audio()->codecs()) {
1242 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001243 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001244 }
zhihuang1c378ed2017-08-17 14:10:50 -07001245 }
1246 return false;
1247 }
1248
Steve Anton36da6ff2018-02-16 16:04:20 -08001249 const char* GetSdpStringWithStream1() const {
1250 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1251 return kSdpStringWithStream1PlanB;
1252 } else {
1253 return kSdpStringWithStream1UnifiedPlan;
1254 }
1255 }
1256
1257 const char* GetSdpStringWithStream1And2() const {
1258 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1259 return kSdpStringWithStream1And2PlanB;
1260 } else {
1261 return kSdpStringWithStream1And2UnifiedPlan;
1262 }
1263 }
1264
deadbeef9a6f4d42017-05-15 19:43:33 -07001265 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1266 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001267 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001268 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001269 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001270 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1271 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1272 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001274 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001275 const SdpSemantics sdp_semantics_;
1276};
1277
1278class PeerConnectionInterfaceTest
1279 : public PeerConnectionInterfaceBaseTest,
1280 public ::testing::WithParamInterface<SdpSemantics> {
1281 protected:
1282 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1283};
1284
1285class PeerConnectionInterfaceTestPlanB
1286 : public PeerConnectionInterfaceBaseTest {
1287 protected:
1288 PeerConnectionInterfaceTestPlanB()
1289 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290};
1291
zhihuang8f65cdf2016-05-06 18:40:30 -07001292// Generate different CNAMEs when PeerConnections are created.
1293// The CNAMEs are expected to be generated randomly. It is possible
1294// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001295TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001296 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001297 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001298 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001299 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001300 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1301 GetFirstAudioStreamCname(offer2.get()));
1302}
1303
Steve Anton36da6ff2018-02-16 16:04:20 -08001304TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001305 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001306 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001307 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001308 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001309 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1310 GetFirstAudioStreamCname(answer2.get()));
1311}
1312
Steve Anton36da6ff2018-02-16 16:04:20 -08001313TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 CreatePeerConnectionWithDifferentConfigurations) {
1315 CreatePeerConnectionWithDifferentConfigurations();
1316}
1317
Steve Anton36da6ff2018-02-16 16:04:20 -08001318TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001319 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1320 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1321 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1322 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1323 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1324 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1325 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1326 port_allocator_->candidate_filter());
1327 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1328 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1329}
1330
1331// Test that when a PeerConnection is created with a nonzero candidate pool
1332// size, the pooled PortAllocatorSession is created with all the attributes
1333// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001334TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001335 PeerConnectionInterface::RTCConfiguration config;
1336 PeerConnectionInterface::IceServer server;
1337 server.uri = kStunAddressOnly;
1338 config.servers.push_back(server);
1339 config.type = PeerConnectionInterface::kRelay;
1340 config.disable_ipv6 = true;
1341 config.tcp_candidate_policy =
1342 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001343 config.candidate_network_policy =
1344 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001345 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001346 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001347
1348 const cricket::FakePortAllocatorSession* session =
1349 static_cast<const cricket::FakePortAllocatorSession*>(
1350 port_allocator_->GetPooledSession());
1351 ASSERT_NE(nullptr, session);
1352 EXPECT_EQ(1UL, session->stun_servers().size());
1353 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1354 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001355 EXPECT_LT(0U,
1356 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001357}
1358
deadbeefd21eab32017-07-26 16:50:11 -07001359// Test that network-related RTCConfiguration members are applied to the
1360// PortAllocator when CreatePeerConnection is called. Specifically:
1361// - disable_ipv6_on_wifi
1362// - max_ipv6_networks
1363// - tcp_candidate_policy
1364// - candidate_network_policy
1365// - prune_turn_ports
1366//
1367// Note that the candidate filter (RTCConfiguration::type) is already tested
1368// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001369TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001370 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1371 // Create fake port allocator.
1372 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1373 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1374 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1375
1376 // Create RTCConfiguration with some network-related fields relevant to
1377 // PortAllocator populated.
1378 PeerConnectionInterface::RTCConfiguration config;
1379 config.disable_ipv6_on_wifi = true;
1380 config.max_ipv6_networks = 10;
1381 config.tcp_candidate_policy =
1382 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1383 config.candidate_network_policy =
1384 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1385 config.prune_turn_ports = true;
1386
1387 // Create the PC factory and PC with the above config.
1388 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1389 webrtc::CreatePeerConnectionFactory(
1390 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001391 rtc::Thread::Current(), fake_audio_capture_module_,
1392 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001393 webrtc::CreateBuiltinAudioDecoderFactory(),
1394 webrtc::CreateBuiltinVideoEncoderFactory(),
1395 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1396 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001397 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001398 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1399 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001400 EXPECT_TRUE(pc.get());
1401 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001402
1403 // Now validate that the config fields set above were applied to the
1404 // PortAllocator, as flags or otherwise.
1405 EXPECT_FALSE(raw_port_allocator->flags() &
1406 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1407 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1408 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1409 EXPECT_TRUE(raw_port_allocator->flags() &
1410 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1411 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1412}
1413
deadbeef46c73892016-11-16 19:42:04 -08001414// Check that GetConfiguration returns the configuration the PeerConnection was
1415// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001416TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001417 PeerConnectionInterface::RTCConfiguration config;
1418 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001419 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001420
1421 PeerConnectionInterface::RTCConfiguration returned_config =
1422 pc_->GetConfiguration();
1423 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1424}
1425
1426// Check that GetConfiguration returns the last configuration passed into
1427// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001428TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001429 PeerConnectionInterface::RTCConfiguration starting_config;
1430 starting_config.bundle_policy =
1431 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1432 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001433
Steve Anton36da6ff2018-02-16 16:04:20 -08001434 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001435 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001436 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001437 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001438 EXPECT_TRUE(pc_->SetConfiguration(config));
1439
1440 PeerConnectionInterface::RTCConfiguration returned_config =
1441 pc_->GetConfiguration();
1442 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001443 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001444 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001445}
1446
Steve Antonc79268f2018-04-24 09:54:10 -07001447TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1448 CreatePeerConnection();
1449
1450 pc_->Close();
1451
1452 EXPECT_FALSE(
1453 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1454}
1455
Steve Anton36da6ff2018-02-16 16:04:20 -08001456TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001457 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001458 AddVideoStream(kStreamId1);
1459 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 ASSERT_EQ(2u, pc_->local_streams()->count());
1461
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001462 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001463 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001464 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001465 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001466 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001467 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001469 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001470 EXPECT_EQ(3u, pc_->local_streams()->count());
1471
1472 // Remove the third stream.
1473 pc_->RemoveStream(pc_->local_streams()->at(2));
1474 EXPECT_EQ(2u, pc_->local_streams()->count());
1475
1476 // Remove the second stream.
1477 pc_->RemoveStream(pc_->local_streams()->at(1));
1478 EXPECT_EQ(1u, pc_->local_streams()->count());
1479
1480 // Remove the first stream.
1481 pc_->RemoveStream(pc_->local_streams()->at(0));
1482 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483}
1484
deadbeefab9b2d12015-10-14 11:33:11 -07001485// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001486// Don't run under Unified Plan since the stream API is not available.
1487TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001488 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001489 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001490 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001491 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001492
deadbeefab9b2d12015-10-14 11:33:11 -07001493 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001494 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001495 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001496
deadbeefab9b2d12015-10-14 11:33:11 -07001497 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001498 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001499 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001500
1501 // Add another stream and ensure the offer includes both the old and new
1502 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001503 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001504 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001505
Steve Antonb1c1de12017-12-21 15:14:30 -08001506 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001507 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1508 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001509
Steve Antonb1c1de12017-12-21 15:14:30 -08001510 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001511 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1512 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001513}
1514
Steve Anton36da6ff2018-02-16 16:04:20 -08001515// Don't run under Unified Plan since the stream API is not available.
1516TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001517 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001518 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 ASSERT_EQ(1u, pc_->local_streams()->count());
1520 pc_->RemoveStream(pc_->local_streams()->at(0));
1521 EXPECT_EQ(0u, pc_->local_streams()->count());
1522}
1523
deadbeefe1f9d832016-01-14 15:35:42 -08001524// Test for AddTrack and RemoveTrack methods.
1525// Tests that the created offer includes tracks we added,
1526// and that the RtpSenders are created correctly.
1527// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001528// Only tested with Plan B since Unified Plan is covered in more detail by tests
1529// in peerconnection_jsep_unittests.cc
1530TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001531 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001532 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001533 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001534 rtc::scoped_refptr<VideoTrackInterface> video_track(
1535 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001536 "video_track", pc_factory_->CreateVideoSource(
1537 std::unique_ptr<cricket::VideoCapturer>(
1538 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001539 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1540 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001541 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001542 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001543 EXPECT_EQ("audio_track", audio_sender->id());
1544 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001545 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001546 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001547 EXPECT_EQ("video_track", video_sender->id());
1548 EXPECT_EQ(video_track, video_sender->track());
1549
1550 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001551 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001552 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001553
1554 const cricket::ContentInfo* audio_content =
1555 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001556 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001557 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001558
1559 const cricket::ContentInfo* video_content =
1560 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001561 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001562 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001563
Steve Antondb45ca82017-09-11 18:27:34 -07001564 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
1566 // Now try removing the tracks.
1567 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1568 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1569
1570 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001571 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001572
1573 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001574 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001575 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001576
1577 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001578 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001579 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001580
Steve Antondb45ca82017-09-11 18:27:34 -07001581 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001582
1583 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1584 // should return false.
1585 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1586 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1587}
1588
1589// Test creating senders without a stream specified,
1590// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001591TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001592 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001593 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001594 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001595 rtc::scoped_refptr<VideoTrackInterface> video_track(
1596 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001597 "video_track", pc_factory_->CreateVideoSource(
1598 std::unique_ptr<cricket::VideoCapturer>(
1599 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001600 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001601 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001602 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001603 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001604 EXPECT_EQ("audio_track", audio_sender->id());
1605 EXPECT_EQ(audio_track, audio_sender->track());
1606 EXPECT_EQ("video_track", video_sender->id());
1607 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001608 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1609 // If the ID is truly a random GUID, it should be infinitely unlikely they
1610 // will be the same.
1611 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1612 } else {
1613 // We allows creating tracks without stream ids under Unified Plan
1614 // semantics.
1615 EXPECT_EQ(0u, video_sender->stream_ids().size());
1616 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1617 }
deadbeefe1f9d832016-01-14 15:35:42 -08001618}
1619
Harald Alvestrand89061872018-01-02 14:08:34 +01001620// Test that we can call GetStats() after AddTrack but before connecting
1621// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001622TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001623 CreatePeerConnectionWithoutDtls();
1624 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1625 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1626 rtc::scoped_refptr<VideoTrackInterface> video_track(
1627 pc_factory_->CreateVideoTrack(
1628 "video_track", pc_factory_->CreateVideoSource(
1629 std::unique_ptr<cricket::VideoCapturer>(
1630 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001631 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1632 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001633 EXPECT_TRUE(DoGetStats(nullptr));
1634}
1635
Steve Anton36da6ff2018-02-16 16:04:20 -08001636TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001637 CreatePeerConnectionWithoutDtls();
1638 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1639 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1640 rtc::scoped_refptr<VideoTrackInterface> video_track(
1641 pc_factory_->CreateVideoTrack(
1642 "video_track", pc_factory_->CreateVideoSource(
1643 std::unique_ptr<cricket::VideoCapturer>(
1644 new cricket::FakeVideoCapturer()))));
1645 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001646 ASSERT_TRUE(audio_sender.ok());
1647 auto* audio_sender_proxy =
1648 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1649 audio_sender.value().get());
1650 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1651
Harald Alvestrandc72af932018-01-11 17:18:19 +01001652 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001653 ASSERT_TRUE(video_sender.ok());
1654 auto* video_sender_proxy =
1655 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1656 video_sender.value().get());
1657 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001658}
1659
Steve Anton36da6ff2018-02-16 16:04:20 -08001660// Don't run under Unified Plan since the stream API is not available.
1661TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001662 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001663 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001664 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001665 ASSERT_EQ(1u, senders.size());
1666 auto* sender_proxy =
1667 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1668 senders[0].get());
1669 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001670}
1671
Steve Anton36da6ff2018-02-16 16:04:20 -08001672TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001674 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 VerifyRemoteRtpHeaderExtensions();
1676}
1677
Steve Anton36da6ff2018-02-16 16:04:20 -08001678TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001679 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001680 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 CreateOfferAsLocalDescription();
1682 std::string offer;
1683 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1684 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001685 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686}
1687
Steve Anton36da6ff2018-02-16 16:04:20 -08001688TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001689 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001690 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691
1692 CreateOfferAsRemoteDescription();
1693 CreateAnswerAsLocalDescription();
1694
Seth Hampson845e8782018-03-02 11:34:10 -08001695 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696}
1697
Steve Anton36da6ff2018-02-16 16:04:20 -08001698TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001699 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001700 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701
1702 CreateOfferAsRemoteDescription();
1703 CreatePrAnswerAsLocalDescription();
1704 CreateAnswerAsLocalDescription();
1705
Seth Hampson845e8782018-03-02 11:34:10 -08001706 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707}
1708
Steve Anton36da6ff2018-02-16 16:04:20 -08001709// Don't run under Unified Plan since the stream API is not available.
1710TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 InitiateCall();
1712 ASSERT_EQ(1u, pc_->remote_streams()->count());
1713 pc_->RemoveStream(pc_->local_streams()->at(0));
1714 CreateOfferReceiveAnswer();
1715 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001716 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 CreateOfferReceiveAnswer();
1718}
1719
1720// Tests that after negotiating an audio only call, the respondent can perform a
1721// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001722TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001723 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001724 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 CreateOfferAsRemoteDescription();
1726 CreateAnswerAsLocalDescription();
1727
1728 ASSERT_EQ(1u, pc_->remote_streams()->count());
1729 pc_->RemoveStream(pc_->local_streams()->at(0));
1730 CreateOfferReceiveAnswer();
1731 EXPECT_EQ(0u, pc_->remote_streams()->count());
1732}
1733
1734// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001735TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001736 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737
Steve Antonf1c6db12017-10-13 11:13:35 -07001738 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001740 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001741 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001742 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001743 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
1745 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001746 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001747 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001748 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749
Steve Antonf1c6db12017-10-13 11:13:35 -07001750 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001751 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752
Steve Antonf1c6db12017-10-13 11:13:35 -07001753 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754}
1755
deadbeefab9b2d12015-10-14 11:33:11 -07001756// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001758TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001759 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001761 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001762 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001763 EXPECT_TRUE(offer);
1764 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765
1766 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001767 AddAudioTrack("track_label", {kStreamId1});
1768 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769
1770 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001771 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772
1773 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001774 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001775 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776}
1777
1778// Test that we will get different SSRCs for each tracks in the offer and answer
1779// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001780TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001781 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001783 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1784 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785
1786 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001787 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001788 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 int audio_ssrc = 0;
1790 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001791 EXPECT_TRUE(
1792 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1793 EXPECT_TRUE(
1794 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 EXPECT_NE(audio_ssrc, video_ssrc);
1796
1797 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001798 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001799 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001800 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 audio_ssrc = 0;
1802 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001803 EXPECT_TRUE(
1804 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1805 EXPECT_TRUE(
1806 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 EXPECT_NE(audio_ssrc, video_ssrc);
1808}
1809
deadbeefeb459812015-12-15 19:24:43 -08001810// Test that it's possible to call AddTrack on a MediaStream after adding
1811// the stream to a PeerConnection.
1812// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001813// Don't run under Unified Plan since the stream API is not available.
1814TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001815 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001816 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001817 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001818 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1819
1820 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001821 rtc::scoped_refptr<VideoTrackInterface> video_track(
1822 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001823 "video_label", pc_factory_->CreateVideoSource(
1824 std::unique_ptr<cricket::VideoCapturer>(
1825 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001826 stream->AddTrack(video_track.get());
1827
kwibergd1fe2812016-04-27 06:47:29 -07001828 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001829 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001830
1831 const cricket::MediaContentDescription* video_desc =
1832 cricket::GetFirstVideoContentDescription(offer->description());
1833 EXPECT_TRUE(video_desc != nullptr);
1834}
1835
1836// Test that it's possible to call RemoveTrack on a MediaStream after adding
1837// the stream to a PeerConnection.
1838// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001839// Don't run under Unified Plan since the stream API is not available.
1840TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001841 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001842 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001843 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001844 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1845
1846 // Remove the video track.
1847 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1848
kwibergd1fe2812016-04-27 06:47:29 -07001849 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001850 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001851
1852 const cricket::MediaContentDescription* video_desc =
1853 cricket::GetFirstVideoContentDescription(offer->description());
1854 EXPECT_TRUE(video_desc == nullptr);
1855}
1856
deadbeefbd7d8f72015-12-18 16:58:44 -08001857// Test creating a sender with a stream ID, and ensure the ID is populated
1858// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001859// Don't run under Unified Plan since the stream API is not available.
1860TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001861 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001862 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001863
kwibergd1fe2812016-04-27 06:47:29 -07001864 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001865 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001866
1867 const cricket::MediaContentDescription* video_desc =
1868 cricket::GetFirstVideoContentDescription(offer->description());
1869 ASSERT_TRUE(video_desc != nullptr);
1870 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001871 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001872}
1873
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001875TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001877 ASSERT_LT(0u, pc_->GetSenders().size());
1878 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001879 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001880 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 EXPECT_TRUE(DoGetStats(remote_audio));
1882
1883 // Remove the stream. Since we are sending to our selves the local
1884 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001885 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 // Do a re-negotiation.
1887 CreateOfferReceiveAnswer();
1888
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 // Test that we still can get statistics for the old track. Even if it is not
1890 // sent any longer.
1891 EXPECT_TRUE(DoGetStats(remote_audio));
1892}
1893
1894// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001895TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001897 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1898 ASSERT_TRUE(video_receiver);
1899 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900}
1901
1902// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001903TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001905 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 pc_factory_->CreateAudioTrack("unknown track", NULL));
1907 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1908}
1909
Steve Anton36da6ff2018-02-16 16:04:20 -08001910TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001911 CreatePeerConnectionWithoutDtls();
1912 EXPECT_TRUE(DoGetRTCStats());
1913 // Clearing stats cache is needed now, but should be temporary.
1914 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1915 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001916 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1917 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001918 EXPECT_TRUE(DoGetRTCStats());
1919 pc_->ClearStatsCache();
1920 CreateOfferReceiveAnswer();
1921 EXPECT_TRUE(DoGetRTCStats());
1922}
1923
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001925TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001926 RTCConfiguration config;
1927 config.enable_rtp_data_channel = true;
1928 config.enable_dtls_srtp = false;
1929 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001930 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001932 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 pc_->CreateDataChannel("test2", NULL);
1934 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001935 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001937 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 new MockDataChannelObserver(data2));
1939
1940 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1941 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1942 std::string data_to_send1 = "testing testing";
1943 std::string data_to_send2 = "testing something else";
1944 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1945
1946 CreateOfferReceiveAnswer();
1947 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1948 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1949
1950 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1951 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1952 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1953 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1954
1955 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1956 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1957
1958 data1->Close();
1959 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1960 CreateOfferReceiveAnswer();
1961 EXPECT_FALSE(observer1->IsOpen());
1962 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1963 EXPECT_TRUE(observer2->IsOpen());
1964
1965 data_to_send2 = "testing something else again";
1966 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1967
1968 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1969}
1970
1971// This test verifies that sendnig binary data over RTP data channels should
1972// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001973TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001974 RTCConfiguration config;
1975 config.enable_rtp_data_channel = true;
1976 config.enable_dtls_srtp = false;
1977 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001978 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001980 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 pc_->CreateDataChannel("test2", NULL);
1982 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001983 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001985 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 new MockDataChannelObserver(data2));
1987
1988 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1989 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1990
1991 CreateOfferReceiveAnswer();
1992 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1993 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1994
1995 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1996 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1997
jbaucheec21bd2016-03-20 06:15:43 -07001998 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2000}
2001
2002// This test setup a RTP data channels in loop back and test that a channel is
2003// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002004TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002005 RTCConfiguration config;
2006 config.enable_rtp_data_channel = true;
2007 config.enable_dtls_srtp = false;
2008 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07002009 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002011 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 new MockDataChannelObserver(data1));
2013
2014 CreateOfferReceiveAnswerWithoutSsrc();
2015
2016 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2017
2018 data1->Close();
2019 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2020 CreateOfferReceiveAnswerWithoutSsrc();
2021 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2022 EXPECT_FALSE(observer1->IsOpen());
2023}
2024
2025// This test that if a data channel is added in an answer a receive only channel
2026// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002027TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002028 RTCConfiguration config;
2029 config.enable_rtp_data_channel = true;
2030 config.enable_dtls_srtp = false;
2031
2032 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033
2034 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002035 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 pc_->CreateDataChannel(offer_label, NULL);
2037
2038 CreateOfferAsLocalDescription();
2039
2040 // Replace the data channel label in the offer and apply it as an answer.
2041 std::string receive_label = "answer_channel";
2042 std::string sdp;
2043 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002044 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002045 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 CreateAnswerAsRemoteDescription(sdp);
2047
2048 // Verify that a new incoming data channel has been created and that
2049 // it is open but can't we written to.
2050 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2051 DataChannelInterface* received_channel = observer_.last_datachannel_;
2052 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2053 EXPECT_EQ(receive_label, received_channel->label());
2054 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2055
2056 // Verify that the channel we initially offered has been rejected.
2057 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2058
2059 // Do another offer / answer exchange and verify that the data channel is
2060 // opened.
2061 CreateOfferReceiveAnswer();
2062 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2063 kTimeout);
2064}
2065
2066// This test that no data channel is returned if a reliable channel is
2067// requested.
2068// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002069TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002070 RTCConfiguration rtc_config;
2071 rtc_config.enable_rtp_data_channel = true;
2072 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073
2074 std::string label = "test";
2075 webrtc::DataChannelInit config;
2076 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002077 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 pc_->CreateDataChannel(label, &config);
2079 EXPECT_TRUE(channel == NULL);
2080}
2081
deadbeefab9b2d12015-10-14 11:33:11 -07002082// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002083TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002084 RTCConfiguration config;
2085 config.enable_rtp_data_channel = true;
2086 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002087
2088 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002089 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002090 pc_->CreateDataChannel(label, nullptr);
2091 EXPECT_NE(channel, nullptr);
2092
zhihuang9763d562016-08-05 11:14:50 -07002093 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002094 pc_->CreateDataChannel(label, nullptr);
2095 EXPECT_EQ(dup_channel, nullptr);
2096}
2097
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098// This tests that a SCTP data channel is returned using different
2099// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002100TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002101 RTCConfiguration rtc_config;
2102 rtc_config.enable_dtls_srtp = true;
2103 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
2105 webrtc::DataChannelInit config;
2106
zhihuang9763d562016-08-05 11:14:50 -07002107 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 pc_->CreateDataChannel("1", &config);
2109 EXPECT_TRUE(channel != NULL);
2110 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002111 EXPECT_TRUE(observer_.renegotiation_needed_);
2112 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113
2114 config.ordered = false;
2115 channel = pc_->CreateDataChannel("2", &config);
2116 EXPECT_TRUE(channel != NULL);
2117 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002118 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119
2120 config.ordered = true;
2121 config.maxRetransmits = 0;
2122 channel = pc_->CreateDataChannel("3", &config);
2123 EXPECT_TRUE(channel != NULL);
2124 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002125 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126
2127 config.maxRetransmits = -1;
2128 config.maxRetransmitTime = 0;
2129 channel = pc_->CreateDataChannel("4", &config);
2130 EXPECT_TRUE(channel != NULL);
2131 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002132 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133}
2134
2135// This tests that no data channel is returned if both maxRetransmits and
2136// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002137TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002139 RTCConfiguration rtc_config;
2140 rtc_config.enable_dtls_srtp = true;
2141 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142
2143 std::string label = "test";
2144 webrtc::DataChannelInit config;
2145 config.maxRetransmits = 0;
2146 config.maxRetransmitTime = 0;
2147
zhihuang9763d562016-08-05 11:14:50 -07002148 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 pc_->CreateDataChannel(label, &config);
2150 EXPECT_TRUE(channel == NULL);
2151}
2152
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153// The test verifies that creating a SCTP data channel with an id already in use
2154// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002155TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002157 RTCConfiguration rtc_config;
2158 rtc_config.enable_dtls_srtp = true;
2159 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160
2161 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002162 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002164 config.id = 1;
2165 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 EXPECT_TRUE(channel != NULL);
2167 EXPECT_EQ(1, channel->id());
2168
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 channel = pc_->CreateDataChannel("x", &config);
2170 EXPECT_TRUE(channel == NULL);
2171
2172 config.id = cricket::kMaxSctpSid;
2173 channel = pc_->CreateDataChannel("max", &config);
2174 EXPECT_TRUE(channel != NULL);
2175 EXPECT_EQ(config.id, channel->id());
2176
2177 config.id = cricket::kMaxSctpSid + 1;
2178 channel = pc_->CreateDataChannel("x", &config);
2179 EXPECT_TRUE(channel == NULL);
2180}
2181
deadbeefab9b2d12015-10-14 11:33:11 -07002182// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002183TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002184 RTCConfiguration rtc_config;
2185 rtc_config.enable_dtls_srtp = true;
2186 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002187
2188 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002189 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002190 pc_->CreateDataChannel(label, nullptr);
2191 EXPECT_NE(channel, nullptr);
2192
zhihuang9763d562016-08-05 11:14:50 -07002193 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002194 pc_->CreateDataChannel(label, nullptr);
2195 EXPECT_NE(dup_channel, nullptr);
2196}
2197
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002198// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2199// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002200TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002201 RTCConfiguration rtc_config;
2202 rtc_config.enable_rtp_data_channel = true;
2203 rtc_config.enable_dtls_srtp = false;
2204 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002205
zhihuang9763d562016-08-05 11:14:50 -07002206 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002207 pc_->CreateDataChannel("test1", NULL);
2208 EXPECT_TRUE(observer_.renegotiation_needed_);
2209 observer_.renegotiation_needed_ = false;
2210
zhihuang9763d562016-08-05 11:14:50 -07002211 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002212 pc_->CreateDataChannel("test2", NULL);
2213 EXPECT_TRUE(observer_.renegotiation_needed_);
2214}
2215
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002217TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002218 RTCConfiguration rtc_config;
2219 rtc_config.enable_rtp_data_channel = true;
2220 rtc_config.enable_dtls_srtp = false;
2221 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222
zhihuang9763d562016-08-05 11:14:50 -07002223 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002225 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 pc_->CreateDataChannel("test2", NULL);
2227 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002228 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002230 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 new MockDataChannelObserver(data2));
2232
2233 CreateOfferReceiveAnswer();
2234 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2235 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2236
2237 ReleasePeerConnection();
2238 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2239 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2240}
2241
Zhi Huang644fde42018-04-02 19:16:26 -07002242// This tests that RTP data channels can be rejected in an answer.
2243TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002244 RTCConfiguration rtc_config;
2245 rtc_config.enable_rtp_data_channel = true;
2246 rtc_config.enable_dtls_srtp = false;
2247 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248
zhihuang9763d562016-08-05 11:14:50 -07002249 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 pc_->CreateDataChannel("offer_channel", NULL));
2251
2252 CreateOfferAsLocalDescription();
2253
2254 // Create an answer where the m-line for data channels are rejected.
2255 std::string sdp;
2256 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002257 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002258 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002259 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002261 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 data_info->rejected = true;
2263
Steve Antondb45ca82017-09-11 18:27:34 -07002264 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2266}
2267
Zhi Huang644fde42018-04-02 19:16:26 -07002268#ifdef HAVE_SCTP
2269// This tests that SCTP data channels can be rejected in an answer.
2270TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2271#else
2272TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2273#endif
2274{
Niels Möllerf06f9232018-08-07 12:32:18 +02002275 RTCConfiguration rtc_config;
2276 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002277
2278 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2279 pc_->CreateDataChannel("offer_channel", NULL));
2280
2281 CreateOfferAsLocalDescription();
2282
2283 // Create an answer where the m-line for data channels are rejected.
2284 std::string sdp;
2285 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2286 std::unique_ptr<SessionDescriptionInterface> answer(
2287 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2288 ASSERT_TRUE(answer);
2289 cricket::ContentInfo* data_info =
2290 cricket::GetFirstDataContent(answer->description());
2291 data_info->rejected = true;
2292
2293 DoSetRemoteDescription(std::move(answer));
2294 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2295}
2296
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297// Test that we can create a session description from an SDP string from
2298// FireFox, use it as a remote session description, generate an answer and use
2299// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002300TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002301 RTCConfiguration rtc_config;
2302 rtc_config.enable_dtls_srtp = true;
2303 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002304 AddAudioTrack("audio_label");
2305 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002306 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002307 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002308 webrtc::kFireFoxSdpOffer, nullptr));
2309 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 CreateAnswerAsLocalDescription();
2311 ASSERT_TRUE(pc_->local_description() != NULL);
2312 ASSERT_TRUE(pc_->remote_description() != NULL);
2313
2314 const cricket::ContentInfo* content =
2315 cricket::GetFirstAudioContent(pc_->local_description()->description());
2316 ASSERT_TRUE(content != NULL);
2317 EXPECT_FALSE(content->rejected);
2318
2319 content =
2320 cricket::GetFirstVideoContent(pc_->local_description()->description());
2321 ASSERT_TRUE(content != NULL);
2322 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002323#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 content =
2325 cricket::GetFirstDataContent(pc_->local_description()->description());
2326 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002327 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002328#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329}
2330
zhihuangb19012e2017-09-19 13:47:59 -07002331// Test that fallback from DTLS to SDES is not supported.
2332// The fallback was previously supported but was removed to simplify the code
2333// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002334TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002335 RTCConfiguration rtc_config;
2336 rtc_config.enable_dtls_srtp = true;
2337 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002338 // Wait for fake certificate to be generated. Previously, this is what caused
2339 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002340 AddAudioTrack("audio_label");
2341 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002342 ASSERT_NE(nullptr, fake_certificate_generator_);
2343 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2344 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002345 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002346 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2347 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002348 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002349}
2350
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351// Test that we can create an audio only offer and receive an answer with a
2352// limited set of audio codecs and receive an updated offer with more audio
2353// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002354TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002355 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002356 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 CreateOfferAsLocalDescription();
2358
Steve Anton36da6ff2018-02-16 16:04:20 -08002359 const char* answer_sdp =
2360 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2361 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002362 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002363 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002364 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365
Steve Anton36da6ff2018-02-16 16:04:20 -08002366 const char* reoffer_sdp =
2367 (sdp_semantics_ == SdpSemantics::kPlanB
2368 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2369 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002370 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002371 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002372 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 CreateAnswerAsLocalDescription();
2374}
2375
deadbeefc80741f2015-10-22 13:14:45 -07002376// Test that if we're receiving (but not sending) a track, subsequent offers
2377// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002378TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002379 RTCConfiguration rtc_config;
2380 rtc_config.enable_dtls_srtp = true;
2381 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002382 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002383 CreateAnswerAsLocalDescription();
2384
2385 // At this point we should be receiving stream 1, but not sending anything.
2386 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002387 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002388 DoCreateOffer(&offer, nullptr);
2389
2390 const cricket::ContentInfo* video_content =
2391 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002392 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2393 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002394
2395 const cricket::ContentInfo* audio_content =
2396 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002397 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2398 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002399}
2400
2401// Test that if we're receiving (but not sending) a track, and the
2402// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2403// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002404TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002405 RTCConfiguration rtc_config;
2406 rtc_config.enable_dtls_srtp = true;
2407 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002408 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002409 CreateAnswerAsLocalDescription();
2410
2411 // At this point we should be receiving stream 1, but not sending anything.
2412 // A new offer would be recvonly, but we'll set the "no receive" constraints
2413 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002414 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002415 RTCOfferAnswerOptions options;
2416 options.offer_to_receive_audio = 0;
2417 options.offer_to_receive_video = 0;
2418 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002419
2420 const cricket::ContentInfo* video_content =
2421 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002422 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2423 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002424
2425 const cricket::ContentInfo* audio_content =
2426 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002427 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2428 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002429}
2430
deadbeef653b8e02015-11-11 12:55:10 -08002431// Test that we can use SetConfiguration to change the ICE servers of the
2432// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002433TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002434 CreatePeerConnection();
2435
Steve Anton36da6ff2018-02-16 16:04:20 -08002436 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002437 PeerConnectionInterface::IceServer server;
2438 server.uri = "stun:test_hostname";
2439 config.servers.push_back(server);
2440 EXPECT_TRUE(pc_->SetConfiguration(config));
2441
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002442 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2443 EXPECT_EQ("test_hostname",
2444 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002445}
2446
Steve Anton36da6ff2018-02-16 16:04:20 -08002447TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002448 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002449 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002450 config.type = PeerConnectionInterface::kRelay;
2451 EXPECT_TRUE(pc_->SetConfiguration(config));
2452 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2453}
2454
Steve Anton36da6ff2018-02-16 16:04:20 -08002455TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002456 PeerConnectionInterface::RTCConfiguration config;
2457 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002458 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002459 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002460 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2461
2462 config.prune_turn_ports = true;
2463 EXPECT_TRUE(pc_->SetConfiguration(config));
2464 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2465}
2466
skvladd1f5fda2017-02-03 16:54:05 -08002467// Test that the ice check interval can be changed. This does not verify that
2468// the setting makes it all the way to P2PTransportChannel, as that would
2469// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002470TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002471 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002472 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002473 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002474 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002475 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002476 EXPECT_TRUE(pc_->SetConfiguration(config));
2477 PeerConnectionInterface::RTCConfiguration new_config =
2478 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002479 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002480}
2481
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002482// Test that when SetConfiguration changes both the pool size and other
2483// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002484TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002485 SetConfigurationCreatesPooledSessionCorrectly) {
2486 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002487 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002488 config.ice_candidate_pool_size = 1;
2489 PeerConnectionInterface::IceServer server;
2490 server.uri = kStunAddressOnly;
2491 config.servers.push_back(server);
2492 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002493 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002494
2495 const cricket::FakePortAllocatorSession* session =
2496 static_cast<const cricket::FakePortAllocatorSession*>(
2497 port_allocator_->GetPooledSession());
2498 ASSERT_NE(nullptr, session);
2499 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002500}
2501
deadbeef293e9262017-01-11 12:28:30 -08002502// Test that after SetLocalDescription, changing the pool size is not allowed,
2503// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002504TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002505 CantChangePoolSizeAfterSetLocalDescription) {
2506 CreatePeerConnection();
2507 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002508 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002509 config.ice_candidate_pool_size = 1;
2510 EXPECT_TRUE(pc_->SetConfiguration(config));
2511
2512 // Set remote offer; can still change pool size at this point.
2513 CreateOfferAsRemoteDescription();
2514 config.ice_candidate_pool_size = 2;
2515 EXPECT_TRUE(pc_->SetConfiguration(config));
2516
2517 // Set local answer; now it's too late.
2518 CreateAnswerAsLocalDescription();
2519 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002520 RTCError error;
2521 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2522 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2523}
2524
deadbeef42a42632017-03-10 15:18:00 -08002525// Test that after setting an answer, extra pooled sessions are discarded. The
2526// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002527TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002528 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2529 CreatePeerConnection();
2530
2531 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002532 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002533 config.ice_candidate_pool_size = 4;
2534 EXPECT_TRUE(pc_->SetConfiguration(config));
2535
2536 // Do offer/answer.
2537 CreateOfferAsRemoteDescription();
2538 CreateAnswerAsLocalDescription();
2539
2540 // Expect no pooled sessions to be left.
2541 const cricket::PortAllocatorSession* session =
2542 port_allocator_->GetPooledSession();
2543 EXPECT_EQ(nullptr, session);
2544}
2545
2546// After Close is called, pooled candidates should be discarded so as to not
2547// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002548TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002549 CreatePeerConnection();
2550
Steve Anton36da6ff2018-02-16 16:04:20 -08002551 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002552 config.ice_candidate_pool_size = 3;
2553 EXPECT_TRUE(pc_->SetConfiguration(config));
2554 pc_->Close();
2555
2556 // Expect no pooled sessions to be left.
2557 const cricket::PortAllocatorSession* session =
2558 port_allocator_->GetPooledSession();
2559 EXPECT_EQ(nullptr, session);
2560}
2561
deadbeef293e9262017-01-11 12:28:30 -08002562// Test that SetConfiguration returns an invalid modification error if
2563// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002564TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002565 SetConfigurationReturnsInvalidModificationError) {
2566 PeerConnectionInterface::RTCConfiguration config;
2567 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2568 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2569 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002570 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002571
Steve Anton36da6ff2018-02-16 16:04:20 -08002572 PeerConnectionInterface::RTCConfiguration modified_config =
2573 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002574 modified_config.bundle_policy =
2575 PeerConnectionInterface::kBundlePolicyMaxBundle;
2576 RTCError error;
2577 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2578 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2579
Steve Anton36da6ff2018-02-16 16:04:20 -08002580 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002581 modified_config.rtcp_mux_policy =
2582 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2583 error.set_type(RTCErrorType::NONE);
2584 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2585 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2586
Steve Anton36da6ff2018-02-16 16:04:20 -08002587 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002588 modified_config.continual_gathering_policy =
2589 PeerConnectionInterface::GATHER_CONTINUALLY;
2590 error.set_type(RTCErrorType::NONE);
2591 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2592 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2593}
2594
2595// Test that SetConfiguration returns a range error if the candidate pool size
2596// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002597TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002598 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2599 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002600 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002601 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002602
2603 config.ice_candidate_pool_size = -1;
2604 RTCError error;
2605 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2606 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2607
2608 config.ice_candidate_pool_size = INT_MAX;
2609 error.set_type(RTCErrorType::NONE);
2610 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2611 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2612}
2613
2614// Test that SetConfiguration returns a syntax error if parsing an ICE server
2615// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002616TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002617 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2618 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002619 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002620 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002621
2622 PeerConnectionInterface::IceServer bad_server;
2623 bad_server.uri = "stunn:www.example.com";
2624 config.servers.push_back(bad_server);
2625 RTCError error;
2626 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2627 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2628}
2629
2630// Test that SetConfiguration returns an invalid parameter error if a TURN
2631// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002632TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002633 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2634 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002635 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002636 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002637
2638 PeerConnectionInterface::IceServer bad_server;
2639 bad_server.uri = "turn:www.example.com";
2640 // Missing password.
2641 bad_server.username = "foo";
2642 config.servers.push_back(bad_server);
2643 RTCError error;
2644 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2645 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002646}
2647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648// Test that PeerConnection::Close changes the states to closed and all remote
2649// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002650TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 // Initialize a PeerConnection and negotiate local and remote session
2652 // description.
2653 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002654
2655 // With Plan B, verify the stream count. The analog with Unified Plan is the
2656 // RtpTransceiver count.
2657 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2658 ASSERT_EQ(1u, pc_->local_streams()->count());
2659 ASSERT_EQ(1u, pc_->remote_streams()->count());
2660 } else {
2661 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2662 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663
2664 pc_->Close();
2665
2666 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2667 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2668 pc_->ice_connection_state());
2669 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2670 pc_->ice_gathering_state());
2671
Steve Anton36da6ff2018-02-16 16:04:20 -08002672 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2673 EXPECT_EQ(1u, pc_->local_streams()->count());
2674 EXPECT_EQ(1u, pc_->remote_streams()->count());
2675 } else {
2676 // Verify that the RtpTransceivers are still present but all stopped.
2677 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2678 for (auto transceiver : pc_->GetTransceivers()) {
2679 EXPECT_TRUE(transceiver->stopped());
2680 }
2681 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682
Steve Anton36da6ff2018-02-16 16:04:20 -08002683 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2684 ASSERT_TRUE(audio_receiver);
2685 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2686 ASSERT_TRUE(video_receiver);
2687
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002688 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002689 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002690 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002691 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002692 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693}
2694
2695// Test that PeerConnection methods fails gracefully after
2696// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002697// Don't run under Unified Plan since the stream API is not available.
2698TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002699 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002700 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701 CreateOfferAsRemoteDescription();
2702 CreateAnswerAsLocalDescription();
2703
2704 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002705 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 pc_->local_streams()->at(0);
2707
2708 pc_->Close();
2709
2710 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002711 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2714
2715 EXPECT_TRUE(pc_->local_description() != NULL);
2716 EXPECT_TRUE(pc_->remote_description() != NULL);
2717
kwibergd1fe2812016-04-27 06:47:29 -07002718 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002719 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002720 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002721 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722
2723 std::string sdp;
2724 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002725 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002726 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002727 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728
2729 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002730 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002731 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002732 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733}
2734
2735// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002736TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 InitiateCall();
2738 pc_->Close();
2739 DoGetStats(NULL);
2740}
deadbeefab9b2d12015-10-14 11:33:11 -07002741
2742// NOTE: The series of tests below come from what used to be
2743// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2744// setting a remote or local description has the expected effects.
2745
2746// This test verifies that the remote MediaStreams corresponding to a received
2747// SDP string is created. In this test the two separate MediaStreams are
2748// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002749TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002750 RTCConfiguration config;
2751 config.enable_dtls_srtp = true;
2752 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002753 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002754
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002755 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002756 EXPECT_TRUE(
2757 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2758 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2759 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2760
2761 // Create a session description based on another SDP with another
2762 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002763 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002764
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002765 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002766 EXPECT_TRUE(
2767 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2768}
2769
2770// This test verifies that when remote tracks are added/removed from SDP, the
2771// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002772// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2773// specific behavior.
2774TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002775 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002776 RTCConfiguration config;
2777 config.enable_dtls_srtp = true;
2778 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002779 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002780 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002781 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002782 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2783 reference_collection_));
2784
2785 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002786 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002787 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002788 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002789 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2790 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002791 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002792 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2793 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002794 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002795 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2796 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002797
2798 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002799 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002800 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002801 MockTrackObserver audio_track_observer(audio_track2);
2802 MockTrackObserver video_track_observer(video_track2);
2803
2804 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2805 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002806 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002807 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2808 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002809 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002810 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002811 audio_track2->state(), kTimeout);
2812 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2813 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002814}
2815
2816// This tests that remote tracks are ended if a local session description is set
2817// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002818TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002819 RTCConfiguration config;
2820 config.enable_dtls_srtp = true;
2821 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002822 // First create and set a remote offer, then reject its video content in our
2823 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002824 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2825 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2826 ASSERT_TRUE(audio_receiver);
2827 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2828 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002829
Steve Anton36da6ff2018-02-16 16:04:20 -08002830 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2831 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002832 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002833 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2834 video_receiver->track();
2835 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002836
kwibergd1fe2812016-04-27 06:47:29 -07002837 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002838 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002839 cricket::ContentInfo* video_info =
2840 local_answer->description()->GetContentByName("video");
2841 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002842 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002843 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2844 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002845
2846 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002847 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002848 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002849 video_info = local_offer->description()->GetContentByName("video");
2850 ASSERT_TRUE(video_info != nullptr);
2851 video_info->rejected = true;
2852 cricket::ContentInfo* audio_info =
2853 local_offer->description()->GetContentByName("audio");
2854 ASSERT_TRUE(audio_info != nullptr);
2855 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002856 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002857 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002858 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2859 kTimeout);
2860 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2861 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002862}
2863
2864// This tests that we won't crash if the remote track has been removed outside
2865// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002866// Don't run under Unified Plan since the stream API is not available.
2867TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002868 RTCConfiguration config;
2869 config.enable_dtls_srtp = true;
2870 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002871 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002872 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2873 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2874 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2875
kwibergd1fe2812016-04-27 06:47:29 -07002876 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002877 webrtc::CreateSessionDescription(SdpType::kAnswer,
2878 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002879 cricket::ContentInfo* video_info =
2880 local_answer->description()->GetContentByName("video");
2881 video_info->rejected = true;
2882 cricket::ContentInfo* audio_info =
2883 local_answer->description()->GetContentByName("audio");
2884 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002885 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002886
2887 // No crash is a pass.
2888}
2889
deadbeef5e97fb52015-10-15 12:49:08 -07002890// This tests that if a recvonly remote description is set, no remote streams
2891// will be created, even if the description contains SSRCs/MSIDs.
2892// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002893TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002894 RTCConfiguration config;
2895 config.enable_dtls_srtp = true;
2896 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002897
Steve Anton36da6ff2018-02-16 16:04:20 -08002898 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002899 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2900 strlen(kRecvonly), &recvonly_offer);
2901 CreateAndSetRemoteOffer(recvonly_offer);
2902
2903 EXPECT_EQ(0u, observer_.remote_streams()->count());
2904}
2905
deadbeefab9b2d12015-10-14 11:33:11 -07002906// This tests that a default MediaStream is created if a remote session
2907// description doesn't contain any streams and no MSID support.
2908// It also tests that the default stream is updated if a video m-line is added
2909// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002910// Don't run under Unified Plan since this behavior is Plan B specific.
2911TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002912 RTCConfiguration config;
2913 config.enable_dtls_srtp = true;
2914 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002915 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2916
2917 ASSERT_EQ(1u, observer_.remote_streams()->count());
2918 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2919
2920 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2921 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002922 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002923
2924 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2925 ASSERT_EQ(1u, observer_.remote_streams()->count());
2926 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2927 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002928 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2929 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002930 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2931 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002932 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2933 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002934}
2935
2936// This tests that a default MediaStream is created if a remote session
2937// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002938// Don't run under Unified Plan since this behavior is Plan B specific.
2939TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002940 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002941 RTCConfiguration config;
2942 config.enable_dtls_srtp = true;
2943 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002944 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2945
2946 ASSERT_EQ(1u, observer_.remote_streams()->count());
2947 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2948
2949 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2950 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002951 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002952}
2953
2954// This tests that it won't crash when PeerConnection tries to remove
2955// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002956// Don't run under Unified Plan since this behavior is Plan B specific.
2957TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002958 RTCConfiguration config;
2959 config.enable_dtls_srtp = true;
2960 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002961 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002962 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2963 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2964 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2965
2966 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2967
2968 // No crash is a pass.
2969}
2970
2971// This tests that a default MediaStream is created if the remote session
2972// description doesn't contain any streams and don't contain an indication if
2973// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002974// Don't run under Unified Plan since this behavior is Plan B specific.
2975TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002976 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002977 RTCConfiguration config;
2978 config.enable_dtls_srtp = true;
2979 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002980 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2981
2982 ASSERT_EQ(1u, observer_.remote_streams()->count());
2983 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2984 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2985 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2986}
2987
2988// This tests that a default MediaStream is not created if the remote session
2989// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002990// Don't run under Unified Plan since this behavior is Plan B specific.
2991TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002992 RTCConfiguration config;
2993 config.enable_dtls_srtp = true;
2994 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002995 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2996 EXPECT_EQ(0u, observer_.remote_streams()->count());
2997}
2998
deadbeefbda7e0b2015-12-08 17:13:40 -08002999// This tests that when setting a new description, the old default tracks are
3000// not destroyed and recreated.
3001// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003002// Don't run under Unified Plan since this behavior is Plan B specific.
3003TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003004 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003005 RTCConfiguration config;
3006 config.enable_dtls_srtp = true;
3007 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003008 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3009
3010 ASSERT_EQ(1u, observer_.remote_streams()->count());
3011 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3012 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3013
3014 // Set the track to "disabled", then set a new description and ensure the
3015 // track is still disabled, which ensures it hasn't been recreated.
3016 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3017 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3018 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3019 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3020}
3021
deadbeefab9b2d12015-10-14 11:33:11 -07003022// This tests that a default MediaStream is not created if a remote session
3023// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003024// Don't run under Unified Plan since this behavior is Plan B specific.
3025TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003026 RTCConfiguration config;
3027 config.enable_dtls_srtp = true;
3028 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003029 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003030 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003031 EXPECT_TRUE(
3032 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3033
3034 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3035 EXPECT_EQ(0u, observer_.remote_streams()->count());
3036}
3037
Seth Hampson5897a6e2018-04-03 11:16:33 -07003038// This tests that a default MediaStream is created if a remote SDP comes from
3039// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3040TEST_F(PeerConnectionInterfaceTestPlanB,
3041 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003042 RTCConfiguration config;
3043 config.enable_dtls_srtp = true;
3044 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003045 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3046 // Add a=msid lines to simulate a Unified Plan endpoint that only
3047 // signals stream IDs with a=msid lines.
3048 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3049
3050 CreateAndSetRemoteOffer(sdp_string);
3051
3052 ASSERT_EQ(1u, observer_.remote_streams()->count());
3053 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3054 EXPECT_EQ("default", remote_stream->id());
3055 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3056}
3057
Seth Hampson5b4f0752018-04-02 16:31:36 -07003058// This tests that when a Plan B endpoint receives an SDP that signals no media
3059// stream IDs indicated by the special character "-" in the a=msid line, that
3060// a default stream ID will be used for the MediaStream ID. This can occur
3061// when a Unified Plan endpoint signals no media stream IDs, but signals both
3062// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3063TEST_F(PeerConnectionInterfaceTestPlanB,
3064 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003065 RTCConfiguration config;
3066 config.enable_dtls_srtp = true;
3067 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003068 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3069 // the sender's stream ID will be interpreted as no stream IDs.
3070 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3071 sdp_string.append("a=msid:- audiotrack0\n");
3072
3073 CreateAndSetRemoteOffer(sdp_string);
3074
3075 ASSERT_EQ(1u, observer_.remote_streams()->count());
3076 // Because SSRCs are signaled the track ID will be what was signaled in the
3077 // a=msid line.
3078 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3079 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3080 EXPECT_EQ("default", remote_stream->id());
3081 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003082
3083 // Previously a bug ocurred when setting the remote description a second time.
3084 // This is because we checked equality of the remote StreamParams stream ID
3085 // (empty), and the previously set stream ID for the remote sender
3086 // ("default"). This cause a track to be removed, then added, when really
3087 // nothing should occur because it is the same track.
3088 CreateAndSetRemoteOffer(sdp_string);
3089 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3090 EXPECT_EQ(1u, observer_.add_track_events_.size());
3091 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3092 remote_stream = observer_.remote_streams()->at(0);
3093 EXPECT_EQ("default", remote_stream->id());
3094 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003095}
3096
deadbeefab9b2d12015-10-14 11:33:11 -07003097// This tests that an RtpSender is created when the local description is set
3098// after adding a local stream.
3099// TODO(deadbeef): This test and the one below it need to be updated when
3100// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003101// Don't run under Unified Plan since this behavior is Plan B specific.
3102TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003103 RTCConfiguration config;
3104 config.enable_dtls_srtp = true;
3105 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003106
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003107 // Create an offer with 1 stream with 2 tracks of each type.
3108 rtc::scoped_refptr<StreamCollection> stream_collection =
3109 CreateStreamCollection(1, 2);
3110 pc_->AddStream(stream_collection->at(0));
3111 std::unique_ptr<SessionDescriptionInterface> offer;
3112 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003113 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003114
deadbeefab9b2d12015-10-14 11:33:11 -07003115 auto senders = pc_->GetSenders();
3116 EXPECT_EQ(4u, senders.size());
3117 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3118 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3119 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3120 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3121
3122 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003123 pc_->RemoveStream(stream_collection->at(0));
3124 stream_collection = CreateStreamCollection(1, 1);
3125 pc_->AddStream(stream_collection->at(0));
3126 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003127 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003128
deadbeefab9b2d12015-10-14 11:33:11 -07003129 senders = pc_->GetSenders();
3130 EXPECT_EQ(2u, senders.size());
3131 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3132 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3133 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3134 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3135}
3136
3137// This tests that an RtpSender is created when the local description is set
3138// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003139// Don't run under Unified Plan since this behavior is Plan B specific.
3140TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003141 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003142 RTCConfiguration config;
3143 config.enable_dtls_srtp = true;
3144 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003145
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003146 rtc::scoped_refptr<StreamCollection> stream_collection =
3147 CreateStreamCollection(1, 2);
3148 // Add a stream to create the offer, but remove it afterwards.
3149 pc_->AddStream(stream_collection->at(0));
3150 std::unique_ptr<SessionDescriptionInterface> offer;
3151 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3152 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003153
Steve Antondb45ca82017-09-11 18:27:34 -07003154 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003155 auto senders = pc_->GetSenders();
3156 EXPECT_EQ(0u, senders.size());
3157
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003158 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003159 senders = pc_->GetSenders();
3160 EXPECT_EQ(4u, senders.size());
3161 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3162 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3163 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3164 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3165}
3166
3167// This tests that the expected behavior occurs if the SSRC on a local track is
3168// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003169TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003170 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003171 RTCConfiguration config;
3172 config.enable_dtls_srtp = true;
3173 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003174
Steve Anton36da6ff2018-02-16 16:04:20 -08003175 AddAudioTrack(kAudioTracks[0]);
3176 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003177 std::unique_ptr<SessionDescriptionInterface> offer;
3178 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3179 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003180 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3181 webrtc::CreateSessionDescription(
3182 webrtc::SdpType::kOffer, offer->session_id(),
3183 offer->session_version(),
3184 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003185 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003186
deadbeefab9b2d12015-10-14 11:33:11 -07003187 auto senders = pc_->GetSenders();
3188 EXPECT_EQ(2u, senders.size());
3189 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3190 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3191
3192 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003193 cricket::MediaContentDescription* desc =
3194 cricket::GetFirstAudioContentDescription(modified_offer->description());
3195 ASSERT_TRUE(desc != NULL);
3196 for (StreamParams& stream : desc->mutable_streams()) {
3197 for (unsigned int& ssrc : stream.ssrcs) {
3198 ++ssrc;
3199 }
3200 }
deadbeefab9b2d12015-10-14 11:33:11 -07003201
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003202 desc =
3203 cricket::GetFirstVideoContentDescription(modified_offer->description());
3204 ASSERT_TRUE(desc != NULL);
3205 for (StreamParams& stream : desc->mutable_streams()) {
3206 for (unsigned int& ssrc : stream.ssrcs) {
3207 ++ssrc;
3208 }
3209 }
3210
Steve Antondb45ca82017-09-11 18:27:34 -07003211 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003212 senders = pc_->GetSenders();
3213 EXPECT_EQ(2u, senders.size());
3214 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3215 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3216 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3217 // changed.
3218}
3219
3220// This tests that the expected behavior occurs if a new session description is
3221// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003222// Don't run under Unified Plan since the stream API is not available.
3223TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003224 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003225 RTCConfiguration config;
3226 config.enable_dtls_srtp = true;
3227 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003228
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003229 rtc::scoped_refptr<StreamCollection> stream_collection =
3230 CreateStreamCollection(2, 1);
3231 pc_->AddStream(stream_collection->at(0));
3232 std::unique_ptr<SessionDescriptionInterface> offer;
3233 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003234 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003235
deadbeefab9b2d12015-10-14 11:33:11 -07003236 auto senders = pc_->GetSenders();
3237 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003238 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3239 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003240
3241 // Add a new MediaStream but with the same tracks as in the first stream.
3242 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3243 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003244 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3245 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003246 pc_->AddStream(stream_1);
3247
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003248 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003249 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003250
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003251 auto new_senders = pc_->GetSenders();
3252 // Should be the same senders as before, but with updated stream id.
3253 // Note that this behavior is subject to change in the future.
3254 // We may decide the PC should ignore existing tracks in AddStream.
3255 EXPECT_EQ(senders, new_senders);
3256 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3257 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003258}
3259
zhihuang81c3a032016-11-17 12:06:24 -08003260// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003261TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003262 RTCConfiguration config;
3263 config.enable_dtls_srtp = true;
3264 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003265 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3266 EXPECT_EQ(observer_.num_added_tracks_, 1);
3267 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3268
3269 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003270 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003271 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003272 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3273}
3274
deadbeefd1a38b52016-12-10 13:15:33 -08003275// Test that when SetConfiguration is called and the configuration is
3276// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003277TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003278 PeerConnectionInterface::RTCConfiguration config;
3279 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003280 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003281 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003282 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3283 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003284
3285 // Do initial offer/answer so there's something to restart.
3286 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003287 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003288
3289 // Grab the ufrags.
3290 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3291
3292 // Change ICE policy, which should trigger an ICE restart on the next offer.
3293 config.type = PeerConnectionInterface::kAll;
3294 EXPECT_TRUE(pc_->SetConfiguration(config));
3295 CreateOfferAsLocalDescription();
3296
3297 // Grab the new ufrags.
3298 std::vector<std::string> subsequent_ufrags =
3299 GetUfrags(pc_->local_description());
3300
3301 // Sanity check.
3302 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3303 // Check that each ufrag is different.
3304 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3305 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3306 }
3307}
3308
3309// Test that when SetConfiguration is called and the configuration *isn't*
3310// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003311TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003312 PeerConnectionInterface::RTCConfiguration config;
3313 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003314 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003315 config = pc_->GetConfiguration();
3316 AddAudioTrack(kAudioTracks[0]);
3317 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003318
3319 // Do initial offer/answer so there's something to restart.
3320 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003321 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003322
3323 // Grab the ufrags.
3324 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3325
3326 // Call SetConfiguration with a config identical to what the PC was
3327 // constructed with.
3328 EXPECT_TRUE(pc_->SetConfiguration(config));
3329 CreateOfferAsLocalDescription();
3330
3331 // Grab the new ufrags.
3332 std::vector<std::string> subsequent_ufrags =
3333 GetUfrags(pc_->local_description());
3334
3335 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3336}
3337
3338// Test for a weird corner case scenario:
3339// 1. Audio/video session established.
3340// 2. SetConfiguration changes ICE config; ICE restart needed.
3341// 3. ICE restart initiated by remote peer, but only for one m= section.
3342// 4. Next createOffer should initiate an ICE restart, but only for the other
3343// m= section; it would be pointless to do an ICE restart for the m= section
3344// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003345TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003346 PeerConnectionInterface::RTCConfiguration config;
3347 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003348 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003349 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003350 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3351 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003352
3353 // Do initial offer/answer so there's something to restart.
3354 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003355 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003356
3357 // Change ICE policy, which should set the "needs-ice-restart" flag.
3358 config.type = PeerConnectionInterface::kAll;
3359 EXPECT_TRUE(pc_->SetConfiguration(config));
3360
3361 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003362 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003363 webrtc::CreateSessionDescription(SdpType::kOffer,
3364 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003365 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003366 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3367 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003368 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003369 CreateAnswerAsLocalDescription();
3370
3371 // Grab the ufrags.
3372 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003373 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003374
3375 // Create offer and grab the new ufrags.
3376 CreateOfferAsLocalDescription();
3377 std::vector<std::string> subsequent_ufrags =
3378 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003379 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003380
3381 // Ensure that only the ufrag for the second m= section changed.
3382 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3383 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3384}
3385
deadbeeffe4a8a42016-12-20 17:56:17 -08003386// Tests that the methods to return current/pending descriptions work as
3387// expected at different points in the offer/answer exchange. This test does
3388// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003389TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003390 // This disables DTLS so we can apply an answer to ourselves.
3391 CreatePeerConnection();
3392
3393 // Create initial local offer and get SDP (which will also be used as
3394 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003395 std::unique_ptr<SessionDescriptionInterface> local_offer;
3396 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003397 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003398 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003399
3400 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003401 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3402 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3403 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003404 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3405 EXPECT_EQ(nullptr, pc_->current_local_description());
3406 EXPECT_EQ(nullptr, pc_->current_remote_description());
3407
3408 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003409 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003410 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003411 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3412 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3413 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3414 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003415 EXPECT_EQ(nullptr, pc_->current_local_description());
3416 EXPECT_EQ(nullptr, pc_->current_remote_description());
3417
3418 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003419 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003420 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003421 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3422 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003423 EXPECT_EQ(nullptr, pc_->pending_local_description());
3424 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003425 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3426 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003427
3428 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003429 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003430 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003431 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3432 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3433 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003434 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003435 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3436 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003437
3438 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003439 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003440 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003441 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3442 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3443 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3444 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3445 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3446 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003447
3448 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003449 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003450 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003451 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3452 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003453 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3454 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003455 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3456 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003457}
3458
zhihuang77985012017-02-07 15:45:16 -08003459// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3460// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003461// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003462TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003463 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003464 CreatePeerConnection();
3465 // The RtcEventLog will be reset when the PeerConnection is closed.
3466 pc_->Close();
3467
Elad Alon9e6565b2017-10-11 16:04:13 +02003468 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3469 std::string filename = webrtc::test::OutputPath() +
3470 test_info->test_case_name() + test_info->name();
3471 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3472
3473 constexpr int64_t max_size_bytes = 1024;
3474
zhihuang77985012017-02-07 15:45:16 -08003475 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3476 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003477
3478 // Cleanup.
3479 rtc::ClosePlatformFile(file);
3480 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003481}
3482
Elad Alon99c3fe52017-10-13 16:29:40 +02003483// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3484// after the PeerConnection is closed.
3485// This version tests the StartRtcEventLog version that receives an object
3486// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003487TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003488 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3489 CreatePeerConnection();
3490 // The RtcEventLog will be reset when the PeerConnection is closed.
3491 pc_->Close();
3492
3493 rtc::PlatformFile file = 0;
3494 int64_t max_size_bytes = 1024;
3495 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003496 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003497 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003498 pc_->StopRtcEventLog();
3499}
3500
deadbeef30952b42017-04-21 02:41:29 -07003501// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003502TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003503 CreatePeerConnection();
3504
3505 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003506 RTCOfferAnswerOptions options;
3507 options.offer_to_receive_audio = 1;
3508 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003509 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003510 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003511 cricket::SessionDescription* desc = offer->description();
3512 ASSERT_EQ(2u, desc->transport_infos().size());
3513 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3514 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3515
3516 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003517 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003518 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003519 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003520 desc = answer->description();
3521 ASSERT_EQ(2u, desc->transport_infos().size());
3522 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3523 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3524}
3525
deadbeef1dcb1642017-03-29 21:08:16 -07003526// Test that ICE renomination isn't offered if it's not enabled in the PC's
3527// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003528TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003529 PeerConnectionInterface::RTCConfiguration config;
3530 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003531 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003532 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003533
3534 std::unique_ptr<SessionDescriptionInterface> offer;
3535 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3536 cricket::SessionDescription* desc = offer->description();
3537 EXPECT_EQ(1u, desc->transport_infos().size());
3538 EXPECT_FALSE(
3539 desc->transport_infos()[0].description.GetIceParameters().renomination);
3540}
3541
3542// Test that the ICE renomination option is present in generated offers/answers
3543// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003544TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003545 PeerConnectionInterface::RTCConfiguration config;
3546 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003547 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003548 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003549
3550 std::unique_ptr<SessionDescriptionInterface> offer;
3551 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3552 cricket::SessionDescription* desc = offer->description();
3553 EXPECT_EQ(1u, desc->transport_infos().size());
3554 EXPECT_TRUE(
3555 desc->transport_infos()[0].description.GetIceParameters().renomination);
3556
3557 // Set the offer as a remote description, then create an answer and ensure it
3558 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003559 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003560 std::unique_ptr<SessionDescriptionInterface> answer;
3561 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3562 desc = answer->description();
3563 EXPECT_EQ(1u, desc->transport_infos().size());
3564 EXPECT_TRUE(
3565 desc->transport_infos()[0].description.GetIceParameters().renomination);
3566}
3567
3568// Test that if CreateOffer is called with the deprecated "offer to receive
3569// audio/video" constraints, they're processed and result in an offer with
3570// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003571TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003572 CreatePeerConnection();
3573
Niels Möllerf06f9232018-08-07 12:32:18 +02003574 RTCOfferAnswerOptions options;
3575 options.offer_to_receive_audio = 1;
3576 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003577 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003578 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003579
3580 cricket::SessionDescription* desc = offer->description();
3581 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3582 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3583 ASSERT_NE(nullptr, audio);
3584 ASSERT_NE(nullptr, video);
3585 EXPECT_FALSE(audio->rejected);
3586 EXPECT_FALSE(video->rejected);
3587}
3588
3589// Test that if CreateAnswer is called with the deprecated "offer to receive
3590// audio/video" constraints, they're processed and can be used to reject an
3591// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003592// Don't run under Unified Plan since this behavior is not supported.
3593TEST_F(PeerConnectionInterfaceTestPlanB,
3594 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003595 CreatePeerConnection();
3596
3597 // First, create an offer with audio/video and apply it as a remote
3598 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003599 RTCOfferAnswerOptions options;
3600 options.offer_to_receive_audio = 1;
3601 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003602 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003603 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003604 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003605
3606 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003607 options.offer_to_receive_audio = 0;
3608 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003609 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003610 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003611
3612 cricket::SessionDescription* desc = answer->description();
3613 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3614 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3615 ASSERT_NE(nullptr, audio);
3616 ASSERT_NE(nullptr, video);
3617 EXPECT_TRUE(audio->rejected);
3618 EXPECT_TRUE(video->rejected);
3619}
3620
deadbeef1dcb1642017-03-29 21:08:16 -07003621// Test that negotiation can succeed with a data channel only, and with the max
3622// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003623#ifdef HAVE_SCTP
3624TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3625#else
3626TEST_P(PeerConnectionInterfaceTest,
3627 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3628#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003629 PeerConnectionInterface::RTCConfiguration config;
3630 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003631 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003632
3633 // First, create an offer with only a data channel and apply it as a remote
3634 // description.
3635 pc_->CreateDataChannel("test", nullptr);
3636 std::unique_ptr<SessionDescriptionInterface> offer;
3637 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003638 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003639
3640 // Create and set answer as well.
3641 std::unique_ptr<SessionDescriptionInterface> answer;
3642 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003643 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003644}
3645
Steve Anton36da6ff2018-02-16 16:04:20 -08003646TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003647 CreatePeerConnection();
3648 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003649 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003650 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3651}
3652
Steve Anton36da6ff2018-02-16 16:04:20 -08003653TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003654 CreatePeerConnection();
3655 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003656 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003657 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3658}
3659
Steve Anton36da6ff2018-02-16 16:04:20 -08003660TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003661 CreatePeerConnection();
3662 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003663 bitrate.min_bitrate_bps = 5;
3664 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003665 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3666}
3667
Steve Anton36da6ff2018-02-16 16:04:20 -08003668TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003669 CreatePeerConnection();
3670 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003671 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003672 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3673}
3674
Steve Anton36da6ff2018-02-16 16:04:20 -08003675TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003676 CreatePeerConnection();
3677 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003678 bitrate.current_bitrate_bps = 10;
3679 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003680 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3681}
3682
Steve Anton36da6ff2018-02-16 16:04:20 -08003683TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003684 CreatePeerConnection();
3685 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003686 bitrate.min_bitrate_bps = 10;
3687 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003688 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3689}
3690
Steve Anton36da6ff2018-02-16 16:04:20 -08003691TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003692 CreatePeerConnection();
3693 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003694 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003695 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3696}
3697
Steve Anton038834f2017-07-14 15:59:59 -07003698// ice_regather_interval_range requires WebRTC to be configured for continual
3699// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003700TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003701 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3702 PeerConnectionInterface::RTCConfiguration config;
3703 config.ice_regather_interval_range.emplace(1000, 2000);
3704 config.continual_gathering_policy =
3705 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3706 CreatePeerConnectionExpectFail(config);
3707}
3708
3709// Ensures that there is no error when ice_regather_interval_range is set with
3710// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003711TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003712 SetIceRegatherIntervalRangeWithContinualGathering) {
3713 PeerConnectionInterface::RTCConfiguration config;
3714 config.ice_regather_interval_range.emplace(1000, 2000);
3715 config.continual_gathering_policy =
3716 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003717 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003718}
3719
Niels Möller0c4f7be2018-05-07 14:01:37 +02003720// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003721// by Call's BitrateConstraints, which comes from the SDP or a default value.
3722// This test checks that a call to SetBitrate with a current bitrate that will
3723// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003724TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003725 CreatePeerConnection();
3726 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003727 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003728 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3729}
3730
zhihuang1c378ed2017-08-17 14:10:50 -07003731// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003732TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003733 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3734 RTCOfferAnswerOptions rtc_options;
3735
3736 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3737 // than kMaxOfferToReceiveMedia should be treated as invalid.
3738 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3739 CreatePeerConnection();
3740 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3741
3742 rtc_options.offer_to_receive_audio =
3743 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3744 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3745}
3746
Steve Anton36da6ff2018-02-16 16:04:20 -08003747TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003748 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3749 RTCOfferAnswerOptions rtc_options;
3750
3751 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3752 // than kMaxOfferToReceiveMedia should be treated as invalid.
3753 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3754 CreatePeerConnection();
3755 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3756
3757 rtc_options.offer_to_receive_video =
3758 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3759 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3760}
3761
3762// Test that the audio and video content will be added to an offer if both
3763// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003764TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003765 RTCOfferAnswerOptions rtc_options;
3766 rtc_options.offer_to_receive_audio = 1;
3767 rtc_options.offer_to_receive_video = 1;
3768
3769 std::unique_ptr<SessionDescriptionInterface> offer;
3770 CreatePeerConnection();
3771 offer = CreateOfferWithOptions(rtc_options);
3772 ASSERT_TRUE(offer);
3773 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3774 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3775}
3776
3777// Test that only audio content will be added to the offer if only
3778// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003779TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003780 RTCOfferAnswerOptions rtc_options;
3781 rtc_options.offer_to_receive_audio = 1;
3782 rtc_options.offer_to_receive_video = 0;
3783
3784 std::unique_ptr<SessionDescriptionInterface> offer;
3785 CreatePeerConnection();
3786 offer = CreateOfferWithOptions(rtc_options);
3787 ASSERT_TRUE(offer);
3788 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3789 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3790}
3791
3792// Test that only video content will be added if only |offer_to_receive_video|
3793// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003794TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003795 RTCOfferAnswerOptions rtc_options;
3796 rtc_options.offer_to_receive_audio = 0;
3797 rtc_options.offer_to_receive_video = 1;
3798
3799 std::unique_ptr<SessionDescriptionInterface> offer;
3800 CreatePeerConnection();
3801 offer = CreateOfferWithOptions(rtc_options);
3802 ASSERT_TRUE(offer);
3803 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3804 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3805}
3806
zhihuang1c378ed2017-08-17 14:10:50 -07003807// Test that no media content will be added to the offer if using default
3808// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003809TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003810 RTCOfferAnswerOptions rtc_options;
3811
3812 std::unique_ptr<SessionDescriptionInterface> offer;
3813 CreatePeerConnection();
3814 offer = CreateOfferWithOptions(rtc_options);
3815 ASSERT_TRUE(offer);
3816 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3817 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3818}
3819
3820// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3821// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003822TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3823 CreatePeerConnection();
3824
zhihuang1c378ed2017-08-17 14:10:50 -07003825 RTCOfferAnswerOptions rtc_options;
3826 rtc_options.ice_restart = false;
3827 rtc_options.offer_to_receive_audio = 1;
3828
3829 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003830 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003831 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3832 auto ufrag1 =
3833 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3834 auto pwd1 =
3835 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003836
3837 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3838 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003839 auto ufrag2 =
3840 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3841 auto pwd2 =
3842 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003843
3844 // |ice_restart| is true, the ufrag/pwd should change.
3845 rtc_options.ice_restart = true;
3846 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003847 auto ufrag3 =
3848 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3849 auto pwd3 =
3850 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003851
3852 EXPECT_EQ(ufrag1, ufrag2);
3853 EXPECT_EQ(pwd1, pwd2);
3854 EXPECT_NE(ufrag2, ufrag3);
3855 EXPECT_NE(pwd2, pwd3);
3856}
3857
3858// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3859// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003860TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003861 RTCOfferAnswerOptions rtc_options;
3862 rtc_options.offer_to_receive_audio = 1;
3863 rtc_options.offer_to_receive_video = 1;
3864
3865 std::unique_ptr<SessionDescriptionInterface> offer;
3866 CreatePeerConnection();
3867
3868 rtc_options.use_rtp_mux = true;
3869 offer = CreateOfferWithOptions(rtc_options);
3870 ASSERT_TRUE(offer);
3871 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3872 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3873 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3874
3875 rtc_options.use_rtp_mux = false;
3876 offer = CreateOfferWithOptions(rtc_options);
3877 ASSERT_TRUE(offer);
3878 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3879 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3880 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3881}
3882
zhihuang141aacb2017-08-29 13:23:53 -07003883// This test ensures OnRenegotiationNeeded is called when we add track with
3884// MediaStream -> AddTrack in the same way it is called when we add track with
3885// PeerConnection -> AddTrack.
3886// The test can be removed once addStream is rewritten in terms of addTrack
3887// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003888// Don't run under Unified Plan since the stream API is not available.
3889TEST_F(PeerConnectionInterfaceTestPlanB,
3890 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003891 CreatePeerConnectionWithoutDtls();
3892 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003893 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003894 pc_->AddStream(stream);
3895 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3896 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3897 rtc::scoped_refptr<VideoTrackInterface> video_track(
3898 pc_factory_->CreateVideoTrack(
3899 "video_track", pc_factory_->CreateVideoSource(
3900 std::unique_ptr<cricket::VideoCapturer>(
3901 new cricket::FakeVideoCapturer()))));
3902 stream->AddTrack(audio_track);
3903 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3904 observer_.renegotiation_needed_ = false;
3905
3906 stream->AddTrack(video_track);
3907 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3908 observer_.renegotiation_needed_ = false;
3909
3910 stream->RemoveTrack(audio_track);
3911 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3912 observer_.renegotiation_needed_ = false;
3913
3914 stream->RemoveTrack(video_track);
3915 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3916 observer_.renegotiation_needed_ = false;
3917}
3918
Zhi Huangb2d355e2017-10-26 17:26:37 -07003919// Tests that an error is returned if a description is applied that has fewer
3920// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003921TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003922 MediaSectionCountEnforcedForSubsequentOffer) {
3923 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003924 AddAudioTrack("audio_label");
3925 AddVideoTrack("video_label");
3926
Zhi Huangb2d355e2017-10-26 17:26:37 -07003927 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003928 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003929 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3930
3931 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003932 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003933 offer->description()->contents().pop_back();
3934 offer->description()->contents().pop_back();
3935 ASSERT_TRUE(offer->description()->contents().empty());
3936 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3937
3938 std::unique_ptr<SessionDescriptionInterface> answer;
3939 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3940 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3941
3942 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003943 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003944 offer->description()->contents().pop_back();
3945 offer->description()->contents().pop_back();
3946 ASSERT_TRUE(offer->description()->contents().empty());
3947 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3948}
3949
Johannes Kron89f874e2018-11-12 10:25:48 +01003950TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3951 RTCConfiguration config;
3952 // Default behavior is false.
3953 CreatePeerConnection(config);
3954 std::unique_ptr<SessionDescriptionInterface> offer;
3955 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3956 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3957 // Possible to set to true.
3958 config.offer_extmap_allow_mixed = true;
3959 CreatePeerConnection(config);
3960 offer.release();
3961 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3962 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3963}
3964
Steve Anton36da6ff2018-02-16 16:04:20 -08003965INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3966 PeerConnectionInterfaceTest,
3967 Values(SdpSemantics::kPlanB,
3968 SdpSemantics::kUnifiedPlan));
3969
nisse51542be2016-02-12 02:27:06 -08003970class PeerConnectionMediaConfigTest : public testing::Test {
3971 protected:
3972 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003973 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003974 pcf_->Initialize();
3975 }
nisseeaabdf62017-05-05 02:23:02 -07003976 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003977 const RTCConfiguration& config) {
3978 rtc::scoped_refptr<PeerConnectionInterface> pc(
3979 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003980 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003981 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003982 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003983 }
3984
zhihuang9763d562016-08-05 11:14:50 -07003985 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003986 MockPeerConnectionObserver observer_;
3987};
3988
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003989// This sanity check validates the test infrastructure itself.
3990TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3991 PeerConnectionInterface::RTCConfiguration config;
3992 rtc::scoped_refptr<PeerConnectionInterface> pc(
3993 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3994 EXPECT_TRUE(pc.get());
3995 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3996 pc->Close(); // No abort -> ok.
3997 SUCCEED();
3998}
3999
nisse51542be2016-02-12 02:27:06 -08004000// This test verifies the default behaviour with no constraints and a
4001// default RTCConfiguration.
4002TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4003 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004004
Niels Möllerf06f9232018-08-07 12:32:18 +02004005 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004006
4007 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004008 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4009 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004010 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004011 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004012}
4013
Niels Möller1d7ecd22018-01-18 15:25:12 +01004014// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004015// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004016TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4017 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004018
Niels Möller71bdda02016-03-31 12:59:59 +02004019 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004020 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004021
Niels Möller1d7ecd22018-01-18 15:25:12 +01004022 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004023}
4024
Niels Möller6539f692018-01-18 08:58:50 +01004025// This test verifies that the experiment_cpu_load_estimator flag is
4026// propagated from RTCConfiguration to the PeerConnection.
4027TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4028 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004029
4030 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004031 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004032
4033 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4034}
4035
deadbeef293e9262017-01-11 12:28:30 -08004036// Tests a few random fields being different.
4037TEST(RTCConfigurationTest, ComparisonOperators) {
4038 PeerConnectionInterface::RTCConfiguration a;
4039 PeerConnectionInterface::RTCConfiguration b;
4040 EXPECT_EQ(a, b);
4041
4042 PeerConnectionInterface::RTCConfiguration c;
4043 c.servers.push_back(PeerConnectionInterface::IceServer());
4044 EXPECT_NE(a, c);
4045
4046 PeerConnectionInterface::RTCConfiguration d;
4047 d.type = PeerConnectionInterface::kRelay;
4048 EXPECT_NE(a, d);
4049
4050 PeerConnectionInterface::RTCConfiguration e;
4051 e.audio_jitter_buffer_max_packets = 5;
4052 EXPECT_NE(a, e);
4053
4054 PeerConnectionInterface::RTCConfiguration f;
4055 f.ice_connection_receiving_timeout = 1337;
4056 EXPECT_NE(a, f);
4057
4058 PeerConnectionInterface::RTCConfiguration g;
4059 g.disable_ipv6 = true;
4060 EXPECT_NE(a, g);
4061
4062 PeerConnectionInterface::RTCConfiguration h(
4063 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4064 EXPECT_NE(a, h);
4065}