blob: 02c7932b37be58ed9d230d47376eeefc7f5f4e3f [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
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080012#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080014#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
kwiberg087bd342017-02-10 08:15:44 -080016#include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/jsepsessiondescription.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/mediastreaminterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010019#include "webrtc/api/peerconnectioninterface.h"
20#include "webrtc/api/rtpreceiverinterface.h"
21#include "webrtc/api/rtpsenderinterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010022#include "webrtc/api/test/fakeconstraints.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000023#include "webrtc/base/gunit.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000024#include "webrtc/base/ssladapter.h"
25#include "webrtc/base/sslstreamadapter.h"
26#include "webrtc/base/stringutils.h"
27#include "webrtc/base/thread.h"
kjellandera96e2d72016-02-04 23:52:28 -080028#include "webrtc/media/base/fakevideocapturer.h"
deadbeef953c2ce2017-01-09 14:53:41 -080029#include "webrtc/media/sctp/sctptransportinternal.h"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070030#include "webrtc/p2p/base/fakeportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010032#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080033#include "webrtc/pc/mediastream.h"
34#include "webrtc/pc/peerconnection.h"
35#include "webrtc/pc/streamcollection.h"
36#include "webrtc/pc/test/fakertccertificategenerator.h"
37#include "webrtc/pc/test/fakevideotracksource.h"
38#include "webrtc/pc/test/mockpeerconnectionobservers.h"
39#include "webrtc/pc/test/testsdpstrings.h"
40#include "webrtc/pc/videocapturertracksource.h"
41#include "webrtc/pc/videotrack.h"
kwibergac9f8762016-09-30 22:29:43 -070042#include "webrtc/test/gmock.h"
43
44#ifdef WEBRTC_ANDROID
ossu7bb87ee2017-01-23 04:56:25 -080045#include "webrtc/pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070046#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48static const char kStreamLabel1[] = "local_stream_1";
49static const char kStreamLabel2[] = "local_stream_2";
50static const char kStreamLabel3[] = "local_stream_3";
51static const int kDefaultStunPort = 3478;
52static const char kStunAddressOnly[] = "stun:address";
53static const char kStunInvalidPort[] = "stun:address:-1";
54static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
55static const char kStunAddressPortAndMore2[] = "stun:address:port more";
56static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
57static const char kTurnUsername[] = "user";
58static const char kTurnPassword[] = "password";
59static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020060static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
deadbeefab9b2d12015-10-14 11:33:11 -070062static const char kStreams[][8] = {"stream1", "stream2"};
63static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
64static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
65
deadbeef5e97fb52015-10-15 12:49:08 -070066static const char kRecvonly[] = "recvonly";
67static const char kSendrecv[] = "sendrecv";
68
deadbeefab9b2d12015-10-14 11:33:11 -070069// Reference SDP with a MediaStream with label "stream1" and audio track with
70// id "audio_1" and a video track with id "video_1;
71static const char kSdpStringWithStream1[] =
72 "v=0\r\n"
73 "o=- 0 0 IN IP4 127.0.0.1\r\n"
74 "s=-\r\n"
75 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080076 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070077 "a=ice-ufrag:e5785931\r\n"
78 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
79 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
80 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070081 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070082 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080083 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070084 "a=rtpmap:103 ISAC/16000\r\n"
85 "a=ssrc:1 cname:stream1\r\n"
86 "a=ssrc:1 mslabel:stream1\r\n"
87 "a=ssrc:1 label:audiotrack0\r\n"
88 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080089 "a=ice-ufrag:e5785931\r\n"
90 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
91 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
92 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070093 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070094 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080095 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070096 "a=rtpmap:120 VP8/90000\r\n"
97 "a=ssrc:2 cname:stream1\r\n"
98 "a=ssrc:2 mslabel:stream1\r\n"
99 "a=ssrc:2 label:videotrack0\r\n";
100
zhihuang81c3a032016-11-17 12:06:24 -0800101// Reference SDP with a MediaStream with label "stream1" and audio track with
102// id "audio_1";
103static const char kSdpStringWithStream1AudioTrackOnly[] =
104 "v=0\r\n"
105 "o=- 0 0 IN IP4 127.0.0.1\r\n"
106 "s=-\r\n"
107 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800108 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800109 "a=ice-ufrag:e5785931\r\n"
110 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
111 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
112 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800113 "a=mid:audio\r\n"
114 "a=sendrecv\r\n"
115 "a=rtpmap:103 ISAC/16000\r\n"
116 "a=ssrc:1 cname:stream1\r\n"
117 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800118 "a=ssrc:1 label:audiotrack0\r\n"
119 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800120
deadbeefab9b2d12015-10-14 11:33:11 -0700121// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
122// MediaStreams have one audio track and one video track.
123// This uses MSID.
124static const char kSdpStringWithStream1And2[] =
125 "v=0\r\n"
126 "o=- 0 0 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800129 "a=msid-semantic: WMS stream1 stream2\r\n"
130 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700131 "a=ice-ufrag:e5785931\r\n"
132 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
133 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
134 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700136 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800137 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700138 "a=rtpmap:103 ISAC/16000\r\n"
139 "a=ssrc:1 cname:stream1\r\n"
140 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
141 "a=ssrc:3 cname:stream2\r\n"
142 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
143 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800144 "a=ice-ufrag:e5785931\r\n"
145 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
146 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
147 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700148 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700149 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800150 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700151 "a=rtpmap:120 VP8/0\r\n"
152 "a=ssrc:2 cname:stream1\r\n"
153 "a=ssrc:2 msid:stream1 videotrack0\r\n"
154 "a=ssrc:4 cname:stream2\r\n"
155 "a=ssrc:4 msid:stream2 videotrack1\r\n";
156
157// Reference SDP without MediaStreams. Msid is not supported.
158static const char kSdpStringWithoutStreams[] =
159 "v=0\r\n"
160 "o=- 0 0 IN IP4 127.0.0.1\r\n"
161 "s=-\r\n"
162 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800163 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700164 "a=ice-ufrag:e5785931\r\n"
165 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
166 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
167 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700168 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700169 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800170 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700171 "a=rtpmap:103 ISAC/16000\r\n"
172 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800173 "a=ice-ufrag:e5785931\r\n"
174 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
175 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
176 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700177 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700178 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800179 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700180 "a=rtpmap:120 VP8/90000\r\n";
181
182// Reference SDP without MediaStreams. Msid is supported.
183static const char kSdpStringWithMsidWithoutStreams[] =
184 "v=0\r\n"
185 "o=- 0 0 IN IP4 127.0.0.1\r\n"
186 "s=-\r\n"
187 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800188 "a=msid-semantic: WMS\r\n"
189 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700190 "a=ice-ufrag:e5785931\r\n"
191 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
192 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
193 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700194 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700195 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800196 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700197 "a=rtpmap:103 ISAC/16000\r\n"
198 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800199 "a=ice-ufrag:e5785931\r\n"
200 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
201 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
202 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700203 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700204 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800205 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700206 "a=rtpmap:120 VP8/90000\r\n";
207
208// Reference SDP without MediaStreams and audio only.
209static const char kSdpStringWithoutStreamsAudioOnly[] =
210 "v=0\r\n"
211 "o=- 0 0 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800214 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700215 "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"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700220 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800221 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700222 "a=rtpmap:103 ISAC/16000\r\n";
223
224// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
225static const char kSdpStringSendOnlyWithoutStreams[] =
226 "v=0\r\n"
227 "o=- 0 0 IN IP4 127.0.0.1\r\n"
228 "s=-\r\n"
229 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800230 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700231 "a=ice-ufrag:e5785931\r\n"
232 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
233 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
234 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700235 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700236 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700237 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800238 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700239 "a=rtpmap:103 ISAC/16000\r\n"
240 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800241 "a=ice-ufrag:e5785931\r\n"
242 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
243 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
244 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700245 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700246 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700247 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800248 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700249 "a=rtpmap:120 VP8/90000\r\n";
250
251static const char kSdpStringInit[] =
252 "v=0\r\n"
253 "o=- 0 0 IN IP4 127.0.0.1\r\n"
254 "s=-\r\n"
255 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700256 "a=msid-semantic: WMS\r\n";
257
258static const char kSdpStringAudio[] =
259 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800260 "a=ice-ufrag:e5785931\r\n"
261 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
262 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
263 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700264 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700265 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800266 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700267 "a=rtpmap:103 ISAC/16000\r\n";
268
269static const char kSdpStringVideo[] =
270 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800271 "a=ice-ufrag:e5785931\r\n"
272 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
273 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
274 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700275 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700276 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800277 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700278 "a=rtpmap:120 VP8/90000\r\n";
279
280static const char kSdpStringMs1Audio0[] =
281 "a=ssrc:1 cname:stream1\r\n"
282 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
283
284static const char kSdpStringMs1Video0[] =
285 "a=ssrc:2 cname:stream1\r\n"
286 "a=ssrc:2 msid:stream1 videotrack0\r\n";
287
288static const char kSdpStringMs1Audio1[] =
289 "a=ssrc:3 cname:stream1\r\n"
290 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
291
292static const char kSdpStringMs1Video1[] =
293 "a=ssrc:4 cname:stream1\r\n"
294 "a=ssrc:4 msid:stream1 videotrack1\r\n";
295
deadbeef8662f942017-01-20 21:20:51 -0800296static const char kDtlsSdesFallbackSdp[] =
297 "v=0\r\n"
298 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
299 "s=-\r\n"
300 "c=IN IP4 0.0.0.0\r\n"
301 "t=0 0\r\n"
302 "a=group:BUNDLE audio\r\n"
303 "a=msid-semantic: WMS\r\n"
304 "m=audio 1 RTP/SAVPF 0\r\n"
305 "a=sendrecv\r\n"
306 "a=rtcp-mux\r\n"
307 "a=mid:audio\r\n"
308 "a=ssrc:1 cname:stream1\r\n"
309 "a=ssrc:1 mslabel:stream1\r\n"
310 "a=ssrc:1 label:audiotrack0\r\n"
311 "a=ice-ufrag:e5785931\r\n"
312 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
313 "a=rtpmap:0 pcmu/8000\r\n"
314 "a=fingerprint:sha-1 "
315 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
316 "a=setup:actpass\r\n"
317 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
318 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
319 "dummy_session_params\r\n";
320
perkjd61bf802016-03-24 03:16:19 -0700321using ::testing::Exactly;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700322using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700324using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325using webrtc::AudioTrackInterface;
326using webrtc::DataBuffer;
327using webrtc::DataChannelInterface;
328using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329using webrtc::IceCandidateInterface;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700330using webrtc::JsepSessionDescription;
deadbeefc80741f2015-10-22 13:14:45 -0700331using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700332using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333using webrtc::MediaStreamInterface;
334using webrtc::MediaStreamTrackInterface;
335using webrtc::MockCreateSessionDescriptionObserver;
336using webrtc::MockDataChannelObserver;
337using webrtc::MockSetSessionDescriptionObserver;
338using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700339using webrtc::NotifierInterface;
340using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341using webrtc::PeerConnectionInterface;
342using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800343using webrtc::RTCError;
344using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700345using webrtc::RtpReceiverInterface;
346using webrtc::RtpSenderInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347using webrtc::SdpParseError;
348using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700349using webrtc::StreamCollection;
350using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100351using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700352using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353using webrtc::VideoTrackInterface;
354
deadbeefab9b2d12015-10-14 11:33:11 -0700355typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
356
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357namespace {
358
359// Gets the first ssrc of given content type from the ContentInfo.
360bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
361 if (!content_info || !ssrc) {
362 return false;
363 }
364 const cricket::MediaContentDescription* media_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000365 static_cast<const cricket::MediaContentDescription*>(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 content_info->description);
367 if (!media_desc || media_desc->streams().empty()) {
368 return false;
369 }
370 *ssrc = media_desc->streams().begin()->first_ssrc();
371 return true;
372}
373
deadbeefd1a38b52016-12-10 13:15:33 -0800374// Get the ufrags out of an SDP blob. Useful for testing ICE restart
375// behavior.
376std::vector<std::string> GetUfrags(
377 const webrtc::SessionDescriptionInterface* desc) {
378 std::vector<std::string> ufrags;
379 for (const cricket::TransportInfo& info :
380 desc->description()->transport_infos()) {
381 ufrags.push_back(info.description.ice_ufrag);
382 }
383 return ufrags;
384}
385
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386void SetSsrcToZero(std::string* sdp) {
387 const char kSdpSsrcAtribute[] = "a=ssrc:";
388 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
389 size_t ssrc_pos = 0;
390 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
391 std::string::npos) {
392 size_t end_ssrc = sdp->find(" ", ssrc_pos);
393 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
394 ssrc_pos = end_ssrc;
395 }
396}
397
deadbeefab9b2d12015-10-14 11:33:11 -0700398// Check if |streams| contains the specified track.
399bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
400 const std::string& stream_label,
401 const std::string& track_id) {
402 for (const cricket::StreamParams& params : streams) {
403 if (params.sync_label == stream_label && params.id == track_id) {
404 return true;
405 }
406 }
407 return false;
408}
409
410// Check if |senders| contains the specified sender, by id.
411bool ContainsSender(
412 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
413 const std::string& id) {
414 for (const auto& sender : senders) {
415 if (sender->id() == id) {
416 return true;
417 }
418 }
419 return false;
420}
421
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700422// Check if |senders| contains the specified sender, by id and stream id.
423bool ContainsSender(
424 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
425 const std::string& id,
426 const std::string& stream_id) {
427 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700428 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700429 return true;
430 }
431 }
432 return false;
433}
434
deadbeefab9b2d12015-10-14 11:33:11 -0700435// Create a collection of streams.
436// CreateStreamCollection(1) creates a collection that
437// correspond to kSdpStringWithStream1.
438// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
439rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700440 int number_of_streams,
441 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700442 rtc::scoped_refptr<StreamCollection> local_collection(
443 StreamCollection::Create());
444
445 for (int i = 0; i < number_of_streams; ++i) {
446 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
447 webrtc::MediaStream::Create(kStreams[i]));
448
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700449 for (int j = 0; j < tracks_per_stream; ++j) {
450 // Add a local audio track.
451 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
452 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
453 nullptr));
454 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700455
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700456 // Add a local video track.
457 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
458 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
459 webrtc::FakeVideoTrackSource::Create()));
460 stream->AddTrack(video_track);
461 }
deadbeefab9b2d12015-10-14 11:33:11 -0700462
463 local_collection->AddStream(stream);
464 }
465 return local_collection;
466}
467
468// Check equality of StreamCollections.
469bool CompareStreamCollections(StreamCollectionInterface* s1,
470 StreamCollectionInterface* s2) {
471 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
472 return false;
473 }
474
475 for (size_t i = 0; i != s1->count(); ++i) {
476 if (s1->at(i)->label() != s2->at(i)->label()) {
477 return false;
478 }
479 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
480 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
481 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
482 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
483
484 if (audio_tracks1.size() != audio_tracks2.size()) {
485 return false;
486 }
487 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
488 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
489 return false;
490 }
491 }
492 if (video_tracks1.size() != video_tracks2.size()) {
493 return false;
494 }
495 for (size_t j = 0; j != video_tracks1.size(); ++j) {
496 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
497 return false;
498 }
499 }
500 }
501 return true;
502}
503
perkjd61bf802016-03-24 03:16:19 -0700504// Helper class to test Observer.
505class MockTrackObserver : public ObserverInterface {
506 public:
507 explicit MockTrackObserver(NotifierInterface* notifier)
508 : notifier_(notifier) {
509 notifier_->RegisterObserver(this);
510 }
511
512 ~MockTrackObserver() { Unregister(); }
513
514 void Unregister() {
515 if (notifier_) {
516 notifier_->UnregisterObserver(this);
517 notifier_ = nullptr;
518 }
519 }
520
521 MOCK_METHOD0(OnChanged, void());
522
523 private:
524 NotifierInterface* notifier_;
525};
526
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527class MockPeerConnectionObserver : public PeerConnectionObserver {
528 public:
deadbeefab9b2d12015-10-14 11:33:11 -0700529 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200530 virtual ~MockPeerConnectionObserver() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 }
532 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
533 pc_ = pc;
534 if (pc) {
535 state_ = pc_->signaling_state();
536 }
537 }
nisseef8b61e2016-04-29 06:09:15 -0700538 void OnSignalingChange(
539 PeerConnectionInterface::SignalingState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 EXPECT_EQ(pc_->signaling_state(), new_state);
541 state_ = new_state;
542 }
deadbeefab9b2d12015-10-14 11:33:11 -0700543
544 MediaStreamInterface* RemoteStream(const std::string& label) {
545 return remote_streams_->find(label);
546 }
547 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700548 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 last_added_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700550 remote_streams_->AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700552 void OnRemoveStream(
553 rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 last_removed_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700555 remote_streams_->RemoveStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 }
perkjdfb769d2016-02-09 03:09:43 -0800557 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700558 void OnDataChannel(
559 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 last_datachannel_ = data_channel;
561 }
562
perkjdfb769d2016-02-09 03:09:43 -0800563 void OnIceConnectionChange(
564 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 EXPECT_EQ(pc_->ice_connection_state(), new_state);
zhihuang81c3a032016-11-17 12:06:24 -0800566 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 }
perkjdfb769d2016-02-09 03:09:43 -0800568 void OnIceGatheringChange(
569 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
perkjdfb769d2016-02-09 03:09:43 -0800571 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete;
zhihuang81c3a032016-11-17 12:06:24 -0800572 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 }
perkjdfb769d2016-02-09 03:09:43 -0800574 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
576 pc_->ice_gathering_state());
577
578 std::string sdp;
579 EXPECT_TRUE(candidate->ToString(&sdp));
580 EXPECT_LT(0u, sdp.size());
581 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
582 candidate->sdp_mline_index(), sdp, NULL));
583 EXPECT_TRUE(last_candidate_.get() != NULL);
zhihuang81c3a032016-11-17 12:06:24 -0800584 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700585 }
586
587 void OnIceCandidatesRemoved(
588 const std::vector<cricket::Candidate>& candidates) override {
zhihuang81c3a032016-11-17 12:06:24 -0800589 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700590 }
591
592 void OnIceConnectionReceivingChange(bool receiving) override {
zhihuang81c3a032016-11-17 12:06:24 -0800593 callback_triggered_ = true;
594 }
595
zhihuangc63b8942016-12-02 15:41:10 -0800596 void OnAddTrack(
597 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
598 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
599 streams) override {
zhihuang81c3a032016-11-17 12:06:24 -0800600 EXPECT_TRUE(receiver != nullptr);
601 num_added_tracks_++;
602 last_added_track_label_ = receiver->id();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604
605 // Returns the label of the last added stream.
606 // Empty string if no stream have been added.
607 std::string GetLastAddedStreamLabel() {
608 if (last_added_stream_.get())
609 return last_added_stream_->label();
610 return "";
611 }
612 std::string GetLastRemovedStreamLabel() {
613 if (last_removed_stream_.get())
614 return last_removed_stream_->label();
615 return "";
616 }
617
zhihuang9763d562016-08-05 11:14:50 -0700618 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 PeerConnectionInterface::SignalingState state_;
kwibergd1fe2812016-04-27 06:47:29 -0700620 std::unique_ptr<IceCandidateInterface> last_candidate_;
zhihuang9763d562016-08-05 11:14:50 -0700621 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
deadbeefab9b2d12015-10-14 11:33:11 -0700622 rtc::scoped_refptr<StreamCollection> remote_streams_;
623 bool renegotiation_needed_ = false;
624 bool ice_complete_ = false;
zhihuang81c3a032016-11-17 12:06:24 -0800625 bool callback_triggered_ = false;
626 int num_added_tracks_ = 0;
627 std::string last_added_track_label_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628
629 private:
zhihuang9763d562016-08-05 11:14:50 -0700630 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
631 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632};
633
634} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700635
zhihuang29ff8442016-07-27 11:07:25 -0700636// The PeerConnectionMediaConfig tests below verify that configuration
637// and constraints are propagated into the MediaConfig passed to
638// CreateMediaController. These settings are intended for MediaChannel
639// constructors, but that is not exercised by these unittest.
640class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
641 public:
kwiberg1e4e8cb2017-01-31 01:48:08 -0800642 PeerConnectionFactoryForTest()
643 : webrtc::PeerConnectionFactory(
644 webrtc::CreateBuiltinAudioEncoderFactory(),
645 webrtc::CreateBuiltinAudioDecoderFactory()) {}
646
zhihuang29ff8442016-07-27 11:07:25 -0700647 webrtc::MediaControllerInterface* CreateMediaController(
skvlad11a9cbf2016-10-07 11:53:05 -0700648 const cricket::MediaConfig& config,
649 webrtc::RtcEventLog* event_log) const override {
zhihuang29ff8442016-07-27 11:07:25 -0700650 create_media_controller_called_ = true;
651 create_media_controller_config_ = config;
652
653 webrtc::MediaControllerInterface* mc =
skvlad11a9cbf2016-10-07 11:53:05 -0700654 PeerConnectionFactory::CreateMediaController(config, event_log);
zhihuang29ff8442016-07-27 11:07:25 -0700655 EXPECT_TRUE(mc != nullptr);
656 return mc;
657 }
658
659 cricket::TransportController* CreateTransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700660 cricket::PortAllocator* port_allocator,
661 bool redetermine_role_on_ice_restart) override {
zhihuang29ff8442016-07-27 11:07:25 -0700662 transport_controller = new cricket::TransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700663 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
664 redetermine_role_on_ice_restart);
zhihuang29ff8442016-07-27 11:07:25 -0700665 return transport_controller;
666 }
667
668 cricket::TransportController* transport_controller;
669 // Mutable, so they can be modified in the above const-declared method.
670 mutable bool create_media_controller_called_ = false;
671 mutable cricket::MediaConfig create_media_controller_config_;
672};
673
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674class PeerConnectionInterfaceTest : public testing::Test {
675 protected:
phoglund37ebcf02016-01-08 05:04:57 -0800676 PeerConnectionInterfaceTest() {
677#ifdef WEBRTC_ANDROID
678 webrtc::InitializeAndroidObjects();
679#endif
680 }
681
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 virtual void SetUp() {
683 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700684 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
685 nullptr, nullptr, nullptr);
686 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700687 pc_factory_for_test_ =
688 new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
689 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 }
691
692 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700693 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 }
695
deadbeef293e9262017-01-11 12:28:30 -0800696 // DTLS does not work in a loopback call, so is disabled for most of the
697 // tests in this file.
698 void CreatePeerConnectionWithoutDtls() {
699 FakeConstraints no_dtls_constraints;
700 no_dtls_constraints.AddMandatory(
701 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
702
703 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
704 &no_dtls_constraints);
705 }
706
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700708 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
709 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 }
711
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700712 void CreatePeerConnectionWithIceTransportsType(
713 PeerConnectionInterface::IceTransportsType type) {
714 PeerConnectionInterface::RTCConfiguration config;
715 config.type = type;
716 return CreatePeerConnection(config, nullptr);
717 }
718
719 void CreatePeerConnectionWithIceServer(const std::string& uri,
720 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800721 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700723 server.uri = uri;
724 server.password = password;
725 config.servers.push_back(server);
726 CreatePeerConnection(config, nullptr);
727 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700729 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
730 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700731 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800732 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
733 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000734
Henrik Boströmd79599d2016-06-01 13:58:50 +0200735 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000736 bool dtls;
737 if (FindConstraint(constraints,
738 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
739 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200740 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800741 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
742 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000743 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200744 pc_ = pc_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800745 config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200746 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 ASSERT_TRUE(pc_.get() != NULL);
748 observer_.SetPeerConnectionInterface(pc_.get());
749 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
750 }
751
deadbeef0a6c4ca2015-10-06 11:38:28 -0700752 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800753 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700754 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700755 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800756 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700757
zhihuang9763d562016-08-05 11:14:50 -0700758 rtc::scoped_refptr<PeerConnectionInterface> pc;
hbosd7973cc2016-05-27 06:08:53 -0700759 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
760 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800761 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700762 }
763
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700765 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800766 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
767 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
768 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800770 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771
deadbeef0a6c4ca2015-10-06 11:38:28 -0700772 CreatePeerConnectionExpectFail(kStunInvalidPort);
773 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
774 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700776 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800777 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
778 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800780 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800782 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800784 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 }
786
787 void ReleasePeerConnection() {
788 pc_ = NULL;
789 observer_.SetPeerConnectionInterface(NULL);
790 }
791
deadbeefab9b2d12015-10-14 11:33:11 -0700792 void AddVideoStream(const std::string& label) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700794 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700796 rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
deadbeef112b2e92017-02-10 20:13:37 -0800797 pc_factory_->CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(
798 new cricket::FakeVideoCapturer()),
799 NULL));
zhihuang9763d562016-08-05 11:14:50 -0700800 rtc::scoped_refptr<VideoTrackInterface> video_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 pc_factory_->CreateVideoTrack(label + "v0", video_source));
802 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000803 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
805 observer_.renegotiation_needed_ = false;
806 }
807
808 void AddVoiceStream(const std::string& label) {
809 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700810 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700812 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 pc_factory_->CreateAudioTrack(label + "a0", NULL));
814 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000815 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
817 observer_.renegotiation_needed_ = false;
818 }
819
820 void AddAudioVideoStream(const std::string& stream_label,
821 const std::string& audio_track_label,
822 const std::string& video_track_label) {
823 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700824 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 pc_factory_->CreateLocalMediaStream(stream_label));
zhihuang9763d562016-08-05 11:14:50 -0700826 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 pc_factory_->CreateAudioTrack(
828 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
829 stream->AddTrack(audio_track.get());
zhihuang9763d562016-08-05 11:14:50 -0700830 rtc::scoped_refptr<VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -0700831 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -0800832 video_track_label, pc_factory_->CreateVideoSource(
833 std::unique_ptr<cricket::VideoCapturer>(
834 new cricket::FakeVideoCapturer()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000836 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
838 observer_.renegotiation_needed_ = false;
839 }
840
kwibergd1fe2812016-04-27 06:47:29 -0700841 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700842 bool offer,
843 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000844 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
845 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 MockCreateSessionDescriptionObserver>());
847 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700848 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700850 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 }
852 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
kwiberg2bbff992016-03-16 11:03:04 -0700853 desc->reset(observer->release_desc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 return observer->result();
855 }
856
kwibergd1fe2812016-04-27 06:47:29 -0700857 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700858 MediaConstraintsInterface* constraints) {
859 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 }
861
kwibergd1fe2812016-04-27 06:47:29 -0700862 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700863 MediaConstraintsInterface* constraints) {
864 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 }
866
867 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000868 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
869 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 MockSetSessionDescriptionObserver>());
871 if (local) {
872 pc_->SetLocalDescription(observer, desc);
873 } else {
874 pc_->SetRemoteDescription(observer, desc);
875 }
zhihuang29ff8442016-07-27 11:07:25 -0700876 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
877 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 return observer->result();
880 }
881
882 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
883 return DoSetSessionDescription(desc, true);
884 }
885
886 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
887 return DoSetSessionDescription(desc, false);
888 }
889
890 // Calls PeerConnection::GetStats and check the return value.
891 // It does not verify the values in the StatReports since a RTCP packet might
892 // be required.
893 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000894 rtc::scoped_refptr<MockStatsObserver> observer(
895 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000896 if (!pc_->GetStats(
897 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 return false;
899 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
900 return observer->called();
901 }
902
903 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800904 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 // Create a local stream with audio&video tracks.
906 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
907 CreateOfferReceiveAnswer();
908 }
909
910 // Verify that RTP Header extensions has been negotiated for audio and video.
911 void VerifyRemoteRtpHeaderExtensions() {
912 const cricket::MediaContentDescription* desc =
913 cricket::GetFirstAudioContentDescription(
914 pc_->remote_description()->description());
915 ASSERT_TRUE(desc != NULL);
916 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
917
918 desc = cricket::GetFirstVideoContentDescription(
919 pc_->remote_description()->description());
920 ASSERT_TRUE(desc != NULL);
921 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
922 }
923
924 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700925 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700926 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 std::string sdp;
928 EXPECT_TRUE(offer->ToString(&sdp));
929 SessionDescriptionInterface* remote_offer =
930 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
931 sdp, NULL);
932 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
933 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
934 }
935
deadbeefab9b2d12015-10-14 11:33:11 -0700936 void CreateAndSetRemoteOffer(const std::string& sdp) {
937 SessionDescriptionInterface* remote_offer =
938 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
939 sdp, nullptr);
940 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
941 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
942 }
943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700945 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700946 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947
948 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
949 // audio codec change, even if the parameter has nothing to do with
950 // receiving. Not all parameters are serialized to SDP.
951 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
952 // the SessionDescription, it is necessary to do that here to in order to
953 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
954 // https://code.google.com/p/webrtc/issues/detail?id=1356
955 std::string sdp;
956 EXPECT_TRUE(answer->ToString(&sdp));
957 SessionDescriptionInterface* new_answer =
958 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
959 sdp, NULL);
960 EXPECT_TRUE(DoSetLocalDescription(new_answer));
961 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
962 }
963
964 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700965 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700966 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967
968 std::string sdp;
969 EXPECT_TRUE(answer->ToString(&sdp));
970 SessionDescriptionInterface* pr_answer =
971 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
972 sdp, NULL);
973 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
974 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
975 }
976
977 void CreateOfferReceiveAnswer() {
978 CreateOfferAsLocalDescription();
979 std::string sdp;
980 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
981 CreateAnswerAsRemoteDescription(sdp);
982 }
983
984 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700985 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700986 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
988 // audio codec change, even if the parameter has nothing to do with
989 // receiving. Not all parameters are serialized to SDP.
990 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
991 // the SessionDescription, it is necessary to do that here to in order to
992 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
993 // https://code.google.com/p/webrtc/issues/detail?id=1356
994 std::string sdp;
995 EXPECT_TRUE(offer->ToString(&sdp));
996 SessionDescriptionInterface* new_offer =
997 webrtc::CreateSessionDescription(
998 SessionDescriptionInterface::kOffer,
999 sdp, NULL);
1000
1001 EXPECT_TRUE(DoSetLocalDescription(new_offer));
1002 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001003 // Wait for the ice_complete message, so that SDP will have candidates.
1004 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 }
1006
deadbeefab9b2d12015-10-14 11:33:11 -07001007 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1009 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001010 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 EXPECT_TRUE(DoSetRemoteDescription(answer));
1012 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1013 }
1014
deadbeefab9b2d12015-10-14 11:33:11 -07001015 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 webrtc::JsepSessionDescription* pr_answer =
1017 new webrtc::JsepSessionDescription(
1018 SessionDescriptionInterface::kPrAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001019 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
1021 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
1022 webrtc::JsepSessionDescription* answer =
1023 new webrtc::JsepSessionDescription(
1024 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001025 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 EXPECT_TRUE(DoSetRemoteDescription(answer));
1027 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1028 }
1029
1030 // Help function used for waiting until a the last signaled remote stream has
1031 // the same label as |stream_label|. In a few of the tests in this file we
1032 // answer with the same session description as we offer and thus we can
1033 // check if OnAddStream have been called with the same stream as we offer to
1034 // send.
1035 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
1036 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
1037 }
1038
1039 // Creates an offer and applies it as a local session description.
1040 // Creates an answer with the same SDP an the offer but removes all lines
1041 // that start with a:ssrc"
1042 void CreateOfferReceiveAnswerWithoutSsrc() {
1043 CreateOfferAsLocalDescription();
1044 std::string sdp;
1045 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1046 SetSsrcToZero(&sdp);
1047 CreateAnswerAsRemoteDescription(sdp);
1048 }
1049
deadbeefab9b2d12015-10-14 11:33:11 -07001050 // This function creates a MediaStream with label kStreams[0] and
1051 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1052 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001053 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001054 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001055 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001056 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1057 size_t number_of_video_tracks) {
1058 EXPECT_LE(number_of_audio_tracks, 2u);
1059 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001060
1061 reference_collection_ = StreamCollection::Create();
1062 std::string sdp_ms1 = std::string(kSdpStringInit);
1063
1064 std::string mediastream_label = kStreams[0];
1065
1066 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1067 webrtc::MediaStream::Create(mediastream_label));
1068 reference_collection_->AddStream(stream);
1069
1070 if (number_of_audio_tracks > 0) {
1071 sdp_ms1 += std::string(kSdpStringAudio);
1072 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1073 AddAudioTrack(kAudioTracks[0], stream);
1074 }
1075 if (number_of_audio_tracks > 1) {
1076 sdp_ms1 += kSdpStringMs1Audio1;
1077 AddAudioTrack(kAudioTracks[1], stream);
1078 }
1079
1080 if (number_of_video_tracks > 0) {
1081 sdp_ms1 += std::string(kSdpStringVideo);
1082 sdp_ms1 += std::string(kSdpStringMs1Video0);
1083 AddVideoTrack(kVideoTracks[0], stream);
1084 }
1085 if (number_of_video_tracks > 1) {
1086 sdp_ms1 += kSdpStringMs1Video1;
1087 AddVideoTrack(kVideoTracks[1], stream);
1088 }
1089
kwibergd1fe2812016-04-27 06:47:29 -07001090 return std::unique_ptr<SessionDescriptionInterface>(
kwiberg2bbff992016-03-16 11:03:04 -07001091 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1092 sdp_ms1, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001093 }
1094
1095 void AddAudioTrack(const std::string& track_id,
1096 MediaStreamInterface* stream) {
1097 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1098 webrtc::AudioTrack::Create(track_id, nullptr));
1099 ASSERT_TRUE(stream->AddTrack(audio_track));
1100 }
1101
1102 void AddVideoTrack(const std::string& track_id,
1103 MediaStreamInterface* stream) {
1104 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001105 webrtc::VideoTrack::Create(track_id,
1106 webrtc::FakeVideoTrackSource::Create()));
deadbeefab9b2d12015-10-14 11:33:11 -07001107 ASSERT_TRUE(stream->AddTrack(video_track));
1108 }
1109
kwibergfd8be342016-05-14 19:44:11 -07001110 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
deadbeef293e9262017-01-11 12:28:30 -08001111 CreatePeerConnectionWithoutDtls();
zhihuang8f65cdf2016-05-06 18:40:30 -07001112 AddVoiceStream(kStreamLabel1);
kwibergfd8be342016-05-14 19:44:11 -07001113 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001114 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1115 return offer;
1116 }
1117
kwibergfd8be342016-05-14 19:44:11 -07001118 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001119 CreateAnswerWithOneAudioStream() {
kwibergfd8be342016-05-14 19:44:11 -07001120 std::unique_ptr<SessionDescriptionInterface> offer =
zhihuang8f65cdf2016-05-06 18:40:30 -07001121 CreateOfferWithOneAudioStream();
1122 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergfd8be342016-05-14 19:44:11 -07001123 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001124 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1125 return answer;
1126 }
1127
1128 const std::string& GetFirstAudioStreamCname(
1129 const SessionDescriptionInterface* desc) {
1130 const cricket::ContentInfo* audio_content =
1131 cricket::GetFirstAudioContent(desc->description());
1132 const cricket::AudioContentDescription* audio_desc =
1133 static_cast<const cricket::AudioContentDescription*>(
1134 audio_content->description);
1135 return audio_desc->streams()[0].cname;
1136 }
1137
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001138 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001139 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001140 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1141 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1142 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001143 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001144 rtc::scoped_refptr<StreamCollection> reference_collection_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145};
1146
zhihuang29ff8442016-07-27 11:07:25 -07001147// Test that no callbacks on the PeerConnectionObserver are called after the
1148// PeerConnection is closed.
1149TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) {
zhihuang9763d562016-08-05 11:14:50 -07001150 rtc::scoped_refptr<PeerConnectionInterface> pc(
zhihuang29ff8442016-07-27 11:07:25 -07001151 pc_factory_for_test_->CreatePeerConnection(
1152 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr,
1153 nullptr, &observer_));
1154 observer_.SetPeerConnectionInterface(pc.get());
1155 pc->Close();
1156
1157 // No callbacks is expected to be called.
zhihuang81c3a032016-11-17 12:06:24 -08001158 observer_.callback_triggered_ = false;
zhihuang29ff8442016-07-27 11:07:25 -07001159 std::vector<cricket::Candidate> candidates;
1160 pc_factory_for_test_->transport_controller->SignalGatheringState(
1161 cricket::IceGatheringState{});
1162 pc_factory_for_test_->transport_controller->SignalCandidatesGathered(
1163 "", candidates);
1164 pc_factory_for_test_->transport_controller->SignalConnectionState(
1165 cricket::IceConnectionState{});
1166 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved(
1167 candidates);
1168 pc_factory_for_test_->transport_controller->SignalReceiving(false);
zhihuang81c3a032016-11-17 12:06:24 -08001169 EXPECT_FALSE(observer_.callback_triggered_);
zhihuang29ff8442016-07-27 11:07:25 -07001170}
1171
zhihuang8f65cdf2016-05-06 18:40:30 -07001172// Generate different CNAMEs when PeerConnections are created.
1173// The CNAMEs are expected to be generated randomly. It is possible
1174// that the test fails, though the possibility is very low.
1175TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001176 std::unique_ptr<SessionDescriptionInterface> offer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001177 CreateOfferWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001178 std::unique_ptr<SessionDescriptionInterface> offer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001179 CreateOfferWithOneAudioStream();
1180 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1181 GetFirstAudioStreamCname(offer2.get()));
1182}
1183
1184TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001185 std::unique_ptr<SessionDescriptionInterface> answer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001186 CreateAnswerWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001187 std::unique_ptr<SessionDescriptionInterface> answer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001188 CreateAnswerWithOneAudioStream();
1189 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1190 GetFirstAudioStreamCname(answer2.get()));
1191}
1192
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193TEST_F(PeerConnectionInterfaceTest,
1194 CreatePeerConnectionWithDifferentConfigurations) {
1195 CreatePeerConnectionWithDifferentConfigurations();
1196}
1197
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001198TEST_F(PeerConnectionInterfaceTest,
1199 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1200 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1201 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1202 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1203 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1204 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1205 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1206 port_allocator_->candidate_filter());
1207 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1208 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1209}
1210
1211// Test that when a PeerConnection is created with a nonzero candidate pool
1212// size, the pooled PortAllocatorSession is created with all the attributes
1213// in the RTCConfiguration.
1214TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1215 PeerConnectionInterface::RTCConfiguration config;
1216 PeerConnectionInterface::IceServer server;
1217 server.uri = kStunAddressOnly;
1218 config.servers.push_back(server);
1219 config.type = PeerConnectionInterface::kRelay;
1220 config.disable_ipv6 = true;
1221 config.tcp_candidate_policy =
1222 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001223 config.candidate_network_policy =
1224 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001225 config.ice_candidate_pool_size = 1;
1226 CreatePeerConnection(config, nullptr);
1227
1228 const cricket::FakePortAllocatorSession* session =
1229 static_cast<const cricket::FakePortAllocatorSession*>(
1230 port_allocator_->GetPooledSession());
1231 ASSERT_NE(nullptr, session);
1232 EXPECT_EQ(1UL, session->stun_servers().size());
1233 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1234 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001235 EXPECT_LT(0U,
1236 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001237}
1238
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001239// Test that the PeerConnection initializes the port allocator passed into it,
1240// and on the correct thread.
1241TEST_F(PeerConnectionInterfaceTest,
1242 CreatePeerConnectionInitializesPortAllocator) {
1243 rtc::Thread network_thread;
1244 network_thread.Start();
1245 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1246 webrtc::CreatePeerConnectionFactory(
1247 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
1248 nullptr, nullptr, nullptr));
1249 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1250 new cricket::FakePortAllocator(&network_thread, nullptr));
1251 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1252 PeerConnectionInterface::RTCConfiguration config;
1253 rtc::scoped_refptr<PeerConnectionInterface> pc(
1254 pc_factory->CreatePeerConnection(
1255 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1256 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1257 // so all we have to do here is check that it's initialized.
1258 EXPECT_TRUE(raw_port_allocator->initialized());
1259}
1260
deadbeef46c73892016-11-16 19:42:04 -08001261// Check that GetConfiguration returns the configuration the PeerConnection was
1262// constructed with, before SetConfiguration is called.
1263TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1264 PeerConnectionInterface::RTCConfiguration config;
1265 config.type = PeerConnectionInterface::kRelay;
1266 CreatePeerConnection(config, nullptr);
1267
1268 PeerConnectionInterface::RTCConfiguration returned_config =
1269 pc_->GetConfiguration();
1270 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1271}
1272
1273// Check that GetConfiguration returns the last configuration passed into
1274// SetConfiguration.
1275TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1276 CreatePeerConnection();
1277
1278 PeerConnectionInterface::RTCConfiguration config;
1279 config.type = PeerConnectionInterface::kRelay;
1280 EXPECT_TRUE(pc_->SetConfiguration(config));
1281
1282 PeerConnectionInterface::RTCConfiguration returned_config =
1283 pc_->GetConfiguration();
1284 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1285}
1286
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287TEST_F(PeerConnectionInterfaceTest, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001288 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001289 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 AddVoiceStream(kStreamLabel2);
1291 ASSERT_EQ(2u, pc_->local_streams()->count());
1292
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001293 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001294 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
zhihuang9763d562016-08-05 11:14:50 -07001296 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1297 pc_factory_->CreateAudioTrack(kStreamLabel3,
1298 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001300 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001301 EXPECT_EQ(3u, pc_->local_streams()->count());
1302
1303 // Remove the third stream.
1304 pc_->RemoveStream(pc_->local_streams()->at(2));
1305 EXPECT_EQ(2u, pc_->local_streams()->count());
1306
1307 // Remove the second stream.
1308 pc_->RemoveStream(pc_->local_streams()->at(1));
1309 EXPECT_EQ(1u, pc_->local_streams()->count());
1310
1311 // Remove the first stream.
1312 pc_->RemoveStream(pc_->local_streams()->at(0));
1313 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314}
1315
deadbeefab9b2d12015-10-14 11:33:11 -07001316// Test that the created offer includes streams we added.
1317TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001318 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001319 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001320 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001321 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001322
1323 const cricket::ContentInfo* audio_content =
1324 cricket::GetFirstAudioContent(offer->description());
1325 const cricket::AudioContentDescription* audio_desc =
1326 static_cast<const cricket::AudioContentDescription*>(
1327 audio_content->description);
1328 EXPECT_TRUE(
1329 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1330
1331 const cricket::ContentInfo* video_content =
1332 cricket::GetFirstVideoContent(offer->description());
1333 const cricket::VideoContentDescription* video_desc =
1334 static_cast<const cricket::VideoContentDescription*>(
1335 video_content->description);
1336 EXPECT_TRUE(
1337 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1338
1339 // Add another stream and ensure the offer includes both the old and new
1340 // streams.
1341 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001342 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001343
1344 audio_content = cricket::GetFirstAudioContent(offer->description());
1345 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1346 audio_content->description);
1347 EXPECT_TRUE(
1348 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1349 EXPECT_TRUE(
1350 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1351
1352 video_content = cricket::GetFirstVideoContent(offer->description());
1353 video_desc = static_cast<const cricket::VideoContentDescription*>(
1354 video_content->description);
1355 EXPECT_TRUE(
1356 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1357 EXPECT_TRUE(
1358 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1359}
1360
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001362 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001363 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 ASSERT_EQ(1u, pc_->local_streams()->count());
1365 pc_->RemoveStream(pc_->local_streams()->at(0));
1366 EXPECT_EQ(0u, pc_->local_streams()->count());
1367}
1368
deadbeefe1f9d832016-01-14 15:35:42 -08001369// Test for AddTrack and RemoveTrack methods.
1370// Tests that the created offer includes tracks we added,
1371// and that the RtpSenders are created correctly.
1372// Also tests that RemoveTrack removes the tracks from subsequent offers.
1373TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001374 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001375 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001376 rtc::scoped_refptr<MediaStreamInterface> stream(
deadbeefe1f9d832016-01-14 15:35:42 -08001377 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1378 std::vector<MediaStreamInterface*> stream_list;
1379 stream_list.push_back(stream.get());
zhihuang9763d562016-08-05 11:14:50 -07001380 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001381 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001382 rtc::scoped_refptr<VideoTrackInterface> video_track(
1383 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001384 "video_track", pc_factory_->CreateVideoSource(
1385 std::unique_ptr<cricket::VideoCapturer>(
1386 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001387 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1388 auto video_sender = pc_->AddTrack(video_track, stream_list);
deadbeefa601f5c2016-06-06 14:27:39 -07001389 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1390 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001391 EXPECT_EQ("audio_track", audio_sender->id());
1392 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001393 EXPECT_EQ(1UL, video_sender->stream_ids().size());
1394 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001395 EXPECT_EQ("video_track", video_sender->id());
1396 EXPECT_EQ(video_track, video_sender->track());
1397
1398 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001399 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001400 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001401
1402 const cricket::ContentInfo* audio_content =
1403 cricket::GetFirstAudioContent(offer->description());
1404 const cricket::AudioContentDescription* audio_desc =
1405 static_cast<const cricket::AudioContentDescription*>(
1406 audio_content->description);
1407 EXPECT_TRUE(
1408 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1409
1410 const cricket::ContentInfo* video_content =
1411 cricket::GetFirstVideoContent(offer->description());
1412 const cricket::VideoContentDescription* video_desc =
1413 static_cast<const cricket::VideoContentDescription*>(
1414 video_content->description);
1415 EXPECT_TRUE(
1416 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1417
1418 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1419
1420 // Now try removing the tracks.
1421 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1422 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1423
1424 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001425 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001426
1427 audio_content = cricket::GetFirstAudioContent(offer->description());
1428 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1429 audio_content->description);
1430 EXPECT_FALSE(
1431 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1432
1433 video_content = cricket::GetFirstVideoContent(offer->description());
1434 video_desc = static_cast<const cricket::VideoContentDescription*>(
1435 video_content->description);
1436 EXPECT_FALSE(
1437 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1438
1439 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1440
1441 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1442 // should return false.
1443 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1444 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1445}
1446
1447// Test creating senders without a stream specified,
1448// expecting a random stream ID to be generated.
1449TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001450 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001451 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001452 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001453 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001454 rtc::scoped_refptr<VideoTrackInterface> video_track(
1455 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001456 "video_track", pc_factory_->CreateVideoSource(
1457 std::unique_ptr<cricket::VideoCapturer>(
1458 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001459 auto audio_sender =
1460 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1461 auto video_sender =
1462 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1463 EXPECT_EQ("audio_track", audio_sender->id());
1464 EXPECT_EQ(audio_track, audio_sender->track());
1465 EXPECT_EQ("video_track", video_sender->id());
1466 EXPECT_EQ(video_track, video_sender->track());
1467 // If the ID is truly a random GUID, it should be infinitely unlikely they
1468 // will be the same.
deadbeefa601f5c2016-06-06 14:27:39 -07001469 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
deadbeefe1f9d832016-01-14 15:35:42 -08001470}
1471
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1473 InitiateCall();
1474 WaitAndVerifyOnAddStream(kStreamLabel1);
1475 VerifyRemoteRtpHeaderExtensions();
1476}
1477
1478TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001479 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001480 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 CreateOfferAsLocalDescription();
1482 std::string offer;
1483 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1484 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1485 WaitAndVerifyOnAddStream(kStreamLabel1);
1486}
1487
1488TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001489 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001490 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491
1492 CreateOfferAsRemoteDescription();
1493 CreateAnswerAsLocalDescription();
1494
1495 WaitAndVerifyOnAddStream(kStreamLabel1);
1496}
1497
1498TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001499 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001500 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501
1502 CreateOfferAsRemoteDescription();
1503 CreatePrAnswerAsLocalDescription();
1504 CreateAnswerAsLocalDescription();
1505
1506 WaitAndVerifyOnAddStream(kStreamLabel1);
1507}
1508
1509TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1510 InitiateCall();
1511 ASSERT_EQ(1u, pc_->remote_streams()->count());
1512 pc_->RemoveStream(pc_->local_streams()->at(0));
1513 CreateOfferReceiveAnswer();
1514 EXPECT_EQ(0u, pc_->remote_streams()->count());
deadbeefab9b2d12015-10-14 11:33:11 -07001515 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 CreateOfferReceiveAnswer();
1517}
1518
1519// Tests that after negotiating an audio only call, the respondent can perform a
1520// renegotiation that removes the audio stream.
1521TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001522 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 AddVoiceStream(kStreamLabel1);
1524 CreateOfferAsRemoteDescription();
1525 CreateAnswerAsLocalDescription();
1526
1527 ASSERT_EQ(1u, pc_->remote_streams()->count());
1528 pc_->RemoveStream(pc_->local_streams()->at(0));
1529 CreateOfferReceiveAnswer();
1530 EXPECT_EQ(0u, pc_->remote_streams()->count());
1531}
1532
1533// Test that candidates are generated and that we can parse our own candidates.
1534TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001535 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536
1537 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1538 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001539 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefab9b2d12015-10-14 11:33:11 -07001540 AddVideoStream(kStreamLabel1);
deadbeefc80741f2015-10-22 13:14:45 -07001541 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001542 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543
1544 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001545 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001546 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001547 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548
1549 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1550 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1551
1552 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1553}
1554
deadbeefab9b2d12015-10-14 11:33:11 -07001555// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556// not unique.
1557TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001558 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001560 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001561 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001562 EXPECT_TRUE(offer);
1563 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564
1565 // Create a local stream with audio&video tracks having same label.
1566 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1567
1568 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001569 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570
1571 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001572 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001573 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574}
1575
1576// Test that we will get different SSRCs for each tracks in the offer and answer
1577// we created.
1578TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001579 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 // Create a local stream with audio&video tracks having different labels.
1581 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1582
1583 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001584 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001585 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 int audio_ssrc = 0;
1587 int video_ssrc = 0;
1588 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1589 &audio_ssrc));
1590 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1591 &video_ssrc));
1592 EXPECT_NE(audio_ssrc, video_ssrc);
1593
1594 // Test CreateAnswer
1595 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergd1fe2812016-04-27 06:47:29 -07001596 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001597 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 audio_ssrc = 0;
1599 video_ssrc = 0;
1600 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1601 &audio_ssrc));
1602 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1603 &video_ssrc));
1604 EXPECT_NE(audio_ssrc, video_ssrc);
1605}
1606
deadbeefeb459812015-12-15 19:24:43 -08001607// Test that it's possible to call AddTrack on a MediaStream after adding
1608// the stream to a PeerConnection.
1609// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1610TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001611 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001612 // Create audio stream and add to PeerConnection.
1613 AddVoiceStream(kStreamLabel1);
1614 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1615
1616 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001617 rtc::scoped_refptr<VideoTrackInterface> video_track(
1618 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001619 "video_label", pc_factory_->CreateVideoSource(
1620 std::unique_ptr<cricket::VideoCapturer>(
1621 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001622 stream->AddTrack(video_track.get());
1623
kwibergd1fe2812016-04-27 06:47:29 -07001624 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001625 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001626
1627 const cricket::MediaContentDescription* video_desc =
1628 cricket::GetFirstVideoContentDescription(offer->description());
1629 EXPECT_TRUE(video_desc != nullptr);
1630}
1631
1632// Test that it's possible to call RemoveTrack on a MediaStream after adding
1633// the stream to a PeerConnection.
1634// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1635TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001636 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001637 // Create audio/video stream and add to PeerConnection.
1638 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1639 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1640
1641 // Remove the video track.
1642 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1643
kwibergd1fe2812016-04-27 06:47:29 -07001644 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001645 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001646
1647 const cricket::MediaContentDescription* video_desc =
1648 cricket::GetFirstVideoContentDescription(offer->description());
1649 EXPECT_TRUE(video_desc == nullptr);
1650}
1651
deadbeefbd7d8f72015-12-18 16:58:44 -08001652// Test creating a sender with a stream ID, and ensure the ID is populated
1653// in the offer.
1654TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001655 CreatePeerConnectionWithoutDtls();
deadbeefbd7d8f72015-12-18 16:58:44 -08001656 pc_->CreateSender("video", kStreamLabel1);
1657
kwibergd1fe2812016-04-27 06:47:29 -07001658 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001659 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001660
1661 const cricket::MediaContentDescription* video_desc =
1662 cricket::GetFirstVideoContentDescription(offer->description());
1663 ASSERT_TRUE(video_desc != nullptr);
1664 ASSERT_EQ(1u, video_desc->streams().size());
1665 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1666}
1667
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668// Test that we can specify a certain track that we want statistics about.
1669TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1670 InitiateCall();
1671 ASSERT_LT(0u, pc_->remote_streams()->count());
1672 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001673 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1675 EXPECT_TRUE(DoGetStats(remote_audio));
1676
1677 // Remove the stream. Since we are sending to our selves the local
1678 // and the remote stream is the same.
1679 pc_->RemoveStream(pc_->local_streams()->at(0));
1680 // Do a re-negotiation.
1681 CreateOfferReceiveAnswer();
1682
1683 ASSERT_EQ(0u, pc_->remote_streams()->count());
1684
1685 // Test that we still can get statistics for the old track. Even if it is not
1686 // sent any longer.
1687 EXPECT_TRUE(DoGetStats(remote_audio));
1688}
1689
1690// Test that we can get stats on a video track.
1691TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1692 InitiateCall();
1693 ASSERT_LT(0u, pc_->remote_streams()->count());
1694 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001695 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1697 EXPECT_TRUE(DoGetStats(remote_video));
1698}
1699
1700// Test that we don't get statistics for an invalid track.
zhihuange9e94c32016-11-04 11:38:15 -07001701TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001703 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 pc_factory_->CreateAudioTrack("unknown track", NULL));
1705 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1706}
1707
1708// This test setup two RTP data channels in loop back.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 FakeConstraints constraints;
1711 constraints.SetAllowRtpDataChannels();
1712 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001713 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001715 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 pc_->CreateDataChannel("test2", NULL);
1717 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001718 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001720 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 new MockDataChannelObserver(data2));
1722
1723 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1724 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1725 std::string data_to_send1 = "testing testing";
1726 std::string data_to_send2 = "testing something else";
1727 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1728
1729 CreateOfferReceiveAnswer();
1730 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1731 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1732
1733 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1734 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1735 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1736 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1737
1738 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1739 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1740
1741 data1->Close();
1742 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1743 CreateOfferReceiveAnswer();
1744 EXPECT_FALSE(observer1->IsOpen());
1745 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1746 EXPECT_TRUE(observer2->IsOpen());
1747
1748 data_to_send2 = "testing something else again";
1749 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1750
1751 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1752}
1753
1754// This test verifies that sendnig binary data over RTP data channels should
1755// fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 FakeConstraints constraints;
1758 constraints.SetAllowRtpDataChannels();
1759 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001760 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001762 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 pc_->CreateDataChannel("test2", NULL);
1764 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001765 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001767 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 new MockDataChannelObserver(data2));
1769
1770 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1771 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1772
1773 CreateOfferReceiveAnswer();
1774 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1775 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1776
1777 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1778 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1779
jbaucheec21bd2016-03-20 06:15:43 -07001780 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1782}
1783
1784// This test setup a RTP data channels in loop back and test that a channel is
1785// opened even if the remote end answer with a zero SSRC.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 FakeConstraints constraints;
1788 constraints.SetAllowRtpDataChannels();
1789 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001790 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001792 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 new MockDataChannelObserver(data1));
1794
1795 CreateOfferReceiveAnswerWithoutSsrc();
1796
1797 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1798
1799 data1->Close();
1800 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1801 CreateOfferReceiveAnswerWithoutSsrc();
1802 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1803 EXPECT_FALSE(observer1->IsOpen());
1804}
1805
1806// This test that if a data channel is added in an answer a receive only channel
1807// channel is created.
1808TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1809 FakeConstraints constraints;
1810 constraints.SetAllowRtpDataChannels();
1811 CreatePeerConnection(&constraints);
1812
1813 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07001814 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 pc_->CreateDataChannel(offer_label, NULL);
1816
1817 CreateOfferAsLocalDescription();
1818
1819 // Replace the data channel label in the offer and apply it as an answer.
1820 std::string receive_label = "answer_channel";
1821 std::string sdp;
1822 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001823 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 receive_label.c_str(), receive_label.length(),
1825 &sdp);
1826 CreateAnswerAsRemoteDescription(sdp);
1827
1828 // Verify that a new incoming data channel has been created and that
1829 // it is open but can't we written to.
1830 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1831 DataChannelInterface* received_channel = observer_.last_datachannel_;
1832 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1833 EXPECT_EQ(receive_label, received_channel->label());
1834 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1835
1836 // Verify that the channel we initially offered has been rejected.
1837 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1838
1839 // Do another offer / answer exchange and verify that the data channel is
1840 // opened.
1841 CreateOfferReceiveAnswer();
1842 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1843 kTimeout);
1844}
1845
1846// This test that no data channel is returned if a reliable channel is
1847// requested.
1848// TODO(perkj): Remove this test once reliable channels are implemented.
1849TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1850 FakeConstraints constraints;
1851 constraints.SetAllowRtpDataChannels();
1852 CreatePeerConnection(&constraints);
1853
1854 std::string label = "test";
1855 webrtc::DataChannelInit config;
1856 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07001857 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 pc_->CreateDataChannel(label, &config);
1859 EXPECT_TRUE(channel == NULL);
1860}
1861
deadbeefab9b2d12015-10-14 11:33:11 -07001862// Verifies that duplicated label is not allowed for RTP data channel.
1863TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1864 FakeConstraints constraints;
1865 constraints.SetAllowRtpDataChannels();
1866 CreatePeerConnection(&constraints);
1867
1868 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001869 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001870 pc_->CreateDataChannel(label, nullptr);
1871 EXPECT_NE(channel, nullptr);
1872
zhihuang9763d562016-08-05 11:14:50 -07001873 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001874 pc_->CreateDataChannel(label, nullptr);
1875 EXPECT_EQ(dup_channel, nullptr);
1876}
1877
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878// This tests that a SCTP data channel is returned using different
1879// DataChannelInit configurations.
1880TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1881 FakeConstraints constraints;
1882 constraints.SetAllowDtlsSctpDataChannels();
1883 CreatePeerConnection(&constraints);
1884
1885 webrtc::DataChannelInit config;
1886
zhihuang9763d562016-08-05 11:14:50 -07001887 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 pc_->CreateDataChannel("1", &config);
1889 EXPECT_TRUE(channel != NULL);
1890 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001891 EXPECT_TRUE(observer_.renegotiation_needed_);
1892 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893
1894 config.ordered = false;
1895 channel = pc_->CreateDataChannel("2", &config);
1896 EXPECT_TRUE(channel != NULL);
1897 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001898 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899
1900 config.ordered = true;
1901 config.maxRetransmits = 0;
1902 channel = pc_->CreateDataChannel("3", &config);
1903 EXPECT_TRUE(channel != NULL);
1904 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001905 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906
1907 config.maxRetransmits = -1;
1908 config.maxRetransmitTime = 0;
1909 channel = pc_->CreateDataChannel("4", &config);
1910 EXPECT_TRUE(channel != NULL);
1911 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001912 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913}
1914
1915// This tests that no data channel is returned if both maxRetransmits and
1916// maxRetransmitTime are set for SCTP data channels.
1917TEST_F(PeerConnectionInterfaceTest,
1918 CreateSctpDataChannelShouldFailForInvalidConfig) {
1919 FakeConstraints constraints;
1920 constraints.SetAllowDtlsSctpDataChannels();
1921 CreatePeerConnection(&constraints);
1922
1923 std::string label = "test";
1924 webrtc::DataChannelInit config;
1925 config.maxRetransmits = 0;
1926 config.maxRetransmitTime = 0;
1927
zhihuang9763d562016-08-05 11:14:50 -07001928 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 pc_->CreateDataChannel(label, &config);
1930 EXPECT_TRUE(channel == NULL);
1931}
1932
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933// The test verifies that creating a SCTP data channel with an id already in use
1934// or out of range should fail.
1935TEST_F(PeerConnectionInterfaceTest,
1936 CreateSctpDataChannelWithInvalidIdShouldFail) {
1937 FakeConstraints constraints;
1938 constraints.SetAllowDtlsSctpDataChannels();
1939 CreatePeerConnection(&constraints);
1940
1941 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07001942 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001944 config.id = 1;
1945 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 EXPECT_TRUE(channel != NULL);
1947 EXPECT_EQ(1, channel->id());
1948
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 channel = pc_->CreateDataChannel("x", &config);
1950 EXPECT_TRUE(channel == NULL);
1951
1952 config.id = cricket::kMaxSctpSid;
1953 channel = pc_->CreateDataChannel("max", &config);
1954 EXPECT_TRUE(channel != NULL);
1955 EXPECT_EQ(config.id, channel->id());
1956
1957 config.id = cricket::kMaxSctpSid + 1;
1958 channel = pc_->CreateDataChannel("x", &config);
1959 EXPECT_TRUE(channel == NULL);
1960}
1961
deadbeefab9b2d12015-10-14 11:33:11 -07001962// Verifies that duplicated label is allowed for SCTP data channel.
1963TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
1964 FakeConstraints constraints;
1965 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1966 true);
1967 CreatePeerConnection(&constraints);
1968
1969 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001970 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001971 pc_->CreateDataChannel(label, nullptr);
1972 EXPECT_NE(channel, nullptr);
1973
zhihuang9763d562016-08-05 11:14:50 -07001974 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001975 pc_->CreateDataChannel(label, nullptr);
1976 EXPECT_NE(dup_channel, nullptr);
1977}
1978
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001979// This test verifies that OnRenegotiationNeeded is fired for every new RTP
1980// DataChannel.
1981TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
1982 FakeConstraints constraints;
1983 constraints.SetAllowRtpDataChannels();
1984 CreatePeerConnection(&constraints);
1985
zhihuang9763d562016-08-05 11:14:50 -07001986 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001987 pc_->CreateDataChannel("test1", NULL);
1988 EXPECT_TRUE(observer_.renegotiation_needed_);
1989 observer_.renegotiation_needed_ = false;
1990
zhihuang9763d562016-08-05 11:14:50 -07001991 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001992 pc_->CreateDataChannel("test2", NULL);
1993 EXPECT_TRUE(observer_.renegotiation_needed_);
1994}
1995
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996// This test that a data channel closes when a PeerConnection is deleted/closed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 FakeConstraints constraints;
1999 constraints.SetAllowRtpDataChannels();
2000 CreatePeerConnection(&constraints);
2001
zhihuang9763d562016-08-05 11:14:50 -07002002 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002004 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 pc_->CreateDataChannel("test2", NULL);
2006 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002007 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002009 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 new MockDataChannelObserver(data2));
2011
2012 CreateOfferReceiveAnswer();
2013 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2014 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2015
2016 ReleasePeerConnection();
2017 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2018 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2019}
2020
2021// This test that data channels can be rejected in an answer.
2022TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
2023 FakeConstraints constraints;
2024 constraints.SetAllowRtpDataChannels();
2025 CreatePeerConnection(&constraints);
2026
zhihuang9763d562016-08-05 11:14:50 -07002027 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 pc_->CreateDataChannel("offer_channel", NULL));
2029
2030 CreateOfferAsLocalDescription();
2031
2032 // Create an answer where the m-line for data channels are rejected.
2033 std::string sdp;
2034 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2035 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
2036 SessionDescriptionInterface::kAnswer);
2037 EXPECT_TRUE(answer->Initialize(sdp, NULL));
2038 cricket::ContentInfo* data_info =
2039 answer->description()->GetContentByName("data");
2040 data_info->rejected = true;
2041
2042 DoSetRemoteDescription(answer);
2043 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2044}
2045
2046// Test that we can create a session description from an SDP string from
2047// FireFox, use it as a remote session description, generate an answer and use
2048// the answer as a local description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002049TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 FakeConstraints constraints;
2051 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2052 true);
2053 CreatePeerConnection(&constraints);
2054 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2055 SessionDescriptionInterface* desc =
2056 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002057 webrtc::kFireFoxSdpOffer, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2059 CreateAnswerAsLocalDescription();
2060 ASSERT_TRUE(pc_->local_description() != NULL);
2061 ASSERT_TRUE(pc_->remote_description() != NULL);
2062
2063 const cricket::ContentInfo* content =
2064 cricket::GetFirstAudioContent(pc_->local_description()->description());
2065 ASSERT_TRUE(content != NULL);
2066 EXPECT_FALSE(content->rejected);
2067
2068 content =
2069 cricket::GetFirstVideoContent(pc_->local_description()->description());
2070 ASSERT_TRUE(content != NULL);
2071 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002072#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 content =
2074 cricket::GetFirstDataContent(pc_->local_description()->description());
2075 ASSERT_TRUE(content != NULL);
2076 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002077#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078}
2079
deadbeef8662f942017-01-20 21:20:51 -08002080// Test that an offer can be received which offers DTLS with SDES fallback.
2081// Regression test for issue:
2082// https://bugs.chromium.org/p/webrtc/issues/detail?id=6972
2083TEST_F(PeerConnectionInterfaceTest, ReceiveDtlsSdesFallbackOffer) {
2084 FakeConstraints constraints;
2085 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2086 true);
2087 CreatePeerConnection(&constraints);
2088 // Wait for fake certificate to be generated. Previously, this is what caused
2089 // the "a=crypto" lines to be rejected.
2090 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2091 ASSERT_NE(nullptr, fake_certificate_generator_);
2092 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2093 kTimeout);
2094 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
2095 SessionDescriptionInterface::kOffer, kDtlsSdesFallbackSdp, nullptr);
2096 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2097 CreateAnswerAsLocalDescription();
2098}
2099
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100// Test that we can create an audio only offer and receive an answer with a
2101// limited set of audio codecs and receive an updated offer with more audio
2102// codecs, where the added codecs are not supported.
2103TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002104 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 AddVoiceStream("audio_label");
2106 CreateOfferAsLocalDescription();
2107
2108 SessionDescriptionInterface* answer =
2109 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
jbauchfabe2c92015-07-16 13:43:14 -07002110 webrtc::kAudioSdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 EXPECT_TRUE(DoSetSessionDescription(answer, false));
2112
2113 SessionDescriptionInterface* updated_offer =
2114 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002115 webrtc::kAudioSdpWithUnsupportedCodecs,
2116 nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
2118 CreateAnswerAsLocalDescription();
2119}
2120
deadbeefc80741f2015-10-22 13:14:45 -07002121// Test that if we're receiving (but not sending) a track, subsequent offers
2122// will have m-lines with a=recvonly.
2123TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2124 FakeConstraints constraints;
2125 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2126 true);
2127 CreatePeerConnection(&constraints);
2128 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2129 CreateAnswerAsLocalDescription();
2130
2131 // At this point we should be receiving stream 1, but not sending anything.
2132 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002133 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002134 DoCreateOffer(&offer, nullptr);
2135
2136 const cricket::ContentInfo* video_content =
2137 cricket::GetFirstVideoContent(offer->description());
2138 const cricket::VideoContentDescription* video_desc =
2139 static_cast<const cricket::VideoContentDescription*>(
2140 video_content->description);
2141 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
2142
2143 const cricket::ContentInfo* audio_content =
2144 cricket::GetFirstAudioContent(offer->description());
2145 const cricket::AudioContentDescription* audio_desc =
2146 static_cast<const cricket::AudioContentDescription*>(
2147 audio_content->description);
2148 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
2149}
2150
2151// Test that if we're receiving (but not sending) a track, and the
2152// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2153// false, the generated m-lines will be a=inactive.
2154TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2155 FakeConstraints constraints;
2156 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2157 true);
2158 CreatePeerConnection(&constraints);
2159 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2160 CreateAnswerAsLocalDescription();
2161
2162 // At this point we should be receiving stream 1, but not sending anything.
2163 // A new offer would be recvonly, but we'll set the "no receive" constraints
2164 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002165 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002166 FakeConstraints offer_constraints;
2167 offer_constraints.AddMandatory(
2168 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2169 offer_constraints.AddMandatory(
2170 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2171 DoCreateOffer(&offer, &offer_constraints);
2172
2173 const cricket::ContentInfo* video_content =
2174 cricket::GetFirstVideoContent(offer->description());
2175 const cricket::VideoContentDescription* video_desc =
2176 static_cast<const cricket::VideoContentDescription*>(
2177 video_content->description);
2178 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
2179
2180 const cricket::ContentInfo* audio_content =
2181 cricket::GetFirstAudioContent(offer->description());
2182 const cricket::AudioContentDescription* audio_desc =
2183 static_cast<const cricket::AudioContentDescription*>(
2184 audio_content->description);
2185 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
2186}
2187
deadbeef653b8e02015-11-11 12:55:10 -08002188// Test that we can use SetConfiguration to change the ICE servers of the
2189// PortAllocator.
2190TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2191 CreatePeerConnection();
2192
2193 PeerConnectionInterface::RTCConfiguration config;
2194 PeerConnectionInterface::IceServer server;
2195 server.uri = "stun:test_hostname";
2196 config.servers.push_back(server);
2197 EXPECT_TRUE(pc_->SetConfiguration(config));
2198
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002199 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2200 EXPECT_EQ("test_hostname",
2201 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002202}
2203
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002204TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2205 CreatePeerConnection();
2206 PeerConnectionInterface::RTCConfiguration config;
2207 config.type = PeerConnectionInterface::kRelay;
2208 EXPECT_TRUE(pc_->SetConfiguration(config));
2209 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2210}
2211
deadbeef293e9262017-01-11 12:28:30 -08002212TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
2213 PeerConnectionInterface::RTCConfiguration config;
2214 config.prune_turn_ports = false;
2215 CreatePeerConnection(config, nullptr);
2216 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2217
2218 config.prune_turn_ports = true;
2219 EXPECT_TRUE(pc_->SetConfiguration(config));
2220 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2221}
2222
skvladd1f5fda2017-02-03 16:54:05 -08002223// Test that the ice check interval can be changed. This does not verify that
2224// the setting makes it all the way to P2PTransportChannel, as that would
2225// require a very complex set of mocks.
2226TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
2227 PeerConnectionInterface::RTCConfiguration config;
2228 config.ice_check_min_interval = rtc::Optional<int>();
2229 CreatePeerConnection(config, nullptr);
2230 config.ice_check_min_interval = rtc::Optional<int>(100);
2231 EXPECT_TRUE(pc_->SetConfiguration(config));
2232 PeerConnectionInterface::RTCConfiguration new_config =
2233 pc_->GetConfiguration();
2234 EXPECT_EQ(new_config.ice_check_min_interval, rtc::Optional<int>(100));
2235}
2236
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002237// Test that when SetConfiguration changes both the pool size and other
2238// attributes, the pooled session is created with the updated attributes.
2239TEST_F(PeerConnectionInterfaceTest,
2240 SetConfigurationCreatesPooledSessionCorrectly) {
2241 CreatePeerConnection();
2242 PeerConnectionInterface::RTCConfiguration config;
2243 config.ice_candidate_pool_size = 1;
2244 PeerConnectionInterface::IceServer server;
2245 server.uri = kStunAddressOnly;
2246 config.servers.push_back(server);
2247 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002248 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002249
2250 const cricket::FakePortAllocatorSession* session =
2251 static_cast<const cricket::FakePortAllocatorSession*>(
2252 port_allocator_->GetPooledSession());
2253 ASSERT_NE(nullptr, session);
2254 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002255}
2256
deadbeef293e9262017-01-11 12:28:30 -08002257// Test that after SetLocalDescription, changing the pool size is not allowed,
2258// and an invalid modification error is returned.
deadbeef6de92f92016-12-12 18:49:32 -08002259TEST_F(PeerConnectionInterfaceTest,
2260 CantChangePoolSizeAfterSetLocalDescription) {
2261 CreatePeerConnection();
2262 // Start by setting a size of 1.
2263 PeerConnectionInterface::RTCConfiguration config;
2264 config.ice_candidate_pool_size = 1;
2265 EXPECT_TRUE(pc_->SetConfiguration(config));
2266
2267 // Set remote offer; can still change pool size at this point.
2268 CreateOfferAsRemoteDescription();
2269 config.ice_candidate_pool_size = 2;
2270 EXPECT_TRUE(pc_->SetConfiguration(config));
2271
2272 // Set local answer; now it's too late.
2273 CreateAnswerAsLocalDescription();
2274 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002275 RTCError error;
2276 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2277 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2278}
2279
2280// Test that SetConfiguration returns an invalid modification error if
2281// modifying a field in the configuration that isn't allowed to be modified.
2282TEST_F(PeerConnectionInterfaceTest,
2283 SetConfigurationReturnsInvalidModificationError) {
2284 PeerConnectionInterface::RTCConfiguration config;
2285 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2286 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2287 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2288 CreatePeerConnection(config, nullptr);
2289
2290 PeerConnectionInterface::RTCConfiguration modified_config = config;
2291 modified_config.bundle_policy =
2292 PeerConnectionInterface::kBundlePolicyMaxBundle;
2293 RTCError error;
2294 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2295 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2296
2297 modified_config = config;
2298 modified_config.rtcp_mux_policy =
2299 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2300 error.set_type(RTCErrorType::NONE);
2301 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2302 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2303
2304 modified_config = config;
2305 modified_config.continual_gathering_policy =
2306 PeerConnectionInterface::GATHER_CONTINUALLY;
2307 error.set_type(RTCErrorType::NONE);
2308 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2309 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2310}
2311
2312// Test that SetConfiguration returns a range error if the candidate pool size
2313// is negative or larger than allowed by the spec.
2314TEST_F(PeerConnectionInterfaceTest,
2315 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2316 PeerConnectionInterface::RTCConfiguration config;
2317 CreatePeerConnection(config, nullptr);
2318
2319 config.ice_candidate_pool_size = -1;
2320 RTCError error;
2321 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2322 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2323
2324 config.ice_candidate_pool_size = INT_MAX;
2325 error.set_type(RTCErrorType::NONE);
2326 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2327 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2328}
2329
2330// Test that SetConfiguration returns a syntax error if parsing an ICE server
2331// URL failed.
2332TEST_F(PeerConnectionInterfaceTest,
2333 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2334 PeerConnectionInterface::RTCConfiguration config;
2335 CreatePeerConnection(config, nullptr);
2336
2337 PeerConnectionInterface::IceServer bad_server;
2338 bad_server.uri = "stunn:www.example.com";
2339 config.servers.push_back(bad_server);
2340 RTCError error;
2341 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2342 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2343}
2344
2345// Test that SetConfiguration returns an invalid parameter error if a TURN
2346// IceServer is missing a username or password.
2347TEST_F(PeerConnectionInterfaceTest,
2348 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2349 PeerConnectionInterface::RTCConfiguration config;
2350 CreatePeerConnection(config, nullptr);
2351
2352 PeerConnectionInterface::IceServer bad_server;
2353 bad_server.uri = "turn:www.example.com";
2354 // Missing password.
2355 bad_server.username = "foo";
2356 config.servers.push_back(bad_server);
2357 RTCError error;
2358 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2359 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002360}
2361
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362// Test that PeerConnection::Close changes the states to closed and all remote
2363// tracks change state to ended.
2364TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2365 // Initialize a PeerConnection and negotiate local and remote session
2366 // description.
2367 InitiateCall();
2368 ASSERT_EQ(1u, pc_->local_streams()->count());
2369 ASSERT_EQ(1u, pc_->remote_streams()->count());
2370
2371 pc_->Close();
2372
2373 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2374 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2375 pc_->ice_connection_state());
2376 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2377 pc_->ice_gathering_state());
2378
2379 EXPECT_EQ(1u, pc_->local_streams()->count());
2380 EXPECT_EQ(1u, pc_->remote_streams()->count());
2381
zhihuang9763d562016-08-05 11:14:50 -07002382 rtc::scoped_refptr<MediaStreamInterface> remote_stream =
2383 pc_->remote_streams()->at(0);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002384 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002385 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002386 remote_stream->GetAudioTracks()[0]->state(), kTimeout);
2387 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2388 remote_stream->GetVideoTracks()[0]->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389}
2390
2391// Test that PeerConnection methods fails gracefully after
2392// PeerConnection::Close has been called.
2393TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002394 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2396 CreateOfferAsRemoteDescription();
2397 CreateAnswerAsLocalDescription();
2398
2399 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002400 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 pc_->local_streams()->at(0);
2402
2403 pc_->Close();
2404
2405 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002406 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407
2408 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002409 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002411 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412
2413 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2414
2415 EXPECT_TRUE(pc_->local_description() != NULL);
2416 EXPECT_TRUE(pc_->remote_description() != NULL);
2417
kwibergd1fe2812016-04-27 06:47:29 -07002418 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07002419 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002420 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07002421 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422
2423 std::string sdp;
2424 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2425 SessionDescriptionInterface* remote_offer =
2426 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2427 sdp, NULL);
2428 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
2429
2430 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2431 SessionDescriptionInterface* local_offer =
2432 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2433 sdp, NULL);
2434 EXPECT_FALSE(DoSetLocalDescription(local_offer));
2435}
2436
2437// Test that GetStats can still be called after PeerConnection::Close.
2438TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
2439 InitiateCall();
2440 pc_->Close();
2441 DoGetStats(NULL);
2442}
deadbeefab9b2d12015-10-14 11:33:11 -07002443
2444// NOTE: The series of tests below come from what used to be
2445// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2446// setting a remote or local description has the expected effects.
2447
2448// This test verifies that the remote MediaStreams corresponding to a received
2449// SDP string is created. In this test the two separate MediaStreams are
2450// signaled.
2451TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2452 FakeConstraints constraints;
2453 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2454 true);
2455 CreatePeerConnection(&constraints);
2456 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2457
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002458 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002459 EXPECT_TRUE(
2460 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2461 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2462 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2463
2464 // Create a session description based on another SDP with another
2465 // MediaStream.
2466 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
2467
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002468 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002469 EXPECT_TRUE(
2470 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2471}
2472
2473// This test verifies that when remote tracks are added/removed from SDP, the
2474// created remote streams are updated appropriately.
2475TEST_F(PeerConnectionInterfaceTest,
2476 AddRemoveTrackFromExistingRemoteMediaStream) {
2477 FakeConstraints constraints;
2478 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2479 true);
2480 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002481 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002482 CreateSessionDescriptionAndReference(1, 1);
deadbeefab9b2d12015-10-14 11:33:11 -07002483 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
2484 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2485 reference_collection_));
2486
2487 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002488 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002489 CreateSessionDescriptionAndReference(2, 2);
deadbeefab9b2d12015-10-14 11:33:11 -07002490 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
2491 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2492 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002493 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002494 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2495 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002496 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002497 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2498 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002499
2500 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002501 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002502 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002503 MockTrackObserver audio_track_observer(audio_track2);
2504 MockTrackObserver video_track_observer(video_track2);
2505
2506 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2507 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
deadbeefab9b2d12015-10-14 11:33:11 -07002508 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
2509 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2510 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002511 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002512 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002513 audio_track2->state(), kTimeout);
2514 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2515 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002516}
2517
2518// This tests that remote tracks are ended if a local session description is set
2519// that rejects the media content type.
2520TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
2521 FakeConstraints constraints;
2522 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2523 true);
2524 CreatePeerConnection(&constraints);
2525 // First create and set a remote offer, then reject its video content in our
2526 // answer.
2527 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2528 ASSERT_EQ(1u, observer_.remote_streams()->count());
2529 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2530 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2531 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2532
2533 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
2534 remote_stream->GetVideoTracks()[0];
2535 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
2536 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
2537 remote_stream->GetAudioTracks()[0];
2538 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2539
kwibergd1fe2812016-04-27 06:47:29 -07002540 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002541 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002542 cricket::ContentInfo* video_info =
2543 local_answer->description()->GetContentByName("video");
2544 video_info->rejected = true;
2545 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2546 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2547 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2548
2549 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002550 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002551 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002552 video_info = local_offer->description()->GetContentByName("video");
2553 ASSERT_TRUE(video_info != nullptr);
2554 video_info->rejected = true;
2555 cricket::ContentInfo* audio_info =
2556 local_offer->description()->GetContentByName("audio");
2557 ASSERT_TRUE(audio_info != nullptr);
2558 audio_info->rejected = true;
2559 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002560 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002561 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002562 remote_audio->state(), kTimeout);
2563 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2564 remote_video->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002565}
2566
2567// This tests that we won't crash if the remote track has been removed outside
2568// of PeerConnection and then PeerConnection tries to reject the track.
2569TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2570 FakeConstraints constraints;
2571 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2572 true);
2573 CreatePeerConnection(&constraints);
2574 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2575 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2576 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2577 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2578
kwibergd1fe2812016-04-27 06:47:29 -07002579 std::unique_ptr<SessionDescriptionInterface> local_answer(
deadbeefab9b2d12015-10-14 11:33:11 -07002580 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2581 kSdpStringWithStream1, nullptr));
2582 cricket::ContentInfo* video_info =
2583 local_answer->description()->GetContentByName("video");
2584 video_info->rejected = true;
2585 cricket::ContentInfo* audio_info =
2586 local_answer->description()->GetContentByName("audio");
2587 audio_info->rejected = true;
2588 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2589
2590 // No crash is a pass.
2591}
2592
deadbeef5e97fb52015-10-15 12:49:08 -07002593// This tests that if a recvonly remote description is set, no remote streams
2594// will be created, even if the description contains SSRCs/MSIDs.
2595// See: https://code.google.com/p/webrtc/issues/detail?id=5054
2596TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2597 FakeConstraints constraints;
2598 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2599 true);
2600 CreatePeerConnection(&constraints);
2601
2602 std::string recvonly_offer = kSdpStringWithStream1;
2603 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2604 strlen(kRecvonly), &recvonly_offer);
2605 CreateAndSetRemoteOffer(recvonly_offer);
2606
2607 EXPECT_EQ(0u, observer_.remote_streams()->count());
2608}
2609
deadbeefab9b2d12015-10-14 11:33:11 -07002610// This tests that a default MediaStream is created if a remote session
2611// description doesn't contain any streams and no MSID support.
2612// It also tests that the default stream is updated if a video m-line is added
2613// in a subsequent session description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002614TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002615 FakeConstraints constraints;
2616 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2617 true);
2618 CreatePeerConnection(&constraints);
2619 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2620
2621 ASSERT_EQ(1u, observer_.remote_streams()->count());
2622 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2623
2624 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2625 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2626 EXPECT_EQ("default", remote_stream->label());
2627
2628 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2629 ASSERT_EQ(1u, observer_.remote_streams()->count());
2630 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2631 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002632 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2633 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002634 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2635 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002636 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2637 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002638}
2639
2640// This tests that a default MediaStream is created if a remote session
2641// description doesn't contain any streams and media direction is send only.
2642TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002643 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002644 FakeConstraints constraints;
2645 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2646 true);
2647 CreatePeerConnection(&constraints);
2648 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2649
2650 ASSERT_EQ(1u, observer_.remote_streams()->count());
2651 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2652
2653 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2654 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2655 EXPECT_EQ("default", remote_stream->label());
2656}
2657
2658// This tests that it won't crash when PeerConnection tries to remove
2659// a remote track that as already been removed from the MediaStream.
2660TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2661 FakeConstraints constraints;
2662 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2663 true);
2664 CreatePeerConnection(&constraints);
2665 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2666 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2667 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2668 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2669
2670 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2671
2672 // No crash is a pass.
2673}
2674
2675// This tests that a default MediaStream is created if the remote session
2676// description doesn't contain any streams and don't contain an indication if
2677// MSID is supported.
2678TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002679 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002680 FakeConstraints constraints;
2681 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2682 true);
2683 CreatePeerConnection(&constraints);
2684 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2685
2686 ASSERT_EQ(1u, observer_.remote_streams()->count());
2687 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2688 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2689 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2690}
2691
2692// This tests that a default MediaStream is not created if the remote session
2693// description doesn't contain any streams but does support MSID.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002694TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002695 FakeConstraints constraints;
2696 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2697 true);
2698 CreatePeerConnection(&constraints);
2699 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2700 EXPECT_EQ(0u, observer_.remote_streams()->count());
2701}
2702
deadbeefbda7e0b2015-12-08 17:13:40 -08002703// This tests that when setting a new description, the old default tracks are
2704// not destroyed and recreated.
2705// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Stefan Holmer102362b2016-03-18 09:39:07 +01002706TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002707 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08002708 FakeConstraints constraints;
2709 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2710 true);
2711 CreatePeerConnection(&constraints);
2712 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2713
2714 ASSERT_EQ(1u, observer_.remote_streams()->count());
2715 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2716 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2717
2718 // Set the track to "disabled", then set a new description and ensure the
2719 // track is still disabled, which ensures it hasn't been recreated.
2720 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2721 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2722 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2723 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2724}
2725
deadbeefab9b2d12015-10-14 11:33:11 -07002726// This tests that a default MediaStream is not created if a remote session
2727// description is updated to not have any MediaStreams.
2728TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2729 FakeConstraints constraints;
2730 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2731 true);
2732 CreatePeerConnection(&constraints);
2733 CreateAndSetRemoteOffer(kSdpStringWithStream1);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002734 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002735 EXPECT_TRUE(
2736 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2737
2738 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2739 EXPECT_EQ(0u, observer_.remote_streams()->count());
2740}
2741
2742// This tests that an RtpSender is created when the local description is set
2743// after adding a local stream.
2744// TODO(deadbeef): This test and the one below it need to be updated when
2745// an RtpSender's lifetime isn't determined by when a local description is set.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002746TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002747 FakeConstraints constraints;
2748 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2749 true);
2750 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002751
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002752 // Create an offer with 1 stream with 2 tracks of each type.
2753 rtc::scoped_refptr<StreamCollection> stream_collection =
2754 CreateStreamCollection(1, 2);
2755 pc_->AddStream(stream_collection->at(0));
2756 std::unique_ptr<SessionDescriptionInterface> offer;
2757 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2758 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002759
deadbeefab9b2d12015-10-14 11:33:11 -07002760 auto senders = pc_->GetSenders();
2761 EXPECT_EQ(4u, senders.size());
2762 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2763 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2764 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2765 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2766
2767 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002768 pc_->RemoveStream(stream_collection->at(0));
2769 stream_collection = CreateStreamCollection(1, 1);
2770 pc_->AddStream(stream_collection->at(0));
2771 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2772 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2773
deadbeefab9b2d12015-10-14 11:33:11 -07002774 senders = pc_->GetSenders();
2775 EXPECT_EQ(2u, senders.size());
2776 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2777 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2778 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2779 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2780}
2781
2782// This tests that an RtpSender is created when the local description is set
2783// before adding a local stream.
2784TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002785 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002786 FakeConstraints constraints;
2787 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2788 true);
2789 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002790
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002791 rtc::scoped_refptr<StreamCollection> stream_collection =
2792 CreateStreamCollection(1, 2);
2793 // Add a stream to create the offer, but remove it afterwards.
2794 pc_->AddStream(stream_collection->at(0));
2795 std::unique_ptr<SessionDescriptionInterface> offer;
2796 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2797 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002798
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002799 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002800 auto senders = pc_->GetSenders();
2801 EXPECT_EQ(0u, senders.size());
2802
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002803 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002804 senders = pc_->GetSenders();
2805 EXPECT_EQ(4u, senders.size());
2806 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2807 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2808 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2809 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2810}
2811
2812// This tests that the expected behavior occurs if the SSRC on a local track is
2813// changed when SetLocalDescription is called.
2814TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002815 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07002816 FakeConstraints constraints;
2817 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2818 true);
2819 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002820
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002821 rtc::scoped_refptr<StreamCollection> stream_collection =
2822 CreateStreamCollection(2, 1);
2823 pc_->AddStream(stream_collection->at(0));
2824 std::unique_ptr<SessionDescriptionInterface> offer;
2825 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2826 // Grab a copy of the offer before it gets passed into the PC.
2827 std::unique_ptr<JsepSessionDescription> modified_offer(
2828 new JsepSessionDescription(JsepSessionDescription::kOffer));
2829 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
2830 offer->session_version());
2831 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002832
deadbeefab9b2d12015-10-14 11:33:11 -07002833 auto senders = pc_->GetSenders();
2834 EXPECT_EQ(2u, senders.size());
2835 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2836 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2837
2838 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002839 cricket::MediaContentDescription* desc =
2840 cricket::GetFirstAudioContentDescription(modified_offer->description());
2841 ASSERT_TRUE(desc != NULL);
2842 for (StreamParams& stream : desc->mutable_streams()) {
2843 for (unsigned int& ssrc : stream.ssrcs) {
2844 ++ssrc;
2845 }
2846 }
deadbeefab9b2d12015-10-14 11:33:11 -07002847
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002848 desc =
2849 cricket::GetFirstVideoContentDescription(modified_offer->description());
2850 ASSERT_TRUE(desc != NULL);
2851 for (StreamParams& stream : desc->mutable_streams()) {
2852 for (unsigned int& ssrc : stream.ssrcs) {
2853 ++ssrc;
2854 }
2855 }
2856
2857 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002858 senders = pc_->GetSenders();
2859 EXPECT_EQ(2u, senders.size());
2860 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2861 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2862 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2863 // changed.
2864}
2865
2866// This tests that the expected behavior occurs if a new session description is
2867// set with the same tracks, but on a different MediaStream.
Stefan Holmer55d6e7c2016-03-17 16:26:40 +01002868TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002869 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002870 FakeConstraints constraints;
2871 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2872 true);
2873 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002874
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002875 rtc::scoped_refptr<StreamCollection> stream_collection =
2876 CreateStreamCollection(2, 1);
2877 pc_->AddStream(stream_collection->at(0));
2878 std::unique_ptr<SessionDescriptionInterface> offer;
2879 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2880 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002881
deadbeefab9b2d12015-10-14 11:33:11 -07002882 auto senders = pc_->GetSenders();
2883 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002884 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2885 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002886
2887 // Add a new MediaStream but with the same tracks as in the first stream.
2888 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2889 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002890 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2891 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002892 pc_->AddStream(stream_1);
2893
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002894 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2895 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002896
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002897 auto new_senders = pc_->GetSenders();
2898 // Should be the same senders as before, but with updated stream id.
2899 // Note that this behavior is subject to change in the future.
2900 // We may decide the PC should ignore existing tracks in AddStream.
2901 EXPECT_EQ(senders, new_senders);
2902 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2903 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002904}
2905
zhihuang81c3a032016-11-17 12:06:24 -08002906// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
2907TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) {
2908 FakeConstraints constraints;
2909 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2910 true);
2911 CreatePeerConnection(&constraints);
2912 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2913 EXPECT_EQ(observer_.num_added_tracks_, 1);
2914 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2915
2916 // Create and set the updated remote SDP.
2917 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2918 EXPECT_EQ(observer_.num_added_tracks_, 2);
2919 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2920}
2921
deadbeefd1a38b52016-12-10 13:15:33 -08002922// Test that when SetConfiguration is called and the configuration is
2923// changing, the next offer causes an ICE restart.
2924TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingIceRetart) {
2925 PeerConnectionInterface::RTCConfiguration config;
2926 config.type = PeerConnectionInterface::kRelay;
2927 // Need to pass default constraints to prevent disabling of DTLS...
2928 FakeConstraints default_constraints;
2929 CreatePeerConnection(config, &default_constraints);
2930 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2931
2932 // Do initial offer/answer so there's something to restart.
2933 CreateOfferAsLocalDescription();
2934 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2935
2936 // Grab the ufrags.
2937 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2938
2939 // Change ICE policy, which should trigger an ICE restart on the next offer.
2940 config.type = PeerConnectionInterface::kAll;
2941 EXPECT_TRUE(pc_->SetConfiguration(config));
2942 CreateOfferAsLocalDescription();
2943
2944 // Grab the new ufrags.
2945 std::vector<std::string> subsequent_ufrags =
2946 GetUfrags(pc_->local_description());
2947
2948 // Sanity check.
2949 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
2950 // Check that each ufrag is different.
2951 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
2952 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
2953 }
2954}
2955
2956// Test that when SetConfiguration is called and the configuration *isn't*
2957// changing, the next offer does *not* cause an ICE restart.
2958TEST_F(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRetart) {
2959 PeerConnectionInterface::RTCConfiguration config;
2960 config.type = PeerConnectionInterface::kRelay;
2961 // Need to pass default constraints to prevent disabling of DTLS...
2962 FakeConstraints default_constraints;
2963 CreatePeerConnection(config, &default_constraints);
2964 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2965
2966 // Do initial offer/answer so there's something to restart.
2967 CreateOfferAsLocalDescription();
2968 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2969
2970 // Grab the ufrags.
2971 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2972
2973 // Call SetConfiguration with a config identical to what the PC was
2974 // constructed with.
2975 EXPECT_TRUE(pc_->SetConfiguration(config));
2976 CreateOfferAsLocalDescription();
2977
2978 // Grab the new ufrags.
2979 std::vector<std::string> subsequent_ufrags =
2980 GetUfrags(pc_->local_description());
2981
2982 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
2983}
2984
2985// Test for a weird corner case scenario:
2986// 1. Audio/video session established.
2987// 2. SetConfiguration changes ICE config; ICE restart needed.
2988// 3. ICE restart initiated by remote peer, but only for one m= section.
2989// 4. Next createOffer should initiate an ICE restart, but only for the other
2990// m= section; it would be pointless to do an ICE restart for the m= section
2991// that was already restarted.
2992TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
2993 PeerConnectionInterface::RTCConfiguration config;
2994 config.type = PeerConnectionInterface::kRelay;
2995 // Need to pass default constraints to prevent disabling of DTLS...
2996 FakeConstraints default_constraints;
2997 CreatePeerConnection(config, &default_constraints);
2998 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2999
3000 // Do initial offer/answer so there's something to restart.
3001 CreateOfferAsLocalDescription();
3002 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
3003
3004 // Change ICE policy, which should set the "needs-ice-restart" flag.
3005 config.type = PeerConnectionInterface::kAll;
3006 EXPECT_TRUE(pc_->SetConfiguration(config));
3007
3008 // Do ICE restart for the first m= section, initiated by remote peer.
3009 webrtc::JsepSessionDescription* remote_offer =
3010 new webrtc::JsepSessionDescription(SessionDescriptionInterface::kOffer);
3011 EXPECT_TRUE(remote_offer->Initialize(kSdpStringWithStream1, nullptr));
3012 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3013 "modified";
3014 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3015 CreateAnswerAsLocalDescription();
3016
3017 // Grab the ufrags.
3018 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3019 ASSERT_EQ(2, initial_ufrags.size());
3020
3021 // Create offer and grab the new ufrags.
3022 CreateOfferAsLocalDescription();
3023 std::vector<std::string> subsequent_ufrags =
3024 GetUfrags(pc_->local_description());
3025 ASSERT_EQ(2, subsequent_ufrags.size());
3026
3027 // Ensure that only the ufrag for the second m= section changed.
3028 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3029 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3030}
3031
deadbeeffe4a8a42016-12-20 17:56:17 -08003032// Tests that the methods to return current/pending descriptions work as
3033// expected at different points in the offer/answer exchange. This test does
3034// one offer/answer exchange as the offerer, then another as the answerer.
3035TEST_F(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
3036 // This disables DTLS so we can apply an answer to ourselves.
3037 CreatePeerConnection();
3038
3039 // Create initial local offer and get SDP (which will also be used as
3040 // answer/pranswer);
3041 std::unique_ptr<SessionDescriptionInterface> offer;
3042 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3043 std::string sdp;
3044 EXPECT_TRUE(offer->ToString(&sdp));
3045
3046 // Set local offer.
3047 SessionDescriptionInterface* local_offer = offer.release();
3048 EXPECT_TRUE(DoSetLocalDescription(local_offer));
3049 EXPECT_EQ(local_offer, pc_->pending_local_description());
3050 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3051 EXPECT_EQ(nullptr, pc_->current_local_description());
3052 EXPECT_EQ(nullptr, pc_->current_remote_description());
3053
3054 // Set remote pranswer.
3055 SessionDescriptionInterface* remote_pranswer =
3056 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3057 sdp, nullptr);
3058 EXPECT_TRUE(DoSetRemoteDescription(remote_pranswer));
3059 EXPECT_EQ(local_offer, pc_->pending_local_description());
3060 EXPECT_EQ(remote_pranswer, pc_->pending_remote_description());
3061 EXPECT_EQ(nullptr, pc_->current_local_description());
3062 EXPECT_EQ(nullptr, pc_->current_remote_description());
3063
3064 // Set remote answer.
3065 SessionDescriptionInterface* remote_answer = webrtc::CreateSessionDescription(
3066 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3067 EXPECT_TRUE(DoSetRemoteDescription(remote_answer));
3068 EXPECT_EQ(nullptr, pc_->pending_local_description());
3069 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3070 EXPECT_EQ(local_offer, pc_->current_local_description());
3071 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3072
3073 // Set remote offer.
3074 SessionDescriptionInterface* remote_offer = webrtc::CreateSessionDescription(
3075 SessionDescriptionInterface::kOffer, sdp, nullptr);
3076 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3077 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3078 EXPECT_EQ(nullptr, pc_->pending_local_description());
3079 EXPECT_EQ(local_offer, pc_->current_local_description());
3080 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3081
3082 // Set local pranswer.
3083 SessionDescriptionInterface* local_pranswer =
3084 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3085 sdp, nullptr);
3086 EXPECT_TRUE(DoSetLocalDescription(local_pranswer));
3087 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3088 EXPECT_EQ(local_pranswer, pc_->pending_local_description());
3089 EXPECT_EQ(local_offer, pc_->current_local_description());
3090 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3091
3092 // Set local answer.
3093 SessionDescriptionInterface* local_answer = webrtc::CreateSessionDescription(
3094 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3095 EXPECT_TRUE(DoSetLocalDescription(local_answer));
3096 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3097 EXPECT_EQ(nullptr, pc_->pending_local_description());
3098 EXPECT_EQ(remote_offer, pc_->current_remote_description());
3099 EXPECT_EQ(local_answer, pc_->current_local_description());
3100}
3101
zhihuang77985012017-02-07 15:45:16 -08003102// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3103// after the PeerConnection is closed.
3104TEST_F(PeerConnectionInterfaceTest,
3105 StartAndStopLoggingAfterPeerConnectionClosed) {
3106 CreatePeerConnection();
3107 // The RtcEventLog will be reset when the PeerConnection is closed.
3108 pc_->Close();
3109
3110 rtc::PlatformFile file = 0;
3111 int64_t max_size_bytes = 1024;
3112 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3113 pc_->StopRtcEventLog();
3114}
3115
nisse51542be2016-02-12 02:27:06 -08003116class PeerConnectionMediaConfigTest : public testing::Test {
3117 protected:
3118 void SetUp() override {
nisseaf510af2016-03-21 08:20:42 -07003119 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
nisse51542be2016-02-12 02:27:06 -08003120 pcf_->Initialize();
3121 }
3122 const cricket::MediaConfig& TestCreatePeerConnection(
3123 const PeerConnectionInterface::RTCConfiguration& config,
3124 const MediaConstraintsInterface *constraints) {
3125 pcf_->create_media_controller_called_ = false;
3126
zhihuang9763d562016-08-05 11:14:50 -07003127 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3128 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003129 EXPECT_TRUE(pc.get());
3130 EXPECT_TRUE(pcf_->create_media_controller_called_);
3131 return pcf_->create_media_controller_config_;
3132 }
3133
zhihuang9763d562016-08-05 11:14:50 -07003134 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003135 MockPeerConnectionObserver observer_;
3136};
3137
3138// This test verifies the default behaviour with no constraints and a
3139// default RTCConfiguration.
3140TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3141 PeerConnectionInterface::RTCConfiguration config;
3142 FakeConstraints constraints;
3143
3144 const cricket::MediaConfig& media_config =
3145 TestCreatePeerConnection(config, &constraints);
3146
3147 EXPECT_FALSE(media_config.enable_dscp);
nisse0db023a2016-03-01 04:29:59 -08003148 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection);
3149 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing);
3150 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003151}
3152
3153// This test verifies the DSCP constraint is recognized and passed to
3154// the CreateMediaController call.
3155TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
3156 PeerConnectionInterface::RTCConfiguration config;
3157 FakeConstraints constraints;
3158
3159 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
3160 const cricket::MediaConfig& media_config =
3161 TestCreatePeerConnection(config, &constraints);
3162
3163 EXPECT_TRUE(media_config.enable_dscp);
3164}
3165
3166// This test verifies the cpu overuse detection constraint is
3167// recognized and passed to the CreateMediaController call.
3168TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
3169 PeerConnectionInterface::RTCConfiguration config;
3170 FakeConstraints constraints;
3171
3172 constraints.AddOptional(
3173 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
3174 const cricket::MediaConfig media_config =
3175 TestCreatePeerConnection(config, &constraints);
3176
nisse0db023a2016-03-01 04:29:59 -08003177 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection);
nisse51542be2016-02-12 02:27:06 -08003178}
3179
3180// This test verifies that the disable_prerenderer_smoothing flag is
3181// propagated from RTCConfiguration to the CreateMediaController call.
3182TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3183 PeerConnectionInterface::RTCConfiguration config;
3184 FakeConstraints constraints;
3185
Niels Möller71bdda02016-03-31 12:59:59 +02003186 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08003187 const cricket::MediaConfig& media_config =
3188 TestCreatePeerConnection(config, &constraints);
3189
nisse0db023a2016-03-01 04:29:59 -08003190 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing);
3191}
3192
3193// This test verifies the suspend below min bitrate constraint is
3194// recognized and passed to the CreateMediaController call.
3195TEST_F(PeerConnectionMediaConfigTest,
3196 TestSuspendBelowMinBitrateConstraintTrue) {
3197 PeerConnectionInterface::RTCConfiguration config;
3198 FakeConstraints constraints;
3199
3200 constraints.AddOptional(
3201 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3202 true);
3203 const cricket::MediaConfig media_config =
3204 TestCreatePeerConnection(config, &constraints);
3205
3206 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003207}
3208
deadbeefab9b2d12015-10-14 11:33:11 -07003209// The following tests verify that session options are created correctly.
deadbeefc80741f2015-10-22 13:14:45 -07003210// TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
3211// "verify options are converted correctly", should be "pass options into
3212// CreateOffer and verify the correct offer is produced."
deadbeefab9b2d12015-10-14 11:33:11 -07003213
3214TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
3215 RTCOfferAnswerOptions rtc_options;
3216 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3217
3218 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003219 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003220
3221 rtc_options.offer_to_receive_audio =
3222 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003223 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003224}
3225
3226TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
3227 RTCOfferAnswerOptions rtc_options;
3228 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3229
3230 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003231 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003232
3233 rtc_options.offer_to_receive_video =
3234 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003235 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003236}
3237
3238// Test that a MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003239// OfferToReceiveAudio and OfferToReceiveVideo options are set.
deadbeefab9b2d12015-10-14 11:33:11 -07003240TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
3241 RTCOfferAnswerOptions rtc_options;
3242 rtc_options.offer_to_receive_audio = 1;
3243 rtc_options.offer_to_receive_video = 1;
3244
3245 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003246 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003247 EXPECT_TRUE(options.has_audio());
3248 EXPECT_TRUE(options.has_video());
3249 EXPECT_TRUE(options.bundle_enabled);
3250}
3251
3252// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003253// OfferToReceiveAudio is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003254TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
3255 RTCOfferAnswerOptions rtc_options;
3256 rtc_options.offer_to_receive_audio = 1;
3257
3258 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003259 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003260 EXPECT_TRUE(options.has_audio());
3261 EXPECT_FALSE(options.has_video());
3262 EXPECT_TRUE(options.bundle_enabled);
3263}
3264
3265// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003266// the default OfferOptions are used.
deadbeefab9b2d12015-10-14 11:33:11 -07003267TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
3268 RTCOfferAnswerOptions rtc_options;
3269
3270 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003271 options.transport_options["audio"] = cricket::TransportOptions();
3272 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003273 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefc80741f2015-10-22 13:14:45 -07003274 EXPECT_TRUE(options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07003275 EXPECT_FALSE(options.has_video());
deadbeefc80741f2015-10-22 13:14:45 -07003276 EXPECT_TRUE(options.bundle_enabled);
deadbeefab9b2d12015-10-14 11:33:11 -07003277 EXPECT_TRUE(options.vad_enabled);
deadbeef0ed85b22016-02-23 17:24:52 -08003278 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3279 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003280}
3281
3282// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003283// OfferToReceiveVideo is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003284TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
3285 RTCOfferAnswerOptions rtc_options;
3286 rtc_options.offer_to_receive_audio = 0;
3287 rtc_options.offer_to_receive_video = 1;
3288
3289 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003290 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003291 EXPECT_FALSE(options.has_audio());
3292 EXPECT_TRUE(options.has_video());
3293 EXPECT_TRUE(options.bundle_enabled);
3294}
3295
3296// Test that a correct MediaSessionOptions is created for an offer if
3297// UseRtpMux is set to false.
3298TEST(CreateSessionOptionsTest,
3299 GetMediaSessionOptionsForOfferWithBundleDisabled) {
3300 RTCOfferAnswerOptions rtc_options;
3301 rtc_options.offer_to_receive_audio = 1;
3302 rtc_options.offer_to_receive_video = 1;
3303 rtc_options.use_rtp_mux = false;
3304
3305 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003306 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003307 EXPECT_TRUE(options.has_audio());
3308 EXPECT_TRUE(options.has_video());
3309 EXPECT_FALSE(options.bundle_enabled);
3310}
3311
3312// Test that a correct MediaSessionOptions is created to restart ice if
3313// IceRestart is set. It also tests that subsequent MediaSessionOptions don't
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003314// have |audio_transport_options.ice_restart| etc. set.
deadbeefab9b2d12015-10-14 11:33:11 -07003315TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
3316 RTCOfferAnswerOptions rtc_options;
3317 rtc_options.ice_restart = true;
3318
3319 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003320 options.transport_options["audio"] = cricket::TransportOptions();
3321 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003322 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003323 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
3324 EXPECT_TRUE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003325
3326 rtc_options = RTCOfferAnswerOptions();
htaaac2dea2016-03-10 13:35:55 -08003327 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003328 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3329 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003330}
3331
3332// Test that the MediaConstraints in an answer don't affect if audio and video
3333// is offered in an offer but that if kOfferToReceiveAudio or
3334// kOfferToReceiveVideo constraints are true in an offer, the media type will be
3335// included in subsequent answers.
3336TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
3337 FakeConstraints answer_c;
3338 answer_c.SetMandatoryReceiveAudio(true);
3339 answer_c.SetMandatoryReceiveVideo(true);
3340
3341 cricket::MediaSessionOptions answer_options;
3342 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
3343 EXPECT_TRUE(answer_options.has_audio());
3344 EXPECT_TRUE(answer_options.has_video());
3345
deadbeefc80741f2015-10-22 13:14:45 -07003346 RTCOfferAnswerOptions rtc_offer_options;
deadbeefab9b2d12015-10-14 11:33:11 -07003347
3348 cricket::MediaSessionOptions offer_options;
htaaac2dea2016-03-10 13:35:55 -08003349 EXPECT_TRUE(
3350 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
deadbeefc80741f2015-10-22 13:14:45 -07003351 EXPECT_TRUE(offer_options.has_audio());
htaaac2dea2016-03-10 13:35:55 -08003352 EXPECT_TRUE(offer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003353
deadbeefc80741f2015-10-22 13:14:45 -07003354 RTCOfferAnswerOptions updated_rtc_offer_options;
3355 updated_rtc_offer_options.offer_to_receive_audio = 1;
3356 updated_rtc_offer_options.offer_to_receive_video = 1;
deadbeefab9b2d12015-10-14 11:33:11 -07003357
3358 cricket::MediaSessionOptions updated_offer_options;
htaaac2dea2016-03-10 13:35:55 -08003359 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
htaa2a49d92016-03-04 02:51:39 -08003360 &updated_offer_options));
deadbeefab9b2d12015-10-14 11:33:11 -07003361 EXPECT_TRUE(updated_offer_options.has_audio());
3362 EXPECT_TRUE(updated_offer_options.has_video());
3363
3364 // Since an offer has been created with both audio and video, subsequent
3365 // offers and answers should contain both audio and video.
3366 // Answers will only contain the media types that exist in the offer
3367 // regardless of the value of |updated_answer_options.has_audio| and
3368 // |updated_answer_options.has_video|.
3369 FakeConstraints updated_answer_c;
3370 answer_c.SetMandatoryReceiveAudio(false);
3371 answer_c.SetMandatoryReceiveVideo(false);
3372
3373 cricket::MediaSessionOptions updated_answer_options;
3374 EXPECT_TRUE(
3375 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
3376 EXPECT_TRUE(updated_answer_options.has_audio());
3377 EXPECT_TRUE(updated_answer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003378}
deadbeef3edec7c2016-12-10 11:44:26 -08003379
deadbeef293e9262017-01-11 12:28:30 -08003380// Tests a few random fields being different.
3381TEST(RTCConfigurationTest, ComparisonOperators) {
3382 PeerConnectionInterface::RTCConfiguration a;
3383 PeerConnectionInterface::RTCConfiguration b;
3384 EXPECT_EQ(a, b);
3385
3386 PeerConnectionInterface::RTCConfiguration c;
3387 c.servers.push_back(PeerConnectionInterface::IceServer());
3388 EXPECT_NE(a, c);
3389
3390 PeerConnectionInterface::RTCConfiguration d;
3391 d.type = PeerConnectionInterface::kRelay;
3392 EXPECT_NE(a, d);
3393
3394 PeerConnectionInterface::RTCConfiguration e;
3395 e.audio_jitter_buffer_max_packets = 5;
3396 EXPECT_NE(a, e);
3397
3398 PeerConnectionInterface::RTCConfiguration f;
3399 f.ice_connection_receiving_timeout = 1337;
3400 EXPECT_NE(a, f);
3401
3402 PeerConnectionInterface::RTCConfiguration g;
3403 g.disable_ipv6 = true;
3404 EXPECT_NE(a, g);
3405
3406 PeerConnectionInterface::RTCConfiguration h(
3407 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3408 EXPECT_NE(a, h);
3409}