blob: ef3f317de42b81c2509d0951201ad2c345fa4f6b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Zhi Huang2a5e4262017-09-14 01:15:03 -070011#include <algorithm>
kwibergd1fe2812016-04-27 06:47:29 -070012#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080013#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080015#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/audio_codecs/builtin_audio_decoder_factory.h"
18#include "api/audio_codecs/builtin_audio_encoder_factory.h"
19#include "api/jsepsessiondescription.h"
20#include "api/mediastreaminterface.h"
21#include "api/peerconnectioninterface.h"
22#include "api/rtpreceiverinterface.h"
23#include "api/rtpsenderinterface.h"
24#include "api/test/fakeconstraints.h"
Anders Carlsson67537952018-05-03 11:28:29 +020025#include "api/video_codecs/builtin_video_decoder_factory.h"
26#include "api/video_codecs/builtin_video_encoder_factory.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020027#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "media/base/fakevideocapturer.h"
29#include "media/engine/webrtcmediaengine.h"
30#include "media/sctp/sctptransportinternal.h"
31#include "modules/audio_processing/include/audio_processing.h"
32#include "p2p/base/fakeportallocator.h"
33#include "pc/audiotrack.h"
34#include "pc/mediasession.h"
35#include "pc/mediastream.h"
36#include "pc/peerconnection.h"
Steve Anton57858b32018-02-15 15:19:50 -080037#include "pc/rtpsender.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "pc/streamcollection.h"
39#include "pc/test/fakeaudiocapturemodule.h"
40#include "pc/test/fakertccertificategenerator.h"
41#include "pc/test/fakevideotracksource.h"
42#include "pc/test/mockpeerconnectionobservers.h"
43#include "pc/test/testsdpstrings.h"
44#include "pc/videocapturertracksource.h"
45#include "pc/videotrack.h"
46#include "rtc_base/gunit.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020047#include "rtc_base/ptr_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "rtc_base/stringutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#include "rtc_base/virtualsocketserver.h"
50#include "test/gmock.h"
Elad Alon9e6565b2017-10-11 16:04:13 +020051#include "test/testsupport/fileutils.h"
kwibergac9f8762016-09-30 22:29:43 -070052
53#ifdef WEBRTC_ANDROID
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#include "pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070055#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
Seth Hampson845e8782018-03-02 11:34:10 -080057static const char kStreamId1[] = "local_stream_1";
58static const char kStreamId2[] = "local_stream_2";
59static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060static const int kDefaultStunPort = 3478;
61static const char kStunAddressOnly[] = "stun:address";
62static const char kStunInvalidPort[] = "stun:address:-1";
63static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
64static const char kStunAddressPortAndMore2[] = "stun:address:port more";
65static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
66static const char kTurnUsername[] = "user";
67static const char kTurnPassword[] = "password";
68static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020069static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070
deadbeefab9b2d12015-10-14 11:33:11 -070071static const char kStreams[][8] = {"stream1", "stream2"};
72static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
73static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
74
deadbeef5e97fb52015-10-15 12:49:08 -070075static const char kRecvonly[] = "recvonly";
76static const char kSendrecv[] = "sendrecv";
77
deadbeefab9b2d12015-10-14 11:33:11 -070078// Reference SDP with a MediaStream with label "stream1" and audio track with
79// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -080080static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -070081 "v=0\r\n"
82 "o=- 0 0 IN IP4 127.0.0.1\r\n"
83 "s=-\r\n"
84 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080085 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070086 "a=ice-ufrag:e5785931\r\n"
87 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
88 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
89 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070090 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070091 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080092 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070093 "a=rtpmap:103 ISAC/16000\r\n"
94 "a=ssrc:1 cname:stream1\r\n"
95 "a=ssrc:1 mslabel:stream1\r\n"
96 "a=ssrc:1 label:audiotrack0\r\n"
97 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080098 "a=ice-ufrag:e5785931\r\n"
99 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
100 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
101 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700102 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700103 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800104 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700105 "a=rtpmap:120 VP8/90000\r\n"
106 "a=ssrc:2 cname:stream1\r\n"
107 "a=ssrc:2 mslabel:stream1\r\n"
108 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800109// Same string as above but with the MID changed to the Unified Plan default.
110// This is needed so that this SDP can be used as an answer for a Unified Plan
111// offer.
112static const char kSdpStringWithStream1UnifiedPlan[] =
113 "v=0\r\n"
114 "o=- 0 0 IN IP4 127.0.0.1\r\n"
115 "s=-\r\n"
116 "t=0 0\r\n"
117 "m=audio 1 RTP/AVPF 103\r\n"
118 "a=ice-ufrag:e5785931\r\n"
119 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
120 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
121 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
122 "a=mid:0\r\n"
123 "a=sendrecv\r\n"
124 "a=rtcp-mux\r\n"
125 "a=rtpmap:103 ISAC/16000\r\n"
126 "a=ssrc:1 cname:stream1\r\n"
127 "a=ssrc:1 mslabel:stream1\r\n"
128 "a=ssrc:1 label:audiotrack0\r\n"
129 "m=video 1 RTP/AVPF 120\r\n"
130 "a=ice-ufrag:e5785931\r\n"
131 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
132 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
133 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
134 "a=mid:1\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=rtpmap:120 VP8/90000\r\n"
138 "a=ssrc:2 cname:stream1\r\n"
139 "a=ssrc:2 mslabel:stream1\r\n"
140 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700141
zhihuang81c3a032016-11-17 12:06:24 -0800142// Reference SDP with a MediaStream with label "stream1" and audio track with
143// id "audio_1";
144static const char kSdpStringWithStream1AudioTrackOnly[] =
145 "v=0\r\n"
146 "o=- 0 0 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800149 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800150 "a=ice-ufrag:e5785931\r\n"
151 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
152 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
153 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800154 "a=mid:audio\r\n"
155 "a=sendrecv\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
157 "a=ssrc:1 cname:stream1\r\n"
158 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800159 "a=ssrc:1 label:audiotrack0\r\n"
160 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800161
deadbeefab9b2d12015-10-14 11:33:11 -0700162// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
163// MediaStreams have one audio track and one video track.
164// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800165static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700166 "v=0\r\n"
167 "o=- 0 0 IN IP4 127.0.0.1\r\n"
168 "s=-\r\n"
169 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800170 "a=msid-semantic: WMS stream1 stream2\r\n"
171 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700172 "a=ice-ufrag:e5785931\r\n"
173 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
174 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
175 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700176 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700177 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800178 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700179 "a=rtpmap:103 ISAC/16000\r\n"
180 "a=ssrc:1 cname:stream1\r\n"
181 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
182 "a=ssrc:3 cname:stream2\r\n"
183 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
184 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800185 "a=ice-ufrag:e5785931\r\n"
186 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
187 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
188 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700189 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700190 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800191 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700192 "a=rtpmap:120 VP8/0\r\n"
193 "a=ssrc:2 cname:stream1\r\n"
194 "a=ssrc:2 msid:stream1 videotrack0\r\n"
195 "a=ssrc:4 cname:stream2\r\n"
196 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800197static const char kSdpStringWithStream1And2UnifiedPlan[] =
198 "v=0\r\n"
199 "o=- 0 0 IN IP4 127.0.0.1\r\n"
200 "s=-\r\n"
201 "t=0 0\r\n"
202 "a=msid-semantic: WMS stream1 stream2\r\n"
203 "m=audio 1 RTP/AVPF 103\r\n"
204 "a=ice-ufrag:e5785931\r\n"
205 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
206 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
207 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
208 "a=mid:0\r\n"
209 "a=sendrecv\r\n"
210 "a=rtcp-mux\r\n"
211 "a=rtpmap:103 ISAC/16000\r\n"
212 "a=ssrc:1 cname:stream1\r\n"
213 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
214 "m=video 1 RTP/AVPF 120\r\n"
215 "a=ice-ufrag:e5785931\r\n"
216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
219 "a=mid:1\r\n"
220 "a=sendrecv\r\n"
221 "a=rtcp-mux\r\n"
222 "a=rtpmap:120 VP8/0\r\n"
223 "a=ssrc:2 cname:stream1\r\n"
224 "a=ssrc:2 msid:stream1 videotrack0\r\n"
225 "m=audio 1 RTP/AVPF 103\r\n"
226 "a=ice-ufrag:e5785931\r\n"
227 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
228 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
229 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
230 "a=mid:2\r\n"
231 "a=sendrecv\r\n"
232 "a=rtcp-mux\r\n"
233 "a=rtpmap:103 ISAC/16000\r\n"
234 "a=ssrc:3 cname:stream2\r\n"
235 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
236 "m=video 1 RTP/AVPF 120\r\n"
237 "a=ice-ufrag:e5785931\r\n"
238 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
239 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
240 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
241 "a=mid:3\r\n"
242 "a=sendrecv\r\n"
243 "a=rtcp-mux\r\n"
244 "a=rtpmap:120 VP8/0\r\n"
245 "a=ssrc:4 cname:stream2\r\n"
246 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700247
248// Reference SDP without MediaStreams. Msid is not supported.
249static const char kSdpStringWithoutStreams[] =
250 "v=0\r\n"
251 "o=- 0 0 IN IP4 127.0.0.1\r\n"
252 "s=-\r\n"
253 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800254 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700255 "a=ice-ufrag:e5785931\r\n"
256 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
257 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
258 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700259 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700260 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800261 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700262 "a=rtpmap:103 ISAC/16000\r\n"
263 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800264 "a=ice-ufrag:e5785931\r\n"
265 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
266 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
267 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700268 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700269 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800270 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700271 "a=rtpmap:120 VP8/90000\r\n";
272
273// Reference SDP without MediaStreams. Msid is supported.
274static const char kSdpStringWithMsidWithoutStreams[] =
275 "v=0\r\n"
276 "o=- 0 0 IN IP4 127.0.0.1\r\n"
277 "s=-\r\n"
278 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800279 "a=msid-semantic: WMS\r\n"
280 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700281 "a=ice-ufrag:e5785931\r\n"
282 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
283 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
284 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700285 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700286 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800287 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700288 "a=rtpmap:103 ISAC/16000\r\n"
289 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800290 "a=ice-ufrag:e5785931\r\n"
291 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
292 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
293 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700294 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700295 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800296 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700297 "a=rtpmap:120 VP8/90000\r\n";
298
299// Reference SDP without MediaStreams and audio only.
300static const char kSdpStringWithoutStreamsAudioOnly[] =
301 "v=0\r\n"
302 "o=- 0 0 IN IP4 127.0.0.1\r\n"
303 "s=-\r\n"
304 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800305 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700306 "a=ice-ufrag:e5785931\r\n"
307 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
308 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
309 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700310 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700311 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800312 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700313 "a=rtpmap:103 ISAC/16000\r\n";
314
315// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
316static const char kSdpStringSendOnlyWithoutStreams[] =
317 "v=0\r\n"
318 "o=- 0 0 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800321 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700322 "a=ice-ufrag:e5785931\r\n"
323 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
324 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
325 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700326 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700327 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700330 "a=rtpmap:103 ISAC/16000\r\n"
331 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800332 "a=ice-ufrag:e5785931\r\n"
333 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
334 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
335 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700336 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700337 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700338 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800339 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700340 "a=rtpmap:120 VP8/90000\r\n";
341
342static const char kSdpStringInit[] =
343 "v=0\r\n"
344 "o=- 0 0 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700347 "a=msid-semantic: WMS\r\n";
348
349static const char kSdpStringAudio[] =
350 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800351 "a=ice-ufrag:e5785931\r\n"
352 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
353 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
354 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700356 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800357 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700358 "a=rtpmap:103 ISAC/16000\r\n";
359
360static const char kSdpStringVideo[] =
361 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800362 "a=ice-ufrag:e5785931\r\n"
363 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
364 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
365 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700366 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700367 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800368 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700369 "a=rtpmap:120 VP8/90000\r\n";
370
371static const char kSdpStringMs1Audio0[] =
372 "a=ssrc:1 cname:stream1\r\n"
373 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
374
375static const char kSdpStringMs1Video0[] =
376 "a=ssrc:2 cname:stream1\r\n"
377 "a=ssrc:2 msid:stream1 videotrack0\r\n";
378
379static const char kSdpStringMs1Audio1[] =
380 "a=ssrc:3 cname:stream1\r\n"
381 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
382
383static const char kSdpStringMs1Video1[] =
384 "a=ssrc:4 cname:stream1\r\n"
385 "a=ssrc:4 msid:stream1 videotrack1\r\n";
386
deadbeef8662f942017-01-20 21:20:51 -0800387static const char kDtlsSdesFallbackSdp[] =
388 "v=0\r\n"
389 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
390 "s=-\r\n"
391 "c=IN IP4 0.0.0.0\r\n"
392 "t=0 0\r\n"
393 "a=group:BUNDLE audio\r\n"
394 "a=msid-semantic: WMS\r\n"
395 "m=audio 1 RTP/SAVPF 0\r\n"
396 "a=sendrecv\r\n"
397 "a=rtcp-mux\r\n"
398 "a=mid:audio\r\n"
399 "a=ssrc:1 cname:stream1\r\n"
400 "a=ssrc:1 mslabel:stream1\r\n"
401 "a=ssrc:1 label:audiotrack0\r\n"
402 "a=ice-ufrag:e5785931\r\n"
403 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
404 "a=rtpmap:0 pcmu/8000\r\n"
405 "a=fingerprint:sha-1 "
406 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
407 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700408 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800409 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
410 "dummy_session_params\r\n";
411
perkjd61bf802016-03-24 03:16:19 -0700412using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800413using ::testing::Values;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700414using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700416using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417using webrtc::AudioTrackInterface;
418using webrtc::DataBuffer;
419using webrtc::DataChannelInterface;
420using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421using webrtc::IceCandidateInterface;
deadbeefc80741f2015-10-22 13:14:45 -0700422using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700423using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424using webrtc::MediaStreamInterface;
425using webrtc::MediaStreamTrackInterface;
426using webrtc::MockCreateSessionDescriptionObserver;
427using webrtc::MockDataChannelObserver;
Steve Anton94286cb2017-09-26 16:20:19 -0700428using webrtc::MockPeerConnectionObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429using webrtc::MockSetSessionDescriptionObserver;
430using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700431using webrtc::NotifierInterface;
432using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433using webrtc::PeerConnectionInterface;
434using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800435using webrtc::RTCError;
436using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700437using webrtc::RtpReceiverInterface;
438using webrtc::RtpSenderInterface;
Steve Anton57858b32018-02-15 15:19:50 -0800439using webrtc::RtpSenderProxyWithInternal;
440using webrtc::RtpSenderInternal;
Steve Anton4e70a722017-11-28 14:57:10 -0800441using webrtc::RtpTransceiverDirection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442using webrtc::SdpParseError;
Steve Anton36da6ff2018-02-16 16:04:20 -0800443using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800444using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700446using webrtc::StreamCollection;
447using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100448using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700449using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450using webrtc::VideoTrackInterface;
451
Steve Anton36da6ff2018-02-16 16:04:20 -0800452using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
453using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700454
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455namespace {
456
457// Gets the first ssrc of given content type from the ContentInfo.
458bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
459 if (!content_info || !ssrc) {
460 return false;
461 }
462 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800463 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 if (!media_desc || media_desc->streams().empty()) {
465 return false;
466 }
467 *ssrc = media_desc->streams().begin()->first_ssrc();
468 return true;
469}
470
deadbeefd1a38b52016-12-10 13:15:33 -0800471// Get the ufrags out of an SDP blob. Useful for testing ICE restart
472// behavior.
473std::vector<std::string> GetUfrags(
474 const webrtc::SessionDescriptionInterface* desc) {
475 std::vector<std::string> ufrags;
476 for (const cricket::TransportInfo& info :
477 desc->description()->transport_infos()) {
478 ufrags.push_back(info.description.ice_ufrag);
479 }
480 return ufrags;
481}
482
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483void SetSsrcToZero(std::string* sdp) {
484 const char kSdpSsrcAtribute[] = "a=ssrc:";
485 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
486 size_t ssrc_pos = 0;
487 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
488 std::string::npos) {
489 size_t end_ssrc = sdp->find(" ", ssrc_pos);
490 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
491 ssrc_pos = end_ssrc;
492 }
493}
494
deadbeefab9b2d12015-10-14 11:33:11 -0700495// Check if |streams| contains the specified track.
496bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800497 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700498 const std::string& track_id) {
499 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800500 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700501 return true;
502 }
503 }
504 return false;
505}
506
507// Check if |senders| contains the specified sender, by id.
508bool ContainsSender(
509 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
510 const std::string& id) {
511 for (const auto& sender : senders) {
512 if (sender->id() == id) {
513 return true;
514 }
515 }
516 return false;
517}
518
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700519// Check if |senders| contains the specified sender, by id and stream id.
520bool ContainsSender(
521 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
522 const std::string& id,
523 const std::string& stream_id) {
524 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700525 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700526 return true;
527 }
528 }
529 return false;
530}
531
deadbeefab9b2d12015-10-14 11:33:11 -0700532// Create a collection of streams.
533// CreateStreamCollection(1) creates a collection that
534// correspond to kSdpStringWithStream1.
535// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
536rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700537 int number_of_streams,
538 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700539 rtc::scoped_refptr<StreamCollection> local_collection(
540 StreamCollection::Create());
541
542 for (int i = 0; i < number_of_streams; ++i) {
543 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
544 webrtc::MediaStream::Create(kStreams[i]));
545
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700546 for (int j = 0; j < tracks_per_stream; ++j) {
547 // Add a local audio track.
548 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
549 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
550 nullptr));
551 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700552
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700553 // Add a local video track.
554 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
555 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700556 webrtc::FakeVideoTrackSource::Create(),
557 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700558 stream->AddTrack(video_track);
559 }
deadbeefab9b2d12015-10-14 11:33:11 -0700560
561 local_collection->AddStream(stream);
562 }
563 return local_collection;
564}
565
566// Check equality of StreamCollections.
567bool CompareStreamCollections(StreamCollectionInterface* s1,
568 StreamCollectionInterface* s2) {
569 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
570 return false;
571 }
572
573 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700574 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700575 return false;
576 }
577 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
578 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
579 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
580 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
581
582 if (audio_tracks1.size() != audio_tracks2.size()) {
583 return false;
584 }
585 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
586 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
587 return false;
588 }
589 }
590 if (video_tracks1.size() != video_tracks2.size()) {
591 return false;
592 }
593 for (size_t j = 0; j != video_tracks1.size(); ++j) {
594 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
595 return false;
596 }
597 }
598 }
599 return true;
600}
601
perkjd61bf802016-03-24 03:16:19 -0700602// Helper class to test Observer.
603class MockTrackObserver : public ObserverInterface {
604 public:
605 explicit MockTrackObserver(NotifierInterface* notifier)
606 : notifier_(notifier) {
607 notifier_->RegisterObserver(this);
608 }
609
610 ~MockTrackObserver() { Unregister(); }
611
612 void Unregister() {
613 if (notifier_) {
614 notifier_->UnregisterObserver(this);
615 notifier_ = nullptr;
616 }
617 }
618
619 MOCK_METHOD0(OnChanged, void());
620
621 private:
622 NotifierInterface* notifier_;
623};
624
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700626
nisse528b7932017-05-08 03:21:43 -0700627// The PeerConnectionMediaConfig tests below verify that configuration and
628// constraints are propagated into the PeerConnection's MediaConfig. These
629// settings are intended for MediaChannel constructors, but that is not
630// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700631class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
632 public:
zhihuang38ede132017-06-15 12:52:32 -0700633 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
634 CreatePeerConnectionFactoryForTest() {
635 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
636 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200637 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
638 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700639
henrika919dc2e2017-10-12 14:24:55 +0200640 // Use fake audio device module since we're only testing the interface
641 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700642 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
643 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200644 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200645 audio_decoder_factory, std::move(video_encoder_factory),
646 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100647 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700648
649 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
650 webrtc::CreateCallFactory();
651
652 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
653 webrtc::CreateRtcEventLogFactory();
654
655 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
656 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200657 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700658 std::move(event_log_factory));
659 }
660
661 PeerConnectionFactoryForTest(
662 rtc::Thread* network_thread,
663 rtc::Thread* worker_thread,
664 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700665 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
666 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
667 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
668 : webrtc::PeerConnectionFactory(network_thread,
669 worker_thread,
670 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700671 std::move(media_engine),
672 std::move(call_factory),
673 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800674
deadbeefd7850b22017-08-23 10:59:19 -0700675 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700676};
677
Steve Anton36da6ff2018-02-16 16:04:20 -0800678// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
679class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800681 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
682 : vss_(new rtc::VirtualSocketServer()),
683 main_(vss_.get()),
684 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800685#ifdef WEBRTC_ANDROID
686 webrtc::InitializeAndroidObjects();
687#endif
688 }
689
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700691 // Use fake audio capture module since we're only testing the interface
692 // level, and using a real one could make tests flaky when run in parallel.
693 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700695 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200696 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
697 fake_audio_capture_module_),
698 webrtc::CreateBuiltinAudioEncoderFactory(),
699 webrtc::CreateBuiltinAudioDecoderFactory(),
700 webrtc::CreateBuiltinVideoEncoderFactory(),
701 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
702 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700703 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700704 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700705 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700706 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 }
708
709 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700710 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 }
712
deadbeef293e9262017-01-11 12:28:30 -0800713 // DTLS does not work in a loopback call, so is disabled for most of the
714 // tests in this file.
715 void CreatePeerConnectionWithoutDtls() {
716 FakeConstraints no_dtls_constraints;
717 no_dtls_constraints.AddMandatory(
718 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
719
720 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
721 &no_dtls_constraints);
722 }
723
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700725 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
726 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 }
728
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700729 void CreatePeerConnectionWithIceTransportsType(
730 PeerConnectionInterface::IceTransportsType type) {
731 PeerConnectionInterface::RTCConfiguration config;
732 config.type = type;
733 return CreatePeerConnection(config, nullptr);
734 }
735
736 void CreatePeerConnectionWithIceServer(const std::string& uri,
737 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800738 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700740 server.uri = uri;
741 server.password = password;
742 config.servers.push_back(server);
743 CreatePeerConnection(config, nullptr);
744 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100746 void CreatePeerConnection(
747 const PeerConnectionInterface::RTCConfiguration& config,
748 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700749 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800750 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
751 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000752
deadbeef1dcb1642017-03-29 21:08:16 -0700753 // Create certificate generator unless DTLS constraint is explicitly set to
754 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200755 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000756 bool dtls;
757 if (FindConstraint(constraints,
758 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
759 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200760 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800761 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
762 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000763 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800764 RTCConfiguration modified_config = config;
765 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200766 pc_ = pc_factory_->CreatePeerConnection(
Steve Anton36da6ff2018-02-16 16:04:20 -0800767 modified_config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200768 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 ASSERT_TRUE(pc_.get() != NULL);
770 observer_.SetPeerConnectionInterface(pc_.get());
771 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
772 }
773
deadbeef0a6c4ca2015-10-06 11:38:28 -0700774 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800775 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700776 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700777 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800778 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800779 config.sdp_semantics = sdp_semantics_;
780 rtc::scoped_refptr<PeerConnectionInterface> pc =
781 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
782 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800783 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700784 }
785
Steve Anton038834f2017-07-14 15:59:59 -0700786 void CreatePeerConnectionExpectFail(
787 PeerConnectionInterface::RTCConfiguration config) {
788 PeerConnectionInterface::IceServer server;
789 server.uri = kTurnIceServerUri;
790 server.password = kTurnPassword;
791 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800792 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700793 rtc::scoped_refptr<PeerConnectionInterface> pc =
794 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
795 EXPECT_EQ(nullptr, pc);
796 }
797
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700799 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
801 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
802 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805
deadbeef0a6c4ca2015-10-06 11:38:28 -0700806 CreatePeerConnectionExpectFail(kStunInvalidPort);
807 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
808 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700810 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800811 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
812 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800814 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800816 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800818 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 }
820
821 void ReleasePeerConnection() {
822 pc_ = NULL;
823 observer_.SetPeerConnectionInterface(NULL);
824 }
825
Steve Anton36da6ff2018-02-16 16:04:20 -0800826 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
827 const std::string& label) {
828 auto video_source = pc_factory_->CreateVideoSource(
829 rtc::MakeUnique<cricket::FakeVideoCapturer>(), nullptr);
830 return pc_factory_->CreateVideoTrack(label, video_source);
831 }
832
833 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800834 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800835 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800836 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800837 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
839 observer_.renegotiation_needed_ = false;
840 }
841
Steve Anton36da6ff2018-02-16 16:04:20 -0800842 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700843 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800845 stream->AddTrack(CreateVideoTrack(label + "v0"));
846 ASSERT_TRUE(pc_->AddStream(stream));
847 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
848 observer_.renegotiation_needed_ = false;
849 }
850
851 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
852 const std::string& label) {
853 return pc_factory_->CreateAudioTrack(label, nullptr);
854 }
855
856 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800857 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800858 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800859 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800860 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
861 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
862 observer_.renegotiation_needed_ = false;
863 }
864
865 void AddAudioStream(const std::string& label) {
866 rtc::scoped_refptr<MediaStreamInterface> stream(
867 pc_factory_->CreateLocalMediaStream(label));
868 stream->AddTrack(CreateAudioTrack(label + "a0"));
869 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
871 observer_.renegotiation_needed_ = false;
872 }
873
Seth Hampson845e8782018-03-02 11:34:10 -0800874 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 const std::string& audio_track_label,
876 const std::string& video_track_label) {
877 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700878 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800879 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800880 stream->AddTrack(CreateAudioTrack(audio_track_label));
881 stream->AddTrack(CreateVideoTrack(video_track_label));
882 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
884 observer_.renegotiation_needed_ = false;
885 }
886
Steve Anton36da6ff2018-02-16 16:04:20 -0800887 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
888 cricket::MediaType media_type) {
889 for (auto receiver : pc_->GetReceivers()) {
890 if (receiver->media_type() == media_type) {
891 return receiver;
892 }
893 }
894 return nullptr;
895 }
896
kwibergd1fe2812016-04-27 06:47:29 -0700897 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700898 bool offer,
899 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000900 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
901 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 MockCreateSessionDescriptionObserver>());
903 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700904 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700906 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 }
908 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700909 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 return observer->result();
911 }
912
kwibergd1fe2812016-04-27 06:47:29 -0700913 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700914 MediaConstraintsInterface* constraints) {
915 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 }
917
kwibergd1fe2812016-04-27 06:47:29 -0700918 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700919 MediaConstraintsInterface* constraints) {
920 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 }
922
Steve Antondb45ca82017-09-11 18:27:34 -0700923 bool DoSetSessionDescription(
924 std::unique_ptr<SessionDescriptionInterface> desc,
925 bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000926 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
927 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 MockSetSessionDescriptionObserver>());
929 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700930 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700932 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 }
zhihuang29ff8442016-07-27 11:07:25 -0700934 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
935 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
936 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 return observer->result();
938 }
939
Steve Antondb45ca82017-09-11 18:27:34 -0700940 bool DoSetLocalDescription(
941 std::unique_ptr<SessionDescriptionInterface> desc) {
942 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 }
944
Steve Antondb45ca82017-09-11 18:27:34 -0700945 bool DoSetRemoteDescription(
946 std::unique_ptr<SessionDescriptionInterface> desc) {
947 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 }
949
950 // Calls PeerConnection::GetStats and check the return value.
951 // It does not verify the values in the StatReports since a RTCP packet might
952 // be required.
953 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000954 rtc::scoped_refptr<MockStatsObserver> observer(
955 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000956 if (!pc_->GetStats(
957 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 return false;
959 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
960 return observer->called();
961 }
962
Harald Alvestrand89061872018-01-02 14:08:34 +0100963 // Call the standards-compliant GetStats function.
964 bool DoGetRTCStats() {
965 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
966 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
967 pc_->GetStats(callback);
968 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
969 return callback->called();
970 }
971
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800973 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800975 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800976 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800977 } else {
978 // Unified Plan does not support AddStream, so just add an audio and video
979 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800980 AddAudioTrack(kAudioTracks[0], {kStreamId1});
981 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800982 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 CreateOfferReceiveAnswer();
984 }
985
986 // Verify that RTP Header extensions has been negotiated for audio and video.
987 void VerifyRemoteRtpHeaderExtensions() {
988 const cricket::MediaContentDescription* desc =
989 cricket::GetFirstAudioContentDescription(
990 pc_->remote_description()->description());
991 ASSERT_TRUE(desc != NULL);
992 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
993
994 desc = cricket::GetFirstVideoContentDescription(
995 pc_->remote_description()->description());
996 ASSERT_TRUE(desc != NULL);
997 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
998 }
999
1000 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001001 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001002 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 std::string sdp;
1004 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001005 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001006 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001007 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1009 }
1010
deadbeefab9b2d12015-10-14 11:33:11 -07001011 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001012 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001013 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001014 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001015 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1016 }
1017
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001019 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001020 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021
1022 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1023 // audio codec change, even if the parameter has nothing to do with
1024 // receiving. Not all parameters are serialized to SDP.
1025 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1026 // the SessionDescription, it is necessary to do that here to in order to
1027 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1028 // https://code.google.com/p/webrtc/issues/detail?id=1356
1029 std::string sdp;
1030 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001031 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001032 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001033 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1035 }
1036
1037 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001038 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001039 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040
1041 std::string sdp;
1042 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001043 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001044 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001045 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1047 }
1048
1049 void CreateOfferReceiveAnswer() {
1050 CreateOfferAsLocalDescription();
1051 std::string sdp;
1052 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1053 CreateAnswerAsRemoteDescription(sdp);
1054 }
1055
1056 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001057 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001058 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1060 // audio codec change, even if the parameter has nothing to do with
1061 // receiving. Not all parameters are serialized to SDP.
1062 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1063 // the SessionDescription, it is necessary to do that here to in order to
1064 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1065 // https://code.google.com/p/webrtc/issues/detail?id=1356
1066 std::string sdp;
1067 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001068 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001069 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070
Steve Antondb45ca82017-09-11 18:27:34 -07001071 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001073 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001074 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 }
1076
deadbeefab9b2d12015-10-14 11:33:11 -07001077 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001078 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001079 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001080 ASSERT_TRUE(answer);
1081 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1083 }
1084
deadbeefab9b2d12015-10-14 11:33:11 -07001085 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001086 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001087 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001088 ASSERT_TRUE(pr_answer);
1089 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001091 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001092 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001093 ASSERT_TRUE(answer);
1094 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1096 }
1097
Seth Hampson845e8782018-03-02 11:34:10 -08001098 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001099 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001100 // called with the given stream id and expected number of tracks.
1101 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001102 int expected_num_tracks) {
1103 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001104 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001105 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001106 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 }
1108
1109 // Creates an offer and applies it as a local session description.
1110 // Creates an answer with the same SDP an the offer but removes all lines
1111 // that start with a:ssrc"
1112 void CreateOfferReceiveAnswerWithoutSsrc() {
1113 CreateOfferAsLocalDescription();
1114 std::string sdp;
1115 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1116 SetSsrcToZero(&sdp);
1117 CreateAnswerAsRemoteDescription(sdp);
1118 }
1119
deadbeefab9b2d12015-10-14 11:33:11 -07001120 // This function creates a MediaStream with label kStreams[0] and
1121 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1122 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001123 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001124 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001125 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001126 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1127 size_t number_of_video_tracks) {
1128 EXPECT_LE(number_of_audio_tracks, 2u);
1129 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001130
1131 reference_collection_ = StreamCollection::Create();
1132 std::string sdp_ms1 = std::string(kSdpStringInit);
1133
Seth Hampson845e8782018-03-02 11:34:10 -08001134 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001135
1136 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001137 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001138 reference_collection_->AddStream(stream);
1139
1140 if (number_of_audio_tracks > 0) {
1141 sdp_ms1 += std::string(kSdpStringAudio);
1142 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1143 AddAudioTrack(kAudioTracks[0], stream);
1144 }
1145 if (number_of_audio_tracks > 1) {
1146 sdp_ms1 += kSdpStringMs1Audio1;
1147 AddAudioTrack(kAudioTracks[1], stream);
1148 }
1149
1150 if (number_of_video_tracks > 0) {
1151 sdp_ms1 += std::string(kSdpStringVideo);
1152 sdp_ms1 += std::string(kSdpStringMs1Video0);
1153 AddVideoTrack(kVideoTracks[0], stream);
1154 }
1155 if (number_of_video_tracks > 1) {
1156 sdp_ms1 += kSdpStringMs1Video1;
1157 AddVideoTrack(kVideoTracks[1], stream);
1158 }
1159
kwibergd1fe2812016-04-27 06:47:29 -07001160 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001161 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001162 }
1163
1164 void AddAudioTrack(const std::string& track_id,
1165 MediaStreamInterface* stream) {
1166 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1167 webrtc::AudioTrack::Create(track_id, nullptr));
1168 ASSERT_TRUE(stream->AddTrack(audio_track));
1169 }
1170
1171 void AddVideoTrack(const std::string& track_id,
1172 MediaStreamInterface* stream) {
1173 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001174 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001175 webrtc::FakeVideoTrackSource::Create(),
1176 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001177 ASSERT_TRUE(stream->AddTrack(video_track));
1178 }
1179
Steve Anton36da6ff2018-02-16 16:04:20 -08001180 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001181 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001182 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001183 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001184 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1185 return offer;
1186 }
1187
Steve Anton36da6ff2018-02-16 16:04:20 -08001188 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1189 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001190 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001191 std::unique_ptr<SessionDescriptionInterface> offer;
1192 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1193 return offer;
1194 }
1195
1196 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1197 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1198 std::unique_ptr<SessionDescriptionInterface> answer;
1199 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1200 return answer;
1201 }
1202
kwibergfd8be342016-05-14 19:44:11 -07001203 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001204 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001205 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001206 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001207 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1208 return answer;
1209 }
1210
1211 const std::string& GetFirstAudioStreamCname(
1212 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001213 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001214 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001215 return audio_desc->streams()[0].cname;
1216 }
1217
zhihuang1c378ed2017-08-17 14:10:50 -07001218 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1219 const RTCOfferAnswerOptions& offer_answer_options) {
1220 RTC_DCHECK(pc_);
1221 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1222 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1223 pc_->CreateOffer(observer, offer_answer_options);
1224 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1225 return observer->MoveDescription();
1226 }
1227
1228 void CreateOfferWithOptionsAsRemoteDescription(
1229 std::unique_ptr<SessionDescriptionInterface>* desc,
1230 const RTCOfferAnswerOptions& offer_answer_options) {
1231 *desc = CreateOfferWithOptions(offer_answer_options);
1232 ASSERT_TRUE(desc != nullptr);
1233 std::string sdp;
1234 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001235 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001236 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001237 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001238 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1239 }
1240
1241 void CreateOfferWithOptionsAsLocalDescription(
1242 std::unique_ptr<SessionDescriptionInterface>* desc,
1243 const RTCOfferAnswerOptions& offer_answer_options) {
1244 *desc = CreateOfferWithOptions(offer_answer_options);
1245 ASSERT_TRUE(desc != nullptr);
1246 std::string sdp;
1247 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001248 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001249 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001250
Steve Antondb45ca82017-09-11 18:27:34 -07001251 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001252 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1253 }
1254
1255 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001256 RTC_DCHECK(content);
1257 RTC_DCHECK(content->media_description());
1258 for (const cricket::AudioCodec& codec :
1259 content->media_description()->as_audio()->codecs()) {
1260 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001261 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001262 }
zhihuang1c378ed2017-08-17 14:10:50 -07001263 }
1264 return false;
1265 }
1266
Steve Anton36da6ff2018-02-16 16:04:20 -08001267 const char* GetSdpStringWithStream1() const {
1268 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1269 return kSdpStringWithStream1PlanB;
1270 } else {
1271 return kSdpStringWithStream1UnifiedPlan;
1272 }
1273 }
1274
1275 const char* GetSdpStringWithStream1And2() const {
1276 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1277 return kSdpStringWithStream1And2PlanB;
1278 } else {
1279 return kSdpStringWithStream1And2UnifiedPlan;
1280 }
1281 }
1282
deadbeef9a6f4d42017-05-15 19:43:33 -07001283 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1284 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001285 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001286 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001287 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001288 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1289 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1290 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001292 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001293 const SdpSemantics sdp_semantics_;
1294};
1295
1296class PeerConnectionInterfaceTest
1297 : public PeerConnectionInterfaceBaseTest,
1298 public ::testing::WithParamInterface<SdpSemantics> {
1299 protected:
1300 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1301};
1302
1303class PeerConnectionInterfaceTestPlanB
1304 : public PeerConnectionInterfaceBaseTest {
1305 protected:
1306 PeerConnectionInterfaceTestPlanB()
1307 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308};
1309
zhihuang8f65cdf2016-05-06 18:40:30 -07001310// Generate different CNAMEs when PeerConnections are created.
1311// The CNAMEs are expected to be generated randomly. It is possible
1312// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001313TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001314 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001315 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001316 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001317 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001318 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1319 GetFirstAudioStreamCname(offer2.get()));
1320}
1321
Steve Anton36da6ff2018-02-16 16:04:20 -08001322TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001323 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001324 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001325 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001326 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001327 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1328 GetFirstAudioStreamCname(answer2.get()));
1329}
1330
Steve Anton36da6ff2018-02-16 16:04:20 -08001331TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 CreatePeerConnectionWithDifferentConfigurations) {
1333 CreatePeerConnectionWithDifferentConfigurations();
1334}
1335
Steve Anton36da6ff2018-02-16 16:04:20 -08001336TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001337 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1338 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1339 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1340 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1341 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1342 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1343 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1344 port_allocator_->candidate_filter());
1345 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1346 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1347}
1348
1349// Test that when a PeerConnection is created with a nonzero candidate pool
1350// size, the pooled PortAllocatorSession is created with all the attributes
1351// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001352TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001353 PeerConnectionInterface::RTCConfiguration config;
1354 PeerConnectionInterface::IceServer server;
1355 server.uri = kStunAddressOnly;
1356 config.servers.push_back(server);
1357 config.type = PeerConnectionInterface::kRelay;
1358 config.disable_ipv6 = true;
1359 config.tcp_candidate_policy =
1360 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001361 config.candidate_network_policy =
1362 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001363 config.ice_candidate_pool_size = 1;
1364 CreatePeerConnection(config, nullptr);
1365
1366 const cricket::FakePortAllocatorSession* session =
1367 static_cast<const cricket::FakePortAllocatorSession*>(
1368 port_allocator_->GetPooledSession());
1369 ASSERT_NE(nullptr, session);
1370 EXPECT_EQ(1UL, session->stun_servers().size());
1371 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1372 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001373 EXPECT_LT(0U,
1374 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001375}
1376
deadbeefd21eab32017-07-26 16:50:11 -07001377// Test that network-related RTCConfiguration members are applied to the
1378// PortAllocator when CreatePeerConnection is called. Specifically:
1379// - disable_ipv6_on_wifi
1380// - max_ipv6_networks
1381// - tcp_candidate_policy
1382// - candidate_network_policy
1383// - prune_turn_ports
1384//
1385// Note that the candidate filter (RTCConfiguration::type) is already tested
1386// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001387TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001388 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1389 // Create fake port allocator.
1390 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1391 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1392 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1393
1394 // Create RTCConfiguration with some network-related fields relevant to
1395 // PortAllocator populated.
1396 PeerConnectionInterface::RTCConfiguration config;
1397 config.disable_ipv6_on_wifi = true;
1398 config.max_ipv6_networks = 10;
1399 config.tcp_candidate_policy =
1400 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1401 config.candidate_network_policy =
1402 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1403 config.prune_turn_ports = true;
1404
1405 // Create the PC factory and PC with the above config.
1406 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1407 webrtc::CreatePeerConnectionFactory(
1408 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001409 rtc::Thread::Current(), fake_audio_capture_module_,
1410 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001411 webrtc::CreateBuiltinAudioDecoderFactory(),
1412 webrtc::CreateBuiltinVideoEncoderFactory(),
1413 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1414 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001415 rtc::scoped_refptr<PeerConnectionInterface> pc(
1416 pc_factory->CreatePeerConnection(
1417 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1418
1419 // Now validate that the config fields set above were applied to the
1420 // PortAllocator, as flags or otherwise.
1421 EXPECT_FALSE(raw_port_allocator->flags() &
1422 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1423 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1424 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1425 EXPECT_TRUE(raw_port_allocator->flags() &
1426 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1427 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1428}
1429
deadbeef46c73892016-11-16 19:42:04 -08001430// Check that GetConfiguration returns the configuration the PeerConnection was
1431// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001432TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001433 PeerConnectionInterface::RTCConfiguration config;
1434 config.type = PeerConnectionInterface::kRelay;
1435 CreatePeerConnection(config, nullptr);
1436
1437 PeerConnectionInterface::RTCConfiguration returned_config =
1438 pc_->GetConfiguration();
1439 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1440}
1441
1442// Check that GetConfiguration returns the last configuration passed into
1443// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001444TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001445 CreatePeerConnection();
1446
Steve Anton36da6ff2018-02-16 16:04:20 -08001447 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001448 config.type = PeerConnectionInterface::kRelay;
1449 EXPECT_TRUE(pc_->SetConfiguration(config));
1450
1451 PeerConnectionInterface::RTCConfiguration returned_config =
1452 pc_->GetConfiguration();
1453 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1454}
1455
Steve Antonc79268f2018-04-24 09:54:10 -07001456TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1457 CreatePeerConnection();
1458
1459 pc_->Close();
1460
1461 EXPECT_FALSE(
1462 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1463}
1464
Steve Anton36da6ff2018-02-16 16:04:20 -08001465TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001466 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001467 AddVideoStream(kStreamId1);
1468 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 ASSERT_EQ(2u, pc_->local_streams()->count());
1470
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001471 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001472 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001473 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001474 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001475 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001476 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001478 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001479 EXPECT_EQ(3u, pc_->local_streams()->count());
1480
1481 // Remove the third stream.
1482 pc_->RemoveStream(pc_->local_streams()->at(2));
1483 EXPECT_EQ(2u, pc_->local_streams()->count());
1484
1485 // Remove the second stream.
1486 pc_->RemoveStream(pc_->local_streams()->at(1));
1487 EXPECT_EQ(1u, pc_->local_streams()->count());
1488
1489 // Remove the first stream.
1490 pc_->RemoveStream(pc_->local_streams()->at(0));
1491 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492}
1493
deadbeefab9b2d12015-10-14 11:33:11 -07001494// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001495// Don't run under Unified Plan since the stream API is not available.
1496TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001497 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001498 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001499 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001500 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001501
deadbeefab9b2d12015-10-14 11:33:11 -07001502 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001503 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001504 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001505
deadbeefab9b2d12015-10-14 11:33:11 -07001506 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001507 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001508 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001509
1510 // Add another stream and ensure the offer includes both the old and new
1511 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001512 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001513 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001514
Steve Antonb1c1de12017-12-21 15:14:30 -08001515 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001516 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1517 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001518
Steve Antonb1c1de12017-12-21 15:14:30 -08001519 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001520 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1521 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001522}
1523
Steve Anton36da6ff2018-02-16 16:04:20 -08001524// Don't run under Unified Plan since the stream API is not available.
1525TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001526 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001527 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 ASSERT_EQ(1u, pc_->local_streams()->count());
1529 pc_->RemoveStream(pc_->local_streams()->at(0));
1530 EXPECT_EQ(0u, pc_->local_streams()->count());
1531}
1532
deadbeefe1f9d832016-01-14 15:35:42 -08001533// Test for AddTrack and RemoveTrack methods.
1534// Tests that the created offer includes tracks we added,
1535// and that the RtpSenders are created correctly.
1536// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001537// Only tested with Plan B since Unified Plan is covered in more detail by tests
1538// in peerconnection_jsep_unittests.cc
1539TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001540 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001541 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001542 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001543 rtc::scoped_refptr<VideoTrackInterface> video_track(
1544 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001545 "video_track", pc_factory_->CreateVideoSource(
1546 std::unique_ptr<cricket::VideoCapturer>(
1547 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001548 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1549 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001550 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001551 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001552 EXPECT_EQ("audio_track", audio_sender->id());
1553 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001554 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001555 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001556 EXPECT_EQ("video_track", video_sender->id());
1557 EXPECT_EQ(video_track, video_sender->track());
1558
1559 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001560 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001561 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001562
1563 const cricket::ContentInfo* audio_content =
1564 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001565 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001566 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001567
1568 const cricket::ContentInfo* video_content =
1569 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001570 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001571 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001572
Steve Antondb45ca82017-09-11 18:27:34 -07001573 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001574
1575 // Now try removing the tracks.
1576 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1577 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1578
1579 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001580 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001581
1582 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001583 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001584 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001585
1586 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001587 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001588 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001589
Steve Antondb45ca82017-09-11 18:27:34 -07001590 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001591
1592 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1593 // should return false.
1594 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1595 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1596}
1597
1598// Test creating senders without a stream specified,
1599// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001600TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001601 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001602 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001603 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001604 rtc::scoped_refptr<VideoTrackInterface> video_track(
1605 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001606 "video_track", pc_factory_->CreateVideoSource(
1607 std::unique_ptr<cricket::VideoCapturer>(
1608 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001609 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001610 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001611 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001612 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001613 EXPECT_EQ("audio_track", audio_sender->id());
1614 EXPECT_EQ(audio_track, audio_sender->track());
1615 EXPECT_EQ("video_track", video_sender->id());
1616 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001617 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1618 // If the ID is truly a random GUID, it should be infinitely unlikely they
1619 // will be the same.
1620 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1621 } else {
1622 // We allows creating tracks without stream ids under Unified Plan
1623 // semantics.
1624 EXPECT_EQ(0u, video_sender->stream_ids().size());
1625 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1626 }
deadbeefe1f9d832016-01-14 15:35:42 -08001627}
1628
Harald Alvestrand89061872018-01-02 14:08:34 +01001629// Test that we can call GetStats() after AddTrack but before connecting
1630// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001631TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001632 CreatePeerConnectionWithoutDtls();
1633 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1634 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1635 rtc::scoped_refptr<VideoTrackInterface> video_track(
1636 pc_factory_->CreateVideoTrack(
1637 "video_track", pc_factory_->CreateVideoSource(
1638 std::unique_ptr<cricket::VideoCapturer>(
1639 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001640 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1641 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001642 EXPECT_TRUE(DoGetStats(nullptr));
1643}
1644
Steve Anton36da6ff2018-02-16 16:04:20 -08001645TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001646 CreatePeerConnectionWithoutDtls();
1647 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1648 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1649 rtc::scoped_refptr<VideoTrackInterface> video_track(
1650 pc_factory_->CreateVideoTrack(
1651 "video_track", pc_factory_->CreateVideoSource(
1652 std::unique_ptr<cricket::VideoCapturer>(
1653 new cricket::FakeVideoCapturer()))));
1654 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001655 ASSERT_TRUE(audio_sender.ok());
1656 auto* audio_sender_proxy =
1657 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1658 audio_sender.value().get());
1659 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1660
Harald Alvestrandc72af932018-01-11 17:18:19 +01001661 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001662 ASSERT_TRUE(video_sender.ok());
1663 auto* video_sender_proxy =
1664 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1665 video_sender.value().get());
1666 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001667}
1668
Steve Anton36da6ff2018-02-16 16:04:20 -08001669// Don't run under Unified Plan since the stream API is not available.
1670TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001671 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001672 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001673 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001674 ASSERT_EQ(1u, senders.size());
1675 auto* sender_proxy =
1676 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1677 senders[0].get());
1678 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001679}
1680
Steve Anton36da6ff2018-02-16 16:04:20 -08001681TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001683 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 VerifyRemoteRtpHeaderExtensions();
1685}
1686
Steve Anton36da6ff2018-02-16 16:04:20 -08001687TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001688 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001689 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 CreateOfferAsLocalDescription();
1691 std::string offer;
1692 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1693 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001694 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695}
1696
Steve Anton36da6ff2018-02-16 16:04:20 -08001697TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001698 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001699 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700
1701 CreateOfferAsRemoteDescription();
1702 CreateAnswerAsLocalDescription();
1703
Seth Hampson845e8782018-03-02 11:34:10 -08001704 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705}
1706
Steve Anton36da6ff2018-02-16 16:04:20 -08001707TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001708 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001709 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710
1711 CreateOfferAsRemoteDescription();
1712 CreatePrAnswerAsLocalDescription();
1713 CreateAnswerAsLocalDescription();
1714
Seth Hampson845e8782018-03-02 11:34:10 -08001715 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716}
1717
Steve Anton36da6ff2018-02-16 16:04:20 -08001718// Don't run under Unified Plan since the stream API is not available.
1719TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 InitiateCall();
1721 ASSERT_EQ(1u, pc_->remote_streams()->count());
1722 pc_->RemoveStream(pc_->local_streams()->at(0));
1723 CreateOfferReceiveAnswer();
1724 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001725 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 CreateOfferReceiveAnswer();
1727}
1728
1729// Tests that after negotiating an audio only call, the respondent can perform a
1730// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001731TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001732 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001733 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 CreateOfferAsRemoteDescription();
1735 CreateAnswerAsLocalDescription();
1736
1737 ASSERT_EQ(1u, pc_->remote_streams()->count());
1738 pc_->RemoveStream(pc_->local_streams()->at(0));
1739 CreateOfferReceiveAnswer();
1740 EXPECT_EQ(0u, pc_->remote_streams()->count());
1741}
1742
1743// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001744TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001745 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746
Steve Antonf1c6db12017-10-13 11:13:35 -07001747 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001749 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001750 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001751 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001752 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753
1754 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001755 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001756 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001757 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
Steve Antonf1c6db12017-10-13 11:13:35 -07001759 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001760 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761
Steve Antonf1c6db12017-10-13 11:13:35 -07001762 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763}
1764
deadbeefab9b2d12015-10-14 11:33:11 -07001765// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766// not unique.
Steve Anton36da6ff2018-02-16 16:04:20 -08001767TEST_P(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001768 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001770 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001771 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001772 EXPECT_TRUE(offer);
1773 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774
1775 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001776 AddAudioTrack("track_label", {kStreamId1});
1777 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778
1779 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001780 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781
1782 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001783 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001784 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785}
1786
1787// Test that we will get different SSRCs for each tracks in the offer and answer
1788// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001789TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001790 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001792 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1793 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794
1795 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001796 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001797 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 int audio_ssrc = 0;
1799 int video_ssrc = 0;
1800 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1801 &audio_ssrc));
1802 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1803 &video_ssrc));
1804 EXPECT_NE(audio_ssrc, video_ssrc);
1805
1806 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001807 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001808 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001809 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 audio_ssrc = 0;
1811 video_ssrc = 0;
1812 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1813 &audio_ssrc));
1814 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1815 &video_ssrc));
1816 EXPECT_NE(audio_ssrc, video_ssrc);
1817}
1818
deadbeefeb459812015-12-15 19:24:43 -08001819// Test that it's possible to call AddTrack on a MediaStream after adding
1820// the stream to a PeerConnection.
1821// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001822// Don't run under Unified Plan since the stream API is not available.
1823TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001824 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001825 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001826 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001827 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1828
1829 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001830 rtc::scoped_refptr<VideoTrackInterface> video_track(
1831 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001832 "video_label", pc_factory_->CreateVideoSource(
1833 std::unique_ptr<cricket::VideoCapturer>(
1834 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001835 stream->AddTrack(video_track.get());
1836
kwibergd1fe2812016-04-27 06:47:29 -07001837 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001838 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001839
1840 const cricket::MediaContentDescription* video_desc =
1841 cricket::GetFirstVideoContentDescription(offer->description());
1842 EXPECT_TRUE(video_desc != nullptr);
1843}
1844
1845// Test that it's possible to call RemoveTrack on a MediaStream after adding
1846// the stream to a PeerConnection.
1847// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001848// Don't run under Unified Plan since the stream API is not available.
1849TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001850 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001851 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001852 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001853 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1854
1855 // Remove the video track.
1856 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1857
kwibergd1fe2812016-04-27 06:47:29 -07001858 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001859 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001860
1861 const cricket::MediaContentDescription* video_desc =
1862 cricket::GetFirstVideoContentDescription(offer->description());
1863 EXPECT_TRUE(video_desc == nullptr);
1864}
1865
deadbeef1dcb1642017-03-29 21:08:16 -07001866// Verify that CreateDtmfSender only succeeds if called with a valid local
1867// track. Other aspects of DtmfSenders are tested in
1868// peerconnection_integrationtest.cc.
Steve Anton36da6ff2018-02-16 16:04:20 -08001869TEST_P(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
deadbeef1dcb1642017-03-29 21:08:16 -07001870 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08001871 AddAudioTrack(kAudioTracks[0]);
deadbeef1dcb1642017-03-29 21:08:16 -07001872 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1873 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1874 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1875 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1876}
1877
deadbeefbd7d8f72015-12-18 16:58:44 -08001878// Test creating a sender with a stream ID, and ensure the ID is populated
1879// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001880// Don't run under Unified Plan since the stream API is not available.
1881TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001882 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001883 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001884
kwibergd1fe2812016-04-27 06:47:29 -07001885 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001886 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001887
1888 const cricket::MediaContentDescription* video_desc =
1889 cricket::GetFirstVideoContentDescription(offer->description());
1890 ASSERT_TRUE(video_desc != nullptr);
1891 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001892 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001893}
1894
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001896TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001898 ASSERT_LT(0u, pc_->GetSenders().size());
1899 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001900 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001901 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 EXPECT_TRUE(DoGetStats(remote_audio));
1903
1904 // Remove the stream. Since we are sending to our selves the local
1905 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001906 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 // Do a re-negotiation.
1908 CreateOfferReceiveAnswer();
1909
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 // Test that we still can get statistics for the old track. Even if it is not
1911 // sent any longer.
1912 EXPECT_TRUE(DoGetStats(remote_audio));
1913}
1914
1915// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001916TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001918 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1919 ASSERT_TRUE(video_receiver);
1920 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921}
1922
1923// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001924TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001926 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 pc_factory_->CreateAudioTrack("unknown track", NULL));
1928 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1929}
1930
Steve Anton36da6ff2018-02-16 16:04:20 -08001931TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001932 CreatePeerConnectionWithoutDtls();
1933 EXPECT_TRUE(DoGetRTCStats());
1934 // Clearing stats cache is needed now, but should be temporary.
1935 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1936 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001937 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1938 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001939 EXPECT_TRUE(DoGetRTCStats());
1940 pc_->ClearStatsCache();
1941 CreateOfferReceiveAnswer();
1942 EXPECT_TRUE(DoGetRTCStats());
1943}
1944
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001946TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 FakeConstraints constraints;
1948 constraints.SetAllowRtpDataChannels();
1949 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001950 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001952 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 pc_->CreateDataChannel("test2", NULL);
1954 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001955 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001957 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 new MockDataChannelObserver(data2));
1959
1960 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1961 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1962 std::string data_to_send1 = "testing testing";
1963 std::string data_to_send2 = "testing something else";
1964 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1965
1966 CreateOfferReceiveAnswer();
1967 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1968 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1969
1970 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1971 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1972 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1973 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1974
1975 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1976 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1977
1978 data1->Close();
1979 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1980 CreateOfferReceiveAnswer();
1981 EXPECT_FALSE(observer1->IsOpen());
1982 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1983 EXPECT_TRUE(observer2->IsOpen());
1984
1985 data_to_send2 = "testing something else again";
1986 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1987
1988 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1989}
1990
1991// This test verifies that sendnig binary data over RTP data channels should
1992// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001993TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 FakeConstraints constraints;
1995 constraints.SetAllowRtpDataChannels();
1996 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001997 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001999 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 pc_->CreateDataChannel("test2", NULL);
2001 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002002 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002004 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 new MockDataChannelObserver(data2));
2006
2007 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
2008 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
2009
2010 CreateOfferReceiveAnswer();
2011 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2012 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2013
2014 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2015 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2016
jbaucheec21bd2016-03-20 06:15:43 -07002017 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2019}
2020
2021// This test setup a RTP data channels in loop back and test that a channel is
2022// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002023TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 FakeConstraints constraints;
2025 constraints.SetAllowRtpDataChannels();
2026 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002027 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002029 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 new MockDataChannelObserver(data1));
2031
2032 CreateOfferReceiveAnswerWithoutSsrc();
2033
2034 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2035
2036 data1->Close();
2037 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2038 CreateOfferReceiveAnswerWithoutSsrc();
2039 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2040 EXPECT_FALSE(observer1->IsOpen());
2041}
2042
2043// This test that if a data channel is added in an answer a receive only channel
2044// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002045TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 FakeConstraints constraints;
2047 constraints.SetAllowRtpDataChannels();
2048 CreatePeerConnection(&constraints);
2049
2050 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002051 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 pc_->CreateDataChannel(offer_label, NULL);
2053
2054 CreateOfferAsLocalDescription();
2055
2056 // Replace the data channel label in the offer and apply it as an answer.
2057 std::string receive_label = "answer_channel";
2058 std::string sdp;
2059 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002060 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 receive_label.c_str(), receive_label.length(),
2062 &sdp);
2063 CreateAnswerAsRemoteDescription(sdp);
2064
2065 // Verify that a new incoming data channel has been created and that
2066 // it is open but can't we written to.
2067 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2068 DataChannelInterface* received_channel = observer_.last_datachannel_;
2069 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2070 EXPECT_EQ(receive_label, received_channel->label());
2071 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2072
2073 // Verify that the channel we initially offered has been rejected.
2074 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2075
2076 // Do another offer / answer exchange and verify that the data channel is
2077 // opened.
2078 CreateOfferReceiveAnswer();
2079 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2080 kTimeout);
2081}
2082
2083// This test that no data channel is returned if a reliable channel is
2084// requested.
2085// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002086TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 FakeConstraints constraints;
2088 constraints.SetAllowRtpDataChannels();
2089 CreatePeerConnection(&constraints);
2090
2091 std::string label = "test";
2092 webrtc::DataChannelInit config;
2093 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002094 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 pc_->CreateDataChannel(label, &config);
2096 EXPECT_TRUE(channel == NULL);
2097}
2098
deadbeefab9b2d12015-10-14 11:33:11 -07002099// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002100TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002101 FakeConstraints constraints;
2102 constraints.SetAllowRtpDataChannels();
2103 CreatePeerConnection(&constraints);
2104
2105 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002106 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002107 pc_->CreateDataChannel(label, nullptr);
2108 EXPECT_NE(channel, nullptr);
2109
zhihuang9763d562016-08-05 11:14:50 -07002110 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002111 pc_->CreateDataChannel(label, nullptr);
2112 EXPECT_EQ(dup_channel, nullptr);
2113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115// This tests that a SCTP data channel is returned using different
2116// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002117TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 FakeConstraints constraints;
2119 constraints.SetAllowDtlsSctpDataChannels();
2120 CreatePeerConnection(&constraints);
2121
2122 webrtc::DataChannelInit config;
2123
zhihuang9763d562016-08-05 11:14:50 -07002124 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 pc_->CreateDataChannel("1", &config);
2126 EXPECT_TRUE(channel != NULL);
2127 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002128 EXPECT_TRUE(observer_.renegotiation_needed_);
2129 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
2131 config.ordered = false;
2132 channel = pc_->CreateDataChannel("2", &config);
2133 EXPECT_TRUE(channel != NULL);
2134 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002135 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136
2137 config.ordered = true;
2138 config.maxRetransmits = 0;
2139 channel = pc_->CreateDataChannel("3", &config);
2140 EXPECT_TRUE(channel != NULL);
2141 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002142 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143
2144 config.maxRetransmits = -1;
2145 config.maxRetransmitTime = 0;
2146 channel = pc_->CreateDataChannel("4", &config);
2147 EXPECT_TRUE(channel != NULL);
2148 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002149 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150}
2151
2152// This tests that no data channel is returned if both maxRetransmits and
2153// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002154TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 CreateSctpDataChannelShouldFailForInvalidConfig) {
2156 FakeConstraints constraints;
2157 constraints.SetAllowDtlsSctpDataChannels();
2158 CreatePeerConnection(&constraints);
2159
2160 std::string label = "test";
2161 webrtc::DataChannelInit config;
2162 config.maxRetransmits = 0;
2163 config.maxRetransmitTime = 0;
2164
zhihuang9763d562016-08-05 11:14:50 -07002165 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 pc_->CreateDataChannel(label, &config);
2167 EXPECT_TRUE(channel == NULL);
2168}
2169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170// The test verifies that creating a SCTP data channel with an id already in use
2171// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002172TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 CreateSctpDataChannelWithInvalidIdShouldFail) {
2174 FakeConstraints constraints;
2175 constraints.SetAllowDtlsSctpDataChannels();
2176 CreatePeerConnection(&constraints);
2177
2178 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002179 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002181 config.id = 1;
2182 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 EXPECT_TRUE(channel != NULL);
2184 EXPECT_EQ(1, channel->id());
2185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 channel = pc_->CreateDataChannel("x", &config);
2187 EXPECT_TRUE(channel == NULL);
2188
2189 config.id = cricket::kMaxSctpSid;
2190 channel = pc_->CreateDataChannel("max", &config);
2191 EXPECT_TRUE(channel != NULL);
2192 EXPECT_EQ(config.id, channel->id());
2193
2194 config.id = cricket::kMaxSctpSid + 1;
2195 channel = pc_->CreateDataChannel("x", &config);
2196 EXPECT_TRUE(channel == NULL);
2197}
2198
deadbeefab9b2d12015-10-14 11:33:11 -07002199// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002200TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002201 FakeConstraints constraints;
2202 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2203 true);
2204 CreatePeerConnection(&constraints);
2205
2206 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002207 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002208 pc_->CreateDataChannel(label, nullptr);
2209 EXPECT_NE(channel, nullptr);
2210
zhihuang9763d562016-08-05 11:14:50 -07002211 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002212 pc_->CreateDataChannel(label, nullptr);
2213 EXPECT_NE(dup_channel, nullptr);
2214}
2215
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002216// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2217// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002218TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002219 FakeConstraints constraints;
2220 constraints.SetAllowRtpDataChannels();
2221 CreatePeerConnection(&constraints);
2222
zhihuang9763d562016-08-05 11:14:50 -07002223 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002224 pc_->CreateDataChannel("test1", NULL);
2225 EXPECT_TRUE(observer_.renegotiation_needed_);
2226 observer_.renegotiation_needed_ = false;
2227
zhihuang9763d562016-08-05 11:14:50 -07002228 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002229 pc_->CreateDataChannel("test2", NULL);
2230 EXPECT_TRUE(observer_.renegotiation_needed_);
2231}
2232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002234TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 FakeConstraints constraints;
2236 constraints.SetAllowRtpDataChannels();
2237 CreatePeerConnection(&constraints);
2238
zhihuang9763d562016-08-05 11:14:50 -07002239 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002241 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 pc_->CreateDataChannel("test2", NULL);
2243 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002244 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002246 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 new MockDataChannelObserver(data2));
2248
2249 CreateOfferReceiveAnswer();
2250 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2251 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2252
2253 ReleasePeerConnection();
2254 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2255 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2256}
2257
Zhi Huang644fde42018-04-02 19:16:26 -07002258// This tests that RTP data channels can be rejected in an answer.
2259TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 FakeConstraints constraints;
2261 constraints.SetAllowRtpDataChannels();
2262 CreatePeerConnection(&constraints);
2263
zhihuang9763d562016-08-05 11:14:50 -07002264 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 pc_->CreateDataChannel("offer_channel", NULL));
2266
2267 CreateOfferAsLocalDescription();
2268
2269 // Create an answer where the m-line for data channels are rejected.
2270 std::string sdp;
2271 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002272 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002273 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002274 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002276 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 data_info->rejected = true;
2278
Steve Antondb45ca82017-09-11 18:27:34 -07002279 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2281}
2282
Zhi Huang644fde42018-04-02 19:16:26 -07002283#ifdef HAVE_SCTP
2284// This tests that SCTP data channels can be rejected in an answer.
2285TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2286#else
2287TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2288#endif
2289{
2290 FakeConstraints constraints;
2291 CreatePeerConnection(&constraints);
2292
2293 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2294 pc_->CreateDataChannel("offer_channel", NULL));
2295
2296 CreateOfferAsLocalDescription();
2297
2298 // Create an answer where the m-line for data channels are rejected.
2299 std::string sdp;
2300 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2301 std::unique_ptr<SessionDescriptionInterface> answer(
2302 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2303 ASSERT_TRUE(answer);
2304 cricket::ContentInfo* data_info =
2305 cricket::GetFirstDataContent(answer->description());
2306 data_info->rejected = true;
2307
2308 DoSetRemoteDescription(std::move(answer));
2309 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2310}
2311
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312// Test that we can create a session description from an SDP string from
2313// FireFox, use it as a remote session description, generate an answer and use
2314// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002315TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 FakeConstraints constraints;
2317 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2318 true);
2319 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002320 AddAudioTrack("audio_label");
2321 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002322 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002323 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002324 webrtc::kFireFoxSdpOffer, nullptr));
2325 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 CreateAnswerAsLocalDescription();
2327 ASSERT_TRUE(pc_->local_description() != NULL);
2328 ASSERT_TRUE(pc_->remote_description() != NULL);
2329
2330 const cricket::ContentInfo* content =
2331 cricket::GetFirstAudioContent(pc_->local_description()->description());
2332 ASSERT_TRUE(content != NULL);
2333 EXPECT_FALSE(content->rejected);
2334
2335 content =
2336 cricket::GetFirstVideoContent(pc_->local_description()->description());
2337 ASSERT_TRUE(content != NULL);
2338 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002339#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 content =
2341 cricket::GetFirstDataContent(pc_->local_description()->description());
2342 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002343 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002344#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345}
2346
zhihuangb19012e2017-09-19 13:47:59 -07002347// Test that fallback from DTLS to SDES is not supported.
2348// The fallback was previously supported but was removed to simplify the code
2349// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002350TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
deadbeef8662f942017-01-20 21:20:51 -08002351 FakeConstraints constraints;
2352 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2353 true);
2354 CreatePeerConnection(&constraints);
2355 // Wait for fake certificate to be generated. Previously, this is what caused
2356 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002357 AddAudioTrack("audio_label");
2358 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002359 ASSERT_NE(nullptr, fake_certificate_generator_);
2360 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2361 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002362 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002363 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2364 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002365 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002366}
2367
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368// Test that we can create an audio only offer and receive an answer with a
2369// limited set of audio codecs and receive an updated offer with more audio
2370// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002371TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002372 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002373 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 CreateOfferAsLocalDescription();
2375
Steve Anton36da6ff2018-02-16 16:04:20 -08002376 const char* answer_sdp =
2377 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2378 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002379 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002380 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002381 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382
Steve Anton36da6ff2018-02-16 16:04:20 -08002383 const char* reoffer_sdp =
2384 (sdp_semantics_ == SdpSemantics::kPlanB
2385 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2386 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002387 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002388 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002389 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 CreateAnswerAsLocalDescription();
2391}
2392
deadbeefc80741f2015-10-22 13:14:45 -07002393// Test that if we're receiving (but not sending) a track, subsequent offers
2394// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002395TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002396 FakeConstraints constraints;
2397 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2398 true);
2399 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002400 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002401 CreateAnswerAsLocalDescription();
2402
2403 // At this point we should be receiving stream 1, but not sending anything.
2404 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002405 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002406 DoCreateOffer(&offer, nullptr);
2407
2408 const cricket::ContentInfo* video_content =
2409 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002410 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2411 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002412
2413 const cricket::ContentInfo* audio_content =
2414 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002415 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2416 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002417}
2418
2419// Test that if we're receiving (but not sending) a track, and the
2420// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2421// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002422TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002423 FakeConstraints constraints;
2424 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2425 true);
2426 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002427 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002428 CreateAnswerAsLocalDescription();
2429
2430 // At this point we should be receiving stream 1, but not sending anything.
2431 // A new offer would be recvonly, but we'll set the "no receive" constraints
2432 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002433 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002434 FakeConstraints offer_constraints;
2435 offer_constraints.AddMandatory(
2436 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2437 offer_constraints.AddMandatory(
2438 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2439 DoCreateOffer(&offer, &offer_constraints);
2440
2441 const cricket::ContentInfo* video_content =
2442 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002443 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2444 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002445
2446 const cricket::ContentInfo* audio_content =
2447 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002448 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2449 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002450}
2451
deadbeef653b8e02015-11-11 12:55:10 -08002452// Test that we can use SetConfiguration to change the ICE servers of the
2453// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002454TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002455 CreatePeerConnection();
2456
Steve Anton36da6ff2018-02-16 16:04:20 -08002457 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002458 PeerConnectionInterface::IceServer server;
2459 server.uri = "stun:test_hostname";
2460 config.servers.push_back(server);
2461 EXPECT_TRUE(pc_->SetConfiguration(config));
2462
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002463 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2464 EXPECT_EQ("test_hostname",
2465 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002466}
2467
Steve Anton36da6ff2018-02-16 16:04:20 -08002468TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002469 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002470 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002471 config.type = PeerConnectionInterface::kRelay;
2472 EXPECT_TRUE(pc_->SetConfiguration(config));
2473 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2474}
2475
Steve Anton36da6ff2018-02-16 16:04:20 -08002476TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002477 PeerConnectionInterface::RTCConfiguration config;
2478 config.prune_turn_ports = false;
2479 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002480 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002481 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2482
2483 config.prune_turn_ports = true;
2484 EXPECT_TRUE(pc_->SetConfiguration(config));
2485 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2486}
2487
skvladd1f5fda2017-02-03 16:54:05 -08002488// Test that the ice check interval can be changed. This does not verify that
2489// the setting makes it all the way to P2PTransportChannel, as that would
2490// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002491TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002492 PeerConnectionInterface::RTCConfiguration config;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002493 config.ice_check_min_interval = rtc::nullopt;
skvladd1f5fda2017-02-03 16:54:05 -08002494 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002495 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002496 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002497 EXPECT_TRUE(pc_->SetConfiguration(config));
2498 PeerConnectionInterface::RTCConfiguration new_config =
2499 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002500 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002501}
2502
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002503// Test that when SetConfiguration changes both the pool size and other
2504// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002505TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002506 SetConfigurationCreatesPooledSessionCorrectly) {
2507 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002508 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002509 config.ice_candidate_pool_size = 1;
2510 PeerConnectionInterface::IceServer server;
2511 server.uri = kStunAddressOnly;
2512 config.servers.push_back(server);
2513 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002514 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002515
2516 const cricket::FakePortAllocatorSession* session =
2517 static_cast<const cricket::FakePortAllocatorSession*>(
2518 port_allocator_->GetPooledSession());
2519 ASSERT_NE(nullptr, session);
2520 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002521}
2522
deadbeef293e9262017-01-11 12:28:30 -08002523// Test that after SetLocalDescription, changing the pool size is not allowed,
2524// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002525TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002526 CantChangePoolSizeAfterSetLocalDescription) {
2527 CreatePeerConnection();
2528 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002529 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002530 config.ice_candidate_pool_size = 1;
2531 EXPECT_TRUE(pc_->SetConfiguration(config));
2532
2533 // Set remote offer; can still change pool size at this point.
2534 CreateOfferAsRemoteDescription();
2535 config.ice_candidate_pool_size = 2;
2536 EXPECT_TRUE(pc_->SetConfiguration(config));
2537
2538 // Set local answer; now it's too late.
2539 CreateAnswerAsLocalDescription();
2540 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002541 RTCError error;
2542 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2543 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2544}
2545
deadbeef42a42632017-03-10 15:18:00 -08002546// Test that after setting an answer, extra pooled sessions are discarded. The
2547// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002548TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002549 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2550 CreatePeerConnection();
2551
2552 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002553 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002554 config.ice_candidate_pool_size = 4;
2555 EXPECT_TRUE(pc_->SetConfiguration(config));
2556
2557 // Do offer/answer.
2558 CreateOfferAsRemoteDescription();
2559 CreateAnswerAsLocalDescription();
2560
2561 // Expect no pooled sessions to be left.
2562 const cricket::PortAllocatorSession* session =
2563 port_allocator_->GetPooledSession();
2564 EXPECT_EQ(nullptr, session);
2565}
2566
2567// After Close is called, pooled candidates should be discarded so as to not
2568// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002569TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002570 CreatePeerConnection();
2571
Steve Anton36da6ff2018-02-16 16:04:20 -08002572 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002573 config.ice_candidate_pool_size = 3;
2574 EXPECT_TRUE(pc_->SetConfiguration(config));
2575 pc_->Close();
2576
2577 // Expect no pooled sessions to be left.
2578 const cricket::PortAllocatorSession* session =
2579 port_allocator_->GetPooledSession();
2580 EXPECT_EQ(nullptr, session);
2581}
2582
deadbeef293e9262017-01-11 12:28:30 -08002583// Test that SetConfiguration returns an invalid modification error if
2584// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002585TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002586 SetConfigurationReturnsInvalidModificationError) {
2587 PeerConnectionInterface::RTCConfiguration config;
2588 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2589 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2590 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2591 CreatePeerConnection(config, nullptr);
2592
Steve Anton36da6ff2018-02-16 16:04:20 -08002593 PeerConnectionInterface::RTCConfiguration modified_config =
2594 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002595 modified_config.bundle_policy =
2596 PeerConnectionInterface::kBundlePolicyMaxBundle;
2597 RTCError error;
2598 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2599 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2600
Steve Anton36da6ff2018-02-16 16:04:20 -08002601 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002602 modified_config.rtcp_mux_policy =
2603 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2604 error.set_type(RTCErrorType::NONE);
2605 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2606 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2607
Steve Anton36da6ff2018-02-16 16:04:20 -08002608 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002609 modified_config.continual_gathering_policy =
2610 PeerConnectionInterface::GATHER_CONTINUALLY;
2611 error.set_type(RTCErrorType::NONE);
2612 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2613 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2614}
2615
2616// Test that SetConfiguration returns a range error if the candidate pool size
2617// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002618TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002619 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2620 PeerConnectionInterface::RTCConfiguration config;
2621 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002622 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002623
2624 config.ice_candidate_pool_size = -1;
2625 RTCError error;
2626 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2627 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2628
2629 config.ice_candidate_pool_size = INT_MAX;
2630 error.set_type(RTCErrorType::NONE);
2631 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2632 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2633}
2634
2635// Test that SetConfiguration returns a syntax error if parsing an ICE server
2636// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002637TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002638 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2639 PeerConnectionInterface::RTCConfiguration config;
2640 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002641 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002642
2643 PeerConnectionInterface::IceServer bad_server;
2644 bad_server.uri = "stunn:www.example.com";
2645 config.servers.push_back(bad_server);
2646 RTCError error;
2647 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2648 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2649}
2650
2651// Test that SetConfiguration returns an invalid parameter error if a TURN
2652// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002653TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002654 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2655 PeerConnectionInterface::RTCConfiguration config;
2656 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002657 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002658
2659 PeerConnectionInterface::IceServer bad_server;
2660 bad_server.uri = "turn:www.example.com";
2661 // Missing password.
2662 bad_server.username = "foo";
2663 config.servers.push_back(bad_server);
2664 RTCError error;
2665 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2666 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002667}
2668
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669// Test that PeerConnection::Close changes the states to closed and all remote
2670// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002671TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 // Initialize a PeerConnection and negotiate local and remote session
2673 // description.
2674 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002675
2676 // With Plan B, verify the stream count. The analog with Unified Plan is the
2677 // RtpTransceiver count.
2678 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2679 ASSERT_EQ(1u, pc_->local_streams()->count());
2680 ASSERT_EQ(1u, pc_->remote_streams()->count());
2681 } else {
2682 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2683 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684
2685 pc_->Close();
2686
2687 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2688 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2689 pc_->ice_connection_state());
2690 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2691 pc_->ice_gathering_state());
2692
Steve Anton36da6ff2018-02-16 16:04:20 -08002693 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2694 EXPECT_EQ(1u, pc_->local_streams()->count());
2695 EXPECT_EQ(1u, pc_->remote_streams()->count());
2696 } else {
2697 // Verify that the RtpTransceivers are still present but all stopped.
2698 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2699 for (auto transceiver : pc_->GetTransceivers()) {
2700 EXPECT_TRUE(transceiver->stopped());
2701 }
2702 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703
Steve Anton36da6ff2018-02-16 16:04:20 -08002704 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2705 ASSERT_TRUE(audio_receiver);
2706 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2707 ASSERT_TRUE(video_receiver);
2708
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002709 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002710 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002711 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002712 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002713 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714}
2715
2716// Test that PeerConnection methods fails gracefully after
2717// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002718// Don't run under Unified Plan since the stream API is not available.
2719TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002720 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002721 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722 CreateOfferAsRemoteDescription();
2723 CreateAnswerAsLocalDescription();
2724
2725 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002726 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727 pc_->local_streams()->at(0);
2728
2729 pc_->Close();
2730
2731 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002732 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733
2734 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002735 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002737 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738
2739 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2740
2741 EXPECT_TRUE(pc_->local_description() != NULL);
2742 EXPECT_TRUE(pc_->remote_description() != NULL);
2743
kwibergd1fe2812016-04-27 06:47:29 -07002744 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002745 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002746 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002747 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748
2749 std::string sdp;
2750 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002751 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002752 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002753 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754
2755 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002756 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002757 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002758 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759}
2760
2761// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002762TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763 InitiateCall();
2764 pc_->Close();
2765 DoGetStats(NULL);
2766}
deadbeefab9b2d12015-10-14 11:33:11 -07002767
2768// NOTE: The series of tests below come from what used to be
2769// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2770// setting a remote or local description has the expected effects.
2771
2772// This test verifies that the remote MediaStreams corresponding to a received
2773// SDP string is created. In this test the two separate MediaStreams are
2774// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002775TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
deadbeefab9b2d12015-10-14 11:33:11 -07002776 FakeConstraints constraints;
2777 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2778 true);
2779 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002780 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002781
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002782 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002783 EXPECT_TRUE(
2784 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2785 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2786 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2787
2788 // Create a session description based on another SDP with another
2789 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002790 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002791
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002792 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002793 EXPECT_TRUE(
2794 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2795}
2796
2797// This test verifies that when remote tracks are added/removed from SDP, the
2798// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002799// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2800// specific behavior.
2801TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002802 AddRemoveTrackFromExistingRemoteMediaStream) {
2803 FakeConstraints constraints;
2804 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2805 true);
2806 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002807 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002808 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002809 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002810 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2811 reference_collection_));
2812
2813 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002814 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002815 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002816 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002817 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2818 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002819 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002820 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2821 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002822 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002823 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2824 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002825
2826 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002827 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002828 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002829 MockTrackObserver audio_track_observer(audio_track2);
2830 MockTrackObserver video_track_observer(video_track2);
2831
2832 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2833 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002834 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002835 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2836 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002837 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002838 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002839 audio_track2->state(), kTimeout);
2840 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2841 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002842}
2843
2844// This tests that remote tracks are ended if a local session description is set
2845// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002846TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002847 FakeConstraints constraints;
2848 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2849 true);
2850 CreatePeerConnection(&constraints);
2851 // First create and set a remote offer, then reject its video content in our
2852 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002853 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2854 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2855 ASSERT_TRUE(audio_receiver);
2856 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2857 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002858
Steve Anton36da6ff2018-02-16 16:04:20 -08002859 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2860 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002861 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002862 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2863 video_receiver->track();
2864 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002865
kwibergd1fe2812016-04-27 06:47:29 -07002866 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002867 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002868 cricket::ContentInfo* video_info =
2869 local_answer->description()->GetContentByName("video");
2870 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002871 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002872 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2873 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002874
2875 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002876 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002877 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002878 video_info = local_offer->description()->GetContentByName("video");
2879 ASSERT_TRUE(video_info != nullptr);
2880 video_info->rejected = true;
2881 cricket::ContentInfo* audio_info =
2882 local_offer->description()->GetContentByName("audio");
2883 ASSERT_TRUE(audio_info != nullptr);
2884 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002885 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002886 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002887 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2888 kTimeout);
2889 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2890 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002891}
2892
2893// This tests that we won't crash if the remote track has been removed outside
2894// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002895// Don't run under Unified Plan since the stream API is not available.
2896TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002897 FakeConstraints constraints;
2898 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2899 true);
2900 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002901 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002902 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2903 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2904 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2905
kwibergd1fe2812016-04-27 06:47:29 -07002906 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002907 webrtc::CreateSessionDescription(SdpType::kAnswer,
2908 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002909 cricket::ContentInfo* video_info =
2910 local_answer->description()->GetContentByName("video");
2911 video_info->rejected = true;
2912 cricket::ContentInfo* audio_info =
2913 local_answer->description()->GetContentByName("audio");
2914 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002915 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002916
2917 // No crash is a pass.
2918}
2919
deadbeef5e97fb52015-10-15 12:49:08 -07002920// This tests that if a recvonly remote description is set, no remote streams
2921// will be created, even if the description contains SSRCs/MSIDs.
2922// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002923TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
deadbeef5e97fb52015-10-15 12:49:08 -07002924 FakeConstraints constraints;
2925 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2926 true);
2927 CreatePeerConnection(&constraints);
2928
Steve Anton36da6ff2018-02-16 16:04:20 -08002929 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002930 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2931 strlen(kRecvonly), &recvonly_offer);
2932 CreateAndSetRemoteOffer(recvonly_offer);
2933
2934 EXPECT_EQ(0u, observer_.remote_streams()->count());
2935}
2936
deadbeefab9b2d12015-10-14 11:33:11 -07002937// This tests that a default MediaStream is created if a remote session
2938// description doesn't contain any streams and no MSID support.
2939// It also tests that the default stream is updated if a video m-line is added
2940// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002941// Don't run under Unified Plan since this behavior is Plan B specific.
2942TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002943 FakeConstraints constraints;
2944 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2945 true);
2946 CreatePeerConnection(&constraints);
2947 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2948
2949 ASSERT_EQ(1u, observer_.remote_streams()->count());
2950 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2951
2952 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2953 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002954 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002955
2956 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2957 ASSERT_EQ(1u, observer_.remote_streams()->count());
2958 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2959 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002960 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2961 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002962 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2963 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002964 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2965 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002966}
2967
2968// This tests that a default MediaStream is created if a remote session
2969// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002970// Don't run under Unified Plan since this behavior is Plan B specific.
2971TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002972 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002973 FakeConstraints constraints;
2974 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2975 true);
2976 CreatePeerConnection(&constraints);
2977 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2978
2979 ASSERT_EQ(1u, observer_.remote_streams()->count());
2980 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2981
2982 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2983 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002984 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002985}
2986
2987// This tests that it won't crash when PeerConnection tries to remove
2988// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002989// Don't run under Unified Plan since this behavior is Plan B specific.
2990TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002991 FakeConstraints constraints;
2992 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2993 true);
2994 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002995 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002996 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2997 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2998 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2999
3000 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3001
3002 // No crash is a pass.
3003}
3004
3005// This tests that a default MediaStream is created if the remote session
3006// description doesn't contain any streams and don't contain an indication if
3007// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08003008// Don't run under Unified Plan since this behavior is Plan B specific.
3009TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003010 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003011 FakeConstraints constraints;
3012 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3013 true);
3014 CreatePeerConnection(&constraints);
3015 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3016
3017 ASSERT_EQ(1u, observer_.remote_streams()->count());
3018 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3019 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
3020 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3021}
3022
3023// This tests that a default MediaStream is not created if the remote session
3024// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003025// Don't run under Unified Plan since this behavior is Plan B specific.
3026TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003027 FakeConstraints constraints;
3028 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3029 true);
3030 CreatePeerConnection(&constraints);
3031 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3032 EXPECT_EQ(0u, observer_.remote_streams()->count());
3033}
3034
deadbeefbda7e0b2015-12-08 17:13:40 -08003035// This tests that when setting a new description, the old default tracks are
3036// not destroyed and recreated.
3037// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003038// Don't run under Unified Plan since this behavior is Plan B specific.
3039TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003040 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08003041 FakeConstraints constraints;
3042 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3043 true);
3044 CreatePeerConnection(&constraints);
3045 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3046
3047 ASSERT_EQ(1u, observer_.remote_streams()->count());
3048 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3049 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3050
3051 // Set the track to "disabled", then set a new description and ensure the
3052 // track is still disabled, which ensures it hasn't been recreated.
3053 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3054 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3055 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3056 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3057}
3058
deadbeefab9b2d12015-10-14 11:33:11 -07003059// This tests that a default MediaStream is not created if a remote session
3060// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003061// Don't run under Unified Plan since this behavior is Plan B specific.
3062TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
deadbeefab9b2d12015-10-14 11:33:11 -07003063 FakeConstraints constraints;
3064 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3065 true);
3066 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003067 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003068 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003069 EXPECT_TRUE(
3070 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3071
3072 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3073 EXPECT_EQ(0u, observer_.remote_streams()->count());
3074}
3075
Seth Hampson5897a6e2018-04-03 11:16:33 -07003076// This tests that a default MediaStream is created if a remote SDP comes from
3077// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3078TEST_F(PeerConnectionInterfaceTestPlanB,
3079 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
3080 FakeConstraints constraints;
3081 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3082 true);
3083 CreatePeerConnection(&constraints);
3084 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3085 // Add a=msid lines to simulate a Unified Plan endpoint that only
3086 // signals stream IDs with a=msid lines.
3087 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3088
3089 CreateAndSetRemoteOffer(sdp_string);
3090
3091 ASSERT_EQ(1u, observer_.remote_streams()->count());
3092 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3093 EXPECT_EQ("default", remote_stream->id());
3094 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3095}
3096
Seth Hampson5b4f0752018-04-02 16:31:36 -07003097// This tests that when a Plan B endpoint receives an SDP that signals no media
3098// stream IDs indicated by the special character "-" in the a=msid line, that
3099// a default stream ID will be used for the MediaStream ID. This can occur
3100// when a Unified Plan endpoint signals no media stream IDs, but signals both
3101// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3102TEST_F(PeerConnectionInterfaceTestPlanB,
3103 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
3104 FakeConstraints constraints;
3105 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3106 true);
3107 CreatePeerConnection(&constraints);
3108 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3109 // the sender's stream ID will be interpreted as no stream IDs.
3110 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3111 sdp_string.append("a=msid:- audiotrack0\n");
3112
3113 CreateAndSetRemoteOffer(sdp_string);
3114
3115 ASSERT_EQ(1u, observer_.remote_streams()->count());
3116 // Because SSRCs are signaled the track ID will be what was signaled in the
3117 // a=msid line.
3118 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3119 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3120 EXPECT_EQ("default", remote_stream->id());
3121 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003122
3123 // Previously a bug ocurred when setting the remote description a second time.
3124 // This is because we checked equality of the remote StreamParams stream ID
3125 // (empty), and the previously set stream ID for the remote sender
3126 // ("default"). This cause a track to be removed, then added, when really
3127 // nothing should occur because it is the same track.
3128 CreateAndSetRemoteOffer(sdp_string);
3129 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3130 EXPECT_EQ(1u, observer_.add_track_events_.size());
3131 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3132 remote_stream = observer_.remote_streams()->at(0);
3133 EXPECT_EQ("default", remote_stream->id());
3134 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003135}
3136
deadbeefab9b2d12015-10-14 11:33:11 -07003137// This tests that an RtpSender is created when the local description is set
3138// after adding a local stream.
3139// TODO(deadbeef): This test and the one below it need to be updated when
3140// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003141// Don't run under Unified Plan since this behavior is Plan B specific.
3142TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003143 FakeConstraints constraints;
3144 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3145 true);
3146 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003147
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003148 // Create an offer with 1 stream with 2 tracks of each type.
3149 rtc::scoped_refptr<StreamCollection> stream_collection =
3150 CreateStreamCollection(1, 2);
3151 pc_->AddStream(stream_collection->at(0));
3152 std::unique_ptr<SessionDescriptionInterface> offer;
3153 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003154 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003155
deadbeefab9b2d12015-10-14 11:33:11 -07003156 auto senders = pc_->GetSenders();
3157 EXPECT_EQ(4u, senders.size());
3158 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3159 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3160 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3161 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3162
3163 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003164 pc_->RemoveStream(stream_collection->at(0));
3165 stream_collection = CreateStreamCollection(1, 1);
3166 pc_->AddStream(stream_collection->at(0));
3167 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003168 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003169
deadbeefab9b2d12015-10-14 11:33:11 -07003170 senders = pc_->GetSenders();
3171 EXPECT_EQ(2u, senders.size());
3172 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3173 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3174 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3175 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3176}
3177
3178// This tests that an RtpSender is created when the local description is set
3179// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003180// Don't run under Unified Plan since this behavior is Plan B specific.
3181TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003182 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003183 FakeConstraints constraints;
3184 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3185 true);
3186 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003187
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003188 rtc::scoped_refptr<StreamCollection> stream_collection =
3189 CreateStreamCollection(1, 2);
3190 // Add a stream to create the offer, but remove it afterwards.
3191 pc_->AddStream(stream_collection->at(0));
3192 std::unique_ptr<SessionDescriptionInterface> offer;
3193 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3194 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003195
Steve Antondb45ca82017-09-11 18:27:34 -07003196 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003197 auto senders = pc_->GetSenders();
3198 EXPECT_EQ(0u, senders.size());
3199
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003200 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003201 senders = pc_->GetSenders();
3202 EXPECT_EQ(4u, senders.size());
3203 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3204 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3205 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3206 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3207}
3208
3209// This tests that the expected behavior occurs if the SSRC on a local track is
3210// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003211TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003212 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07003213 FakeConstraints constraints;
3214 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3215 true);
3216 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003217
Steve Anton36da6ff2018-02-16 16:04:20 -08003218 AddAudioTrack(kAudioTracks[0]);
3219 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003220 std::unique_ptr<SessionDescriptionInterface> offer;
3221 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3222 // Grab a copy of the offer before it gets passed into the PC.
Steve Antona3a92c22017-12-07 10:27:41 -08003223 auto modified_offer =
3224 rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003225 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
3226 offer->session_version());
Steve Antondb45ca82017-09-11 18:27:34 -07003227 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003228
deadbeefab9b2d12015-10-14 11:33:11 -07003229 auto senders = pc_->GetSenders();
3230 EXPECT_EQ(2u, senders.size());
3231 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3232 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3233
3234 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003235 cricket::MediaContentDescription* desc =
3236 cricket::GetFirstAudioContentDescription(modified_offer->description());
3237 ASSERT_TRUE(desc != NULL);
3238 for (StreamParams& stream : desc->mutable_streams()) {
3239 for (unsigned int& ssrc : stream.ssrcs) {
3240 ++ssrc;
3241 }
3242 }
deadbeefab9b2d12015-10-14 11:33:11 -07003243
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003244 desc =
3245 cricket::GetFirstVideoContentDescription(modified_offer->description());
3246 ASSERT_TRUE(desc != NULL);
3247 for (StreamParams& stream : desc->mutable_streams()) {
3248 for (unsigned int& ssrc : stream.ssrcs) {
3249 ++ssrc;
3250 }
3251 }
3252
Steve Antondb45ca82017-09-11 18:27:34 -07003253 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003254 senders = pc_->GetSenders();
3255 EXPECT_EQ(2u, senders.size());
3256 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3257 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3258 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3259 // changed.
3260}
3261
3262// This tests that the expected behavior occurs if a new session description is
3263// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003264// Don't run under Unified Plan since the stream API is not available.
3265TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003266 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003267 FakeConstraints constraints;
3268 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3269 true);
3270 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003271
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003272 rtc::scoped_refptr<StreamCollection> stream_collection =
3273 CreateStreamCollection(2, 1);
3274 pc_->AddStream(stream_collection->at(0));
3275 std::unique_ptr<SessionDescriptionInterface> offer;
3276 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003277 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003278
deadbeefab9b2d12015-10-14 11:33:11 -07003279 auto senders = pc_->GetSenders();
3280 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003281 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3282 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003283
3284 // Add a new MediaStream but with the same tracks as in the first stream.
3285 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3286 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003287 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3288 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003289 pc_->AddStream(stream_1);
3290
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003291 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003292 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003293
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003294 auto new_senders = pc_->GetSenders();
3295 // Should be the same senders as before, but with updated stream id.
3296 // Note that this behavior is subject to change in the future.
3297 // We may decide the PC should ignore existing tracks in AddStream.
3298 EXPECT_EQ(senders, new_senders);
3299 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3300 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003301}
3302
zhihuang81c3a032016-11-17 12:06:24 -08003303// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003304TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
zhihuang81c3a032016-11-17 12:06:24 -08003305 FakeConstraints constraints;
3306 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3307 true);
3308 CreatePeerConnection(&constraints);
3309 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3310 EXPECT_EQ(observer_.num_added_tracks_, 1);
3311 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3312
3313 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003314 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3315 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3316 EXPECT_EQ(observer_.num_added_tracks_, 2);
3317 } else {
3318 // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription
3319 // is called until the offer/answer exchange is complete. So in this case
3320 // OnAddTrack is fired twice for the first audio track plus the one time
3321 // for the video track.
3322 EXPECT_EQ(observer_.num_added_tracks_, 3);
3323 }
zhihuang81c3a032016-11-17 12:06:24 -08003324 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3325}
3326
deadbeefd1a38b52016-12-10 13:15:33 -08003327// Test that when SetConfiguration is called and the configuration is
3328// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003329TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003330 PeerConnectionInterface::RTCConfiguration config;
3331 config.type = PeerConnectionInterface::kRelay;
3332 // Need to pass default constraints to prevent disabling of DTLS...
3333 FakeConstraints default_constraints;
3334 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003335 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003336 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3337 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003338
3339 // Do initial offer/answer so there's something to restart.
3340 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003341 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003342
3343 // Grab the ufrags.
3344 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3345
3346 // Change ICE policy, which should trigger an ICE restart on the next offer.
3347 config.type = PeerConnectionInterface::kAll;
3348 EXPECT_TRUE(pc_->SetConfiguration(config));
3349 CreateOfferAsLocalDescription();
3350
3351 // Grab the new ufrags.
3352 std::vector<std::string> subsequent_ufrags =
3353 GetUfrags(pc_->local_description());
3354
3355 // Sanity check.
3356 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3357 // Check that each ufrag is different.
3358 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3359 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3360 }
3361}
3362
3363// Test that when SetConfiguration is called and the configuration *isn't*
3364// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003365TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003366 PeerConnectionInterface::RTCConfiguration config;
3367 config.type = PeerConnectionInterface::kRelay;
3368 // Need to pass default constraints to prevent disabling of DTLS...
3369 FakeConstraints default_constraints;
3370 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003371 config = pc_->GetConfiguration();
3372 AddAudioTrack(kAudioTracks[0]);
3373 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003374
3375 // Do initial offer/answer so there's something to restart.
3376 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003377 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003378
3379 // Grab the ufrags.
3380 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3381
3382 // Call SetConfiguration with a config identical to what the PC was
3383 // constructed with.
3384 EXPECT_TRUE(pc_->SetConfiguration(config));
3385 CreateOfferAsLocalDescription();
3386
3387 // Grab the new ufrags.
3388 std::vector<std::string> subsequent_ufrags =
3389 GetUfrags(pc_->local_description());
3390
3391 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3392}
3393
3394// Test for a weird corner case scenario:
3395// 1. Audio/video session established.
3396// 2. SetConfiguration changes ICE config; ICE restart needed.
3397// 3. ICE restart initiated by remote peer, but only for one m= section.
3398// 4. Next createOffer should initiate an ICE restart, but only for the other
3399// m= section; it would be pointless to do an ICE restart for the m= section
3400// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003401TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003402 PeerConnectionInterface::RTCConfiguration config;
3403 config.type = PeerConnectionInterface::kRelay;
3404 // Need to pass default constraints to prevent disabling of DTLS...
3405 FakeConstraints default_constraints;
3406 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003407 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003408 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3409 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003410
3411 // Do initial offer/answer so there's something to restart.
3412 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003413 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003414
3415 // Change ICE policy, which should set the "needs-ice-restart" flag.
3416 config.type = PeerConnectionInterface::kAll;
3417 EXPECT_TRUE(pc_->SetConfiguration(config));
3418
3419 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003420 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003421 webrtc::CreateSessionDescription(SdpType::kOffer,
3422 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003423 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003424 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3425 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003426 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003427 CreateAnswerAsLocalDescription();
3428
3429 // Grab the ufrags.
3430 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3431 ASSERT_EQ(2, initial_ufrags.size());
3432
3433 // Create offer and grab the new ufrags.
3434 CreateOfferAsLocalDescription();
3435 std::vector<std::string> subsequent_ufrags =
3436 GetUfrags(pc_->local_description());
3437 ASSERT_EQ(2, subsequent_ufrags.size());
3438
3439 // Ensure that only the ufrag for the second m= section changed.
3440 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3441 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3442}
3443
deadbeeffe4a8a42016-12-20 17:56:17 -08003444// Tests that the methods to return current/pending descriptions work as
3445// expected at different points in the offer/answer exchange. This test does
3446// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003447TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003448 // This disables DTLS so we can apply an answer to ourselves.
3449 CreatePeerConnection();
3450
3451 // Create initial local offer and get SDP (which will also be used as
3452 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003453 std::unique_ptr<SessionDescriptionInterface> local_offer;
3454 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003455 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003456 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003457
3458 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003459 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3460 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3461 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003462 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3463 EXPECT_EQ(nullptr, pc_->current_local_description());
3464 EXPECT_EQ(nullptr, pc_->current_remote_description());
3465
3466 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003467 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003468 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003469 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3470 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3471 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3472 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003473 EXPECT_EQ(nullptr, pc_->current_local_description());
3474 EXPECT_EQ(nullptr, pc_->current_remote_description());
3475
3476 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003477 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003478 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003479 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3480 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003481 EXPECT_EQ(nullptr, pc_->pending_local_description());
3482 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003483 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3484 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003485
3486 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003487 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003488 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003489 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3490 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3491 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003492 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003493 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3494 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003495
3496 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003497 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003498 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003499 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3500 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3501 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3502 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3503 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3504 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003505
3506 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003507 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003508 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003509 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3510 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003511 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3512 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003513 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3514 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003515}
3516
zhihuang77985012017-02-07 15:45:16 -08003517// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3518// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003519// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003520TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003521 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003522 CreatePeerConnection();
3523 // The RtcEventLog will be reset when the PeerConnection is closed.
3524 pc_->Close();
3525
Elad Alon9e6565b2017-10-11 16:04:13 +02003526 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3527 std::string filename = webrtc::test::OutputPath() +
3528 test_info->test_case_name() + test_info->name();
3529 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3530
3531 constexpr int64_t max_size_bytes = 1024;
3532
zhihuang77985012017-02-07 15:45:16 -08003533 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3534 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003535
3536 // Cleanup.
3537 rtc::ClosePlatformFile(file);
3538 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003539}
3540
Elad Alon99c3fe52017-10-13 16:29:40 +02003541// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3542// after the PeerConnection is closed.
3543// This version tests the StartRtcEventLog version that receives an object
3544// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003545TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003546 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3547 CreatePeerConnection();
3548 // The RtcEventLog will be reset when the PeerConnection is closed.
3549 pc_->Close();
3550
3551 rtc::PlatformFile file = 0;
3552 int64_t max_size_bytes = 1024;
3553 EXPECT_FALSE(pc_->StartRtcEventLog(
Bjorn Tereliusde939432017-11-20 17:38:14 +01003554 rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
3555 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003556 pc_->StopRtcEventLog();
3557}
3558
deadbeef30952b42017-04-21 02:41:29 -07003559// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003560TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003561 CreatePeerConnection();
3562
3563 // First, create an offer with audio/video.
3564 FakeConstraints constraints;
3565 constraints.SetMandatoryReceiveAudio(true);
3566 constraints.SetMandatoryReceiveVideo(true);
3567 std::unique_ptr<SessionDescriptionInterface> offer;
3568 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3569 cricket::SessionDescription* desc = offer->description();
3570 ASSERT_EQ(2u, desc->transport_infos().size());
3571 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3572 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3573
3574 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003575 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003576 std::unique_ptr<SessionDescriptionInterface> answer;
3577 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3578 desc = answer->description();
3579 ASSERT_EQ(2u, desc->transport_infos().size());
3580 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3581 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3582}
3583
deadbeef1dcb1642017-03-29 21:08:16 -07003584// Test that ICE renomination isn't offered if it's not enabled in the PC's
3585// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003586TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003587 PeerConnectionInterface::RTCConfiguration config;
3588 config.enable_ice_renomination = false;
3589 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003590 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003591
3592 std::unique_ptr<SessionDescriptionInterface> offer;
3593 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3594 cricket::SessionDescription* desc = offer->description();
3595 EXPECT_EQ(1u, desc->transport_infos().size());
3596 EXPECT_FALSE(
3597 desc->transport_infos()[0].description.GetIceParameters().renomination);
3598}
3599
3600// Test that the ICE renomination option is present in generated offers/answers
3601// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003602TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003603 PeerConnectionInterface::RTCConfiguration config;
3604 config.enable_ice_renomination = true;
3605 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003606 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003607
3608 std::unique_ptr<SessionDescriptionInterface> offer;
3609 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3610 cricket::SessionDescription* desc = offer->description();
3611 EXPECT_EQ(1u, desc->transport_infos().size());
3612 EXPECT_TRUE(
3613 desc->transport_infos()[0].description.GetIceParameters().renomination);
3614
3615 // Set the offer as a remote description, then create an answer and ensure it
3616 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003617 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003618 std::unique_ptr<SessionDescriptionInterface> answer;
3619 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3620 desc = answer->description();
3621 EXPECT_EQ(1u, desc->transport_infos().size());
3622 EXPECT_TRUE(
3623 desc->transport_infos()[0].description.GetIceParameters().renomination);
3624}
3625
3626// Test that if CreateOffer is called with the deprecated "offer to receive
3627// audio/video" constraints, they're processed and result in an offer with
3628// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003629TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003630 CreatePeerConnection();
3631
3632 FakeConstraints constraints;
3633 constraints.SetMandatoryReceiveAudio(true);
3634 constraints.SetMandatoryReceiveVideo(true);
3635 std::unique_ptr<SessionDescriptionInterface> offer;
3636 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3637
3638 cricket::SessionDescription* desc = offer->description();
3639 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3640 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3641 ASSERT_NE(nullptr, audio);
3642 ASSERT_NE(nullptr, video);
3643 EXPECT_FALSE(audio->rejected);
3644 EXPECT_FALSE(video->rejected);
3645}
3646
3647// Test that if CreateAnswer is called with the deprecated "offer to receive
3648// audio/video" constraints, they're processed and can be used to reject an
3649// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003650// Don't run under Unified Plan since this behavior is not supported.
3651TEST_F(PeerConnectionInterfaceTestPlanB,
3652 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003653 CreatePeerConnection();
3654
3655 // First, create an offer with audio/video and apply it as a remote
3656 // description.
3657 FakeConstraints constraints;
3658 constraints.SetMandatoryReceiveAudio(true);
3659 constraints.SetMandatoryReceiveVideo(true);
3660 std::unique_ptr<SessionDescriptionInterface> offer;
3661 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
Steve Antondb45ca82017-09-11 18:27:34 -07003662 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003663
3664 // Now create answer that rejects audio/video.
3665 constraints.SetMandatoryReceiveAudio(false);
3666 constraints.SetMandatoryReceiveVideo(false);
3667 std::unique_ptr<SessionDescriptionInterface> answer;
3668 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3669
3670 cricket::SessionDescription* desc = answer->description();
3671 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3672 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3673 ASSERT_NE(nullptr, audio);
3674 ASSERT_NE(nullptr, video);
3675 EXPECT_TRUE(audio->rejected);
3676 EXPECT_TRUE(video->rejected);
3677}
3678
deadbeef1dcb1642017-03-29 21:08:16 -07003679// Test that negotiation can succeed with a data channel only, and with the max
3680// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003681#ifdef HAVE_SCTP
3682TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3683#else
3684TEST_P(PeerConnectionInterfaceTest,
3685 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3686#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003687 PeerConnectionInterface::RTCConfiguration config;
3688 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3689 CreatePeerConnection(config, nullptr);
3690
3691 // First, create an offer with only a data channel and apply it as a remote
3692 // description.
3693 pc_->CreateDataChannel("test", nullptr);
3694 std::unique_ptr<SessionDescriptionInterface> offer;
3695 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003696 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003697
3698 // Create and set answer as well.
3699 std::unique_ptr<SessionDescriptionInterface> answer;
3700 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003701 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003702}
3703
Steve Anton36da6ff2018-02-16 16:04:20 -08003704TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003705 CreatePeerConnection();
3706 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003707 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003708 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3709}
3710
Steve Anton36da6ff2018-02-16 16:04:20 -08003711TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003712 CreatePeerConnection();
3713 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003714 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003715 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3716}
3717
Steve Anton36da6ff2018-02-16 16:04:20 -08003718TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003719 CreatePeerConnection();
3720 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003721 bitrate.min_bitrate_bps = 5;
3722 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003723 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3724}
3725
Steve Anton36da6ff2018-02-16 16:04:20 -08003726TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003727 CreatePeerConnection();
3728 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003729 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003730 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3731}
3732
Steve Anton36da6ff2018-02-16 16:04:20 -08003733TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003734 CreatePeerConnection();
3735 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003736 bitrate.current_bitrate_bps = 10;
3737 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003738 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3739}
3740
Steve Anton36da6ff2018-02-16 16:04:20 -08003741TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003742 CreatePeerConnection();
3743 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003744 bitrate.min_bitrate_bps = 10;
3745 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003746 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3747}
3748
Steve Anton36da6ff2018-02-16 16:04:20 -08003749TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003750 CreatePeerConnection();
3751 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003752 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003753 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3754}
3755
Steve Anton038834f2017-07-14 15:59:59 -07003756// ice_regather_interval_range requires WebRTC to be configured for continual
3757// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003758TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003759 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3760 PeerConnectionInterface::RTCConfiguration config;
3761 config.ice_regather_interval_range.emplace(1000, 2000);
3762 config.continual_gathering_policy =
3763 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3764 CreatePeerConnectionExpectFail(config);
3765}
3766
3767// Ensures that there is no error when ice_regather_interval_range is set with
3768// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003769TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003770 SetIceRegatherIntervalRangeWithContinualGathering) {
3771 PeerConnectionInterface::RTCConfiguration config;
3772 config.ice_regather_interval_range.emplace(1000, 2000);
3773 config.continual_gathering_policy =
3774 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3775 CreatePeerConnection(config, nullptr);
3776}
3777
Niels Möller0c4f7be2018-05-07 14:01:37 +02003778// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003779// by Call's BitrateConstraints, which comes from the SDP or a default value.
3780// This test checks that a call to SetBitrate with a current bitrate that will
3781// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003782TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003783 CreatePeerConnection();
3784 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003785 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003786 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3787}
3788
zhihuang1c378ed2017-08-17 14:10:50 -07003789// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003790TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003791 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3792 RTCOfferAnswerOptions rtc_options;
3793
3794 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3795 // than kMaxOfferToReceiveMedia should be treated as invalid.
3796 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3797 CreatePeerConnection();
3798 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3799
3800 rtc_options.offer_to_receive_audio =
3801 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3802 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3803}
3804
Steve Anton36da6ff2018-02-16 16:04:20 -08003805TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003806 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3807 RTCOfferAnswerOptions rtc_options;
3808
3809 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3810 // than kMaxOfferToReceiveMedia should be treated as invalid.
3811 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3812 CreatePeerConnection();
3813 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3814
3815 rtc_options.offer_to_receive_video =
3816 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3817 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3818}
3819
3820// Test that the audio and video content will be added to an offer if both
3821// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003822TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003823 RTCOfferAnswerOptions rtc_options;
3824 rtc_options.offer_to_receive_audio = 1;
3825 rtc_options.offer_to_receive_video = 1;
3826
3827 std::unique_ptr<SessionDescriptionInterface> offer;
3828 CreatePeerConnection();
3829 offer = CreateOfferWithOptions(rtc_options);
3830 ASSERT_TRUE(offer);
3831 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3832 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3833}
3834
3835// Test that only audio content will be added to the offer if only
3836// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003837TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003838 RTCOfferAnswerOptions rtc_options;
3839 rtc_options.offer_to_receive_audio = 1;
3840 rtc_options.offer_to_receive_video = 0;
3841
3842 std::unique_ptr<SessionDescriptionInterface> offer;
3843 CreatePeerConnection();
3844 offer = CreateOfferWithOptions(rtc_options);
3845 ASSERT_TRUE(offer);
3846 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3847 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3848}
3849
3850// Test that only video content will be added if only |offer_to_receive_video|
3851// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003852TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003853 RTCOfferAnswerOptions rtc_options;
3854 rtc_options.offer_to_receive_audio = 0;
3855 rtc_options.offer_to_receive_video = 1;
3856
3857 std::unique_ptr<SessionDescriptionInterface> offer;
3858 CreatePeerConnection();
3859 offer = CreateOfferWithOptions(rtc_options);
3860 ASSERT_TRUE(offer);
3861 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3862 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3863}
3864
zhihuang1c378ed2017-08-17 14:10:50 -07003865// Test that no media content will be added to the offer if using default
3866// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003867TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003868 RTCOfferAnswerOptions rtc_options;
3869
3870 std::unique_ptr<SessionDescriptionInterface> offer;
3871 CreatePeerConnection();
3872 offer = CreateOfferWithOptions(rtc_options);
3873 ASSERT_TRUE(offer);
3874 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3875 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3876}
3877
3878// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3879// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003880TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3881 CreatePeerConnection();
3882
zhihuang1c378ed2017-08-17 14:10:50 -07003883 RTCOfferAnswerOptions rtc_options;
3884 rtc_options.ice_restart = false;
3885 rtc_options.offer_to_receive_audio = 1;
3886
3887 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003888 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003889 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3890 auto ufrag1 =
3891 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3892 auto pwd1 =
3893 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003894
3895 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3896 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003897 auto ufrag2 =
3898 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3899 auto pwd2 =
3900 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003901
3902 // |ice_restart| is true, the ufrag/pwd should change.
3903 rtc_options.ice_restart = true;
3904 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003905 auto ufrag3 =
3906 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3907 auto pwd3 =
3908 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003909
3910 EXPECT_EQ(ufrag1, ufrag2);
3911 EXPECT_EQ(pwd1, pwd2);
3912 EXPECT_NE(ufrag2, ufrag3);
3913 EXPECT_NE(pwd2, pwd3);
3914}
3915
3916// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3917// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003918TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003919 RTCOfferAnswerOptions rtc_options;
3920 rtc_options.offer_to_receive_audio = 1;
3921 rtc_options.offer_to_receive_video = 1;
3922
3923 std::unique_ptr<SessionDescriptionInterface> offer;
3924 CreatePeerConnection();
3925
3926 rtc_options.use_rtp_mux = true;
3927 offer = CreateOfferWithOptions(rtc_options);
3928 ASSERT_TRUE(offer);
3929 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3930 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3931 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3932
3933 rtc_options.use_rtp_mux = false;
3934 offer = CreateOfferWithOptions(rtc_options);
3935 ASSERT_TRUE(offer);
3936 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3937 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3938 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3939}
3940
zhihuang141aacb2017-08-29 13:23:53 -07003941// This test ensures OnRenegotiationNeeded is called when we add track with
3942// MediaStream -> AddTrack in the same way it is called when we add track with
3943// PeerConnection -> AddTrack.
3944// The test can be removed once addStream is rewritten in terms of addTrack
3945// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003946// Don't run under Unified Plan since the stream API is not available.
3947TEST_F(PeerConnectionInterfaceTestPlanB,
3948 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003949 CreatePeerConnectionWithoutDtls();
3950 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003951 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003952 pc_->AddStream(stream);
3953 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3954 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3955 rtc::scoped_refptr<VideoTrackInterface> video_track(
3956 pc_factory_->CreateVideoTrack(
3957 "video_track", pc_factory_->CreateVideoSource(
3958 std::unique_ptr<cricket::VideoCapturer>(
3959 new cricket::FakeVideoCapturer()))));
3960 stream->AddTrack(audio_track);
3961 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3962 observer_.renegotiation_needed_ = false;
3963
3964 stream->AddTrack(video_track);
3965 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3966 observer_.renegotiation_needed_ = false;
3967
3968 stream->RemoveTrack(audio_track);
3969 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3970 observer_.renegotiation_needed_ = false;
3971
3972 stream->RemoveTrack(video_track);
3973 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3974 observer_.renegotiation_needed_ = false;
3975}
3976
Zhi Huangb2d355e2017-10-26 17:26:37 -07003977// Tests that an error is returned if a description is applied that has fewer
3978// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003979TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003980 MediaSectionCountEnforcedForSubsequentOffer) {
3981 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003982 AddAudioTrack("audio_label");
3983 AddVideoTrack("video_label");
3984
Zhi Huangb2d355e2017-10-26 17:26:37 -07003985 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003986 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003987 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3988
3989 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003990 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003991 offer->description()->contents().pop_back();
3992 offer->description()->contents().pop_back();
3993 ASSERT_TRUE(offer->description()->contents().empty());
3994 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3995
3996 std::unique_ptr<SessionDescriptionInterface> answer;
3997 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3998 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3999
4000 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08004001 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07004002 offer->description()->contents().pop_back();
4003 offer->description()->contents().pop_back();
4004 ASSERT_TRUE(offer->description()->contents().empty());
4005 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
4006}
4007
Steve Anton36da6ff2018-02-16 16:04:20 -08004008INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
4009 PeerConnectionInterfaceTest,
4010 Values(SdpSemantics::kPlanB,
4011 SdpSemantics::kUnifiedPlan));
4012
nisse51542be2016-02-12 02:27:06 -08004013class PeerConnectionMediaConfigTest : public testing::Test {
4014 protected:
4015 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07004016 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08004017 pcf_->Initialize();
4018 }
nisseeaabdf62017-05-05 02:23:02 -07004019 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08004020 const PeerConnectionInterface::RTCConfiguration& config,
zhihuang1c378ed2017-08-17 14:10:50 -07004021 const MediaConstraintsInterface* constraints) {
zhihuang9763d562016-08-05 11:14:50 -07004022 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
4023 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08004024 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07004025 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08004026 }
4027
zhihuang9763d562016-08-05 11:14:50 -07004028 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08004029 MockPeerConnectionObserver observer_;
4030};
4031
4032// This test verifies the default behaviour with no constraints and a
4033// default RTCConfiguration.
4034TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4035 PeerConnectionInterface::RTCConfiguration config;
4036 FakeConstraints constraints;
4037
4038 const cricket::MediaConfig& media_config =
4039 TestCreatePeerConnection(config, &constraints);
4040
4041 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004042 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4043 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004044 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004045 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004046}
4047
4048// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07004049// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004050TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
4051 PeerConnectionInterface::RTCConfiguration config;
4052 FakeConstraints constraints;
4053
4054 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
4055 const cricket::MediaConfig& media_config =
4056 TestCreatePeerConnection(config, &constraints);
4057
4058 EXPECT_TRUE(media_config.enable_dscp);
4059}
4060
4061// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07004062// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004063TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
4064 PeerConnectionInterface::RTCConfiguration config;
4065 FakeConstraints constraints;
4066
4067 constraints.AddOptional(
4068 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
4069 const cricket::MediaConfig media_config =
4070 TestCreatePeerConnection(config, &constraints);
4071
Niels Möller1d7ecd22018-01-18 15:25:12 +01004072 EXPECT_FALSE(media_config.video.enable_cpu_adaptation);
nisse51542be2016-02-12 02:27:06 -08004073}
4074
Niels Möller1d7ecd22018-01-18 15:25:12 +01004075// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004076// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004077TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4078 PeerConnectionInterface::RTCConfiguration config;
4079 FakeConstraints constraints;
4080
Niels Möller71bdda02016-03-31 12:59:59 +02004081 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08004082 const cricket::MediaConfig& media_config =
4083 TestCreatePeerConnection(config, &constraints);
4084
Niels Möller1d7ecd22018-01-18 15:25:12 +01004085 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004086}
4087
Niels Möller6539f692018-01-18 08:58:50 +01004088// This test verifies that the experiment_cpu_load_estimator flag is
4089// propagated from RTCConfiguration to the PeerConnection.
4090TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4091 PeerConnectionInterface::RTCConfiguration config;
4092 FakeConstraints constraints;
4093
4094 config.set_experiment_cpu_load_estimator(true);
4095 const cricket::MediaConfig& media_config =
4096 TestCreatePeerConnection(config, &constraints);
4097
4098 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4099}
4100
nisse0db023a2016-03-01 04:29:59 -08004101// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07004102// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08004103TEST_F(PeerConnectionMediaConfigTest,
4104 TestSuspendBelowMinBitrateConstraintTrue) {
4105 PeerConnectionInterface::RTCConfiguration config;
4106 FakeConstraints constraints;
4107
4108 constraints.AddOptional(
4109 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4110 true);
4111 const cricket::MediaConfig media_config =
4112 TestCreatePeerConnection(config, &constraints);
4113
4114 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08004115}
4116
deadbeef293e9262017-01-11 12:28:30 -08004117// Tests a few random fields being different.
4118TEST(RTCConfigurationTest, ComparisonOperators) {
4119 PeerConnectionInterface::RTCConfiguration a;
4120 PeerConnectionInterface::RTCConfiguration b;
4121 EXPECT_EQ(a, b);
4122
4123 PeerConnectionInterface::RTCConfiguration c;
4124 c.servers.push_back(PeerConnectionInterface::IceServer());
4125 EXPECT_NE(a, c);
4126
4127 PeerConnectionInterface::RTCConfiguration d;
4128 d.type = PeerConnectionInterface::kRelay;
4129 EXPECT_NE(a, d);
4130
4131 PeerConnectionInterface::RTCConfiguration e;
4132 e.audio_jitter_buffer_max_packets = 5;
4133 EXPECT_NE(a, e);
4134
4135 PeerConnectionInterface::RTCConfiguration f;
4136 f.ice_connection_receiving_timeout = 1337;
4137 EXPECT_NE(a, f);
4138
4139 PeerConnectionInterface::RTCConfiguration g;
4140 g.disable_ipv6 = true;
4141 EXPECT_NE(a, g);
4142
4143 PeerConnectionInterface::RTCConfiguration h(
4144 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4145 EXPECT_NE(a, h);
4146}