blob: 799baa641de19b5b14719ff925babe5c4c7efebb [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();
637
henrika919dc2e2017-10-12 14:24:55 +0200638 // Use fake audio device module since we're only testing the interface
639 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700640 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
641 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200642 FakeAudioCaptureModule::Create(), audio_encoder_factory,
643 audio_decoder_factory, nullptr, nullptr, nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100644 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700645
646 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
647 webrtc::CreateCallFactory();
648
649 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
650 webrtc::CreateRtcEventLogFactory();
651
652 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
653 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200654 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700655 std::move(event_log_factory));
656 }
657
658 PeerConnectionFactoryForTest(
659 rtc::Thread* network_thread,
660 rtc::Thread* worker_thread,
661 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700662 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
663 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
664 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
665 : webrtc::PeerConnectionFactory(network_thread,
666 worker_thread,
667 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700668 std::move(media_engine),
669 std::move(call_factory),
670 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800671
deadbeefd7850b22017-08-23 10:59:19 -0700672 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700673};
674
Steve Anton36da6ff2018-02-16 16:04:20 -0800675// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
676class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800678 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
679 : vss_(new rtc::VirtualSocketServer()),
680 main_(vss_.get()),
681 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800682#ifdef WEBRTC_ANDROID
683 webrtc::InitializeAndroidObjects();
684#endif
685 }
686
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700688 // Use fake audio capture module since we're only testing the interface
689 // level, and using a real one could make tests flaky when run in parallel.
690 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700692 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200693 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
694 fake_audio_capture_module_),
695 webrtc::CreateBuiltinAudioEncoderFactory(),
696 webrtc::CreateBuiltinAudioDecoderFactory(),
697 webrtc::CreateBuiltinVideoEncoderFactory(),
698 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
699 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700700 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700701 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700702 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700703 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 }
705
706 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700707 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
deadbeef293e9262017-01-11 12:28:30 -0800710 // DTLS does not work in a loopback call, so is disabled for most of the
711 // tests in this file.
712 void CreatePeerConnectionWithoutDtls() {
713 FakeConstraints no_dtls_constraints;
714 no_dtls_constraints.AddMandatory(
715 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
716
717 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
718 &no_dtls_constraints);
719 }
720
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700722 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
723 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 }
725
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700726 void CreatePeerConnectionWithIceTransportsType(
727 PeerConnectionInterface::IceTransportsType type) {
728 PeerConnectionInterface::RTCConfiguration config;
729 config.type = type;
730 return CreatePeerConnection(config, nullptr);
731 }
732
733 void CreatePeerConnectionWithIceServer(const std::string& uri,
734 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800735 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700737 server.uri = uri;
738 server.password = password;
739 config.servers.push_back(server);
740 CreatePeerConnection(config, nullptr);
741 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100743 void CreatePeerConnection(
744 const PeerConnectionInterface::RTCConfiguration& config,
745 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700746 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800747 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
748 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000749
deadbeef1dcb1642017-03-29 21:08:16 -0700750 // Create certificate generator unless DTLS constraint is explicitly set to
751 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200752 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000753 bool dtls;
754 if (FindConstraint(constraints,
755 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
756 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200757 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800758 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
759 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000760 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800761 RTCConfiguration modified_config = config;
762 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200763 pc_ = pc_factory_->CreatePeerConnection(
Steve Anton36da6ff2018-02-16 16:04:20 -0800764 modified_config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200765 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 ASSERT_TRUE(pc_.get() != NULL);
767 observer_.SetPeerConnectionInterface(pc_.get());
768 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
769 }
770
deadbeef0a6c4ca2015-10-06 11:38:28 -0700771 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800772 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700773 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700774 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800775 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800776 config.sdp_semantics = sdp_semantics_;
777 rtc::scoped_refptr<PeerConnectionInterface> pc =
778 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
779 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800780 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700781 }
782
Steve Anton038834f2017-07-14 15:59:59 -0700783 void CreatePeerConnectionExpectFail(
784 PeerConnectionInterface::RTCConfiguration config) {
785 PeerConnectionInterface::IceServer server;
786 server.uri = kTurnIceServerUri;
787 server.password = kTurnPassword;
788 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800789 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700790 rtc::scoped_refptr<PeerConnectionInterface> pc =
791 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
792 EXPECT_EQ(nullptr, pc);
793 }
794
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700796 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800797 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
798 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
799 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802
deadbeef0a6c4ca2015-10-06 11:38:28 -0700803 CreatePeerConnectionExpectFail(kStunInvalidPort);
804 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
805 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700807 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800808 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
809 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800811 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800813 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800815 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 }
817
818 void ReleasePeerConnection() {
819 pc_ = NULL;
820 observer_.SetPeerConnectionInterface(NULL);
821 }
822
Steve Anton36da6ff2018-02-16 16:04:20 -0800823 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
824 const std::string& label) {
825 auto video_source = pc_factory_->CreateVideoSource(
826 rtc::MakeUnique<cricket::FakeVideoCapturer>(), nullptr);
827 return pc_factory_->CreateVideoTrack(label, video_source);
828 }
829
830 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800831 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800832 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800833 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800834 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
836 observer_.renegotiation_needed_ = false;
837 }
838
Steve Anton36da6ff2018-02-16 16:04:20 -0800839 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700840 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800842 stream->AddTrack(CreateVideoTrack(label + "v0"));
843 ASSERT_TRUE(pc_->AddStream(stream));
844 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
845 observer_.renegotiation_needed_ = false;
846 }
847
848 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
849 const std::string& label) {
850 return pc_factory_->CreateAudioTrack(label, nullptr);
851 }
852
853 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800854 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800855 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800856 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800857 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
858 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
859 observer_.renegotiation_needed_ = false;
860 }
861
862 void AddAudioStream(const std::string& label) {
863 rtc::scoped_refptr<MediaStreamInterface> stream(
864 pc_factory_->CreateLocalMediaStream(label));
865 stream->AddTrack(CreateAudioTrack(label + "a0"));
866 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
868 observer_.renegotiation_needed_ = false;
869 }
870
Seth Hampson845e8782018-03-02 11:34:10 -0800871 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 const std::string& audio_track_label,
873 const std::string& video_track_label) {
874 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700875 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800876 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800877 stream->AddTrack(CreateAudioTrack(audio_track_label));
878 stream->AddTrack(CreateVideoTrack(video_track_label));
879 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
881 observer_.renegotiation_needed_ = false;
882 }
883
Steve Anton36da6ff2018-02-16 16:04:20 -0800884 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
885 cricket::MediaType media_type) {
886 for (auto receiver : pc_->GetReceivers()) {
887 if (receiver->media_type() == media_type) {
888 return receiver;
889 }
890 }
891 return nullptr;
892 }
893
kwibergd1fe2812016-04-27 06:47:29 -0700894 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700895 bool offer,
896 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000897 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
898 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 MockCreateSessionDescriptionObserver>());
900 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700901 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700903 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 }
905 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700906 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 return observer->result();
908 }
909
kwibergd1fe2812016-04-27 06:47:29 -0700910 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700911 MediaConstraintsInterface* constraints) {
912 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 }
914
kwibergd1fe2812016-04-27 06:47:29 -0700915 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700916 MediaConstraintsInterface* constraints) {
917 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 }
919
Steve Antondb45ca82017-09-11 18:27:34 -0700920 bool DoSetSessionDescription(
921 std::unique_ptr<SessionDescriptionInterface> desc,
922 bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000923 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
924 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 MockSetSessionDescriptionObserver>());
926 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700927 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700929 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 }
zhihuang29ff8442016-07-27 11:07:25 -0700931 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
932 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
933 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 return observer->result();
935 }
936
Steve Antondb45ca82017-09-11 18:27:34 -0700937 bool DoSetLocalDescription(
938 std::unique_ptr<SessionDescriptionInterface> desc) {
939 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 }
941
Steve Antondb45ca82017-09-11 18:27:34 -0700942 bool DoSetRemoteDescription(
943 std::unique_ptr<SessionDescriptionInterface> desc) {
944 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 }
946
947 // Calls PeerConnection::GetStats and check the return value.
948 // It does not verify the values in the StatReports since a RTCP packet might
949 // be required.
950 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000951 rtc::scoped_refptr<MockStatsObserver> observer(
952 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000953 if (!pc_->GetStats(
954 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 return false;
956 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
957 return observer->called();
958 }
959
Harald Alvestrand89061872018-01-02 14:08:34 +0100960 // Call the standards-compliant GetStats function.
961 bool DoGetRTCStats() {
962 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
963 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
964 pc_->GetStats(callback);
965 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
966 return callback->called();
967 }
968
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800970 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800972 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800973 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800974 } else {
975 // Unified Plan does not support AddStream, so just add an audio and video
976 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800977 AddAudioTrack(kAudioTracks[0], {kStreamId1});
978 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800979 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 CreateOfferReceiveAnswer();
981 }
982
983 // Verify that RTP Header extensions has been negotiated for audio and video.
984 void VerifyRemoteRtpHeaderExtensions() {
985 const cricket::MediaContentDescription* desc =
986 cricket::GetFirstAudioContentDescription(
987 pc_->remote_description()->description());
988 ASSERT_TRUE(desc != NULL);
989 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
990
991 desc = cricket::GetFirstVideoContentDescription(
992 pc_->remote_description()->description());
993 ASSERT_TRUE(desc != NULL);
994 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
995 }
996
997 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700998 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700999 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 std::string sdp;
1001 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001002 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001003 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001004 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1006 }
1007
deadbeefab9b2d12015-10-14 11:33:11 -07001008 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001009 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001010 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001011 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001012 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1013 }
1014
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001016 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001017 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018
1019 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1020 // audio codec change, even if the parameter has nothing to do with
1021 // receiving. Not all parameters are serialized to SDP.
1022 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1023 // the SessionDescription, it is necessary to do that here to in order to
1024 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1025 // https://code.google.com/p/webrtc/issues/detail?id=1356
1026 std::string sdp;
1027 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001028 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001029 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001030 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1032 }
1033
1034 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001035 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001036 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037
1038 std::string sdp;
1039 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001040 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001041 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001042 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1044 }
1045
1046 void CreateOfferReceiveAnswer() {
1047 CreateOfferAsLocalDescription();
1048 std::string sdp;
1049 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1050 CreateAnswerAsRemoteDescription(sdp);
1051 }
1052
1053 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001054 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001055 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1057 // audio codec change, even if the parameter has nothing to do with
1058 // receiving. Not all parameters are serialized to SDP.
1059 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1060 // the SessionDescription, it is necessary to do that here to in order to
1061 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1062 // https://code.google.com/p/webrtc/issues/detail?id=1356
1063 std::string sdp;
1064 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001065 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001066 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067
Steve Antondb45ca82017-09-11 18:27:34 -07001068 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001070 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001071 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 }
1073
deadbeefab9b2d12015-10-14 11:33:11 -07001074 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001075 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001076 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001077 ASSERT_TRUE(answer);
1078 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1080 }
1081
deadbeefab9b2d12015-10-14 11:33:11 -07001082 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001083 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001084 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001085 ASSERT_TRUE(pr_answer);
1086 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001088 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001089 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001090 ASSERT_TRUE(answer);
1091 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1093 }
1094
Seth Hampson845e8782018-03-02 11:34:10 -08001095 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001096 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001097 // called with the given stream id and expected number of tracks.
1098 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001099 int expected_num_tracks) {
1100 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001101 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001102 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001103 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 }
1105
1106 // Creates an offer and applies it as a local session description.
1107 // Creates an answer with the same SDP an the offer but removes all lines
1108 // that start with a:ssrc"
1109 void CreateOfferReceiveAnswerWithoutSsrc() {
1110 CreateOfferAsLocalDescription();
1111 std::string sdp;
1112 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1113 SetSsrcToZero(&sdp);
1114 CreateAnswerAsRemoteDescription(sdp);
1115 }
1116
deadbeefab9b2d12015-10-14 11:33:11 -07001117 // This function creates a MediaStream with label kStreams[0] and
1118 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1119 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001120 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001121 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001122 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001123 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1124 size_t number_of_video_tracks) {
1125 EXPECT_LE(number_of_audio_tracks, 2u);
1126 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001127
1128 reference_collection_ = StreamCollection::Create();
1129 std::string sdp_ms1 = std::string(kSdpStringInit);
1130
Seth Hampson845e8782018-03-02 11:34:10 -08001131 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001132
1133 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001134 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001135 reference_collection_->AddStream(stream);
1136
1137 if (number_of_audio_tracks > 0) {
1138 sdp_ms1 += std::string(kSdpStringAudio);
1139 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1140 AddAudioTrack(kAudioTracks[0], stream);
1141 }
1142 if (number_of_audio_tracks > 1) {
1143 sdp_ms1 += kSdpStringMs1Audio1;
1144 AddAudioTrack(kAudioTracks[1], stream);
1145 }
1146
1147 if (number_of_video_tracks > 0) {
1148 sdp_ms1 += std::string(kSdpStringVideo);
1149 sdp_ms1 += std::string(kSdpStringMs1Video0);
1150 AddVideoTrack(kVideoTracks[0], stream);
1151 }
1152 if (number_of_video_tracks > 1) {
1153 sdp_ms1 += kSdpStringMs1Video1;
1154 AddVideoTrack(kVideoTracks[1], stream);
1155 }
1156
kwibergd1fe2812016-04-27 06:47:29 -07001157 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001158 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001159 }
1160
1161 void AddAudioTrack(const std::string& track_id,
1162 MediaStreamInterface* stream) {
1163 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1164 webrtc::AudioTrack::Create(track_id, nullptr));
1165 ASSERT_TRUE(stream->AddTrack(audio_track));
1166 }
1167
1168 void AddVideoTrack(const std::string& track_id,
1169 MediaStreamInterface* stream) {
1170 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001171 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001172 webrtc::FakeVideoTrackSource::Create(),
1173 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001174 ASSERT_TRUE(stream->AddTrack(video_track));
1175 }
1176
Steve Anton36da6ff2018-02-16 16:04:20 -08001177 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001178 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001179 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001180 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001181 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1182 return offer;
1183 }
1184
Steve Anton36da6ff2018-02-16 16:04:20 -08001185 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1186 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001187 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001188 std::unique_ptr<SessionDescriptionInterface> offer;
1189 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1190 return offer;
1191 }
1192
1193 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1194 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1195 std::unique_ptr<SessionDescriptionInterface> answer;
1196 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1197 return answer;
1198 }
1199
kwibergfd8be342016-05-14 19:44:11 -07001200 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001201 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001202 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001203 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001204 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1205 return answer;
1206 }
1207
1208 const std::string& GetFirstAudioStreamCname(
1209 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001210 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001211 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001212 return audio_desc->streams()[0].cname;
1213 }
1214
zhihuang1c378ed2017-08-17 14:10:50 -07001215 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1216 const RTCOfferAnswerOptions& offer_answer_options) {
1217 RTC_DCHECK(pc_);
1218 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1219 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1220 pc_->CreateOffer(observer, offer_answer_options);
1221 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1222 return observer->MoveDescription();
1223 }
1224
1225 void CreateOfferWithOptionsAsRemoteDescription(
1226 std::unique_ptr<SessionDescriptionInterface>* desc,
1227 const RTCOfferAnswerOptions& offer_answer_options) {
1228 *desc = CreateOfferWithOptions(offer_answer_options);
1229 ASSERT_TRUE(desc != nullptr);
1230 std::string sdp;
1231 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001232 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001233 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001234 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001235 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1236 }
1237
1238 void CreateOfferWithOptionsAsLocalDescription(
1239 std::unique_ptr<SessionDescriptionInterface>* desc,
1240 const RTCOfferAnswerOptions& offer_answer_options) {
1241 *desc = CreateOfferWithOptions(offer_answer_options);
1242 ASSERT_TRUE(desc != nullptr);
1243 std::string sdp;
1244 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001245 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001246 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001247
Steve Antondb45ca82017-09-11 18:27:34 -07001248 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001249 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1250 }
1251
1252 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001253 RTC_DCHECK(content);
1254 RTC_DCHECK(content->media_description());
1255 for (const cricket::AudioCodec& codec :
1256 content->media_description()->as_audio()->codecs()) {
1257 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001258 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001259 }
zhihuang1c378ed2017-08-17 14:10:50 -07001260 }
1261 return false;
1262 }
1263
Steve Anton36da6ff2018-02-16 16:04:20 -08001264 const char* GetSdpStringWithStream1() const {
1265 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1266 return kSdpStringWithStream1PlanB;
1267 } else {
1268 return kSdpStringWithStream1UnifiedPlan;
1269 }
1270 }
1271
1272 const char* GetSdpStringWithStream1And2() const {
1273 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1274 return kSdpStringWithStream1And2PlanB;
1275 } else {
1276 return kSdpStringWithStream1And2UnifiedPlan;
1277 }
1278 }
1279
deadbeef9a6f4d42017-05-15 19:43:33 -07001280 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1281 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001282 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001283 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001284 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001285 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1286 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1287 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001289 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001290 const SdpSemantics sdp_semantics_;
1291};
1292
1293class PeerConnectionInterfaceTest
1294 : public PeerConnectionInterfaceBaseTest,
1295 public ::testing::WithParamInterface<SdpSemantics> {
1296 protected:
1297 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1298};
1299
1300class PeerConnectionInterfaceTestPlanB
1301 : public PeerConnectionInterfaceBaseTest {
1302 protected:
1303 PeerConnectionInterfaceTestPlanB()
1304 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305};
1306
zhihuang8f65cdf2016-05-06 18:40:30 -07001307// Generate different CNAMEs when PeerConnections are created.
1308// The CNAMEs are expected to be generated randomly. It is possible
1309// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001310TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001311 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001312 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001313 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001314 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001315 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1316 GetFirstAudioStreamCname(offer2.get()));
1317}
1318
Steve Anton36da6ff2018-02-16 16:04:20 -08001319TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001320 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001321 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001322 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001323 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001324 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1325 GetFirstAudioStreamCname(answer2.get()));
1326}
1327
Steve Anton36da6ff2018-02-16 16:04:20 -08001328TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 CreatePeerConnectionWithDifferentConfigurations) {
1330 CreatePeerConnectionWithDifferentConfigurations();
1331}
1332
Steve Anton36da6ff2018-02-16 16:04:20 -08001333TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001334 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1335 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1336 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1337 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1338 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1339 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1340 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1341 port_allocator_->candidate_filter());
1342 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1343 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1344}
1345
1346// Test that when a PeerConnection is created with a nonzero candidate pool
1347// size, the pooled PortAllocatorSession is created with all the attributes
1348// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001349TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001350 PeerConnectionInterface::RTCConfiguration config;
1351 PeerConnectionInterface::IceServer server;
1352 server.uri = kStunAddressOnly;
1353 config.servers.push_back(server);
1354 config.type = PeerConnectionInterface::kRelay;
1355 config.disable_ipv6 = true;
1356 config.tcp_candidate_policy =
1357 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001358 config.candidate_network_policy =
1359 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001360 config.ice_candidate_pool_size = 1;
1361 CreatePeerConnection(config, nullptr);
1362
1363 const cricket::FakePortAllocatorSession* session =
1364 static_cast<const cricket::FakePortAllocatorSession*>(
1365 port_allocator_->GetPooledSession());
1366 ASSERT_NE(nullptr, session);
1367 EXPECT_EQ(1UL, session->stun_servers().size());
1368 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1369 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001370 EXPECT_LT(0U,
1371 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001372}
1373
deadbeefd21eab32017-07-26 16:50:11 -07001374// Test that network-related RTCConfiguration members are applied to the
1375// PortAllocator when CreatePeerConnection is called. Specifically:
1376// - disable_ipv6_on_wifi
1377// - max_ipv6_networks
1378// - tcp_candidate_policy
1379// - candidate_network_policy
1380// - prune_turn_ports
1381//
1382// Note that the candidate filter (RTCConfiguration::type) is already tested
1383// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001384TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001385 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1386 // Create fake port allocator.
1387 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1388 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1389 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1390
1391 // Create RTCConfiguration with some network-related fields relevant to
1392 // PortAllocator populated.
1393 PeerConnectionInterface::RTCConfiguration config;
1394 config.disable_ipv6_on_wifi = true;
1395 config.max_ipv6_networks = 10;
1396 config.tcp_candidate_policy =
1397 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1398 config.candidate_network_policy =
1399 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1400 config.prune_turn_ports = true;
1401
1402 // Create the PC factory and PC with the above config.
1403 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1404 webrtc::CreatePeerConnectionFactory(
1405 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001406 rtc::Thread::Current(), fake_audio_capture_module_,
1407 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001408 webrtc::CreateBuiltinAudioDecoderFactory(),
1409 webrtc::CreateBuiltinVideoEncoderFactory(),
1410 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1411 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001412 rtc::scoped_refptr<PeerConnectionInterface> pc(
1413 pc_factory->CreatePeerConnection(
1414 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1415
1416 // Now validate that the config fields set above were applied to the
1417 // PortAllocator, as flags or otherwise.
1418 EXPECT_FALSE(raw_port_allocator->flags() &
1419 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1420 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1421 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1422 EXPECT_TRUE(raw_port_allocator->flags() &
1423 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1424 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1425}
1426
deadbeef46c73892016-11-16 19:42:04 -08001427// Check that GetConfiguration returns the configuration the PeerConnection was
1428// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001429TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001430 PeerConnectionInterface::RTCConfiguration config;
1431 config.type = PeerConnectionInterface::kRelay;
1432 CreatePeerConnection(config, nullptr);
1433
1434 PeerConnectionInterface::RTCConfiguration returned_config =
1435 pc_->GetConfiguration();
1436 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1437}
1438
1439// Check that GetConfiguration returns the last configuration passed into
1440// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001441TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
deadbeef46c73892016-11-16 19:42:04 -08001442 CreatePeerConnection();
1443
Steve Anton36da6ff2018-02-16 16:04:20 -08001444 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001445 config.type = PeerConnectionInterface::kRelay;
1446 EXPECT_TRUE(pc_->SetConfiguration(config));
1447
1448 PeerConnectionInterface::RTCConfiguration returned_config =
1449 pc_->GetConfiguration();
1450 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1451}
1452
Steve Antonc79268f2018-04-24 09:54:10 -07001453TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1454 CreatePeerConnection();
1455
1456 pc_->Close();
1457
1458 EXPECT_FALSE(
1459 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1460}
1461
Steve Anton36da6ff2018-02-16 16:04:20 -08001462TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001463 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001464 AddVideoStream(kStreamId1);
1465 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 ASSERT_EQ(2u, pc_->local_streams()->count());
1467
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001468 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001469 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001470 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001471 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001472 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001473 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001475 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001476 EXPECT_EQ(3u, pc_->local_streams()->count());
1477
1478 // Remove the third stream.
1479 pc_->RemoveStream(pc_->local_streams()->at(2));
1480 EXPECT_EQ(2u, pc_->local_streams()->count());
1481
1482 // Remove the second stream.
1483 pc_->RemoveStream(pc_->local_streams()->at(1));
1484 EXPECT_EQ(1u, pc_->local_streams()->count());
1485
1486 // Remove the first stream.
1487 pc_->RemoveStream(pc_->local_streams()->at(0));
1488 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489}
1490
deadbeefab9b2d12015-10-14 11:33:11 -07001491// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001492// Don't run under Unified Plan since the stream API is not available.
1493TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001494 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001495 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001496 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001497 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001498
deadbeefab9b2d12015-10-14 11:33:11 -07001499 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001500 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001501 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001502
deadbeefab9b2d12015-10-14 11:33:11 -07001503 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001504 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001505 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001506
1507 // Add another stream and ensure the offer includes both the old and new
1508 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001509 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001510 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001511
Steve Antonb1c1de12017-12-21 15:14:30 -08001512 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001513 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1514 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001515
Steve Antonb1c1de12017-12-21 15:14:30 -08001516 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001517 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1518 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001519}
1520
Steve Anton36da6ff2018-02-16 16:04:20 -08001521// Don't run under Unified Plan since the stream API is not available.
1522TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001523 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001524 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 ASSERT_EQ(1u, pc_->local_streams()->count());
1526 pc_->RemoveStream(pc_->local_streams()->at(0));
1527 EXPECT_EQ(0u, pc_->local_streams()->count());
1528}
1529
deadbeefe1f9d832016-01-14 15:35:42 -08001530// Test for AddTrack and RemoveTrack methods.
1531// Tests that the created offer includes tracks we added,
1532// and that the RtpSenders are created correctly.
1533// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001534// Only tested with Plan B since Unified Plan is covered in more detail by tests
1535// in peerconnection_jsep_unittests.cc
1536TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001537 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001538 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001539 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001540 rtc::scoped_refptr<VideoTrackInterface> video_track(
1541 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001542 "video_track", pc_factory_->CreateVideoSource(
1543 std::unique_ptr<cricket::VideoCapturer>(
1544 new cricket::FakeVideoCapturer()))));
Seth Hampson845e8782018-03-02 11:34:10 -08001545 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1546 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001547 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001548 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001549 EXPECT_EQ("audio_track", audio_sender->id());
1550 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001551 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001552 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001553 EXPECT_EQ("video_track", video_sender->id());
1554 EXPECT_EQ(video_track, video_sender->track());
1555
1556 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001557 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001558 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 const cricket::ContentInfo* audio_content =
1561 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
1565 const cricket::ContentInfo* video_content =
1566 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001567 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001568 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001569
Steve Antondb45ca82017-09-11 18:27:34 -07001570 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001571
1572 // Now try removing the tracks.
1573 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1574 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1575
1576 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001577 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001578
1579 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001580 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001581 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001582
1583 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001584 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001585 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001586
Steve Antondb45ca82017-09-11 18:27:34 -07001587 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001588
1589 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1590 // should return false.
1591 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1592 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1593}
1594
1595// Test creating senders without a stream specified,
1596// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001597TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001598 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001599 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001600 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001601 rtc::scoped_refptr<VideoTrackInterface> video_track(
1602 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001603 "video_track", pc_factory_->CreateVideoSource(
1604 std::unique_ptr<cricket::VideoCapturer>(
1605 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001606 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001607 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001608 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001609 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001610 EXPECT_EQ("audio_track", audio_sender->id());
1611 EXPECT_EQ(audio_track, audio_sender->track());
1612 EXPECT_EQ("video_track", video_sender->id());
1613 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001614 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1615 // If the ID is truly a random GUID, it should be infinitely unlikely they
1616 // will be the same.
1617 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1618 } else {
1619 // We allows creating tracks without stream ids under Unified Plan
1620 // semantics.
1621 EXPECT_EQ(0u, video_sender->stream_ids().size());
1622 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1623 }
deadbeefe1f9d832016-01-14 15:35:42 -08001624}
1625
Harald Alvestrand89061872018-01-02 14:08:34 +01001626// Test that we can call GetStats() after AddTrack but before connecting
1627// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001628TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001629 CreatePeerConnectionWithoutDtls();
1630 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1631 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1632 rtc::scoped_refptr<VideoTrackInterface> video_track(
1633 pc_factory_->CreateVideoTrack(
1634 "video_track", pc_factory_->CreateVideoSource(
1635 std::unique_ptr<cricket::VideoCapturer>(
1636 new cricket::FakeVideoCapturer()))));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001637 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1638 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001639 EXPECT_TRUE(DoGetStats(nullptr));
1640}
1641
Steve Anton36da6ff2018-02-16 16:04:20 -08001642TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001643 CreatePeerConnectionWithoutDtls();
1644 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1645 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1646 rtc::scoped_refptr<VideoTrackInterface> video_track(
1647 pc_factory_->CreateVideoTrack(
1648 "video_track", pc_factory_->CreateVideoSource(
1649 std::unique_ptr<cricket::VideoCapturer>(
1650 new cricket::FakeVideoCapturer()))));
1651 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001652 ASSERT_TRUE(audio_sender.ok());
1653 auto* audio_sender_proxy =
1654 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1655 audio_sender.value().get());
1656 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1657
Harald Alvestrandc72af932018-01-11 17:18:19 +01001658 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001659 ASSERT_TRUE(video_sender.ok());
1660 auto* video_sender_proxy =
1661 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1662 video_sender.value().get());
1663 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001664}
1665
Steve Anton36da6ff2018-02-16 16:04:20 -08001666// Don't run under Unified Plan since the stream API is not available.
1667TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001668 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001669 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001670 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001671 ASSERT_EQ(1u, senders.size());
1672 auto* sender_proxy =
1673 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1674 senders[0].get());
1675 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001676}
1677
Steve Anton36da6ff2018-02-16 16:04:20 -08001678TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001680 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 VerifyRemoteRtpHeaderExtensions();
1682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001685 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001686 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 CreateOfferAsLocalDescription();
1688 std::string offer;
1689 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1690 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001691 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692}
1693
Steve Anton36da6ff2018-02-16 16:04:20 -08001694TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001695 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001696 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697
1698 CreateOfferAsRemoteDescription();
1699 CreateAnswerAsLocalDescription();
1700
Seth Hampson845e8782018-03-02 11:34:10 -08001701 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702}
1703
Steve Anton36da6ff2018-02-16 16:04:20 -08001704TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001705 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001706 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707
1708 CreateOfferAsRemoteDescription();
1709 CreatePrAnswerAsLocalDescription();
1710 CreateAnswerAsLocalDescription();
1711
Seth Hampson845e8782018-03-02 11:34:10 -08001712 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713}
1714
Steve Anton36da6ff2018-02-16 16:04:20 -08001715// Don't run under Unified Plan since the stream API is not available.
1716TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 InitiateCall();
1718 ASSERT_EQ(1u, pc_->remote_streams()->count());
1719 pc_->RemoveStream(pc_->local_streams()->at(0));
1720 CreateOfferReceiveAnswer();
1721 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001722 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 CreateOfferReceiveAnswer();
1724}
1725
1726// Tests that after negotiating an audio only call, the respondent can perform a
1727// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001728TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001729 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001730 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 CreateOfferAsRemoteDescription();
1732 CreateAnswerAsLocalDescription();
1733
1734 ASSERT_EQ(1u, pc_->remote_streams()->count());
1735 pc_->RemoveStream(pc_->local_streams()->at(0));
1736 CreateOfferReceiveAnswer();
1737 EXPECT_EQ(0u, pc_->remote_streams()->count());
1738}
1739
1740// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001741TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001742 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743
Steve Antonf1c6db12017-10-13 11:13:35 -07001744 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001746 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001747 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001748 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001749 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
1751 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001752 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001753 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001754 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755
Steve Antonf1c6db12017-10-13 11:13:35 -07001756 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001757 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
Steve Antonf1c6db12017-10-13 11:13:35 -07001759 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760}
1761
deadbeefab9b2d12015-10-14 11:33:11 -07001762// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763// not unique.
Steve Anton36da6ff2018-02-16 16:04:20 -08001764TEST_P(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001765 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001767 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001768 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001769 EXPECT_TRUE(offer);
1770 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771
1772 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001773 AddAudioTrack("track_label", {kStreamId1});
1774 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775
1776 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001777 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778
1779 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001780 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001781 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782}
1783
1784// Test that we will get different SSRCs for each tracks in the offer and answer
1785// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001786TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001787 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001789 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1790 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791
1792 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001793 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001794 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 int audio_ssrc = 0;
1796 int video_ssrc = 0;
1797 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1798 &audio_ssrc));
1799 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1800 &video_ssrc));
1801 EXPECT_NE(audio_ssrc, video_ssrc);
1802
1803 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001804 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001805 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001806 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 audio_ssrc = 0;
1808 video_ssrc = 0;
1809 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1810 &audio_ssrc));
1811 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1812 &video_ssrc));
1813 EXPECT_NE(audio_ssrc, video_ssrc);
1814}
1815
deadbeefeb459812015-12-15 19:24:43 -08001816// Test that it's possible to call AddTrack on a MediaStream after adding
1817// the stream to a PeerConnection.
1818// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001819// Don't run under Unified Plan since the stream API is not available.
1820TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001821 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001822 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001823 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001824 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1825
1826 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001827 rtc::scoped_refptr<VideoTrackInterface> video_track(
1828 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001829 "video_label", pc_factory_->CreateVideoSource(
1830 std::unique_ptr<cricket::VideoCapturer>(
1831 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001832 stream->AddTrack(video_track.get());
1833
kwibergd1fe2812016-04-27 06:47:29 -07001834 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001835 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001836
1837 const cricket::MediaContentDescription* video_desc =
1838 cricket::GetFirstVideoContentDescription(offer->description());
1839 EXPECT_TRUE(video_desc != nullptr);
1840}
1841
1842// Test that it's possible to call RemoveTrack on a MediaStream after adding
1843// the stream to a PeerConnection.
1844// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001845// Don't run under Unified Plan since the stream API is not available.
1846TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001847 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001848 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001849 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001850 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1851
1852 // Remove the video track.
1853 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1854
kwibergd1fe2812016-04-27 06:47:29 -07001855 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001856 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001857
1858 const cricket::MediaContentDescription* video_desc =
1859 cricket::GetFirstVideoContentDescription(offer->description());
1860 EXPECT_TRUE(video_desc == nullptr);
1861}
1862
deadbeef1dcb1642017-03-29 21:08:16 -07001863// Verify that CreateDtmfSender only succeeds if called with a valid local
1864// track. Other aspects of DtmfSenders are tested in
1865// peerconnection_integrationtest.cc.
Steve Anton36da6ff2018-02-16 16:04:20 -08001866TEST_P(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
deadbeef1dcb1642017-03-29 21:08:16 -07001867 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08001868 AddAudioTrack(kAudioTracks[0]);
deadbeef1dcb1642017-03-29 21:08:16 -07001869 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1870 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1871 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1872 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1873}
1874
deadbeefbd7d8f72015-12-18 16:58:44 -08001875// Test creating a sender with a stream ID, and ensure the ID is populated
1876// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001877// Don't run under Unified Plan since the stream API is not available.
1878TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001879 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001880 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001881
kwibergd1fe2812016-04-27 06:47:29 -07001882 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001883 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001884
1885 const cricket::MediaContentDescription* video_desc =
1886 cricket::GetFirstVideoContentDescription(offer->description());
1887 ASSERT_TRUE(video_desc != nullptr);
1888 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001889 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001890}
1891
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001893TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001895 ASSERT_LT(0u, pc_->GetSenders().size());
1896 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001897 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001898 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 EXPECT_TRUE(DoGetStats(remote_audio));
1900
1901 // Remove the stream. Since we are sending to our selves the local
1902 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001903 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 // Do a re-negotiation.
1905 CreateOfferReceiveAnswer();
1906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 // Test that we still can get statistics for the old track. Even if it is not
1908 // sent any longer.
1909 EXPECT_TRUE(DoGetStats(remote_audio));
1910}
1911
1912// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001913TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001915 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1916 ASSERT_TRUE(video_receiver);
1917 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918}
1919
1920// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001921TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001923 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 pc_factory_->CreateAudioTrack("unknown track", NULL));
1925 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1926}
1927
Steve Anton36da6ff2018-02-16 16:04:20 -08001928TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001929 CreatePeerConnectionWithoutDtls();
1930 EXPECT_TRUE(DoGetRTCStats());
1931 // Clearing stats cache is needed now, but should be temporary.
1932 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1933 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001934 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1935 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001936 EXPECT_TRUE(DoGetRTCStats());
1937 pc_->ClearStatsCache();
1938 CreateOfferReceiveAnswer();
1939 EXPECT_TRUE(DoGetRTCStats());
1940}
1941
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001943TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944 FakeConstraints constraints;
1945 constraints.SetAllowRtpDataChannels();
1946 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001947 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001949 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 pc_->CreateDataChannel("test2", NULL);
1951 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001952 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001954 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 new MockDataChannelObserver(data2));
1956
1957 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1958 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1959 std::string data_to_send1 = "testing testing";
1960 std::string data_to_send2 = "testing something else";
1961 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1962
1963 CreateOfferReceiveAnswer();
1964 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1965 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1966
1967 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1968 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1969 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1970 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1971
1972 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1973 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1974
1975 data1->Close();
1976 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1977 CreateOfferReceiveAnswer();
1978 EXPECT_FALSE(observer1->IsOpen());
1979 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1980 EXPECT_TRUE(observer2->IsOpen());
1981
1982 data_to_send2 = "testing something else again";
1983 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1984
1985 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1986}
1987
1988// This test verifies that sendnig binary data over RTP data channels should
1989// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001990TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 FakeConstraints constraints;
1992 constraints.SetAllowRtpDataChannels();
1993 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001994 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001996 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 pc_->CreateDataChannel("test2", NULL);
1998 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001999 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002001 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 new MockDataChannelObserver(data2));
2003
2004 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
2005 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
2006
2007 CreateOfferReceiveAnswer();
2008 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2009 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2010
2011 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
2012 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
2013
jbaucheec21bd2016-03-20 06:15:43 -07002014 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
2016}
2017
2018// This test setup a RTP data channels in loop back and test that a channel is
2019// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08002020TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 FakeConstraints constraints;
2022 constraints.SetAllowRtpDataChannels();
2023 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07002024 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002026 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 new MockDataChannelObserver(data1));
2028
2029 CreateOfferReceiveAnswerWithoutSsrc();
2030
2031 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2032
2033 data1->Close();
2034 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2035 CreateOfferReceiveAnswerWithoutSsrc();
2036 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2037 EXPECT_FALSE(observer1->IsOpen());
2038}
2039
2040// This test that if a data channel is added in an answer a receive only channel
2041// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002042TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 FakeConstraints constraints;
2044 constraints.SetAllowRtpDataChannels();
2045 CreatePeerConnection(&constraints);
2046
2047 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002048 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 pc_->CreateDataChannel(offer_label, NULL);
2050
2051 CreateOfferAsLocalDescription();
2052
2053 // Replace the data channel label in the offer and apply it as an answer.
2054 std::string receive_label = "answer_channel";
2055 std::string sdp;
2056 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002057 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 receive_label.c_str(), receive_label.length(),
2059 &sdp);
2060 CreateAnswerAsRemoteDescription(sdp);
2061
2062 // Verify that a new incoming data channel has been created and that
2063 // it is open but can't we written to.
2064 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2065 DataChannelInterface* received_channel = observer_.last_datachannel_;
2066 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2067 EXPECT_EQ(receive_label, received_channel->label());
2068 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2069
2070 // Verify that the channel we initially offered has been rejected.
2071 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2072
2073 // Do another offer / answer exchange and verify that the data channel is
2074 // opened.
2075 CreateOfferReceiveAnswer();
2076 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2077 kTimeout);
2078}
2079
2080// This test that no data channel is returned if a reliable channel is
2081// requested.
2082// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002083TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 FakeConstraints constraints;
2085 constraints.SetAllowRtpDataChannels();
2086 CreatePeerConnection(&constraints);
2087
2088 std::string label = "test";
2089 webrtc::DataChannelInit config;
2090 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002091 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 pc_->CreateDataChannel(label, &config);
2093 EXPECT_TRUE(channel == NULL);
2094}
2095
deadbeefab9b2d12015-10-14 11:33:11 -07002096// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002097TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002098 FakeConstraints constraints;
2099 constraints.SetAllowRtpDataChannels();
2100 CreatePeerConnection(&constraints);
2101
2102 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002103 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002104 pc_->CreateDataChannel(label, nullptr);
2105 EXPECT_NE(channel, nullptr);
2106
zhihuang9763d562016-08-05 11:14:50 -07002107 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002108 pc_->CreateDataChannel(label, nullptr);
2109 EXPECT_EQ(dup_channel, nullptr);
2110}
2111
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112// This tests that a SCTP data channel is returned using different
2113// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002114TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 FakeConstraints constraints;
2116 constraints.SetAllowDtlsSctpDataChannels();
2117 CreatePeerConnection(&constraints);
2118
2119 webrtc::DataChannelInit config;
2120
zhihuang9763d562016-08-05 11:14:50 -07002121 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 pc_->CreateDataChannel("1", &config);
2123 EXPECT_TRUE(channel != NULL);
2124 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002125 EXPECT_TRUE(observer_.renegotiation_needed_);
2126 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127
2128 config.ordered = false;
2129 channel = pc_->CreateDataChannel("2", &config);
2130 EXPECT_TRUE(channel != NULL);
2131 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002132 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
2134 config.ordered = true;
2135 config.maxRetransmits = 0;
2136 channel = pc_->CreateDataChannel("3", &config);
2137 EXPECT_TRUE(channel != NULL);
2138 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002139 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140
2141 config.maxRetransmits = -1;
2142 config.maxRetransmitTime = 0;
2143 channel = pc_->CreateDataChannel("4", &config);
2144 EXPECT_TRUE(channel != NULL);
2145 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002146 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147}
2148
2149// This tests that no data channel is returned if both maxRetransmits and
2150// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002151TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 CreateSctpDataChannelShouldFailForInvalidConfig) {
2153 FakeConstraints constraints;
2154 constraints.SetAllowDtlsSctpDataChannels();
2155 CreatePeerConnection(&constraints);
2156
2157 std::string label = "test";
2158 webrtc::DataChannelInit config;
2159 config.maxRetransmits = 0;
2160 config.maxRetransmitTime = 0;
2161
zhihuang9763d562016-08-05 11:14:50 -07002162 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 pc_->CreateDataChannel(label, &config);
2164 EXPECT_TRUE(channel == NULL);
2165}
2166
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167// The test verifies that creating a SCTP data channel with an id already in use
2168// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002169TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 CreateSctpDataChannelWithInvalidIdShouldFail) {
2171 FakeConstraints constraints;
2172 constraints.SetAllowDtlsSctpDataChannels();
2173 CreatePeerConnection(&constraints);
2174
2175 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002176 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002178 config.id = 1;
2179 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 EXPECT_TRUE(channel != NULL);
2181 EXPECT_EQ(1, channel->id());
2182
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 channel = pc_->CreateDataChannel("x", &config);
2184 EXPECT_TRUE(channel == NULL);
2185
2186 config.id = cricket::kMaxSctpSid;
2187 channel = pc_->CreateDataChannel("max", &config);
2188 EXPECT_TRUE(channel != NULL);
2189 EXPECT_EQ(config.id, channel->id());
2190
2191 config.id = cricket::kMaxSctpSid + 1;
2192 channel = pc_->CreateDataChannel("x", &config);
2193 EXPECT_TRUE(channel == NULL);
2194}
2195
deadbeefab9b2d12015-10-14 11:33:11 -07002196// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002197TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
deadbeefab9b2d12015-10-14 11:33:11 -07002198 FakeConstraints constraints;
2199 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2200 true);
2201 CreatePeerConnection(&constraints);
2202
2203 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002204 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002205 pc_->CreateDataChannel(label, nullptr);
2206 EXPECT_NE(channel, nullptr);
2207
zhihuang9763d562016-08-05 11:14:50 -07002208 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002209 pc_->CreateDataChannel(label, nullptr);
2210 EXPECT_NE(dup_channel, nullptr);
2211}
2212
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002213// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2214// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002215TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002216 FakeConstraints constraints;
2217 constraints.SetAllowRtpDataChannels();
2218 CreatePeerConnection(&constraints);
2219
zhihuang9763d562016-08-05 11:14:50 -07002220 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002221 pc_->CreateDataChannel("test1", NULL);
2222 EXPECT_TRUE(observer_.renegotiation_needed_);
2223 observer_.renegotiation_needed_ = false;
2224
zhihuang9763d562016-08-05 11:14:50 -07002225 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002226 pc_->CreateDataChannel("test2", NULL);
2227 EXPECT_TRUE(observer_.renegotiation_needed_);
2228}
2229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002231TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 FakeConstraints constraints;
2233 constraints.SetAllowRtpDataChannels();
2234 CreatePeerConnection(&constraints);
2235
zhihuang9763d562016-08-05 11:14:50 -07002236 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002238 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 pc_->CreateDataChannel("test2", NULL);
2240 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002241 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002243 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 new MockDataChannelObserver(data2));
2245
2246 CreateOfferReceiveAnswer();
2247 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2248 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2249
2250 ReleasePeerConnection();
2251 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2252 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2253}
2254
Zhi Huang644fde42018-04-02 19:16:26 -07002255// This tests that RTP data channels can be rejected in an answer.
2256TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 FakeConstraints constraints;
2258 constraints.SetAllowRtpDataChannels();
2259 CreatePeerConnection(&constraints);
2260
zhihuang9763d562016-08-05 11:14:50 -07002261 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 pc_->CreateDataChannel("offer_channel", NULL));
2263
2264 CreateOfferAsLocalDescription();
2265
2266 // Create an answer where the m-line for data channels are rejected.
2267 std::string sdp;
2268 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002269 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002270 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002271 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002273 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 data_info->rejected = true;
2275
Steve Antondb45ca82017-09-11 18:27:34 -07002276 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2278}
2279
Zhi Huang644fde42018-04-02 19:16:26 -07002280#ifdef HAVE_SCTP
2281// This tests that SCTP data channels can be rejected in an answer.
2282TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2283#else
2284TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2285#endif
2286{
2287 FakeConstraints constraints;
2288 CreatePeerConnection(&constraints);
2289
2290 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2291 pc_->CreateDataChannel("offer_channel", NULL));
2292
2293 CreateOfferAsLocalDescription();
2294
2295 // Create an answer where the m-line for data channels are rejected.
2296 std::string sdp;
2297 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2298 std::unique_ptr<SessionDescriptionInterface> answer(
2299 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2300 ASSERT_TRUE(answer);
2301 cricket::ContentInfo* data_info =
2302 cricket::GetFirstDataContent(answer->description());
2303 data_info->rejected = true;
2304
2305 DoSetRemoteDescription(std::move(answer));
2306 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2307}
2308
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309// Test that we can create a session description from an SDP string from
2310// FireFox, use it as a remote session description, generate an answer and use
2311// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002312TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 FakeConstraints constraints;
2314 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2315 true);
2316 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002317 AddAudioTrack("audio_label");
2318 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002319 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002320 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002321 webrtc::kFireFoxSdpOffer, nullptr));
2322 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 CreateAnswerAsLocalDescription();
2324 ASSERT_TRUE(pc_->local_description() != NULL);
2325 ASSERT_TRUE(pc_->remote_description() != NULL);
2326
2327 const cricket::ContentInfo* content =
2328 cricket::GetFirstAudioContent(pc_->local_description()->description());
2329 ASSERT_TRUE(content != NULL);
2330 EXPECT_FALSE(content->rejected);
2331
2332 content =
2333 cricket::GetFirstVideoContent(pc_->local_description()->description());
2334 ASSERT_TRUE(content != NULL);
2335 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002336#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 content =
2338 cricket::GetFirstDataContent(pc_->local_description()->description());
2339 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002340 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002341#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342}
2343
zhihuangb19012e2017-09-19 13:47:59 -07002344// Test that fallback from DTLS to SDES is not supported.
2345// The fallback was previously supported but was removed to simplify the code
2346// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002347TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
deadbeef8662f942017-01-20 21:20:51 -08002348 FakeConstraints constraints;
2349 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2350 true);
2351 CreatePeerConnection(&constraints);
2352 // Wait for fake certificate to be generated. Previously, this is what caused
2353 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002354 AddAudioTrack("audio_label");
2355 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002356 ASSERT_NE(nullptr, fake_certificate_generator_);
2357 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2358 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002359 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002360 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2361 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002362 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002363}
2364
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365// Test that we can create an audio only offer and receive an answer with a
2366// limited set of audio codecs and receive an updated offer with more audio
2367// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002368TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002369 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002370 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 CreateOfferAsLocalDescription();
2372
Steve Anton36da6ff2018-02-16 16:04:20 -08002373 const char* answer_sdp =
2374 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2375 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002376 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002377 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002378 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
Steve Anton36da6ff2018-02-16 16:04:20 -08002380 const char* reoffer_sdp =
2381 (sdp_semantics_ == SdpSemantics::kPlanB
2382 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2383 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002384 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002385 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002386 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 CreateAnswerAsLocalDescription();
2388}
2389
deadbeefc80741f2015-10-22 13:14:45 -07002390// Test that if we're receiving (but not sending) a track, subsequent offers
2391// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002392TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002393 FakeConstraints constraints;
2394 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2395 true);
2396 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002397 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002398 CreateAnswerAsLocalDescription();
2399
2400 // At this point we should be receiving stream 1, but not sending anything.
2401 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002402 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002403 DoCreateOffer(&offer, nullptr);
2404
2405 const cricket::ContentInfo* video_content =
2406 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002407 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2408 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002409
2410 const cricket::ContentInfo* audio_content =
2411 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002412 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2413 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002414}
2415
2416// Test that if we're receiving (but not sending) a track, and the
2417// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2418// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002419TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
deadbeefc80741f2015-10-22 13:14:45 -07002420 FakeConstraints constraints;
2421 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2422 true);
2423 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002424 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002425 CreateAnswerAsLocalDescription();
2426
2427 // At this point we should be receiving stream 1, but not sending anything.
2428 // A new offer would be recvonly, but we'll set the "no receive" constraints
2429 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002430 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002431 FakeConstraints offer_constraints;
2432 offer_constraints.AddMandatory(
2433 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2434 offer_constraints.AddMandatory(
2435 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2436 DoCreateOffer(&offer, &offer_constraints);
2437
2438 const cricket::ContentInfo* video_content =
2439 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002440 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2441 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002442
2443 const cricket::ContentInfo* audio_content =
2444 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002445 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2446 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002447}
2448
deadbeef653b8e02015-11-11 12:55:10 -08002449// Test that we can use SetConfiguration to change the ICE servers of the
2450// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002451TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002452 CreatePeerConnection();
2453
Steve Anton36da6ff2018-02-16 16:04:20 -08002454 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002455 PeerConnectionInterface::IceServer server;
2456 server.uri = "stun:test_hostname";
2457 config.servers.push_back(server);
2458 EXPECT_TRUE(pc_->SetConfiguration(config));
2459
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002460 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2461 EXPECT_EQ("test_hostname",
2462 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002463}
2464
Steve Anton36da6ff2018-02-16 16:04:20 -08002465TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002466 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002467 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002468 config.type = PeerConnectionInterface::kRelay;
2469 EXPECT_TRUE(pc_->SetConfiguration(config));
2470 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2471}
2472
Steve Anton36da6ff2018-02-16 16:04:20 -08002473TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002474 PeerConnectionInterface::RTCConfiguration config;
2475 config.prune_turn_ports = false;
2476 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002477 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002478 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2479
2480 config.prune_turn_ports = true;
2481 EXPECT_TRUE(pc_->SetConfiguration(config));
2482 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2483}
2484
skvladd1f5fda2017-02-03 16:54:05 -08002485// Test that the ice check interval can be changed. This does not verify that
2486// the setting makes it all the way to P2PTransportChannel, as that would
2487// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002488TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002489 PeerConnectionInterface::RTCConfiguration config;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002490 config.ice_check_min_interval = rtc::nullopt;
skvladd1f5fda2017-02-03 16:54:05 -08002491 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002492 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002493 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002494 EXPECT_TRUE(pc_->SetConfiguration(config));
2495 PeerConnectionInterface::RTCConfiguration new_config =
2496 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002497 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002498}
2499
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002500// Test that when SetConfiguration changes both the pool size and other
2501// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002502TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002503 SetConfigurationCreatesPooledSessionCorrectly) {
2504 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002505 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002506 config.ice_candidate_pool_size = 1;
2507 PeerConnectionInterface::IceServer server;
2508 server.uri = kStunAddressOnly;
2509 config.servers.push_back(server);
2510 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002511 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002512
2513 const cricket::FakePortAllocatorSession* session =
2514 static_cast<const cricket::FakePortAllocatorSession*>(
2515 port_allocator_->GetPooledSession());
2516 ASSERT_NE(nullptr, session);
2517 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002518}
2519
deadbeef293e9262017-01-11 12:28:30 -08002520// Test that after SetLocalDescription, changing the pool size is not allowed,
2521// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002522TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002523 CantChangePoolSizeAfterSetLocalDescription) {
2524 CreatePeerConnection();
2525 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002526 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002527 config.ice_candidate_pool_size = 1;
2528 EXPECT_TRUE(pc_->SetConfiguration(config));
2529
2530 // Set remote offer; can still change pool size at this point.
2531 CreateOfferAsRemoteDescription();
2532 config.ice_candidate_pool_size = 2;
2533 EXPECT_TRUE(pc_->SetConfiguration(config));
2534
2535 // Set local answer; now it's too late.
2536 CreateAnswerAsLocalDescription();
2537 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002538 RTCError error;
2539 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2540 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2541}
2542
deadbeef42a42632017-03-10 15:18:00 -08002543// Test that after setting an answer, extra pooled sessions are discarded. The
2544// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002545TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002546 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2547 CreatePeerConnection();
2548
2549 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002550 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002551 config.ice_candidate_pool_size = 4;
2552 EXPECT_TRUE(pc_->SetConfiguration(config));
2553
2554 // Do offer/answer.
2555 CreateOfferAsRemoteDescription();
2556 CreateAnswerAsLocalDescription();
2557
2558 // Expect no pooled sessions to be left.
2559 const cricket::PortAllocatorSession* session =
2560 port_allocator_->GetPooledSession();
2561 EXPECT_EQ(nullptr, session);
2562}
2563
2564// After Close is called, pooled candidates should be discarded so as to not
2565// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002566TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002567 CreatePeerConnection();
2568
Steve Anton36da6ff2018-02-16 16:04:20 -08002569 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002570 config.ice_candidate_pool_size = 3;
2571 EXPECT_TRUE(pc_->SetConfiguration(config));
2572 pc_->Close();
2573
2574 // Expect no pooled sessions to be left.
2575 const cricket::PortAllocatorSession* session =
2576 port_allocator_->GetPooledSession();
2577 EXPECT_EQ(nullptr, session);
2578}
2579
deadbeef293e9262017-01-11 12:28:30 -08002580// Test that SetConfiguration returns an invalid modification error if
2581// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002582TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002583 SetConfigurationReturnsInvalidModificationError) {
2584 PeerConnectionInterface::RTCConfiguration config;
2585 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2586 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2587 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2588 CreatePeerConnection(config, nullptr);
2589
Steve Anton36da6ff2018-02-16 16:04:20 -08002590 PeerConnectionInterface::RTCConfiguration modified_config =
2591 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002592 modified_config.bundle_policy =
2593 PeerConnectionInterface::kBundlePolicyMaxBundle;
2594 RTCError error;
2595 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2596 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2597
Steve Anton36da6ff2018-02-16 16:04:20 -08002598 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002599 modified_config.rtcp_mux_policy =
2600 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2601 error.set_type(RTCErrorType::NONE);
2602 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2603 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2604
Steve Anton36da6ff2018-02-16 16:04:20 -08002605 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002606 modified_config.continual_gathering_policy =
2607 PeerConnectionInterface::GATHER_CONTINUALLY;
2608 error.set_type(RTCErrorType::NONE);
2609 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2610 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2611}
2612
2613// Test that SetConfiguration returns a range error if the candidate pool size
2614// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002615TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002616 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2617 PeerConnectionInterface::RTCConfiguration config;
2618 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002619 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002620
2621 config.ice_candidate_pool_size = -1;
2622 RTCError error;
2623 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2624 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2625
2626 config.ice_candidate_pool_size = INT_MAX;
2627 error.set_type(RTCErrorType::NONE);
2628 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2629 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2630}
2631
2632// Test that SetConfiguration returns a syntax error if parsing an ICE server
2633// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002634TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002635 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2636 PeerConnectionInterface::RTCConfiguration config;
2637 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002638 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002639
2640 PeerConnectionInterface::IceServer bad_server;
2641 bad_server.uri = "stunn:www.example.com";
2642 config.servers.push_back(bad_server);
2643 RTCError error;
2644 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2645 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2646}
2647
2648// Test that SetConfiguration returns an invalid parameter error if a TURN
2649// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002650TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002651 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2652 PeerConnectionInterface::RTCConfiguration config;
2653 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08002654 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002655
2656 PeerConnectionInterface::IceServer bad_server;
2657 bad_server.uri = "turn:www.example.com";
2658 // Missing password.
2659 bad_server.username = "foo";
2660 config.servers.push_back(bad_server);
2661 RTCError error;
2662 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2663 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002664}
2665
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666// Test that PeerConnection::Close changes the states to closed and all remote
2667// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002668TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669 // Initialize a PeerConnection and negotiate local and remote session
2670 // description.
2671 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002672
2673 // With Plan B, verify the stream count. The analog with Unified Plan is the
2674 // RtpTransceiver count.
2675 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2676 ASSERT_EQ(1u, pc_->local_streams()->count());
2677 ASSERT_EQ(1u, pc_->remote_streams()->count());
2678 } else {
2679 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2680 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681
2682 pc_->Close();
2683
2684 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2685 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2686 pc_->ice_connection_state());
2687 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2688 pc_->ice_gathering_state());
2689
Steve Anton36da6ff2018-02-16 16:04:20 -08002690 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2691 EXPECT_EQ(1u, pc_->local_streams()->count());
2692 EXPECT_EQ(1u, pc_->remote_streams()->count());
2693 } else {
2694 // Verify that the RtpTransceivers are still present but all stopped.
2695 EXPECT_EQ(2u, pc_->GetTransceivers().size());
2696 for (auto transceiver : pc_->GetTransceivers()) {
2697 EXPECT_TRUE(transceiver->stopped());
2698 }
2699 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700
Steve Anton36da6ff2018-02-16 16:04:20 -08002701 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2702 ASSERT_TRUE(audio_receiver);
2703 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2704 ASSERT_TRUE(video_receiver);
2705
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002706 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002707 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002708 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002709 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002710 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711}
2712
2713// Test that PeerConnection methods fails gracefully after
2714// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002715// Don't run under Unified Plan since the stream API is not available.
2716TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002717 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002718 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 CreateOfferAsRemoteDescription();
2720 CreateAnswerAsLocalDescription();
2721
2722 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002723 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724 pc_->local_streams()->at(0);
2725
2726 pc_->Close();
2727
2728 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002729 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730
2731 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002732 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002734 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735
2736 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2737
2738 EXPECT_TRUE(pc_->local_description() != NULL);
2739 EXPECT_TRUE(pc_->remote_description() != NULL);
2740
kwibergd1fe2812016-04-27 06:47:29 -07002741 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002742 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002743 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002744 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002745
2746 std::string sdp;
2747 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002748 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002749 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002750 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751
2752 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002753 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002754 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002755 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756}
2757
2758// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002759TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760 InitiateCall();
2761 pc_->Close();
2762 DoGetStats(NULL);
2763}
deadbeefab9b2d12015-10-14 11:33:11 -07002764
2765// NOTE: The series of tests below come from what used to be
2766// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2767// setting a remote or local description has the expected effects.
2768
2769// This test verifies that the remote MediaStreams corresponding to a received
2770// SDP string is created. In this test the two separate MediaStreams are
2771// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002772TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
deadbeefab9b2d12015-10-14 11:33:11 -07002773 FakeConstraints constraints;
2774 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2775 true);
2776 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002777 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002778
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002779 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002780 EXPECT_TRUE(
2781 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2782 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2783 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2784
2785 // Create a session description based on another SDP with another
2786 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002787 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002788
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002789 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002790 EXPECT_TRUE(
2791 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2792}
2793
2794// This test verifies that when remote tracks are added/removed from SDP, the
2795// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002796// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2797// specific behavior.
2798TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002799 AddRemoveTrackFromExistingRemoteMediaStream) {
2800 FakeConstraints constraints;
2801 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2802 true);
2803 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002804 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002805 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002806 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002807 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2808 reference_collection_));
2809
2810 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002811 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002812 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002813 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002814 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2815 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002816 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002817 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2818 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002819 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002820 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2821 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002822
2823 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002824 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002825 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002826 MockTrackObserver audio_track_observer(audio_track2);
2827 MockTrackObserver video_track_observer(video_track2);
2828
2829 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2830 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002831 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002832 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2833 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002834 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002835 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002836 audio_track2->state(), kTimeout);
2837 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2838 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002839}
2840
2841// This tests that remote tracks are ended if a local session description is set
2842// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002843TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002844 FakeConstraints constraints;
2845 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2846 true);
2847 CreatePeerConnection(&constraints);
2848 // First create and set a remote offer, then reject its video content in our
2849 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002850 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2851 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2852 ASSERT_TRUE(audio_receiver);
2853 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2854 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002855
Steve Anton36da6ff2018-02-16 16:04:20 -08002856 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2857 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002858 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002859 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2860 video_receiver->track();
2861 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002862
kwibergd1fe2812016-04-27 06:47:29 -07002863 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002864 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002865 cricket::ContentInfo* video_info =
2866 local_answer->description()->GetContentByName("video");
2867 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002868 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002869 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2870 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002871
2872 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002873 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002874 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002875 video_info = local_offer->description()->GetContentByName("video");
2876 ASSERT_TRUE(video_info != nullptr);
2877 video_info->rejected = true;
2878 cricket::ContentInfo* audio_info =
2879 local_offer->description()->GetContentByName("audio");
2880 ASSERT_TRUE(audio_info != nullptr);
2881 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002882 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002883 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002884 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2885 kTimeout);
2886 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2887 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002888}
2889
2890// This tests that we won't crash if the remote track has been removed outside
2891// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002892// Don't run under Unified Plan since the stream API is not available.
2893TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
deadbeefab9b2d12015-10-14 11:33:11 -07002894 FakeConstraints constraints;
2895 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2896 true);
2897 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002898 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002899 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2900 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2901 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2902
kwibergd1fe2812016-04-27 06:47:29 -07002903 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002904 webrtc::CreateSessionDescription(SdpType::kAnswer,
2905 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002906 cricket::ContentInfo* video_info =
2907 local_answer->description()->GetContentByName("video");
2908 video_info->rejected = true;
2909 cricket::ContentInfo* audio_info =
2910 local_answer->description()->GetContentByName("audio");
2911 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002912 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002913
2914 // No crash is a pass.
2915}
2916
deadbeef5e97fb52015-10-15 12:49:08 -07002917// This tests that if a recvonly remote description is set, no remote streams
2918// will be created, even if the description contains SSRCs/MSIDs.
2919// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002920TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
deadbeef5e97fb52015-10-15 12:49:08 -07002921 FakeConstraints constraints;
2922 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2923 true);
2924 CreatePeerConnection(&constraints);
2925
Steve Anton36da6ff2018-02-16 16:04:20 -08002926 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002927 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2928 strlen(kRecvonly), &recvonly_offer);
2929 CreateAndSetRemoteOffer(recvonly_offer);
2930
2931 EXPECT_EQ(0u, observer_.remote_streams()->count());
2932}
2933
deadbeefab9b2d12015-10-14 11:33:11 -07002934// This tests that a default MediaStream is created if a remote session
2935// description doesn't contain any streams and no MSID support.
2936// It also tests that the default stream is updated if a video m-line is added
2937// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002938// Don't run under Unified Plan since this behavior is Plan B specific.
2939TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002940 FakeConstraints constraints;
2941 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2942 true);
2943 CreatePeerConnection(&constraints);
2944 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2945
2946 ASSERT_EQ(1u, observer_.remote_streams()->count());
2947 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2948
2949 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2950 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002951 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002952
2953 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2954 ASSERT_EQ(1u, observer_.remote_streams()->count());
2955 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2956 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002957 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2958 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002959 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2960 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002961 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2962 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002963}
2964
2965// This tests that a default MediaStream is created if a remote session
2966// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002967// Don't run under Unified Plan since this behavior is Plan B specific.
2968TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002969 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002970 FakeConstraints constraints;
2971 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2972 true);
2973 CreatePeerConnection(&constraints);
2974 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2975
2976 ASSERT_EQ(1u, observer_.remote_streams()->count());
2977 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2978
2979 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2980 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002981 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002982}
2983
2984// This tests that it won't crash when PeerConnection tries to remove
2985// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002986// Don't run under Unified Plan since this behavior is Plan B specific.
2987TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002988 FakeConstraints constraints;
2989 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2990 true);
2991 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08002992 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002993 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2994 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2995 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2996
2997 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2998
2999 // No crash is a pass.
3000}
3001
3002// This tests that a default MediaStream is created if the remote session
3003// description doesn't contain any streams and don't contain an indication if
3004// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08003005// Don't run under Unified Plan since this behavior is Plan B specific.
3006TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003007 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003008 FakeConstraints constraints;
3009 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3010 true);
3011 CreatePeerConnection(&constraints);
3012 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3013
3014 ASSERT_EQ(1u, observer_.remote_streams()->count());
3015 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3016 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
3017 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
3018}
3019
3020// This tests that a default MediaStream is not created if the remote session
3021// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08003022// Don't run under Unified Plan since this behavior is Plan B specific.
3023TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003024 FakeConstraints constraints;
3025 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3026 true);
3027 CreatePeerConnection(&constraints);
3028 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3029 EXPECT_EQ(0u, observer_.remote_streams()->count());
3030}
3031
deadbeefbda7e0b2015-12-08 17:13:40 -08003032// This tests that when setting a new description, the old default tracks are
3033// not destroyed and recreated.
3034// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003035// Don't run under Unified Plan since this behavior is Plan B specific.
3036TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003037 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08003038 FakeConstraints constraints;
3039 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3040 true);
3041 CreatePeerConnection(&constraints);
3042 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3043
3044 ASSERT_EQ(1u, observer_.remote_streams()->count());
3045 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3046 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3047
3048 // Set the track to "disabled", then set a new description and ensure the
3049 // track is still disabled, which ensures it hasn't been recreated.
3050 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3051 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3052 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3053 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3054}
3055
deadbeefab9b2d12015-10-14 11:33:11 -07003056// This tests that a default MediaStream is not created if a remote session
3057// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003058// Don't run under Unified Plan since this behavior is Plan B specific.
3059TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
deadbeefab9b2d12015-10-14 11:33:11 -07003060 FakeConstraints constraints;
3061 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3062 true);
3063 CreatePeerConnection(&constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003064 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003065 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003066 EXPECT_TRUE(
3067 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3068
3069 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3070 EXPECT_EQ(0u, observer_.remote_streams()->count());
3071}
3072
Seth Hampson5897a6e2018-04-03 11:16:33 -07003073// This tests that a default MediaStream is created if a remote SDP comes from
3074// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3075TEST_F(PeerConnectionInterfaceTestPlanB,
3076 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
3077 FakeConstraints constraints;
3078 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3079 true);
3080 CreatePeerConnection(&constraints);
3081 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3082 // Add a=msid lines to simulate a Unified Plan endpoint that only
3083 // signals stream IDs with a=msid lines.
3084 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3085
3086 CreateAndSetRemoteOffer(sdp_string);
3087
3088 ASSERT_EQ(1u, observer_.remote_streams()->count());
3089 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3090 EXPECT_EQ("default", remote_stream->id());
3091 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3092}
3093
Seth Hampson5b4f0752018-04-02 16:31:36 -07003094// This tests that when a Plan B endpoint receives an SDP that signals no media
3095// stream IDs indicated by the special character "-" in the a=msid line, that
3096// a default stream ID will be used for the MediaStream ID. This can occur
3097// when a Unified Plan endpoint signals no media stream IDs, but signals both
3098// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3099TEST_F(PeerConnectionInterfaceTestPlanB,
3100 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
3101 FakeConstraints constraints;
3102 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3103 true);
3104 CreatePeerConnection(&constraints);
3105 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3106 // the sender's stream ID will be interpreted as no stream IDs.
3107 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3108 sdp_string.append("a=msid:- audiotrack0\n");
3109
3110 CreateAndSetRemoteOffer(sdp_string);
3111
3112 ASSERT_EQ(1u, observer_.remote_streams()->count());
3113 // Because SSRCs are signaled the track ID will be what was signaled in the
3114 // a=msid line.
3115 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3116 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3117 EXPECT_EQ("default", remote_stream->id());
3118 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003119
3120 // Previously a bug ocurred when setting the remote description a second time.
3121 // This is because we checked equality of the remote StreamParams stream ID
3122 // (empty), and the previously set stream ID for the remote sender
3123 // ("default"). This cause a track to be removed, then added, when really
3124 // nothing should occur because it is the same track.
3125 CreateAndSetRemoteOffer(sdp_string);
3126 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3127 EXPECT_EQ(1u, observer_.add_track_events_.size());
3128 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3129 remote_stream = observer_.remote_streams()->at(0);
3130 EXPECT_EQ("default", remote_stream->id());
3131 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003132}
3133
deadbeefab9b2d12015-10-14 11:33:11 -07003134// This tests that an RtpSender is created when the local description is set
3135// after adding a local stream.
3136// TODO(deadbeef): This test and the one below it need to be updated when
3137// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003138// Don't run under Unified Plan since this behavior is Plan B specific.
3139TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003140 FakeConstraints constraints;
3141 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3142 true);
3143 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003144
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003145 // Create an offer with 1 stream with 2 tracks of each type.
3146 rtc::scoped_refptr<StreamCollection> stream_collection =
3147 CreateStreamCollection(1, 2);
3148 pc_->AddStream(stream_collection->at(0));
3149 std::unique_ptr<SessionDescriptionInterface> offer;
3150 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003151 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003152
deadbeefab9b2d12015-10-14 11:33:11 -07003153 auto senders = pc_->GetSenders();
3154 EXPECT_EQ(4u, senders.size());
3155 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3156 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3157 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3158 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3159
3160 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003161 pc_->RemoveStream(stream_collection->at(0));
3162 stream_collection = CreateStreamCollection(1, 1);
3163 pc_->AddStream(stream_collection->at(0));
3164 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003165 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003166
deadbeefab9b2d12015-10-14 11:33:11 -07003167 senders = pc_->GetSenders();
3168 EXPECT_EQ(2u, senders.size());
3169 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3170 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3171 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3172 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3173}
3174
3175// This tests that an RtpSender is created when the local description is set
3176// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003177// Don't run under Unified Plan since this behavior is Plan B specific.
3178TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003179 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07003180 FakeConstraints constraints;
3181 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3182 true);
3183 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003184
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003185 rtc::scoped_refptr<StreamCollection> stream_collection =
3186 CreateStreamCollection(1, 2);
3187 // Add a stream to create the offer, but remove it afterwards.
3188 pc_->AddStream(stream_collection->at(0));
3189 std::unique_ptr<SessionDescriptionInterface> offer;
3190 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3191 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003192
Steve Antondb45ca82017-09-11 18:27:34 -07003193 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003194 auto senders = pc_->GetSenders();
3195 EXPECT_EQ(0u, senders.size());
3196
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003197 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003198 senders = pc_->GetSenders();
3199 EXPECT_EQ(4u, senders.size());
3200 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3201 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3202 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3203 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3204}
3205
3206// This tests that the expected behavior occurs if the SSRC on a local track is
3207// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003208TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003209 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07003210 FakeConstraints constraints;
3211 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3212 true);
3213 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003214
Steve Anton36da6ff2018-02-16 16:04:20 -08003215 AddAudioTrack(kAudioTracks[0]);
3216 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003217 std::unique_ptr<SessionDescriptionInterface> offer;
3218 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3219 // Grab a copy of the offer before it gets passed into the PC.
Steve Antona3a92c22017-12-07 10:27:41 -08003220 auto modified_offer =
3221 rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003222 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
3223 offer->session_version());
Steve Antondb45ca82017-09-11 18:27:34 -07003224 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003225
deadbeefab9b2d12015-10-14 11:33:11 -07003226 auto senders = pc_->GetSenders();
3227 EXPECT_EQ(2u, senders.size());
3228 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3229 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3230
3231 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003232 cricket::MediaContentDescription* desc =
3233 cricket::GetFirstAudioContentDescription(modified_offer->description());
3234 ASSERT_TRUE(desc != NULL);
3235 for (StreamParams& stream : desc->mutable_streams()) {
3236 for (unsigned int& ssrc : stream.ssrcs) {
3237 ++ssrc;
3238 }
3239 }
deadbeefab9b2d12015-10-14 11:33:11 -07003240
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003241 desc =
3242 cricket::GetFirstVideoContentDescription(modified_offer->description());
3243 ASSERT_TRUE(desc != NULL);
3244 for (StreamParams& stream : desc->mutable_streams()) {
3245 for (unsigned int& ssrc : stream.ssrcs) {
3246 ++ssrc;
3247 }
3248 }
3249
Steve Antondb45ca82017-09-11 18:27:34 -07003250 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003251 senders = pc_->GetSenders();
3252 EXPECT_EQ(2u, senders.size());
3253 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3254 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3255 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3256 // changed.
3257}
3258
3259// This tests that the expected behavior occurs if a new session description is
3260// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003261// Don't run under Unified Plan since the stream API is not available.
3262TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003263 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003264 FakeConstraints constraints;
3265 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3266 true);
3267 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003268
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003269 rtc::scoped_refptr<StreamCollection> stream_collection =
3270 CreateStreamCollection(2, 1);
3271 pc_->AddStream(stream_collection->at(0));
3272 std::unique_ptr<SessionDescriptionInterface> offer;
3273 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003274 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003275
deadbeefab9b2d12015-10-14 11:33:11 -07003276 auto senders = pc_->GetSenders();
3277 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003278 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3279 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003280
3281 // Add a new MediaStream but with the same tracks as in the first stream.
3282 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3283 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003284 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3285 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003286 pc_->AddStream(stream_1);
3287
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003288 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003289 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003290
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003291 auto new_senders = pc_->GetSenders();
3292 // Should be the same senders as before, but with updated stream id.
3293 // Note that this behavior is subject to change in the future.
3294 // We may decide the PC should ignore existing tracks in AddStream.
3295 EXPECT_EQ(senders, new_senders);
3296 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3297 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003298}
3299
zhihuang81c3a032016-11-17 12:06:24 -08003300// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003301TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
zhihuang81c3a032016-11-17 12:06:24 -08003302 FakeConstraints constraints;
3303 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3304 true);
3305 CreatePeerConnection(&constraints);
3306 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3307 EXPECT_EQ(observer_.num_added_tracks_, 1);
3308 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3309
3310 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003311 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3312 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3313 EXPECT_EQ(observer_.num_added_tracks_, 2);
3314 } else {
3315 // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription
3316 // is called until the offer/answer exchange is complete. So in this case
3317 // OnAddTrack is fired twice for the first audio track plus the one time
3318 // for the video track.
3319 EXPECT_EQ(observer_.num_added_tracks_, 3);
3320 }
zhihuang81c3a032016-11-17 12:06:24 -08003321 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3322}
3323
deadbeefd1a38b52016-12-10 13:15:33 -08003324// Test that when SetConfiguration is called and the configuration is
3325// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003326TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003327 PeerConnectionInterface::RTCConfiguration config;
3328 config.type = PeerConnectionInterface::kRelay;
3329 // Need to pass default constraints to prevent disabling of DTLS...
3330 FakeConstraints default_constraints;
3331 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003332 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003333 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3334 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003335
3336 // Do initial offer/answer so there's something to restart.
3337 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003338 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003339
3340 // Grab the ufrags.
3341 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3342
3343 // Change ICE policy, which should trigger an ICE restart on the next offer.
3344 config.type = PeerConnectionInterface::kAll;
3345 EXPECT_TRUE(pc_->SetConfiguration(config));
3346 CreateOfferAsLocalDescription();
3347
3348 // Grab the new ufrags.
3349 std::vector<std::string> subsequent_ufrags =
3350 GetUfrags(pc_->local_description());
3351
3352 // Sanity check.
3353 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3354 // Check that each ufrag is different.
3355 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3356 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3357 }
3358}
3359
3360// Test that when SetConfiguration is called and the configuration *isn't*
3361// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003362TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003363 PeerConnectionInterface::RTCConfiguration config;
3364 config.type = PeerConnectionInterface::kRelay;
3365 // Need to pass default constraints to prevent disabling of DTLS...
3366 FakeConstraints default_constraints;
3367 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003368 config = pc_->GetConfiguration();
3369 AddAudioTrack(kAudioTracks[0]);
3370 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003371
3372 // Do initial offer/answer so there's something to restart.
3373 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003374 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003375
3376 // Grab the ufrags.
3377 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3378
3379 // Call SetConfiguration with a config identical to what the PC was
3380 // constructed with.
3381 EXPECT_TRUE(pc_->SetConfiguration(config));
3382 CreateOfferAsLocalDescription();
3383
3384 // Grab the new ufrags.
3385 std::vector<std::string> subsequent_ufrags =
3386 GetUfrags(pc_->local_description());
3387
3388 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3389}
3390
3391// Test for a weird corner case scenario:
3392// 1. Audio/video session established.
3393// 2. SetConfiguration changes ICE config; ICE restart needed.
3394// 3. ICE restart initiated by remote peer, but only for one m= section.
3395// 4. Next createOffer should initiate an ICE restart, but only for the other
3396// m= section; it would be pointless to do an ICE restart for the m= section
3397// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003398TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003399 PeerConnectionInterface::RTCConfiguration config;
3400 config.type = PeerConnectionInterface::kRelay;
3401 // Need to pass default constraints to prevent disabling of DTLS...
3402 FakeConstraints default_constraints;
3403 CreatePeerConnection(config, &default_constraints);
Steve Anton36da6ff2018-02-16 16:04:20 -08003404 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003405 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3406 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003407
3408 // Do initial offer/answer so there's something to restart.
3409 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003410 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003411
3412 // Change ICE policy, which should set the "needs-ice-restart" flag.
3413 config.type = PeerConnectionInterface::kAll;
3414 EXPECT_TRUE(pc_->SetConfiguration(config));
3415
3416 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003417 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003418 webrtc::CreateSessionDescription(SdpType::kOffer,
3419 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003420 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003421 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3422 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003423 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003424 CreateAnswerAsLocalDescription();
3425
3426 // Grab the ufrags.
3427 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3428 ASSERT_EQ(2, initial_ufrags.size());
3429
3430 // Create offer and grab the new ufrags.
3431 CreateOfferAsLocalDescription();
3432 std::vector<std::string> subsequent_ufrags =
3433 GetUfrags(pc_->local_description());
3434 ASSERT_EQ(2, subsequent_ufrags.size());
3435
3436 // Ensure that only the ufrag for the second m= section changed.
3437 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3438 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3439}
3440
deadbeeffe4a8a42016-12-20 17:56:17 -08003441// Tests that the methods to return current/pending descriptions work as
3442// expected at different points in the offer/answer exchange. This test does
3443// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003444TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003445 // This disables DTLS so we can apply an answer to ourselves.
3446 CreatePeerConnection();
3447
3448 // Create initial local offer and get SDP (which will also be used as
3449 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003450 std::unique_ptr<SessionDescriptionInterface> local_offer;
3451 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003452 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003453 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003454
3455 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003456 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3457 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3458 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003459 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3460 EXPECT_EQ(nullptr, pc_->current_local_description());
3461 EXPECT_EQ(nullptr, pc_->current_remote_description());
3462
3463 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003464 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003465 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003466 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3467 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3468 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3469 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003470 EXPECT_EQ(nullptr, pc_->current_local_description());
3471 EXPECT_EQ(nullptr, pc_->current_remote_description());
3472
3473 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003474 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003475 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003476 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3477 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003478 EXPECT_EQ(nullptr, pc_->pending_local_description());
3479 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003480 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3481 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003482
3483 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003484 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003485 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003486 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3487 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3488 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003489 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003490 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3491 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003492
3493 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003494 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003495 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003496 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3497 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3498 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3499 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3500 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3501 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003502
3503 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003504 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003505 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003506 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3507 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003508 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3509 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003510 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3511 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003512}
3513
zhihuang77985012017-02-07 15:45:16 -08003514// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3515// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003516// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003517TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003518 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003519 CreatePeerConnection();
3520 // The RtcEventLog will be reset when the PeerConnection is closed.
3521 pc_->Close();
3522
Elad Alon9e6565b2017-10-11 16:04:13 +02003523 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3524 std::string filename = webrtc::test::OutputPath() +
3525 test_info->test_case_name() + test_info->name();
3526 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3527
3528 constexpr int64_t max_size_bytes = 1024;
3529
zhihuang77985012017-02-07 15:45:16 -08003530 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3531 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003532
3533 // Cleanup.
3534 rtc::ClosePlatformFile(file);
3535 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003536}
3537
Elad Alon99c3fe52017-10-13 16:29:40 +02003538// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3539// after the PeerConnection is closed.
3540// This version tests the StartRtcEventLog version that receives an object
3541// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003542TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003543 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3544 CreatePeerConnection();
3545 // The RtcEventLog will be reset when the PeerConnection is closed.
3546 pc_->Close();
3547
3548 rtc::PlatformFile file = 0;
3549 int64_t max_size_bytes = 1024;
3550 EXPECT_FALSE(pc_->StartRtcEventLog(
Bjorn Tereliusde939432017-11-20 17:38:14 +01003551 rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
3552 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003553 pc_->StopRtcEventLog();
3554}
3555
deadbeef30952b42017-04-21 02:41:29 -07003556// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003557TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003558 CreatePeerConnection();
3559
3560 // First, create an offer with audio/video.
3561 FakeConstraints constraints;
3562 constraints.SetMandatoryReceiveAudio(true);
3563 constraints.SetMandatoryReceiveVideo(true);
3564 std::unique_ptr<SessionDescriptionInterface> offer;
3565 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3566 cricket::SessionDescription* desc = offer->description();
3567 ASSERT_EQ(2u, desc->transport_infos().size());
3568 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3569 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3570
3571 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003572 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003573 std::unique_ptr<SessionDescriptionInterface> answer;
3574 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3575 desc = answer->description();
3576 ASSERT_EQ(2u, desc->transport_infos().size());
3577 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3578 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3579}
3580
deadbeef1dcb1642017-03-29 21:08:16 -07003581// Test that ICE renomination isn't offered if it's not enabled in the PC's
3582// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003583TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003584 PeerConnectionInterface::RTCConfiguration config;
3585 config.enable_ice_renomination = false;
3586 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003587 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003588
3589 std::unique_ptr<SessionDescriptionInterface> offer;
3590 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3591 cricket::SessionDescription* desc = offer->description();
3592 EXPECT_EQ(1u, desc->transport_infos().size());
3593 EXPECT_FALSE(
3594 desc->transport_infos()[0].description.GetIceParameters().renomination);
3595}
3596
3597// Test that the ICE renomination option is present in generated offers/answers
3598// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003599TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003600 PeerConnectionInterface::RTCConfiguration config;
3601 config.enable_ice_renomination = true;
3602 CreatePeerConnection(config, nullptr);
Steve Anton36da6ff2018-02-16 16:04:20 -08003603 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003604
3605 std::unique_ptr<SessionDescriptionInterface> offer;
3606 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3607 cricket::SessionDescription* desc = offer->description();
3608 EXPECT_EQ(1u, desc->transport_infos().size());
3609 EXPECT_TRUE(
3610 desc->transport_infos()[0].description.GetIceParameters().renomination);
3611
3612 // Set the offer as a remote description, then create an answer and ensure it
3613 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003614 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003615 std::unique_ptr<SessionDescriptionInterface> answer;
3616 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3617 desc = answer->description();
3618 EXPECT_EQ(1u, desc->transport_infos().size());
3619 EXPECT_TRUE(
3620 desc->transport_infos()[0].description.GetIceParameters().renomination);
3621}
3622
3623// Test that if CreateOffer is called with the deprecated "offer to receive
3624// audio/video" constraints, they're processed and result in an offer with
3625// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003626TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003627 CreatePeerConnection();
3628
3629 FakeConstraints constraints;
3630 constraints.SetMandatoryReceiveAudio(true);
3631 constraints.SetMandatoryReceiveVideo(true);
3632 std::unique_ptr<SessionDescriptionInterface> offer;
3633 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3634
3635 cricket::SessionDescription* desc = offer->description();
3636 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3637 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3638 ASSERT_NE(nullptr, audio);
3639 ASSERT_NE(nullptr, video);
3640 EXPECT_FALSE(audio->rejected);
3641 EXPECT_FALSE(video->rejected);
3642}
3643
3644// Test that if CreateAnswer is called with the deprecated "offer to receive
3645// audio/video" constraints, they're processed and can be used to reject an
3646// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003647// Don't run under Unified Plan since this behavior is not supported.
3648TEST_F(PeerConnectionInterfaceTestPlanB,
3649 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003650 CreatePeerConnection();
3651
3652 // First, create an offer with audio/video and apply it as a remote
3653 // description.
3654 FakeConstraints constraints;
3655 constraints.SetMandatoryReceiveAudio(true);
3656 constraints.SetMandatoryReceiveVideo(true);
3657 std::unique_ptr<SessionDescriptionInterface> offer;
3658 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
Steve Antondb45ca82017-09-11 18:27:34 -07003659 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003660
3661 // Now create answer that rejects audio/video.
3662 constraints.SetMandatoryReceiveAudio(false);
3663 constraints.SetMandatoryReceiveVideo(false);
3664 std::unique_ptr<SessionDescriptionInterface> answer;
3665 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3666
3667 cricket::SessionDescription* desc = answer->description();
3668 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3669 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3670 ASSERT_NE(nullptr, audio);
3671 ASSERT_NE(nullptr, video);
3672 EXPECT_TRUE(audio->rejected);
3673 EXPECT_TRUE(video->rejected);
3674}
3675
deadbeef1dcb1642017-03-29 21:08:16 -07003676// Test that negotiation can succeed with a data channel only, and with the max
3677// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003678#ifdef HAVE_SCTP
3679TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3680#else
3681TEST_P(PeerConnectionInterfaceTest,
3682 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3683#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003684 PeerConnectionInterface::RTCConfiguration config;
3685 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3686 CreatePeerConnection(config, nullptr);
3687
3688 // First, create an offer with only a data channel and apply it as a remote
3689 // description.
3690 pc_->CreateDataChannel("test", nullptr);
3691 std::unique_ptr<SessionDescriptionInterface> offer;
3692 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003693 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003694
3695 // Create and set answer as well.
3696 std::unique_ptr<SessionDescriptionInterface> answer;
3697 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003698 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003699}
3700
Steve Anton36da6ff2018-02-16 16:04:20 -08003701TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003702 CreatePeerConnection();
3703 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003704 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003705 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3706}
3707
Steve Anton36da6ff2018-02-16 16:04:20 -08003708TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003709 CreatePeerConnection();
3710 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003711 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003712 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3713}
3714
Steve Anton36da6ff2018-02-16 16:04:20 -08003715TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003716 CreatePeerConnection();
3717 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003718 bitrate.min_bitrate_bps = 5;
3719 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003720 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3721}
3722
Steve Anton36da6ff2018-02-16 16:04:20 -08003723TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003724 CreatePeerConnection();
3725 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003726 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003727 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3728}
3729
Steve Anton36da6ff2018-02-16 16:04:20 -08003730TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003731 CreatePeerConnection();
3732 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003733 bitrate.current_bitrate_bps = 10;
3734 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003735 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3736}
3737
Steve Anton36da6ff2018-02-16 16:04:20 -08003738TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003739 CreatePeerConnection();
3740 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003741 bitrate.min_bitrate_bps = 10;
3742 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003743 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3744}
3745
Steve Anton36da6ff2018-02-16 16:04:20 -08003746TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003747 CreatePeerConnection();
3748 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003749 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003750 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3751}
3752
Steve Anton038834f2017-07-14 15:59:59 -07003753// ice_regather_interval_range requires WebRTC to be configured for continual
3754// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003755TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003756 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3757 PeerConnectionInterface::RTCConfiguration config;
3758 config.ice_regather_interval_range.emplace(1000, 2000);
3759 config.continual_gathering_policy =
3760 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3761 CreatePeerConnectionExpectFail(config);
3762}
3763
3764// Ensures that there is no error when ice_regather_interval_range is set with
3765// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003766TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003767 SetIceRegatherIntervalRangeWithContinualGathering) {
3768 PeerConnectionInterface::RTCConfiguration config;
3769 config.ice_regather_interval_range.emplace(1000, 2000);
3770 config.continual_gathering_policy =
3771 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3772 CreatePeerConnection(config, nullptr);
3773}
3774
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003775// The current bitrate from Call's BitrateConstraintsMask is currently clamped
3776// by Call's BitrateConstraints, which comes from the SDP or a default value.
3777// This test checks that a call to SetBitrate with a current bitrate that will
3778// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003779TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003780 CreatePeerConnection();
3781 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003782 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003783 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3784}
3785
zhihuang1c378ed2017-08-17 14:10:50 -07003786// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003787TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003788 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3789 RTCOfferAnswerOptions rtc_options;
3790
3791 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3792 // than kMaxOfferToReceiveMedia should be treated as invalid.
3793 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3794 CreatePeerConnection();
3795 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3796
3797 rtc_options.offer_to_receive_audio =
3798 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3799 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3800}
3801
Steve Anton36da6ff2018-02-16 16:04:20 -08003802TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003803 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3804 RTCOfferAnswerOptions rtc_options;
3805
3806 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3807 // than kMaxOfferToReceiveMedia should be treated as invalid.
3808 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3809 CreatePeerConnection();
3810 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3811
3812 rtc_options.offer_to_receive_video =
3813 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3814 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3815}
3816
3817// Test that the audio and video content will be added to an offer if both
3818// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003819TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003820 RTCOfferAnswerOptions rtc_options;
3821 rtc_options.offer_to_receive_audio = 1;
3822 rtc_options.offer_to_receive_video = 1;
3823
3824 std::unique_ptr<SessionDescriptionInterface> offer;
3825 CreatePeerConnection();
3826 offer = CreateOfferWithOptions(rtc_options);
3827 ASSERT_TRUE(offer);
3828 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3829 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3830}
3831
3832// Test that only audio content will be added to the offer if only
3833// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003834TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003835 RTCOfferAnswerOptions rtc_options;
3836 rtc_options.offer_to_receive_audio = 1;
3837 rtc_options.offer_to_receive_video = 0;
3838
3839 std::unique_ptr<SessionDescriptionInterface> offer;
3840 CreatePeerConnection();
3841 offer = CreateOfferWithOptions(rtc_options);
3842 ASSERT_TRUE(offer);
3843 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3844 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3845}
3846
3847// Test that only video content will be added if only |offer_to_receive_video|
3848// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003849TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003850 RTCOfferAnswerOptions rtc_options;
3851 rtc_options.offer_to_receive_audio = 0;
3852 rtc_options.offer_to_receive_video = 1;
3853
3854 std::unique_ptr<SessionDescriptionInterface> offer;
3855 CreatePeerConnection();
3856 offer = CreateOfferWithOptions(rtc_options);
3857 ASSERT_TRUE(offer);
3858 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3859 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3860}
3861
zhihuang1c378ed2017-08-17 14:10:50 -07003862// Test that no media content will be added to the offer if using default
3863// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003864TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003865 RTCOfferAnswerOptions rtc_options;
3866
3867 std::unique_ptr<SessionDescriptionInterface> offer;
3868 CreatePeerConnection();
3869 offer = CreateOfferWithOptions(rtc_options);
3870 ASSERT_TRUE(offer);
3871 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3872 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3873}
3874
3875// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3876// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003877TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3878 CreatePeerConnection();
3879
zhihuang1c378ed2017-08-17 14:10:50 -07003880 RTCOfferAnswerOptions rtc_options;
3881 rtc_options.ice_restart = false;
3882 rtc_options.offer_to_receive_audio = 1;
3883
3884 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003885 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003886 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3887 auto ufrag1 =
3888 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3889 auto pwd1 =
3890 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003891
3892 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3893 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003894 auto ufrag2 =
3895 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3896 auto pwd2 =
3897 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003898
3899 // |ice_restart| is true, the ufrag/pwd should change.
3900 rtc_options.ice_restart = true;
3901 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003902 auto ufrag3 =
3903 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3904 auto pwd3 =
3905 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003906
3907 EXPECT_EQ(ufrag1, ufrag2);
3908 EXPECT_EQ(pwd1, pwd2);
3909 EXPECT_NE(ufrag2, ufrag3);
3910 EXPECT_NE(pwd2, pwd3);
3911}
3912
3913// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3914// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003915TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003916 RTCOfferAnswerOptions rtc_options;
3917 rtc_options.offer_to_receive_audio = 1;
3918 rtc_options.offer_to_receive_video = 1;
3919
3920 std::unique_ptr<SessionDescriptionInterface> offer;
3921 CreatePeerConnection();
3922
3923 rtc_options.use_rtp_mux = true;
3924 offer = CreateOfferWithOptions(rtc_options);
3925 ASSERT_TRUE(offer);
3926 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3927 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3928 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3929
3930 rtc_options.use_rtp_mux = false;
3931 offer = CreateOfferWithOptions(rtc_options);
3932 ASSERT_TRUE(offer);
3933 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3934 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3935 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3936}
3937
zhihuang141aacb2017-08-29 13:23:53 -07003938// This test ensures OnRenegotiationNeeded is called when we add track with
3939// MediaStream -> AddTrack in the same way it is called when we add track with
3940// PeerConnection -> AddTrack.
3941// The test can be removed once addStream is rewritten in terms of addTrack
3942// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003943// Don't run under Unified Plan since the stream API is not available.
3944TEST_F(PeerConnectionInterfaceTestPlanB,
3945 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003946 CreatePeerConnectionWithoutDtls();
3947 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003948 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003949 pc_->AddStream(stream);
3950 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3951 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3952 rtc::scoped_refptr<VideoTrackInterface> video_track(
3953 pc_factory_->CreateVideoTrack(
3954 "video_track", pc_factory_->CreateVideoSource(
3955 std::unique_ptr<cricket::VideoCapturer>(
3956 new cricket::FakeVideoCapturer()))));
3957 stream->AddTrack(audio_track);
3958 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3959 observer_.renegotiation_needed_ = false;
3960
3961 stream->AddTrack(video_track);
3962 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3963 observer_.renegotiation_needed_ = false;
3964
3965 stream->RemoveTrack(audio_track);
3966 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3967 observer_.renegotiation_needed_ = false;
3968
3969 stream->RemoveTrack(video_track);
3970 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3971 observer_.renegotiation_needed_ = false;
3972}
3973
Zhi Huangb2d355e2017-10-26 17:26:37 -07003974// Tests that an error is returned if a description is applied that has fewer
3975// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003976TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003977 MediaSectionCountEnforcedForSubsequentOffer) {
3978 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003979 AddAudioTrack("audio_label");
3980 AddVideoTrack("video_label");
3981
Zhi Huangb2d355e2017-10-26 17:26:37 -07003982 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003983 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003984 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3985
3986 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003987 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003988 offer->description()->contents().pop_back();
3989 offer->description()->contents().pop_back();
3990 ASSERT_TRUE(offer->description()->contents().empty());
3991 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3992
3993 std::unique_ptr<SessionDescriptionInterface> answer;
3994 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3995 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3996
3997 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003998 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003999 offer->description()->contents().pop_back();
4000 offer->description()->contents().pop_back();
4001 ASSERT_TRUE(offer->description()->contents().empty());
4002 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
4003}
4004
Steve Anton36da6ff2018-02-16 16:04:20 -08004005INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
4006 PeerConnectionInterfaceTest,
4007 Values(SdpSemantics::kPlanB,
4008 SdpSemantics::kUnifiedPlan));
4009
nisse51542be2016-02-12 02:27:06 -08004010class PeerConnectionMediaConfigTest : public testing::Test {
4011 protected:
4012 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07004013 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08004014 pcf_->Initialize();
4015 }
nisseeaabdf62017-05-05 02:23:02 -07004016 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08004017 const PeerConnectionInterface::RTCConfiguration& config,
zhihuang1c378ed2017-08-17 14:10:50 -07004018 const MediaConstraintsInterface* constraints) {
zhihuang9763d562016-08-05 11:14:50 -07004019 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
4020 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08004021 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07004022 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08004023 }
4024
zhihuang9763d562016-08-05 11:14:50 -07004025 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08004026 MockPeerConnectionObserver observer_;
4027};
4028
4029// This test verifies the default behaviour with no constraints and a
4030// default RTCConfiguration.
4031TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
4032 PeerConnectionInterface::RTCConfiguration config;
4033 FakeConstraints constraints;
4034
4035 const cricket::MediaConfig& media_config =
4036 TestCreatePeerConnection(config, &constraints);
4037
4038 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01004039 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
4040 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004041 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01004042 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08004043}
4044
4045// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07004046// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004047TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
4048 PeerConnectionInterface::RTCConfiguration config;
4049 FakeConstraints constraints;
4050
4051 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
4052 const cricket::MediaConfig& media_config =
4053 TestCreatePeerConnection(config, &constraints);
4054
4055 EXPECT_TRUE(media_config.enable_dscp);
4056}
4057
4058// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07004059// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004060TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
4061 PeerConnectionInterface::RTCConfiguration config;
4062 FakeConstraints constraints;
4063
4064 constraints.AddOptional(
4065 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
4066 const cricket::MediaConfig media_config =
4067 TestCreatePeerConnection(config, &constraints);
4068
Niels Möller1d7ecd22018-01-18 15:25:12 +01004069 EXPECT_FALSE(media_config.video.enable_cpu_adaptation);
nisse51542be2016-02-12 02:27:06 -08004070}
4071
Niels Möller1d7ecd22018-01-18 15:25:12 +01004072// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004073// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004074TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4075 PeerConnectionInterface::RTCConfiguration config;
4076 FakeConstraints constraints;
4077
Niels Möller71bdda02016-03-31 12:59:59 +02004078 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08004079 const cricket::MediaConfig& media_config =
4080 TestCreatePeerConnection(config, &constraints);
4081
Niels Möller1d7ecd22018-01-18 15:25:12 +01004082 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004083}
4084
Niels Möller6539f692018-01-18 08:58:50 +01004085// This test verifies that the experiment_cpu_load_estimator flag is
4086// propagated from RTCConfiguration to the PeerConnection.
4087TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4088 PeerConnectionInterface::RTCConfiguration config;
4089 FakeConstraints constraints;
4090
4091 config.set_experiment_cpu_load_estimator(true);
4092 const cricket::MediaConfig& media_config =
4093 TestCreatePeerConnection(config, &constraints);
4094
4095 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4096}
4097
nisse0db023a2016-03-01 04:29:59 -08004098// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07004099// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08004100TEST_F(PeerConnectionMediaConfigTest,
4101 TestSuspendBelowMinBitrateConstraintTrue) {
4102 PeerConnectionInterface::RTCConfiguration config;
4103 FakeConstraints constraints;
4104
4105 constraints.AddOptional(
4106 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4107 true);
4108 const cricket::MediaConfig media_config =
4109 TestCreatePeerConnection(config, &constraints);
4110
4111 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08004112}
4113
deadbeef293e9262017-01-11 12:28:30 -08004114// Tests a few random fields being different.
4115TEST(RTCConfigurationTest, ComparisonOperators) {
4116 PeerConnectionInterface::RTCConfiguration a;
4117 PeerConnectionInterface::RTCConfiguration b;
4118 EXPECT_EQ(a, b);
4119
4120 PeerConnectionInterface::RTCConfiguration c;
4121 c.servers.push_back(PeerConnectionInterface::IceServer());
4122 EXPECT_NE(a, c);
4123
4124 PeerConnectionInterface::RTCConfiguration d;
4125 d.type = PeerConnectionInterface::kRelay;
4126 EXPECT_NE(a, d);
4127
4128 PeerConnectionInterface::RTCConfiguration e;
4129 e.audio_jitter_buffer_max_packets = 5;
4130 EXPECT_NE(a, e);
4131
4132 PeerConnectionInterface::RTCConfiguration f;
4133 f.ice_connection_receiving_timeout = 1337;
4134 EXPECT_NE(a, f);
4135
4136 PeerConnectionInterface::RTCConfiguration g;
4137 g.disable_ipv6 = true;
4138 EXPECT_NE(a, g);
4139
4140 PeerConnectionInterface::RTCConfiguration h(
4141 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4142 EXPECT_NE(a, h);
4143}